public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Fangrui Song <maskray@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/maskray/clang] benchtests: Improve bench-memcpy-random
Date: Tue,  2 Nov 2021 19:59:42 +0000 (GMT)	[thread overview]
Message-ID: <20211102195942.93B9C3858007@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f392915d1e9aa74a3255ab5afc091a86373aa3d2

commit f392915d1e9aa74a3255ab5afc091a86373aa3d2
Author: Wilco Dijkstra <wdijkstr@arm.com>
Date:   Fri Oct 29 15:41:18 2021 +0100

    benchtests: Improve bench-memcpy-random
    
    Improve the random memcpy benchmark. Double the number of tests and increase
    the size of the memory region to test between 32KB and 1024KB. This improves
    accuracy on modern cores. Clean up formatting of the frequency array.
    
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

Diff:
---
 benchtests/bench-memcpy-random.c | 54 +++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
index c490b73ed0..b2edd8b7e3 100644
--- a/benchtests/bench-memcpy-random.c
+++ b/benchtests/bench-memcpy-random.c
@@ -16,15 +16,17 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#define MIN_PAGE_SIZE (512*1024+getpagesize())
+#define MIN_SIZE 32768
+#define MAX_SIZE (1024*1024)
+#define NUM_TESTS 16384
+
+#define MIN_PAGE_SIZE (MAX_SIZE + getpagesize())
 #define TEST_MAIN
 #define TEST_NAME "memcpy"
 #include "bench-string.h"
 #include <assert.h>
 #include "json-lib.h"
 
-#define MAX_COPIES 8192
-
 IMPL (memcpy, 1)
 
 typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
@@ -37,36 +39,36 @@ static uint8_t size_arr[SIZE_NUM];
 /* Frequency data for memcpy of less than 4096 bytes based on SPEC2017.  */
 static freq_data_t size_freq[] =
 {
-{ 32, 22320}, { 16, 9554}, {  8, 8915}, {152, 5327}, {  4, 2159}, {292, 2035},
-{ 12, 1608}, { 24, 1343}, {1152, 895}, {144, 813}, {884, 733}, {284, 721},
+{32,22320}, { 16,9554}, {  8,8915}, {152,5327}, {  4,2159}, {292,2035},
+{ 12,1608}, { 24,1343}, {1152,895}, {144, 813}, {884, 733}, {284, 721},
 {120, 661}, {  2, 649}, {882, 550}, {  5, 475}, {  7, 461}, {108, 460},
-{ 10, 361}, {  9, 361}, {  6, 334}, {  3, 326}, {464, 308}, {2048, 303},
+{ 10, 361}, {  9, 361}, {  6, 334}, {  3, 326}, {464, 308}, {2048,303},
 {  1, 298}, { 64, 250}, { 11, 197}, {296, 194}, { 68, 187}, { 15, 185},
-{192, 184}, {1764, 183}, { 13, 173}, {560, 126}, {160, 115}, {288,  96},
-{104,  96}, {1144,  83}, { 18,  80}, { 23,  78}, { 40,  77}, { 19,  68},
-{ 48,  63}, { 17,  57}, { 72,  54}, {1280,  51}, { 20,  49}, { 28,  47},
+{192, 184}, {1764,183}, { 13, 173}, {560, 126}, {160, 115}, {288,  96},
+{104,  96}, {1144, 83}, { 18,  80}, { 23,  78}, { 40,  77}, { 19,  68},
+{ 48,  63}, { 17,  57}, { 72,  54}, {1280, 51}, { 20,  49}, { 28,  47},
 { 22,  46}, {640,  45}, { 25,  41}, { 14,  40}, { 56,  37}, { 27,  35},
-{ 35,  33}, {384,  33}, { 29,  32}, { 80,  30}, {4095,  22}, {232,  22},
+{ 35,  33}, {384,  33}, { 29,  32}, { 80,  30}, {4095, 22}, {232,  22},
 { 36,  19}, {184,  17}, { 21,  17}, {256,  16}, { 44,  15}, { 26,  15},
-{ 31,  14}, { 88,  14}, {176,  13}, { 33,  12}, {1024,  12}, {208,  11},
+{ 31,  14}, { 88,  14}, {176,  13}, { 33,  12}, {1024, 12}, {208,  11},
 { 62,  11}, {128,  10}, {704,  10}, {324,  10}, { 96,  10}, { 60,   9},
-{136,   9}, {124,   9}, { 34,   8}, { 30,   8}, {480,   8}, {1344,   8},
+{136,   9}, {124,   9}, { 34,   8}, { 30,   8}, {480,   8}, {1344,  8},
 {273,   7}, {520,   7}, {112,   6}, { 52,   6}, {344,   6}, {336,   6},
 {504,   5}, {168,   5}, {424,   5}, {  0,   4}, { 76,   3}, {200,   3},
 {512,   3}, {312,   3}, {240,   3}, {960,   3}, {264,   2}, {672,   2},
 { 38,   2}, {328,   2}, { 84,   2}, { 39,   2}, {216,   2}, { 42,   2},
-{ 37,   2}, {1608,   2}, { 70,   2}, { 46,   2}, {536,   2}, {280,   1},
-{248,   1}, { 47,   1}, {1088,   1}, {1288,   1}, {224,   1}, { 41,   1},
+{ 37,   2}, {1608,  2}, { 70,   2}, { 46,   2}, {536,   2}, {280,   1},
+{248,   1}, { 47,   1}, {1088,  1}, {1288,  1}, {224,   1}, { 41,   1},
 { 50,   1}, { 49,   1}, {808,   1}, {360,   1}, {440,   1}, { 43,   1},
 { 45,   1}, { 78,   1}, {968,   1}, {392,   1}, { 54,   1}, { 53,   1},
 { 59,   1}, {376,   1}, {664,   1}, { 58,   1}, {272,   1}, { 66,   1},
-{2688,   1}, {472,   1}, {568,   1}, {720,   1}, { 51,   1}, { 63,   1},
+{2688,  1}, {472,   1}, {568,   1}, {720,   1}, { 51,   1}, { 63,   1},
 { 86,   1}, {496,   1}, {776,   1}, { 57,   1}, {680,   1}, {792,   1},
 {122,   1}, {760,   1}, {824,   1}, {552,   1}, { 67,   1}, {456,   1},
 {984,   1}, { 74,   1}, {408,   1}, { 75,   1}, { 92,   1}, {576,   1},
 {116,   1}, { 65,   1}, {117,   1}, { 82,   1}, {352,   1}, { 55,   1},
 {100,   1}, { 90,   1}, {696,   1}, {111,   1}, {880,   1}, { 79,   1},
-{488,   1}, { 61,   1}, {114,   1}, { 94,   1}, {1032,   1}, { 98,   1},
+{488,   1}, { 61,   1}, {114,   1}, { 94,   1}, {1032,  1}, { 98,   1},
 { 87,   1}, {584,   1}, { 85,   1}, {648,   1}, {0, 0}
 };
 
@@ -94,7 +96,7 @@ typedef struct
   uint64_t len : 16;
 } copy_t;
 
-static copy_t copy[MAX_COPIES];
+static copy_t test_arr[NUM_TESTS];
 
 typedef char *(*proto_t) (char *, const char *, size_t);
 
@@ -150,13 +152,13 @@ do_test (json_ctx_t *json_ctx, size_t max_size)
 
   /* Create a random set of copies with the given size and alignment
      distributions.  */
-  for (i = 0; i < MAX_COPIES; i++)
+  for (i = 0; i < NUM_TESTS; i++)
     {
-      copy[i].dst = (rand () & (max_size - 1));
-      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
-      copy[i].src = (rand () & (max_size - 1));
-      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
-      copy[i].len = size_arr[rand () & SIZE_MASK];
+      test_arr[i].dst = (rand () & (max_size - 1));
+      test_arr[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
+      test_arr[i].src = (rand () & (max_size - 1));
+      test_arr[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
+      test_arr[i].len = size_arr[rand () & SIZE_MASK];
     }
 
   json_element_object_begin (json_ctx);
@@ -164,7 +166,7 @@ do_test (json_ctx_t *json_ctx, size_t max_size)
   json_array_begin (json_ctx, "timings");
 
   FOR_EACH_IMPL (impl, 0)
-    do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, i);
+    do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, test_arr, i);
 
   json_array_end (json_ctx);
   json_element_object_end (json_ctx);
@@ -193,8 +195,8 @@ test_main (void)
   json_array_end (&json_ctx);
 
   json_array_begin (&json_ctx, "results");
-  for (int i = 4; i <= 512; i = i * 2)
-    do_test (&json_ctx, i * 1024);
+  for (int i = MIN_SIZE; i <= MAX_SIZE; i = i * 2)
+    do_test (&json_ctx, i);
 
   json_array_end (&json_ctx);
   json_attr_object_end (&json_ctx);


                 reply	other threads:[~2021-11-02 19:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211102195942.93B9C3858007@sourceware.org \
    --to=maskray@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).