From patchwork Mon May 24 01:30:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 43548 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 B3FFE3857405; Mon, 24 May 2021 01:30:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3FFE3857405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1621819853; bh=zwctSagYVTePj9a99bY2gi0kJ6IAK+EaEgZC/BWZPyE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=j1iKIEzMhCckG/OURYS0S5NgPcrFT4AzGDQ/hltxgoJfifAt6JN1v8Qf3DVe4zvWP Y0tAQCAoBmTwZD82DB8BrrIty/QScyQkFq4azzPrMQRzAfQKxh1IKbFlKxHrEtXi7V cI5BLux12SpEs4eKBXI2+aVI+uA5CN3UCt2sPCmU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by sourceware.org (Postfix) with ESMTPS id AF5873857C74 for ; Mon, 24 May 2021 01:30:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AF5873857C74 Received: by mail-qv1-xf32.google.com with SMTP id c13so12250145qvx.5 for ; Sun, 23 May 2021 18:30:50 -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:mime-version :content-transfer-encoding; bh=zwctSagYVTePj9a99bY2gi0kJ6IAK+EaEgZC/BWZPyE=; b=OKC3GBMcEbNPGsAA5Ag33d9hgVn/iz2MskBAhOc1otpFKIBRocxhTXbN2OTCmeUQ8E zuTz8t9jxayeiOvzLp7Ddmn1f3qTSyEKsNS8PLfbfmersgmYYW2Y5GbRv4bwWYh1vCFI v1N8X8tDDk+QyitPtxI7SV7p1mOsJEkCqW0aEFiNP0KddDlqqVi56X98XRYgcjBddnxz hhVHQ4A0/pQ7qOkjZx72NExb5Q/1kIWzENzyk3zeOynzNI7CWj/IgU7mPjKHxgKcz6Gr 5n+nuADtjDwR/Oc8mvaqyCjQqTNi7D3DCozh6OoFv/06ajQfsEAnqqNQNr2sMwx66IHz VixQ== X-Gm-Message-State: AOAM531npmFh8w9nf8ZT9Y+q2dKwigpfypmCGS1DfK+dx3rw5Zzs4ArR rq6RRE9d2V3h2IhppERcCLmcMVTQwRTiww== X-Google-Smtp-Source: ABdhPJwEc/W+OM2WyJH7Z3z/Vb7YYZUFbsuJyjX8KJhmJg4Cx+U31OHrRHS67j8E828niDs48DVicQ== X-Received: by 2002:a0c:c492:: with SMTP id u18mr26736517qvi.40.1621819849677; Sun, 23 May 2021 18:30:49 -0700 (PDT) Received: from noah-tigerlake.home (pool-71-245-178-39.pitbpa.fios.verizon.net. [71.245.178.39]) by smtp.googlemail.com with ESMTPSA id d12sm5523041qkn.126.2021.05.23.18.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 May 2021 18:30:49 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1 1/2] Bench: Add support for choose direction of memcpy in benchtests Date: Sun, 23 May 2021 21:30:19 -0400 Message-Id: <20210524013020.1869687-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@sourceware.org Sender: "Libc-alpha" This patch adds support for testing memcpy with both dst > src and dst < src. Since memcpy is implemented as memmove which has seperate control flows for certain sizes depending on dst > src it seems like 1) information that should be provided in the benchtest output and a variable that can be controlled for the benchmarks. Signed-off-by: Noah Goldstein Reviewed-by: H.J. Lu --- benchtests/bench-memcpy-large.c | 50 +++++++++++++--------- benchtests/bench-memcpy-walk.c | 33 +++++++++----- benchtests/bench-memcpy.c | 76 ++++++++++++++++++--------------- 3 files changed, 94 insertions(+), 65 deletions(-) diff --git a/benchtests/bench-memcpy-large.c b/benchtests/bench-memcpy-large.c index efb9627b1e..0021274e92 100644 --- a/benchtests/bench-memcpy-large.c +++ b/benchtests/bench-memcpy-large.c @@ -52,11 +52,12 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src, } static void -do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len) +do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, + int both_ways) { size_t i, j; char *s1, *s2; - + size_t repeats; align1 &= 4095; if (align1 + len >= page_size) return; @@ -68,20 +69,27 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len) s1 = (char *) (buf1 + align1); s2 = (char *) (buf2 + align2); - for (i = 0, j = 1; i < len; i++, j += 23) - s1[i] = j; + for (repeats = both_ways ? 2 : 1; repeats; --repeats) + { + for (i = 0, j = 1; i < len; i++, j += 23) + s1[i] = j; - json_element_object_begin (json_ctx); - json_attr_uint (json_ctx, "length", (double) len); - json_attr_uint (json_ctx, "align1", (double) align1); - json_attr_uint (json_ctx, "align2", (double) align2); - json_array_begin (json_ctx, "timings"); + json_element_object_begin (json_ctx); + json_attr_uint (json_ctx, "length", (double) len); + json_attr_uint (json_ctx, "align1", (double) align1); + json_attr_uint (json_ctx, "align2", (double) align2); + json_attr_uint (json_ctx, "dst > src", (double) (s2 > s1)); + json_array_begin (json_ctx, "timings"); - FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, s2, s1, len); + FOR_EACH_IMPL (impl, 0) + do_one_test (json_ctx, impl, s2, s1, len); - json_array_end (json_ctx); - json_element_object_end (json_ctx); + json_array_end (json_ctx); + json_element_object_end (json_ctx); + + s1 = (char *) (buf2 + align1); + s2 = (char *) (buf1 + align2); + } } int @@ -109,14 +117,14 @@ test_main (void) json_array_begin (&json_ctx, "results"); for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) { - do_test (&json_ctx, 0, 0, i + 7); - do_test (&json_ctx, 0, 3, i + 15); - do_test (&json_ctx, 3, 0, i + 31); - do_test (&json_ctx, 3, 5, i + 63); - do_test (&json_ctx, 0, 127, i); - do_test (&json_ctx, 0, 255, i); - do_test (&json_ctx, 0, 256, i); - do_test (&json_ctx, 0, 4064, i); + do_test (&json_ctx, 0, 0, i + 7, 1); + do_test (&json_ctx, 0, 3, i + 15, 1); + do_test (&json_ctx, 3, 0, i + 31, 1); + do_test (&json_ctx, 3, 5, i + 63, 1); + do_test (&json_ctx, 0, 127, i, 1); + do_test (&json_ctx, 0, 255, i, 1); + do_test (&json_ctx, 0, 256, i, 1); + do_test (&json_ctx, 0, 4064, i, 1); } json_array_end (&json_ctx); diff --git a/benchtests/bench-memcpy-walk.c b/benchtests/bench-memcpy-walk.c index b04d8ac0ed..610529ef1b 100644 --- a/benchtests/bench-memcpy-walk.c +++ b/benchtests/bench-memcpy-walk.c @@ -66,17 +66,30 @@ 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 len) +do_test (json_ctx_t *json_ctx, size_t len, int both_ways) { - json_element_object_begin (json_ctx); - json_attr_uint (json_ctx, "length", (double) len); - json_array_begin (json_ctx, "timings"); - FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, len); + char *s1, *s2; + size_t repeats; + s1 = (char *) (buf1); + s2 = (char *) (buf2); + + for (repeats = both_ways ? 2 : 1; repeats; --repeats) + { + json_element_object_begin (json_ctx); + json_attr_uint (json_ctx, "length", (double) len); + json_attr_uint (json_ctx, "dst > src", (double) (s2 > s1)); + json_array_begin (json_ctx, "timings"); - json_array_end (json_ctx); - json_element_object_end (json_ctx); + FOR_EACH_IMPL (impl, 0) + do_one_test (json_ctx, impl, s2, s1, len); + + json_array_end (json_ctx); + json_element_object_end (json_ctx); + + s1 = (char *) (buf2); + s2 = (char *) (buf1); + } } int @@ -103,8 +116,8 @@ test_main (void) json_array_begin (&json_ctx, "results"); for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) { - do_test (&json_ctx, i); - do_test (&json_ctx, i + 1); + do_test (&json_ctx, i, 1); + do_test (&json_ctx, i + 1, 1); } json_array_end (&json_ctx); diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c index 184495d539..d9236a2282 100644 --- a/benchtests/bench-memcpy.c +++ b/benchtests/bench-memcpy.c @@ -54,11 +54,12 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src, } static void -do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len) +do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, + int both_ways) { size_t i, j; char *s1, *s2; - + size_t repeats; align1 &= 63; if (align1 + len >= page_size) return; @@ -70,20 +71,27 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len) s1 = (char *) (buf1 + align1); s2 = (char *) (buf2 + align2); - for (i = 0, j = 1; i < len; i++, j += 23) - s1[i] = j; + for (repeats = both_ways ? 2 : 1; repeats; --repeats) + { + for (i = 0, j = 1; i < len; i++, j += 23) + s1[i] = j; - json_element_object_begin (json_ctx); - json_attr_uint (json_ctx, "length", (double) len); - json_attr_uint (json_ctx, "align1", (double) align1); - json_attr_uint (json_ctx, "align2", (double) align2); - json_array_begin (json_ctx, "timings"); + json_element_object_begin (json_ctx); + json_attr_uint (json_ctx, "length", (double) len); + json_attr_uint (json_ctx, "align1", (double) align1); + json_attr_uint (json_ctx, "align2", (double) align2); + json_attr_uint (json_ctx, "dst > src", (double) (s2 > s1)); + json_array_begin (json_ctx, "timings"); - FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, s2, s1, len); + FOR_EACH_IMPL (impl, 0) + do_one_test (json_ctx, impl, s2, s1, len); - json_array_end (json_ctx); - json_element_object_end (json_ctx); + json_array_end (json_ctx); + json_element_object_end (json_ctx); + + s1 = (char *) (buf2 + align1); + s2 = (char *) (buf1 + align2); + } } int @@ -111,46 +119,46 @@ test_main (void) json_array_begin (&json_ctx, "results"); for (i = 0; i < 18; ++i) { - do_test (&json_ctx, 0, 0, 1 << i); - do_test (&json_ctx, i, 0, 1 << i); - do_test (&json_ctx, 0, i, 1 << i); - do_test (&json_ctx, i, i, 1 << i); + do_test (&json_ctx, 0, 0, 1 << i, 1); + do_test (&json_ctx, i, 0, 1 << i, 1); + do_test (&json_ctx, 0, i, 1 << i, 1); + do_test (&json_ctx, i, i, 1 << i, 1); } for (i = 0; i < 32; ++i) { - do_test (&json_ctx, 0, 0, i); - do_test (&json_ctx, i, 0, i); - do_test (&json_ctx, 0, i, i); - do_test (&json_ctx, i, i, i); + do_test (&json_ctx, 0, 0, i, 0); + do_test (&json_ctx, i, 0, i, 0); + do_test (&json_ctx, 0, i, i, 0); + do_test (&json_ctx, i, i, i, 0); } for (i = 3; i < 32; ++i) { if ((i & (i - 1)) == 0) continue; - do_test (&json_ctx, 0, 0, 16 * i); - do_test (&json_ctx, i, 0, 16 * i); - do_test (&json_ctx, 0, i, 16 * i); - do_test (&json_ctx, i, i, 16 * i); + do_test (&json_ctx, 0, 0, 16 * i, 1); + do_test (&json_ctx, i, 0, 16 * i, 1); + do_test (&json_ctx, 0, i, 16 * i, 1); + do_test (&json_ctx, i, i, 16 * i, 1); } for (i = 32; i < 64; ++i) { - do_test (&json_ctx, 0, 0, 32 * i); - do_test (&json_ctx, i, 0, 32 * i); - do_test (&json_ctx, 0, i, 32 * i); - do_test (&json_ctx, i, i, 32 * i); + do_test (&json_ctx, 0, 0, 32 * i, 1); + do_test (&json_ctx, i, 0, 32 * i, 1); + do_test (&json_ctx, 0, i, 32 * i, 1); + do_test (&json_ctx, i, i, 32 * i, 1); } - do_test (&json_ctx, 0, 0, getpagesize ()); + do_test (&json_ctx, 0, 0, getpagesize (), 1); for (i = 0; i <= 32; ++i) { - do_test (&json_ctx, 0, 0, 2048 + 64 * i); - do_test (&json_ctx, i, 0, 2048 + 64 * i); - do_test (&json_ctx, 0, i, 2048 + 64 * i); - do_test (&json_ctx, i, i, 2048 + 64 * i); + do_test (&json_ctx, 0, 0, 2048 + 64 * i, 1); + do_test (&json_ctx, i, 0, 2048 + 64 * i, 1); + do_test (&json_ctx, 0, i, 2048 + 64 * i, 1); + do_test (&json_ctx, i, i, 2048 + 64 * i, 1); } json_array_end (&json_ctx);