Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Nov 2018 19:28:01 +0000 (UTC)
From:      Maxim Sobolev <sobomax@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r341257 - head/bin/dd
Message-ID:  <201811291928.wATJS1mP021888@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sobomax
Date: Thu Nov 29 19:28:01 2018
New Revision: 341257
URL: https://svnweb.freebsd.org/changeset/base/341257

Log:
  Replace hand-crafted naive byte-by-byte zero block detection routine
  with macro based around memcmp(). The latter is expected to be some
  8 times faster on a modern 64-bit architectures.
  
  In practice, throughput of doing conv=sparse from /dev/zero to /dev/null
  went up some 5-fold here from 1.9GB/sec to 9.7GB/sec with this change
  (bs=128k).
  
  MFC after:	2 weeks

Modified:
  head/bin/dd/dd.c
  head/bin/dd/dd.h

Modified: head/bin/dd/dd.c
==============================================================================
--- head/bin/dd/dd.c	Thu Nov 29 19:13:10 2018	(r341256)
+++ head/bin/dd/dd.c	Thu Nov 29 19:28:01 2018	(r341257)
@@ -511,7 +511,7 @@ void
 dd_out(int force)
 {
 	u_char *outp;
-	size_t cnt, i, n;
+	size_t cnt, n;
 	ssize_t nw;
 	static int warned;
 	int sparse;
@@ -544,12 +544,8 @@ dd_out(int force)
 		do {
 			sparse = 0;
 			if (ddflags & C_SPARSE) {
-				sparse = 1;	/* Is buffer sparse? */
-				for (i = 0; i < cnt; i++)
-					if (outp[i] != 0) {
-						sparse = 0;
-						break;
-					}
+				/* Is buffer sparse? */
+				sparse = BISZERO(outp, cnt);
 			}
 			if (sparse && !force) {
 				pending += cnt;

Modified: head/bin/dd/dd.h
==============================================================================
--- head/bin/dd/dd.h	Thu Nov 29 19:13:10 2018	(r341256)
+++ head/bin/dd/dd.h	Thu Nov 29 19:28:01 2018	(r341257)
@@ -103,3 +103,7 @@ typedef struct {
 #define	C_PROGRESS	0x40000000
 
 #define	C_PARITY	(C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
+
+#define	BISZERO(p, s)	((s) > 0 && *((const char *)p) == 0 && !memcmp( \
+			    (const void *)(p), (const void *) \
+			    ((const char *)p + 1), (s) - 1))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811291928.wATJS1mP021888>