From patchwork Fri Jun 3 12:34:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 629789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rLk865HYNz9t7r for ; Fri, 3 Jun 2016 22:35:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=naDdqi9P; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=ntMEf6GBEZOVBTFI yVWNDkpLN7jXrUguYAPo9ij+6Hn8DIbexCWsWUQtW59bFGOU3R3Ht2VPLsu1L2oD K2A+3Uw5wAxB4LpVPsAfj2wb4TtWsBBv43EEuYLWB32cqdMlT0XuOA6VVbW9VZfZ MEJL6WdciKm+tvk+0cXib1OrNgI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:mime-version:content-type :content-transfer-encoding; s=default; bh=BRkBmW8kLiAZuHcOT6rH23 4BITY=; b=naDdqi9PrFUKvbu/4AXIpkqaYAyYj407YNWpDWER7C5+/yo8L3c4+E pHLQfuUlZizGVmBQtArn1q3h+QPqLJuJAuhGzSRgC2dbD/aMf/AyvdiuKiH61cbr 4h0xH2W9MCJjuB3ehYK5F4THVes+3sdlCb2/0vFLq8d4+Yo9vioVM= Received: (qmail 117199 invoked by alias); 3 Jun 2016 12:35:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 117187 invoked by uid 89); 3 Jun 2016 12:35:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=20160511, 2016-05-11, Measure, favors X-HELO: eu-smtp-delivery-143.mimecast.com From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: Re: [PATCH] Add random memcpy test Date: Fri, 3 Jun 2016 12:34:55 +0000 Message-ID: References: , In-Reply-To: x-ms-office365-filtering-correlation-id: 3940e1ac-17b7-48fc-fabc-08d38bab783b x-microsoft-exchange-diagnostics: 1; DB3PR08MB0089; 5:jAmg/L4sIRTZ1e3Gi3B6RLeEpRvrqnjDHf9rzB/72WpFxRYYhANCAlLBwjC1GP4S75EIZ31XF2PBgKPuWEsmgXrtB8YpkB6eE4htneLFD7kTfasW1mqjvJu7VQZt8u/PBvpxP56CdEmCZbwCatFYlw==; 24:qfs43HbWKeoWC/CfaYDXX50vibj743w1hktS7RhnMW3Z7Zgkai9WtUmmhj/M7DIE/ebdUG5wQc8wC0dUFH39voKmXLD7xZO5YwQEzVZ39Ys=; 7:jffEfhiLyfKbKloo+8rrulyX4QUvkeIF67JV47e/TPFO0aGUGHwAyLkJSUJVBTJPCcVkV3HaeZp8OHPkxr8VqzCMIh3yZgLvyAcGxrbmKaSzHGFhrBNSZLUer3urYQpVz4PQs/iMkD6KBb49jI4T3GXlLHA/Afuyrjm/WniSbXDRJyPXwHlEaNLMKZ5Msm2tfN6i3h9UKmzwb4Fi2xfiSHzH+3pHcMil6PpOHCiFlow=; 20:byvWrXfFWT216PA8sXtGLoTYNyqWOIFD+5J+9mTu//vFnA2aE5gdRSf0tncoIrP2BD5ItNJkLEE/HmK9sQo6sfHZaLAdznS4dwujd6G56TVOM2UuogqZOcpkrj9vcSQoMX0ysghbhCO5W3Mkool4to4B1dNJ5tYHmIn1PsONs2A= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB3PR08MB0089; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(250305191791016)(180628864354917)(22074186197030); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:DB3PR08MB0089; BCL:0; PCL:0; RULEID:; SRVR:DB3PR08MB0089; x-forefront-prvs: 0962D394D2 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(54534003)(377424004)(19580405001)(19580395003)(33656002)(5008740100001)(81166006)(189998001)(3900700001)(3660700001)(586003)(50986999)(54356999)(76176999)(8676002)(102836003)(2900100001)(6116002)(3846002)(2906002)(450100001)(4326007)(66066001)(3280700002)(106116001)(74316001)(92566002)(5003600100002)(5004730100002)(76576001)(11100500001)(86362001)(8936002)(575784001)(87936001)(77096005)(2950100001)(110136002)(15975445007)(9686002)(122556002)(5002640100001)(10400500002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR08MB0089; H:DB3PR08MB0089.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jun 2016 12:34:55.8643 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR08MB0089 X-MC-Unique: OYBjd_mERz6UU84Y3biFCg-1 ping diff --git a/benchtests/Makefile b/benchtests/Makefile index 61077ea9b6f7d4c342192429a8d90ecdf9bdaea7..03311dd72856bf0e595a759b817cb772f0fd3a6f 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -38,7 +38,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \ strcat strchr strchrnul strcmp strcpy strcspn strlen \ strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \ strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \ - strcoll memcpy-large memmove-large memset-large + strcoll memcpy-large memcpy-random memmove-large memset-large wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \ wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \ wmemchr wmemset wmemcmp diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c new file mode 100644 index 0000000000000000000000000000000000000000..668d6a1d35074f4227be4e1ff424da556a377cef --- /dev/null +++ b/benchtests/bench-memcpy-random.c @@ -0,0 +1,130 @@ +/* Measure memcpy functions. + Copyright (C) 2016 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 MIN_PAGE_SIZE 131072 +#define TEST_MAIN +#define TEST_NAME "memcpy-random" +#include "bench-string.h" + +IMPL (memcpy, 0) + +#define NUM_COPIES 2048 +#define NUM_DISTR 1024 + +typedef struct +{ + uint16_t src; + uint16_t dst; + uint16_t len; +} copy_t; + +static copy_t copy[NUM_COPIES]; +static uint8_t copy_distribution[NUM_DISTR]; + +typedef char *(*proto_t) (char *, const char *, size_t); + + +static void +init_copy_distribution (void) +{ + int i, n, pos = 0; + for (i = 0; i < 256; i++) + { + if (i < 8) + n = 1; + else if (i < 16) + n = 8; + else if (i < 32) + n = 6; + else if (i < 64) + n = 4; + else if (i < 128) + n = 2; + else + n = 1; + + if ((i & 15) == 0) + n = n * 7; + else if ((i & 7) == 0) + n = n * 5; + else if ((i & 3) == 0) + n = n * 3; + + for ( ; n > 0 && pos < NUM_DISTR; n--) + copy_distribution[pos++] = i; + } + for ( ; pos < NUM_DISTR; pos++) + copy_distribution[pos] = 255; +} + +static void +do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n) +{ + timing_t start, stop, cur; + size_t iters = INNER_LOOP_ITERS * 20; + + 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, copy[j].len); + TIMING_NOW (stop); + + TIMING_DIFF (cur, start, stop); + + TIMING_PRINT_MEAN ((double) cur, (double) iters); +} + +static void +do_test (size_t max_size) +{ + for (int i = 0; i < max_size; i++) + buf1[i] = i * 3; + + for (int i = 0; i < NUM_COPIES; i++) + { + copy[i].dst = rand () & (max_size - 1); + copy[i].src = rand () & (max_size - 1); + copy[i].len = copy_distribution[rand () & (NUM_DISTR - 1)]; + } + + printf ("Memory size %6zd:", max_size); + + FOR_EACH_IMPL (impl, 0) + do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES); + + putchar ('\n'); +} + +int +test_main (void) +{ + test_init (); + init_copy_distribution (); + + printf ("%23s", ""); + FOR_EACH_IMPL (impl, 0) + printf ("\t%s", impl->name); + putchar ('\n'); + + for (int i = 4; i <= 64; i = i * 2) + do_test (i * 1024); + + return ret; +} + +#include "../test-skeleton.c"