Message ID | PAWPR08MB8982DC44B324DE1952A3EE97838EA@PAWPR08MB8982.eurprd08.prod.outlook.com |
---|---|
State | Superseded |
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 39FED3857C4B for <patchwork@sourceware.org>; Tue, 12 Dec 2023 17:43:43 +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 <libc-alpha@sourceware.org>; 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 <Wilco.Dijkstra@arm.com> To: 'GNU C Library' <libc-alpha@sourceware.org> 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: <PAWPR08MB8982DC44B324DE1952A3EE97838EA@PAWPR08MB8982.eurprd08.prod.outlook.com> 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; Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
Series |
[v2,1/2] Add random benchmark
|
|
Checks
Context | Check | Description |
---|---|---|
redhat-pt-bot/TryBot-apply_patch | success | Patch applied to master at the time it was sent |
redhat-pt-bot/TryBot-32bit | success | Build for i686 |
linaro-tcwg-bot/tcwg_glibc_build--master-arm | success | Testing passed |
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 | success | Testing passed |
linaro-tcwg-bot/tcwg_glibc_check--master-arm | success | Testing passed |
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 | success | Testing passed |
Commit Message
Wilco Dijkstra
Dec. 12, 2023, 5:43 p.m. UTC
Improve performance of rand() and __random() by adding a single-threaded fast path. Bench-random-lock shows about 5x speedup on Neoverse V1. ---
Comments
On 12/12/23 09:43, Wilco Dijkstra wrote: > +#include <single-thread.h> > #include <limits.h> > #include <stddef.h> > #include <stdlib.h> > @@ -288,6 +289,12 @@ __random (void) > { > int32_t retval; > > + if (SINGLE_THREAD_P) Since random.c is sort-of shared with gnulib, would there be any harm in using the user-visible "#include <sys/single_threaded.h>" and __libc_single_threaded instead? That would lessen the differences between the two source files. (I don't know why glibc code sometimes includes <sys/single_threaded.h> and sometimes <single-thread.h>.)
* Paul Eggert: > On 12/12/23 09:43, Wilco Dijkstra wrote: >> +#include <single-thread.h> >> #include <limits.h> >> #include <stddef.h> >> #include <stdlib.h> >> @@ -288,6 +289,12 @@ __random (void) >> { >> int32_t retval; >> + if (SINGLE_THREAD_P) > > Since random.c is sort-of shared with gnulib, would there be any harm > in using the user-visible "#include <sys/single_threaded.h>" and > __libc_single_threaded instead? That would lessen the differences > between the two source files. (I don't know why glibc code sometimes > includes <sys/single_threaded.h> and sometimes <single-thread.h>.) We can put the whole optimization into an #ifdef _LIBC block. SINGLE_THREAD_P is more optimized than the global __libc_single_threaded variable, and the difference is likely going to be visible on some architectures on some architectures. Thanks, Florian
Hi, >> Since random.c is sort-of shared with gnulib, would there be any harm >> in using the user-visible "#include <sys/single_threaded.h>" and >> __libc_single_threaded instead? That would lessen the differences >> between the two source files. (I don't know why glibc code sometimes >> includes <sys/single_threaded.h> and sometimes <single-thread.h>.) Which header should be used is confusing indeed. It seems that sys/single_threaded.h is more frequently used, so I'll change it to that. > We can put the whole optimization into an #ifdef _LIBC block. > SINGLE_THREAD_P is more optimized than the global __libc_single_threaded > variable, and the difference is likely going to be visible on some > architectures on some architectures. Given there are many uses of SINGLE_THREAD_P scattered around GLIBC this should really be done in the header or alternatively gnulib could define its own SINGLE_THREAD_P (no idea how it works today given that stdio and malloc have many uses). Cheers, Wilco
On 12/12/23 15:47, Paul Eggert wrote: > Since random.c is sort-of shared with gnulib, would there be any harm > in using the user-visible "#include <sys/single_threaded.h>" and > __libc_single_threaded instead? That would lessen the differences > between the two source files. (I don't know why glibc code sometimes > includes <sys/single_threaded.h> and sometimes <single-thread.h>.) Paul, Please update glibc/SHARED-FILES if random.c is being used by gnulib. We actively use SHARED-FILES to ensure that gnulib code changes have copyright assignment to the FSF. This is explained to new contributors via: https://sourceware.org/glibc/wiki/Contribution%20checklist#Copyright_FSF_or_disclaimer Please also note that it is not clear to me that all of the copyright in random.c is assigned to the FSF given the origins of that code.
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 <libc-lock.h> +#include <single-thread.h> #include <limits.h> #include <stddef.h> #include <stdlib.h> @@ -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);