From patchwork Mon Aug 22 15:14:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 56915 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 474D6385842E for ; Mon, 22 Aug 2022 15:15:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 474D6385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661181312; bh=a+ZKpo5r9b48alNxdT4HqSdi6UcUvL2jh5MPdZQdpFc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=u/EgvDmWJ7jzRDOoHbZZlZ0tibur5Jn4K7uvquBX2VtSfhNjVIKVjbOyI6/GnlhlL dvgoCUNZV3ropyR6NTjCWDjPn+uqCHeZnv3LFzjbbPrPZvRzeFolRdGIT2rppxHmxi E5Pl5VWiajD7QI1dRpSuAuyVUncbRVP22r8+9HRs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60060.outbound.protection.outlook.com [40.107.6.60]) by sourceware.org (Postfix) with ESMTPS id 2B1793858D32 for ; Mon, 22 Aug 2022 15:14:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B1793858D32 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=RqUim8o9KTvWfZGU08MOEtc3kTFl/56OnPBCdi1G79Tf/KmJ9WE/k/OGBOpKjrtX4sm4679R3vuIGoi2oojm/H4euiorxDaCJ7AtDgHRO1G3P04pdHaQ54TLVHEVmDreLGFvcrIk3zNLcASpxsRrTUJiEBaXfUaQOMjb5lL7PxSjLQ7Wom3fB4WDrI9AakXjec16XjDmlZOFwxT2xvlQsTxnTU5E3ppgKRcGcYxNopLMZi8EHCk/aAxsGcsXEmvxPwSbocQLynujEW8oQMLrSm9F0SuWeD/yPkApVNKv2zHMcR07qCoLSRA+LbY+UUp2P6cKe4zqXx5Bs8huGqTYQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=a+ZKpo5r9b48alNxdT4HqSdi6UcUvL2jh5MPdZQdpFc=; b=n14+sd0Q9hmq2ThjKVceuU2tT2y294X4RiJ9l+w/h9Iht+Ij47JNDT/Fkl5Qif6czy6Ybco+U3YYuVLmWCkS5a1o2+5jB9yjoGBsh6bU4fk23KC+YKdfPn9kqAV9Qn7U9BP7giyDhlQTzxttyngh5gL25zthoHjxYFAULokPA88FnQlxB2pdlNhPY+mE118sO9Mc1ZPN6dmIP5T5M/13PMrtxnVRs0IOZffk0fBWaZKrLTG2mpb9ZexDGrvpz7Q6x6vD/VZTdGqx14VnXKqWQko+SOL5mcUHwUnWgxOLTGlK2AWOoLiurZ8QV1YC8ebHEfGGVU7GT8HZZ8Lyxn+fqQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DU2PR04CA0056.eurprd04.prod.outlook.com (2603:10a6:10:234::31) by AM6PR08MB3288.eurprd08.prod.outlook.com (2603:10a6:209:47::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Mon, 22 Aug 2022 15:14:43 +0000 Received: from DBAEUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:234:cafe::d3) by DU2PR04CA0056.outlook.office365.com (2603:10a6:10:234::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.22 via Frontend Transport; Mon, 22 Aug 2022 15:14:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass 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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT060.mail.protection.outlook.com (100.127.142.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.15 via Frontend Transport; Mon, 22 Aug 2022 15:14:43 +0000 Received: ("Tessian outbound 73dd6a25223d:v123"); Mon, 22 Aug 2022 15:14:43 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cd89cb9aa9b06d7e X-CR-MTA-TID: 64aa7808 Received: from 726d3f4b5133.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 79060312-1550-4503-B3A5-195F27314145.1; Mon, 22 Aug 2022 15:14:36 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 726d3f4b5133.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 22 Aug 2022 15:14:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KkCqVgHlLo9BXGmf6Yw1vjqhuRCpW4iMB0IDR0evalV6fbjzd448oXUyqe2mD6Lyv3E3eXKWe38dzz+Grxx4AXj61c43AP2OjpXvw7p5GqtUqIBgrTLd6r6N4YILuv5hVkJUnuDM5sas7TqC7W8ZFwOc2n+K0SapbBgk0riyUw5DFRszbEfjtqZUWQrTWOcxuA0qysYJqbtKrKXA+od+RzncPwciu4F4D3J0eozzX9P1+jO5XUX3b4V78SvWC+hbO4c7IByXZyCI9mygfa1xYvh7rAlOH3/k2ZQuumA55RcYXrhUTh3oqiNo4abF3C6RS7/ocHjZ9O2NRD6ev59TGQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=a+ZKpo5r9b48alNxdT4HqSdi6UcUvL2jh5MPdZQdpFc=; b=flIFK7UkFO0kgcVz3MjpHU2PK+8QIVOZYSnBDN6EFDQqGnTuzx+NB7KcAiwB7I8V7Kdd0IguF6N93ZswR+yK1CRUaTKV3Z66zFOcR+oa4slrTbA2C070sAFROQ+B1UD3lg85jp1QQ31YE6821R203xrqGQ7ivOBoe6hECJN1UPkRzI/6clovEuz7fe35zHtQoWaqjpzrwWiTaJ+1O2AIpH8lgk+oh3tgwvMFvqJ4ox0v4FlZWm1Ikj8UFhVN2HrLd+jMUWGyf7KB6CWq3Ql9fM0VEntS9KYqrsJ9WX8z4OXBqmsdnxmQemtzBoVjFDpBg90LMcDTgqcdMpjVR0GKAw== 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 Received: from AM5PR0801MB1668.eurprd08.prod.outlook.com (2603:10a6:203:3c::14) by GV1PR08MB8108.eurprd08.prod.outlook.com (2603:10a6:150:93::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.22; Mon, 22 Aug 2022 15:14:32 +0000 Received: from AM5PR0801MB1668.eurprd08.prod.outlook.com ([fe80::e434:1b13:e8ed:9e14]) by AM5PR0801MB1668.eurprd08.prod.outlook.com ([fe80::e434:1b13:e8ed:9e14%12]) with mapi id 15.20.5546.022; Mon, 22 Aug 2022 15:14:32 +0000 To: 'GNU C Library' Subject: [PATCH v2] Add random locking benchmark Thread-Topic: [PATCH v2] Add random locking benchmark Thread-Index: AQHYtjmErPPmS0gWSE6HojYzdbLo9g== Date: Mon, 22 Aug 2022 15:14:32 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-MS-Office365-Filtering-Correlation-Id: 0d5a982c-1314-408b-7c22-08da84510aa6 x-ms-traffictypediagnostic: GV1PR08MB8108:EE_|DBAEUR03FT060:EE_|AM6PR08MB3288:EE_ x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: S1WAuE9V41LIw51ZhvkkBk+HaZQNzXCjgNujMVkRcwtJm4r8grixlD+e4c/VbY9SByRzv+AnT5yoPoxGEMipOlzlqwKD4UIoNhLFrTyF/3NEbjPC3oQfeEtEbO2nGQa4wjJVAfNHO71czAmRaqvlUIocsnxEDGKqOGGl7cLqva0QI5Ou4FrdxXrhWqyP0Z41TQZ+TC1gFpvNW7GR/5GY3ZR1fxYQj3CWM1+a3pn+66C7/8leQMLpoKWSSpyV4ZsHZCMcKTCllhZlUymZXTK5cecDjtR2H1JCkok7OoMDc59EF4K3u7QF22bwMKUf1gsspg/SuFRnH8lppIVgiIiIyQCfLTNy+8Tqz4KiVlTQzzDWovQMsgxryrlB41NVceQmmAUsg9GYsRYZKku5taL4bWGqJ/JtoiYtI0523PSTOCyHAt74ZkeVGFHh0rlmGEgDUFZngX5GGAh1gA/aKcBjiGakeDipZY98SViKZcHGl8zuv0mIVOa+67K55eyT8VWsi5gi5qA9IkTfbt5CfMu92QwEJvilQda+M9KK6q5PXn4poqyd3Cj8aShDOu3DosjfxZ/zFBZIcsEdFOgu+arwDWwZWsn7oaw4GFoh252CDhU62TD//p3Qggkzp2IsX5JaBH/T/RxbFoMNHLIzGH1oqnSnM/a73ANHWrgANzQRikA8zRvraQnPF2+OTN3IQwODOQThqgmx8yUNvUgZevkKIXqbgnqH4dCq0RoIak522DvK7jRC3N62c7YbMY6gvqIRly+3699eYvSI793Bq9gM6CGKPpDyqYpVFHBJuy9kp/CfLbexThEJxODZ87/ooxDq X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM5PR0801MB1668.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(136003)(396003)(39860400002)(376002)(366004)(346002)(6916009)(83380400001)(52536014)(71200400001)(9686003)(8936002)(55016003)(86362001)(2906002)(33656002)(186003)(5660300002)(66556008)(64756008)(66446008)(66476007)(66946007)(122000001)(6506007)(316002)(478600001)(7696005)(38100700002)(41300700001)(26005)(76116006)(38070700005)(8676002)(91956017)(2004002); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB8108 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 40526383-e70b-482a-eb24-08da8451040f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QJCY0qHvkxZyaeL76+T1qeEgQ17j1adL8TXDlNNvmUGUQJOTvQarfLJTKo2klkZSkUwo4lxZKhkyDwsyeOwyvbQmrDC9ZXQOhdNuWp3fOwajFm6O4JZDJYEUwQ1w1sepYlx6F2sQ28EEngs8fgQ9UGtNB9Ok5FOZVh9V7aT13hG1jYQ61QwZGjBLKphs8ehPM3IU3SpsoP0v1qpzDHELDlbFPNEnP9Ez/2q4wePspanlpUFgZF4LZ4Fcuv9GK+Bd8s9FAsd32XOtU9C9VGYMT5GQTfDsK9lSeSsbE1C5x7kkh/RVZhzhirYC9mftkj+a5h/i8RfIKaeU+Et8lFVwC0/9xDP+uWaMT0EgH7ixASQchaxVYhQodkBKxQzW59ENYlA+Wod2fZuiwOz6KsXdp+nvQaz0hFwRXtfTiW8yd+P2LmgDKmkFepJ9hZz8vkS1nFNNBVa4LxiJARkJxMAWaZWfMUnbWTvSFU4L2chfUJRnmiLEXFEohTuZhCxXzTvNGOopcBaJSCM9NHsVquM20YymV2pywrC+y9fxk3toipHBykBCtT0Xxff8dXvaKmlfEojqgJh1e0+N71qCTgnm7JNxb9GR7r1OgXgtlAjeLJvRiSbOdnvz4Ix3hC8k1ySKKmKXyH6cntfOGqM/V+USBEf2Z723+rdG0VUQt4jKv2JMiyWZr9pk+vswOoPXo6xCRQOiQYjV+KDMNxwOo99mDonkqXtDMN79Ty9URVNzVFDzTuYuAPgJCpSpSOfePzhKHwHQUKquUJaA2eI+2gcKN+U+lJmoTn+Nn9bbEC4OtefLfV/YX3CWVIWB/WOtKeUX X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(346002)(396003)(39860400002)(46966006)(40470700004)(36840700001)(6506007)(7696005)(478600001)(336012)(47076005)(52536014)(186003)(9686003)(26005)(83380400001)(41300700001)(2906002)(8936002)(5660300002)(82310400005)(40460700003)(55016003)(40480700001)(316002)(6916009)(8676002)(70206006)(86362001)(33656002)(70586007)(81166007)(36860700001)(82740400003)(356005)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2022 15:14:43.2246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d5a982c-1314-408b-7c22-08da84510aa6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT060.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3288 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Wilco Dijkstra via Libc-alpha From: Wilco Dijkstra Reply-To: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" v2: rename as suggested, use random throughout Add a simple benchmark to measure the overhead of internal libc locks in the random() implementation on both single- and multi-threaded cases. This relies on the implementation of random using internal locks to access shared global data. diff --git a/benchtests/Makefile b/benchtests/Makefile index d99771be74b40f8afa3953f61c0721b19658d4b7..c413eac1d23568cb88bf22c6e50303e24ec10ea0 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -236,6 +236,7 @@ hash-benchset := \ stdlib-benchset := \ arc4random \ strtod \ + random-lock \ # stdlib-benchset stdio-common-benchset := sprintf diff --git a/benchtests/bench-random-lock.c b/benchtests/bench-random-lock.c new file mode 100644 index 0000000000000000000000000000000000000000..13c8e77cbd3538bb1a15f81def0a2c41a3763729 --- /dev/null +++ b/benchtests/bench-random-lock.c @@ -0,0 +1,102 @@ +/* Benchmark internal libc locking functions used in random. + Copyright (C) 2022 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 "random-lock" + +#include +#include +#include +#include "bench-timing.h" +#include "json-lib.h" + +#define NUM_ITERS 20000000 + +json_ctx_t json_ctx; + + +/* Measure the overhead of __libc_lock_lock and __libc_lock_unlock by + calling random (). */ +static void +bench_random_lock (size_t iters) +{ + timing_t start, stop, total; + + srandom (0); + for (int i = 0; i < iters / 4; i++) + (void) random (); + + TIMING_NOW (start); + + for (int i = 0; i < iters; i++) + (void) random (); + + TIMING_NOW (stop); + + TIMING_DIFF (total, start, stop); + + json_element_double (&json_ctx, (double) total / (double) iters); +} + +static void * +thread_start (void *p) +{ + return p; +} + +int +do_bench (void) +{ + 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, "random"); + json_attr_string (&json_ctx, "bench-variant", "single-threaded"); + json_array_begin (&json_ctx, "results"); + + /* Run benchmark single threaded. */ + bench_random_lock (NUM_ITERS); + + json_array_end (&json_ctx); + json_attr_object_end (&json_ctx); + + json_attr_object_begin (&json_ctx, "random"); + json_attr_string (&json_ctx, "bench-variant", "multi-threaded"); + json_array_begin (&json_ctx, "results"); + + pthread_t t; + pthread_create (&t, NULL, thread_start, NULL); + pthread_join (t, NULL); + + /* Repeat benchmark now SINGLE_THREAD_P == false. */ + bench_random_lock (NUM_ITERS); + + json_array_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_document_end (&json_ctx); + return 0; +} + +#define TEST_FUNCTION do_bench () + +#include "../test-skeleton.c" +