From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12hn2235.outbound.protection.outlook.com [52.100.165.235]) by sourceware.org (Postfix) with ESMTPS id 442AA3858D38; Fri, 30 Sep 2022 13:18:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 442AA3858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=darrentristano.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=darrentristano.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kNtze+3REJUnI0lcmQEv5O9IJzPE8Ugrz0yZNEblGJ+BTbQMIIddhZU95yFQN/HR4iQtt+HYY3iJrA1ZWNwDuvlo7kSaSj26xVSzEVh6XQuiGtgsx+wq3e870YrEMm3YQ8CVUNB7ta+GiGLcY0kclTOdkLs1P9UO1imqx98KdkolaginkAKibsGX49+Uf4DE/1tSI6dF0B39Bb/LqTkeJ621sS36PYt7MYuiOkcEhflBJjOLVjveEN5pr/iPfHEEri0huci4Q8f6TgQwS5iB/LSEEVzbMFmu5q/hwbDiNeZSfxuJ7gp8BUCfQJ63NwmVQXETiYQ1QDKlkZvMhBm8Ww== 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=NdOpVDcbFsHyn8x/CVlvqxzzveLo75xnJcYyBa22MTo=; b=ECYh0xj5fKYMOI8WZx8RUH1LrGCNRK+wf9Dp0uLvlBdDBfvrYslRpdojC8vovbSdR2fMXMiFoNs/ohyPzqewZV8wqUOMSJdYAyirLA7BXCG7syXBIdTyV0uZlgtCEPoVKGUwwWzcJyCFlvw9TDp86wM3+Etrpqw+LDD/09Gd+0CZoYbDP/f1RqNP7AzsRwxgBUjAKvgHUudDfoMTJjgjZ9I756tlqgai2TfUqzpbVeGh3ft5aaIpNWOCGMx3TOPlkVKYyaoD5UopyP5EaS8yVEnx5Rs7GIUbdnF3zvyc/y/kvQSyzw/hjPBLzaSlsCOZoS1/awIpclG9uMU2imMrjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=darrentristano.com; dmarc=pass action=none header.from=darrentristano.com; dkim=pass header.d=darrentristano.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NETORG3144382.onmicrosoft.com; s=selector2-NETORG3144382-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NdOpVDcbFsHyn8x/CVlvqxzzveLo75xnJcYyBa22MTo=; b=bVuuxauziOxXpjI7VPBXFbjVo7hAaWo1evc4UzCi6Gd7W8u7iaeCYBWiq0S7U4zWMVKNN5Sqjzl7a32QBHGeZyYT0AJOWf4U1iKmyhIz0FOygXcuSBvyfsAJb8rYCYHsbb5k8CkDloLwmFbj1zbqlxz1SCH+7MOr+/51yFktzwA= Received: from CH2PR17MB3541.namprd17.prod.outlook.com (2603:10b6:610:45::16) by MW4PR17MB4385.namprd17.prod.outlook.com (2603:10b6:303:7d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Fri, 30 Sep 2022 13:18:16 +0000 Received: from CH2PR17MB3541.namprd17.prod.outlook.com ([fe80::4702:617:871d:b3cb]) by CH2PR17MB3541.namprd17.prod.outlook.com ([fe80::4702:617:871d:b3cb%5]) with mapi id 15.20.5676.023; Fri, 30 Sep 2022 13:18:16 +0000 From: Darren Tristano To: Sunil Pandey , Noah Goldstein CC: Florian Weimer , GNU C Library , Wangyang Guo , Libc-stable Mailing List Subject: FUCKETY FUCK FUCK, PLEASE REMOVE ME FROM THESE EMAILS Thread-Topic: FUCKETY FUCK FUCK, PLEASE REMOVE ME FROM THESE EMAILS Thread-Index: AQHY1M8ZD/uh1n7XvkeComxdHwjW7A== Date: Fri, 30 Sep 2022 13:18:16 +0000 Message-ID: References: <20220504031710.60677-1-wangyang.guo@intel.com> <20220506015010.362894-1-wangyang.guo@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=darrentristano.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH2PR17MB3541:EE_|MW4PR17MB4385:EE_ x-ms-office365-filtering-correlation-id: 561e7c38-f649-4cc6-01cf-08daa2e63c2f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: =?us-ascii?Q?QITR7NsJRGrZWwoIuZgnuoq/1aLABFiQBYt/Fu55nR7KK0NxJ1ffgb6OS+rQ?= =?us-ascii?Q?x59jnDwkfX2oTNiyl7PzgG5QFD+4C1V1MqNjZXfntK82+Ud4qwrW9fHIG0BS?= =?us-ascii?Q?9BlpLMOdTI0BKQ4teHW/lLTqViambaDlnHb+1QHrjdE3zj3YaMUwjrC0ErRS?= =?us-ascii?Q?RpLsH2alwrDFlW0tzZ/VyXMNwZx8S9EDGUVshYVgrs2sXrsxrjKB8Vl1pSgU?= =?us-ascii?Q?QOPOOitJ1Il3j4v2M9kbsLRjknydTizKloCaMYN2C0gk5V2BacTVwnVinWeQ?= =?us-ascii?Q?riIZWDkOZLw/8U/zkGGlIpWcA4UErrf8gJsn8fCyuRAIifUJeGr0UsMI+B+U?= =?us-ascii?Q?SfLDb4quhNemDGcEy9hoHwfgA6QJ79qX/J02Hyna6pmGZEKNyvJ0eiopiryr?= =?us-ascii?Q?+bTJm03BGsVq1+scRggYf2wsiLCkhrwtLicq0EnHagfx6OLXthVgY136Asaz?= =?us-ascii?Q?po+7pv0OXl8nuBn6y4fEJx9k37njKCpQOX8oEotkicMPc1KxLCbq8She6Ep1?= =?us-ascii?Q?kIQRsR8xXC/3emhUN0Gg2/daBVJCN/i1aOUhPM49q5dh1q/9aNurGbcZbzFd?= =?us-ascii?Q?qcbtqdUDDXNiMZXbqCSVHOpc3+VSkX+FvJ/KX/BRGvHR9l3mJxDFQB8r/s/s?= =?us-ascii?Q?QJkRcXzy147FWs3E0+g8q8wKcuSo5pipdPyWE2I7+dto1Hbqainz7Ks2hMYZ?= =?us-ascii?Q?snLR7pv0X5dz6/eC7ppHm05CGoZVWAFB/6su8CWkEPK19QJc4q586R7l6OqC?= =?us-ascii?Q?0neXUTd7LwVOPQkaPyf1PYhH2cYCgERv4ytkAq95W7uRsginNWRDwlBDswuO?= =?us-ascii?Q?BZL6yFTgPcJftyYn6Ck8cQ/pTA0XO+sG3N8udZbjVpCK5vXFS6MuQz4Rv0Yt?= =?us-ascii?Q?+ekDvVsLu492uc53E52q4qfGcG/cL/FKmlSOSJ6IJQnumZE0mlmnBzuAwKC5?= =?us-ascii?Q?ADCNJevVOpWoJrZeS7jcAclJbNJx5jWxZp3Wy4s5ClJWhf1sEJ6Kan+cu+53?= =?us-ascii?Q?W7MsfW09HFNfTkFW+4cCj9yBfp3vtoGKswi/W8nfEtgJOtwLbZk5b8j5loMX?= =?us-ascii?Q?2jA7I9u5V8bzt0c2b2iOLQjPYNtVuZlxok6h9e0jjGIpDsIwBXMqlJ/A3DVZ?= =?us-ascii?Q?DN9Oiu5YxaTLifkznrkFNz8BQfqfEVyYEx81VKTpfzB1cY6earXwh1anC3AK?= =?us-ascii?Q?tnBPtGsVR3GQ5MW442xLm7wAThS9G+xt3Gjs1KbSXOwXBryu2mCPcL7ulol+?= =?us-ascii?Q?P8S/qpt9ms08CYyzlEWA?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:CH2PR17MB3541.namprd17.prod.outlook.com;PTR:;CAT:OSPM;SFS:(13230022)(376002)(366004)(136003)(396003)(39830400003)(346002)(451199015)(19627405001)(54906003)(478600001)(316002)(110136005)(2906002)(55016003)(86362001)(66476007)(66446008)(64756008)(76116006)(66946007)(66556008)(4326008)(8676002)(38070700005)(41300700001)(6506007)(7696005)(53546011)(26005)(122000001)(5660300002)(8936002)(9686003)(30864003)(166002)(52536014)(38100700002)(33656002)(186003)(83380400001)(71200400001)(124803006)(556444004)(2004002);DIR:OUT;SFP:1501; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?OeIoyUqAREja5+1uTu5AMyLAJLJdxMlLPmzvGB0CqQAy71+dtwbooUevPhRj?= =?us-ascii?Q?iWwHQOMNeL7h+RrtlAakJFN8lQLPXmgVrbAalAK+Sc1Pi432QRVi1jCtVosx?= =?us-ascii?Q?Iha5yemChZo7aeYenBeR4NVNqyME9l6eWv8gPuE5qZsEB0SVD7dfkuyf+FCO?= =?us-ascii?Q?zIwLgifAu0BZKURGA1EWggOcLfvNQsxRtDJoNrh98HuhXpfA/l8qtx+JYR9O?= =?us-ascii?Q?tG9FrXabJJXqGW1ZwYjPr0QwD9bvij5sqF5WnldFV2piL29CMf9xnFG85mUS?= =?us-ascii?Q?BvHk5mom/r+FepCIQkrxTijauVl/nAOB8wAmEYtyVlI4y+kql/AKJmoK/cr5?= =?us-ascii?Q?VcDY6PUCm4k4mUXW15yZVYS9aEhK/izcP77Av1jsYZgtJ3reJCm7qQQVw79c?= =?us-ascii?Q?SR+vizbOPx8l2kVtXEHjtezzLtno7u6PUXPOdzmFokZz8iDQlvtuMSIoJ/+r?= =?us-ascii?Q?3Sv9qtiBV4P5GCGi8dfPU0/dXNDU/mSQgzY7aXz+CH8arO9ajUkDDgzGGVt9?= =?us-ascii?Q?+YcYq6RyoHuLirXCrPUiMeIxEVg2ZqQLEVN2ADIljOUSIe6Y+Vz9CEqxv2Hc?= =?us-ascii?Q?d5pLf/B/u8yXtYpoSwvuj8Bdu38v1lq7UFSYCnKbFvXijIkUf04tTAIRRfZX?= =?us-ascii?Q?8QzDDmHozU7NpyKwLld7XMXkbJULKGbdeUpjlvZPmEo2WeZ8/qKef45Sriqf?= =?us-ascii?Q?U80TJUDoFfwIGTwriJamRPba1yvctpzLmoOVMn1cG9IofnRTwis9KwLUgHAo?= =?us-ascii?Q?SbovZKJ4i0ntV2kriAWFM5h44fpA+Ay1pFecxkNEhUM8HDZflkm4is9CDJSs?= =?us-ascii?Q?CZWMOJS57vBkk2BxX7C2thwlJgn8zazygzI8RQi+o2DveMn9ScAlzcL41RVs?= =?us-ascii?Q?W+l70XlNW6ECmb3rc5PtYMQ62ZN8rc6yJEGiA33HYndaaaozMfn63vzQy7Rw?= =?us-ascii?Q?4w2+pkH43cgjZds4oCK+acw92+Bf1S2vfG2L0r1bxeiLa4+L6wwBcxng0hQV?= =?us-ascii?Q?W9spqmUsf90epppiu6KVOmmS0HiUb5r5plZ/cb3mc/2A2PJOv/SQEQxiHH6z?= =?us-ascii?Q?14MtzGHe7nXQ0zBPeuNTtjlRs7iPpHhAExyKsqoMcNMjRzLLL/iUi0Gny8Zn?= =?us-ascii?Q?UP/CM+BWJJ8WRtJOOZZTZodU4mwPrpVQN8hC3UIvUa6zc/BY3htQLwlhuiPV?= =?us-ascii?Q?/ljBFKMb8myMLgMHYC+8ADMlr++q7lUAvyjTSidzAjuwS7DfUi3dNUybjMUa?= =?us-ascii?Q?8zYy7dG5URI7qgBraK5YD8tfT3HPUXNR2erwECXoL2lP5bKZiOgjKE9hjHSB?= =?us-ascii?Q?dVvsVNGGbHSv8XhiQyefY7+Oz5cPUNuzcBDRD/wi2hBv4MHmCLwuzF9ki8Xg?= =?us-ascii?Q?Pe2MS1APt5oz6yL4+Ut95A6es5PjlL3NW0dwo786ulVOOZHwG6/UVrp4Vn63?= =?us-ascii?Q?BgUYg/z28NSNqxGKqxamj4Qqu+DQjH4CVhY30J4/z5sAVdkvKsaICCC3JglO?= =?us-ascii?Q?Rm8kpSGzAjTVGge1lMGw3lYdTPcjEdTXa/X5oRbXWy8hVTor8gZAtcCYbKRD?= =?us-ascii?Q?qtyxxAQUw7VeIitBMLWoOFx1hMPUBPm11dpsTKS3?= Content-Type: multipart/alternative; boundary="_000_CH2PR17MB3541C13E1355A609E541704BBD569CH2PR17MB3541namp_" MIME-Version: 1.0 X-OriginatorOrg: darrentristano.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR17MB3541.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 561e7c38-f649-4cc6-01cf-08daa2e63c2f X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Sep 2022 13:18:16.1769 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 595cff3a-a98e-4be2-a9e0-981f0e29e085 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: YPP4a3kC+KfXNhyFYwNuI8oJL/wfpTo+mz56ok6fsQWEQ803LmR5KkGikDUZoCQyFjDESMYzfGrgQdY13RX5U7+NJs6EwH221ZL4zePlRK0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR17MB4385 X-Spam-Status: No, score=-10.1 required=5.0 tests=AXB_X_FF_SEZ_S,BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,SUBJ_ALL_CAPS,TXREP 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: --_000_CH2PR17MB3541C13E1355A609E541704BBD569CH2PR17MB3541namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable FUCK FUCK FUCK ________________________________ From: Libc-stable on behalf of Noah Goldstein via Libc-stable Sent: Wednesday, September 28, 2022 7:12 PM To: Sunil Pandey Cc: Florian Weimer ; GNU C Library ; Wangyang Guo ; Libc-stable Mailing List Subject: Re: [PATCH v5] nptl: Add backoff mechanism to spinlock loop On Sun, Sep 11, 2022 at 4:30 PM Sunil Pandey via Libc-stable wrote: > > On Thu, May 5, 2022 at 8:07 PM H.J. Lu via Libc-alpha > wrote: > > > > On Thu, May 5, 2022 at 6:50 PM Wangyang Guo wr= ote: > > > > > > When mutiple threads waiting for lock at the same time, once lock own= er > > > releases the lock, waiters will see lock available and all try to loc= k, > > > which may cause an expensive CAS storm. > > > > > > Binary exponential backoff with random jitter is introduced. As try-l= ock > > > attempt increases, there is more likely that a larger number threads > > > compete for adaptive mutex lock, so increase wait time in exponential. > > > A random jitter is also added to avoid synchronous try-lock from other > > > threads. > > > > > > v2: Remove read-check before try-lock for performance. > > > > > > v3: > > > 1. Restore read-check since it works well in some platform. > > > 2. Make backoff arch dependent, and enable it for x86_64. > > > 3. Limit max backoff to reduce latency in large critical section. > > > > > > v4: Fix strict-prototypes error in sysdeps/nptl/pthread_mutex_backoff= .h > > > > > > v5: Commit log updated for regression in large critical section. > > > > > > Result of pthread-mutex-locks bench > > > > > > Test Platform: Xeon 8280L (2 socket, 112 CPUs in total) > > > First Row: thread number > > > First Col: critical section length > > > Values: backoff vs upstream, time based, low is better > > > > > > non-critical-length: 1 > > > 1 2 4 8 16 32 64 112 = 140 > > > 0 0.99 0.58 0.52 0.49 0.43 0.44 0.46 0.52 = 0.54 > > > 1 0.98 0.43 0.56 0.50 0.44 0.45 0.50 0.56 = 0.57 > > > 2 0.99 0.41 0.57 0.51 0.45 0.47 0.48 0.60 = 0.61 > > > 4 0.99 0.45 0.59 0.53 0.48 0.49 0.52 0.64 = 0.65 > > > 8 1.00 0.66 0.71 0.63 0.56 0.59 0.66 0.72 = 0.71 > > > 16 0.97 0.78 0.91 0.73 0.67 0.70 0.79 0.80 = 0.80 > > > 32 0.95 1.17 0.98 0.87 0.82 0.86 0.89 0.90 = 0.90 > > > 64 0.96 0.95 1.01 1.01 0.98 1.00 1.03 0.99 = 0.99 > > > 128 0.99 1.01 1.01 1.17 1.08 1.12 1.02 0.97 = 1.02 > > > > > > non-critical-length: 32 > > > 1 2 4 8 16 32 64 112 = 140 > > > 0 1.03 0.97 0.75 0.65 0.58 0.58 0.56 0.70 = 0.70 > > > 1 0.94 0.95 0.76 0.65 0.58 0.58 0.61 0.71 = 0.72 > > > 2 0.97 0.96 0.77 0.66 0.58 0.59 0.62 0.74 = 0.74 > > > 4 0.99 0.96 0.78 0.66 0.60 0.61 0.66 0.76 = 0.77 > > > 8 0.99 0.99 0.84 0.70 0.64 0.66 0.71 0.80 = 0.80 > > > 16 0.98 0.97 0.95 0.76 0.70 0.73 0.81 0.85 = 0.84 > > > 32 1.04 1.12 1.04 0.89 0.82 0.86 0.93 0.91 = 0.91 > > > 64 0.99 1.15 1.07 1.00 0.99 1.01 1.05 0.99 = 0.99 > > > 128 1.00 1.21 1.20 1.22 1.25 1.31 1.12 1.10 = 0.99 > > > > > > non-critical-length: 128 > > > 1 2 4 8 16 32 64 112 = 140 > > > 0 1.02 1.00 0.99 0.67 0.61 0.61 0.61 0.74 = 0.73 > > > 1 0.95 0.99 1.00 0.68 0.61 0.60 0.60 0.74 = 0.74 > > > 2 1.00 1.04 1.00 0.68 0.59 0.61 0.65 0.76 = 0.76 > > > 4 1.00 0.96 0.98 0.70 0.63 0.63 0.67 0.78 = 0.77 > > > 8 1.01 1.02 0.89 0.73 0.65 0.67 0.71 0.81 = 0.80 > > > 16 0.99 0.96 0.96 0.79 0.71 0.73 0.80 0.84 = 0.84 > > > 32 0.99 0.95 1.05 0.89 0.84 0.85 0.94 0.92 = 0.91 > > > 64 1.00 0.99 1.16 1.04 1.00 1.02 1.06 0.99 = 0.99 > > > 128 1.00 1.06 0.98 1.14 1.39 1.26 1.08 1.02 = 0.98 > > > > > > There is regression in large critical section. But adaptive mutex is > > > aimed for "quick" locks. Small critical section is more common when > > > users choose to use adaptive pthread_mutex. > > > > > > Signed-off-by: Wangyang Guo > > > --- > > > nptl/pthread_mutex_lock.c | 16 +++++++-- > > > sysdeps/nptl/pthreadP.h | 1 + > > > sysdeps/nptl/pthread_mutex_backoff.h | 35 ++++++++++++++++++ > > > sysdeps/x86_64/nptl/pthread_mutex_backoff.h | 39 +++++++++++++++++++= ++ > > > 4 files changed, 89 insertions(+), 2 deletions(-) > > > create mode 100644 sysdeps/nptl/pthread_mutex_backoff.h > > > create mode 100644 sysdeps/x86_64/nptl/pthread_mutex_backoff.h > > > > > > diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c > > > index d2e652d151..6e767a8724 100644 > > > --- a/nptl/pthread_mutex_lock.c > > > +++ b/nptl/pthread_mutex_lock.c > > > @@ -138,14 +138,26 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex) > > > int cnt =3D 0; > > > int max_cnt =3D MIN (max_adaptive_count (), > > > mutex->__data.__spins * 2 + 10); > > > + int spin_count, exp_backoff =3D 1; > > > + unsigned int jitter =3D get_jitter (); > > > do > > > { > > > - if (cnt++ >=3D max_cnt) > > > + /* In each loop, spin count is exponential backoff plus > > > + random jitter, random range is [0, exp_backoff-1]. = */ > > > + spin_count =3D exp_backoff + (jitter & (exp_backoff - 1= )); > > > + cnt +=3D spin_count; > > > + if (cnt >=3D max_cnt) > > > { > > > + /* If cnt exceeds max spin count, just go to wait > > > + queue. */ > > > LLL_MUTEX_LOCK (mutex); > > > break; > > > } > > > - atomic_spin_nop (); > > > + do > > > + atomic_spin_nop (); > > > + while (--spin_count > 0); > > > + /* Prepare for next loop. */ > > > + exp_backoff =3D get_next_backoff (exp_backoff); > > > } > > > while (LLL_MUTEX_READ_LOCK (mutex) !=3D 0 > > > || LLL_MUTEX_TRYLOCK (mutex) !=3D 0); > > > diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h > > > index 601db4ff2b..39af275c25 100644 > > > --- a/sysdeps/nptl/pthreadP.h > > > +++ b/sysdeps/nptl/pthreadP.h > > > @@ -33,6 +33,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include "pthread_mutex_conf.h" > > > > > > > > > diff --git a/sysdeps/nptl/pthread_mutex_backoff.h b/sysdeps/nptl/pthr= ead_mutex_backoff.h > > > new file mode 100644 > > > index 0000000000..5b26c22ac7 > > > --- /dev/null > > > +++ b/sysdeps/nptl/pthread_mutex_backoff.h > > > @@ -0,0 +1,35 @@ > > > +/* Pthread mutex backoff configuration. > > > + 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 usef= ul, > > > + 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 > > > + . */ > > > +#ifndef _PTHREAD_MUTEX_BACKOFF_H > > > +#define _PTHREAD_MUTEX_BACKOFF_H 1 > > > + > > > +static inline unsigned int > > > +get_jitter (void) > > > +{ > > > + /* Arch dependent random jitter, return 0 disables random. */ > > > + return 0; > > > +} > > > + > > > +static inline int > > > +get_next_backoff (int backoff) > > > +{ > > > + /* Next backoff, return 1 disables mutex backoff. */ > > > + return 1; > > > +} > > > + > > > +#endif > > > diff --git a/sysdeps/x86_64/nptl/pthread_mutex_backoff.h b/sysdeps/x8= 6_64/nptl/pthread_mutex_backoff.h > > > new file mode 100644 > > > index 0000000000..ec74c3d9db > > > --- /dev/null > > > +++ b/sysdeps/x86_64/nptl/pthread_mutex_backoff.h > > > @@ -0,0 +1,39 @@ > > > +/* Pthread mutex backoff configuration. > > > + 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 usef= ul, > > > + 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 > > > + . */ > > > +#ifndef _PTHREAD_MUTEX_BACKOFF_H > > > +#define _PTHREAD_MUTEX_BACKOFF_H 1 > > > + > > > +#include > > > + > > > +static inline unsigned int > > > +get_jitter (void) > > > +{ > > > + return get_fast_jitter (); > > > +} > > > + > > > +#define MAX_BACKOFF 16 > > > + > > > +static inline int > > > +get_next_backoff (int backoff) > > > +{ > > > + /* Binary expontial backoff. Limiting max backoff > > > + can reduce latency in large critical section. */ > > > + return (backoff < MAX_BACKOFF) ? backoff << 1 : backoff; > > > +} > > > + > > > +#endif > > > -- > > > 2.35.1 > > > > > > > LGTM. > > > > Reviewed-by: H.J. Lu > > > > Please wait until next Monday for more comments. > > > > Thanks. > > > > -- > > H.J. > > I would like to backport this patch to release branch 2.33, 2.34 and 2.35 Fine by me. > > Any comments/suggestions or objections on this. > > commit 8162147872491bb5b48e91543b19c49a29ae6b6d > Author: Wangyang Guo > Date: Fri May 6 01:50:10 2022 +0000 > > nptl: Add backoff mechanism to spinlock loop > > When mutiple threads waiting for lock at the same time, once lock own= er > releases the lock, waiters will see lock available and all try to loc= k, > which may cause an expensive CAS storm. --_000_CH2PR17MB3541C13E1355A609E541704BBD569CH2PR17MB3541namp_--