From patchwork Mon Mar 18 15:20:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 87321 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com 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 8E05E3858401 for ; Mon, 18 Mar 2024 15:21:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2060.outbound.protection.outlook.com [40.107.22.60]) by sourceware.org (Postfix) with ESMTPS id 0039B3858D37 for ; Mon, 18 Mar 2024 15:20:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0039B3858D37 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 0039B3858D37 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.22.60 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1710775252; cv=pass; b=Y7wm8/Ea65L06xk1fYKHP3IXPIrgEu1gfSnZ0/ZL12FzTbprV3XDA8HbHBm5Da3XtfkGoyph0uVGZIV5lYtD6dlVmxICxeRHEMstL8kFYBkqxSrARSvMk/mw3IRQWDSa61f0W4AwTN0kDaX3Zcq4Ed9VK/MOyzIsM3oMRMQO/XA= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1710775252; c=relaxed/simple; bh=cdShbtg8H9bmIjLOsdsFOcdqya2Y7/JrqamkCs7TiA0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=iBUEqeYOWbShfhscPNxdSMYr0KwoVno0wWpm9AxfsgKA7K1zZdq3W+UVJHLi1HPD2f2V79EpL22Mn6hCLPIeYRQ1XjeikzDeZbpYXPqy6XIK9a5vbZy8qzRxkn4oo/LGpxCNEblsxSCHB5YlYddpT9dvo9G8wvnd+pPvSALxG7Y= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=XrIkNOaZzMVBi8eKmIDaoFFmGsf57nFdIuf35wABpY8CotMS5X8RkNce9j9yU3gJmINAZebu79Z7bxB/ndcAbAwXXmQcRh0r69FuoAVgpPMcfMgMgIs2pLPiXhpitNlI6eZv5E2FyW5zwDgb34wdp3M+S1yz2MQ40lY5cNMcLKu/CKRD+EbLxkkrIPp4MA9Hov588g+D620zvw/56cMBko1MhMdJ8usd5d7kXY8SiMMngrKVCPEzJ8aZ74qsiI2/ZY/rBcpP8c+Z8zc0ztni7/9oqtLmmmHDRq78lou/I6vS/UeXrArrVufnkHgtVg17hYP5Baq8pwSBJpv4zc2YNg== 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=btKD+9l64Dm5C0jGR73EDTonH+mSGph8ttXh8fFwgw8=; b=Kn+DfJfwBUl+Wslv9mqc4cmyXIyGX5j/jrp8FsmPpVhePMzAIqt7rrdPDsupq+AwCBbU8ikRlkhyaQS6mxIuFfAyG61y0qeBK41BfmnWWcQ7AB6oIsaZkeVbdgVHgyzFH1HXnsFshCQVfmfuCUx0wQ8n8ZClBMEACEJLO7k4V6knSXN8UcVXHQDNaPrKkP3D/smK72neWeIH5Y7tXFI+2oCbOhr/a20Kx5gLmIr0AenYM1HzXqbcKOVR1DhSoTa048GSMQZ3f/XCSzbtNIzQmTRU02oOtK5zMcye+vddHGoI0ersyZZeb47fVC+EFlkXLXfyf3FlYrzr/SxRIZnVvw== 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=btKD+9l64Dm5C0jGR73EDTonH+mSGph8ttXh8fFwgw8=; b=G+8rzd2YzmEpkhjfwe99yJM2cTUyWn2GQ03Bf6O18x+wN2GklfybVFg4thz+a0cRhem3lfE8Jf/avQXbnX59PcgguDemOjanhjWzuOWJ2EBJ5HnPAxWwwB1sOWxMkutztP4qwgxMhqgwxlLzlZ9fWergxG6PKZZZQDLn2GBH9gI= Received: from AS9PR04CA0100.eurprd04.prod.outlook.com (2603:10a6:20b:50e::16) by DU0PR08MB9821.eurprd08.prod.outlook.com (2603:10a6:10:446::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Mon, 18 Mar 2024 15:20:45 +0000 Received: from AMS0EPF000001A8.eurprd05.prod.outlook.com (2603:10a6:20b:50e:cafe::76) by AS9PR04CA0100.outlook.office365.com (2603:10a6:20b:50e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26 via Frontend Transport; Mon, 18 Mar 2024 15:20:45 +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 AMS0EPF000001A8.mail.protection.outlook.com (10.167.16.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.10 via Frontend Transport; Mon, 18 Mar 2024 15:20:44 +0000 Received: ("Tessian outbound e26069fc76b9:v300"); Mon, 18 Mar 2024 15:20:43 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 032f4d4c2d129847 X-CR-MTA-TID: 64aa7808 Received: from b300d399d13f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7E4D39CD-DAC7-4738-B142-B0F3438995ED.1; Mon, 18 Mar 2024 15:20:37 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b300d399d13f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Mar 2024 15:20:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AACRCkgzQba4VDBiUjhE8Tha1GuGkDMlyrSMrMs2tV3rtEty+bVm+ch8vvGJDmGFDsUAVlh09naFSDF9spWey0IxhvddXd2jKXBEwLWIbEGTzVlRFSrj7JIDHPZqdEGLKT1KVL4f8wpRbbNbxbJsuBEfhLzq1LafcDKFxKd2kKukwbRHfmhz02nixFuPk5KeiR4ckgLLX0iBw1ZoOA3MROrrfQNMvTpA0nNCIg+rHtCVAs2Dslu9fixlfyilNp8g5RDFesgv5AkkhWtFXx5juxbVn1tkPlhDeAZ97Po2RZBgjnbFjnlYgU8k0P2l84xwHlRg1U7g0v6kuyyZcy2fXA== 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=btKD+9l64Dm5C0jGR73EDTonH+mSGph8ttXh8fFwgw8=; b=L+a6BdWgt/PU8uswtzZnWbHFeFF+d8gxUN6xumxQainkIU7SAu6hWDniJ2V9EvZfKED06kja24aDeNRZ/MQo3mGh3AzC05ChpcZCCQc4j3D0jHYDXXgfWP07B4M9Te8Tf/SfMsA3vFlPoZBhr8fdeU+q0ypmKoZBELOPKLGNGvDLqVLZndAu1POaEZk6FEha1Hv2ZQXCCnzRq96OO13WvEo+RRUY1eWF+/aF/eFfl/hp4HV1VFYN0tbPtl4pRWw5oBSJrXhoZKmLf6KqDuzFWImpZ0FGA2QrFzIQRl+n+e027QRetsaYLt9Unhy/XlwpWX9Jj349zxcDormVWc4rFg== 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=btKD+9l64Dm5C0jGR73EDTonH+mSGph8ttXh8fFwgw8=; b=G+8rzd2YzmEpkhjfwe99yJM2cTUyWn2GQ03Bf6O18x+wN2GklfybVFg4thz+a0cRhem3lfE8Jf/avQXbnX59PcgguDemOjanhjWzuOWJ2EBJ5HnPAxWwwB1sOWxMkutztP4qwgxMhqgwxlLzlZ9fWergxG6PKZZZQDLn2GBH9gI= Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by GV2PR08MB9301.eurprd08.prod.outlook.com (2603:10a6:150:d4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Mon, 18 Mar 2024 15:20:33 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::8b1b:5f28:5006:ac18]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::8b1b:5f28:5006:ac18%4]) with mapi id 15.20.7386.023; Mon, 18 Mar 2024 15:20:33 +0000 From: Wilco Dijkstra To: 'GNU C Library' Subject: [PATCH 2/2] Add single-threaded fast path to rand() Thread-Topic: [PATCH 2/2] Add single-threaded fast path to rand() Thread-Index: AQHaeUdlLczthbtZN0yQRvy3br3L0A== Date: Mon, 18 Mar 2024 15:20:33 +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_|GV2PR08MB9301:EE_|AMS0EPF000001A8:EE_|DU0PR08MB9821:EE_ X-MS-Office365-Filtering-Correlation-Id: e163ebcf-033c-48df-88ca-08dc475efb02 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: tcGO2RRzf45I3qzP1+8ieSQeKOoF3I29sgieosAJIGd/yX8hrjktJpSkxlLXqa9/QB+s9wglq+gQtrnDYhn6XXoz7qju6zyFFHe95LTKSjeRQt9jKZQZPAPNaTW+FE07BYWxq049VevcqSBFbp1Oo+NpsYu85q5+3IAgsGb6hQ7/QRF5TWDX+VJLLT77JGTZofMFAI/6Q8QLo/YELafQ6jxl/k90MAWgvJ2F30/13yVPxZApmQTHdjprGZI9KE4mUOt8NAJfBvRq1KVIgATcBz0Z1hpf01Y8OEiISiLuuS3d0/fBGW8Oj9FU/1dAdUJu/L3uvWdFwiimejcfl4EYSB0fawgSnMgB6BsiuzdQjKw/18BRlE0Vh6MQfMRicMQ/ijNGSd/hpIG7Nedp+rRY3Vywj1prwGscjCG77oht9G0OCn7PVv+lQav+orUAaS3TO89WQ5StjW6RoS3FzqFuitC5jBqWGxIr25i3PL/FmaSBY9xBJC4I70MqGenSiHxRAxj+6eOdyWy+63pfhGTLtLUOVu1zxgruxwSgDiHzLUC9N2lOHKYjqtaeTKEB6KwH8DmrM19qZ+aeENB1CkdxYOTptP1sNbtbypxMeSP/p1yhCo8q3ztgNnFowNnHkvGIOd83oM2DuG24qGdEtIbEjuJyP0cOIpblpAXunbm/SjANendYqJqcFB0Jdmz82mY2NyKFoCfQ5W6hr85Zh64rcA== 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)(366007)(1800799015)(376005)(38070700009); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9301 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: AMS0EPF000001A8.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 0ca2e880-fd37-44cd-9ba2-08dc475ef476 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PjIGCnlYLPij9ygLrj5JM2U12YTtX/N4M9CzsaPS0wP8PDY/s6yAYrDnYhINkiOosM+m6Vo4M3Iyu9uZ7H+NZ/ZlRDjjYAvdBOMchypIvW9V5S0+NXyDNnptpGVaHfneiujSsugcjFP7JtJcc/BkZ1ltUajUCTAzyTems1IUBmnzKx/85Dj0GtBS7GKw1p/xFZLVAZ0B/+lh4m+Cx5IX6RhLQ2gX3AV9KI/t9Q2ANug9gg/OQdIVrIp2ru35M76+JDjXJUaAzK0M5anTi1mtqV6r+nJJzvwaGRl/5RlIgFCvRNQ9AFlYER0gUJUYMVMju+4OfGi1n3f7+8bWW5y8tkZDzI/o824vZkIQKDS4AmvCTfBD4vXW9mGJcfR+44IV9x9v63IkVP9aXmO7Sd84FAlf+33MnvqLe+MivP3Wpol7rkeu9K6jM/tBMsK+g7ZoJN4ecqNNaWXs2dL+yQK/mBWmKdJytP/91HJV34y1j4Ti3hror4H+gEj2Ij30kcHl5FeuMHeUHtFWJRfVDOQabaovZniN/wU510AAHlQs8/HVS3YRvFfuhRtTTjUNKFuo1vziJiHOnFlcF82B+8TFaS0jCOOMuN6FNlAncp4rtWeXwVYkaqudR4u+0J3IXFeac9eVA4zRja3WGSCGozlTMnEj3hTqUHWR7hv+B4hk9YIIgJdV3bGWWR+FvAfMvF6W3TGzkHIr5W3431TpH+Xqe02ORdqYSoy2Nmu7iKRAqOcWnWYRXzjHr7dHvEgdN4LN 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)(1800799015)(376005)(36860700004)(82310400014); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2024 15:20:44.2419 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e163ebcf-033c-48df-88ca-08dc475efb02 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: AMS0EPF000001A8.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9821 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+patchwork=sourceware.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. OK for commit? diff --git a/stdlib/random.c b/stdlib/random.c index 62f22fac8d58c7977f09c134bf80a797750da645..174603a8915fd8aa4b3ae64d023003c9e2c038f2 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);