From patchwork Thu Sep 14 17:25:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 22887 Received: (qmail 111763 invoked by alias); 14 Sep 2017 17:26:14 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 111202 invoked by uid 89); 14 Sep 2017 17:26:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: homiemail-a83.g.dreamhost.com From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [COMMITTED 2/2] benchtests: Reallocate buffers for memset Date: Thu, 14 Sep 2017 22:55:59 +0530 Message-Id: <1505409959-6088-2-git-send-email-siddhesh@sourceware.org> In-Reply-To: <1505409959-6088-1-git-send-email-siddhesh@sourceware.org> References: <1505409959-6088-1-git-send-email-siddhesh@sourceware.org> 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. --- benchtests/bench-memset-large.c | 5 ++++- benchtests/bench-memset.c | 5 ++++- benchtests/bench-string.h | 50 ++++++++++++++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/benchtests/bench-memset-large.c b/benchtests/bench-memset-large.c index c0f1974..6cd48c9 100644 --- a/benchtests/bench-memset-large.c +++ b/benchtests/bench-memset-large.c @@ -90,7 +90,10 @@ do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len) json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); + { + do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); + realloc_bufs (); + } json_array_end (json_ctx); json_element_object_end (json_ctx); diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c index 107e2b7..724c105 100644 --- a/benchtests/bench-memset.c +++ b/benchtests/bench-memset.c @@ -132,7 +132,10 @@ do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len) json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); + { + do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); + realloc_bufs (); + } json_array_end (json_ctx); json_element_object_end (json_ctx); diff --git a/benchtests/bench-string.h b/benchtests/bench-string.h index 3aacfdf..40c735c 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);