From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2056.outbound.protection.outlook.com [40.107.20.56]) by sourceware.org (Postfix) with ESMTPS id 10B34385134B for ; Fri, 9 Dec 2022 13:59:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10B34385134B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.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=tmECx3VYLpfySrBrO6ij7tREpMQFUWwJsnt1Te8wgH4=; b=nkTpmhEaHTzTk0TVLfPhVIYfi31x3kp51TKKzIx7GMOzDstQP8LgcX76EeuT9r7++f+cZR2aSZTDhJthI7fPQT8hZG2T9+3u5tRM4K8Z21l+btLv/PKxG/ig5llG/VP3m6nQfsFelkX3hK4RMbLLnG2ZrhAcTlUzYTWzaAvRMtQ= Received: from DU2PR04CA0083.eurprd04.prod.outlook.com (2603:10a6:10:232::28) by AS2PR08MB10268.eurprd08.prod.outlook.com (2603:10a6:20b:648::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Fri, 9 Dec 2022 13:59:22 +0000 Received: from DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:232:cafe::80) by DU2PR04CA0083.outlook.office365.com (2603:10a6:10:232::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8 via Frontend Transport; Fri, 9 Dec 2022 13:59:22 +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 DBAEUR03FT008.mail.protection.outlook.com (100.127.142.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.17 via Frontend Transport; Fri, 9 Dec 2022 13:59:21 +0000 Received: ("Tessian outbound f394866f3f2b:v130"); Fri, 09 Dec 2022 13:59:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c1f621126b431604 X-CR-MTA-TID: 64aa7808 Received: from 8b70ad1b1761.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 41D8B456-9E21-484F-BA65-C4CDD6F83BCD.1; Fri, 09 Dec 2022 13:59:15 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8b70ad1b1761.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 09 Dec 2022 13:59:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f3cfhuQTPMZxgSlW+K0U1tJtHMNvLIK8V3H8asrtGkOfmmy2nC85qkYabSZCyKUvdMFbCuWdHqfbXAgstJ2LpOjkabfiVv62Vw0ZD2X/11/TbWZ4x4/C6raz8o3ddXwOo5o6THZSDl42uP1sklVBtzzQZto3bYY6xFENAqp1s5S2ptq1ZDJVbRPwVH6ScbOfvF8LRM5B8qa2ceglXt64Qy+vQ0cAeFwXljsV0lo1PhmImTMDww+4QzJB/K0/GHZEbaB6Cj05i1wrm7aJKZ19S4p2IIQYedUpxHlYnSoSnxZT9K21VlTCZhR7wuMnP52DeJDQIIlcoy0xfWIrQP+QCA== 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=tmECx3VYLpfySrBrO6ij7tREpMQFUWwJsnt1Te8wgH4=; b=JhPNsLLWGAXz98zS0ld6qMWWZRIC9aSFBuqV5KNiQ7QrG/xr0hz3jR1QjLbVdwBHXkGaqO5/d2L5xFdoALd05DQ6OTai2GvfHpRVfBG50s/iI4Kisq12ECjG/Wv7kR7eRxs6p1IJnyuaP2EP2wbfv/q/jLESf06HzAjDIdsWHAVowZ2WcArNFNEUUMp0f+CXz5dQnNC8Fjs2HXPPCEsgDSIMOfpEVXpXHWi29f4woVdfol0J0rry/RyL0D3TQQEld4kYzr2lRfgvqbmQAaEUsSz62fF6TNgkKDtHnVR0KDlYiu2v4JmvhfqF4hIrNBSGbTUa+lHI3yow09KMZ/tSow== 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=tmECx3VYLpfySrBrO6ij7tREpMQFUWwJsnt1Te8wgH4=; b=nkTpmhEaHTzTk0TVLfPhVIYfi31x3kp51TKKzIx7GMOzDstQP8LgcX76EeuT9r7++f+cZR2aSZTDhJthI7fPQT8hZG2T9+3u5tRM4K8Z21l+btLv/PKxG/ig5llG/VP3m6nQfsFelkX3hK4RMbLLnG2ZrhAcTlUzYTWzaAvRMtQ= Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by DU0PR08MB9847.eurprd08.prod.outlook.com (2603:10a6:10:444::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.6; Fri, 9 Dec 2022 13:59:13 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::66e4:4940:d096:4f7]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::66e4:4940:d096:4f7%8]) with mapi id 15.20.5880.008; Fri, 9 Dec 2022 13:59:13 +0000 From: Wilco Dijkstra To: Carlos O'Donell , 'GNU C Library' Subject: Re: [PATCH v2] Add random locking benchmark Thread-Topic: [PATCH v2] Add random locking benchmark Thread-Index: AQHYtjmErPPmS0gWSE6HojYzdbLo9q27a64AgAKzreaAqCBleg== Date: Fri, 9 Dec 2022 13:59:13 +0000 Message-ID: References: <6a3d9283-3866-e837-c348-6d2a4a701c4f@redhat.com> In-Reply-To: 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-traffictypediagnostic: PAWPR08MB8982:EE_|DU0PR08MB9847:EE_|DBAEUR03FT008:EE_|AS2PR08MB10268:EE_ X-MS-Office365-Filtering-Correlation-Id: feba7086-5906-4ac4-02ee-08dad9ed92c2 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: Ds3vJo1qC5EGlapXrIvovWt3HxMofHv37JwOyHq/AD7lFl2Y2Gh8gXmz7IWqDbEDosesyEumt4TA2619eQ6mDjDko7iPX76C26b4fr5LYn+hrLD2OHbPOv6XxaKNdv6KboUi14MDi47oP0nduGmXb5cjCGV45fAsGkLkVK++IxpkXyh49tZOmfVVOKX+ouyHx0l8cE/DCuLq1zoge+Cd/iOG4hsf5V21nhpJg2GsJxxxOyp88va2tUT5b4chUX9IobKy97W/fJqGSeKL80F19rAAJZN0NgVkJITjSHG6wPhP+DNismfaYOnaY8me3fG17iSjaH1TtmwSCYs9hehmfUls9XIVMXNNlquF6Jmf34lv3kj9SegwbLWsLRCmu5qNHZWk4UyB4LhUPN7uCr8iKofMDW5TxGzdk3KNTUyL2Qqk1z/VxgvwxTcvxNspY5SlxRzjpPS/mQdHopy/K0bp3Ym+/rMc+XsO/Wb5jxVMYz1AugX1mMXEQ29JLcsRYnwXxvZtUx69x5C3duMp1AmLAm/WNVE1R2QchJCUQXHlbs+tcSa3MEeBXf0vwsy1Yk4Vl5GR9dvIhLFlgOL9JuVmRw0exczk+EIAUf20fS2PlUHYrZcp4XGbfsNfMgcTQChamGxGSvnT48d8ol5uYpHFu31rxFUEwe81G6Mao2W/2XywdTZAnU5a2tn3LxS6hLkOc2Sh0ndwvxR/xp4weA+/xAMH8TfUkuaPZMdia9EY3vwllKmtlU/TtXM3dLuHXJVf X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAWPR08MB8982.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(366004)(396003)(39860400002)(346002)(451199015)(86362001)(55016003)(33656002)(41300700001)(76116006)(66946007)(64756008)(66446008)(8936002)(8676002)(91956017)(66556008)(66476007)(5660300002)(53546011)(71200400001)(6506007)(7696005)(110136005)(478600001)(26005)(186003)(316002)(9686003)(52536014)(38100700002)(38070700005)(2906002)(83380400001)(122000001)(2004002);DIR:OUT;SFP:1101; Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9847 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: DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 395d72cb-fe57-46d3-fe34-08dad9ed8db1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OG11OdKZXczG7TOSaTk6tHySJJmwF7m0kvYPHmUe6Jt4GtW/k9Jo7Pjcyw6lrjheHozZi+LxAEd6CwSknQi7i+FZgDT9NdOZVSBTSfYUGsDn1xNNG1tNR5dRmvUeWLaMzcLkfJ3S4ObM84FTl8ZVRjXmeuU6VK+rQPGHfUxGRJA3qOryFcjvNONqh4hYBQ3QCOtn24BYfjnIuhyzvKGsaIwMH/okog/WozesJhifqQTBrjd4QEacCnAh/q6vjFykiX4TDmB3aRte3L4dKK3Znu8ksPMlNpFnHTBGw5+pEjEc/vBd9d+xW50PqSEUCf8lxHVRMlGgxIdjTtQjIAU97PgP6vtv8SJVSrWmw6FGcfwf1vpswCWGUwKcMWV9n4JRY02yq7XWCgvFjB21wZE2FKP+rrOonBGgk5zRp0rp9HwuadwTVpsyYT0g1ii1QNXbE/WuO7klP38u8hDk4jieFdilX6X5ORWbqdCsEcoEH30v3cCbDnS5M8/8x65aadDllDSS38+l08KtWfnwZUbYjHngkAM9Kn7e3rOmDusQSJJM+A2YbH6UjQD3fDyg/x6UqdaW2ve4aJOU6WOp0u1hH6L4+nn55cuytwP6MYIrWxGR74ix5+O8YtfK0upB+6+7WL6bhgJud5fbYJ3eaniAxWIkrM+Rrnz90kKl4LB/R5MpLQp8lVZXAQfxNl2K2ZXxwG7YE/MNtQ2zzooNR6OA5vI+HoFVXSJURd4gJ0aP2HDMYomP93iMfdJysOP+uVEy 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:(13230022)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199015)(36840700001)(40470700004)(46966006)(83380400001)(33656002)(36860700001)(41300700001)(356005)(478600001)(86362001)(2906002)(8936002)(82740400003)(40460700003)(82310400005)(55016003)(52536014)(8676002)(40480700001)(186003)(53546011)(26005)(6506007)(47076005)(336012)(7696005)(9686003)(70586007)(316002)(70206006)(110136005)(81166007)(5660300002)(2004002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2022 13:59:21.9011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: feba7086-5906-4ac4-02ee-08dad9ed92c2 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: DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10268 X-Spam-Status: No, score=-11.1 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,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 List-Id: =0A= ping=0A= =0A= From: Wilco Dijkstra =0A= Sent: 24 August 2022 15:43=0A= To: Carlos O'Donell ; 'GNU C Library' =0A= Subject: Re: [PATCH v2] Add random locking benchmark =0A= =A0=0A= Hi Carlos,=0A= =0A= > We could run the benchmark for a fixed amount of time, rather than a=0A= > fixed number of iterations, see bench-skeleton.c and DURATION.=0A= =0A= Unfortunately bench-skeleton is way too difficult to use - I'd just want to= =0A= give it a few functions to benchmark and let it do the rest. So it needs=0A= cleaning up before benchmarks can use it without a magic python script.=0A= =0A= I've updated the comments, see v3 below.=0A= =0A= Cheers,=0A= Wilco=0A= =0A= v3: Improve comments=0A= =0A= Add a simple benchmark to measure the overhead of internal libc=0A= locks in the random() implementation on both single- and=0A= multi-threaded cases.=A0 This relies on the implementation of random=0A= using internal locks to access shared global data, and that the runtime=0A= uses multi-threaded locking once a thread has been created (even after=0A= it finishes).=0A= =0A= ---=0A= diff --git a/benchtests/Makefile b/benchtests/Makefile=0A= index d99771be74b40f8afa3953f61c0721b19658d4b7..c413eac1d23568cb88bf22c6e50= 303e24ec10ea0 100644=0A= --- a/benchtests/Makefile=0A= +++ b/benchtests/Makefile=0A= @@ -236,6 +236,7 @@ hash-benchset :=3D \=0A= =A0stdlib-benchset :=3D \=0A= =A0=A0 arc4random \=0A= =A0=A0 strtod \=0A= +=A0 random-lock \=0A= =A0=A0 # stdlib-benchset=0A= =A0=0A= =A0stdio-common-benchset :=3D sprintf=0A= diff --git a/benchtests/bench-random-lock.c b/benchtests/bench-random-lock.= c=0A= new file mode 100644=0A= index 0000000000000000000000000000000000000000..c0aecb7f95b9f185df3bba7a75e= 3ef0884dbf6ce=0A= --- /dev/null=0A= +++ b/benchtests/bench-random-lock.c=0A= @@ -0,0 +1,109 @@=0A= +/* Benchmark internal libc locking functions used in random.=0A= +=A0=A0 Copyright (C) 2022 Free Software Foundation, Inc.=0A= +=A0=A0 This file is part of the GNU C Library.=0A= +=0A= +=A0=A0 The GNU C Library is free software; you can redistribute it and/or= =0A= +=A0=A0 modify it under the terms of the GNU Lesser General Public=0A= +=A0=A0 License as published by the Free Software Foundation; either=0A= +=A0=A0 version 2.1 of the License, or (at your option) any later version.= =0A= +=0A= +=A0=A0 The GNU C Library is distributed in the hope that it will be useful= ,=0A= +=A0=A0 but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= +=A0=A0 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=A0 See the GNU= =0A= +=A0=A0 Lesser General Public License for more details.=0A= +=0A= +=A0=A0 You should have received a copy of the GNU Lesser General Public=0A= +=A0=A0 License along with the GNU C Library; if not, see=0A= +=A0=A0 .=A0 */=0A= +=0A= +#define TEST_MAIN=0A= +#define TEST_NAME "random-lock"=0A= +=0A= +#include =0A= +#include =0A= +#include =0A= +#include "bench-timing.h"=0A= +#include "json-lib.h"=0A= +=0A= +/* Modern cores run 20M iterations in about 1 second.=A0 */=0A= +#define NUM_ITERS 20000000=0A= +=0A= +json_ctx_t json_ctx;=0A= +=0A= +=0A= +/* Measure the overhead of __libc_lock_lock and __libc_lock_unlock by=0A= +=A0=A0 calling random ().=A0 */=0A= +static void=0A= +bench_random_lock (size_t iters)=0A= +{=0A= +=A0 timing_t start, stop, total;=0A= +=0A= +=A0 srandom (0);=0A= +=0A= +=A0 /* Warmup to reduce variations due to frequency scaling.=A0 */=0A= +=A0 for (int i =3D 0; i < iters / 4; i++)=0A= +=A0=A0=A0 (void) random ();=0A= +=0A= +=A0 TIMING_NOW (start);=0A= +=0A= +=A0 for (int i =3D 0; i < iters; i++)=0A= +=A0=A0=A0 (void) random ();=0A= +=0A= +=A0 TIMING_NOW (stop);=0A= +=0A= +=A0 TIMING_DIFF (total, start, stop);=0A= +=0A= +=A0 json_element_double (&json_ctx, (double) total / (double) iters);=0A= +}=0A= +=0A= +static void *=0A= +thread_start (void *p)=0A= +{=0A= +=A0 return p;=0A= +}=0A= +=0A= +int=0A= +do_bench (void)=0A= +{=0A= +=A0 json_init (&json_ctx, 0, stdout);=0A= +=0A= +=A0 json_document_begin (&json_ctx);=0A= +=0A= +=A0 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);=0A= +=A0 json_attr_object_begin (&json_ctx, "functions");=0A= +=A0 json_attr_object_begin (&json_ctx, "random");=0A= +=A0 json_attr_string (&json_ctx, "bench-variant", "single-threaded");=0A= +=A0 json_array_begin (&json_ctx, "results");=0A= +=0A= +=A0 /* Run benchmark single threaded.=A0 */=0A= +=A0 bench_random_lock (NUM_ITERS);=0A= +=0A= +=A0 json_array_end (&json_ctx);=0A= +=A0 json_attr_object_end (&json_ctx);=0A= +=0A= +=A0 json_attr_object_begin (&json_ctx, "random");=0A= +=A0 json_attr_string (&json_ctx, "bench-variant", "multi-threaded");=0A= +=A0 json_array_begin (&json_ctx, "results");=0A= +=0A= +=A0 /* Start a short thread to force SINGLE_THREAD_P =3D=3D false.=A0 This= relies on=0A= +=A0=A0=A0=A0 the runtime disabling single-threaded optimizations when mult= iple=0A= +=A0=A0=A0=A0 threads are used, even after they finish.=A0 */=0A= +=0A= +=A0 pthread_t t;=0A= +=A0 pthread_create (&t, NULL, thread_start, NULL);=0A= +=A0 pthread_join (t, NULL);=0A= +=0A= +=A0 /* Repeat benchmark with single-threaded optimizations disabled.=A0 */= =0A= +=A0 bench_random_lock (NUM_ITERS);=0A= +=0A= +=A0 json_array_end (&json_ctx);=0A= +=A0 json_attr_object_end (&json_ctx);=0A= +=A0 json_attr_object_end (&json_ctx);=0A= +=A0 json_document_end (&json_ctx);=0A= +=A0 return 0;=0A= +}=0A= +=0A= +#define TEST_FUNCTION do_bench ()=0A= +=0A= +#include "../test-skeleton.c"=0A= +=0A=