From: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH 4/5] benchtests: Add additional cases to bench-memcpy.c and bench-memmove.c
Date: Tue, 24 Aug 2021 08:19:09 -0700 [thread overview]
Message-ID: <CAMe9rOrWWY8+uCYTZMTGL8TMGjxtCbUNJoLKkq6pW1CTCwfNGw@mail.gmail.com> (raw)
In-Reply-To: <20210824082753.3356637-4-goldstein.w.n@gmail.com>
On Tue, Aug 24, 2021 at 1:28 AM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> This commit adds more benchmarks for the common memcpy/memmove
> benchmarks. The most signifcant cases are the half page offsets. The
> current versions leaves dst and src near page aligned which leads to
> false 4k aliasing on x86_64. This can add noise due to false
> dependencies from one run to the next. As well, this seems like more
> of an edge case that common case so it shouldn't be the only thing
> benchmarked.
> ---
> benchtests/bench-memcpy.c | 42 ++++++++++++++++++++++++++++++++++----
> benchtests/bench-memmove.c | 21 +++++++++++++++++--
> 2 files changed, 57 insertions(+), 6 deletions(-)
>
> diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c
> index d9236a2282..b9e661c997 100644
> --- a/benchtests/bench-memcpy.c
> +++ b/benchtests/bench-memcpy.c
> @@ -60,11 +60,11 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,
> size_t i, j;
> char *s1, *s2;
> size_t repeats;
> - align1 &= 63;
> + align1 &= (getpagesize () - 1);
> if (align1 + len >= page_size)
> return;
>
> - align2 &= 63;
> + align2 &= (getpagesize () - 1);
> if (align2 + len >= page_size)
> return;
>
> @@ -99,7 +99,7 @@ test_main (void)
> {
> json_ctx_t json_ctx;
> size_t i;
> -
> + size_t half_page = getpagesize () / 2;
> test_init ();
>
> json_init (&json_ctx, 0, stdout);
> @@ -121,8 +121,15 @@ test_main (void)
> {
> do_test (&json_ctx, 0, 0, 1 << i, 1);
> do_test (&json_ctx, i, 0, 1 << i, 1);
> + do_test (&json_ctx, i + 32, 0, 1 << i, 1);
> do_test (&json_ctx, 0, i, 1 << i, 1);
> + do_test (&json_ctx, 0, i + 32, 1 << i, 1);
> do_test (&json_ctx, i, i, 1 << i, 1);
> + do_test (&json_ctx, i + 32, i + 32, 1 << i, 1);
> + do_test (&json_ctx, half_page, 0, 1 << i, 1);
> + do_test (&json_ctx, half_page + i, 0, 1 << i, 1);
> + do_test (&json_ctx, half_page, i, 1 << i, 1);
> + do_test (&json_ctx, half_page + i, i, 1 << i, 1);
> }
>
> for (i = 0; i < 32; ++i)
> @@ -131,6 +138,12 @@ test_main (void)
> do_test (&json_ctx, i, 0, i, 0);
> do_test (&json_ctx, 0, i, i, 0);
> do_test (&json_ctx, i, i, i, 0);
> + do_test (&json_ctx, half_page, 0, i, 0);
> + do_test (&json_ctx, half_page + i, 0, i, 0);
> + do_test (&json_ctx, half_page, i, i, 0);
> + do_test (&json_ctx, half_page + i, i, i, 0);
> + do_test (&json_ctx, getpagesize () - 1, 0, i, 0);
> + do_test (&json_ctx, 0, getpagesize () - 1, i, 0);
> }
>
> for (i = 3; i < 32; ++i)
> @@ -141,6 +154,10 @@ test_main (void)
> do_test (&json_ctx, i, 0, 16 * i, 1);
> do_test (&json_ctx, 0, i, 16 * i, 1);
> do_test (&json_ctx, i, i, 16 * i, 1);
> + do_test (&json_ctx, half_page, 0, 16 * i, 1);
> + do_test (&json_ctx, half_page + i, 0, 16 * i, 1);
> + do_test (&json_ctx, half_page, i, 16 * i, 1);
> + do_test (&json_ctx, half_page + i, i, 16 * i, 1);
> }
>
> for (i = 32; i < 64; ++i)
> @@ -149,16 +166,33 @@ test_main (void)
> do_test (&json_ctx, i, 0, 32 * i, 1);
> do_test (&json_ctx, 0, i, 32 * i, 1);
> do_test (&json_ctx, i, i, 32 * i, 1);
> + do_test (&json_ctx, half_page, 0, 32 * i, 1);
> + do_test (&json_ctx, half_page + i, 0, 32 * i, 1);
> + do_test (&json_ctx, half_page, i, 32 * i, 1);
> + do_test (&json_ctx, half_page + i, i, 32 * i, 1);
> }
>
> do_test (&json_ctx, 0, 0, getpagesize (), 1);
>
> - for (i = 0; i <= 32; ++i)
> + for (i = 0; i <= 48; ++i)
> {
> do_test (&json_ctx, 0, 0, 2048 + 64 * i, 1);
> do_test (&json_ctx, i, 0, 2048 + 64 * i, 1);
> + do_test (&json_ctx, i + 32, 0, 2048 + 64 * i, 1);
> do_test (&json_ctx, 0, i, 2048 + 64 * i, 1);
> + do_test (&json_ctx, 0, i + 32, 2048 + 64 * i, 1);
> do_test (&json_ctx, i, i, 2048 + 64 * i, 1);
> + do_test (&json_ctx, i + 32, i + 32, 2048 + 64 * i, 1);
> + do_test (&json_ctx, half_page, 0, 2048 + 64 * i, 1);
> + do_test (&json_ctx, half_page + i, 0, 2048 + 64 * i, 1);
> + do_test (&json_ctx, half_page, i, 2048 + 64 * i, 1);
> + do_test (&json_ctx, half_page + i, i, 2048 + 64 * i, 1);
> + do_test (&json_ctx, i, 1, 2048 + 64 * i, 1);
> + do_test (&json_ctx, 1, i, 2048 + 64 * i, 1);
> + do_test (&json_ctx, i + 32, 1, 2048 + 64 * i, 1);
> + do_test (&json_ctx, 1, i + 32, 2048 + 64 * i, 1);
> + do_test (&json_ctx, half_page + i, 1, 2048 + 64 * i, 1);
> + do_test (&json_ctx, half_page + 1, i, 2048 + 64 * i, 1);
> }
>
> json_array_end (&json_ctx);
> diff --git a/benchtests/bench-memmove.c b/benchtests/bench-memmove.c
> index 6becbf4782..bec1455f7b 100644
> --- a/benchtests/bench-memmove.c
> +++ b/benchtests/bench-memmove.c
> @@ -53,11 +53,11 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
> size_t i, j;
> char *s1, *s2;
>
> - align1 &= 63;
> + align1 &= (getpagesize () - 1);
> if (align1 + len >= page_size)
> return;
>
> - align2 &= 63;
> + align2 &= (getpagesize () - 1);
> if (align2 + len >= page_size)
> return;
>
> @@ -85,6 +85,7 @@ test_main (void)
> {
> json_ctx_t json_ctx;
> size_t i;
> + size_t half_page = getpagesize () / 2;
>
> test_init ();
>
> @@ -138,6 +139,22 @@ test_main (void)
> do_test (&json_ctx, i, i, 32 * i);
> }
>
> + for (i = 0; i <= 48; ++i)
> + {
> + do_test (&json_ctx, 0, 0, 2048 + 64 * i);
> + do_test (&json_ctx, i, 0, 2048 + 64 * i);
> + do_test (&json_ctx, 0, i, 2048 + 64 * i);
> + do_test (&json_ctx, i, i, 2048 + 64 * i);
> + do_test (&json_ctx, half_page, 0, 2048 + 64 * i);
> + do_test (&json_ctx, 0, half_page, 2048 + 64 * i);
> + do_test (&json_ctx, half_page + i, 0, 2048 + 64 * i);
> + do_test (&json_ctx, i, half_page, 2048 + 64 * i);
> + do_test (&json_ctx, half_page, i, 2048 + 64 * i);
> + do_test (&json_ctx, 0, half_page + i, 2048 + 64 * i);
> + do_test (&json_ctx, half_page + i, i, 2048 + 64 * i);
> + do_test (&json_ctx, i, half_page + i, 2048 + 64 * i);
> + }
> +
> json_array_end (&json_ctx);
> json_attr_object_end (&json_ctx);
> json_attr_object_end (&json_ctx);
> --
> 2.25.1
>
LGTM.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Thanks.
--
H.J.
next prev parent reply other threads:[~2021-08-24 15:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-24 8:27 [PATCH 1/5] string: Make tests birdirectional test-memcpy.c Noah Goldstein via Libc-alpha
2021-08-24 8:27 ` [PATCH 2/5] benchtests: Add new random cases to bench-memcpy-random.c Noah Goldstein via Libc-alpha
2021-08-24 15:18 ` H.J. Lu via Libc-alpha
2021-08-24 8:27 ` [PATCH 3/5] benchtests: Add partial overlap case in bench-memmove-walk.c Noah Goldstein via Libc-alpha
2021-08-24 15:18 ` H.J. Lu via Libc-alpha
2021-08-24 8:27 ` [PATCH 4/5] benchtests: Add additional cases to bench-memcpy.c and bench-memmove.c Noah Goldstein via Libc-alpha
2021-08-24 15:19 ` H.J. Lu via Libc-alpha [this message]
2021-08-24 8:27 ` [PATCH 5/5] X86-64: Optimize memmove-vec-unaligned-erms.S Noah Goldstein via Libc-alpha
2021-08-24 9:12 ` Noah Goldstein via Libc-alpha
2021-08-24 15:17 ` [PATCH 1/5] string: Make tests birdirectional test-memcpy.c H.J. Lu via Libc-alpha
2021-08-24 19:32 ` [PATCH v1 " Noah Goldstein via Libc-alpha
2021-08-24 19:32 ` [PATCH v1 2/5] benchtests: Add new random cases to bench-memcpy-random.c Noah Goldstein via Libc-alpha
2021-08-24 19:32 ` [PATCH v1 3/5] benchtests: Add partial overlap case in bench-memmove-walk.c Noah Goldstein via Libc-alpha
2021-08-24 19:32 ` [PATCH v1 4/5] benchtests: Add additional cases to bench-memcpy.c and bench-memmove.c Noah Goldstein via Libc-alpha
2021-08-24 19:32 ` [PATCH v1 5/5] X86-64: Optimize memmove-vec-unaligned-erms.S Noah Goldstein via Libc-alpha
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
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOrWWY8+uCYTZMTGL8TMGjxtCbUNJoLKkq6pW1CTCwfNGw@mail.gmail.com \
--to=libc-alpha@sourceware.org \
--cc=goldstein.w.n@gmail.com \
--cc=hjl.tools@gmail.com \
/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).