From patchwork Mon Feb 10 15:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 37853 Received: (qmail 15890 invoked by alias); 10 Feb 2020 15:48:41 -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 15776 invoked by uid 89); 10 Feb 2020 15:48:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=H*RU:sk:EUR04-V, HX-HELO:sk:EUR04-V, HX-Spam-Relays-External:sk:EUR04-V X-HELO: EUR04-VI1-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r40nNP68O61+0zGH8RlTiDTjmbbgLoIWEl2A/kVUfsw=; b=6IqK7y+8cDICL6YiegVMNR9Y841wShuMlzKMdwLe3/ZTPniDatoPB/L8B1tPD1m3m3cT3y8WsBCf23M8TimGAy6jM7seOnAj9fXHgeV3YCmjWAvhYRIW/e8eV2AAXsKNmEOd2hJiFz4/ePmD2OGmV90zwJtHHdLwmt1s60Kf4Pc= Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CheckRecipientChecked: true X-CR-MTA-CID: e5807e47548adb77 X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NskwcfSDdndrw1L2c5a+K6QnwnW/jH8lxEcI39MzkUOxbZPOMVgzuAaQr5ey5U6tHCzFUKVKVnnr55jaRCkrHAQ55utHj1F8wj+4KkyBDJY8WYEuthEMLRbGJiRrUr9T0G7rczYOwBFK2UikgpJI0A82MXqNa2rb9nA11jGEDWsBP72yTJU22HCkck3utkycebBknGNNUvvIy437+p9ul8YgGeKKcJh3h4NujVIZzTYlbVUZA4Oz8o9nGxwpOLYMl3hk2qGOar2NTMLjnEPZgkoarqEiLzwynG5W1RGHlIHqLL4oDwnzUPjzfu2k9klKSMGVKrbbj9Ri5RmnelDrVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r40nNP68O61+0zGH8RlTiDTjmbbgLoIWEl2A/kVUfsw=; b=ZUF6ClNEFd11bHKF6Hcpe1YGb8gOVO+1cuci+PHziT8480uWvm/HLI3EP15HTnxleviyzVpl7txqJvKjVUqkTEyu0Q2xLJMFad5Eq7afbhmXQoU7FD5rSnWbLju9Bw+teu/WZ5HkoFvwWSCpf/Zxj5/xK+AGEDTJJW4KzKoPKHxUwTiLgYxuWV5WUbPrxktpCq0UZ097g9TYHTclGMZUSn7dorPG/EqBmtP2O9uO33G7Ghr9lRgPL+2+qL8izWGcxPAgX0ZsdryC3QNWGEChfvKXnZNHETBSUpff9pwrJYXktGnaTMIX05gGdvm6+pC5tGSia7ZPscSSmvPEdPfR0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r40nNP68O61+0zGH8RlTiDTjmbbgLoIWEl2A/kVUfsw=; b=6IqK7y+8cDICL6YiegVMNR9Y841wShuMlzKMdwLe3/ZTPniDatoPB/L8B1tPD1m3m3cT3y8WsBCf23M8TimGAy6jM7seOnAj9fXHgeV3YCmjWAvhYRIW/e8eV2AAXsKNmEOd2hJiFz4/ePmD2OGmV90zwJtHHdLwmt1s60Kf4Pc= From: Wilco Dijkstra To: 'GNU C Library' Subject: [PATCH] Improve random memcpy benchmark Date: Mon, 10 Feb 2020 15:47:58 +0000 Message-ID: Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:4941;OLM:4941; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(136003)(39860400002)(396003)(346002)(189003)(199004)(7696005)(86362001)(478600001)(71200400001)(8936002)(76116006)(6506007)(6916009)(66446008)(9686003)(66556008)(55016002)(66946007)(52536014)(316002)(66476007)(64756008)(2906002)(186003)(26005)(33656002)(8676002)(5660300002)(81166006)(81156014); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0801MB1907; H:AM5PR0801MB2035.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: CjupDDWHJiWyI59l3QU4+KQC8JXdK+sobGSD50jav779GZ2/R/ARUQnstOWLSkz7RrU9uDaph3ecuRXMOKczNtOBlC/ymy5K02Fy/Knc06Rw4OJ0UFo1HaXALb4+Ty6UQa4yT51A5kdWqtjgLkfjmO8dRUgrnJgouNIazLEAMsutNQ0jN7pNpHo14sgb87lbteP895XXYzfFGBY9wpnbPIu9fz/5rfOWbOY/ar+ZrZL4vZapn+/ZLGyaR0/82I78aTvctRiqxr0Mzis7hF9E29fS/34tEIPyAw71lDgfs0WTLuGM5Mk9ZrELj3R4MhrrX9+Rhgl6pXit1EgeSjSpXSEVsLn1cFzmJbwpxmUMxlkhjr1G2yOlLe7gNAzWghG5PAiWYJbvjGprRijs/pn1VF6kM14q3cEMZnSoQuGFnI3EoSl8VcwXI8exUjtzQITFyuwH49Fb+szvhy2wJuIGZp+EBcdB6NU7WFoEV3H13Qg1+/051IIr3BXvb1k14zErl5cOEzlBOU/XmB02OkjIgQ== x-ms-exchange-antispam-messagedata: N5Ty6FKfAyw06ftSQX4kb98nqPEDNE6zrFKIX/flodaEPaukQu8cGH3Od/owrmm4pBQzYua7i7RvbGva+DfKz/auFS23uJtBZbaevQucD1Edeez3xPf1VQ4vpU/DXCXFAcCtiYb0AKw0EEsnlqu3uA== x-ms-exchange-transport-forked: True MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; Return-Path: Wilco.Dijkstra@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: d381b506-9280-4d60-cdef-08d7ae409a59 Improve the random memcpy benchmark. Double the number of copies and increase the memory sizes tested to 512KB. Add a more detailed distribution of memcpy alignment and sizes up to 4096 based on SPEC2017 traces. diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c index d6a60a2eb014e3069b336b36d4b0797a3aa9bcce..c7b34ce3bfeb50ee611f176f6a8ccad42b216b88 100644 --- a/benchtests/bench-memcpy-random.c +++ b/benchtests/bench-memcpy-random.c @@ -16,61 +16,85 @@ License along with the GNU C Library; if not, see . */ -#define MIN_PAGE_SIZE 131072 +#define MIN_PAGE_SIZE (512*1024+4096) #define TEST_MAIN #define TEST_NAME "memcpy" #include "bench-string.h" #include #include "json-lib.h" -IMPL (memcpy, 1) +#define MAX_COPIES 8192 -#define NUM_COPIES 4096 +IMPL (memcpy, 1) typedef struct { uint16_t size; uint16_t freq; } freq_data_t; -typedef struct { uint8_t align; uint8_t freq; } align_data_t; +typedef struct { uint8_t align; uint16_t freq; } align_data_t; -#define SIZE_NUM 1024 +#define SIZE_NUM 65536 #define SIZE_MASK (SIZE_NUM-1) static uint8_t size_arr[SIZE_NUM]; -/* Frequency data for memcpy of less than 256 bytes based on SPEC2006. */ +/* Frequency data for memcpy of less than 4096 bytes based on SPEC2017. */ static freq_data_t size_freq[] = { - { 8, 576}, {104, 94}, { 24, 78}, { 48, 58}, { 32, 48}, { 16, 46}, - { 1, 30}, { 96, 12}, { 72, 11}, {216, 11}, {192, 8}, { 12, 7}, - {144, 5}, { 2, 4}, { 64, 4}, {120, 4}, { 4, 3}, { 40, 2}, - { 7, 2}, {168, 2}, {160, 2}, {128, 1}, { 3, 1}, { 9, 1}, - {176, 1}, {240, 1}, { 11, 1}, { 0, 1}, { 5, 1}, { 6, 1}, - { 80, 1}, { 52, 1}, {152, 1}, { 10, 1}, { 56, 1}, { 51, 1}, - { 14, 1}, {208, 1}, { 0, 0} +{ 32, 22320}, { 16, 9554}, { 8, 8915}, {152, 5327}, { 4, 2159}, {292, 2035}, +{ 12, 1608}, { 24, 1343}, {1152, 895}, {144, 813}, {884, 733}, {284, 721}, +{120, 661}, { 2, 649}, {882, 550}, { 5, 475}, { 7, 461}, {108, 460}, +{ 10, 361}, { 9, 361}, { 6, 334}, { 3, 326}, {464, 308}, {2048, 303}, +{ 1, 298}, { 64, 250}, { 11, 197}, {296, 194}, { 68, 187}, { 15, 185}, +{192, 184}, {1764, 183}, { 13, 173}, {560, 126}, {160, 115}, {288, 96}, +{104, 96}, {1144, 83}, { 18, 80}, { 23, 78}, { 40, 77}, { 19, 68}, +{ 48, 63}, { 17, 57}, { 72, 54}, {1280, 51}, { 20, 49}, { 28, 47}, +{ 22, 46}, {640, 45}, { 25, 41}, { 14, 40}, { 56, 37}, { 27, 35}, +{ 35, 33}, {384, 33}, { 29, 32}, { 80, 30}, {4095, 22}, {232, 22}, +{ 36, 19}, {184, 17}, { 21, 17}, {256, 16}, { 44, 15}, { 26, 15}, +{ 31, 14}, { 88, 14}, {176, 13}, { 33, 12}, {1024, 12}, {208, 11}, +{ 62, 11}, {128, 10}, {704, 10}, {324, 10}, { 96, 10}, { 60, 9}, +{136, 9}, {124, 9}, { 34, 8}, { 30, 8}, {480, 8}, {1344, 8}, +{273, 7}, {520, 7}, {112, 6}, { 52, 6}, {344, 6}, {336, 6}, +{504, 5}, {168, 5}, {424, 5}, { 0, 4}, { 76, 3}, {200, 3}, +{512, 3}, {312, 3}, {240, 3}, {960, 3}, {264, 2}, {672, 2}, +{ 38, 2}, {328, 2}, { 84, 2}, { 39, 2}, {216, 2}, { 42, 2}, +{ 37, 2}, {1608, 2}, { 70, 2}, { 46, 2}, {536, 2}, {280, 1}, +{248, 1}, { 47, 1}, {1088, 1}, {1288, 1}, {224, 1}, { 41, 1}, +{ 50, 1}, { 49, 1}, {808, 1}, {360, 1}, {440, 1}, { 43, 1}, +{ 45, 1}, { 78, 1}, {968, 1}, {392, 1}, { 54, 1}, { 53, 1}, +{ 59, 1}, {376, 1}, {664, 1}, { 58, 1}, {272, 1}, { 66, 1}, +{2688, 1}, {472, 1}, {568, 1}, {720, 1}, { 51, 1}, { 63, 1}, +{ 86, 1}, {496, 1}, {776, 1}, { 57, 1}, {680, 1}, {792, 1}, +{122, 1}, {760, 1}, {824, 1}, {552, 1}, { 67, 1}, {456, 1}, +{984, 1}, { 74, 1}, {408, 1}, { 75, 1}, { 92, 1}, {576, 1}, +{116, 1}, { 65, 1}, {117, 1}, { 82, 1}, {352, 1}, { 55, 1}, +{100, 1}, { 90, 1}, {696, 1}, {111, 1}, {880, 1}, { 79, 1}, +{488, 1}, { 61, 1}, {114, 1}, { 94, 1}, {1032, 1}, { 98, 1}, +{ 87, 1}, {584, 1}, { 85, 1}, {648, 1}, {0, 0} }; -#define ALIGN_NUM 256 +#define ALIGN_NUM 1024 #define ALIGN_MASK (ALIGN_NUM-1) static uint8_t src_align_arr[ALIGN_NUM]; static uint8_t dst_align_arr[ALIGN_NUM]; -/* Source alignment frequency for memcpy based on SPEC2006. */ +/* Source alignment frequency for memcpy based on SPEC2017. */ static align_data_t src_align_freq[] = { - {16, 144}, {8, 86}, {3, 23}, {1, 3}, {0, 0} + {8, 300}, {16, 292}, {32, 168}, {64, 153}, {4, 79}, {2, 14}, {1, 18}, {0, 0} }; -/* Destination alignment frequency for memcpy based on SPEC2006. */ +/* Destination alignment frequency for memcpy based on SPEC2017. */ static align_data_t dst_align_freq[] = { - {16, 197}, {8, 30}, {3, 23}, {1, 6}, {0, 0} + {8, 265}, {16, 263}, {64, 209}, {32, 174}, {4, 90}, {2, 10}, {1, 13}, {0, 0} }; typedef struct { - uint16_t src; - uint16_t dst; - uint16_t len; + uint64_t src : 24; + uint64_t dst : 24; + uint64_t len : 16; } copy_t; -static copy_t copy[NUM_COPIES]; +static copy_t copy[MAX_COPIES]; typedef char *(*proto_t) (char *, const char *, size_t); @@ -103,6 +127,9 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src, timing_t start, stop, cur; size_t iters = INNER_LOOP_ITERS_MEDIUM; + for (int j = 0; j < n; j++) + CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len); + TIMING_NOW (start); for (int i = 0; i < iters; ++i) for (int j = 0; j < n; j++) @@ -117,16 +144,17 @@ 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) { - for (int i = 0; i < max_size; i++) - buf1[i] = i * 3; + int i; + + memset (buf1, 1, max_size); /* Create a random set of copies with the given size and alignment distributions. */ - for (int i = 0; i < NUM_COPIES; i++) + for (i = 0; i < MAX_COPIES; i++) { - copy[i].dst = (rand () & (max_size - 1)) | 1; + copy[i].dst = (rand () & (max_size - 1)); copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK]; - copy[i].src = (rand () & (max_size - 1)) | 3; + copy[i].src = (rand () & (max_size - 1)); copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK]; copy[i].len = size_arr[rand () & SIZE_MASK]; } @@ -136,7 +164,7 @@ do_test (json_ctx_t *json_ctx, size_t max_size) json_array_begin (json_ctx, "timings"); FOR_EACH_IMPL (impl, 0) - do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES); + do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, i); json_array_end (json_ctx); json_element_object_end (json_ctx); @@ -165,7 +193,7 @@ test_main (void) json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); - for (int i = 4; i <= 64; i = i * 2) + for (int i = 4; i <= 512; i = i * 2) do_test (&json_ctx, i * 1024); json_array_end (&json_ctx);