about summary refs log tree commit diff
path: root/benchtests/bench-string.h
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2017-09-14 22:39:49 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2017-09-14 22:54:24 +0530
commit503c92c37a95f769762e65aff9383b302178c2bc (patch)
tree6374607403822c719c9e0719e549478b378557c0 /benchtests/bench-string.h
parent29c933fb35b7bf872f57dc6977c879832983ab6c (diff)
downloadglibc-503c92c37a95f769762e65aff9383b302178c2bc.tar.gz
glibc-503c92c37a95f769762e65aff9383b302178c2bc.tar.xz
glibc-503c92c37a95f769762e65aff9383b302178c2bc.zip
benchtests: Reallocate buffers for memset
Keeping the same buffers along with copying the same size of data into
the same location means that the first routine is typically the
slowest since it has to bear the cost of fetching data into to cache.
Reallocating buffers stabilizes numbers by a bit.

	* benchtests/bench-string.h (realloc_bufs): New function.
	(test_init): Call it.
	* benchtests/bench-memset-large.c (do_test): Likewise.
	* benchtests/bench-memset.c (do_test): Likewise.
Diffstat (limited to 'benchtests/bench-string.h')
-rw-r--r--benchtests/bench-string.h50
1 files changed, 39 insertions, 11 deletions
diff --git a/benchtests/bench-string.h b/benchtests/bench-string.h
index 3aacfdf83e..40c735c18e 100644
--- a/benchtests/bench-string.h
+++ b/benchtests/bench-string.h
@@ -173,14 +173,8 @@ static impl_t *impl_array;
 # endif
 
 static void
-test_init (void)
+alloc_bufs (void)
 {
-# ifdef TEST_NAME
-  func_count = __libc_ifunc_impl_list (TEST_NAME, func_list,
-				       (sizeof func_list
-					/ sizeof func_list[0]));
-# endif
-
   page_size = 2 * getpagesize ();
 # ifdef MIN_PAGE_SIZE
   if (page_size < MIN_PAGE_SIZE)
@@ -189,15 +183,49 @@ test_init (void)
   buf1 = mmap (0, (BUF1PAGES + 1) * page_size, PROT_READ | PROT_WRITE,
 	       MAP_PRIVATE | MAP_ANON, -1, 0);
   if (buf1 == MAP_FAILED)
-    error (EXIT_FAILURE, errno, "mmap failed");
+    error (EXIT_FAILURE, errno, "mmap failed for buf1");
   if (mprotect (buf1 + BUF1PAGES * page_size, page_size, PROT_NONE))
-    error (EXIT_FAILURE, errno, "mprotect failed");
+    error (EXIT_FAILURE, errno, "mprotect failed for buf1");
   buf2 = mmap (0, 2 * page_size, PROT_READ | PROT_WRITE,
 	       MAP_PRIVATE | MAP_ANON, -1, 0);
   if (buf2 == MAP_FAILED)
-    error (EXIT_FAILURE, errno, "mmap failed");
+    error (EXIT_FAILURE, errno, "mmap failed for buf2");
   if (mprotect (buf2 + page_size, page_size, PROT_NONE))
-    error (EXIT_FAILURE, errno, "mprotect failed");
+    error (EXIT_FAILURE, errno, "mprotect failed for buf2");
+}
+
+static void
+__attribute__ ((unused))
+realloc_bufs (void)
+{
+  int ret = 0;
+
+  if (buf1)
+    ret = munmap (buf1, (BUF1PAGES + 1) * page_size);
+
+  if (ret != 0)
+    error (EXIT_FAILURE, errno, "munmap failed for buf1");
+
+  if (buf2)
+    ret = munmap (buf2, 2 * page_size);
+
+  if (ret != 0)
+    error (EXIT_FAILURE, errno, "munmap failed for buf2");
+
+  alloc_bufs ();
+}
+
+static void
+test_init (void)
+{
+# ifdef TEST_NAME
+  func_count = __libc_ifunc_impl_list (TEST_NAME, func_list,
+				       (sizeof func_list
+					/ sizeof func_list[0]));
+# endif
+
+  alloc_bufs ();
+
   if (do_srandom)
     {
       printf ("Setting seed to 0x%x\n", seed);