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: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 A36CB1F5AE for ; Tue, 20 Jul 2021 06:35:38 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5303398580D for ; Tue, 20 Jul 2021 06:35:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5303398580D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626762937; bh=ynxQCmjt/FnjC/ZI7KIu0TgdtKzdlC8OP2hUFgP6FmA=; 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=hSao8B6waiCcXqMgpPRRHLKLRoGWHZFhWtomrwuHHPSyEQExm+2Cv02lwvy53pBDL +9lBpBi0LpBsWfQTEVHK93EFhZ/SHR6BrIz9HDLhZXXDXlzsKvhD2OJlQqATkMSOIP f4Q7KXAkvSiIp+BM4VAO7Tb5XX2x9HeaDFGwREDw= Received: from esa9.hc1455-7.c3s2.iphmx.com (esa9.hc1455-7.c3s2.iphmx.com [139.138.36.223]) by sourceware.org (Postfix) with ESMTPS id 8A7973985808 for ; Tue, 20 Jul 2021 06:35:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A7973985808 IronPort-SDR: j9edmNf3mAQ1ZIcmX0zDIB/5ZUl9YV9yLE8bEk3b9DTf3sV1ojHnfbT1gKUYnCOBZFXMhIlfMJ EbK/NFmM8R52tKOL7f5tNut9as8Vq4vjfnyjCjEOlLbify2nIBrS0vftKPgKPAxjzawRv/9DO5 vHf59in3mkFl7p6CmVRiKsBPiCA9QOlzdgJvp05RwSgygeC3Aw4MUUayWW01dv4x1RMSFHxzvC PXOZ6LVd9IVQLpfwosz5/r1cjyM+4gukYaQ8YKurzgs9V26c3Y+UxnJP2ITtKZWjARWPaIF6+C vIrOZM8felspxHC2qz887r8+ X-IronPort-AV: E=McAfee;i="6200,9189,10050"; a="25295082" X-IronPort-AV: E=Sophos;i="5.84,254,1620658800"; d="scan'208";a="25295082" Received: from unknown (HELO oym-r4.gw.nic.fujitsu.com) ([210.162.30.92]) by esa9.hc1455-7.c3s2.iphmx.com with ESMTP; 20 Jul 2021 15:35:07 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 0C82532F7C6 for ; Tue, 20 Jul 2021 15:35:07 +0900 (JST) Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 32B8942C3EF for ; Tue, 20 Jul 2021 15:35:06 +0900 (JST) Received: from bionic.lxd (unknown [10.126.53.116]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id 0ED99A2; Tue, 20 Jul 2021 15:35:06 +0900 (JST) To: Noah Goldstein , Wilco Dijkstra , "Lucas A. M. Magalhaes" , libc-alpha@sourceware.org Subject: [PATCH v2 2/5] benchtests: Add memset zero fill benchtest Date: Tue, 20 Jul 2021 06:35:00 +0000 Message-Id: <20210720063500.362313-1-naohirot@fujitsu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210713082214.307529-1-naohirot@fujitsu.com> References: <20210713082214.307529-1-naohirot@fujitsu.com> X-TM-AS-GCONF: 00 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: Naohiro Tamura via Libc-alpha Reply-To: Naohiro Tamura Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Memset takes 0 as the second parameter in most cases. However, we cannot measure the zero fill performance by bench-memset.c and bench-memset-large.c precisely. X86_64 micro-architecture has some zero-over-zero optimization, and AArch64 micro-architecture also has some optimization for DC ZVA instruction. This patch provides bench-memset-zerofill.c which is suitable to analyze the zero fill performance by zero-over-zero and zero-over-one test cases from 16KB(L1), through L2 and L3, to 64MB(RAM). --- benchtests/Makefile | 2 +- benchtests/bench-memset-zerofill.c | 128 +++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 benchtests/bench-memset-zerofill.c diff --git a/benchtests/Makefile b/benchtests/Makefile index 1530939a8ce8..21b95c736190 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -53,7 +53,7 @@ string-benchset := memccpy memchr memcmp memcpy memmem memmove \ strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \ strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \ strcoll memcpy-large memcpy-random memmove-large memset-large \ - memcpy-walk memset-walk memmove-walk + memcpy-walk memset-walk memmove-walk memset-zerofill # Build and run locale-dependent benchmarks only if we're building natively. ifeq (no,$(cross-compiling)) diff --git a/benchtests/bench-memset-zerofill.c b/benchtests/bench-memset-zerofill.c new file mode 100644 index 000000000000..2579b6edd09e --- /dev/null +++ b/benchtests/bench-memset-zerofill.c @@ -0,0 +1,128 @@ +/* Measure memset functions with zero fill data. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define TEST_MAIN +#define TEST_NAME "memset" +#define START_SIZE (16 * 1024) +#define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024) +#define TIMEOUT (20 * 60) +#include "bench-string.h" + +#include "json-lib.h" + +void *generic_memset (void *, int, size_t); +typedef void *(*proto_t) (void *, int, size_t); + +IMPL (MEMSET, 1) +IMPL (generic_memset, 0) + +static void +do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, + int c1 __attribute ((unused)), int c2 __attribute ((unused)), + size_t n) +{ + size_t i, iters = 16; + timing_t start, stop, cur; + + TIMING_NOW (start); + for (i = 0; i < iters; i += 2) + { + CALL (impl, s, c1, n); + CALL (impl, s, c2, n); + } + TIMING_NOW (stop); + + TIMING_DIFF (cur, start, stop); + + json_element_double (json_ctx, (double) cur / (double) iters); +} + +static void +do_test (json_ctx_t *json_ctx, size_t align, int c1, int c2, size_t len) +{ + align &= 63; + if ((align + len) * sizeof (CHAR) > page_size) + return; + + json_element_object_begin (json_ctx); + json_attr_uint (json_ctx, "length", len); + json_attr_uint (json_ctx, "alignment", align); + json_attr_int (json_ctx, "char1", c1); + json_attr_int (json_ctx, "char2", c2); + json_array_begin (json_ctx, "timings"); + + FOR_EACH_IMPL (impl, 0) + { + do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c1, c2, len); + alloc_bufs (); + } + + json_array_end (json_ctx); + json_element_object_end (json_ctx); +} + +int +test_main (void) +{ + json_ctx_t json_ctx; + size_t i; + int c1, c2; + + test_init (); + + json_init (&json_ctx, 0, stdout); + + json_document_begin (&json_ctx); + json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); + + json_attr_object_begin (&json_ctx, "functions"); + json_attr_object_begin (&json_ctx, TEST_NAME); + json_attr_string (&json_ctx, "bench-variant", "zerofill"); + + json_array_begin (&json_ctx, "ifuncs"); + FOR_EACH_IMPL (impl, 0) + json_element_string (&json_ctx, impl->name); + json_array_end (&json_ctx); + + json_array_begin (&json_ctx, "results"); + + c2 = 0; + for (c1 = 0; c1 < 2; c1++) + for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) + { + do_test (&json_ctx, 0, c1, c2, i); + do_test (&json_ctx, 3, c1, c2, i); + } + + json_array_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_document_end (&json_ctx); + + return ret; +} + +#include + +#define libc_hidden_builtin_def(X) +#define libc_hidden_def(X) +#define libc_hidden_weak(X) +#define weak_alias(X,Y) +#undef MEMSET +#define MEMSET generic_memset +#include -- 2.17.1