public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] Add random memcpy test
@ 2017-02-09 19:30 Wilco Dijkstra
  2017-02-09 22:43 ` H.J. Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Wilco Dijkstra @ 2017-02-09 19:30 UTC (permalink / raw)
  To: libc-alpha; +Cc: nd

The 2nd version of this patch removes the made-up distribution and one based on a real 
trace instead:

Add a new randomized memcpy test for copies up to 256 bytes.  The distribution of size and
alignment is based on a trace of SPEC2006 (other traces could be added in the future).
Instead of repeating the same copy over and over again like the existing tests, it times several
thousand different copies to more accurately estimate the overhead of branch prediction due to
the different sizes and alignments.

ChangeLog:
2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>

	* benchtests/Makefile (string-benchset): Add memcpy-random.
	* benchtests/bench-memcpy-random.c: New file.


diff --git a/benchtests/Makefile b/benchtests/Makefile
index 81edf8a933ce7371ac60c118a4a46daee6391800..a96e9533b3b2d7223c2ce90a723b6a434ba1a1ea 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -37,7 +37,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
 		   strcat strchr strchrnul strcmp strcpy strcspn strlen \
 		   strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
 		   strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
-		   strcoll memcpy-large memmove-large memset-large
+		   strcoll memcpy-large memcpy-random memmove-large memset-large
 
 # Build and run locale-dependent benchmarks only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
new file mode 100644
index 0000000000000000000000000000000000000000..0e6955b292cde96d3100429e19138ba3d0114096
--- /dev/null
+++ b/benchtests/bench-memcpy-random.c
@@ -0,0 +1,157 @@
+/* Measure memcpy performance.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define MIN_PAGE_SIZE 131072
+#define TEST_MAIN
+#define TEST_NAME "memcpy-random"
+#include "bench-string.h"
+#include <assert.h>
+
+IMPL (memcpy, 0)
+
+#define NUM_COPIES 4096
+
+typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
+typedef struct { uint8_t align; uint8_t freq; } align_data_t;
+
+#define SIZE_NUM 1024
+#define SIZE_MASK (SIZE_NUM-1)
+static uint8_t size_arr[SIZE_NUM];
+
+/* Frequency data for memcpy of less than 256 bytes based on SPEC2006.  */
+static freq_data_t size_freq[] =
+{
+  {  8, 576}, {104,  94}, { 24,  78}, { 48,  58}, { 32,  48}, { 16,  46},
+  {  1,  30}, { 96,  12}, { 72,  11}, {216,  11}, {192,   8}, { 12,   7},
+  {144,   5}, {  2,   4}, { 64,   4}, {120,   4}, {  4,   3}, { 40,   2},
+  {  7,   2}, {168,   2}, {160,   2}, {128,   1}, {  3,   1}, {  9,   1},
+  {176,   1}, {240,   1}, { 11,   1}, {  0,   1}, {  5,   1}, {  6,   1},
+  { 80,   1}, { 52,   1}, {152,   1}, { 10,   1}, { 56,   1}, { 51,   1},
+  { 14,   1}, {208,   1}, {  0,   0}
+};
+
+#define ALIGN_NUM 256
+#define ALIGN_MASK (ALIGN_NUM-1)
+static uint8_t src_align_arr[ALIGN_NUM];
+static uint8_t dst_align_arr[ALIGN_NUM];
+
+/* Source alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t src_align_freq[] =
+{
+  {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0}
+};
+
+/* Destination alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t dst_align_freq[] =
+{
+  {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0}
+};
+
+typedef struct
+{
+  uint16_t src;
+  uint16_t dst;
+  uint16_t len;
+} copy_t;
+
+static copy_t copy[NUM_COPIES];
+
+typedef char *(*proto_t) (char *, const char *, size_t);
+
+static void
+init_copy_distribution (void)
+{
+  int i, j, freq, size, n;
+
+  for (n = i = 0; freq = size_freq[i].freq; i++)
+    for (j = 0, size = size_freq[i].size; j < freq; j++)
+      size_arr[n++] = size;
+  assert (n == SIZE_NUM);
+
+  for (n = i = 0; freq = src_align_freq[i].freq; i++)
+    for (j = 0, size = src_align_freq[i].align; j < freq; j++)
+      src_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+
+  for (n = i = 0; freq = dst_align_freq[i].freq; i++)
+    for (j = 0, size = dst_align_freq[i].align; j < freq; j++)
+      dst_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+}
+
+
+static void
+do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n)
+{
+  timing_t start, stop, cur;
+  size_t iters = INNER_LOOP_ITERS * 20;
+
+  TIMING_NOW (start);
+  for (int i = 0; i < iters; ++i)
+    for (int j = 0; j < n; j++)
+      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len);
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t max_size)
+{
+  for (int i = 0; i < max_size; i++)
+    buf1[i] = i * 3;
+
+  /* Create a random set of copies with the given size and alignment
+     distributions.  */
+  for (int i = 0; i < NUM_COPIES; i++)
+    {
+      copy[i].dst = (rand () & (max_size - 1)) | 1;
+      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
+      copy[i].src = (rand () & (max_size - 1)) | 3;
+      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
+      copy[i].len = size_arr[rand () & SIZE_MASK];
+    }
+
+  printf ("Memory size %6zd:", max_size);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  test_init ();
+  init_copy_distribution ();
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%s", impl->name);
+  putchar ('\n');
+
+  for (int i = 4; i <= 64; i = i * 2)
+    do_test (i * 1024);
+
+  return ret;
+}
+
+#include <support/test-driver.c>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2] Add random memcpy test
  2017-02-09 19:30 [PATCH v2] Add random memcpy test Wilco Dijkstra
@ 2017-02-09 22:43 ` H.J. Lu
  2017-02-10 18:21   ` [PATCH v3] " Wilco Dijkstra
  0 siblings, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2017-02-09 22:43 UTC (permalink / raw)
  To: Wilco Dijkstra; +Cc: libc-alpha, nd

On Thu, Feb 9, 2017 at 11:30 AM, Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> The 2nd version of this patch removes the made-up distribution and one based on a real
> trace instead:
>
> Add a new randomized memcpy test for copies up to 256 bytes.  The distribution of size and
> alignment is based on a trace of SPEC2006 (other traces could be added in the future).
> Instead of repeating the same copy over and over again like the existing tests, it times several
> thousand different copies to more accurately estimate the overhead of branch prediction due to
> the different sizes and alignments.
>
> ChangeLog:
> 2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>
>
>         * benchtests/Makefile (string-benchset): Add memcpy-random.
>         * benchtests/bench-memcpy-random.c: New file.
>
>
> diff --git a/benchtests/Makefile b/benchtests/Makefile
> index 81edf8a933ce7371ac60c118a4a46daee6391800..a96e9533b3b2d7223c2ce90a723b6a434ba1a1ea 100644
> --- a/benchtests/Makefile
> +++ b/benchtests/Makefile
> @@ -37,7 +37,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
>                    strcat strchr strchrnul strcmp strcpy strcspn strlen \
>                    strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
>                    strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
> -                  strcoll memcpy-large memmove-large memset-large
> +                  strcoll memcpy-large memcpy-random memmove-large memset-large
>
>  # Build and run locale-dependent benchmarks only if we're building natively.
>  ifeq (no,$(cross-compiling))
> diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..0e6955b292cde96d3100429e19138ba3d0114096
> --- /dev/null
> +++ b/benchtests/bench-memcpy-random.c
> @@ -0,0 +1,157 @@
> +/* Measure memcpy performance.
> +   Copyright (C) 2016-2017 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#define MIN_PAGE_SIZE 131072
> +#define TEST_MAIN
> +#define TEST_NAME "memcpy-random"
> +#include "bench-string.h"
> +#include <assert.h>
> +
> +IMPL (memcpy, 0)
> +
> +#define NUM_COPIES 4096
> +
> +typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
> +typedef struct { uint8_t align; uint8_t freq; } align_data_t;
> +
> +#define SIZE_NUM 1024
> +#define SIZE_MASK (SIZE_NUM-1)
> +static uint8_t size_arr[SIZE_NUM];
> +
> +/* Frequency data for memcpy of less than 256 bytes based on SPEC2006.  */
> +static freq_data_t size_freq[] =
> +{
> +  {  8, 576}, {104,  94}, { 24,  78}, { 48,  58}, { 32,  48}, { 16,  46},
> +  {  1,  30}, { 96,  12}, { 72,  11}, {216,  11}, {192,   8}, { 12,   7},
> +  {144,   5}, {  2,   4}, { 64,   4}, {120,   4}, {  4,   3}, { 40,   2},
> +  {  7,   2}, {168,   2}, {160,   2}, {128,   1}, {  3,   1}, {  9,   1},
> +  {176,   1}, {240,   1}, { 11,   1}, {  0,   1}, {  5,   1}, {  6,   1},
> +  { 80,   1}, { 52,   1}, {152,   1}, { 10,   1}, { 56,   1}, { 51,   1},
> +  { 14,   1}, {208,   1}, {  0,   0}
> +};
> +
> +#define ALIGN_NUM 256
> +#define ALIGN_MASK (ALIGN_NUM-1)
> +static uint8_t src_align_arr[ALIGN_NUM];
> +static uint8_t dst_align_arr[ALIGN_NUM];
> +
> +/* Source alignment frequency for memcpy based on SPEC2006.  */
> +static align_data_t src_align_freq[] =
> +{
> +  {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0}
> +};
> +
> +/* Destination alignment frequency for memcpy based on SPEC2006.  */
> +static align_data_t dst_align_freq[] =
> +{
> +  {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0}
> +};
> +
> +typedef struct
> +{
> +  uint16_t src;
> +  uint16_t dst;
> +  uint16_t len;
> +} copy_t;
> +
> +static copy_t copy[NUM_COPIES];
> +
> +typedef char *(*proto_t) (char *, const char *, size_t);
> +
> +static void
> +init_copy_distribution (void)
> +{
> +  int i, j, freq, size, n;
> +
> +  for (n = i = 0; freq = size_freq[i].freq; i++)
> +    for (j = 0, size = size_freq[i].size; j < freq; j++)
> +      size_arr[n++] = size;
> +  assert (n == SIZE_NUM);
> +
> +  for (n = i = 0; freq = src_align_freq[i].freq; i++)
> +    for (j = 0, size = src_align_freq[i].align; j < freq; j++)
> +      src_align_arr[n++] = size - 1;
> +  assert (n == ALIGN_NUM);
> +
> +  for (n = i = 0; freq = dst_align_freq[i].freq; i++)
> +    for (j = 0, size = dst_align_freq[i].align; j < freq; j++)
> +      dst_align_arr[n++] = size - 1;
> +  assert (n == ALIGN_NUM);
> +}
> +
> +
> +static void
> +do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n)
> +{
> +  timing_t start, stop, cur;
> +  size_t iters = INNER_LOOP_ITERS * 20;
> +
> +  TIMING_NOW (start);
> +  for (int i = 0; i < iters; ++i)
> +    for (int j = 0; j < n; j++)
> +      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len);
> +  TIMING_NOW (stop);
> +
> +  TIMING_DIFF (cur, start, stop);
> +
> +  TIMING_PRINT_MEAN ((double) cur, (double) iters);
> +}
> +
> +static void
> +do_test (size_t max_size)
> +{
> +  for (int i = 0; i < max_size; i++)
> +    buf1[i] = i * 3;
> +
> +  /* Create a random set of copies with the given size and alignment
> +     distributions.  */
> +  for (int i = 0; i < NUM_COPIES; i++)
> +    {
> +      copy[i].dst = (rand () & (max_size - 1)) | 1;
> +      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
> +      copy[i].src = (rand () & (max_size - 1)) | 3;
> +      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
> +      copy[i].len = size_arr[rand () & SIZE_MASK];
> +    }
> +
> +  printf ("Memory size %6zd:", max_size);
> +
> +  FOR_EACH_IMPL (impl, 0)
> +    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES);
> +
> +  putchar ('\n');
> +}
> +
> +int
> +test_main (void)
> +{
> +  test_init ();
> +  init_copy_distribution ();
> +
> +  printf ("%23s", "");
> +  FOR_EACH_IMPL (impl, 0)
> +    printf ("\t%s", impl->name);
> +  putchar ('\n');
> +
> +  for (int i = 4; i <= 64; i = i * 2)
> +    do_test (i * 1024);
> +
> +  return ret;
> +}
> +
> +#include <support/test-driver.c>
>

I like it.  But with GCC 6, I got

bench-memcpy-random.c: In function ‘init_copy_distribution’:
bench-memcpy-random.c:81:3: error: suggest parentheses around
assignment used as truth value [-Werror=parentheses]
   for (n = i = 0; freq = size_freq[i].freq; i++)
   ^~~
bench-memcpy-random.c:86:3: error: suggest parentheses around
assignment used as truth value [-Werror=parentheses]
   for (n = i = 0; freq = src_align_freq[i].freq; i++)
   ^~~
bench-memcpy-random.c:91:3: error: suggest parentheses around
assignment used as truth value [-Werror=parentheses]
   for (n = i = 0; freq = dst_align_freq[i].freq; i++)
   ^~~
cc1: all warnings being treated as errors


-- 
H.J.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-02-09 22:43 ` H.J. Lu
@ 2017-02-10 18:21   ` Wilco Dijkstra
  2017-02-17 13:12     ` Wilco Dijkstra
  0 siblings, 1 reply; 14+ messages in thread
From: Wilco Dijkstra @ 2017-02-10 18:21 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha, nd

H.J. Lu wrote:
>
> I like it.  But with GCC 6, I got
>
> bench-memcpy-random.c: In function ‘init_copy_distribution’:
> bench-memcpy-random.c:81:3: error: suggest parentheses around
> assignment used as truth value [-Werror=parentheses]
>    for (n = i = 0; freq = size_freq[i].freq; i++)

I see, I've added those so it now builds with -Werror:

---

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 81edf8a933ce7371ac60c118a4a46daee6391800..a96e9533b3b2d7223c2ce90a723b6a434ba1a1ea 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -37,7 +37,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
 		   strcat strchr strchrnul strcmp strcpy strcspn strlen \
 		   strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
 		   strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
-		   strcoll memcpy-large memmove-large memset-large
+		   strcoll memcpy-large memcpy-random memmove-large memset-large
 
 # Build and run locale-dependent benchmarks only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
new file mode 100644
index 0000000000000000000000000000000000000000..4cd620966d4e2b6790830ab005074c2b19ab922c
--- /dev/null
+++ b/benchtests/bench-memcpy-random.c
@@ -0,0 +1,157 @@
+/* Measure memcpy performance.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define MIN_PAGE_SIZE 131072
+#define TEST_MAIN
+#define TEST_NAME "memcpy-random"
+#include "bench-string.h"
+#include <assert.h>
+
+IMPL (memcpy, 0)
+
+#define NUM_COPIES 4096
+
+typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
+typedef struct { uint8_t align; uint8_t freq; } align_data_t;
+
+#define SIZE_NUM 1024
+#define SIZE_MASK (SIZE_NUM-1)
+static uint8_t size_arr[SIZE_NUM];
+
+/* Frequency data for memcpy of less than 256 bytes based on SPEC2006.  */
+static freq_data_t size_freq[] =
+{
+  {  8, 576}, {104,  94}, { 24,  78}, { 48,  58}, { 32,  48}, { 16,  46},
+  {  1,  30}, { 96,  12}, { 72,  11}, {216,  11}, {192,   8}, { 12,   7},
+  {144,   5}, {  2,   4}, { 64,   4}, {120,   4}, {  4,   3}, { 40,   2},
+  {  7,   2}, {168,   2}, {160,   2}, {128,   1}, {  3,   1}, {  9,   1},
+  {176,   1}, {240,   1}, { 11,   1}, {  0,   1}, {  5,   1}, {  6,   1},
+  { 80,   1}, { 52,   1}, {152,   1}, { 10,   1}, { 56,   1}, { 51,   1},
+  { 14,   1}, {208,   1}, {  0,   0}
+};
+
+#define ALIGN_NUM 256
+#define ALIGN_MASK (ALIGN_NUM-1)
+static uint8_t src_align_arr[ALIGN_NUM];
+static uint8_t dst_align_arr[ALIGN_NUM];
+
+/* Source alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t src_align_freq[] =
+{
+  {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0}
+};
+
+/* Destination alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t dst_align_freq[] =
+{
+  {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0}
+};
+
+typedef struct
+{
+  uint16_t src;
+  uint16_t dst;
+  uint16_t len;
+} copy_t;
+
+static copy_t copy[NUM_COPIES];
+
+typedef char *(*proto_t) (char *, const char *, size_t);
+
+static void
+init_copy_distribution (void)
+{
+  int i, j, freq, size, n;
+
+  for (n = i = 0; (freq = size_freq[i].freq) != 0; i++)
+    for (j = 0, size = size_freq[i].size; j < freq; j++)
+      size_arr[n++] = size;
+  assert (n == SIZE_NUM);
+
+  for (n = i = 0; (freq = src_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = src_align_freq[i].align; j < freq; j++)
+      src_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+
+  for (n = i = 0; (freq = dst_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = dst_align_freq[i].align; j < freq; j++)
+      dst_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+}
+
+
+static void
+do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n)
+{
+  timing_t start, stop, cur;
+  size_t iters = INNER_LOOP_ITERS * 20;
+
+  TIMING_NOW (start);
+  for (int i = 0; i < iters; ++i)
+    for (int j = 0; j < n; j++)
+      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len);
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t max_size)
+{
+  for (int i = 0; i < max_size; i++)
+    buf1[i] = i * 3;
+
+  /* Create a random set of copies with the given size and alignment
+     distributions.  */
+  for (int i = 0; i < NUM_COPIES; i++)
+    {
+      copy[i].dst = (rand () & (max_size - 1)) | 1;
+      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
+      copy[i].src = (rand () & (max_size - 1)) | 3;
+      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
+      copy[i].len = size_arr[rand () & SIZE_MASK];
+    }
+
+  printf ("Memory size %6zd:", max_size);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  test_init ();
+  init_copy_distribution ();
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%s", impl->name);
+  putchar ('\n');
+
+  for (int i = 4; i <= 64; i = i * 2)
+    do_test (i * 1024);
+
+  return ret;
+}
+
+#include <support/test-driver.c>
    

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-02-10 18:21   ` [PATCH v3] " Wilco Dijkstra
@ 2017-02-17 13:12     ` Wilco Dijkstra
  2017-03-07 15:28       ` Wilco Dijkstra
  0 siblings, 1 reply; 14+ messages in thread
From: Wilco Dijkstra @ 2017-02-17 13:12 UTC (permalink / raw)
  To: libc-alpha; +Cc: nd


ping

The 2nd version of this patch removes the made-up distribution and one based on a real
trace instead:

Add a new randomized memcpy test for copies up to 256 bytes.  The distribution of size and
alignment is based on a trace of SPEC2006 (other traces could be added in the future).
Instead of repeating the same copy over and over again like the existing tests, it times several
thousand different copies to more accurately estimate the overhead of branch prediction due to
the different sizes and alignments.

ChangeLog:
2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>

        * benchtests/Makefile (string-benchset): Add memcpy-random.
        * benchtests/bench-memcpy-random.c: New file.


---

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 81edf8a933ce7371ac60c118a4a46daee6391800..a96e9533b3b2d7223c2ce90a723b6a434ba1a1ea 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -37,7 +37,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
                    strcat strchr strchrnul strcmp strcpy strcspn strlen \
                    strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
                    strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
-                  strcoll memcpy-large memmove-large memset-large
+                  strcoll memcpy-large memcpy-random memmove-large memset-large
 
 # Build and run locale-dependent benchmarks only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
new file mode 100644
index 0000000000000000000000000000000000000000..4cd620966d4e2b6790830ab005074c2b19ab922c
--- /dev/null
+++ b/benchtests/bench-memcpy-random.c
@@ -0,0 +1,157 @@
+/* Measure memcpy performance.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define MIN_PAGE_SIZE 131072
+#define TEST_MAIN
+#define TEST_NAME "memcpy-random"
+#include "bench-string.h"
+#include <assert.h>
+
+IMPL (memcpy, 0)
+
+#define NUM_COPIES 4096
+
+typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
+typedef struct { uint8_t align; uint8_t freq; } align_data_t;
+
+#define SIZE_NUM 1024
+#define SIZE_MASK (SIZE_NUM-1)
+static uint8_t size_arr[SIZE_NUM];
+
+/* Frequency data for memcpy of less than 256 bytes based on SPEC2006.  */
+static freq_data_t size_freq[] =
+{
+  {  8, 576}, {104,  94}, { 24,  78}, { 48,  58}, { 32,  48}, { 16,  46},
+  {  1,  30}, { 96,  12}, { 72,  11}, {216,  11}, {192,   8}, { 12,   7},
+  {144,   5}, {  2,   4}, { 64,   4}, {120,   4}, {  4,   3}, { 40,   2},
+  {  7,   2}, {168,   2}, {160,   2}, {128,   1}, {  3,   1}, {  9,   1},
+  {176,   1}, {240,   1}, { 11,   1}, {  0,   1}, {  5,   1}, {  6,   1},
+  { 80,   1}, { 52,   1}, {152,   1}, { 10,   1}, { 56,   1}, { 51,   1},
+  { 14,   1}, {208,   1}, {  0,   0}
+};
+
+#define ALIGN_NUM 256
+#define ALIGN_MASK (ALIGN_NUM-1)
+static uint8_t src_align_arr[ALIGN_NUM];
+static uint8_t dst_align_arr[ALIGN_NUM];
+
+/* Source alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t src_align_freq[] =
+{
+  {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0}
+};
+
+/* Destination alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t dst_align_freq[] =
+{
+  {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0}
+};
+
+typedef struct
+{
+  uint16_t src;
+  uint16_t dst;
+  uint16_t len;
+} copy_t;
+
+static copy_t copy[NUM_COPIES];
+
+typedef char *(*proto_t) (char *, const char *, size_t);
+
+static void
+init_copy_distribution (void)
+{
+  int i, j, freq, size, n;
+
+  for (n = i = 0; (freq = size_freq[i].freq) != 0; i++)
+    for (j = 0, size = size_freq[i].size; j < freq; j++)
+      size_arr[n++] = size;
+  assert (n == SIZE_NUM);
+
+  for (n = i = 0; (freq = src_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = src_align_freq[i].align; j < freq; j++)
+      src_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+
+  for (n = i = 0; (freq = dst_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = dst_align_freq[i].align; j < freq; j++)
+      dst_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+}
+
+
+static void
+do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n)
+{
+  timing_t start, stop, cur;
+  size_t iters = INNER_LOOP_ITERS * 20;
+
+  TIMING_NOW (start);
+  for (int i = 0; i < iters; ++i)
+    for (int j = 0; j < n; j++)
+      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len);
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t max_size)
+{
+  for (int i = 0; i < max_size; i++)
+    buf1[i] = i * 3;
+
+  /* Create a random set of copies with the given size and alignment
+     distributions.  */
+  for (int i = 0; i < NUM_COPIES; i++)
+    {
+      copy[i].dst = (rand () & (max_size - 1)) | 1;
+      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
+      copy[i].src = (rand () & (max_size - 1)) | 3;
+      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
+      copy[i].len = size_arr[rand () & SIZE_MASK];
+    }
+
+  printf ("Memory size %6zd:", max_size);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  test_init ();
+  init_copy_distribution ();
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%s", impl->name);
+  putchar ('\n');
+
+  for (int i = 4; i <= 64; i = i * 2)
+    do_test (i * 1024);
+
+  return ret;
+}
+
+#include <support/test-driver.c>
        

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-02-17 13:12     ` Wilco Dijkstra
@ 2017-03-07 15:28       ` Wilco Dijkstra
  2017-03-23 11:15         ` Wilco Dijkstra
  0 siblings, 1 reply; 14+ messages in thread
From: Wilco Dijkstra @ 2017-03-07 15:28 UTC (permalink / raw)
  To: libc-alpha; +Cc: nd

    

ping

The 2nd version of this patch removes the made-up distribution and one based on a real
trace instead:

Add a new randomized memcpy test for copies up to 256 bytes.  The distribution of size and
alignment is based on a trace of SPEC2006 (other traces could be added in the future).
Instead of repeating the same copy over and over again like the existing tests, it times several
thousand different copies to more accurately estimate the overhead of branch prediction due to
the different sizes and alignments.

ChangeLog:
2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>

        * benchtests/Makefile (string-benchset): Add memcpy-random.
        * benchtests/bench-memcpy-random.c: New file.


---

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 81edf8a933ce7371ac60c118a4a46daee6391800..a96e9533b3b2d7223c2ce90a723b6a434ba1a1ea 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -37,7 +37,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
                    strcat strchr strchrnul strcmp strcpy strcspn strlen \
                    strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
                    strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
-                  strcoll memcpy-large memmove-large memset-large
+                  strcoll memcpy-large memcpy-random memmove-large memset-large
 
 # Build and run locale-dependent benchmarks only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
new file mode 100644
index 0000000000000000000000000000000000000000..4cd620966d4e2b6790830ab005074c2b19ab922c
--- /dev/null
+++ b/benchtests/bench-memcpy-random.c
@@ -0,0 +1,157 @@
+/* Measure memcpy performance.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define MIN_PAGE_SIZE 131072
+#define TEST_MAIN
+#define TEST_NAME "memcpy-random"
+#include "bench-string.h"
+#include <assert.h>
+
+IMPL (memcpy, 0)
+
+#define NUM_COPIES 4096
+
+typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
+typedef struct { uint8_t align; uint8_t freq; } align_data_t;
+
+#define SIZE_NUM 1024
+#define SIZE_MASK (SIZE_NUM-1)
+static uint8_t size_arr[SIZE_NUM];
+
+/* Frequency data for memcpy of less than 256 bytes based on SPEC2006.  */
+static freq_data_t size_freq[] =
+{
+  {  8, 576}, {104,  94}, { 24,  78}, { 48,  58}, { 32,  48}, { 16,  46},
+  {  1,  30}, { 96,  12}, { 72,  11}, {216,  11}, {192,   8}, { 12,   7},
+  {144,   5}, {  2,   4}, { 64,   4}, {120,   4}, {  4,   3}, { 40,   2},
+  {  7,   2}, {168,   2}, {160,   2}, {128,   1}, {  3,   1}, {  9,   1},
+  {176,   1}, {240,   1}, { 11,   1}, {  0,   1}, {  5,   1}, {  6,   1},
+  { 80,   1}, { 52,   1}, {152,   1}, { 10,   1}, { 56,   1}, { 51,   1},
+  { 14,   1}, {208,   1}, {  0,   0}
+};
+
+#define ALIGN_NUM 256
+#define ALIGN_MASK (ALIGN_NUM-1)
+static uint8_t src_align_arr[ALIGN_NUM];
+static uint8_t dst_align_arr[ALIGN_NUM];
+
+/* Source alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t src_align_freq[] =
+{
+  {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0}
+};
+
+/* Destination alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t dst_align_freq[] =
+{
+  {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0}
+};
+
+typedef struct
+{
+  uint16_t src;
+  uint16_t dst;
+  uint16_t len;
+} copy_t;
+
+static copy_t copy[NUM_COPIES];
+
+typedef char *(*proto_t) (char *, const char *, size_t);
+
+static void
+init_copy_distribution (void)
+{
+  int i, j, freq, size, n;
+
+  for (n = i = 0; (freq = size_freq[i].freq) != 0; i++)
+    for (j = 0, size = size_freq[i].size; j < freq; j++)
+      size_arr[n++] = size;
+  assert (n == SIZE_NUM);
+
+  for (n = i = 0; (freq = src_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = src_align_freq[i].align; j < freq; j++)
+      src_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+
+  for (n = i = 0; (freq = dst_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = dst_align_freq[i].align; j < freq; j++)
+      dst_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+}
+
+
+static void
+do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n)
+{
+  timing_t start, stop, cur;
+  size_t iters = INNER_LOOP_ITERS * 20;
+
+  TIMING_NOW (start);
+  for (int i = 0; i < iters; ++i)
+    for (int j = 0; j < n; j++)
+      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len);
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t max_size)
+{
+  for (int i = 0; i < max_size; i++)
+    buf1[i] = i * 3;
+
+  /* Create a random set of copies with the given size and alignment
+     distributions.  */
+  for (int i = 0; i < NUM_COPIES; i++)
+    {
+      copy[i].dst = (rand () & (max_size - 1)) | 1;
+      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
+      copy[i].src = (rand () & (max_size - 1)) | 3;
+      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
+      copy[i].len = size_arr[rand () & SIZE_MASK];
+    }
+
+  printf ("Memory size %6zd:", max_size);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  test_init ();
+  init_copy_distribution ();
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%s", impl->name);
+  putchar ('\n');
+
+  for (int i = 4; i <= 64; i = i * 2)
+    do_test (i * 1024);
+
+  return ret;
+}
+
+#include <support/test-driver.c>
            

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-07 15:28       ` Wilco Dijkstra
@ 2017-03-23 11:15         ` Wilco Dijkstra
  2017-03-23 14:24           ` Siddhesh Poyarekar
  0 siblings, 1 reply; 14+ messages in thread
From: Wilco Dijkstra @ 2017-03-23 11:15 UTC (permalink / raw)
  To: libc-alpha; +Cc: nd


ping

The 2nd version of this patch removes the made-up distribution and one based on a real
trace instead:

Add a new randomized memcpy test for copies up to 256 bytes.  The distribution of size and
alignment is based on a trace of SPEC2006 (other traces could be added in the future).
Instead of repeating the same copy over and over again like the existing tests, it times several
thousand different copies to more accurately estimate the overhead of branch prediction due to
the different sizes and alignments.

ChangeLog:
2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>

        * benchtests/Makefile (string-benchset): Add memcpy-random.
        * benchtests/bench-memcpy-random.c: New file.


---

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 81edf8a933ce7371ac60c118a4a46daee6391800..a96e9533b3b2d7223c2ce90a723b6a434ba1a1ea 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -37,7 +37,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
                    strcat strchr strchrnul strcmp strcpy strcspn strlen \
                    strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
                    strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
-                  strcoll memcpy-large memmove-large memset-large
+                  strcoll memcpy-large memcpy-random memmove-large memset-large
 
 # Build and run locale-dependent benchmarks only if we're building natively.
 ifeq (no,$(cross-compiling))
diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
new file mode 100644
index 0000000000000000000000000000000000000000..4cd620966d4e2b6790830ab005074c2b19ab922c
--- /dev/null
+++ b/benchtests/bench-memcpy-random.c
@@ -0,0 +1,157 @@
+/* Measure memcpy performance.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define MIN_PAGE_SIZE 131072
+#define TEST_MAIN
+#define TEST_NAME "memcpy-random"
+#include "bench-string.h"
+#include <assert.h>
+
+IMPL (memcpy, 0)
+
+#define NUM_COPIES 4096
+
+typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
+typedef struct { uint8_t align; uint8_t freq; } align_data_t;
+
+#define SIZE_NUM 1024
+#define SIZE_MASK (SIZE_NUM-1)
+static uint8_t size_arr[SIZE_NUM];
+
+/* Frequency data for memcpy of less than 256 bytes based on SPEC2006.  */
+static freq_data_t size_freq[] =
+{
+  {  8, 576}, {104,  94}, { 24,  78}, { 48,  58}, { 32,  48}, { 16,  46},
+  {  1,  30}, { 96,  12}, { 72,  11}, {216,  11}, {192,   8}, { 12,   7},
+  {144,   5}, {  2,   4}, { 64,   4}, {120,   4}, {  4,   3}, { 40,   2},
+  {  7,   2}, {168,   2}, {160,   2}, {128,   1}, {  3,   1}, {  9,   1},
+  {176,   1}, {240,   1}, { 11,   1}, {  0,   1}, {  5,   1}, {  6,   1},
+  { 80,   1}, { 52,   1}, {152,   1}, { 10,   1}, { 56,   1}, { 51,   1},
+  { 14,   1}, {208,   1}, {  0,   0}
+};
+
+#define ALIGN_NUM 256
+#define ALIGN_MASK (ALIGN_NUM-1)
+static uint8_t src_align_arr[ALIGN_NUM];
+static uint8_t dst_align_arr[ALIGN_NUM];
+
+/* Source alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t src_align_freq[] =
+{
+  {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0}
+};
+
+/* Destination alignment frequency for memcpy based on SPEC2006.  */
+static align_data_t dst_align_freq[] =
+{
+  {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0}
+};
+
+typedef struct
+{
+  uint16_t src;
+  uint16_t dst;
+  uint16_t len;
+} copy_t;
+
+static copy_t copy[NUM_COPIES];
+
+typedef char *(*proto_t) (char *, const char *, size_t);
+
+static void
+init_copy_distribution (void)
+{
+  int i, j, freq, size, n;
+
+  for (n = i = 0; (freq = size_freq[i].freq) != 0; i++)
+    for (j = 0, size = size_freq[i].size; j < freq; j++)
+      size_arr[n++] = size;
+  assert (n == SIZE_NUM);
+
+  for (n = i = 0; (freq = src_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = src_align_freq[i].align; j < freq; j++)
+      src_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+
+  for (n = i = 0; (freq = dst_align_freq[i].freq) != 0; i++)
+    for (j = 0, size = dst_align_freq[i].align; j < freq; j++)
+      dst_align_arr[n++] = size - 1;
+  assert (n == ALIGN_NUM);
+}
+
+
+static void
+do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n)
+{
+  timing_t start, stop, cur;
+  size_t iters = INNER_LOOP_ITERS * 20;
+
+  TIMING_NOW (start);
+  for (int i = 0; i < iters; ++i)
+    for (int j = 0; j < n; j++)
+      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len);
+  TIMING_NOW (stop);
+
+  TIMING_DIFF (cur, start, stop);
+
+  TIMING_PRINT_MEAN ((double) cur, (double) iters);
+}
+
+static void
+do_test (size_t max_size)
+{
+  for (int i = 0; i < max_size; i++)
+    buf1[i] = i * 3;
+
+  /* Create a random set of copies with the given size and alignment
+     distributions.  */
+  for (int i = 0; i < NUM_COPIES; i++)
+    {
+      copy[i].dst = (rand () & (max_size - 1)) | 1;
+      copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
+      copy[i].src = (rand () & (max_size - 1)) | 3;
+      copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
+      copy[i].len = size_arr[rand () & SIZE_MASK];
+    }
+
+  printf ("Memory size %6zd:", max_size);
+
+  FOR_EACH_IMPL (impl, 0)
+    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES);
+
+  putchar ('\n');
+}
+
+int
+test_main (void)
+{
+  test_init ();
+  init_copy_distribution ();
+
+  printf ("%23s", "");
+  FOR_EACH_IMPL (impl, 0)
+    printf ("\t%s", impl->name);
+  putchar ('\n');
+
+  for (int i = 4; i <= 64; i = i * 2)
+    do_test (i * 1024);
+
+  return ret;
+}
+
+#include <support/test-driver.c>
                

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-23 11:15         ` Wilco Dijkstra
@ 2017-03-23 14:24           ` Siddhesh Poyarekar
  2017-03-24 21:49             ` Steve Ellcey
  0 siblings, 1 reply; 14+ messages in thread
From: Siddhesh Poyarekar @ 2017-03-23 14:24 UTC (permalink / raw)
  To: Wilco Dijkstra, libc-alpha; +Cc: nd

On Thursday 23 March 2017 04:45 PM, Wilco Dijkstra wrote:
> The 2nd version of this patch removes the made-up distribution and one based on a real
> trace instead:
> 
> Add a new randomized memcpy test for copies up to 256 bytes.  The distribution of size and
> alignment is based on a trace of SPEC2006 (other traces could be added in the future).
> Instead of repeating the same copy over and over again like the existing tests, it times several
> thousand different copies to more accurately estimate the overhead of branch prediction due to
> the different sizes and alignments.
> 
> ChangeLog:
> 2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>
> 
>         * benchtests/Makefile (string-benchset): Add memcpy-random.
>         * benchtests/bench-memcpy-random.c: New file.

Nice, this looks good to me.  There may be additional cache effects in
spec2006 that may make these results different from actual spec2006, but
it is still a valuable data point, definitely more than the repeated copies.

Siddhesh

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-23 14:24           ` Siddhesh Poyarekar
@ 2017-03-24 21:49             ` Steve Ellcey
  2017-03-24 22:14               ` Steve Ellcey
  0 siblings, 1 reply; 14+ messages in thread
From: Steve Ellcey @ 2017-03-24 21:49 UTC (permalink / raw)
  To: Siddhesh Poyarekar, Wilco Dijkstra, libc-alpha; +Cc: nd

On Thu, 2017-03-23 at 19:53 +0530, Siddhesh Poyarekar wrote:

> > 
> > ChangeLog:
> > 2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>
> > 
> >         * benchtests/Makefile (string-benchset): Add memcpy-random.
> >         * benchtests/bench-memcpy-random.c: New file.
> Nice, this looks good to me.  There may be additional cache effects in
> spec2006 that may make these results different from actual spec2006, but
> it is still a valuable data point, definitely more than the repeated
> copies.
> 
> Siddhesh

I think there is a Makefile problem in this patch.


make -C ../src/glibc/benchtests  objdir=`pwd` bench
make[1]: Entering directory '/home/ubuntu/sellcey/glibc-
ifunc/src/glibc/benchtests'
make[1]: *** No rule to make target '/home/ubuntu/sellcey/glibc-
ifunc/obj-glibc64/benchtests/bench-memcpy-random.o', needed by
'/home/ubuntu/sellcey/glibc-ifunc/obj-glibc64/benchtests/bench-memcpy-
random'.  Stop.
make[1]: Leaving directory '/home/ubuntu/sellcey/glibc-
ifunc/src/glibc/benchtests'
Makefile:16: recipe for target 'bench' failed
make: *** [bench] Error 2

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-24 21:49             ` Steve Ellcey
@ 2017-03-24 22:14               ` Steve Ellcey
  2017-03-25 19:24                 ` Wilco Dijkstra
  0 siblings, 1 reply; 14+ messages in thread
From: Steve Ellcey @ 2017-03-24 22:14 UTC (permalink / raw)
  To: Siddhesh Poyarekar, Wilco Dijkstra, libc-alpha; +Cc: nd

It looks like the Makefile change got pushed out but the
new benchtests/bench-memcpy-random.c file did not.

Steve Ellcey

On Fri, 2017-03-24 at 14:49 -0700, Steve Ellcey wrote:
> On Thu, 2017-03-23 at 19:53 +0530, Siddhesh Poyarekar wrote:
> 
> > > ChangeLog:
> > > 2017-02-09  Wilco Dijkstra  <wdijkstr@arm.com>
> > > 
> > >         * benchtests/Makefile (string-benchset): Add memcpy-
> > > random.
> > >         * benchtests/bench-memcpy-random.c: New file.
> > Nice, this looks good to me.  There may be additional cache effects in
> > spec2006 that may make these results different from actual spec2006, but
> > it is still a valuable data point, definitely more than the repeated
> > copies.
> > 
> > Siddhesh
> I think there is a Makefile problem in this patch.
> 
> 
> make -C ../src/glibc/benchtests  objdir=`pwd` bench
> make[1]: Entering directory '/home/ubuntu/sellcey/glibc-
> ifunc/src/glibc/benchtests'
> make[1]: *** No rule to make target '/home/ubuntu/sellcey/glibc-
> ifunc/obj-glibc64/benchtests/bench-memcpy-random.o', needed by
> '/home/ubuntu/sellcey/glibc-ifunc/obj-glibc64/benchtests/bench-
> memcpy-
> random'.  Stop.
> make[1]: Leaving directory '/home/ubuntu/sellcey/glibc-
> ifunc/src/glibc/benchtests'
> Makefile:16: recipe for target 'bench' failed
> make: *** [bench] Error 2

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-24 22:14               ` Steve Ellcey
@ 2017-03-25 19:24                 ` Wilco Dijkstra
  2017-03-26 12:42                   ` Siddhesh Poyarekar
  0 siblings, 1 reply; 14+ messages in thread
From: Wilco Dijkstra @ 2017-03-25 19:24 UTC (permalink / raw)
  To: Steve Ellcey, Siddhesh Poyarekar, libc-alpha; +Cc: nd, Szabolcs Nagy

Hi Steve,
    
> It looks like the Makefile change got pushed out but the
> new benchtests/bench-memcpy-random.c file did not.

Yes it seems I forgot to do a git add of the actual file... Sorry about that.

Since I'm on holiday with no access to my GLIBC tree, it's probably best
to revert the Makefile change for now and I'll redo it when I get back.

Cheers,
Wilco

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-25 19:24                 ` Wilco Dijkstra
@ 2017-03-26 12:42                   ` Siddhesh Poyarekar
  2017-03-27 19:58                     ` Steve Ellcey
  0 siblings, 1 reply; 14+ messages in thread
From: Siddhesh Poyarekar @ 2017-03-26 12:42 UTC (permalink / raw)
  To: Wilco Dijkstra, Steve Ellcey, libc-alpha; +Cc: nd, Szabolcs Nagy

On Sunday 26 March 2017 12:54 AM, Wilco Dijkstra wrote:
> Yes it seems I forgot to do a git add of the actual file... Sorry about that.
> 
> Since I'm on holiday with no access to my GLIBC tree, it's probably best
> to revert the Makefile change for now and I'll redo it when I get back.

Don't worry about it, I'll push the file.

Siddhesh

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-26 12:42                   ` Siddhesh Poyarekar
@ 2017-03-27 19:58                     ` Steve Ellcey
  2017-03-27 20:53                       ` Steve Ellcey
  0 siblings, 1 reply; 14+ messages in thread
From: Steve Ellcey @ 2017-03-27 19:58 UTC (permalink / raw)
  To: Siddhesh Poyarekar, Wilco Dijkstra, libc-alpha; +Cc: nd, Szabolcs Nagy

On Sun, 2017-03-26 at 18:12 +0530, Siddhesh Poyarekar wrote:
> On Sunday 26 March 2017 12:54 AM, Wilco Dijkstra wrote:
> > 
> > Yes it seems I forgot to do a git add of the actual file... Sorry
> > about that.
> > 
> > Since I'm on holiday with no access to my GLIBC tree, it's probably best
> > to revert the Makefile change for now and I'll redo it when I get back.

> Don't worry about it, I'll push the file.
> 
> Siddhesh

I see the bench-memcpy-random.c file now but I think there is still
something wrong.  I am using a glibc that has my aarch64 IFUNC version
of memcpy and memmove implemented in it but I do not get measurements
of the different implementations for the random memcpy test like I do
for the other two memcpy tests.

In bench-memcpy.out I have:

                       	builtin_memcpy	simple_memcpy	__memcpy_thunderx  __memcpy_generic
Length    1, alignment  0/ 0:	39.2188	19.375	22.03
12	23.5938
Length    1, alignment  0/ 0:	27.3438	16.25	22.187
5	22.1875
.
.


In bench-memcpy-large.out I have:

                       	__memcpy_thunderx	__memcpy_generi
c
Length 65543, alignment  0/ 0:	8937.5	17000
Length 65551, alignment  0/ 3:	27275.6	35756.9
.
.


In bench-memcpy-random.out I have:

                       	memcpy
Memory size   4096:	105751
Memory size   8192:	103559
Memory size  16384:	112045
Memory size  32768:	118391
Memory size  65536:	158526


I.e.  there are no seperate timings for the generic and thunderx
versions of memcpy like I have in bench-memcpy and bench-memcpy-large.
There is code in bench-memcpy-random.c to do the different
measurements, I see 'FOR_EACH_IMPL' but it doesn't seeem to be working.

Has anyone else seen this?

Steve Ellcey

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-27 19:58                     ` Steve Ellcey
@ 2017-03-27 20:53                       ` Steve Ellcey
  2017-03-28  9:39                         ` Siddhesh Poyarekar
  0 siblings, 1 reply; 14+ messages in thread
From: Steve Ellcey @ 2017-03-27 20:53 UTC (permalink / raw)
  To: Siddhesh Poyarekar, Wilco Dijkstra, libc-alpha; +Cc: nd, Szabolcs Nagy

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

On Mon, 2017-03-27 at 12:57 -0700, Steve Ellcey wrote:
> 
> I see the bench-memcpy-random.c file now but I think there is still
> something wrong.  I am using a glibc that has my aarch64 IFUNC version
> of memcpy and memmove implemented in it but I do not get measurements
> of the different implementations for the random memcpy test like I do
> for the other two memcpy tests.

Here is a patch so that bench-memcpy-random.c prints out timings for
all the IFUNC versions of memcpy.  The TEST_NAME change is clear,
TEST_NAME isn't really the name of the test but the name of the routine
being tested.  If you call it memcpy-random it looks for IFUNC versions
of the memcpy-random function instead of the memcpy function.  I also
changed the IMPL call to have 1 instead of 0 as the second argument.  I
don't really understand this change, but it is what the other two
memcpy tests do so I copied them and it seems to work.  Tested on x86
and aarch64.

Steve Ellcey
sellcey@cavium.com


2017-03-27  Steve Ellcey  <sellcey@caviumnetworks.com>

	* benchtests/bench-memcpy-random.c (TEST_NAME): Change to memcpy.
	(IMPL) Call with 1 instead of 0 as argument.

[-- Attachment #2: bench-memcpy-random.diff --]
[-- Type: text/x-patch, Size: 438 bytes --]

diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c
index 4cd6209..9ae925e 100644
--- a/benchtests/bench-memcpy-random.c
+++ b/benchtests/bench-memcpy-random.c
@@ -18,11 +18,11 @@
 
 #define MIN_PAGE_SIZE 131072
 #define TEST_MAIN
-#define TEST_NAME "memcpy-random"
+#define TEST_NAME "memcpy"
 #include "bench-string.h"
 #include <assert.h>
 
-IMPL (memcpy, 0)
+IMPL (memcpy, 1)
 
 #define NUM_COPIES 4096
 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] Add random memcpy test
  2017-03-27 20:53                       ` Steve Ellcey
@ 2017-03-28  9:39                         ` Siddhesh Poyarekar
  0 siblings, 0 replies; 14+ messages in thread
From: Siddhesh Poyarekar @ 2017-03-28  9:39 UTC (permalink / raw)
  To: Steve Ellcey, Wilco Dijkstra, libc-alpha; +Cc: nd, Szabolcs Nagy

On Tuesday 28 March 2017 02:23 AM, Steve Ellcey wrote:
> Here is a patch so that bench-memcpy-random.c prints out timings for
> all the IFUNC versions of memcpy.  The TEST_NAME change is clear,
> TEST_NAME isn't really the name of the test but the name of the routine
> being tested.  If you call it memcpy-random it looks for IFUNC versions
> of the memcpy-random function instead of the memcpy function.  I also
> changed the IMPL call to have 1 instead of 0 as the second argument.  I
> don't really understand this change, but it is what the other two
> memcpy tests do so I copied them and it seems to work.  Tested on x86
> and aarch64.
> 
> Steve Ellcey
> sellcey@cavium.com
> 
> 
> 2017-03-27  Steve Ellcey  <sellcey@caviumnetworks.com>
> 
> 	* benchtests/bench-memcpy-random.c (TEST_NAME): Change to memcpy.
> 	(IMPL) Call with 1 instead of 0 as argument.

The flag is to enable testing it.  This patch is OK.

Thanks,
Siddhesh

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-03-28  9:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-09 19:30 [PATCH v2] Add random memcpy test Wilco Dijkstra
2017-02-09 22:43 ` H.J. Lu
2017-02-10 18:21   ` [PATCH v3] " Wilco Dijkstra
2017-02-17 13:12     ` Wilco Dijkstra
2017-03-07 15:28       ` Wilco Dijkstra
2017-03-23 11:15         ` Wilco Dijkstra
2017-03-23 14:24           ` Siddhesh Poyarekar
2017-03-24 21:49             ` Steve Ellcey
2017-03-24 22:14               ` Steve Ellcey
2017-03-25 19:24                 ` Wilco Dijkstra
2017-03-26 12:42                   ` Siddhesh Poyarekar
2017-03-27 19:58                     ` Steve Ellcey
2017-03-27 20:53                       ` Steve Ellcey
2017-03-28  9:39                         ` Siddhesh Poyarekar

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).