From patchwork Tue Aug 24 19:32:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1520422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=VydeBANq; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4GvK9j4J2rz9sWc for ; Wed, 25 Aug 2021 05:36:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56AF43857C6D for ; Tue, 24 Aug 2021 19:36:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56AF43857C6D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629833799; bh=vtR/+cqij0b5cH6cLp/K2mBFLxE3d22yRFVA52K5/zQ=; 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=VydeBANqLLr5K7I+ame75nXOgSvh+F6E2Gk/69YPZG0LN8H8NqouxiBZiCYModxJJ EA8vh09KlX7q+btqHGce0i7Exz/+xgYhQ29dWomcno6h0EwASOwq1kJ6XoZPqRlbMa OukTvAb4QaDlCLfTKq5L2iJ2irYxEiZrEqRIIYIg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 49C7E3858426 for ; Tue, 24 Aug 2021 19:32:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 49C7E3858426 Received: by mail-il1-x132.google.com with SMTP id j15so21650296ila.1 for ; Tue, 24 Aug 2021 12:32:40 -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=vtR/+cqij0b5cH6cLp/K2mBFLxE3d22yRFVA52K5/zQ=; b=Y+A/UNrruzYadflr4StuYnti8S+7WPNuowzCOJNjBlwTVZGyOA9a/weTuSyGGis8jq NKO2CzbcfQzIaLleTQ82LQuPe/+QgY89auwCTEULYuN9UxdpqaRC9hIhM1IMNJuOdhVc mPMpJkeDevLlwZzTuy2EMZIgqichGvGH26Hsuc4G40KftcTAYgc5ILU/rP++zxpL6S7O EIJ0rtvm37SuBUsTZyN9Zo3jxO9LRhKEJfWOsXsFquT0gj/zI9nCnJ2rqqgFACFpqMO3 wZM5uDL962hmndyqvct9afRBDQ1COsJxc8ntMRT4SkAC87gyds9fu5hF9ubni2RkqTpI tTmg== X-Gm-Message-State: AOAM531es2S8DsKndytjnKhWKGwgTnFN30GNRt0vRQbQSe+nOi0eASUf 1hVqR6fiU0c8AaZtCgK+2mBb52svmSvfAg== X-Google-Smtp-Source: ABdhPJz9dHpqgQnezQyclDIUd8h8r7erb5vweDcoA26nYWv3QKikvE63WB17twE1TbTwqizWJeaYeg== X-Received: by 2002:a92:611:: with SMTP id x17mr27225596ilg.41.1629833559497; Tue, 24 Aug 2021 12:32:39 -0700 (PDT) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id h10sm10224923ilj.71.2021.08.24.12.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 12:32:39 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1 2/5] benchtests: Add new random cases to bench-memcpy-random.c Date: Tue, 24 Aug 2021 15:32:24 -0400 Message-Id: <20210824193227.3474346-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824193227.3474346-1-goldstein.w.n@gmail.com> References: <20210824082753.3356637-1-goldstein.w.n@gmail.com> <20210824193227.3474346-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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+incoming=patchwork.ozlabs.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. --- benchtests/bench-memcpy-random.c | 103 +++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 11 deletions(-) diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c index c490b73ed0..eeeef42fc1 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+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; + + for (int j = 0; j < n; j++) + CALL (impl, dst + copy[j].dst, src + copy[j].src, size); + + 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_size; + } + else + { + dst_offset = max_size; + src_offset = 0; + } - memset (buf1, 1, max_size); /* 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_size : 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]; } + memset (buf1, 1, 3 * max_size); + return i; +} + +static void +do_test (json_ctx_t *json_ctx, size_t max_size, int dst_gt_src) +{ + size_t n; + n = init_copy(max_size, dst_gt_src); + json_element_object_begin (json_ctx); + json_attr_uint (json_ctx, "region-size", (double) 3 * 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 *) buf1, (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; + n = init_copy(3 * 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, "region-size", (double) 3 * 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_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, i); + do_one_fixed_test (json_ctx, impl, (char *) buf1, (char *) buf1, copy, n, size); json_array_end (json_ctx); json_element_object_end (json_ctx); } + int test_main (void) { @@ -193,8 +263,19 @@ test_main (void) json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); - for (int i = 4; i <= 512; i = i * 2) - do_test (&json_ctx, i * 1024); + for (int i = 4096; i < MAX_TEST_SIZE; i = i * 2) + { + do_test (&json_ctx, i, 0); + do_test (&json_ctx, i, 1); + do_test (&json_ctx, i, -1); + } + + for (int i = 4096; i <= 65536; i = i * 2) + { + do_test_fixed_size (&json_ctx, i, i, 0); + do_test_fixed_size (&json_ctx, i, i, 1); + do_test_fixed_size (&json_ctx, i, i, -1); + } json_array_end (&json_ctx); json_attr_object_end (&json_ctx);