From patchwork Tue Dec 12 17:41:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 1875337 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=im++7/GA; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=im++7/GA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqQt01zHDz20H3 for ; Wed, 13 Dec 2023 04:42:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA25A3858029 for ; Tue, 12 Dec 2023 17:42:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2078.outbound.protection.outlook.com [40.107.247.78]) by sourceware.org (Postfix) with ESMTPS id AE5273858C78 for ; Tue, 12 Dec 2023 17:42:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE5273858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE5273858C78 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.247.78 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1702402923; cv=pass; b=bIx/HHFuOVG8qmIBqCEiemm2XpfFl9jgXJe35tpFhFKROwU4NSJYA1hQSYPHxdpJiIZLO0fs5b3hmWq6km4+krmFBhC49Nntnt21iVlg4SMNHollnsnwz+H8nFF/STn7ex2oHtZrYuVFvjdjxIEFTTztJkNW0dMb8aVBWL9B9u8= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1702402923; c=relaxed/simple; bh=JQPeOePRRQR9Ra7FPpf6gJqSrszWRQQvrj1aag74Jb0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=s7aV/Q0ISn+D+E6UVgDnMqf3uFrmKT+3icVGPxEuKU59oWlVzHYBDSm+qd4II3E0RK8j1cHccq8Zw5gj6HS0IDHvxMJubSLf+pBVah9oyf5qWDpSG+O+18J7E0m4Wt4GXdOQRqzzrn1s3HJ+Oraqw/AbZNLbtfRPfu4u5KL6ieA= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=kbs27LFoCQN5DTZVFOPRZ9n7d/pIeqgDudMPh3XNkowdibCqQ5zUBRVIHHaR98k+dBFgQERpIVBIorwkxQV+3qNE7ecl1FHh7Wwp1vwHh7u/GhfpJ9KtvQ9i2KyRb2m659MZIN9JQP8LrD+LorZTc/yghCLQUefEfuYANtnCXQoJPiej/nfLc/8IceFEWx38VwWCFJ29/Qx9aJrgYulgtKmWG9/2wPi2QU1g0SyG0q8M4MSaQmMgmOBNYjEdjYUWYygifEQ8xtAP87aWOfE7ogNMe9oh/hKpr7WrmwlG6ERVrJ6nZMRG7lBO0TJkzHR8g/P//coI7EIE1AdqEZmbpg== 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=WnYZ0FKTb0i6pe+dAr6KNOKkymn/zU5htXxVqmh/0vI=; b=N8MKebin5GJPNfq6v0Bg6LoNM//viNBecfm8yrR1TaX8KnrCCL81x+WvRRT1Cu5r0ux1088jWH4sEcTG+ZviwVRoHaXKXe1v61bGogFFdylywLA5xuqfaPvrzbJWEj4MsWIfkKMDLETTj0F+H7rIHLVGHFzVWpjaV94Rtnuqje6sfWPlumWi5HzB63iBtdYH2EkkrX6wYYFp4yrfrTMMNie5mY6givSpg0ZrEzGFDaK5K3UzH+W58HyLiJOnnByBZSKKhz3vc4GDOkhgZ+6o7ZFLMlzmRCVeyZVLSWCP9zj9+fMMdLS7vsEn+CNlzlwA9gUNgtvEOXqTag9KRn3qrw== 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]) 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=WnYZ0FKTb0i6pe+dAr6KNOKkymn/zU5htXxVqmh/0vI=; b=im++7/GAjJX1FGcTTMkgEfibfuKKJO9Le7R0G+fgeRyXvHNgpy47qCt1d+DRandBU1ZhfcCoTYI87GCSGPoQouDs95gragZTyrBfaws4CTVqquT5Dwshncqinndye8kjrjKYBklnH/ENlqyKTNiDeqX9WDjFKag4vqvRWNrp9v0= Received: from AS9PR06CA0604.eurprd06.prod.outlook.com (2603:10a6:20b:46e::6) by AS8PR08MB8274.eurprd08.prod.outlook.com (2603:10a6:20b:536::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Tue, 12 Dec 2023 17:41:57 +0000 Received: from AM4PEPF00025F9B.EURPRD83.prod.outlook.com (2603:10a6:20b:46e:cafe::a0) by AS9PR06CA0604.outlook.office365.com (2603:10a6:20b:46e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33 via Frontend Transport; Tue, 12 Dec 2023 17:41:57 +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 AM4PEPF00025F9B.mail.protection.outlook.com (10.167.16.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.2 via Frontend Transport; Tue, 12 Dec 2023 17:41:57 +0000 Received: ("Tessian outbound 7c4ecdadb9e7:v228"); Tue, 12 Dec 2023 17:41:57 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 80ca9cbbb4a1655e X-CR-MTA-TID: 64aa7808 Received: from 4c4faf7a2150.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 29AF1E2F-41CB-463D-8C0D-9D4252CB9449.1; Tue, 12 Dec 2023 17:41:51 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4c4faf7a2150.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 12 Dec 2023 17:41:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ecafM2q0cclQvkyLb0IebcpcsUhguFc3FC9jNFrUHjeXXHEeo/VsWdlkbnWFRFmevuzUcOSOEluV5rud2Fix5dj4dT9K7YB+ArCDg9oUKoFGBvkrtEHMd5Gv4+4iGZX86G08YONzJePd0LffZ3BGiXMh4bZ4PxwEHbdqQkZdNVr8RN4e7aBTk9Di8UXlt3WxgQBrlUSpqSb5C2EGvvmhcoY+gpRMJxWVFODMBdxtsPGB1HAAsWJkIlxqKfoPwOaTLOFdG4pkADN88gpJfoj6xYh6xgFX9rdO8/oHO0wBhhjJ+PxvjaXviaJOSnqr/EI1v+ODcPxa75wsqr5sjOKGJQ== 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=WnYZ0FKTb0i6pe+dAr6KNOKkymn/zU5htXxVqmh/0vI=; b=IkAzEeJmV2gw8aBVJm4g/Z8TmwJg3sHxvrv7V8S8bRyBF+VqhE9ORSwt80D2JMx2C1Evp0cNvokADiYBEcSH/2MOMXyA2OA60nQTK/SzTb7jENw31FkGW/OLbMXAB1PUAruyDN69/gxKp7ZHfVtVvYHFyVMC6nZorKEvOTDeunPM2njRc/UuFvHyUfKwnYiyqGBCMWFZRmxFeEuuqlrf6pxtpMxh3LucZ2LZdvSOb70RA1+Lb7wNQRGr0bx4uk8feBzaismusoExIuCH2VdXUuPsnjYXVx1NoeLoxaPPW2HBtpptYQ9i6oQ6l1dThYGZjFWfWxpxeGWmBiBYlpaHyA== 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=WnYZ0FKTb0i6pe+dAr6KNOKkymn/zU5htXxVqmh/0vI=; b=im++7/GAjJX1FGcTTMkgEfibfuKKJO9Le7R0G+fgeRyXvHNgpy47qCt1d+DRandBU1ZhfcCoTYI87GCSGPoQouDs95gragZTyrBfaws4CTVqquT5Dwshncqinndye8kjrjKYBklnH/ENlqyKTNiDeqX9WDjFKag4vqvRWNrp9v0= Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by DBBPR08MB10463.eurprd08.prod.outlook.com (2603:10a6:10:532::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Tue, 12 Dec 2023 17:41:46 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::2ed5:dc23:2624:df0a]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::2ed5:dc23:2624:df0a%7]) with mapi id 15.20.7068.031; Tue, 12 Dec 2023 17:41:46 +0000 From: Wilco Dijkstra To: 'GNU C Library' Subject: [PATCH v2 1/2] Add random benchmark Thread-Topic: [PATCH v2 1/2] Add random benchmark Thread-Index: AQHaLSJQJB5xulKPW0CIceEnqvRhaQ== Date: Tue, 12 Dec 2023 17:41:45 +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-traffictypediagnostic: PAWPR08MB8982:EE_|DBBPR08MB10463:EE_|AM4PEPF00025F9B:EE_|AS8PR08MB8274:EE_ X-MS-Office365-Filtering-Correlation-Id: fe639b97-2bb0-4dad-a4a6-08dbfb39a376 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: mEbXeQwaqOXGbWryEqjNSQizhDpRabMPrE/mNTvEDt7tPnn4mVv7ldhwM0Hmi9ZePYEajoU0LkEARnEE50k9UuTDuJ/t+wtLR67yGycAyGR1FIEyYV1lJJS8JC5/4BWTIhadG7aRT7lyy7+7KRHL0EMGmnpdVnF6NUQioQBuIJ5vFocR3oEzQSg1TMR3GqB4k6w0V1+ypgWuEBl8+MikpdsFBcEmWj8V3GMjZ64EVXvl7TmbbsdRRjpTxoUa3M0M4QKfA2JmMjpVvlUoUBJUZKWTTcjxnDdzggaaVPDwTKwA+1jmbPQdqsNfpMXxbENfvYojo6Zz/SKdQSlgjXZ1HlNeP0IJMAUuwcHNTz/tO856xl8eYacHSwAUaQnPgkGIMRCszkyI/op319KRzc+5PvpjyN1mGfOrdti/jx3J81yg+Xd7D1Jv75g8/M/AV/7R4fYXs3Kj4/qMMdVEQZiHNV855sUjqal5vge3zKmXsMiGkGerN/SNAbwm1oRQsVuu2grG3G7eBLZVKjpKqg9FiAqL3BZfyU3VFxPTvWWSjwnGqZ3p1vTiJG9lRQHW/XyiJCiOwrtLEq1W3j+lbO6Ldv+DlXr/s0sPhy+JvYegm0UZGA38QG6kJ0gaHJE4L9lq 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:(13230031)(136003)(396003)(366004)(376002)(39860400002)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(91956017)(66476007)(76116006)(66556008)(66446008)(316002)(66946007)(64756008)(7696005)(9686003)(41300700001)(26005)(71200400001)(38070700009)(38100700002)(86362001)(122000001)(6506007)(33656002)(83380400001)(478600001)(2906002)(52536014)(6916009)(5660300002)(55016003)(8676002)(8936002)(2004002); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB10463 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: AM4PEPF00025F9B.EURPRD83.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 19ea9de2-b7b2-4571-4f2f-08dbfb399c63 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: okUlo8OSB19pofwHvihkfdARcNKcSSExpUsnDmPuG3/ngtYPtfWNtyIMyYLRGrtgAdeNZ/eV7UXwrKdIxrCpVsklF44GTciS4hKa14JOggo5g7/TX4OTs7xdpOvY5wZRyFLlu8y4KVmWuDh0VVgjCKO67k+q0rh4EeAvsbFLatHrvEkq0aeLhqJ9G56sQk0rmCNO1s4pjYILKw3/UO9Ugg4/2B36nYRTpovQdmxQPj3hABWRsKh+1+5+7NPCrZQ3MRTMIZ5NJvqOeD5qNC3Ib4HLfTq06ZI8Ri73WIFBYIHhRqqnPOmqkLpMg28iHgtqBTxaEdSb8H5+/bjMYqXgqm137x0HL+XCvr5jVVMK4AIsgAu1J/ntEUYJCEHt/QUs7M85G2f2gbfoRACo7isk1kNWMOSfxJ0ptezrZdtLWQHTKQf821msp/3nPXgFT9aovrgNt0XHN9wnkavIZiqRN3gTx4Bxst+ju2BinqsQ3Pqc+npXG/j+6Om47FeEjv4fD/aF3Cw4Odvq9DSpAE8/KTxUD5iWAGjaq6qZT58KRpPf4Yen1omZ92WJJFzCSmszZ7JHReJUpC89rA/wPHdgNeff4+EVsS0QRp3DnAGc7KXqzhDAvzctT/hlUDHnGbwnTdtBL0AKwyDcMHzEi+4+hYrJJKMNYICGuAog1jZx2zDKB+LZVqs2Zq5bd40lM6Me4zeIVzvr162tgKxQ4/ktTF8/ypFh23YLW2RYYtrOnZmsloCi2vVOEXjNA2EGXGxt 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:(13230031)(4636009)(346002)(396003)(39860400002)(136003)(376002)(230922051799003)(186009)(64100799003)(82310400011)(451199024)(1800799012)(40470700004)(36840700001)(46966006)(40480700001)(55016003)(86362001)(33656002)(6506007)(41300700001)(7696005)(70586007)(70206006)(81166007)(356005)(82740400003)(478600001)(26005)(336012)(9686003)(40460700003)(83380400001)(2906002)(6916009)(316002)(36860700001)(52536014)(47076005)(8676002)(5660300002)(8936002)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 17:41:57.6757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe639b97-2bb0-4dad-a4a6-08dbfb39a376 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: AM4PEPF00025F9B.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8274 X-Spam-Status: No, score=-10.7 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Add a simple benchmark to measure the overhead of internal libc locks in the random() implementation on both single- and multi-threaded cases. diff --git a/benchtests/Makefile b/benchtests/Makefile index e1346bbda125be9fc2b216f9e8be3f2ee7cb0c4d..1ec14078ab73d7c1c0fa1d4d870a075a66543a5c 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -246,6 +246,7 @@ hash-benchset := \ stdlib-benchset := \ arc4random \ + random-lock \ strtod \ # stdlib-benchset diff --git a/benchtests/bench-random-lock.c b/benchtests/bench-random-lock.c new file mode 100644 index 0000000000000000000000000000000000000000..29a02ae9ff3a81114e8dd7e1dddcb3309b92df6c --- /dev/null +++ b/benchtests/bench-random-lock.c @@ -0,0 +1,108 @@ +/* Benchmark internal libc locking functions used in random. + Copyright (C) 2022-2023 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" + +/* Modern cores run 20M iterations in about 1 second. */ +#define NUM_ITERS 50000000 + +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); + + /* Warmup to reduce variations due to frequency scaling. */ + 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"); + + /* Start a short thread to force SINGLE_THREAD_P == false. This relies on + the runtime disabling single-threaded optimizations when multiple + threads are used, even after they finish. */ + + pthread_t t; + pthread_create (&t, NULL, thread_start, NULL); + pthread_join (t, NULL); + + /* Repeat benchmark with single-threaded optimizations disabled. */ + 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" From patchwork Tue Dec 12 17:43:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 1875338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=6gCtJrVP; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=6gCtJrVP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqQvd0GPLz20H3 for ; Wed, 13 Dec 2023 04:43:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E66C385800D for ; Tue, 12 Dec 2023 17:43:39 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2045.outbound.protection.outlook.com [40.107.15.45]) by sourceware.org (Postfix) with ESMTPS id 432F53858C78 for ; Tue, 12 Dec 2023 17:43:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 432F53858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 432F53858C78 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.15.45 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1702403011; cv=pass; b=u70UMQ47vMcgiAUvzWTFr3GNUufSG16KVRGoVov1cfr0BWCzXJbRi2frGzrtHeFA2t32Mc7SfUbU0IGjkL/ZrwO4ikMK3xmqAhxm09AF28rOOTSGKlxoLo25s9o8mWflblarUpqZjSwztEQjKjBhtjeiyiOgfex/U9LfCqCYOjc= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1702403011; c=relaxed/simple; bh=vkmAlDsMWahV9VoSQ2gJZaCEu+dHwEQv/rf+WK7L8gQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=jcmDx8TeOUsUHzqsTyfaUTCTyG4TDHEVtjwm05hOlnKlQbGqaq6Z6XDjW9IHwNeriE1ndaSI9xtKCS5puHl+K+4v0H04iZ37ifmZDun22YTilDtA/X4a5k2B/9oA7xhDpJqS8YkPFKAcahG0oR8G+laUm9M5d8P7iLwL4BKUbg8= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=at7ZaTAcpN5kPd1mKpC9vrF4UNJG6kxgAm3ZVyeNEgkQJnasCkL+WWqen6VfiEKVtNV09X66c9AiFRZfs5QXwmsiv+A+cfOHAj7y81rlgsrHdh0UvbjnbbAtnADpZROa4fLXvEywdpW+9NhXMUReuaC95/MRROsIdvY6MtUCm49tTt8lmY4G48zx5+CuRK0PBXVAXvcgWqlQCwbhjohsWhO0yqGpKE3DuJTfxHjToUD58ogkgDRLC6VKs/dGrGL1zv59anKtQWTVAcaMkWPDW7x+9n6s+2UHjp/QXaBBHSYzlRZsl3MrdEuvXHdCfGDg0CMlXGFURv3Vja4NdBsHjQ== 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=rN2Fs2CDlz/qLtkNdfbDoeNyNHkOY/ct4AJwzxaV6oM=; b=TQhYa2RGQxniOu3mCZixPRhI1n8dL6UDjnLZMwnjHcYGQmjf/Aj+TMP65ahG2eSFrXdI30e5mh+Wu0feT9Z3w3a/rOIewG6/q9faeg2XGpKxv2xaGDKa4IZ49nXSFIyjNN/SrXAUsfkS1XQpoOMNQa8+y7zuVDfdHIaR8Mis4YnibtNBTVYbmmLyNUGJWXbp9NvTXAoTPbRYWM3qI+7uxQBohyJUOP6k34w4qyF3rb3Rjc7I/oiGpo3Cj/G8WSI2ezwH7B/SO/s2dmcXB00985w3QzkCXcXvKnCEYUF6c94tJOEnZ/56Eh8Su3i/IMwKkoB2yndDdwQ6+qBruGRaiA== 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]) 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=rN2Fs2CDlz/qLtkNdfbDoeNyNHkOY/ct4AJwzxaV6oM=; b=6gCtJrVPoETP0xygQ5NTwgYSi+EAEufAX1OIne53m1UTRyvV2jKWeMsvj/S6pMhUEskTn8udVq7547TIhy08L0MBw6fTYlZwUD2ydDmbjMurmnCpzF/r/6X3Yve2lYH8U/LDRyl951aP43mvZYqP6SUBbwZ7fQBjF8eD4ZXlY2E= Received: from AM0PR03CA0048.eurprd03.prod.outlook.com (2603:10a6:208::25) by DB5PR08MB10096.eurprd08.prod.outlook.com (2603:10a6:10:4aa::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.32; Tue, 12 Dec 2023 17:43:26 +0000 Received: from AM3PEPF0000A791.eurprd04.prod.outlook.com (2603:10a6:208:0:cafe::2b) by AM0PR03CA0048.outlook.office365.com (2603:10a6:208::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33 via Frontend Transport; Tue, 12 Dec 2023 17:43:26 +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 AM3PEPF0000A791.mail.protection.outlook.com (10.167.16.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26 via Frontend Transport; Tue, 12 Dec 2023 17:43:25 +0000 Received: ("Tessian outbound e243565b0037:v228"); Tue, 12 Dec 2023 17:43:25 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: edf22637dc6060df X-CR-MTA-TID: 64aa7808 Received: from 150e26986563.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 57F96AF9-4303-47FB-973D-BEDEA77A0D60.1; Tue, 12 Dec 2023 17:43:18 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 150e26986563.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 12 Dec 2023 17:43:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mns5xCBoSvm5jVoOWI8aLly3+++0IzKIsAK6x2/LfLk5KhoWfUAzrm4dzLqvhwqwL1sWQmAgW0N4e6Cal2sSwe9gUpQuXQag3u63m02Nxf2/eP69Vl2VkrcodazoO6mU08pVstzJDwUArfVdbZFi6kMNSeh6cLiR/bsqlawGaI0te1ZCzxx3VkFEe5cjY/7lVRMyRbpJQiSFxc04x3h8rzk8ufnDRlGmfb42wsIeayqhwA8hKYwjAvfIXN3Lkxtz16YpFl/X6aTSi5jfN1jWgsUNDvHp6SvZZiQbfby7CQY5wDoLaX+7Dkzzn35azLVouZjqUwblQDf2n8jZQfvLTw== 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=rN2Fs2CDlz/qLtkNdfbDoeNyNHkOY/ct4AJwzxaV6oM=; b=a446LBLjSmW0b/+QRiKkuAkcBVYnOvgyfuTPFTSx2jgS8jC5wKxuLoPIIb3poZ0bEjVO7sUxgsj5PPL5fPS9DoFDn+t6XhsxNjTKoiLPJYEeQEz4Vb++M6lPUQPqDWapxdzV1/MPvlPFmjocLUGUzhrgnLBXJNEk74agD5wANX4FbFySbimMBdBpFe0n6ktmx/7eefONIPM46A4OneTnph9PPSMGaCe6lIA3G5oqb0IUc5P+u457anEjnumDapXel0sl7M+behSPC47tIPfh9nU3bS5xBIoqwkb5bYJdnBQeYak7FLc7UUgRrl7VLpjkVePJKSrGR6u7Fm93Hy0rpA== 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=rN2Fs2CDlz/qLtkNdfbDoeNyNHkOY/ct4AJwzxaV6oM=; b=6gCtJrVPoETP0xygQ5NTwgYSi+EAEufAX1OIne53m1UTRyvV2jKWeMsvj/S6pMhUEskTn8udVq7547TIhy08L0MBw6fTYlZwUD2ydDmbjMurmnCpzF/r/6X3Yve2lYH8U/LDRyl951aP43mvZYqP6SUBbwZ7fQBjF8eD4ZXlY2E= Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by DBBPR08MB10463.eurprd08.prod.outlook.com (2603:10a6:10:532::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Tue, 12 Dec 2023 17:43:17 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::2ed5:dc23:2624:df0a]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::2ed5:dc23:2624:df0a%7]) with mapi id 15.20.7068.031; Tue, 12 Dec 2023 17:43:17 +0000 From: Wilco Dijkstra To: 'GNU C Library' Subject: [PATCH v2 2/2] Add single-threaded fast path to rand() Thread-Topic: [PATCH v2 2/2] Add single-threaded fast path to rand() Thread-Index: AQHaLSKMOUNofogb6kmD1rn02zEN8w== Date: Tue, 12 Dec 2023 17:43:17 +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-traffictypediagnostic: PAWPR08MB8982:EE_|DBBPR08MB10463:EE_|AM3PEPF0000A791:EE_|DB5PR08MB10096:EE_ X-MS-Office365-Filtering-Correlation-Id: 31ff0705-47ae-4e19-a253-08dbfb39d805 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: LUOFnLw/qQvaPR8gNz440aYY5PyNQ+DvY/J0R4t9kDv0jASkh00zADjuQOO+TdnDqvdS9iEPsK2MmWZfxwJeHXj72VYG91paK02eeEcEKSdh5ih9jMPt3EaAZAd2RTlCh8L4tO+I1JT+pz8tlfcx7VS0177WGAe04xGqqL1Uk3dFFau3w8qXIbewKNPukebUylDuDjUyxNFpkDuO3UAFZdNU/ODV66w6hV/6XxIV+SRDyMPYramJTNTnK0cbuGUJINMDXAiz1BdJSX38wjk6nXeOyNqmNjH0+RakfgOd4hss1dgVK3MTlHY70QCF0DQYlQ0hoo3HpTexIWWAJJgYc0dPfbTA6vTa83LZVAxQWC0hEyhGlg209WPxcDflwDUR865/KElFT8TYZF673wIEDt/uqV4MO+2ac8ORedeP4Lp4pxXEV+GwgcRBPHUk2EQt4I1fHlhBdXm+eHWMHv7URlF724QOII3kKFX4ZBKjsgQFp1pZ+xDM/Q9WGZ2TT0rpxDGNzue0bDhzZKJ9mc5yJQ+Q0orTstTDTRNJDO9WiOAPNoY79taoWTwjGKAPl6OYbU2Z3S99KjpFYUw33WkdQGmkNAWQ4jheEvx8lBGpfuliVHow8cv2ph0Ppv+1i1YU 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:(13230031)(136003)(396003)(366004)(376002)(39860400002)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(91956017)(66476007)(76116006)(66556008)(66446008)(316002)(66946007)(64756008)(7696005)(9686003)(41300700001)(26005)(71200400001)(38070700009)(38100700002)(86362001)(122000001)(6506007)(33656002)(83380400001)(478600001)(2906002)(52536014)(6916009)(5660300002)(4744005)(55016003)(8676002)(8936002); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB10463 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: AM3PEPF0000A791.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 5e3d5ac3-9fda-442d-9b69-08dbfb39d2f2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GplNr6asfmGQ30kEB/eq5lfLlgEv29PIjCaXseuH7nS5MARqIdzJyG68gGSFuWfHCe3Q30sW8H26o0bERllHUb93pXdP44PynfR3h4JDPZS52p2Nz5f6h2TW8Em5uhn5kNRmx09faPLyWbGQrJpIHABBIrrWEVXepeiOgTUs8zp+QUA+57ux2eHBR3jbI0VmPYLvjm+ufO7YJipSUK4kAZaoS5hDd9y0jp3/1AloVbDU0NoKLxhrHryXpI67+ltg5/qRHA0RCr1q2RiuB592CoRzy9bnNJtkXV72VZN5c68abghRf0ihi+eHoFvnkYbprnMt6DCdmwqALMJpBLL3WorY80g+T0rTvTnTSkGUoiYdIiVgSKBBmaJWa8evz8Rz0beOJLskEeFHBBJnQDoTwzsIvoZ8eVYb4vs9nynpv9zxNxHp3WSMYNUuznubt62M6ZrLFb5eqfL023U5ZzXr6782ljJtNVlZj+U+c+gzsuV6uoNic5ZRBa62BRx7LfjGpa6HoONGBZ8mnMXtw4L7gpwlXkM5ZzNSaI6IRzoBqSmpFMzDs+XqoD+hA045K1juI+l4S2n7harTJrFrFOdx1jVJ3xE89j0xh2Pp52pXr3lBUdCTHf6bhkCkDxTQtRz4MLFw9UoiOKLu32GPOO+o0DJjg4P/G1QxoEdwuQbrfqDbARgDfqGj4FQve2M0VlsTClwhSCQPGISNCZJm1eOwL4hVLpJenmZRuy0KnzeJAJQ= 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:(13230031)(4636009)(136003)(346002)(376002)(396003)(39850400004)(230922051799003)(82310400011)(451199024)(1800799012)(64100799003)(186009)(40470700004)(36840700001)(46966006)(40480700001)(336012)(26005)(40460700003)(82740400003)(81166007)(316002)(6916009)(86362001)(356005)(55016003)(33656002)(83380400001)(5660300002)(36860700001)(52536014)(9686003)(6506007)(7696005)(47076005)(70206006)(70586007)(8936002)(8676002)(2906002)(41300700001)(478600001)(4744005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 17:43:25.8543 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31ff0705-47ae-4e19-a253-08dbfb39d805 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: AM3PEPF0000A791.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR08MB10096 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Improve performance of rand() and __random() by adding a single-threaded fast path. Bench-random-lock shows about 5x speedup on Neoverse V1. diff --git a/stdlib/random.c b/stdlib/random.c index 62f22fac8d58c7977f09c134bf80a797750da645..a22de60a0f96031c74dd5a949b6717c2b0fc321a 100644 --- a/stdlib/random.c +++ b/stdlib/random.c @@ -51,6 +51,7 @@ SUCH DAMAGE.*/ #include +#include #include #include #include @@ -288,6 +289,12 @@ __random (void) { int32_t retval; + if (SINGLE_THREAD_P) + { + (void) __random_r (&unsafe_state, &retval); + return retval; + } + __libc_lock_lock (lock); (void) __random_r (&unsafe_state, &retval);