From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id E31641F8C6 for ; Tue, 24 Aug 2021 15:20:45 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DB7F385843B for ; Tue, 24 Aug 2021 15:20:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DB7F385843B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629818445; bh=dkvZTWRBpaC1AX2X245O/BzJxOvqpprJnyu+gxaARbU=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GdF9oZTm5f5Ejiaf09mqwOHX9PcaDs8P0zXuD5Ky+/1NjXHQVRC0RlIHOrPqeq+V5 VZcVHGLaTNRi+jaFvcOq9fFKr5GYKFuvbXljZ/gpSSFaCJE2bIJdq/DFajNNh92Bk7 zZw81TlivV+JJw3qD1Qxgx2Dv44JMtkApbd+rNqo= Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 842A63858410 for ; Tue, 24 Aug 2021 15:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 842A63858410 Received: by mail-pf1-x432.google.com with SMTP id r9so2597312pfh.6 for ; Tue, 24 Aug 2021 08:18:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dkvZTWRBpaC1AX2X245O/BzJxOvqpprJnyu+gxaARbU=; b=Y2J4Jj4ZNlgCUzGW04MAIjqcJkSzpQxPbcKP5IiQqeYjQGW6tsFHoliww0UfvsBGJI 1QrS4naXMblNOAWEx2B2zxpF1baQ+efa2ynV/rxhknXxin60//4EFhw4jQ9IwL8bW0gL mDNbB/Z8EiESCzz8itChiAL0e62ubkRV6Q+9GUWnfLv3ujwdx+O+rLrNEzCVFCqywOiY If5MLi4W/hLfktjwroCXYwlOEHcXA9dNTOBkl/pi7eiie3RQJqiwaTagL4y3oYWlAvF1 J0tNPc4b3DGd8qO4xAa+3QO7BRv2yOK73bHC8kSPWQJZhFXL7g2YDmcfyEl8jFQUNMfw a8Ag== X-Gm-Message-State: AOAM5335xckSqsn2D4FGsNsPTPR0Ox6hccxBVtJV4bHTVxePY4viNmWK 0zrqyO2X/YCKOXPtSKv+ToiybZ6fTwhqMwkaj9w= X-Google-Smtp-Source: ABdhPJzPdg2/oxRMiw+BrHUejh+9qXh0z1lz9n0AT3O4IJVFnngfVpx26NdWIKBS7c7TZklBr5z6gmhNjPBKR349g5E= X-Received: by 2002:a63:4d24:: with SMTP id a36mr24245245pgb.37.1629818328756; Tue, 24 Aug 2021 08:18:48 -0700 (PDT) MIME-Version: 1.0 References: <20210824082753.3356637-1-goldstein.w.n@gmail.com> <20210824082753.3356637-2-goldstein.w.n@gmail.com> In-Reply-To: <20210824082753.3356637-2-goldstein.w.n@gmail.com> Date: Tue, 24 Aug 2021 08:18:12 -0700 Message-ID: Subject: Re: [PATCH 2/5] benchtests: Add new random cases to bench-memcpy-random.c To: Noah Goldstein Content-Type: text/plain; charset="UTF-8" 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: , From: "H.J. Lu via Libc-alpha" Reply-To: "H.J. Lu" Cc: GNU C Library Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On Tue, Aug 24, 2021 at 1:28 AM Noah Goldstein wrote: > > This commit adds three new benchmarks for the SPEC2017 > distribution. One randomized if dst > src and the other two set it > either 1/0. > > As well add some tests for fixed sizes with randomize alignment and > value of dst > src. This can be useful for testing different alignment > configurations. > --- > benchtests/bench-memcpy-random.c | 107 +++++++++++++++++++++++++++---- > 1 file changed, 96 insertions(+), 11 deletions(-) > > diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c > index c490b73ed0..28e0acb05f 100644 > --- a/benchtests/bench-memcpy-random.c > +++ b/benchtests/bench-memcpy-random.c > @@ -16,7 +16,8 @@ > License along with the GNU C Library; if not, see > . */ > > -#define MIN_PAGE_SIZE (512*1024+getpagesize()) > +#define MAX_TEST_SIZE (512*1024) > +#define MIN_PAGE_SIZE (3*MAX_TEST_SIZE+3*getpagesize()) > #define TEST_MAIN > #define TEST_NAME "memcpy" > #include "bench-string.h" > @@ -89,9 +90,12 @@ static align_data_t dst_align_freq[] = > > typedef struct > { > - uint64_t src : 24; > - uint64_t dst : 24; > - uint64_t len : 16; > +/* 26 bits for src and dst so we have extra bit for alternating dst > > + src without a branch. */ > + uint64_t src : 26; > + uint64_t dst : 26; > + /* For size < 4096 12 bits is enough. */ > + uint64_t len : 12; > } copy_t; > > static copy_t copy[MAX_COPIES]; > @@ -142,34 +146,100 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src, > } > > static void > -do_test (json_ctx_t *json_ctx, size_t max_size) > +do_one_fixed_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src, > + copy_t *copy, size_t n, size_t size) > { > - int i; > + timing_t start, stop, cur; > + size_t iters = INNER_LOOP_ITERS_SMALL; > > - memset (buf1, 1, max_size); > + for (int j = 0; j < n; j++) > + CALL (impl, dst + copy[j].dst, src + copy[j].src, size); > > - /* Create a random set of copies with the given size and alignment > + 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, size); > + TIMING_NOW (stop); > + > + TIMING_DIFF (cur, start, stop); > + > + json_element_double (json_ctx, (double) cur / (double) iters); > +} > + > + > +static size_t > +init_copy(size_t max_size, int dst_gt_src) > +{ > + size_t i, dst_offset, src_offset; > + if (dst_gt_src <= 0) > + { > + dst_offset = 0; > + src_offset = MAX_TEST_SIZE + getpagesize(); > + } > + else > + { > + dst_offset = MAX_TEST_SIZE + getpagesize(); > + src_offset = 0; > + } > + > + /* Create a random set of copies with the given size and alignment > distributions. */ > for (i = 0; i < MAX_COPIES; i++) > { > + dst_offset = dst_gt_src == -1 > + ? (rand() & 1) ? MAX_TEST_SIZE + getpagesize() : 0 > + : dst_offset; > copy[i].dst = (rand () & (max_size - 1)); > copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK]; > + copy[i].dst += dst_offset; > copy[i].src = (rand () & (max_size - 1)); > copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK]; > + copy[i].src += src_offset; > copy[i].len = size_arr[rand () & SIZE_MASK]; > } > + return i; > +} > > +static void > +do_test (json_ctx_t *json_ctx, size_t max_size, int dst_gt_src) > +{ > + size_t n; > + memset (buf1, 1, max_size); > + n = init_copy(max_size, dst_gt_src); > json_element_object_begin (json_ctx); > - json_attr_uint (json_ctx, "length", (double) max_size); > + json_attr_uint (json_ctx, "max-alignment", (double) max_size); > + json_attr_int (json_ctx, "dst > src", (double) dst_gt_src); > + json_attr_uint (json_ctx, "with-fixed-size", (double) 0); > json_array_begin (json_ctx, "timings"); > > FOR_EACH_IMPL (impl, 0) > - do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, i); > + do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, n); > > json_array_end (json_ctx); > json_element_object_end (json_ctx); > } > > +static void > +do_test_fixed_size (json_ctx_t *json_ctx, size_t size, size_t max_size, int dst_gt_src) > +{ > + size_t n; > + memset (buf1, 1, max_size); > + n = init_copy(max_size, dst_gt_src); > + json_element_object_begin (json_ctx); > + json_attr_uint (json_ctx, "max-alignment", (double) max_size); > + json_attr_int (json_ctx, "dst > src", (double) dst_gt_src); > + json_attr_uint (json_ctx, "with-fixed-size", (double) 1); > + json_attr_uint (json_ctx, "size", (double) size); > + json_array_begin (json_ctx, "timings"); > + > + FOR_EACH_IMPL (impl, 0) > + do_one_fixed_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, n, size); > + > + json_array_end (json_ctx); > + json_element_object_end (json_ctx); > +} > + > + > int > test_main (void) > { > @@ -194,7 +264,22 @@ test_main (void) > > json_array_begin (&json_ctx, "results"); > for (int i = 4; i <= 512; i = i * 2) > - do_test (&json_ctx, i * 1024); > + { > + if (i * 1024 > MAX_TEST_SIZE) > + continue; > + do_test (&json_ctx, i * 1024, 0); > + do_test (&json_ctx, i * 1024, 1); > + do_test (&json_ctx, i * 1024, -1); > + } > + > + for (int i = 4; i <= 64; i = i * 2) > + { > + if (i * 1024 > MAX_TEST_SIZE) > + continue; > + do_test_fixed_size (&json_ctx, i * 256, i * 1024, 0); > + do_test_fixed_size (&json_ctx, i * 256, i * 1024, 1); > + do_test_fixed_size (&json_ctx, i * 256, i * 1024, -1); > + } > > json_array_end (&json_ctx); > json_attr_object_end (&json_ctx); > -- > 2.25.1 > LGTM. Reviewed-by: H.J. Lu Thanks. -- H.J.