From patchwork Tue Aug 7 19:47:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 954670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-95114-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Vsm5ZSGP"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41lQ6K12kBz9rvt for ; Wed, 8 Aug 2018 05:47:52 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=mche2C/ELHfrKnPyURYTQzlD8yNcfMNxdoymqX5CkDWKwaxw/IRKc Dpcq9NuzWx2ScLCcqHOYH/8UVc2CsI4PnG2KSFTQ7lza5h6n09eHFGjptW0m2/u6 NqAs/GuTptKo4qXXrJc04KbKcyTbNve3lyN1t874nWJ52RePFWHRts= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=Mr7cBKh1ylRUNdicpPTsF/lqesk=; b=Vsm5ZSGPsH9s+zAneCRMDizyQcGw BDE0LKfgSFwrA9+QcWE1ODdhnVWhUv/+dKZZvTlC/brBdYqLxzYCt3q+QvDqAguk rv/IBxsgz2eJsa4hFL8Hm4b1AE0AAJ4bwqwkxjPug6hQCVJUO0NWIOhPHFQrcJNq gzCJ5OqJ6Tsq84U= Received: (qmail 94120 invoked by alias); 7 Aug 2018 19:47:46 -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 94108 invoked by uid 89); 7 Aug 2018 19:47:45 -0000 Authentication-Results: sourceware.org; auth=none 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-a52.g.dreamhost.com From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [COMMITTED] benchtests: Clean up the alloc_bufs Date: Wed, 8 Aug 2018 01:17:25 +0530 Message-Id: <20180807194725.27585-1-siddhesh@sourceware.org> Drop realloc_bufs in favour of making alloc_bufs transparently reallocate the buffers if it had allocated before. Also consolidate computation of buffer lengths so that they don't get repeated on every reallocation. * benchtests/bench-string.h (buf1_size, buf2_size): New variables. (init_sizes): New function. (test_init): Use it. (alloc_buf, exit_error): New functions. (alloc_bufs): Use ALLOC_BUF. (realloc_bufs): Remove. * benchtests/bench-memcmp.c (do_test): Adjust. * benchtests/bench-memset-large.c (do_test): Likewise. * benchtests/bench-memset-walk.c (do_test): Likewise. * benchtests/bench-memset.c (do_test): Likewise. * benchtests/bench-strncmp.c (do_test): Likewise. --- ChangeLog | 15 ++++++++ benchtests/bench-memcmp.c | 2 +- benchtests/bench-memset-large.c | 2 +- benchtests/bench-memset-walk.c | 2 +- benchtests/bench-memset.c | 2 +- benchtests/bench-string.h | 63 +++++++++++++++++++-------------- benchtests/bench-strncmp.c | 4 +-- 7 files changed, 57 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8a1b70619..7e1a5b081f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2018-08-07 Siddhesh Poyarekar + + * benchtests/bench-string.h (buf1_size, buf2_size): New + variables. + (init_sizes): New function. + (test_init): Use it. + (alloc_buf, exit_error): New functions. + (alloc_bufs): Use ALLOC_BUF. + (realloc_bufs): Remove. + * benchtests/bench-memcmp.c (do_test): Adjust. + * benchtests/bench-memset-large.c (do_test): Likewise. + * benchtests/bench-memset-walk.c (do_test): Likewise. + * benchtests/bench-memset.c (do_test): Likewise. + * benchtests/bench-strncmp.c (do_test): Likewise. + 2018-08-06 Andreas Schwab * sysdeps/riscv/nptl/tls.h (DB_THREAD_SELF): Use REGISTER instead diff --git a/benchtests/bench-memcmp.c b/benchtests/bench-memcmp.c index 69ed9c958b..b566f48ae9 100644 --- a/benchtests/bench-memcmp.c +++ b/benchtests/bench-memcmp.c @@ -132,7 +132,7 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, s2[len - 1] -= exp_result; do_one_test (json_ctx, impl, s1, s2, len, exp_result); - realloc_bufs (); + alloc_bufs (); } json_array_end (json_ctx); diff --git a/benchtests/bench-memset-large.c b/benchtests/bench-memset-large.c index 248289108b..1f7bf81fd1 100644 --- a/benchtests/bench-memset-large.c +++ b/benchtests/bench-memset-large.c @@ -92,7 +92,7 @@ do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len) FOR_EACH_IMPL (impl, 0) { do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); - realloc_bufs (); + alloc_bufs (); } json_array_end (json_ctx); diff --git a/benchtests/bench-memset-walk.c b/benchtests/bench-memset-walk.c index 4dcb1529cf..753d6f36f3 100644 --- a/benchtests/bench-memset-walk.c +++ b/benchtests/bench-memset-walk.c @@ -88,7 +88,7 @@ do_test (json_ctx_t *json_ctx, int c, size_t len) { do_one_test (json_ctx, impl, (CHAR *) buf1, (CHAR *) buf1 + MIN_PAGE_SIZE - len, c, len); - realloc_bufs (); + alloc_bufs (); } json_array_end (json_ctx); diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c index 0ae201d4a5..a47620cbfc 100644 --- a/benchtests/bench-memset.c +++ b/benchtests/bench-memset.c @@ -134,7 +134,7 @@ do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len) FOR_EACH_IMPL (impl, 0) { do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); - realloc_bufs (); + alloc_bufs (); } json_array_end (json_ctx); diff --git a/benchtests/bench-string.h b/benchtests/bench-string.h index 94aaafdaf2..f8389982e9 100644 --- a/benchtests/bench-string.h +++ b/benchtests/bench-string.h @@ -76,10 +76,8 @@ extern impl_t __start_impls[], __stop_impls[]; # define INNER_LOOP_ITERS 64 -unsigned char *buf1, *buf2; int ret, do_srandom; unsigned int seed; -size_t page_size; # ifndef ITERATIONS size_t iterations = 100000; @@ -182,47 +180,57 @@ static impl_t *impl_array; # define BUF1PAGES 1 # endif +unsigned char *buf1, *buf2; +static size_t buf1_size, buf2_size, page_size; + static void -alloc_bufs (void) +init_sizes (void) { page_size = 2 * getpagesize (); # ifdef MIN_PAGE_SIZE if (page_size < MIN_PAGE_SIZE) page_size = MIN_PAGE_SIZE; # endif - 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 for buf1"); - if (mprotect (buf1 + BUF1PAGES * page_size, page_size, PROT_NONE)) - 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 for buf2"); - if (mprotect (buf2 + page_size, page_size, PROT_NONE)) - error (EXIT_FAILURE, errno, "mprotect failed for buf2"); + + buf1_size = BUF1PAGES * page_size; + buf2_size = page_size; +} + +static void +exit_error (const char *id, const char *func) +{ + error (EXIT_FAILURE, errno, "%s: %s failed", id, func); } +/* Allocate a buffer of size SIZE with a guard page at the end. */ static void -__attribute__ ((unused)) -realloc_bufs (void) +alloc_buf (const char *id, size_t size, unsigned char **retbuf) { - int ret = 0; + size_t alloc_size = size + page_size; - if (buf1) - ret = munmap (buf1, (BUF1PAGES + 1) * page_size); + if (*retbuf != NULL) + { + int ret = munmap (*retbuf, alloc_size); + if (ret != 0) + exit_error (id, "munmap"); + } - if (ret != 0) - error (EXIT_FAILURE, errno, "munmap failed for buf1"); + unsigned char *buf = mmap (0, alloc_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); - if (buf2) - ret = munmap (buf2, 2 * page_size); + if (buf == MAP_FAILED) + exit_error (id, "mmap"); + if (mprotect (buf + size, page_size, PROT_NONE)) + exit_error (id, "mprotect"); - if (ret != 0) - error (EXIT_FAILURE, errno, "munmap failed for buf2"); + *retbuf = buf; +} - alloc_bufs (); +static void +alloc_bufs (void) +{ + alloc_buf ("buf1", buf1_size, &buf1); + alloc_buf ("buf2", buf2_size, &buf2); } static void @@ -234,6 +242,7 @@ test_init (void) / sizeof func_list[0])); # endif + init_sizes (); alloc_bufs (); if (do_srandom) diff --git a/benchtests/bench-strncmp.c b/benchtests/bench-strncmp.c index 97dc39069d..92cf0d2145 100644 --- a/benchtests/bench-strncmp.c +++ b/benchtests/bench-strncmp.c @@ -150,7 +150,7 @@ do_test_limit (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, FOR_EACH_IMPL (impl, 0) { - realloc_bufs (); + alloc_bufs (); s1 = (CHAR *) (buf1 + page_size - n * CHARBYTES); s2 = (CHAR *) (buf2 + page_size - n * CHARBYTES); @@ -207,7 +207,7 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, size_t FOR_EACH_IMPL (impl, 0) { - realloc_bufs (); + alloc_bufs (); s1 = (CHAR *) (buf1 + align1); s2 = (CHAR *) (buf2 + align2);