From patchwork Tue Aug 24 08:27:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 44775 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0A383857C53 for ; Tue, 24 Aug 2021 08:30:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0A383857C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629793815; bh=8pqlRzOTn8T2WKRlQ9O15DbSbWiLhcYfDZDauCyeqD8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=If+vjNNa+CI89FTqtQZIRMc9SyTebs+EcP3rCLEXsjQcwM0PrC92/u+Rb+p78PV7n ySgM+ARknSEup3kt2oYxWfmvJb7cwKTxU65tK3AZQ6Pby+Hm/wDuJqLpMwmWA3vTJj MOR6BAOme8tWksw/VPCUnTntLI6zl90jlSIEIG88= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id 6E0573858025 for ; Tue, 24 Aug 2021 08:28:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E0573858025 Received: by mail-io1-xd32.google.com with SMTP id j18so25235215ioj.8 for ; Tue, 24 Aug 2021 01:28:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8pqlRzOTn8T2WKRlQ9O15DbSbWiLhcYfDZDauCyeqD8=; b=g5SQxRtExmBjOq1OA6Wo/ibETGgKK08EfVQqTls//AbdiOaQEQ9Zpbeo3/3OxzDgLH 6eHSdVAWqql/FwMXw0w4KLBIIu8IiCKfKG0g+lbyN0mNJuVD1ynybSsEn/Uiatgdk6fn bPiM7qkMWoQC/ynAypN0ViN1MGkgRoFg21KVNh5v5CfKpPNT0cxUO5KxSTYqqEAZ7HI8 nZSxcDW1TK2BaPw+DxfGKHhOAhcYOG8KXQIJJwbjWqlS/0f7uL1K6W+XIYPnboTvKi1L GutaFmVP9UQ2EwQJhrjFGVRSglwaJYDp1YyDaZ0xWubzBby9gdDEcCX4TKYLw40zdSAM Hefg== X-Gm-Message-State: AOAM533L1V9t8kr5sc3VngSBVW0Hmh22f9A3d2az5/9IPZAJr/V9qDNP XkXErcurRhPvg+uliw3jFgf2JRY2mzTApg== X-Google-Smtp-Source: ABdhPJz4ZmHQ3YJf2Vl08GhRqIBAKewtU4p7x1ovinoyPT9ABuyoPbXq0XSJ0k1hc2/Z0GjajFVi4A== X-Received: by 2002:a05:6602:218d:: with SMTP id b13mr30373028iob.143.1629793683701; Tue, 24 Aug 2021 01:28:03 -0700 (PDT) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id d12sm6074744iow.16.2021.08.24.01.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 01:28:03 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/5] benchtests: Add new random cases to bench-memcpy-random.c Date: Tue, 24 Aug 2021 04:27:50 -0400 Message-Id: <20210824082753.3356637-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824082753.3356637-1-goldstein.w.n@gmail.com> References: <20210824082753.3356637-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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 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-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. Reviewed-by: H.J. Lu --- 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);