From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 253D53858C2D for ; Wed, 23 Feb 2022 19:49:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 253D53858C2D Received: by mail-pf1-x435.google.com with SMTP id i21so16357488pfd.13 for ; Wed, 23 Feb 2022 11:49:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3haaY3WINVEcoYMi+sxc849tlzL4Q4c0TSRz6laxshc=; b=rfCx/SMIikFPtCojpWMa4s7+AksNLjbkTAIsKtzhrTPNckPp7Ojt603OzAtN6qqNAe 5acVjP+R78JKO5G9dZrweR+o+e3nE2cNeY1GemEWTp/fMSHarQCkFt+X53i2ntzBlGkv 2PdrrWv3fqQGhlx/MpE/NsWugHSy0J2+jjOlUImnHCmFqZilW0Izv1GRRcs7LIw2x3Rq gKx9ROUEO6uvi0Z3opPwsFKjpVBVKzu8cIWtXxGvFlmLJNk07A9YfqT74lrr1ab5QTc7 bJLX3PeB5h9xj2ApvZ41riyspJIn9sBALsxNdPgM2BRI8JuyXwVy8Cc55il2hMQLBkaE 5pbQ== X-Gm-Message-State: AOAM532Wvat07ASoMf6JgwiHFqAIg+LbBaWr8Yrzuy06YdiW1oVWzMs1 dTl1T2TQ90xLCtGkbvvSLKZlQBG4hGwkBBZj0CU= X-Google-Smtp-Source: ABdhPJxZSwtElMUZlrYCNRRpOHfBV55cC4gBQWhCDJDJ8Prbpo7SVfcfkJebY9m0AwhJ4KgDdAz3vFcA/ow9Q18ewYU= X-Received: by 2002:aa7:8882:0:b0:4e1:4531:e3c8 with SMTP id z2-20020aa78882000000b004e14531e3c8mr1237454pfe.76.1645645796772; Wed, 23 Feb 2022 11:49:56 -0800 (PST) MIME-Version: 1.0 References: <20220209153538.66931-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Wed, 23 Feb 2022 11:49:20 -0800 Message-ID: Subject: Re: [PATCH] benchtests: Add benches for zeroing memset To: Noah Goldstein Cc: Sunil Pandey , GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3026.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Feb 2022 19:50:00 -0000 On Wed, Feb 23, 2022 at 11:20 AM Noah Goldstein wrote: > > On Wed, Feb 23, 2022 at 1:04 PM Sunil Pandey via Libc-alpha > wrote: > > > > LGTM > > Reviewed-by: Sunil K Pandey > > > > Thanks, > > Sunil > > > > Think we should wait until we decide on actually adding `__memsetzero` > to benchmarks for it. This is not for __memsetzero. It is for memset with 0 input value. H.J. > > On Wed, Feb 9, 2022 at 7:36 AM H.J. Lu via Libc-alpha > > wrote: > > > > > > memset with zero as the value to set is by far the majority value (99%+ > > > for Python3 and GCC). Add bench-memset-zero-large.c, > > > bench-memset-zero-walk.c and bench-memset-zero.c to measure memset > > > functions for zeroing. > > > --- > > > benchtests/Makefile | 3 +++ > > > benchtests/bench-bzero-large.c | 29 ++++++++++++++++++++++++++- > > > benchtests/bench-bzero-walk.c | 30 +++++++++++++++++++++++++++- > > > benchtests/bench-bzero.c | 30 +++++++++++++++++++++++++++- > > > benchtests/bench-memset-zero-large.c | 20 +++++++++++++++++++ > > > benchtests/bench-memset-zero-walk.c | 20 +++++++++++++++++++ > > > benchtests/bench-memset-zero.c | 20 +++++++++++++++++++ > > > 7 files changed, 149 insertions(+), 3 deletions(-) > > > create mode 100644 benchtests/bench-memset-zero-large.c > > > create mode 100644 benchtests/bench-memset-zero-walk.c > > > create mode 100644 benchtests/bench-memset-zero.c > > > > > > diff --git a/benchtests/Makefile b/benchtests/Makefile > > > index 6f718fac35..9b8df3b3f5 100644 > > > --- a/benchtests/Makefile > > > +++ b/benchtests/Makefile > > > @@ -139,6 +139,9 @@ string-benchset := \ > > > memset \ > > > memset-large \ > > > memset-walk \ > > > + memset-zero \ > > > + memset-zero-large \ > > > + memset-zero-walk \ > > > rawmemchr \ > > > stpcpy \ > > > stpcpy_chk \ > > > diff --git a/benchtests/bench-bzero-large.c b/benchtests/bench-bzero-large.c > > > index f2e2e981b7..cfc7b81cdf 100644 > > > --- a/benchtests/bench-bzero-large.c > > > +++ b/benchtests/bench-bzero-large.c > > > @@ -17,7 +17,11 @@ > > > . */ > > > > > > #define TEST_MAIN > > > -#define TEST_NAME "bzero" > > > +#ifdef DO_MEMSET > > > +# define TEST_NAME "memset" > > > +#else > > > +# define TEST_NAME "bzero" > > > +#endif > > > #define START_SIZE (128 * 1024) > > > #define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024) > > > #define TIMEOUT (20 * 60) > > > @@ -25,6 +29,14 @@ > > > > > > #include "json-lib.h" > > > > > > +#ifdef DO_MEMSET > > > +void *generic_memset (void *, int, size_t); > > > + > > > +typedef void *(*proto_t) (void *, int, size_t); > > > + > > > +IMPL (memset, 1) > > > +IMPL (generic_memset, 0) > > > +#else > > > static void > > > memset_zero (void * s, size_t len) > > > { > > > @@ -35,6 +47,7 @@ typedef void (*proto_t) (void *, size_t); > > > > > > IMPL (bzero, 1) > > > IMPL (memset_zero, 0) > > > +#endif > > > > > > static void > > > do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n) > > > @@ -45,7 +58,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n) > > > TIMING_NOW (start); > > > for (i = 0; i < iters; ++i) > > > { > > > +#ifdef DO_MEMSET > > > + CALL (impl, s, 0, n); > > > +#else > > > CALL (impl, s, n); > > > +#endif > > > } > > > TIMING_NOW (stop); > > > > > > @@ -115,3 +132,13 @@ test_main (void) > > > } > > > > > > #include > > > + > > > +#ifdef DO_MEMSET > > > +# define libc_hidden_builtin_def(X) > > > +# define libc_hidden_def(X) > > > +# define libc_hidden_weak(X) > > > +# define weak_alias(X,Y) > > > +# undef MEMSET > > > +# define MEMSET generic_memset > > > +# include > > > +#endif > > > diff --git a/benchtests/bench-bzero-walk.c b/benchtests/bench-bzero-walk.c > > > index b65d12a6a2..00226f80b8 100644 > > > --- a/benchtests/bench-bzero-walk.c > > > +++ b/benchtests/bench-bzero-walk.c > > > @@ -17,7 +17,11 @@ > > > . */ > > > > > > #define TEST_MAIN > > > -#define TEST_NAME "bzero" > > > +#ifdef DO_MEMSET > > > +# define TEST_NAME "memset" > > > +#else > > > +# define TEST_NAME "bzero" > > > +#endif > > > #define START_SIZE 128 > > > #define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024) > > > #define TIMEOUT (20 * 60) > > > @@ -25,6 +29,15 @@ > > > > > > #include "json-lib.h" > > > > > > +#ifdef DO_MEMSET > > > +void *generic_memset (void *, int, size_t); > > > + > > > +typedef void *(*proto_t) (void *, int, size_t); > > > + > > > +IMPL (memset, 1) > > > +IMPL (generic_memset, 0) > > > + > > > +#else > > > static void > > > memset_zero (void * s, size_t len) > > > { > > > @@ -35,6 +48,7 @@ typedef void (*proto_t) (void *, size_t); > > > > > > IMPL (bzero, 1) > > > IMPL (memset_zero, 0) > > > +#endif > > > > > > static void > > > do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end, > > > @@ -45,7 +59,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end, > > > > > > TIMING_NOW (start); > > > for (i = 0; i < iters && s <= s_end; s_end -= n, i++) > > > +#ifdef DO_MEMSET > > > + CALL (impl, s, 0, n); > > > +#else > > > CALL (impl, s, n); > > > +#endif > > > TIMING_NOW (stop); > > > > > > TIMING_DIFF (cur, start, stop); > > > @@ -116,3 +134,13 @@ test_main (void) > > > } > > > > > > #include > > > + > > > +#ifdef DO_MEMSET > > > +# define libc_hidden_builtin_def(X) > > > +# define libc_hidden_def(X) > > > +# define libc_hidden_weak(X) > > > +# define weak_alias(X,Y) > > > +# undef MEMSET > > > +# define MEMSET generic_memset > > > +# include > > > +#endif > > > diff --git a/benchtests/bench-bzero.c b/benchtests/bench-bzero.c > > > index 93ec521725..500b7eba96 100644 > > > --- a/benchtests/bench-bzero.c > > > +++ b/benchtests/bench-bzero.c > > > @@ -17,12 +17,25 @@ > > > . */ > > > > > > #define TEST_MAIN > > > -#define TEST_NAME "bzero" > > > +#ifdef DO_MEMSET > > > +# define TEST_NAME "memset" > > > +#else > > > +# define TEST_NAME "bzero" > > > +#endif > > > #define MIN_PAGE_SIZE 131072 > > > #include "bench-string.h" > > > > > > #include "json-lib.h" > > > > > > +#ifdef DO_MEMSET > > > +void *generic_memset (void *, int, size_t); > > > + > > > +typedef void *(*proto_t) (void *, int, size_t); > > > + > > > +IMPL (memset, 1) > > > +IMPL (generic_memset, 0) > > > + > > > +#else > > > static void > > > memset_zero (void * s, size_t len) > > > { > > > @@ -33,6 +46,7 @@ typedef void (*proto_t) (void *, size_t); > > > > > > IMPL (bzero, 1) > > > IMPL (memset_zero, 0) > > > +#endif > > > > > > static void > > > do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n) > > > @@ -43,7 +57,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n) > > > TIMING_NOW (start); > > > for (i = 0; i < iters; ++i) > > > { > > > +#ifdef DO_MEMSET > > > + CALL (impl, s, 0, n); > > > +#else > > > CALL (impl, s, n); > > > +#endif > > > } > > > TIMING_NOW (stop); > > > > > > @@ -132,3 +150,13 @@ test_main (void) > > > } > > > > > > #include > > > + > > > +#ifdef DO_MEMSET > > > +# define libc_hidden_builtin_def(X) > > > +# define libc_hidden_def(X) > > > +# define libc_hidden_weak(X) > > > +# define weak_alias(X,Y) > > > +# undef MEMSET > > > +# define MEMSET generic_memset > > > +# include > > > +#endif > > > diff --git a/benchtests/bench-memset-zero-large.c b/benchtests/bench-memset-zero-large.c > > > new file mode 100644 > > > index 0000000000..bc938cdfff > > > --- /dev/null > > > +++ b/benchtests/bench-memset-zero-large.c > > > @@ -0,0 +1,20 @@ > > > +/* Measure memset functions for zeroing with large data sizes. > > > + Copyright (C) 2022 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 > > > + . */ > > > + > > > +#define DO_MEMSET 1 > > > +#include "bench-bzero-large.c" > > > diff --git a/benchtests/bench-memset-zero-walk.c b/benchtests/bench-memset-zero-walk.c > > > new file mode 100644 > > > index 0000000000..dce4b43e06 > > > --- /dev/null > > > +++ b/benchtests/bench-memset-zero-walk.c > > > @@ -0,0 +1,20 @@ > > > +/* Measure memset functions for zeroing throughput with large data sizes. > > > + Copyright (C) 2022 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 > > > + . */ > > > + > > > +#define DO_MEMSET 1 > > > +#include "bench-bzero-walk.c" > > > diff --git a/benchtests/bench-memset-zero.c b/benchtests/bench-memset-zero.c > > > new file mode 100644 > > > index 0000000000..535005f0e6 > > > --- /dev/null > > > +++ b/benchtests/bench-memset-zero.c > > > @@ -0,0 +1,20 @@ > > > +/* Measure memset functions for zeroing. > > > + Copyright (C) 2022 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 > > > + . */ > > > + > > > +#define DO_MEMSET 1 > > > +#include "bench-bzero.c" > > > -- > > > 2.34.1 > > > -- H.J.