From patchwork Mon Jul 7 12:10:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115753 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 8C5293857BB0 for ; Mon, 7 Jul 2025 12:17:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C5293857BB0 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id C11B13858C62 for ; Mon, 7 Jul 2025 12:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C11B13858C62 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C11B13858C62 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890301; cv=pass; b=jO03IJvuxgKL6AvKDn0HdySQcU96fz8t3Ctzv9FEZ/wGCn6CpybYvhNFq9kgOs+7tFwIKKXivGyDAeAis8DQCLl7gyvIE4hse5SFndnDpQ4kt+dEu9+URaIkj716zLb02NyhYHBhrWFRJ95XlmH85tmEoBScCZkXng1iPbrWwOw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890301; c=relaxed/simple; bh=fC9ngXZ74HcXT/ObNDrCcK4mAcOwMnqMkdpAQEEyHyM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=VifcKSSxkoWDnxrtEGftsWMIJAlxIreoiatl5+Nh98v5QN7CcwC3CKOr56C4k6vYJMS48fN2v4rCAlJ7fn0TYt0OaLBbXsgkvUQOi1GVbgHgJBn8IuolfK5Vbvb6zaBiyd/sEiXPRbGRtJlHf+87BX1tLEk+T8A+BQYq4ri4NEU= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C11B13858C62 Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 567Ag64a018969; Mon, 7 Jul 2025 05:11:31 -0700 Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10on2064.outbound.protection.outlook.com [40.107.93.64]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pyb5hh58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nSXK3wUtq8BF3+LKEdNvB56c7pGXgD1m6BZYn5WaN1A/9lGmBV5Y9Sbh8zokNabHwWUUasV6O0J7ELomK/43oNHy5SHrixhAbOvbzxwtTRZ7EDDW0XW9BWTujRdLo6KT5GhZbR6qSFmL+1WibRGHl/an0WdD956jDRN9cU8y9UmIxq/DS5OQC65jbzsgeWhW5oLWIdxs6DPKwXFDv2jCvVqis+MqenBX27gDFiI+HoZF5VBVWlJu1pqfyTWbPVcGAs4OYMoorM3oYkerhqRtE3kXOc6Tacb+/Uit1S5OU/mKRwuoSTPJLNOKeHFtZZkIpwroQjMU368D++Y0ytRVhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=v4qw/F8F5qhJv/lgG59I0e0n+BBDE/jziLOVT32jPV4=; b=jsykNixuyan/iBTlcOKsw8porVrbELaPE6D5FbEGZVOOhEcY7fThvHCPkye8+dkRS1bdweMt+yEKK3qb/EP4CzF8g+iO36+kuCaxEmz/cRaJ+ojyOk/ifRxC7mAgmGWX9qkbQYH21MSr6VBOuklp8PmtYvyyIx1ImiVoApi8g6saBMpQBHignHhFkT2AQa6T91helcM9OkVfV4ZAqObmaSQOUR7iLSlZnvSqAkowoiOVGt+/wVhe2nA+PJiRidzdP0Ic40uNpCwKfJ9Vyt0xRJzZpGogspppz7i3aDI0I0WELzvbeUiLIwGDuQdCCTDQNleyaDnOTj64Mrm5xRavpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:29 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:29 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 01/10] [2.37] pthreads NPTL: lost wakeup fix 2 Date: Mon, 7 Jul 2025 05:10:56 -0700 Message-ID: <20250707121105.2226766-2-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: da52fce0-fe57-473f-d02e-08ddbd4f6752 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: D0FVg/1BDMPM8FYbb2GH0/4oaekrUJXCkKYlGFqq1tCVaOb3XKUsHRVf5Fs+ucjP34B5zlRZca/Oddw8NRXfi6gWTc7y0Wg0bAmwj9L0KoNcSyEDrSIeQSUpkUiJREXrtojshMykkwvd+QTg9LmhG3NnWBohIDeDsN8qvzLdSN58SB1PmcXKkndEX1XaLC83MN6sLhKb3yrb1yvLvuDnY3d7k12t6H1yUwcylA6CcF9RL7y5E8SvYtpwk45cyTzu1rV/nQG+NsccZmzoNJqrYfNe2joMZ9BiBiIoFM/zHjrE9fCvEoL70OJSOncfya6vhtUXP0B01my9WhXEDD9GxL0CoVH6K+Mq0BEL7sV03jXSJHy1OsbtjQPNdyu8JROltyn4fWHWoZCP46eso9LpnUJn+05xJ9dHIM5n1ZhM6QhSDXiDzYnGBRd1BhnWtFW+9SSTGOKkxuIJodfQW/x/0DEpp8ZSh89jbZx3k2sI+I1/98YRg2mpLN/xxsq8/7Vj/YA68MI5pHibhgya5kKQamLFGeWlzHrOyy4QQR72oooQXZ4gEUahHE39jl0iDUzZOLQ51aWdr7U0Otnt/Ic84OAYkEg41Ljb0uN3gZIxBgyn4VzdyPTPO7Qpo1r4bSd1jCk7hN2n597+p/mj+PU2sh9jsZK4I7iIjf4Zwtvh1RtjTP6lXT20owxOtAI4scLOPffFqXc13hzddMCeGAvoWwJEYYUk9im1zdj3bvVghgByFMMpRUCw337yAw1D0NgxAHTnYlqTZ+cbXIwpBaqXrSyUT9vR3cdKr77R6QccrrnAaqB6IlwMdxmCZQTyN+I+X6Wpl+yWg4VuVsxgvtXmDwt1qBZRfTH+0YxYYLrU4vPyZJBkDBTABxzEVUYIpQZ39X12OmsIHRn/n/oCzSgBU3RxQdrrjYOANepCzXgfPF1fb8CjZx1tVUvNTgvOMTRLwnstAVrs+m8meXLspDBDWZXJgVt8LUBUj+GjOehH7wpTfPsd4prurIZm7YUBNRY52Fht440zcz7DsAWl1T4Mc4WNahPy3ucBNoezhcf8qsvpvYEX5JCKgzlnabTCACER/iID+MSv/ZXskt1ejOXICkxtCO3VnBsnMaxnolff24MuUD0unR1WGi4y/7nSE8+oKR0dRggX17LBYJsRfWoXR5rxlGW4vWW6VlTcIUUOnDG2RJufgNR+z56gfotELg4v6FBIwssIfTPq09SXy7zei99K5m/gOYGi2OV3EoMltdOXKp4njdoujPyOQOoseHXG9N55yEsa8vEbCdAiCxW3ygS4I3LLwbMyiOwbpcO92cMYGOP4by/Ra0EJDemsdlKMtNg598+Z+FwTtKdO0ey/bmzUT9pgL2K2lnw7yBNtlToQo3iz9yLcvlnHR5t8stdZWD2lY2CeUSExnhG5G3hCWheMCLOZuouHVfHzCZ9l34H/bXzwr9Nb8f7wB9NmkMUv82c/ocY2bhlz/OI+1vSe1A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mjsj2f/KTpeAXVdTLm6TsiPKHQOXgGWmZv48aowzoZrVcaYvsPt+Si0g6+auxZd3BJfW45eVevVKOFrBoLedff/vgTzZ04PfXQiseQX3Z//AQ38F5/MsRJWYVCiJeSZRluh3EYt65i9aGlmQ4fXDL2ECKTlyjdypZEhHldb6KpTjGnD4DpqGGcHrL/nzScNUqp3Gp+WPCKblNkE7WMJgTp31YUy9FQw/Wo28SMQuCHJHlWucE6HoQI0aiq2T6KgJ9ylssFs6j0XAGYbL1DKz923CK7Tc0KKGAdCeV7/ZhKEE1J8ltKaW1xq2IFwZWX7i0kGdrUGWnsk953jVdJAXcikJalkTEktEl0par0qBneZ3W7sA9J848iYkzpQ5X2qYM+6/GtamsG8cfnx/r7HXbvdULMqs5HxNuGcqF/HWMT5R1uoSXBdVAm49KpatkpBPJvGtNmrbMs8mxiBtADCCbvGlXDsbtg9vmQl+Hpsw28OXNUCD95weeWAFgFWrY9vnQmHxbFr84eTm9GFWQLPsCuV2CZNBCyua8hnX02iXtLTmA3NruJScgqciSIFGEus8xpmhyplJV4XjAjFE+KW1ci4yV2MDf/C+/pMQtXICj+gq1gJibOL+0HSOZ0JHmpYfbarvPAfYX/i/QO8xoqKKkHKDMvZOW5OXXxPH/AsvodFuM8akMPdfxZWklxoyiVqjvQem6azRj0xwnVebYQAzPwcgn8pXNhwtktbrsuwdPGZweSkE5T67Mu1Cpn7BSn6A7+qJXTxIchZAEyZmRIItmKtHH0zMPzqlFt9HBFopDiY8nPhmx4W84mZ0jrv6M3hS7QC8z6BapWHMwVQHgYERdnxGZVSjSI4E0LFnBN0CAH/XkXZMMbNqECz6Gd2E3O3w8QLoK8x5mqiXyAzUfdpnf9Z13Dxq9oyGphPGhWW85bDeR+TSg3UAubqNU6wnCtIJsah0JGxmClwkR7kQjkop4YYdvNWqJcSvU1R/o2d7/+9Elvk0rVFSxnfh0ShdCvjwG8zD5SKtn9Z5loCU/K98YW1OQujPCLQpoEnd11AsRN6LgCjrHaP6yaQor5DkoDsz9XRff0uHMNAruyLMVxSLNJ/bcNjBvQiByOS5HXPVz51t42/h1meiTWpXPOFwmXi3p+NhaQZlmZG34jZGyi3ap9a61Xt7gOA+j87Vfmga+UgnSSVdK66ANvgaeUHe3VZugbCfePQA+YG/hzCjZGHtMruw5l3JgmkP4o8oL1fdKTJu6TzuuJ3VUV6vdXnxWh2QbssI7N/gGIm1BXnkvFf5WsN9PNQdqmLSruXcPZ/C8VEKYMnBO9F8JIr5lIxw07iLPTq45gC0SylBeVf3Zs5/MwaKuM4r9WWiIVXT+Qn972WIzMxqDhLP+w+zIvJqLmloMLhJx46v04gPA1EJ1EeZx9eZ4B9oxTsdg62GcrT3DaAQ5q5MOokiIBln4o+u+9sLGxzvSh/0iiwJ7RTWBh352OSmBoCgoCFUM1nj1NO8Bd9ERLrwz+V0Tj60+mBUugZ/nZ2bfCpoPhBYfszKV3X/HfmhAuZVk5VeajGxxbp29M0Z36mRpkQSEpIf6kC7d/vs2OKYD5uxOcJpQfLf075wlaM13Tey+f60Hr390NNKdMM= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: da52fce0-fe57-473f-d02e-08ddbd4f6752 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:29.2363 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 906PKzL5qmUT+o5pk8Psjo//2u/GT0DXTHauplHEzLmC8Xqk3Fla7F/3nS+obczdGdPeQaLTbrQdJEL0Brv6I6FXffUV+6ba3GpMe/h2N4Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX0i3Zo3LS1//J RjVtkoUVuYwQWDopS2lemfjFFFCPzuW56TMm/HSNHnoLvz7rXv3ZfaevmZMEZnXo4PMizjxbPQv nmk3yCYUKKosD2iRX5XbJIxtgJvW5wK1Ya6Ja1KZVHNJ2kCnjAAE5HO0wRcjGgifLEzPiolOn+b grfRL2BoyqDMybptBX+4WqZXJgrMFBlmehYPjk2kZZ5/+LD/ZjbrKbOzpUTkQ6Vk2Sl8yfrDZQe Ugzx7JPK0QuB5Bm8dRt25nle2YwyIfRs+8aRewRgKd/lKP3mUE0yXkBSHTtl7dZuInr4iyL0abF eMTv6CjUwdphReEBqJh9UvUlZIkiq1WgftwO112egL61QgO2ODGs22IJtcLOL+45rTLaMpk/h0V il2oHp1/vwx2a2gzyM5cA6QKnYPheCD6QsyW9bSQiMyplb4RozxH4brPIp+Ofpk+QcIYC+KK X-Authority-Analysis: v=2.4 cv=V5590fni c=1 sm=1 tr=0 ts=686bb973 cx=c_pps a=Rsm5HHQ7gKrYD0RmdLKlfg==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=UmlsspICldfRTSun98cA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: TKHMqp7dCy4cDBGh3MjfIL8VLWZ8pSie X-Proofpoint-GUID: TKHMqp7dCy4cDBGh3MjfIL8VLWZ8pSie X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1011 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Frank Barrus [BZ #25847] This fixes the lost wakeup (from a bug in signal stealing) with a change in the usage of g_signals[] in the condition variable internal state. It also completely eliminates the concept and handling of signal stealing, as well as the need for signalers to block to wait for waiters to wake up every time there is a G1/G2 switch. This greatly reduces the average and maximum latency for pthread_cond_signal. The g_signals[] field now contains a signal count that is relative to the current g1_start value. Since it is a 32-bit field, and the LSB is still reserved (though not currently used anymore), it has a 31-bit value that corresponds to the low 31 bits of the sequence number in g1_start. (since g1_start also has an LSB flag, this means bits 31:1 in g_signals correspond to bits 31:1 in g1_start, plus the current signal count) By making the signal count relative to g1_start, there is no longer any ambiguity or A/B/A issue, and thus any checks before blocking, including the futex call itself, are guaranteed not to block if the G1/G2 switch occurs, even if the signal count remains the same. This allows initially safely blocking in G2 until the switch to G1 occurs, and then transitioning from G1 to a new G1 or G2, and always being able to distinguish the state change. This removes the race condition and A/B/A problems that otherwise ocurred if a late (pre-empted) waiter were to resume just as the futex call attempted to block on g_signal since otherwise there was no last opportunity to re-check things like whether the current G1 group was already closed. By fixing these issues, the signal stealing code can be eliminated, since there is no concept of signal stealing anymore. The code to block for all waiters to exit g_refs can also be removed, since any waiters that are still in the g_refs region can be guaranteed to safely wake up and exit. If there are still any left at this time, they are all sent one final futex wakeup to ensure that they are not blocked any longer, but there is no need for the signaller to block and wait for them to wake up and exit the g_refs region. The signal count is then effectively "zeroed" but since it is now relative to g1_start, this is done by advancing it to a new value that can be observed by any pending blocking waiters. Any late waiters can always tell the difference, and can thus just cleanly exit if they are in a stale G1 or G2. They can never steal a signal from the current G1 if they are not in the current G1, since the signal value that has to match in the cmpxchg has the low 31 bits of the g1_start value contained in it, and that's first checked, and then it won't match if there's a G1/G2 change. Note: the 31-bit sequence number used in g_signals is designed to handle wrap-around when checking the signal count, but if the entire 31-bit wraparound (2 billion signals) occurs while there is still a late waiter that has not yet resumed, and it happens to then match the current g1_start low bits, and the pre-emption occurs after the normal "closed group" checks (which are 64-bit) but then hits the futex syscall and signal consuming code, then an A/B/A issue could still result and cause an incorrect assumption about whether it should block. This particular scenario seems unlikely in practice. Note that once awake from the futex, the waiter would notice the closed group before consuming the signal (since that's still a 64-bit check that would not be aliased in the wrap-around in g_signals), so the biggest impact would be blocking on the futex until the next full wakeup from a G1/G2 switch. Signed-off-by: Sunil Dora (cherry picked from commit 1db84775f831a1494993ce9c118deaf9537cc50a) --- nptl/pthread_cond_common.c | 105 +++++++++------------------ nptl/pthread_cond_wait.c | 144 ++++++++++++------------------------- 2 files changed, 81 insertions(+), 168 deletions(-) diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index 3ca9ab92b9..d54f69ee16 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -201,7 +201,6 @@ static bool __attribute__ ((unused)) __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, unsigned int *g1index, int private) { - const unsigned int maxspin = 0; unsigned int g1 = *g1index; /* If there is no waiter in G2, we don't do anything. The expression may @@ -222,84 +221,46 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, * New waiters arriving concurrently with the group switching will all go into G2 until we atomically make the switch. Waiters existing in G2 are not affected. - * Waiters in G1 will be closed out immediately by setting a flag in - __g_signals, which will prevent waiters from blocking using a futex on - __g_signals and also notifies them that the group is closed. As a - result, they will eventually remove their group reference, allowing us - to close switch group roles. */ - - /* First, set the closed flag on __g_signals. This tells waiters that are - about to wait that they shouldn't do that anymore. This basically - serves as an advance notificaton of the upcoming change to __g1_start; - waiters interpret it as if __g1_start was larger than their waiter - sequence position. This allows us to change __g1_start after waiting - for all existing waiters with group references to leave, which in turn - makes recovery after stealing a signal simpler because it then can be - skipped if __g1_start indicates that the group is closed (otherwise, - we would have to recover always because waiters don't know how big their - groups are). Relaxed MO is fine. */ - atomic_fetch_or_relaxed (cond->__data.__g_signals + g1, 1); - - /* Wait until there are no group references anymore. The fetch-or operation - injects us into the modification order of __g_refs; release MO ensures - that waiters incrementing __g_refs after our fetch-or see the previous - changes to __g_signals and to __g1_start that had to happen before we can - switch this G1 and alias with an older group (we have two groups, so - aliasing requires switching group roles twice). Note that nobody else - can have set the wake-request flag, so we do not have to act upon it. - - Also note that it is harmless if older waiters or waiters from this G1 - get a group reference after we have quiesced the group because it will - remain closed for them either because of the closed flag in __g_signals - or the later update to __g1_start. New waiters will never arrive here - but instead continue to go into the still current G2. */ - unsigned r = atomic_fetch_or_release (cond->__data.__g_refs + g1, 0); - while ((r >> 1) > 0) - { - for (unsigned int spin = maxspin; ((r >> 1) > 0) && (spin > 0); spin--) - { - /* TODO Back off. */ - r = atomic_load_relaxed (cond->__data.__g_refs + g1); - } - if ((r >> 1) > 0) - { - /* There is still a waiter after spinning. Set the wake-request - flag and block. Relaxed MO is fine because this is just about - this futex word. - - Update r to include the set wake-request flag so that the upcoming - futex_wait only blocks if the flag is still set (otherwise, we'd - violate the basic client-side futex protocol). */ - r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1) | 1; - - if ((r >> 1) > 0) - futex_wait_simple (cond->__data.__g_refs + g1, r, private); - /* Reload here so we eventually see the most recent value even if we - do not spin. */ - r = atomic_load_relaxed (cond->__data.__g_refs + g1); - } - } - /* Acquire MO so that we synchronize with the release operation that waiters - use to decrement __g_refs and thus happen after the waiters we waited - for. */ - atomic_thread_fence_acquire (); + * Waiters in G1 will be closed out immediately by the advancing of + __g_signals to the next "lowseq" (low 31 bits of the new g1_start), + which will prevent waiters from blocking using a futex on + __g_signals since it provides enough signals for all possible + remaining waiters. As a result, they can each consume a signal + and they will eventually remove their group reference. */ /* Update __g1_start, which finishes closing this group. The value we add will never be negative because old_orig_size can only be zero when we switch groups the first time after a condvar was initialized, in which - case G1 will be at index 1 and we will add a value of 1. See above for - why this takes place after waiting for quiescence of the group. + case G1 will be at index 1 and we will add a value of 1. Relaxed MO is fine because the change comes with no additional constraints that others would have to observe. */ __condvar_add_g1_start_relaxed (cond, (old_orig_size << 1) + (g1 == 1 ? 1 : - 1)); - /* Now reopen the group, thus enabling waiters to again block using the - futex controlled by __g_signals. Release MO so that observers that see - no signals (and thus can block) also see the write __g1_start and thus - that this is now a new group (see __pthread_cond_wait_common for the - matching acquire MO loads). */ - atomic_store_release (cond->__data.__g_signals + g1, 0); + unsigned int lowseq = ((old_g1_start + old_orig_size) << 1) & ~1U; + + /* If any waiters still hold group references (and thus could be blocked), + then wake them all up now and prevent any running ones from blocking. + This is effectively a catch-all for any possible current or future + bugs that can allow the group size to reach 0 before all G1 waiters + have been awakened or at least given signals to consume, or any + other case that can leave blocked (or about to block) older waiters.. */ + if ((atomic_fetch_or_release (cond->__data.__g_refs + g1, 0) >> 1) > 0) + { + /* First advance signals to the end of the group (i.e. enough signals + for the entire G1 group) to ensure that waiters which have not + yet blocked in the futex will not block. + Note that in the vast majority of cases, this should never + actually be necessary, since __g_signals will have enough + signals for the remaining g_refs waiters. As an optimization, + we could check this first before proceeding, although that + could still leave the potential for futex lost wakeup bugs + if the signal count was non-zero but the futex wakeup + was somehow lost. */ + atomic_store_release (cond->__data.__g_signals + g1, lowseq); + + futex_wake (cond->__data.__g_signals + g1, INT_MAX, private); + } /* At this point, the old G1 is now a valid new G2 (but not in use yet). No old waiter can neither grab a signal nor acquire a reference without @@ -311,6 +272,10 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, g1 ^= 1; *g1index ^= 1; + /* Now advance the new G1 g_signals to the new lowseq, giving it + an effective signal count of 0 to start. */ + atomic_store_release (cond->__data.__g_signals + g1, lowseq); + /* These values are just observed by signalers, and thus protected by the lock. */ unsigned int orig_size = wseq - (old_g1_start + old_orig_size); diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 15bbd8b7e8..32af3a3b39 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -238,9 +238,7 @@ __condvar_cleanup_waiting (void *arg) signaled), and a reference count. The group reference count is used to maintain the number of waiters that - are using the group's futex. Before a group can change its role, the - reference count must show that no waiters are using the futex anymore; this - prevents ABA issues on the futex word. + are using the group's futex. To represent which intervals in the waiter sequence the groups cover (and thus also which group slot contains G1 or G2), we use a 64b counter to @@ -300,11 +298,12 @@ __condvar_cleanup_waiting (void *arg) last reference. * Reference count used by waiters concurrently with signalers that have acquired the condvar-internal lock. - __g_signals: The number of signals that can still be consumed. + __g_signals: The number of signals that can still be consumed, relative to + the current g1_start. (i.e. bits 31 to 1 of __g_signals are bits + 31 to 1 of g1_start with the signal count added) * Used as a futex word by waiters. Used concurrently by waiters and signalers. - * LSB is true iff this group has been completely signaled (i.e., it is - closed). + * LSB is currently reserved and 0. __g_size: Waiters remaining in this group (i.e., which have not been signaled yet. * Accessed by signalers and waiters that cancel waiting (both do so only @@ -328,18 +327,6 @@ __condvar_cleanup_waiting (void *arg) sufficient because if a waiter can see a sufficiently large value, it could have also consume a signal in the waiters group. - Waiters try to grab a signal from __g_signals without holding a reference - count, which can lead to stealing a signal from a more recent group after - their own group was already closed. They cannot always detect whether they - in fact did because they do not know when they stole, but they can - conservatively add a signal back to the group they stole from; if they - did so unnecessarily, all that happens is a spurious wake-up. To make this - even less likely, __g1_start contains the index of the current g2 too, - which allows waiters to check if there aliasing on the group slots; if - there wasn't, they didn't steal from the current G1, which means that the - G1 they stole from must have been already closed and they do not need to - fix anything. - It is essential that the last field in pthread_cond_t is __g_signals[1]: The previous condvar used a pointer-sized field in pthread_cond_t, so a PTHREAD_COND_INITIALIZER from that condvar implementation might only @@ -435,6 +422,9 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, { while (1) { + uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); + unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + /* Spin-wait first. Note that spinning first without checking whether a timeout passed might lead to what looks like a spurious wake-up even @@ -446,35 +436,45 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, having to compare against the current time seems to be the right choice from a performance perspective for most use cases. */ unsigned int spin = maxspin; - while (signals == 0 && spin > 0) + while (spin > 0 && ((int)(signals - lowseq) < 2)) { /* Check that we are not spinning on a group that's already closed. */ - if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) - goto done; + if (seq < (g1_start >> 1)) + break; /* TODO Back off. */ /* Reload signals. See above for MO. */ signals = atomic_load_acquire (cond->__data.__g_signals + g); + g1_start = __condvar_load_g1_start_relaxed (cond); + lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; spin--; } - /* If our group will be closed as indicated by the flag on signals, - don't bother grabbing a signal. */ - if (signals & 1) - goto done; - - /* If there is an available signal, don't block. */ - if (signals != 0) + if (seq < (g1_start >> 1)) + { + /* If the group is closed already, + then this waiter originally had enough extra signals to + consume, up until the time its group was closed. */ + goto done; + } + + /* If there is an available signal, don't block. + If __g1_start has advanced at all, then we must be in G1 + by now, perhaps in the process of switching back to an older + G2, but in either case we're allowed to consume the available + signal and should not block anymore. */ + if ((int)(signals - lowseq) >= 2) break; /* No signals available after spinning, so prepare to block. We first acquire a group reference and use acquire MO for that so that we synchronize with the dummy read-modify-write in __condvar_quiesce_and_switch_g1 if we read from that. In turn, - in this case this will make us see the closed flag on __g_signals - that designates a concurrent attempt to reuse the group's slot. + in this case this will make us see the advancement of __g_signals + to the upcoming new g1_start that occurs with a concurrent + attempt to reuse the group's slot. We use acquire MO for the __g_signals check to make the __g1_start check work (see spinning above). Note that the group reference acquisition will not mask the @@ -482,15 +482,24 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, an atomic read-modify-write operation and thus extend the release sequence. */ atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); - if (((atomic_load_acquire (cond->__data.__g_signals + g) & 1) != 0) - || (seq < (__condvar_load_g1_start_relaxed (cond) >> 1))) + signals = atomic_load_acquire (cond->__data.__g_signals + g); + g1_start = __condvar_load_g1_start_relaxed (cond); + lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + + if (seq < (g1_start >> 1)) { - /* Our group is closed. Wake up any signalers that might be - waiting. */ + /* group is closed already, so don't block */ __condvar_dec_grefs (cond, g, private); goto done; } + if ((int)(signals - lowseq) >= 2) + { + /* a signal showed up or G1/G2 switched after we grabbed the refcount */ + __condvar_dec_grefs (cond, g, private); + break; + } + // Now block. struct _pthread_cleanup_buffer buffer; struct _condvar_cleanup_buffer cbuffer; @@ -501,7 +510,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, __pthread_cleanup_push (&buffer, __condvar_cleanup_waiting, &cbuffer); err = __futex_abstimed_wait_cancelable64 ( - cond->__data.__g_signals + g, 0, clockid, abstime, private); + cond->__data.__g_signals + g, signals, clockid, abstime, private); __pthread_cleanup_pop (&buffer, 0); @@ -524,6 +533,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, signals = atomic_load_acquire (cond->__data.__g_signals + g); } + if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) + goto done; } /* Try to grab a signal. Use acquire MO so that we see an up-to-date value of __g1_start below (see spinning above for a similar case). In @@ -532,69 +543,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, while (!atomic_compare_exchange_weak_acquire (cond->__data.__g_signals + g, &signals, signals - 2)); - /* We consumed a signal but we could have consumed from a more recent group - that aliased with ours due to being in the same group slot. If this - might be the case our group must be closed as visible through - __g1_start. */ - uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - if (seq < (g1_start >> 1)) - { - /* We potentially stole a signal from a more recent group but we do not - know which group we really consumed from. - We do not care about groups older than current G1 because they are - closed; we could have stolen from these, but then we just add a - spurious wake-up for the current groups. - We will never steal a signal from current G2 that was really intended - for G2 because G2 never receives signals (until it becomes G1). We - could have stolen a signal from G2 that was conservatively added by a - previous waiter that also thought it stole a signal -- but given that - that signal was added unnecessarily, it's not a problem if we steal - it. - Thus, the remaining case is that we could have stolen from the current - G1, where "current" means the __g1_start value we observed. However, - if the current G1 does not have the same slot index as we do, we did - not steal from it and do not need to undo that. This is the reason - for putting a bit with G2's index into__g1_start as well. */ - if (((g1_start & 1) ^ 1) == g) - { - /* We have to conservatively undo our potential mistake of stealing - a signal. We can stop trying to do that when the current G1 - changes because other spinning waiters will notice this too and - __condvar_quiesce_and_switch_g1 has checked that there are no - futex waiters anymore before switching G1. - Relaxed MO is fine for the __g1_start load because we need to - merely be able to observe this fact and not have to observe - something else as well. - ??? Would it help to spin for a little while to see whether the - current G1 gets closed? This might be worthwhile if the group is - small or close to being closed. */ - unsigned int s = atomic_load_relaxed (cond->__data.__g_signals + g); - while (__condvar_load_g1_start_relaxed (cond) == g1_start) - { - /* Try to add a signal. We don't need to acquire the lock - because at worst we can cause a spurious wake-up. If the - group is in the process of being closed (LSB is true), this - has an effect similar to us adding a signal. */ - if (((s & 1) != 0) - || atomic_compare_exchange_weak_relaxed - (cond->__data.__g_signals + g, &s, s + 2)) - { - /* If we added a signal, we also need to add a wake-up on - the futex. We also need to do that if we skipped adding - a signal because the group is being closed because - while __condvar_quiesce_and_switch_g1 could have closed - the group, it might stil be waiting for futex waiters to - leave (and one of those waiters might be the one we stole - the signal from, which cause it to block using the - futex). */ - futex_wake (cond->__data.__g_signals + g, 1, private); - break; - } - /* TODO Back off. */ - } - } - } - done: /* Confirm that we have been woken. We do that before acquiring the mutex From patchwork Mon Jul 7 12:10:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115746 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 09EC63857BB0 for ; Mon, 7 Jul 2025 12:12:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09EC63857BB0 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id 804DE3858039 for ; Mon, 7 Jul 2025 12:11:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 804DE3858039 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 804DE3858039 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890303; cv=pass; b=X3Ec8SNxGZTLn2NLFZ5ahDEs8acA1D7vskPUmOUjAtEetn+MzUgCwcMJkFtMVv1yYdy62hTy3aQ6Rb/CFlkcf8cyPAPEqBG/t3fNX26EKSNLRKIm1ZbAliMU+WAdI3yfEXpZTEAwtBKrhz4ZUR9ECDQEMUsBO1+Sgshju/fIrrA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890303; c=relaxed/simple; bh=kaxuGKw2NgsMgnRH0u8GBUYe9Y7KjT2p6uxrAhQGeqs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=mPZqe3bdGxSMpvBbG6+5pzAOOWiab1Jw/3tSRSd1uRK4UpP/vPGHdoq0hZ5I1ksBcS08dfsXU0vDt4C2nWQScnI0imKb9qirZjBzVlu182XROnK9/7epuZe69e8azn6y0ap6k/qVVeGEBFJgiF/2FOj902pBDlW7CD5wRI7EdVA= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 804DE3858039 Received: from pps.filterd (m0250809.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5675Seow026397; Mon, 7 Jul 2025 05:11:34 -0700 Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47q3jn1cu3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w4tgDtiXVYCIqSnJIUiN/jLMtrZ59iMr/gPt9EYnV89NBrhrePWbNlN+tS7E5MYwMgQY7AwjTV1Y1BirZWYdsewv/DzeJveJxXxA4xZdmps8HxwZnp4pAmoKG+7IVRgAXBQ+O3dHA62zT+ZYiLDrSPgrxGloaAxFj7HrVCRQx6L/mX3W1ukz8jS1stplaqFg2SJyLKnfgHWFqoAaG06P1l/aKmqUqIShP6ZCvKGWmqK3Y2A2jPDjTliu1WI+Wwg8dV3RdvD8dfytvYUAsYwHzZBzjQwC7KLvLwlDBa/0i3tLJFQy5tpKap8gfqZdjoFFfKJv+s0faKAbZgnE6kt2iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=A3ryMsmP468viilYkedBWv2V9tMaTmFtm3XVGd6hEno=; b=U7xC49pWUNyXyQGcMtFb3YU8xH2UDtwTOc894t9brEG8djKOgBznifzdbc1+lGDrLg3hQxgd3A5Oidj9LwOS2JWTY/fJCyknbAiTU4CQJmRrp2XXjc/AfEVs0yKWENZHGTto+gsT+L8wkNZyBtTGc8i+KwkG64ww5CyJv7RKc62/fWgz+CyRz/Lw6jvkZ+MbAxRmH9DfZnNpUCFQ4oTvsaBi8xY/XMQm15bBNQ7cDZsA8xgMhoPpUyDbNnQ5H18TV8lGTto1SzMRU2JlkegosKwAbQwZ3Aj0MgbUCQWajMOlK70eRx42ZYAosAtE98XlYaN9wwB4+Xe9ISPSNAGYRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:32 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:32 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 02/10] [2.37] nptl: Update comments and indentation for new condvar implementation Date: Mon, 7 Jul 2025 05:10:57 -0700 Message-ID: <20250707121105.2226766-3-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 0edaee09-933f-4700-4d90-08ddbd4f6900 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: dT8Oa2iGmpivtKK4JFgKr3PJGg7a5jDwp277WGhJ3v90urxZeJto1ubp49oZbDY0V//hbC5f3Ci7pJ1e2PDwZIV7iC201U18m7W5HgMw3Z+Sr1tembkFHXy/gJ8juo1Gc6ICo+vwgkbokUPeKMRcArnH1w5Q2ZxVXOiBUo7L5eQoexyxTwVdpRsZHs4jxUwDeGmlj8WVAaUbz+iUE17qdTr8CDEFXGBP3qJi/dC2NiFcro4N5hooibBukDbifZLsvG2F+i5KUgr9sp3SgxMyaH621iGHrWskWn493pWY/c2MUMUICQuQXYDwgvB8PEEQ8p6hAsuyl0fSraTpgrnR9crs+7DBleQBP0G3s1YEyZIJLThuNHzcmJ5uixTB0XJ/1UpGZypJWlUePXxONq3dCBb5fv9IZMF2QAvron9vnP9FX1WTEYuXEsj+i3M5gaTxaoRBJ0vRL7mnnGohbmEg/tKBqDoCKxAH+lOAJHw9esHGWmlLYFDdyloPYTiBuI9DSf5wtyLtui1bC68QGiLzeYNsSoorq4h091wDgOeF/IAHkq4PuCwSpXB4GfLn4JsB+/NAKjIe7fT9XzrVQzPnRA2nAV2L5+5nWL1WOnizzZ+/N7WkqdhHDh8GTwK/eTYSrfV1Drqc0ju+uttx6mwHLqDdTsi0o512x4VvmBuzV9AujgUGtnP/4Ml2v0kOzz4Gp+wtCsm64WubPsvIqAqEmyf7oMQod1NnxpKhn2F6wAuzjR1pjbFJtgi8smAJ9CbMPFxjxgXqybGPw7svNG3d6a1tLgG7egoJfOCGwWoVL3450y2SvObN8zliC6qFiLU7h0K5NT5h2GEQ0yfmTnabvss+2PjxN1KrfaQt0G8m4pREqVLyuWgvbjo6vFDOoYjQxd0q/4IYz/DqnQLyQvUOQe3gIEOqhyt0jyKV7jSY16NxJGvxSxIQdnSW54i9NtaffqVkqlMLIpRbHCYRLcbbo6gNShRv86DE6F0Z19prW1DIj+NY+V0DPqAOwcAMo91txFCdwj7Lmk6eFs7RKhNWWionCw14QjXyBURe9mit4QjknA45mlOfFHEqx4dswb2Aga1RFVDurz0n/V3ZaczON/0jSQ3MFTVpJNlR7DIxDJWQzCyTRWLc+nxqj37OblwtF26/Ut2pXCtv39XgAfoquBLCCWLBpl7YwcJr0KF+QBfcW2xxkV3TyNeUgqSwU1ODXhJMvWtYkJYajFqNTtQdL+Tc3qDqFv/ogpclKW+/wnWAQVHtQ0TesUxLIsR3BO7N9GV9KhhbpBpR8PC+poUF/RcYKvOXvFDLj/ol3hEI+mJ9CIfIyRN680HUZDk6aAiFeG0smjxqYXxO7gYWcuYH5uTmGoamwpX8xWfIdNQ8VKTN8njERgQjuLP5ljP/NuajicEaqJnUtM/18vNLlytgewKE0roMu/fLx6oFh1QIBGEK3sAakUp7pmjLer/sWwn4gOC5okqDCTXh7Y5m8rr9vQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MrUaRF6AowlpmErZba3CHIeR4HNi7K/U2o6k8BAoROMmv5tAY7xN25btAKRQRMs0lurphSA85d1KgC2X4b9CMOpDCEGuqSoF9nHtCY3rjENCOEJQkssSGCc4vww9dXXmNt5IJR5Nk2snvOgS0zWYXWTwbOVpXtt3Nq/Q9JrQVFe7b/K2LfvdzWy7O7ahlkovFXFDfhFTx05dVKzciIxXjhTV8Uajs5Nb/kM4Wdf1j+IiTD3RFoq91rpDY/FRLbe4cGvHViZC0cm+QER7O75rdMGh3Ayt5eKW0/na8WNrJngj2P/oxJJ5MzLqx5EMtiWUsUZE/TWWBh7aMNxv+9lybvTwX1ssdST8AbX3juQLgV9LQWkAO8+Kl8n73MLNCGGy4EuCp8v4sEf1U3YAo1x6CgwbLJuIJKOJGNi8y6ZHyI290MZDAaDBdUIGgO4+X8TTqHsHipHny7RJhWed57JJqg3vvSssPjKZJUbHT/BQZLHxeML9498kPcZSX/qlXZSYBDxl/JbZ1M/R6taIKmtTRQXwmB49PQYTuHpy4Oiey+Z5QskldShq+2sQWywyRSnytMmNMaUfu2s2hEVlIpvTzt3Iz7IJgT6GZaIC2Xn9pnSPSYUqL9gdrSTyABKCOu08o5ta3dunPdjMqUV593sTZMygzlZBUVi/9J1xL/+aOxpBdT6Bo9dc3xL+XAIL24nCZ/fPyMoS06Iab4AzomzT41CQGHVEqAsQ3TWNhGYytOOqbecAY2CSO+Co/SL5XHPS2l/eJixZ01ZJNZwbgG5v7iPC5TBa9nYAuJvWqIR5/jdbDuZVFVe/21E+AspG9CA2qJ6pYWEm+9YWeIZLVtGPvmGdPcyBVaAeuH/r/67VxlJHt9baXGEK7tY/pbWYfUVx0g4fqmxBGY0Lyez07ZM4j+UuAoUTZuniIrF0HAwqxdZcqAd1BfETyMurccsbDH96NSQKysB8C3HU9Z9lRxAFp3QyCMCXUDtughJOdT7oO305VPBRoExyJ6Mwtoe05Sxs5k53rR3nzIq+hrQGmpOODyjkxUohvzEx6wSvm2+OpN1MB+4oLkZtSP/fAs5L3XqwGlVr72bxS91DkwLDfiBRORnd2dRoFYjU6AjydgPDw8y/XJ3w+ILEDucerkTvLiIdEPJJCQY3MTCMcXEiIPTSetYYdPQR5qraP2GIDKBl2YfUmzAQJaVn9BxaG9MNiqc43SgChgFxQ1emsK9V0nQpx8HHI+6eu0WPLGQkVNLg/h6Db1PYte9xVU6XFHxa1+o0CllObCIHuyx0FOhaM69E19+bJnabJk5HPFs9/BCM930B4gADk8b96vYDXNVUyxJYWiv9AQcd0xSrCeynlwp8sF8M0SfAbKK/yjvKcIC0/t+TWXiBtyat01wyuv6xLgL0Slp5cnfT+xPLpSMGod5ha0NnxDTgVQ99lfT0lE+WSGfB+NSkpZ3QsSjF4hy2mVHG7P9P16NP5O67JwkZJcFX+7HTLzlAeUsb0w7W8trKtcRIe6+dPhuy9c2bNVw0XFfAMHYcKtxaLU8rjlCbf2zAisG7LGTKXpolqNdYYNIoah9DiOmZriFd4lk2U5kgzTTtikgx9XgAav72QLClbk5A2xax/n/gXrBhB24PJxSRDVc= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0edaee09-933f-4700-4d90-08ddbd4f6900 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:32.0129 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OvJw1mCDNV61egRyBpf469AkAxtesF+GWv1LSAk+SjcYvG81Whsczb6MRtDcdvyCCcS5154AeHTtKV4u0fbHdVAxodEO9LjGbq24chUcAO0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-GUID: Si2GdVb5YNJ8f6MeLN-tOhjsNnaGuaFD X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX2vN3ZPXk8cZT KLXDT2N/hJHy00SJvt5jjqvxiIgVvOVYFsmaTfsoIVYkec5AkRhsukMfUM3lzJ3fZOyyaq0GKyU nkAniMg0+6g2OQmzI+eurPof203uEYPRYWOCSyZqFkdqR5u+MBN/FwKVVkXOFOWbnbQmsvqRu6J lGPu4yaJ/AUXE8h97axT0S4piysZyxDRLZUS2j1hT5sKSpLyRUCuWo6DbeHnuglIQ+iMfu2l9M+ o5dQG9t4/88lA2EpPy+9Y1Nb31fqSvQbTRsjnxnUrR7nrPrhL7strdB0HYgYqjcKK3Dd8rf9NHZ GzIFTo3HVQy/1G4ztqQu/dIf4z0WqNLKiyy9oYpBgHd5HP09eKj9VRmwY/Y462FL54Lg8JCtgfd Q4bX+nM3jDhTf681YXuA/jymtLO0WEAmyUG7y+trFgAl6RYYLN1MXQqbPV9jE44BZK66AuoY X-Proofpoint-ORIG-GUID: Si2GdVb5YNJ8f6MeLN-tOhjsNnaGuaFD X-Authority-Analysis: v=2.4 cv=fv3cZE4f c=1 sm=1 tr=0 ts=686bb975 cx=c_pps a=tI7H87ngqbXf/HBJ/Vc2+Q==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=UO6VkMP2561qkmehfEQA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 spamscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] Some comments were wrong after the most recent commit. This fixes that. Also fixing indentation where it was using spaces instead of tabs. Signed-off-by: Sunil Dora (cherry picked from commit 0cc973160c23bb67f895bc887dd6942d29f8fee3) --- nptl/pthread_cond_common.c | 5 +++-- nptl/pthread_cond_wait.c | 39 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index d54f69ee16..c1eeec6a93 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -221,8 +221,9 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, * New waiters arriving concurrently with the group switching will all go into G2 until we atomically make the switch. Waiters existing in G2 are not affected. - * Waiters in G1 will be closed out immediately by the advancing of - __g_signals to the next "lowseq" (low 31 bits of the new g1_start), + * Waiters in G1 have already received a signal and been woken. If they + haven't woken yet, they will be closed out immediately by the advancing + of __g_signals to the next "lowseq" (low 31 bits of the new g1_start), which will prevent waiters from blocking using a futex on __g_signals since it provides enough signals for all possible remaining waiters. As a result, they can each consume a signal diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 32af3a3b39..e6417997f8 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -249,7 +249,7 @@ __condvar_cleanup_waiting (void *arg) figure out whether they are in a group that has already been completely signaled (i.e., if the current G1 starts at a later position that the waiter's position). Waiters cannot determine whether they are currently - in G2 or G1 -- but they do not have too because all they are interested in + in G2 or G1 -- but they do not have to because all they are interested in is whether there are available signals, and they always start in G2 (whose group slot they know because of the bit in the waiter sequence. Signalers will simply fill the right group until it is completely signaled and can @@ -412,7 +412,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, } /* Now wait until a signal is available in our group or it is closed. - Acquire MO so that if we observe a value of zero written after group + Acquire MO so that if we observe (signals == lowseq) after group switching in __condvar_quiesce_and_switch_g1, we synchronize with that store and will see the prior update of __g1_start done while switching groups too. */ @@ -422,8 +422,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, { while (1) { - uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); + unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; /* Spin-wait first. Note that spinning first without checking whether a timeout @@ -447,21 +447,21 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, /* Reload signals. See above for MO. */ signals = atomic_load_acquire (cond->__data.__g_signals + g); - g1_start = __condvar_load_g1_start_relaxed (cond); - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + g1_start = __condvar_load_g1_start_relaxed (cond); + lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; spin--; } - if (seq < (g1_start >> 1)) + if (seq < (g1_start >> 1)) { - /* If the group is closed already, + /* If the group is closed already, then this waiter originally had enough extra signals to consume, up until the time its group was closed. */ goto done; - } + } /* If there is an available signal, don't block. - If __g1_start has advanced at all, then we must be in G1 + If __g1_start has advanced at all, then we must be in G1 by now, perhaps in the process of switching back to an older G2, but in either case we're allowed to consume the available signal and should not block anymore. */ @@ -483,22 +483,23 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, sequence. */ atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); signals = atomic_load_acquire (cond->__data.__g_signals + g); - g1_start = __condvar_load_g1_start_relaxed (cond); - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + g1_start = __condvar_load_g1_start_relaxed (cond); + lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - if (seq < (g1_start >> 1)) + if (seq < (g1_start >> 1)) { - /* group is closed already, so don't block */ + /* group is closed already, so don't block */ __condvar_dec_grefs (cond, g, private); goto done; } if ((int)(signals - lowseq) >= 2) { - /* a signal showed up or G1/G2 switched after we grabbed the refcount */ + /* a signal showed up or G1/G2 switched after we grabbed the + refcount */ __condvar_dec_grefs (cond, g, private); break; - } + } // Now block. struct _pthread_cleanup_buffer buffer; @@ -536,10 +537,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) goto done; } - /* Try to grab a signal. Use acquire MO so that we see an up-to-date value - of __g1_start below (see spinning above for a similar case). In - particular, if we steal from a more recent group, we will also see a - more recent __g1_start below. */ + /* Try to grab a signal. See above for MO. (if we do another loop + iteration we need to see the correct value of g1_start) */ while (!atomic_compare_exchange_weak_acquire (cond->__data.__g_signals + g, &signals, signals - 2)); From patchwork Mon Jul 7 12:10:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115754 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 20E4C3857B8F for ; Mon, 7 Jul 2025 12:18:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20E4C3857B8F X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id F24C83858D32 for ; Mon, 7 Jul 2025 12:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F24C83858D32 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F24C83858D32 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890306; cv=pass; b=WTael2TMB+bPSd3cS0SYxs0Pbveuymx5L+P974hd9ABxy7IjyvPPDZbxbn4bFQhasYzvUqCnraRiVZjJUqS40/vH3wBcR+JxXhc6/Sj8RY+m8k9KKChaiXdK9HQIX0ZlKEWgOKkOyaE/0yzIZ7BOSCk5QnvvNvEYC7e5IUOri80= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890306; c=relaxed/simple; bh=QhPBpGvnKYv0OHZnu/iGJF7A2fon4ejCZqNcjKLv7Us=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=nxTp+ob6niK90JlYw88zM2K5qK1pzkekIlC1VKFjNGcO3nrNc89dNO3if6PCpsSuI61p0kaCgPvtxtaUva3OVvopd/vwzbIMyRkKKC6T2AAS/E+nBGybSkYoM/VbyIFnL6GRdcV0u7Lm3wQPCi5b96PFm5fygLr9vd3aojDfyoI= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F24C83858D32 Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 567Ag64b018969; Mon, 7 Jul 2025 05:11:37 -0700 Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04on2068.outbound.protection.outlook.com [40.107.102.68]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pyb5hh59-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WVhojWavl0mPys7GHWxFH8QRtNYaJd+oPufYMSJZ8Ka7m1BcVoWiezn9kgrMbIyq5lTRIbejs3H9hxnzctrnhoLVh9RwoNKiPj9RPRC0llGMKxEjv+1fFd2CEhhrizQ+h7vRakzVT/cQaxGIBLddQjbFjdrDDKoXMOJHjMnpp+iTs4pBhv+QOeTSAZQVGCL2yhwx1pcpuYOyYZWgu0/0E7z5W5mCjHiF5cfizyx6bS48YtJfTT5BDis32xcBLcHiH2emkj2JryvRm5k0GFtgRUTrfYxaN/SqT01BzZ84bItLcj7CFFOcTXhbH4gDPCT2kQmUYiEJL2xOCQTMLSedNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=i240pzJSV1M0QvuqoGIkjsi1TXtDP/Id/xvzukf4vMM=; b=QHthrJGDZ44k2qKLFiDOVVlPgpfvXR5wL+U473I8oNYq3EuDZUn0w8S+4FbsI6Fh8z/IxSBEP+51NDSbSWWvPOE9RSaouA7Rn3tKS8dUJ/plw1y07hBtXTtUxnco/sXpqCZEXinERLR5I17spdVAeWJSR7GwDhXCD02ykRVqd3mxm70WkToob4t1x6LZ3qZ33YQIrn6zoMrV7YMF+inW9FPpTx9lJ9I42yJi5xQEUU9QKZCdeAT7XOOMDbu+sR/ehbFjboN10VpjawwhPtFJmCNVeCFYx1ytdCO4kDBHqG4yUdXALyuVDnyiC5OyyR1+wrkoJ0HlJdJYgxisv9Gb8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:34 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:34 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 03/10] [2.37] nptl: Remove unnecessary catch-all-wake in condvar group switch Date: Mon, 7 Jul 2025 05:10:58 -0700 Message-ID: <20250707121105.2226766-4-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 2670c9e0-c79e-4838-ef02-08ddbd4f6a9f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: VcqPNUkNXQDVr0z2N9twZLosweV9O+R/i8zHSZppoS/WaG2Tvdy7NlMKtEceX9YFARlg0XZcFxlaUk746nrhrviis4xvbWunqqJQWVlIzPPwh1oOYFlS5rLEpbv1evUGWKlW4F9lJ+tjKCRPT1ExFGP6ilFY6Rw+fYywcujhf4Syw7BMvwk2OGhVNutIUv1HePqG8SgxrQTdCT/3tizgcrH27Yfet4S4H6Ttbh7FXGFbqS39OnU8wdmIKUkBEsU4UVLBBOeO5rQJRpRPKydge1NYNrbfJKU/kNf6ZZRe3Cm92Jm4bI6LhrqvumzxTT/HZeD6uX1e+jLpp+mN9y4YxmlwWHD2ruWnzTe4pfYQY0EL2ogGMXkVQJ5N5cSZ38CTsyKSy3HQ7A2PovRlEqiZobXX8Fmj04JoOPg9gMM/2LXhb9qb1A7QHXWJSOTHE4SZhtUsqaHaKsBJFsXGRWdYOLlDNCqcka5ZW3O0JP0YzifPu9sIhMSfaVO+K9r67JOtyLmKEpwmY0T92Igm39FwPFGwXKYQUHnxKA4416+1DAaYDi3IXO5YUBQHeq+FzOwmwGeY9iAeIFY8QBOCRjxIW473oxJR4Dq4vupFdOpjDEt4gmlxH1nJD2ceL3skzNRZrooP+h4sdLzSVtj9EO9RkEeymy22Ph/K7E1wK2V7FmgWeRx7kkVC2LgaSIb4F6yXxUTC+Hku9ug1NRtYmGtbCO3e2QYAKUJgnsokRkaLxfmp9dDYER4BqYu2zyVA1zuqg7hZwROohc3OVhnr7OX1RXkmBnz5JmoRkKO1Bke8pA3Ocm82ziGmtdDN+6xQXnxnSgVRcJ3wyy9UA2ZQUJck3H8cpWwCd29EQ/YanSz+faFhg2dVLV2zBk+eYPcks2tGyRcL333mZlaMgpPoE5abk5ez9ueQ0UiNvtshWTAaybH7X5MnmcdzlxmceLdx0ZCuUNq4s1oeGujAgu7WWeU46EJw7eZenwMiYOnaItBYIRbwQp36NAS89CRUT1MD7rvT4sPmlXtgts/f6mmfBIqqwvNQbVy0TD3p06itk7TqCxTQSYfoUDlHMFrN8RUrVAtpMgXn68dFpF+7Ida60bMl5nIF7C67/kMlZw/wDdGhIb4cGP5JZwz6UE4NduLCRACQePO+iWTjifQEyt40uzGjkX5raOHcsZFDRxxQ7xwxLu5CHELhavw7h0Y+M2gDTJa/IVEw5Djud2QsuVAEKNaZHuWNRmD7eqZCWXHqZyiZ/RCzAq1Gtsf6e540PHdTsoKiTk7vGLxEUG5W6zN8mV5CYAqOr4Zu/eR4mp8r9ayEJCpC3+gn4VilSmio2ie8ORHzvsxry2rZVL8nWbBgHVsMm/MXX5kJskwkGeRmdiNHHhsq9Mi9WryB+9KlWsWmuXQ35Q2cRu0vbGr3GFfmwNQcqF6R6YkcFqcwRvZgSroXATOtlSkw2kT2xb888cNgGFRq2LdmbSBpqYtK1mTgxqlT0Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BSlxGgBEV6UDd0Qv0mkde2peGmDzohl9B2PVD3Gem+mmCH92xI9BUhjImup5MAQOoXrcO4jnNngNos0jNLKNdrCLPmUdMuSifQ5HROw8P+Q1K++rh/b2rYHIUPEBt+f6xe3BuyC97nUGkmaL+iF8n2ZsFxbswNSqJ8hfTaYwsFkcFl+mf7yv9a2qNTC7KTfY6F8vdE/cft6rtGSF/CPOH49ghaM3qLToL6I6JDaI3CaqNE/1sORJ2MGaIE4/WkkyE6oeq8cSz4VLKXkTaCsCm02EWvamuUWJVkKOoNjU3LG/MzEgu0n+21yHE+qytziYh+A1FsMPdavRv+ZvZiE70X5TMIjyKC4PcwxhFzdG2GD9qR1RuZH6Raob02lmk22vlIAvipta+dxIA+GvLbGyNTM70VJcmShLCOMdqJXyXEnzYbVy4ibk52NM66778GfzKl6O8m289jNCto4Afn3AGO7ww0GbCi3BorPRgMd1px6AlZkU4SZeSYM4MbkymrRuPR9S6Rlh8b7uDwge475+6QHOF654pT1pObhMHamv6vrq/EMnbTULQ9jyxkUiz1c0PoreEz2OicGxGj+Vc7XpqqFSSlZsCoKJUWHZPZASv7jb3vLoRybMs4X3aVrdn7fpbcoHekEuvN1SAY/+C+obewJ6D1QAQ4uVb428qBZLCHzzydnUEmZTbJW7SDnU2NgoddrJoVvdtj7MuAp7ZhlA+UrODBPL/P9EfdJmI5hXwuKODqOqTcY4cfTtWJBknhaHPTgT6CEu+t4H7KNSj36io6H9i/gUuPLClhBTiiPVauLu5uED6Jd81nHtwo834JsHlianbBIWxk75XTiCEAw7B4CyKrdrBDdbQVw5mjk4550fT1gC9yXDZyXJH1z8EmoEgLzx1l8MF5lj6LXMvA8J//AabN6cTCpTkTMvgtYTtYpMNdQc4RCPzYSZIeuOo92raJXUa4enADiEEaz0nzxHYjoST295NqLC9zXGHyzYtImcYeN1tP5+bPSc7UFBXPFBYmIaJ2M3ID1gCdhylj4RVf7wAl7428+tJ7KGMg+kE4KqVWOd58mrOCFzbL0Jvca9ziKYk2Fb0tCVG+6X40sFyDdQ6t+TjV7s3/1BjojSIe0xAZhbETFDj48oQIbveu44dGYkGM09jiLPFg6ZK4QzIuheGzkrKlXYcflGEHwt75kg6OQ+IzRRtuaUDVyDsZ2cJM9s+H5jqLBS1VRlEopCtdk3gE2DoB7p0+WrDkG6K4OiTK+FBILgiLNBX6TBuGNMHi/uAQUGHRXXewj/tjJsq3Yo0BGHbBewPxdvfNqwdIz4dvukCi52e39LvOPgKw5zaoUWPTUI7jQJlRcBm0UuS3R3VOa3qyIVsngu12LEBxwh2KtoSKAwPivaq/Ugz4rLPiGync0/ZiknQxdkj2N5FlckGWjsfuYCP6qi8b6liNOGmVionHRkCrnBFFMjhI292+HUkwnynj9FXb12xQ3D7WUykP3M3unzIx2cRY+aj/HkVGG6b6FxSVYaiDLGBH6lBO4IkRmoQFskeHX0aKsinr49uSUTGYTq0xaMMdyU7lA3b84btRKjFUNzRAnYTaqJFNLgJ18eiV7Lw597baME+w== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2670c9e0-c79e-4838-ef02-08ddbd4f6a9f X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:34.7647 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yaujN4MlzPwcVyqJa5nOexYTSirk7UC2yzZk9eIdvhsF5n6ogXP+AWw2y45L5bFL0LHjbLjBMqPCUfwmRkHef+HsO10e3yjv4W4KfqWl80Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX5Q9709EZu4og HNPQRdlEL8CU1hKSaHlc6Uv3QiwTf1ISI5k9t+nbIM0ll1Wv5XoLfLbSrAJ+TvGGrqfmmz/3r6J Y+nbzfHfN5FKwRkKRH7/6nX5K3u2gB1OtssLCYbH1w+yTc9D68zPv1pgeTSTmnEOWHH8YWBXTBJ lct85hm7Vtg5SKnXJSxmin8eswEnYMJh9f/hWAKhwj4D99kJYM2hrmWgtVpjnI0e/YHiCsqjPa+ fMbG1lwMtEdchtTF84Lmu1fTceVKarpQFmia3S3VHlX3VWxtApKSU/Svf3/ise+mHEyn/7dii2N rCJukPSs2o/n+WUEEAXuWAdHazXF+NK25jhyiDDOgYGKvAM3KmghC/zyOgMPL+bPhwHw3xgelGw Y33bCAloMtt7PuP5CWqRFT3hMAmHY+uiSpb1eJTx2uYAqjL7Hoa50FEqZb5oAbHKTJN4mPUx X-Authority-Analysis: v=2.4 cv=V5590fni c=1 sm=1 tr=0 ts=686bb979 cx=c_pps a=YqjARhBgC/QJlLYaippFdQ==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=93FKfIyiHXBki5GTU3EA:9 a=0bXxn9q0MV6snEgNplNhOjQmxlI=:19 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: k_N30vPbK-b8y_1fD9ViL0-9tOtxlwRL X-Proofpoint-GUID: k_N30vPbK-b8y_1fD9ViL0-9tOtxlwRL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1011 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=805 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] This wake is unnecessary. We only switch groups after every sleeper in a group has been woken. Sure, they may take a while to actually wake up and may still hold a reference, but waking them a second time doesn't speed that up. Instead this just makes the code more complicated and may hide problems. In particular this safety wake wouldn't even have helped with the bug that was fixed by Barrus' patch: The bug there was that pthread_cond_signal would not switch g1 when it should, so we wouldn't even have entered this code path. Signed-off-by: Sunil Dora (cherry picked from commit b42cc6af11062c260c7dfa91f1c89891366fed3e) --- nptl/pthread_cond_common.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index c1eeec6a93..1c43432bc5 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -221,13 +221,7 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, * New waiters arriving concurrently with the group switching will all go into G2 until we atomically make the switch. Waiters existing in G2 are not affected. - * Waiters in G1 have already received a signal and been woken. If they - haven't woken yet, they will be closed out immediately by the advancing - of __g_signals to the next "lowseq" (low 31 bits of the new g1_start), - which will prevent waiters from blocking using a futex on - __g_signals since it provides enough signals for all possible - remaining waiters. As a result, they can each consume a signal - and they will eventually remove their group reference. */ + * Waiters in G1 have already received a signal and been woken. */ /* Update __g1_start, which finishes closing this group. The value we add will never be negative because old_orig_size can only be zero when we @@ -240,29 +234,6 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, unsigned int lowseq = ((old_g1_start + old_orig_size) << 1) & ~1U; - /* If any waiters still hold group references (and thus could be blocked), - then wake them all up now and prevent any running ones from blocking. - This is effectively a catch-all for any possible current or future - bugs that can allow the group size to reach 0 before all G1 waiters - have been awakened or at least given signals to consume, or any - other case that can leave blocked (or about to block) older waiters.. */ - if ((atomic_fetch_or_release (cond->__data.__g_refs + g1, 0) >> 1) > 0) - { - /* First advance signals to the end of the group (i.e. enough signals - for the entire G1 group) to ensure that waiters which have not - yet blocked in the futex will not block. - Note that in the vast majority of cases, this should never - actually be necessary, since __g_signals will have enough - signals for the remaining g_refs waiters. As an optimization, - we could check this first before proceeding, although that - could still leave the potential for futex lost wakeup bugs - if the signal count was non-zero but the futex wakeup - was somehow lost. */ - atomic_store_release (cond->__data.__g_signals + g1, lowseq); - - futex_wake (cond->__data.__g_signals + g1, INT_MAX, private); - } - /* At this point, the old G1 is now a valid new G2 (but not in use yet). No old waiter can neither grab a signal nor acquire a reference without noticing that __g1_start is larger. From patchwork Mon Jul 7 12:10:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115755 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 4091F3857C7B for ; Mon, 7 Jul 2025 12:19:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4091F3857C7B X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id 367B9385802C for ; Mon, 7 Jul 2025 12:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 367B9385802C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 367B9385802C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890311; cv=pass; b=lTDFwHGqKaVgzv89huODq5WcyPPF+tM7Q7oacbUB6rnE+cj04Mdkg79yql7IX8hkAMz3hL1o+j8MtozX7VvUxK/eFG0jtsSriH82GFl5ijwFn5YTot8wFNsllWQ4logaMEpU+8FDtQ7xpu3a/jtFU7AWEcpYWDQll1gqKuvifWs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890311; c=relaxed/simple; bh=/fXiNfRmM8EPRSdvE4wWW5JdipBIwmxOeA0ioikfqT0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=udlKOLrEjx8BamIbVDC5Z6iUYT33v7nK/5p/9Cl/f1A5Pl+mVv+iM+A6lM00vpybJM9N4YoCLZnE0RSdPbBpQEHpVLBbQ1IjyiEWW8R1FcoZh6SDcAZyqPp/ckoga6zDOPjw56Uy+gWZjNd5Ax1Y0xdAaCjefbZ/hpLATQqsNF0= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 367B9385802C Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 567Ag64c018969; Mon, 7 Jul 2025 05:11:39 -0700 Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04on2071.outbound.protection.outlook.com [40.107.102.71]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pyb5hh5b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yKnHhi0f3EoySdA0oGGr1da6s88YUBKzHzmioGy6s4dO7vMxC71+/ySFkoOoXX1r2v+MBGwwKDnOXiREmmTYPaq8zbIhOIHUhWowqcQda/TeJRkedGZ6qpY2Bjd7b1hoEBYe6bTVAw+iKOU3e/Nm6+qwD1jkXIurt4jX4+E04DI0MsBNAad0F3JPuxA9S6SMc7ENaG9Eus67VJG92TFICWOquzQW6/ee4WL0DfFPiAauC0ro6yf9C3TSHXc08lU+yXDxfI6nlwlaPmB9Mv13LTQOIpmph7QGNO77R46pgbbbrfQSA/gSUssP+Xfs1mEiJYJC66eLGtx5mdyVV8WN0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=87apyE+bJK1rzi6+FGi+Rzx9ahGGV9sO/mI+4im3b/M=; b=PqksREzFJC/vK9XGikMtXsdBFwk4dQj+x0723v7OGwkVMwaKEDJGgHJiEzqnObC+ZaPxeiZ1g4A8DVTaILnNu/k4BmSTFGkF5x2R9cAw0CHTitV3PyMoP0Uv4Ez8q5ljiU0Qs0FSSYRp4I/n+pvW9ajLrExuRAcHMubOhI6n+ckFC6p1LDdPQXqDP4ostaXkyS1HSMVp8aCkSEkwpWZXkcGJNpkTJiY370jI6JrY4cW4TZmMHCxvPUxn+oJZtRPj26VrBw9lZOsIKVk2fTgHtZDTZb4taQ4t6BFIhUc18NjIheQNDkRjBIo5lJl4F2wsdX8HpCZ6wwjLPTlyer1Y0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:37 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:37 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 04/10] [2.37] nptl: Remove unnecessary quadruple check in pthread_cond_wait Date: Mon, 7 Jul 2025 05:10:59 -0700 Message-ID: <20250707121105.2226766-5-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f6e6d5d-7e11-4d03-7116-08ddbd4f6c44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: 7MI0ahqkGmHQUE294Hi8UxZEBgouztXm3xDf1qMthjq+6QXkiCNTp6IaRIfO0Ndl9jSVsnh0SH710pNKT7ESFB5ZtD1fui1MoZ3LMB121cep/hrbZVYG5hfzK6SDr9TuhhkHQ6OQzeEHa/czgFsL6ooPWwBMDQouRgM3V/U6eABzNCh8C7qh2YDoy1Cwzxv79M+EOLmjBjkc7/wRtslF+QjnxGDoFG3RtUGSIir56ozSoPrpvTalaXAgANVZgTa/Jw+ELtzjm8qTR2YYnuqqA3MFiBzWZjtq+3MEEJCNGuB54ybbXRd4xIbqabXvygDAk5tPMV1Bu418Rta+VG/79f1XDW/FCNMtbu2RI6wiyLAgI+xKPkfanl4f4gx+IFwkGvsbHE9YzmBRWdH+/aDrU8YpGgMkOJX1JbCe/GvznLB2eqh4uaxP5HmkIhHF2ocWmX+ytOeIab3f/yeGIYAZdzH6y2OmbaL54KvucvofGFOQyKdMYpqemEZEevZgWg3nVor0K4daBwCDlrOYo4nsUyH7oZSATVK1VrpSmk1lL/JX0VEwB6aqBzOn5nmepB7IAYZd3iOgt3DPQiEXHjKYzuiFyZUmbHroU++JLqVdhdFC0y5FUdNSu/4rZGRYSlS8xkNlIYzgzrWE9vrS0ZzlnhLzVqt/hYCpxMcyYVh+Ltv8qFSvNe9iGXZ55K5JlWhniNjbcYDdje8ZSmZ4e4gUrCo04p3Gu1z4pmub62pyjTYz8YTwUghTaT26X0DQ1avLgEaLScLBwD9WfxWiHscWw7TXUCjI5Dc+hNIEe2ukedjZB2TwPZiwX6Hv4zHynZGhdjSTiXI5jOUkcwQ0g6MSPNhudyZZx6wkJkCjBmjMjVFYv7tj+uLsjQiuu3lFFDPjxldtVQutTIUuQGHOqoylgi0pEgYOVlEWoXaXoBVo4cvY/UFvlf6aW5ySgn/YY98rEpSefdwhW+S84JTzhca31Xm0lMAp4rsVPoIaWKpaotsWrwXf6Zkzx8XnwzidOAOFqcQo9PnI3eP4PByZhMf7Ql1ASZtPqrvFqET9tDVFp5nhDa9P2uNkhkMTaFy2agLf0FwZrz5WgRgjbydXPULDv0GutZhZdVWljwaY8WKIN3nLOBL2aXRNCjG1haqLMbwQTGldgOxif3DUnJBwUyfHWpSSBydl0ot/eIfTGs6CHFO3V6csALqx84bmWLnQzWx18YEkkks7FW9XsrghlL4c25L/2jGJSYXOw8bNGFyz99aNAVf2JuI4dXL9NZ8sgky2SGUHyh5XXyk+6hZqTagnpnlGLr+A1mXmwYNWe08fRYFaCXwYYKoo5fYuh7ow9yZeAYc6XCPvoc3OfUAnLcXIV9wyDb3AWNUWS6axOyU9ffPvgO0NXjUBHfjSPzzzKKlakQA//XjQlpwclO4zAvPBgQKoY3U32NoVNDCL6kfAljmH0ot5x1dMGh+0WvY6kbYXxSSTcFTla32ObhPYYrhOwA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: El4vW7AR2jheJUcb1PUqC5sE6CpOn9yb6KkdOp2jbYB3UWFgHDv1om1btTT0BmPuMQrHCoe8eia71U68kMwTmRIdv/8wheDLhKMorCjfo60MGjJ+9hAASHkYBf8Nkhgsd0xHoDDak/AwHDmyioGqE0l9D7fVxpnzJ/cq4JehN/TxdX7STfT1X4yQffhL/mj2gFrlymTnGoNnphzDsmqsxn5OReX7kXrXyO8FvvjhR3B8pd/B64Sk3/SgFOdrxuX5IK5SBV5vOHYWKBT7SMpfOfDpF7lstK87ynpqTxgX3HJPP4FYNt/w95A4Uw3BAw9cg0uSM9RqFIvpdjJVozOPYRdbYgqXoXPWbULjjCNQf+t09Tnw8zBdXuGerpFgCImvNbnUJfqDmks36K2AnAPEsaz9flNU1/T83HOEJ7fbJX6zV7cJukwu0kMH23ySQ7kngWqYGHnrO1F7XuOce+E7VIOxbwufbXKGHzQsh3PW+4pWzThoa9xv5DnDPeKbBm7o0v1Mb5F6K2unj/DcmmZuslFrD4hEsLLd/Md4/xAEv6SN96LL6avq01Z2bkeUOG420O4hDyDQk3pcz0GwCjwe2QnH1KkF2dX5MPP8GpUrNpNPszqj5bUpLqTlv2piE6p0S0SL710hD8HOHbH4iOCLjVoxCTPJYftPNENwXLQozBTu6lCiNHyyHCsc7Xy7CsvhDFDWhoAuswuctRypaYX7L/vYoGTBwDGN1eahZH8ZmSiC9y/V3/2fKMAAlAAT0l45oct+UpWCS0f++qLaiv/rL/9mIFixae1d5EBPzqsVvZuG4TrzAKT6IBDJuPcJa+DK8TJ3JdrnI8nNxVlUz9i3Z6mUCS2QDg/ycA8ddfQR+jqPp/lUCKM+p67THHPoZX2VtPzJnX3+kbqulwkShU2eaurwu2Wv8KiNKz0p9HzMPQ79en4jWupI/6c+dMjlyaWmtKs7ZnVBexPScTa1HX1OHXfdRBjrLoEGpnqUSZrVPPLqah9rYkAPsQ+nS1wEmlaGay6F48xnKnLY1rldnKf+K2/NHxi/9AS3gzNhYmglS2dVJdk/4QvoQ7YbpgSZxJku1+I4Qv0lVfgpVONx/DKZjzw0Uyw+lzt5oFi95P1Y3ISRmpZIbrTFKoiC4TEBeZ5l3ASgw9OccSzLhyfEWu3jxBUZwo3yHG4Qzp0L5csjW+VT7+avAdpGhoj5yTcIJJy64zp6nSFzs7zdprq1D8Q9Ut2TDb1kjr0h6Y1G+fELBwfP+MkescJaHTmJ6aWuS94lTC/M1xiPYEjHQU8l+uoxFXzVAm9f+6tof3HZX8pAg2FCSyn+KnXb6DMIzqcYXZWxwFbzKt8koASMIEyorGV1Pgu/HqvOc1pW1TEw1iTtm5Jm4wJV4bN7P42vSxwOzW4hhabOvYpklFR0pBmIRkLve6qsZZe1eLEqaAfQcxpA4IvD0VoCyq3fNCsRBVIG55SJTb1DeaEaoFMsGsEIxCNDaX2Zl1vW4jaiNNXXzHvTJZo0GnTR7LWdQGZxG8GpasyftH+ncJQrxpbcOeS6pnkFuiB/96kX3tfRkaBoHfnnElGR+fbjhCmuRx9DgSlA66Kn4w9jr+fwq/eL7hGdxTHwXg== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f6e6d5d-7e11-4d03-7116-08ddbd4f6c44 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:37.4837 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: y01u5t0lj99HCeIgbeQyWwZ8V0aR89npFcBknoEQ+MLywAFcFLv1sY6zeFXXFRf8dEqktUuP+lGQD+60xVmFodvaNtimUnem31AXIpiroow= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX4RSCwqH01po0 0Ke2Z2eDx3qcdDJUuNHbDKzMG/pA4bfy6EfhE3P/tu1xdNEvqFpcNLqoKm9JZLilODe4ST5TxUe ewZZXr8KV/NRB432REvIpnLlXhI/6FUmG+OgcfVfqDU67O3v9hewQCTvOgbxUzf2To4IJ6eMpPj GhQs7HWV+jX0Zt0RaFvzXcecDvCsbf/t5ID/t4JzQzRdJjLYdC7sdCVjVafnQiIAXMG8Wp+Lc/T yf7rdQDs+zyc9s9HOavGRQXXe8hWrMLZ6UN9xGDzYXltGaVvfoZphGpIzy8Afi+9WhxMg9lX5Zx SsTZPw7K1q+mYYe0tSZntltH58PTc51OmaCP0edYPSn6rjhtUjVLyKpgiLPjhVuO7mNLSHvhr7s tFAUI7txL4GUBI/x5SBut8Ezf8QD9VHDjFmdGeClNg8HbhSa+agfjZfyGwKgV+8QDRYwzU0a X-Authority-Analysis: v=2.4 cv=V5590fni c=1 sm=1 tr=0 ts=686bb97b cx=c_pps a=p48o0NFlLrgQ9ico5GtVJQ==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=A8Pz68axzIWmibrE1SYA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: HcCJvkBbXZuplxngQgrRiEoQeu0R4S7x X-Proofpoint-GUID: HcCJvkBbXZuplxngQgrRiEoQeu0R4S7x X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1011 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] pthread_cond_wait was checking whether it was in a closed group no less than four times. Checking once is enough. Here are the four checks: 1. While spin-waiting. This was dead code: maxspin is set to 0 and has been for years. 2. Before deciding to go to sleep, and before incrementing grefs: I kept this 3. After incrementing grefs. There is no reason to think that the group would close while we do an atomic increment. Obviously it could close at any point, but that doesn't mean we have to recheck after every step. This check was equally good as check 2, except it has to do more work. 4. When we find ourselves in a group that has a signal. We only get here after we check that we're not in a closed group. There is no need to check again. The check would only have helped in cases where the compare_exchange in the next line would also have failed. Relying on the compare_exchange is fine. Removing the duplicate checks clarifies the code. Signed-off-by: Sunil Dora (cherry picked from commit 4f7b051f8ee3feff1b53b27a906f245afaa9cee1) --- nptl/pthread_cond_wait.c | 49 ---------------------------------------- 1 file changed, 49 deletions(-) diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index e6417997f8..11fd45f9a2 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -366,7 +366,6 @@ static __always_inline int __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, clockid_t clockid, const struct __timespec64 *abstime) { - const int maxspin = 0; int err; int result = 0; @@ -425,33 +424,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - /* Spin-wait first. - Note that spinning first without checking whether a timeout - passed might lead to what looks like a spurious wake-up even - though we should return ETIMEDOUT (e.g., if the caller provides - an absolute timeout that is clearly in the past). However, - (1) spurious wake-ups are allowed, (2) it seems unlikely that a - user will (ab)use pthread_cond_wait as a check for whether a - point in time is in the past, and (3) spinning first without - having to compare against the current time seems to be the right - choice from a performance perspective for most use cases. */ - unsigned int spin = maxspin; - while (spin > 0 && ((int)(signals - lowseq) < 2)) - { - /* Check that we are not spinning on a group that's already - closed. */ - if (seq < (g1_start >> 1)) - break; - - /* TODO Back off. */ - - /* Reload signals. See above for MO. */ - signals = atomic_load_acquire (cond->__data.__g_signals + g); - g1_start = __condvar_load_g1_start_relaxed (cond); - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - spin--; - } - if (seq < (g1_start >> 1)) { /* If the group is closed already, @@ -482,24 +454,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, an atomic read-modify-write operation and thus extend the release sequence. */ atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); - signals = atomic_load_acquire (cond->__data.__g_signals + g); - g1_start = __condvar_load_g1_start_relaxed (cond); - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - - if (seq < (g1_start >> 1)) - { - /* group is closed already, so don't block */ - __condvar_dec_grefs (cond, g, private); - goto done; - } - - if ((int)(signals - lowseq) >= 2) - { - /* a signal showed up or G1/G2 switched after we grabbed the - refcount */ - __condvar_dec_grefs (cond, g, private); - break; - } // Now block. struct _pthread_cleanup_buffer buffer; @@ -533,9 +487,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, /* Reload signals. See above for MO. */ signals = atomic_load_acquire (cond->__data.__g_signals + g); } - - if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) - goto done; } /* Try to grab a signal. See above for MO. (if we do another loop iteration we need to see the correct value of g1_start) */ From patchwork Mon Jul 7 12:11:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115748 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 78C5D385840C for ; Mon, 7 Jul 2025 12:14:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78C5D385840C X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id 68DC83857BAF for ; Mon, 7 Jul 2025 12:11:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68DC83857BAF Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 68DC83857BAF Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890312; cv=pass; b=gICwE9ZhzMGu+hYuEUs5VVUAbcxXIM4Q48qmlJlJrO64Elkbc5qENTcNXRqpY2C/m8UCt3GppNzQSlzYPDV5mWHexyLFvay+l3SaAazAVAynloJhMEyNOFTqEcXbAviSX2g/hmFCx/Xnwvwd28V1KebZ3nI2wux01ygg9IElUWo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890312; c=relaxed/simple; bh=d+tPdZzYCZYaLVf09aqYg33PEz26zE9ngxQwKEkdIeU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YR1M9e30uV6Nj51iSyOnkVzSiZLgG6OqkRM3PvLST+WCSXCzvf7Ld4V8sxELi650Bj4QiYNygGsVEeGtmusgBFHqLZTi3bBjuB6d0MgF6mIS+HWylsf7APbvsbAP66OwHW3E+Y/dQxBfmMgHZmc3cnj6z0x7TQjfWTvXWCcUt2A= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68DC83857BAF Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5675mSZo003178; Mon, 7 Jul 2025 05:11:43 -0700 Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pyb5hh5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yCoo/20fcNuvAeV33hl1cFRKKDAyyiFEcPvRCKOB1kgNaYIxxlFQpoIs+fTSlBYZencLdv7GIqvuTXMni0Vw9kk2J3JTIL0iFBqFGnpVHVS01/Ta368Oq5sXYviVv50aEroNKpytXN18C7roUdhi7x8aFjoIdA6PQc8fNyDUqvPJRaE0txf5MGVmaCXI7fGu61QReKQsGtwW99Dao9xLMXpepOD3qqPbDtI5LJWUXkfNhfLlB1QHcIOct9/YoQqwseIinmWTix4Ls9/QqmLw9uns/Gk7A8uxH/nwRRppUh+AF3nOqQhMMJlf2lv4qlgNcA/0GHfzqePSIM54OrUdvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=yB2UnXMLDTBMx/YRLL3bYWw9NJ412HCaeFaoGSLdbAc=; b=oibctIRPFcQJGFGaX51lEdpx9VUyvYFHZkd9t6nBSQgPLe+szGJuXSqgYpCM1XrWqLIU1pF0bPvf298/dBuILpY1om2Jihjq4eA5Degvwyt5jk7Loa7T6HQPGoaLLBJEYHnt+QwGnl418Zug/wa48R7zBGUNfpvnxU6lsIXwCGW7ag+vq9cgQKWj6tFi1wl/OM53YRvLgLRKtAMYGPMaJwp9fQ0bdc4eaV7QrsmzqI3AjTeXAWgLr78t32VEhRC5NK3PhFbBXWpUnkJ+Jr1rJikMivG0bPR2N1mRiWb1ws55SRr9TrsheEmmHYlq2CpL1ly5g/Im/gHwSn0qNY+LXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:40 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:40 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 05/10] [2.37] nptl: Remove g_refs from condition variables Date: Mon, 7 Jul 2025 05:11:00 -0700 Message-ID: <20250707121105.2226766-6-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 32f34697-abe5-4a8b-93b7-08ddbd4f6de8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: x4ynVHYtVl+7IxJViHLpUFkSGFiJj70aFo/Xo7ttZH/72bGE0xSsU51Ru7iitRXslb26Sv+1OGF/hnUp8Jje2Ex/2Pc3I3hWofy5N8T08sZZRz/pJHvLBNmwTbsMSS51cbGEGDN/JSP4Rsy6bDAWNtZoBZsf/8ZejoTCowbxPbgroGwatRuuB1UOsd/BamwB3MUrtRcQSrdyuDg5/gcMvUgKKqIW2+N/KeoG1TL2oAPLy2RDZOiK7dFEaPLGbhUvtzBbaoR7tQs48uUDGyfR7c3Ly67LUCR25h7COW6metSigfLXGYl75/rhUSQTyF3VBG9zVf5+YkZCZZU+br2y+lB3G8rmtBq6rEJkos63o8kVGhBwBOkz2h3wZV3ULYoUQuvGnCCd7DbpOSEXpLc4JJGgckKM/h7DYntX4DA4qBtlsTy77v37l6Nqfeejq+IKMgZptJJ+107DmbPSglsci2riK0Oa+2b0WJYRy0dBof+KF6Y7/POL0dU2aEGcXUocq+Mswn4496zHcL4AtowLkUcEpYsrkWq6c/f0zwXrIz1xvD4OTW66W0j2gbg+0hq/u4hZebzLZTDCulF3bs+D+k+KMTc5ViyyEjiUu+PA/uTSD19hQzclY+GXex7DxdV78FuCWqubXez4Sy++YfvRpXcOtxmdYdg9n+DuNzDGM30VMuV9v1zVmN3ZrcY0Y5jUZGdKMmA43Qn6UEiHtIrnoG+HZ0LMco1DcxANjVNaFxsoCLXVGScOpyOuMPfLUQ4sjy/oEVCi8N56SsWVxss8RNYYMoshIOk8FeRxtDRIbuIIrBPd5qkNUgbsUoKpu7yB/J9+UlmtttrYO/IJKDrIDkZ1uHKYJiSoKNgLCnX921G2zhBevP0TfFJyCEMWGD5pcZIf8BWpruvW5olPcfwV1nN8esLRD39JWIUUH8uFVbqsIORw5HKzaHuirss6f8+rhXT7Su/FT7zdrPUx+7ObIR3U/DNEewLCt8Qj7UXs4I+kdgY1qpytK7vsg2NSMSLJOLxIMCrdGJYQL2+mvKqg7irSTlvi2ZQ13MqgyGoYiu7yRLScsJQDxFzSSo8tR0Lkhhyt31XeodMNIe2PO3PfLATiPGDLV7qhG8kibQq2alF1Iv51vduJ4DCz8adJ6qL1T1cE3YIUvbjcbT+v8Z6YwtVin9zoLEPVbOLXMs50xfFL9y3lst3I8NHiIIpUBHzp/w9FY/I6E20Sk6/nevI+jYdzhxBMoakA7ukhpDCFiOAT52LB3H2hhEG6CMcQmOyMRjubYe9fpZw3ujbcmdlbX4woEfGUIWtSxKqS+RvYRFQ/Hn0UhXJspn52rJlknWyuAqwv+83vX4xW6b3w4iPOWhXq2vIcSY2G/8O2PmISmGt001B9UxFZK2weyh/o1ci6jlA/MIClF5YlLX14Lcqibp0953jpt3M8vlOHuA0z7vH+WSCA+mUBSvyHdw/ntchdPI9lkf32jnvsF/G5+SAmpw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9NJNN3gInYQT0o2/uTdm8bNw7JwmlFjBtoHO5EvaBrqovRsiqIdwHzfyfAg+50zBhFxfHDwqTPVg15y5eReRp1rO4wEPn8BgsNKAiN+lobAjRaoRn/AWE1ks2R3lTfA54bGIbYNlR+ejWrkCwq7HsfuZCQ1A7hBj6+yQ036WQ8ZYiLABP0YHp5KC7xQ00nsJrwNIZS/FFjZ6T6l9s6B8iz4PDlJYaxZpgl/hsMe6jfR3yCOu+DVkGtllOYEFKmiKR+Q7dkf219XNYd9ikdUrcB1IXlnOhnCsclHCRIwHtVtd5mOxRfO6EBXMzcZWFt4sS6bxD6Yx1MkWsV4FRXIkUdN8sKBG1QKs27HJnnucbJTDJFGISrwxlIKMULz03QxNN1eKcgi/7hUVSvAeaMZDp6mafL3ZUdT+hA489dyy6T3dL4nDUh9+NrcUGiLSsnRPJS6XrdCT4fMWo8ILgx6uIfuGMTxYKzxi36r2ddAzTN+vkB+NP9TsKsVAKRh4kVaH2tNPOGVMz4n/7y6tFrYsQUgBju0HPF1UsMTifQCvFNANjRKVSAjlvpaWSWwaScy36ka5HA4xSAeWtLjJrPmN4XFxsPrYjuhxFOq39lEnFNBhOFkXWp6v7GXCLJxCGL5vJaWZZihdRlJ5v6Ou8mqg96ZejWjwKkq+uUxDqtVx0KQlbm8O4NjQNP7tRZOYMOAbSGgkDvsK407v5ho4UP/h6DneV9aY1C0H4d0hdYYDT1SOAOui5VefGZHar6YaIkG5uXJpdVxWqQLfu25LHh6IHCbz8rvzT1zTs4qm/esJar1BR50jynImcVsgjsvpu9cjF3DJJbO1NeMKKEyVfaDGwJ1i2ZZKOGhq1xq9WnL0W+aZllDGDAR+vm7wUh4J/LUakeNsBVoZRXgadFI2uOB8svYVuPQ4c1RwPNw5Xi/qk7zHZe/OlxoP+qneOAlWJdhbGDu3aGUYDE/2ShJU1rhbRm3qbHc7f4stcpnRND8moylqV6I6/a4wpBeCW57tCw1noU/kQIUjTQ7G/mlurDESSKYpPvipLt9wKi9xu0xzYpv2Q+xVfddCya8NThN85odPtfFatoVNY9TVmyWOELZxjSWUFmWtBdDuW1KktLy36lDTQ4+IYNPcHa100CvwLkRh4VpK0b2nfWw8b3gCjsH+WaPanaz6xElCvKNQqTaiR6QjNbjnRf6ovrkcL7Y6On+9J9FXIctfKzfvINxJ095vEHmc4Xcbq9+y5u+Eg13AK/rpE8/x3OxhhhM0KqcoZ4geiAxLoFP51SZ8E94FeGlPnJrb/sy19E2fhhMankb2Tnp/VFay+5UR9rhHo58vLtYUnpaiXdW6vDmcUchAYR4c8YdRXnja3Zs2awYfVHlRaW3CHfzy1f0uJ9DJV/mOBlir+0BfN4zZaiY6JA/fOnGZGRdPvA8NoB8eP+ej10JTT8X17au79kQkl/IKPz/1RPY94vgLDQT1dK2QownSlll1Gt8U6LfRsnyovGB8n8HeBvgl98bX8pF899CsyEXoLjhPs1Q1wHIVK+qHZv9E4R0mnau2dyWQ9gr/jAp9RlEJENfs/pbxdC8K/59kiiEMfnLfD/m86pdjWx9qS4DT3yt8ZA== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32f34697-abe5-4a8b-93b7-08ddbd4f6de8 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:40.2691 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: S2HS9JGDs7tvca8uGGRsiegfiRZsDdSsStmmI8mjFio7UKyco4HRUoZZ/xvxvs0T1bJdFt6SYm+yeoxZmsAQ6PHTgYOdSJRkhWcxnOBaoHg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX4WyfIsZsyNS/ vYEpLk9LBu9Rf97QQDdLuvtfpSWe8rRszqOvcpS33FZMjjhJNN3EWIHQ7XZ2IHfmxB1iRMIOdbh xR8aEOk0GKPmD5jEm7OZ7gdAJ+PdY42CiP33YaehK0na9v2lZHg9MpgDbUcSmauBNoWDVprDe34 T8GGFIXXiNrazsnvVytHjezLs/Fu4cZAUnyiB0svKKIa2dqnE+V07BVZ0kqm5BMez6iZRAIOfpe RhE84AehYGmPzBKK5GJH2g0wX2WdeOG14hsbIyfJVl3RmWPGdVxSt4rwcE4mQmqvknAf4u1qQbq 4MJL7A3olrP/SoU+V4c0niqBlxbpfWxWolfCZ2MiZHbgRzgeW1xIZvhFT9jWfmiDnk1ylndn1ZD I6ZLcivZDbiRbUC7YFh2Pb8k3N0cxc7sjkNGzDqOWalDuPUzhGETPnnPIA+KXhVZsxJlGXyk X-Authority-Analysis: v=2.4 cv=V5590fni c=1 sm=1 tr=0 ts=686bb97e cx=c_pps a=d1No8PtT6ZCK1EqvqO3Ujw==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=g5cTviEHbg7wfX6xL70A:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: _p5GGVsmEc4Lm_9EXYlqdiMLQ_AKChW7 X-Proofpoint-GUID: _p5GGVsmEc4Lm_9EXYlqdiMLQ_AKChW7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] This variable used to be needed to wait in group switching until all sleepers have confirmed that they have woken. This is no longer needed. Nothing waits on this variable so there is no need to track how many threads are currently asleep in each group. Signed-off-by: Sunil Dora (cherry picked from commit c36fc50781995e6758cae2b6927839d0157f213c) --- nptl/pthread_cond_wait.c | 52 +------------------------ nptl/tst-cond22.c | 12 +++--- sysdeps/nptl/bits/thread-shared-types.h | 3 +- sysdeps/nptl/pthread.h | 2 +- 4 files changed, 9 insertions(+), 60 deletions(-) diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 11fd45f9a2..0403df3257 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -143,23 +143,6 @@ __condvar_cancel_waiting (pthread_cond_t *cond, uint64_t seq, unsigned int g, } } -/* Wake up any signalers that might be waiting. */ -static void -__condvar_dec_grefs (pthread_cond_t *cond, unsigned int g, int private) -{ - /* Release MO to synchronize-with the acquire load in - __condvar_quiesce_and_switch_g1. */ - if (atomic_fetch_add_release (cond->__data.__g_refs + g, -2) == 3) - { - /* Clear the wake-up request flag before waking up. We do not need more - than relaxed MO and it doesn't matter if we apply this for an aliased - group because we wake all futex waiters right after clearing the - flag. */ - atomic_fetch_and_relaxed (cond->__data.__g_refs + g, ~(unsigned int) 1); - futex_wake (cond->__data.__g_refs + g, INT_MAX, private); - } -} - /* Clean-up for cancellation of waiters waiting for normal signals. We cancel our registration as a waiter, confirm we have woken up, and re-acquire the mutex. */ @@ -171,8 +154,6 @@ __condvar_cleanup_waiting (void *arg) pthread_cond_t *cond = cbuffer->cond; unsigned g = cbuffer->wseq & 1; - __condvar_dec_grefs (cond, g, cbuffer->private); - __condvar_cancel_waiting (cond, cbuffer->wseq >> 1, g, cbuffer->private); /* FIXME With the current cancellation implementation, it is possible that a thread is cancelled after it has returned from a syscall. This could @@ -327,15 +308,6 @@ __condvar_cleanup_waiting (void *arg) sufficient because if a waiter can see a sufficiently large value, it could have also consume a signal in the waiters group. - It is essential that the last field in pthread_cond_t is __g_signals[1]: - The previous condvar used a pointer-sized field in pthread_cond_t, so a - PTHREAD_COND_INITIALIZER from that condvar implementation might only - initialize 4 bytes to zero instead of the 8 bytes we need (i.e., 44 bytes - in total instead of the 48 we need). __g_signals[1] is not accessed before - the first group switch (G2 starts at index 0), which will set its value to - zero after a harmless fetch-or whose return value is ignored. This - effectively completes initialization. - Limitations: * This condvar isn't designed to allow for more than @@ -440,21 +412,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, if ((int)(signals - lowseq) >= 2) break; - /* No signals available after spinning, so prepare to block. - We first acquire a group reference and use acquire MO for that so - that we synchronize with the dummy read-modify-write in - __condvar_quiesce_and_switch_g1 if we read from that. In turn, - in this case this will make us see the advancement of __g_signals - to the upcoming new g1_start that occurs with a concurrent - attempt to reuse the group's slot. - We use acquire MO for the __g_signals check to make the - __g1_start check work (see spinning above). - Note that the group reference acquisition will not mask the - release MO when decrementing the reference count because we use - an atomic read-modify-write operation and thus extend the release - sequence. */ - atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); - // Now block. struct _pthread_cleanup_buffer buffer; struct _condvar_cleanup_buffer cbuffer; @@ -471,18 +428,11 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, if (__glibc_unlikely (err == ETIMEDOUT || err == EOVERFLOW)) { - __condvar_dec_grefs (cond, g, private); - /* If we timed out, we effectively cancel waiting. Note that - we have decremented __g_refs before cancellation, so that a - deadlock between waiting for quiescence of our group in - __condvar_quiesce_and_switch_g1 and us trying to acquire - the lock during cancellation is not possible. */ + /* If we timed out, we effectively cancel waiting. */ __condvar_cancel_waiting (cond, seq, g, private); result = err; goto done; } - else - __condvar_dec_grefs (cond, g, private); /* Reload signals. See above for MO. */ signals = atomic_load_acquire (cond->__data.__g_signals + g); diff --git a/nptl/tst-cond22.c b/nptl/tst-cond22.c index 1336e9c79d..bdcb45c536 100644 --- a/nptl/tst-cond22.c +++ b/nptl/tst-cond22.c @@ -106,13 +106,13 @@ do_test (void) status = 1; } - printf ("cond = { 0x%x:%x, 0x%x:%x, %u/%u/%u, %u/%u/%u, %u, %u }\n", + printf ("cond = { 0x%x:%x, 0x%x:%x, %u/%u, %u/%u, %u, %u }\n", c.__data.__wseq.__value32.__high, c.__data.__wseq.__value32.__low, c.__data.__g1_start.__value32.__high, c.__data.__g1_start.__value32.__low, - c.__data.__g_signals[0], c.__data.__g_refs[0], c.__data.__g_size[0], - c.__data.__g_signals[1], c.__data.__g_refs[1], c.__data.__g_size[1], + c.__data.__g_signals[0], c.__data.__g_size[0], + c.__data.__g_signals[1], c.__data.__g_size[1], c.__data.__g1_orig_size, c.__data.__wrefs); if (pthread_create (&th, NULL, tf, (void *) 1l) != 0) @@ -152,13 +152,13 @@ do_test (void) status = 1; } - printf ("cond = { 0x%x:%x, 0x%x:%x, %u/%u/%u, %u/%u/%u, %u, %u }\n", + printf ("cond = { 0x%x:%x, 0x%x:%x, %u/%u, %u/%u, %u, %u }\n", c.__data.__wseq.__value32.__high, c.__data.__wseq.__value32.__low, c.__data.__g1_start.__value32.__high, c.__data.__g1_start.__value32.__low, - c.__data.__g_signals[0], c.__data.__g_refs[0], c.__data.__g_size[0], - c.__data.__g_signals[1], c.__data.__g_refs[1], c.__data.__g_size[1], + c.__data.__g_signals[0], c.__data.__g_size[0], + c.__data.__g_signals[1], c.__data.__g_size[1], c.__data.__g1_orig_size, c.__data.__wrefs); return status; diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h index 2de6ff9caf..59f9adc59a 100644 --- a/sysdeps/nptl/bits/thread-shared-types.h +++ b/sysdeps/nptl/bits/thread-shared-types.h @@ -95,8 +95,7 @@ struct __pthread_cond_s { __atomic_wide_counter __wseq; __atomic_wide_counter __g1_start; - unsigned int __g_refs[2] __LOCK_ALIGNMENT; - unsigned int __g_size[2]; + unsigned int __g_size[2] __LOCK_ALIGNMENT; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index 3d0d07ceb2..9d2eb4d512 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -152,7 +152,7 @@ enum /* Conditional variable handling. */ -#define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } } +#define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, 0, 0, {0, 0} } } /* Cleanup buffers */ From patchwork Mon Jul 7 12:11:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115749 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 6764E3857BA3 for ; Mon, 7 Jul 2025 12:14:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6764E3857BA3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by sourceware.org (Postfix) with ESMTPS id BCA1B3857B8F for ; Mon, 7 Jul 2025 12:11:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCA1B3857B8F Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BCA1B3857B8F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890312; cv=pass; b=IPA0p6DWE/5C5FkC7AQ9lCxd2EMYAhH1sZVczKT+3qU12RQx8XDaZKKxTIKrF952p4s+fqt7AGQQxfgp3Lks8SShczGQfQGp+lDQoU45/rtkVtilVTjjub7AdmNmCObhU/lRt54TJcM/UwagvWQ0mC9qTE2Rr5A6r5gkODoF5EI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890312; c=relaxed/simple; bh=TDSmqHM7LQ2A4CTACWqlmXeWNmtEhccDELTaEVWSbnE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=aQJke4PUb7IPxQuWjyLNqmmlH9skZntjpuaOjhwa/ldZRBJnmLdA8TtU4Lta9BwMIK30Ce802HTQV3a5TgibMq9mY4fK53vHRxGh69POKrbPy/7tIMmdgee7oPgoq8nRsppwoS7SSkSyky0Ta4SbOHgvgEj/j/+G38/rU4TA5E0= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BCA1B3857B8F Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 567AmKga004427; Mon, 7 Jul 2025 12:11:45 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10on2047.outbound.protection.outlook.com [40.107.94.47]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47ps91snc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 12:11:45 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WmPSd5lCHnBYDk6tcxEHGLqneE84hNv3NTpj/Qr9shkMQCaevGHlNdv8WXdC5CuHKI7BMTwjXb6KFQGvQ6Kkk8eRpOKxCxpH+wS13DvQkm8n1jKDEI6UbwXq3vNuE0jFjvHMBYRqimRzdyax3TIkCZeMJZkl+BCAcpgkkP9Kw/P7RtoiC2AyVgXZhP5+BFRYmFnplOoxD32M6bdrPqdDsf9NXVVehs7dxbBdu4YkJP/Et1Ipk7pWMdbcRF/9ydv/TIMJDBC2i00/9u1IETIozVjNTT8ApnkJTaYiKeBwUpGe/qq77qOOAImA4ZDhApb6mYXKxzYZl98cqZMGzoPwzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=azpx5jlWA0ikCHkz9LiyWgVEv9I/ZpxN2KIO7rZ0sDc=; b=ihNCnpZhXvyoYpTaXP0YK7hZmDkaR8AhN8cFz94wOh+kYoI8YfHsCJhKdBF3hjouFVAdWDbTWTVAo7ULNtfq77zYYHJqCviliF1KkljpKK/kV+fwnuVrk9leqibl1EU6y/sYf9dnCG5I75CeMzlf5oB5IGnt8mLdJ9VOkjj86plBmTCgB33pV6zFyGyZff9e7zJcMs9zQKjbLh+JvKgZVtv1jyMfpqd8WwgBrhz/pmmAPfZyL+RdgUhbtaX9vKcrdGd3YE1yuekYSsNgknN7hViy0jw9QL2AgOxDcfEJtNT1+U8gcQzxg7I6mKYXHmZ7a7/DpnEayBZajGLOKtqF8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:43 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:43 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 06/10] [2.37] nptl: Use a single loop in pthread_cond_wait instaed of a nested loop Date: Mon, 7 Jul 2025 05:11:01 -0700 Message-ID: <20250707121105.2226766-7-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: c4308298-21f1-4818-91c3-08ddbd4f6f9f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: dmXf3Mp4Syoozf9d1PCY2a5xMvZ09d5EXn1/PAGseTiVd58o3F83xzLa4JN5ARNI6yowgfJ+oP/kwBYHXZsgLYtyumQEz6mr+pPEtkGE/z+66CEaYWOzK6an1C5PnM2dy3ls6029s5YmjdmOQldv4Qx7hyWBmtgM8yHIC5pLRHk0wg3vL0kSPbzfYN5UIze8DMG/ugfj862b7vokR4EdS4w+ewU0JQyaes0p/MWa/Ie1DYL33+aIIxOoahgEDteJAIKSkvyiAzM3Jiw1juTEvH6fyQWILALBwyf38otbnWVdnyRZl2yGYjSNyatsOttp18YEskXNVMD48HgDstAIqoxbRweGMOlVQPzVTzs5Ro2QFWSliHz5JMZqKa+pfrPGdUjb1ybFzJnz+OQXGcbXgakovBti4PdHanK97eyW6j/7yK3o1se6rHNe3Cvhahe9PcGv+5B89kfxk4eZbgx1htqVWgWllEMMmn4umFr0441kwib3YUdrK3nfRijSG81Qnp5Kk9pym2Fcgs43DUMM4nkFNY/fmeeVqwEQhQvDdbh3jhBytew+6L64jl0aHxug2+UW9s6aO7peLADdVvM7W2E7M4c7GPav0XVzX+d6+1lqJ3aDUdnEuMjCqSVDHnF25EPjM8xaTywlsX2HRPqLjeVPylOA/6EfC6WwtD2K8iwwymN+c7I+/sFwhY1HAiOe+z1bq7/NOgsClPnG6WxCzyORRH5yRrnVpouiDFZcRqLROZxAat9hipqKCfXH3OH9+C/sQUMY/5E3XEiTvhIB3YH75+2q+mZm91mEP8LAMZRdNI6EypDW4ib7Gr0ti/nVB/c+7PQ+MWqqLAdzYDp5x+4LhCV/ta5ZGoRvkrXc646XTD5iO5FzGgPHn+j5e2hnEbgmGZAjKhMWD81H4Px/mwBw+aAsYAI4D7KMH2bg5n7bzbV5CKAgqIh8w6FUOMf6Ni1PxN071xTl00QoT/lQMrEcvQdT/sf86+QT4YG88N7gPtt0wvVfzdScGN5WylOyWzYhagykr6a94/hUmx7SS0ZYXidIJDS3xkLzj4vWH0gjPs3nLuc2t3tpGTSi8WYRMdAgVzPl9WGONtZ1zEBbIDxs1XbChs5MA8+jbWtT+RKukDylCnznS2jv+xMePzvIgwFfXMnxuIxPmIZsAl2ZlLwIO9JvzUfeosLb+b66otnkURpmHTxBMpKQNKGgSThA8pDWI9MANS5reuv3viejZO1jZZcztv6Tm6CKY5iar6fhzBOePBdYGAfLm3UVMMIVts5RLvcUl7d3Ey34Toip4Sd+TBug5J/BM0y+gxNtkcll/tvka0QiCZxcb3NQ54js3FGkjshKd7aNdGFbN78BQArj0S1guoR6sAirHQ0DaPXglk5qQPp834UWlUYqrjILeAvoos17CJ4Bi0SseNSdtcBYnM8M05b2PINM5u/JhoDEouR/JCAuKbzR6LwW5fUAcC4jFgpaP4Wq7KL/v69EIg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ojajk8KOLQs03oZUS8IBLDvGFv8qZlyVNvZbMuuicACV+ZIImSUA8H/s6RqmCbAfc3NWADGN7+nVXrBvKfQF6W0SyWXGT/wVtqEFcnDNQIJaar6RaAd6dzQU2rWsDCIPNgG8nY7TOpT+IIWOaKl4Jh4H/o/r/BZUpgJiHaLbce4TpmtxsjymaXIXEJIroeNmqk5D6Og+nVDfmcJXiooDi5fJ9lkeoXOnJnMLK3YZ23+XzRBACU9Y0Ol7TMUZShzr6d4CkSHpxyzGkE7/pWHPnki8k9oSw1ANwczgFi7SdHyEEiYUpVwr0fmIxlB3ThuvTEC0zl0RDKaeGxyo9VrrcTBqbKxkQKcZGHZZwiR9f7kzoQmGqqt5rmDTiEAz/wj+F2/gCfIT9DcawA+R1ioi0+CT3oy1twmnSUyLowKfOH0W8rgTpNDN3Odi8D+JvbB4uDNlYJPqhCXiF8xwgclRDohBP4zfIe39HuL2LMzF47n61TIM3Rwy0zYggdavZ1fttNbtmZTosLFOF+DJqaDFC20Nl069kxSgfaaGKYKGf5dW+NcbN8Tig/eKA/aFJqYBKZljl6toEAsnMw9WpSOfWLQARrpA+pg64LJjJ7hi5vreuMJLV7Oee1upCF3ujGo7ttUfl4yMjTF0c0ZSLEg/Cc/rBTtyQBw7zYOIN8h9YEFWbhBjLr8fiDha4jLIPnR9hkGSwtC6r+2okOnj8GQDoJrXSq3w1Yy9hQIrHVVq8VK4Hy7ICF/jgZKN+V0uIivSJ5KVsffYGkICrH7crv0ptxYpUAmHCIyfm8Yko9u2+5INofGvVnjJWFCi6p/PQDkMSGceKyfw8UepZSCPGPjUDllrmwtTaFJ4J50waj6G/md3a07B60ictHH6MjCMugSUA6s5cRF1JMlXZ63gmEd5ayOlWxCIB0yXWlcvYT1h7a0Yof8qIEl6vuO0VWArStcCkU62+iub9EVZ+dEYo13mcAJjgVEJqzyCD0UwhIujsgNkEgNEVfIg12DcD+4miRw63HGHTaZ6by2Cq9OjHRqaMGDApW3ywdV1paoRymwHkhSzjAUjbuavwKgs/uMz5DJpzNy+Vsq5dhKnbQNVLf7peiGC8O1Df3Ccksy/wHmDBw+EMI5MPnngyG0eXbLxhLZHjRwavFdK+lF0/6FDnRZZUeFM52MwUP9U6X064kNELJeuu5GwtlrwbciIkUGGgOIprhCLnHxZxP+usZm7EJvQF2i0poS7Wc6+3cl+1GelOYrfbIqC70BdV3FCFjEjkjbOCOgjcsM1ynjQ0lBwwxzoaCNjrnlXVOiJhcDtV7kE7M+YSguft5yH82pl1QQ2kc07vFbq/VZws+sv8zFAjs1HvI6Va4tngadESAksXj994qYDs26LmxQsKpCxkr1p4fHci9KqizMTnC61B6gfNFNHH3FMnDDP6ej//XkB/rkdE6Us/GQwWzBC32ydIaydGgGU/sGzvy3GPnnGlFpI/70P5JeDaaiiiiA9CpKK8cq8DYxVNGwsPp2WPjz+2eC8Ia5Ec5jdHRbilvZMEfioMPFE0GJT6rbRtN63/+zabD65dJGtMLY7c5is+d3KbDJbB67J63dpBmTXLipzQeBn1MdWcA== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4308298-21f1-4818-91c3-08ddbd4f6f9f X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:43.1547 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hNQuOlTvwyvmwACShb8ihvRRMmnFbOj881Kmk/LmtUNRIBbrGDOxU1ggmRIE9EHoTQPE0BLRjOR7ZfYswQSqoRzYHqkTkRaX52zW8Po/tR4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Authority-Analysis: v=2.4 cv=PLcP+eqC c=1 sm=1 tr=0 ts=686bb981 cx=c_pps a=ZHDOt/UCYLft9xDhnkUFqg==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=T8vG6WoaKTypD2s_2PEA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: BlHJTjYJoU-czrZGAmR3C_cCpNXfXx-5 X-Proofpoint-ORIG-GUID: BlHJTjYJoU-czrZGAmR3C_cCpNXfXx-5 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX6jrkJi5rYv1A 7vbXgM/q4bBV04vh2OXcYsVbeUi+exysBaQ+poRpoEqEioX23sNIyHDpEUp85b6zTuUzuMmJRhq enl9mazYwk1+Xap2qIf0kw6tIkGG5yo0pr3S1rp5aEQEgBmO+n0BcXnkXB0bnK40VdnixAS34jD v/5rVM7ZoydCr9+NMTaH+zErhpMHBODRRQsT4A+c1nV4GK/FaabKWclL7ddG7ew/PsRKo4QgF3L SGdzMPjdUbhsAC1Rbocv2u1OpM6LR7oRtH5V6XMfp68IXQUljJYqrwEOyfRfTLDxnWxnG7bdvPI e2KGFwWWDU+Lhw+cKX1YY17NjtCKUzH6MZfHNANuWwQGaF07vUKux8AT0smMSnrWNoxwJ/EHbMv QxcC4fMouUYYm9+h1CK9Mm28De7+Q1CNOIIsOWjDHavUun7Gk4IN5ulQ4TIwBxndInMOfFsd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 impostorscore=0 phishscore=0 malwarescore=0 clxscore=1015 suspectscore=0 adultscore=0 mlxlogscore=846 lowpriorityscore=0 bulkscore=0 spamscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] The loop was a little more complicated than necessary. There was only one break statement out of the inner loop, and the outer loop was nearly empty. So just remove the outer loop, moving its code to the one break statement in the inner loop. This allows us to replace all gotos with break statements. Signed-off-by: Sunil Dora (cherry picked from commit 929a4764ac90382616b6a21f099192b2475da674) --- nptl/pthread_cond_wait.c | 41 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 0403df3257..12c1388c1b 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -382,17 +382,15 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, return err; } - /* Now wait until a signal is available in our group or it is closed. - Acquire MO so that if we observe (signals == lowseq) after group - switching in __condvar_quiesce_and_switch_g1, we synchronize with that - store and will see the prior update of __g1_start done while switching - groups too. */ - unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); - - do - { + while (1) { + /* Now wait until a signal is available in our group or it is closed. + Acquire MO so that if we observe (signals == lowseq) after group + switching in __condvar_quiesce_and_switch_g1, we synchronize with that + store and will see the prior update of __g1_start done while switching + groups too. */ + unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; @@ -401,7 +399,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, /* If the group is closed already, then this waiter originally had enough extra signals to consume, up until the time its group was closed. */ - goto done; + break; } /* If there is an available signal, don't block. @@ -410,7 +408,16 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, G2, but in either case we're allowed to consume the available signal and should not block anymore. */ if ((int)(signals - lowseq) >= 2) - break; + { + /* Try to grab a signal. See above for MO. (if we do another loop + iteration we need to see the correct value of g1_start) */ + if (atomic_compare_exchange_weak_acquire ( + cond->__data.__g_signals + g, + &signals, signals - 2)) + break; + else + continue; + } // Now block. struct _pthread_cleanup_buffer buffer; @@ -431,19 +438,9 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, /* If we timed out, we effectively cancel waiting. */ __condvar_cancel_waiting (cond, seq, g, private); result = err; - goto done; + break; } - - /* Reload signals. See above for MO. */ - signals = atomic_load_acquire (cond->__data.__g_signals + g); } - } - /* Try to grab a signal. See above for MO. (if we do another loop - iteration we need to see the correct value of g1_start) */ - while (!atomic_compare_exchange_weak_acquire (cond->__data.__g_signals + g, - &signals, signals - 2)); - - done: /* Confirm that we have been woken. We do that before acquiring the mutex to allow for execution of pthread_cond_destroy while having acquired the From patchwork Mon Jul 7 12:11:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115747 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 333903857C7A for ; Mon, 7 Jul 2025 12:14:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 333903857C7A X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by sourceware.org (Postfix) with ESMTPS id 30BDF385800F for ; Mon, 7 Jul 2025 12:11:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30BDF385800F Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30BDF385800F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890314; cv=pass; b=OG7nvJPk5+/Kei0YefALbsx+0CrXqjPo+4mikB5JJ4xHRLncPQc6gCCjX4DMYUaX4woAMEkYCpF7rABVX2mg0DWtX76FLhPpgOxDrgczPEGEARQAkixi8dyQ9xkgCLOp2IQMuYc6cgXdcF7nUJH2IU0WEGfkVxayLRmwQI/kEJ8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890314; c=relaxed/simple; bh=9MpEj39/jpp5H3e1wH7mlkbtGuZOC+R8DJxmNlzDOUs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kiH/IQMJ70vfOukRPsPLaQx1cpx65xkSCqo106nb8TEbOdS1B+AMMcMa2wjHigl9Wndgf4efzR00ydz1qg2ubU4jRc3wC5x/VaaGdvPa2YUJLqhhmmhXuyYGLcT/2v+TI7NqaBqWgwuLXQXD7YupJ63Uqc8EKIARQwL+K+7HAvU= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30BDF385800F Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 567BRlhk016411; Mon, 7 Jul 2025 12:11:48 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04on2052.outbound.protection.outlook.com [40.107.100.52]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pu19hkd5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 12:11:47 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HXCOMws0TWcXV2luFmJApVRABtFtUahgKkZ2pa34htUys0D/3A5612ZW5RW8Wt/7117A09ZVDh/8NZwP4SJVE1VrTB7LN/NzwbTiA4wlCU//C7UjPCAERt4u4TTlAvUtIhvkARXkwz/DAoRgczdZ4g9R+U3VQltZSh/09gyigCBibzwOthyA6G2aqvCFNB1r0NiTiWCd/x7WMdd3hXKAxGx4T54s9tafO+mssw8O5F7CQCS4kuGzS/d3OLWb/FZsTGv5o34YuLDubfg3MvGzEMV9t5hKR/oflozANB9s/DaKf+9mSOdhbFn/2s34uUc/H4ESXJWdeC6H0e8dCC5yEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Cu64K+BGzFac6jEWGJBcCUS5m99UvpRt2891DHUY2mk=; b=CgO0bZOBErUM+pipBm0qwcnqwYxxBKzwwaLQ9UnjB52WPcwgSAdS8ACeXjF1324+vudigA125AXYAde0392FF3x/WOsQVbMmmQN7JhKmrTgJUWxiv2ksHFZxiXEUxyQfMXhm9dibDGLQjQ6o+MRPh1MkGdiEoJ86MscWeR7eAiO6Ox9FBke7ikShT8/jczdKjHHdE8Ch+DQtnNXLDcNUVyiC6gWWer8drqA+8e+N6/36rDsrG3Bs82xLTyIsmvWsx2Sg6n7dOTQmAZYl8JMm5Du0gvtdgdU26h/LV5+b1NjixTO8TXsdWk4K/Tv3YXRAI7DhBN837wcYa/UkEbur+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:46 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:45 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 07/10] [2.37] nptl: Fix indentation Date: Mon, 7 Jul 2025 05:11:02 -0700 Message-ID: <20250707121105.2226766-8-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 20ea526b-2267-4f11-bd80-08ddbd4f7144 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: lBAsLQgdbo8GdlRaReDTztQUaqoPg5mYJvzErtPdH0Lw5nmvuk1B1Q4rtv1w9IvCqE3DOscb5gu1c+359NJQq5kDalbpXBM0Q75tWo0lHKF9lxQZ9840wGJCeJRSdIE8TtxV+rQq+kHOo2P9vl2sobb8cob5Hse+YNpWNSvHuU+zbcuq3WpUq1NoRsTKnw1MZtNybBPEpynodBQPdZ+wZs4+Tz9YoQTn3uI/z8T8HJtV1XJKl7UKlEjgQfd2YAd1mDJd47kK9152Kt+sNEGm7vb1pA/rTM0qior/PeJ7KN8bA5kKBJ29BbDhm2kNbh6gI0U7Qy/0B/myQJFuC9WyK12S3w4H6SerrMqw9+94sma8G0yY7WvDUSPkWTktmrt4P6ZLy3+ZecnIRnm5BtfedFDc6s4yp/LyoUMr7Meph349lVh7QkkYLzRzOhsCltVPTREq1iKKargoa+DeHECBqWBiw1CfdlHacgDjNNtfIFuj0UvrCbNB4I4vS0ORM46i9/9VmbjdwAiNTDtgPykmZfUdTRCa7OeK2dNUj/WglcttDPow4Ua9o4duM9/0cYcL9giv8Kkxsnq4SchLvmcPKAd7IaJkoBc0glqpMmF+rJW9AXdrnp5UdF4YHWZY6Fu1Q0zViOtFF4fd9n8fLPI+4vmTD09v6W4nfwXl6fHx2kzJla4+rSV+lXST27ehUscTazgzSF2jnPpwc/wkg/4g8hUvtx75ZVI/2CKBveOhJDfhhcj44pEr2jycPSoVZfKShJKVEO3pLfENqQomhI9j1ogBjlJGe+5glR+sBL2tI1cu6Boz3WlfIBZKfnJF97UGyNmuMlfxFa2/I4uu6Zs74aWjSm4hXz/dOr+RAEOqN2v7G+5rw7/CAZCWHCeX3UMhLiqAMe3trEI8LFZPuXzOUheUcNCjmeu9D9gvyhlL6J3AOSHm1Tlw73YF3gwK3f5nN3Hm034wAa+RdHb5ppyxBVu4IZYYRJHK4gQHtyPPbRNW4LUrcoRqa2kmBxHLdS0wPzf/wEZVSqPQtucPQM1+pDWbBHYoJiHThmaAHcXnReiz12Vc6NJP4YsqERxs6bzebWLfqM80A8hdRE8Vzf5KFIAy0RO+DDdDXFR/WnWm6DHTcRlQijQ/VTHnFETBxHP2Q+FQ5dEXlnMaKe83+B14+M8mloqZMyZsqukE9L0htJePUAf9EtPhR710disJzP3TI3ZeUDiFy0/xrq46JS9XYJpb19UPy+fxGjWZ2dnitut3XEhAMfl+WiOAayPRjBgALtpIrRRNCu0RtOD26Wgj7gEnm4fpRFxY5Yvb/7Asc/UbWz/zWO9yK0WFvIFDnf9iykQsRpsOP2PR7lqoxzboHcUM9OUWEx47lMrbx/Y3gRq4DERb9LEV9xDpyYzW5Kko55Cpc+NCnYVFbQCAvWTdOeoZ53grWqOHYXmwGGg7E9eVVQBbK7stRYTdK6g/+cV4tkpUvfsjAYNFTLBQaI+U3g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JICUCWuVkvznqIlxYHZRcEdqwg787ATw+ZbnER8NtnRksb+EocdsRFZVwheIBvuG4/h/pHxotvN4UG7O2d8UGHZR3/ocG7LWZelgCePDIgzEArBA5pbBpRFFeCPlXyAcrHNHWW3DM1xvsK6f5y/pSnR6wDunbtMDFq2Cm9F6+3xp/JU6pajuZsn3Z8EGqg6Oakcrzml23jTCA7V6ClxtFTf80XzDYE7DjyUELJhKYwaLHyAGBstO8Xje7rsJNbDl6RmY/3K7xLc9RNoctqcuog13O2j1X5qviSSgfSInrWSeXNC0LCVJxEHsGCtMVimH+dhwRHBp+D/JsGKN2murIQiusLqcuo25iSUCqhFWzuXYVxgq0JBQ4Cx4aqmp7EtIDgFnpLtQHPmLVulb2YTS7puDhJ3Vyvr+SenM+mjtcelTkFF4fpG3frnij48+hyWQHSxQNnQ976FgqpPYsfBvcC4SZ133yGa1JdnfDOVOWWSWqfMDRgettDRd6yR6OiEQcVLkeB3HreDWBPRA4bH/qHRjUcFy791cve5eXk4XNLGBzsCHuDMHYPdQxpvuw7MiRIEz+cNTKPV1P8HEVdmEV4TnIBMbw7RFr+pDsfWBO0UTxKmPotfcxXZ4sRUJWTlXCDebw5Q7CVMgO73D+idaP0UMNIQZrToWSuZMyXnCy6I4b63okswd4ngroYLgvTsXNAkqpAHAz9n/CGzG5IhPrsHpkXPGQCIPohEFfN6+W3ahEbAPFAJuJPFRls+Ymb1LkrJ9Wx9cM44Bl+aYYarAaeqVqtGo1T+9qwiL5pzQ5Wz1rf7t62+HAJUzB/MttVhJqTVR0MB00XBapEcBG2dvviWALtfDZM5iKd8KDCy+g0IKWut49PRej2xl5ctOWO3XRQxcA2s9XkpE99yivKMFyS5k87mY1llccsN+a4/WHvvHf6r0dQEDE9Z+NyrmghNElZQGOI9prtSU2MHQflFO7vCcWMo3hN8qxwWjhqohaMtl6XeQ7SuY9/3Ih3w/zMWRS/SDmojYAqSN9K777fVk6YwSjogeYreD/VcZpSfFiREJg5Z4JhxYWkzobBmEv5Oqf90zqybVjYVSfRFpmLEb8rK23cUktwZqJ4LJdsX77KGKScUYqImdA5EbDEjmUmvWn9HzuwfSF2BjDM1BZw9IpPH0kC7N4guydUuRdxNySqEQKnV2SIW0hGQuzxXubXiOM2uWa4syjkgwms0giG81QSvLXVJ/8kZzeL9TffCCE1g2OXeer0Q1eC/vMftqKARDFRczMI7U8m/xA4xkyhFoFiFi3Xyawp5RtKD/IKD5rKFskzEDlnhPYwCrqp1AE+TVckNmWMWB2VjJpdnRmxL/v0jHbtaNxNINlkWHPSNu7pMK7Onjmu+wJ6EhFgEj9uXQAX3R8uHtqU93CEKrE5rsb3GQIjDIonvkKtkC68p7bqJ0PIDz8VofEsNP551iNrD2YaZfA1onI+ijWLLkIPjgRkIWaWz6s5X4Y/4PTpFcmMkI4ZlKBzFY8m6r1TeU2q77mci2WPOZbJQpvcgHp8G2MhjohD1vjQHEmduIOWNxe68yWl93Htt96DtFtIp9hru7Hp0NpmbDCoACzhFZHKLACg== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20ea526b-2267-4f11-bd80-08ddbd4f7144 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:45.8897 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iVJyyV2gsgyYTgHTzZbvfNRT4cjuE2kt01kqzAGB8aVwJcTS2jwSNkGgwJuArzoJ/svJ2kehaYO5XTccDGKooypFzqmf3Xojle04fP7qFbo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-ORIG-GUID: cJ-eIixcON7kBeLXFF70NTcqNviXuWo_ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfXzub83NemzLLP NnAxOzlcHD7xKRX3jFJK+esAiuR3aEUCp7ViDXoqo19tKeJChHo0p+6I6z/0yOp+HqsCFjYOPeG qw4qwfQPY0PxlmEXMQfnDq6zLW2LmzrRSjuL1gsjY8RVDHsJfX8nNvVPUHvQsSqVwPXup5DFoL4 MVsczzD44O4JGkJtl6paUxAn0BR7KWzkK8or1Rg+T6zD0zLh78HOqYEczcdDZuy+d070TDtMNYA dGmfLVgrZdlgx8AsWGojidY3P4H+Olq8ZYGYgLW9U69ZI2gklJQtMCDSDiIFiml5Y0sdZGe8h7r B6QN9V7IQh32osxN9vZ7riAftMM/9EXaACNOZmW62eTzsVf7hgEF0dtBCSoLkaOyQ0YWEiTuTC5 kd+HFdYRTBMDiQxZrLBIvj3DOKldFCkHqd+y8tKYsyzoR32dXfoKrC7saGMDssgHWCAIZEnr X-Authority-Analysis: v=2.4 cv=ZrntK87G c=1 sm=1 tr=0 ts=686bb983 cx=c_pps a=TYwVHTXLgyGkI2W0RZOgwA==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=-HArOTkMHXlwkw5IrL8A:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: cJ-eIixcON7kBeLXFF70NTcqNviXuWo_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=785 clxscore=1015 phishscore=0 suspectscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] In my previous change I turned a nested loop into a simple loop. I'm doing the resulting indentation changes in a separate commit to make the diff on the previous commit easier to review. Signed-off-by: Sunil Dora (cherry picked from commit ee6c14ed59d480720721aaacc5fb03213dc153da) --- nptl/pthread_cond_wait.c | 111 +++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 12c1388c1b..1d61441dcd 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -382,66 +382,65 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, return err; } - - while (1) - { - /* Now wait until a signal is available in our group or it is closed. - Acquire MO so that if we observe (signals == lowseq) after group - switching in __condvar_quiesce_and_switch_g1, we synchronize with that - store and will see the prior update of __g1_start done while switching - groups too. */ - unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); - uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - - if (seq < (g1_start >> 1)) - { - /* If the group is closed already, - then this waiter originally had enough extra signals to - consume, up until the time its group was closed. */ - break; - } - - /* If there is an available signal, don't block. - If __g1_start has advanced at all, then we must be in G1 - by now, perhaps in the process of switching back to an older - G2, but in either case we're allowed to consume the available - signal and should not block anymore. */ - if ((int)(signals - lowseq) >= 2) - { - /* Try to grab a signal. See above for MO. (if we do another loop - iteration we need to see the correct value of g1_start) */ - if (atomic_compare_exchange_weak_acquire ( - cond->__data.__g_signals + g, + while (1) + { + /* Now wait until a signal is available in our group or it is closed. + Acquire MO so that if we observe (signals == lowseq) after group + switching in __condvar_quiesce_and_switch_g1, we synchronize with that + store and will see the prior update of __g1_start done while switching + groups too. */ + unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); + uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); + unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; + + if (seq < (g1_start >> 1)) + { + /* If the group is closed already, + then this waiter originally had enough extra signals to + consume, up until the time its group was closed. */ + break; + } + + /* If there is an available signal, don't block. + If __g1_start has advanced at all, then we must be in G1 + by now, perhaps in the process of switching back to an older + G2, but in either case we're allowed to consume the available + signal and should not block anymore. */ + if ((int)(signals - lowseq) >= 2) + { + /* Try to grab a signal. See above for MO. (if we do another loop + iteration we need to see the correct value of g1_start) */ + if (atomic_compare_exchange_weak_acquire ( + cond->__data.__g_signals + g, &signals, signals - 2)) - break; - else - continue; - } - - // Now block. - struct _pthread_cleanup_buffer buffer; - struct _condvar_cleanup_buffer cbuffer; - cbuffer.wseq = wseq; - cbuffer.cond = cond; - cbuffer.mutex = mutex; - cbuffer.private = private; - __pthread_cleanup_push (&buffer, __condvar_cleanup_waiting, &cbuffer); - - err = __futex_abstimed_wait_cancelable64 ( - cond->__data.__g_signals + g, signals, clockid, abstime, private); - - __pthread_cleanup_pop (&buffer, 0); - - if (__glibc_unlikely (err == ETIMEDOUT || err == EOVERFLOW)) - { - /* If we timed out, we effectively cancel waiting. */ - __condvar_cancel_waiting (cond, seq, g, private); - result = err; break; - } + else + continue; } + // Now block. + struct _pthread_cleanup_buffer buffer; + struct _condvar_cleanup_buffer cbuffer; + cbuffer.wseq = wseq; + cbuffer.cond = cond; + cbuffer.mutex = mutex; + cbuffer.private = private; + __pthread_cleanup_push (&buffer, __condvar_cleanup_waiting, &cbuffer); + + err = __futex_abstimed_wait_cancelable64 ( + cond->__data.__g_signals + g, signals, clockid, abstime, private); + + __pthread_cleanup_pop (&buffer, 0); + + if (__glibc_unlikely (err == ETIMEDOUT || err == EOVERFLOW)) + { + /* If we timed out, we effectively cancel waiting. */ + __condvar_cancel_waiting (cond, seq, g, private); + result = err; + break; + } + } + /* Confirm that we have been woken. We do that before acquiring the mutex to allow for execution of pthread_cond_destroy while having acquired the mutex. */ From patchwork Mon Jul 7 12:11:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115751 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 8E43C385781B for ; Mon, 7 Jul 2025 12:15:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E43C385781B X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id 1AA643857BB6 for ; Mon, 7 Jul 2025 12:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AA643857BB6 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1AA643857BB6 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890321; cv=pass; b=TrblBkDl7iBRs6VKEtDPqH/wb7FJOsOJdWvXR6NLTbTO0XZWe0hnE9EiIdWIk9H8JvyzgZqA8iYP1cCUyOoJRVSlv65XiD9DeabEXl7aqfXGjnZI3Rc1WPkKYnvdiN5H81fcrgsrGDwee9omD+IYhxd6yZSqQTP0vIpepH/rm1Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890321; c=relaxed/simple; bh=IY6vqiFciP4mMPTkOSql/QQ1CRy1YoGj6RNfs9nuaio=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TTvu1X3HuQTZZJv0GLJtjAscoo+M/Y4kM8E3X87AMD8gUMWzhdTR7VNcDwUU59KaLjCCiPl/6e9vw0hGkwDeIhaOI0PC7JEAz8XwU/bjv3awfRi/ksTBq9uOioBbSw5KdQnXyMeUas2BJY/M+pG9uGR6u5/ZPFR+xXETrCZqb3Q= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AA643857BB6 Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5675lr7V002767; Mon, 7 Jul 2025 05:11:51 -0700 Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04on2048.outbound.protection.outlook.com [40.107.100.48]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pyb5hh5h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ex+XhpyePpR1IsL2gsoTDji9GOIqVCZeZ85TumTLFDt5g8rC5ConZNgU+8tsgqUI6nrz9elxzSX1dGUrBVYRs82ucao+qYmZuPPh63GgNQyP6YrXVtHcGzBqYzjia6IGGj+RH+EoNb3YGgP0ehWsoRXmbRIbedUk1rK3ndP1ne1nvzLT1SIifDm4nHtEXp9mHQu/lV0lV6cwgnaGnW/jZB0Oc0gbhfCRuOcLzyT5rqpseCrhcJzLa6GoHlPhIb62D2So1sERjnR9bSWuPGinllCocE60/GuNFi/1j4AndIS2NX2vJBjIHD1ApG5sOO7ud7otNXW0d2li8zp0ssegmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Edw3CsMoIqdoLkyPrQvl+9/SrJioAnpW6RwVFVw/UeQ=; b=T1PeurTnVZ0hgC+bq+MXb0wcSZtpBFQCAndOthf6pPxCYHaCSLSnSRxacnzGoOs8YdB3mZeYUXQY1naZWbQTO5opvUa1te7ouATgbKhEZCgKWxxH5OkYIQ2fBDI9ccGazU2K3J31nt8WUXwhoHNf6sqXQowRzCTxlAPkR/S3U0ud4Vqo+83UTN85ZbFllQSAQUkHlmPPNPtd57DVsuTBSMmQh+IzR0CXfrGJsyIFOH6ZMaSHQ69q75l21ZefQ3Oqnq52pfXJ6MPm08vIWH/u5AHaPe8dYpOYtJuxCraLQQrEVTYyo0LwM5LRXcyzoSsBXE5yp5kz2o6x9j4ZWAvfIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:48 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:48 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 08/10] [2.37] nptl: rename __condvar_quiesce_and_switch_g1 Date: Mon, 7 Jul 2025 05:11:03 -0700 Message-ID: <20250707121105.2226766-9-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d9a7591-e7ca-43ad-c1be-08ddbd4f72e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: jfQLKvBkKZWhMSdZhQsVahS/33VlJvnhKPFrUAB+/fMabTv2IRQaQup3UuKbAr+UErworJVRfoF3OwbmohYIXyRPg4XVAktyAqx/rZ6LPH5wnTpMYqHPl9mBgE3T6VCUbGBCjTe9WGxNRqktiA2k2QgofNPqOPG9o13mYyyl6OWBCY0mqdKWW0T1mAWdvEA9F21D3r+ZhhN+h3/tadiZhtE52bLmtDG93FLFy7UAY/1RWWzDmBiXoY1+0i/pcfr1XaIUeJdZt1xnUV8uwewg8xVko1jnpA/L9q5hRmAPUUE8/RMD7tmYfEdbEJvvYGDsR2H6KJXPEgQQjbwQJmpS9a1eLzfNhNyX5kj1D3x0UDFYZYRnLTdDH4LQtWBZ9+GfBOXW/OqBB8u1VTDyG+LhMVxXhj3QxR5ZVpEIuPHG8BfW43jcCoP0jB7KgbwQw7PRo406inDSCxMZlGejF+6kRA0+Mztim14B25943qBWsXsbYMgZ7qG0QcLFro0Lh9XThd+aG8/PguEpZFvyaWzxB9M/yG7p8H3NiKeVcCrwC04fSeCeDBAAEQqvnR+lmtHnLf3azDagSNZueyOQZTDSlfUw6wpX5HnJCOI28/PMF0C8sGvGkmdpgI88vE1exQlJ+4PykHHKn0OKGh+HVpP/OrGIuJ8kghx+mAhF0M1nULUS8Az2fDQQb1l2GM9PtrxXuA22fVE0qjGwXFVlUO2HUYbFJ/MmLh/C1+dDGH2lEzvIi+Syqi5zmzX//J9hrfCEgzXWtKtc1kp2Ije6OKuy4DmtvS63QjhNvoiH0A5urU2ID4sjA5lpc0tsQk4Qpq3vV+9cUQJ6vAw+dPrv1ehp6DTbst0exjrQkm1+aj9ncdKPnGgHNfTXX+5Q+oFtFiOTn8a2RGqjqDN5Fi71KzBGoxbuQuyLvcwi3g1JPrk8Bvbc5CKBQhUrSZ+f6nDODVAXtgbQEbTYQu9IuiCjRdx35jmV7uJn7Et40nrWODFbm1L/y+w+nZBMmklV+QYs9S0DadlFv8DuO9H1rgAYc0ZvambTZuu4vb8vs9qgkBfOk+gJ0isBZOg8e97dT3F9wYVpY/VgbInuqRbhDYY34o5Dzj6P4hg/+pdRbwIZDnlOZWqmcmn5WSPGzKkmnnrquvDXFzfeS09nIZ9M0AF6s13OuTxMy6jXpQn1YbmweFrNkE7czjVBk+Ztdf7d9VTpqoEpnclJs9X7q0QQBlIdXHtSGYodBL3wntfsZ4yYdyTZdKY4f/3ETFJXcH7F+IJtRCg3tLcmYs/DybFNYskJwWJ2FR1zhOCmDkteXWta7m8l22R9Ud+lPOrPXM2fLyijzFgrkL36aPz9l3jKUWOHxJJKwYgOStxMjxoYEMk/Utd/Tuo8jGQp1B6aJxRsVK9QmZydP2uZJJpxnAIL8yjnK30J+jT8w5ukLM/tuZtk1hd+m2NfNVDRPXjiIB7aTHVJV+B18NNt3o3+dXpF1iNfe36V0w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: veGoEOAj0W13S+mDvFCvzm1wT+ysbp9P1WTWiPsOJ3YV8rsihvneRXj26kjyTLCFR0+WlagV2vsbpX+GCajXcgkp7x5Apu8K+JDvSh41fgzQq10xkTJytlfYuhdM98WkQOD7HoRFpMUP/Oit+Yi0Caa9ThU7QA/PKfaepJUI7nh1GbEzQ1LtUQKc0hP2m2CukXTtjcpZm//vVvUugsOzxrqgkt08P7HNgAYheWWeFL6F87M4d9C0IWRnWqZpDUvkL0Yk/jd1zeSO48LhigEBfKepG5j1UIJvMdIjmPTwXn//bM92ud5o+tgxZw5BEqQbwFpchWSalOOqXcTsSQNZxc3Z7NoWNlkTSBSuzRX0QxzEmswZ5RYXrUJ0DyD0uBPdSM+CiHGZWwPtKH0nKa5FPqoBZLHGvI64op1HWO8xgrulk0QmAE34Y9xPntU2japlWHweWUg+C38lGWqDyPX0TgQHfZkumpWtIjf7varcZ3bGB5DkLkJUHjgPHam9a5nM5f/vphwIWQ6FvoAhhdG+9GgvpBO0smoAgZt/sK/AE4AyqwBsPGSyaTcuGjYwOYRXcHN1bFxepIyLLMSs53MAnNlEkXRb54WuA0LQx23OUbgUxKWmzjGh8hQ49dR2VNy1itTpwHjvxBCgHtDOXBdWH3YufYJwdq6F4pHklFy0dpQnBLhVcYbhjKGLH/PkKR5drSPrVab3X+Glytk3ovWGrLoqQAwqwxEMkbVkUULL/8nHbl19+wtcIuz4+4gHfF9u9mM79EUI5YmzdkStwFA66+lsXJSZr6bM88xumjD2TqGoLXrJ9h6ATiNBOraBYVIU7XTrUdYUN9pq213W7klFgUi90vTA8lXdxGw5NAh1325QcADLuXMKP4GQ9EZvMZ5NE8u9lOC3oQKtc/MtgDllZ12h2mAsY4CWlZ+oIPXbFGMObMlUSeizZnUvikUrtDKQefU7jKIA+1tFIJcFPUgTEI8mueV0JKGHKnmfWaxBGwRYEVPofWZHebZhuUxq4ESVcONLfzhrMqlKp/n089pw9b9qOMQrjryCGf4Sg7P3w6fQNZEe6M8wEEJpqadRh+qtzFbfvky9NsSkZIiXQG4h8bZzmXAqfHw0MDtM5dHC6bW9Xwtsqbb/yVuX/UlLUojeVFouKjfC6DNPKSGmMVm0BTmyzf89zRBfX6lSLBmj7sgR2dUAnZ4R102wOaVBp8UdP0jz0FSo1+kNxJ23j9mYptN3//Div8YljgP+0Dt2pzBzdxdRMICT9QbO2qx3UR59XDooh3b6ikjPVD5oJf6+9mBQCkUXUoOQ6NffQVKyMMai3cUHePIF3YSYIh92WuZIBgSsMIXbMUG8TIa151SY7HemUCv1CKbK4QbeHRKhSqkBKPRjLPePWa4ibIzVhdPt2SNdCdmMJDPLUuUEOQJObp/ESxAVacJ1CxIeJfaHj7OXzAIq4bKVdvM6eXseuq+YkrjophMjY5E7lSwpVMwOdkoYVMKvWmr93GESgGFIwNcst38qqp/f1csHF6079jYgCjO7XOp9UhtFP/f5e6hT9pVQVwhVbShOqgoK2kuO+uCbXM4l79MPqGI7ToxCkHh1VmGV6axtDledtVaI8mOq2g== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d9a7591-e7ca-43ad-c1be-08ddbd4f72e7 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:48.6283 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eg9ADIGDNhASzfOZQ8BrNoAT559G0UVQNoyjj1LbffPJ0vJCz8SXxGvRfT+7d0qDtPTSzZRm7G3Obb2PCGbLnHbmluBD+olgTqk21cFCub8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfXxn4djx+0Df3e 7e/4cFs/w3grN16JVLaWG80Lx1szxVvzXsnnwpKFnzL+QU9ouoYltVOW18V+P7pRIyCItQR4+6i 7WIpk0x0REadyEfev/iuWiFCQHcwmKLIDPuXBmj51sWO67pmNL9lthhAnkMsCQJ9nCpemSNSPFD P6GrRCqi8ZnxVIiYkHwCMOMZvlW0L00Uox+rjH5cVlGibAt+o/dlwUiy/XBQDWPXYlB0rYwOM7O FBRY0t7/KKDuxGPgkr09o2YMFtIcGCj3kUoF3t2dVy3KDv86oX+I55jypeDG2wrce2OJTMnCIEO TIaASQ7NlcGKj2yfKyrL1GUXYaEUh//Z4626GHnCGvYRj5EjL+WjwAIxZhXhni9pGge8mtCVVTa D8WSP+XxQbzBeN7DaeoMhsUy3WyTNev4BvlLJh8uoMekA3j3jqwHWBNxaYMnS7+Is+LRsTNt X-Authority-Analysis: v=2.4 cv=V5590fni c=1 sm=1 tr=0 ts=686bb986 cx=c_pps a=IGreAyPUPBSHjVw7E5NCrg==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=VAQzXz6LwKCCr4k1AfUA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: FP4UeQuVkAXBgO0qBRs5TlCkmam4SrZs X-Proofpoint-GUID: FP4UeQuVkAXBgO0qBRs5TlCkmam4SrZs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] This function no longer waits for threads to leave g1, so rename it to __condvar_switch_g1 Signed-off-by: Sunil Dora (cherry picked from commit 4b79e27a5073c02f6bff9aa8f4791230a0ab1867) --- nptl/pthread_cond_broadcast.c | 4 ++-- nptl/pthread_cond_common.c | 26 ++++++++++++-------------- nptl/pthread_cond_signal.c | 17 ++++++++--------- nptl/pthread_cond_wait.c | 9 ++++----- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/nptl/pthread_cond_broadcast.c b/nptl/pthread_cond_broadcast.c index 7409958394..f77198f4b1 100644 --- a/nptl/pthread_cond_broadcast.c +++ b/nptl/pthread_cond_broadcast.c @@ -60,7 +60,7 @@ ___pthread_cond_broadcast (pthread_cond_t *cond) cond->__data.__g_size[g1] << 1); cond->__data.__g_size[g1] = 0; - /* We need to wake G1 waiters before we quiesce G1 below. */ + /* We need to wake G1 waiters before we switch G1 below. */ /* TODO Only set it if there are indeed futex waiters. We could also try to move this out of the critical section in cases when G2 is empty (and we don't need to quiesce). */ @@ -69,7 +69,7 @@ ___pthread_cond_broadcast (pthread_cond_t *cond) /* G1 is complete. Step (2) is next unless there are no waiters in G2, in which case we can stop. */ - if (__condvar_quiesce_and_switch_g1 (cond, wseq, &g1, private)) + if (__condvar_switch_g1 (cond, wseq, &g1, private)) { /* Step (3): Send signals to all waiters in the old G2 / new G1. */ atomic_fetch_add_relaxed (cond->__data.__g_signals + g1, diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index 1c43432bc5..64531e809f 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -189,16 +189,15 @@ __condvar_get_private (int flags) return FUTEX_SHARED; } -/* This closes G1 (whose index is in G1INDEX), waits for all futex waiters to - leave G1, converts G1 into a fresh G2, and then switches group roles so that - the former G2 becomes the new G1 ending at the current __wseq value when we - eventually make the switch (WSEQ is just an observation of __wseq by the - signaler). +/* This closes G1 (whose index is in G1INDEX), converts G1 into a fresh G2, + and then switches group roles so that the former G2 becomes the new G1 + ending at the current __wseq value when we eventually make the switch + (WSEQ is just an observation of __wseq by the signaler). If G2 is empty, it will not switch groups because then it would create an empty G1 which would require switching groups again on the next signal. Returns false iff groups were not switched because G2 was empty. */ static bool __attribute__ ((unused)) -__condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, +__condvar_switch_g1 (pthread_cond_t *cond, uint64_t wseq, unsigned int *g1index, int private) { unsigned int g1 = *g1index; @@ -214,8 +213,7 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, + cond->__data.__g_size[g1 ^ 1]) == 0) return false; - /* Now try to close and quiesce G1. We have to consider the following kinds - of waiters: + /* We have to consider the following kinds of waiters: * Waiters from less recent groups than G1 are not affected because nothing will change for them apart from __g1_start getting larger. * New waiters arriving concurrently with the group switching will all go @@ -223,12 +221,12 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq, are not affected. * Waiters in G1 have already received a signal and been woken. */ - /* Update __g1_start, which finishes closing this group. The value we add - will never be negative because old_orig_size can only be zero when we - switch groups the first time after a condvar was initialized, in which - case G1 will be at index 1 and we will add a value of 1. - Relaxed MO is fine because the change comes with no additional - constraints that others would have to observe. */ + /* Update __g1_start, which closes this group. The value we add will never + be negative because old_orig_size can only be zero when we switch groups + the first time after a condvar was initialized, in which case G1 will be + at index 1 and we will add a value of 1. Relaxed MO is fine because the + change comes with no additional constraints that others would have to + observe. */ __condvar_add_g1_start_relaxed (cond, (old_orig_size << 1) + (g1 == 1 ? 1 : - 1)); diff --git a/nptl/pthread_cond_signal.c b/nptl/pthread_cond_signal.c index 9ac4bd9f75..97316b2579 100644 --- a/nptl/pthread_cond_signal.c +++ b/nptl/pthread_cond_signal.c @@ -69,18 +69,17 @@ ___pthread_cond_signal (pthread_cond_t *cond) bool do_futex_wake = false; /* If G1 is still receiving signals, we put the signal there. If not, we - check if G2 has waiters, and if so, quiesce and switch G1 to the former - G2; if this results in a new G1 with waiters (G2 might have cancellations - already, see __condvar_quiesce_and_switch_g1), we put the signal in the - new G1. */ + check if G2 has waiters, and if so, switch G1 to the former G2; if this + results in a new G1 with waiters (G2 might have cancellations already, + see __condvar_switch_g1), we put the signal in the new G1. */ if ((cond->__data.__g_size[g1] != 0) - || __condvar_quiesce_and_switch_g1 (cond, wseq, &g1, private)) + || __condvar_switch_g1 (cond, wseq, &g1, private)) { /* Add a signal. Relaxed MO is fine because signaling does not need to - establish a happens-before relation (see above). We do not mask the - release-MO store when initializing a group in - __condvar_quiesce_and_switch_g1 because we use an atomic - read-modify-write and thus extend that store's release sequence. */ + establish a happens-before relation (see above). We do not mask the + release-MO store when initializing a group in __condvar_switch_g1 + because we use an atomic read-modify-write and thus extend that + store's release sequence. */ atomic_fetch_add_relaxed (cond->__data.__g_signals + g1, 2); cond->__data.__g_size[g1]--; /* TODO Only set it if there are indeed futex waiters. */ diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 1d61441dcd..0beafce4ed 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -354,8 +354,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, because we do not need to establish any happens-before relation with signalers (see __pthread_cond_signal); modification order alone establishes a total order of waiters/signals. We do need acquire MO - to synchronize with group reinitialization in - __condvar_quiesce_and_switch_g1. */ + to synchronize with group reinitialization in __condvar_switch_g1. */ uint64_t wseq = __condvar_fetch_add_wseq_acquire (cond, 2); /* Find our group's index. We always go into what was G2 when we acquired our position. */ @@ -386,9 +385,9 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, { /* Now wait until a signal is available in our group or it is closed. Acquire MO so that if we observe (signals == lowseq) after group - switching in __condvar_quiesce_and_switch_g1, we synchronize with that - store and will see the prior update of __g1_start done while switching - groups too. */ + switching in __condvar_switch_g1, we synchronize with that store and + will see the prior update of __g1_start done while switching groups + too. */ unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; From patchwork Mon Jul 7 12:11:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115752 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 3BE653857BA3 for ; Mon, 7 Jul 2025 12:16:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BE653857BA3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by sourceware.org (Postfix) with ESMTPS id E156C385843D for ; Mon, 7 Jul 2025 12:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E156C385843D Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E156C385843D Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.166.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890322; cv=pass; b=Xo4ady0CaasG/78nOFhkqJtGE6cXfQ5ZO5rm2sOi0ZoB1gr1cd6s7x3uklsjBbtBMTF5/2cYY0mEjP7ncvnfHnPcTthRuAy98/uDf2yP4klQTxV/Hs031mHJJR07Xf7TUAfMzc+XcGwrw7aKYkr09bneB1rrQ07//UbEgC0liYc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890322; c=relaxed/simple; bh=hb0sHcenzrVI+B40c6BVvgpjk4nYnWSzme76ox/Ez6s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=N0xWTBDKL3SgHlohp+/i/MOZ1ljT0SJwLohFdTYronLKO1nTtR0nhL79qm/uJRUsgrUd88DqbiY3S0P9KIp2knM18OcxPhRJbykTtkFejbMMuX5UrCXI6L5JtgQ9o4R5ExB0HXwMU+9EzN5AI3e3H9SEWVsKynWYiYbhV+I2EnE= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E156C385843D Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 567B8E92025195; Mon, 7 Jul 2025 05:11:53 -0700 Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10on2082.outbound.protection.outlook.com [40.107.93.82]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pyb5hh5j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 05:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XmpM9wHCKdCG7V4+gnYa+Lbwbs45I5cR/hrqWOy6DxhGpniQ0CZQMM+YgtxkG4zMk9xW2PVbXweNVQepcmynM3v94YpSWVNmOhpyOPVAF/6hEE+Lz3a628S+FOJPLc1Qu57RRBDWe0G5foKJ9bkXpRzL86luSzNx4Nm1ZJrfYUbWBZdXzeSTdiEpVm6cFwZGRdgBG17dXgpaVq5d5WdikUnpUrUAZgVUN3eapRQHZ2DVIcpwAxQxYFh1bRXcnR81y5zBGxzmiql71+vzpYGA6kCOPQkuhcu/Ppb7N/oWz+hVeaELTa3t+sIuthFeTT8/N2grDMrq5jHu70iPLUY3Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Y1TeGPksYd+zAgySIi9zRfHSSzCvmN0jgmP/hXOy40s=; b=t49/coIofIr0q8IjmNXh+nBNMtmIpB7lm4tV68SJUWwOrAOOilg6PqDAmQNg8Z2W7KVotbDroHj9+UknNEieohzorHpR8DYD9Iuc0QzW7dxxa9qjj/tbMvXGxaO2B+60KIg/Ws8X4O/0mc55Uw9hKo5xaglmDJ60bauo3QXM25FrJWAsOIl9zF5oI6EyDnUSvNG2kN/DC30UkGkia8UI2RisSbAOScWfS63Dy3G+EVSUP4rBjUQASUepxHZj8FOqHADLyIqDb+vWtc9/d9TPW4ue6oM4p1VYaJG9ogfG5jXu4t1RIK5SVdIX7rbn2oV6S0CMSLd8Z+FXd+j4kl8McA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:51 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:51 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 09/10] [2.37] nptl: Use all of g1_start and g_signals Date: Mon, 7 Jul 2025 05:11:04 -0700 Message-ID: <20250707121105.2226766-10-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: e1b192d1-e135-4361-eca6-08ddbd4f7486 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: Fsjnr5qDt17dN0HZEIS7lS+96m8OkXmgidKX7/nybsEUb8MA5upWEqYGwS4KQuegHs1aAQWo1j1EDr9BUYQ/Z76r+ivu84Iywp8Fj12KimwM6I5vsdCWLLUjBaibHEfWx/UYdkFQYo88sQVFKzNHRKoUXyIyMM/muU3ntfwwYZ9n/xBTIJSuXLBmd393yqzyN2hbL0PEkGLAhMYBv0VD1eIr3JnYiOtHy1WJ3boUMAKyirWRixKtSVxRkmzp0e5NW7Oj/7m8PY4ajupqi2DurpcEYliYLBHer91Nr7YzcS007svX8AMGfoUEYYnoi8fukVxctLm4PrSgS2CtlL88d87L5ZEE8Cc5527EmML1Ny6z2mFEkybpk/EE7MsIVxMG0EhC9Ampe5fl4Dg4iaaf76Azx7PtYpr9LDDLjdIlQsOPMuvxUignOKMAdcE/zHk8gXq1pjbaeyaANVskFBGuve1AvIer0W/atbRW6y1CmqI4c9y49b1V16OsHRVniO2pV9iwUKBYjzo6+PXH45P2chx0uUsOeAEQ+vhVbqgyjN5y6naDqhKRdeK4myj4o1/oI6M1tOXoNMsIz6VE9i8kN5Y2uwT7qBR/eYMV3u7g7K0DSEG88kgrldar3JFLMXHPslakxYym8twD9J2DKwQ7rwbFD56TFLynj51Vlxr8Fho/kRzg42+KynZXJ5Fr9rFYUHlnWAO7GVAX+CZzlbhcfD/G85Y+WhyiX0lcFkYF/RjH2tVabHAb54l9OcSoPkUtx/ElZhN/D5o1N4SRkXuAiI5PuflGy1AUn77Pi7VUOh/H1gEB0PW7Uu4RvC4zujrWbRzqsQlwbWI9IJh1FyGAxRPvw7jURGu52B7UPFFD7t8uHHtVpc82Ug9JgVh/a6NLedbLbsyunBvfDl5EmRGQjFRHtkV4bfm+L5mtxouDlRn3jV7NmaBTOKCTO7t1jhev+GbPyvNLxmZ3us/y2sXcONq1pJG2EBfvN4RhAmF2EtXGqYsvtaSuVyac+Q0aZcC46vt1eqEJrXHjb4epZWdP4IiO33ke3KmQbHcLBKg1FIM7Q5J8f9Wlj/TzTvOu7ay3Eu2r1HFqz47dcQXB5LWlwl+ktZ6g7pJcpWmMOvybPW+ZdpiVfQ07tJc4aJo41Fb6bePoru/YYhwc271l04xEF5yO29mFve32Q8Y/UKucRji5tQ9nYr7i/XMUGyk2feAzHuQvgs5pDVZhGD8CPEPIXYs1DBwYASs4t40umCIJzAlSw821tmWPWxcUfuNgSexlfbdIVOh31P+5pjBLGNyy2oeeAXV9Rt9rnZvdpfpi/9XPhSVHC/GeFOde1CbXdp4SSYZhy9eY4WvY+WhONLlbmeX+bRHZ/wJh4UyXoftUX8//mh9ktBMLdr3xRA8HKN+1ALmEdtWhR0cb+E5D2RyUzkU/HIDS2ekQInOfV0DigC7Tgd24mzicOOdLJVq9fQsJrzW33BKtaXYEh2OO7qwlkg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cQB6EzT+sbXCaeRXijl3nQ0ZAqWB/p3tYDNUqEMVQR6RuJfeXfwo8BdjM3b6/Znvzl85O+dV71+6GXqkKpatghjT/niItAAmsSYZcLwFWktHq4tDBtieG7IjvckPhSRSNutJEoabSuPzj+vTxPe9Uq3TXXlXXtIzHKB+O2Ahg8My5mqGCa4CSCRJEiZmrzF/Xg2vEsnl6lAC0nu/yKk7jNRhzIos19wplzjrOZeBhP6GMUOM85hunGbICEK1EFLDGCAAEIUX0QteP6oIUxh0KYVoU15vRNY5UTuUuwxZOGtGVduNY9YWBxpTo6xXRGJmw3MiK7jVJ6VdXQzzaQH0RRuw4uXmDdAz6F42ou9g4xLHlxZIiN4MO6ZXYr+/rWmaqUeIgBB9Gc1J6aLr9i7Kgt8LmUgS8SmoeHcB8N8gmtyyoyaRPkWtjmhKcskNYGCorkibEupAtxN9uBZLGsRvxUgvNIeCp86qQ/SXE8q7MfCJklEB33TJXIJoe8SoJfHHDTLSyEonL0Y64JpTrJsp+buWo1nMP1g/fWofwf2NJ16m7LD163VXBeymfhIvXDylL1RKDO7LxylqnjYO/6jnXvdrOzwD2LYgvVZRJtINrGDIgKzurccWweLtCf625LWbZMi9kwz2yV/YVKvA4TSvbQQEjknRtzhikLGVqeHpA2U1IUUiMf/He1mAk9wpJR6QrA9wa/+WRGlX8vOHz01aiZP/AGzNkum3N7WIu7d1ZfFLvU/E1Xz3bEpDQTs38vXvZtrmIEv4uJ29+QXATPc0Jc5l6aJuv7FnbN9Q6z98s4zYGe3AXFi67cQUG0M3Z89xz8gnAlq1Lo8klbVGS6J5MmMmeQcwmeYMVy3qLb8DmZS1w3ebVg4ULEuYOC/ZUIZkiLCLMHevrKi8a/Pw8EBG2Ce04gvi6F9NZYb7IJqt/G6uS6reiZSZWtBzb2pi1W0aDtt9dhfCP3vyvwhxuemmnA2kNfKjG+xTWtJ3u6hJNNUlZUB61hhogONIQ15gl6mt2eIlRIhYc4UaiFJdI1Ldwz3KKCmwAFTLTsEfLWan3nRx08mfQqBaKkZmj+p+7UwI8s7KhKQGnRBQJks+sgcP4Vf4iYG6NHriLDG6a5h8HXCGPP0L8Sgi34ov0AVLY6FwuB3iRmrI1oEgEtKkReQiM4AVQO28RTGicnDoEbnbVQJTXgtEu7Kb5XXceJbcoMxmSuQNCqlUDLCgf8dfi37v1FqCGykD7BxHBYc7/taXjxhZn/vuJeocalJxzORlG/9AvSQVwTvj/xoCjbM0xDfY+IzDptnjcqgFFuAIMhmIfyxDi4KDwPqcoE9+RRvll6/82BEy0mmR8xrx7bZRhXCtFJSpVd1o6UEiFPFY19mDp9TICCuyTz30RLXSyz8Ui2k+x4L5jXSAdjS0Hotyt5mGZvvTw6ULL7+rIErYq9Nkw2srV1++ekRkPpZd5x33KeW00AyKCpe9GijHLhlwIgV0ULMyUDxXgLu5FxDZO77XzyYW6Nzd9yPoVRn8Per3mWnw1wFvv1nN6j2J33TY/kJWUcVCifIZM4ks30ALjQfMi3FHeHVUj0FgP1x7ahJbamegyfgc6LQ4GoS2YXkdl8H8ow== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1b192d1-e135-4361-eca6-08ddbd4f7486 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:51.3373 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LgNuYfPli6FOEDORuEmZH2PCrU5Ch9pBwm0JWSM2iBpmgE7I/RQrjSLNiyQqwox3c0xmHgQRKm7xVJoxtqJ/+avTmIpHU2gaj5JN3W7Yv8Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX2v97WCuyBIpu WB+YrtMpYLrUBov6sxpxlmzyJNLTktz8snsxsCHHqcaiqD/DgcU00jeyCz+JwCHbzclk95qsNq2 izID3KDYnUJajWAC8uBwwcY6m6y0zfcP0Mf5iPuVBoseqsSE1FFBsufMuGPaLzM70gcKKL2Mlnk /4vsbTa9d1ZgdH4tl68xmPva+Ojh17TB28/nYNHvDg339gQDKY+Gd7NqQZxZsl6HRAq12BKtrCd Vv1j929PCquwdrSTwNLezPuaVPSgDKWqfXejVe+OZQgIbHgLbiKmcdfSBCsOLRSK1BYqWQwNKNa 6gWc/BVzUvm7k4mJhKPscMa3joI67uK/z0WdKiGH7CLKoEWd5znbgQsEeu/1gIWO3EYuk8viflJ RsgNJe05rczP+FVRIRbnir40RPgTiz7ZeUyH/ArHUh87xXsQN3xanRuuqkdw8EoZIi6lmhs5 X-Authority-Analysis: v=2.4 cv=V5590fni c=1 sm=1 tr=0 ts=686bb989 cx=c_pps a=M73KnBbWnWmIkrHh8bhXvA==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=t7CeM3EgAAAA:8 a=irFmdI_V5gXsOLP1DOAA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-ORIG-GUID: VyZCXooKHGyLBP2E2RYVHod1ao_BsA1G X-Proofpoint-GUID: VyZCXooKHGyLBP2E2RYVHod1ao_BsA1G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 spamscore=0 priorityscore=1501 clxscore=1011 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=927 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Malte Skarupke [BZ #25847] The LSB of g_signals was unused. The LSB of g1_start was used to indicate which group is G2. This was used to always go to sleep in pthread_cond_wait if a waiter is in G2. A comment earlier in the file says that this is not correct to do: "Waiters cannot determine whether they are currently in G2 or G1 -- but they do not have to because all they are interested in is whether there are available signals" I either would have had to update the comment, or get rid of the check. I chose to get rid of the check. In fact I don't quite know why it was there. There will never be available signals for group G2, so we didn't need the special case. Even if there were, this would just be a spurious wake. This might have caught some cases where the count has wrapped around, but it wouldn't reliably do that, (and even if it did, why would you want to force a sleep in that case?) and we don't support that many concurrent waiters anyway. Getting rid of it allows us to use one more bit, making us more robust to wraparound. Signed-off-by: Sunil Dora (cherry picked from commit 91bb902f58264a2fd50fbce8f39a9a290dd23706) --- nptl/pthread_cond_broadcast.c | 4 ++-- nptl/pthread_cond_common.c | 26 ++++++++++---------------- nptl/pthread_cond_signal.c | 2 +- nptl/pthread_cond_wait.c | 14 +++++--------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/nptl/pthread_cond_broadcast.c b/nptl/pthread_cond_broadcast.c index f77198f4b1..f5793e715f 100644 --- a/nptl/pthread_cond_broadcast.c +++ b/nptl/pthread_cond_broadcast.c @@ -57,7 +57,7 @@ ___pthread_cond_broadcast (pthread_cond_t *cond) { /* Add as many signals as the remaining size of the group. */ atomic_fetch_add_relaxed (cond->__data.__g_signals + g1, - cond->__data.__g_size[g1] << 1); + cond->__data.__g_size[g1]); cond->__data.__g_size[g1] = 0; /* We need to wake G1 waiters before we switch G1 below. */ @@ -73,7 +73,7 @@ ___pthread_cond_broadcast (pthread_cond_t *cond) { /* Step (3): Send signals to all waiters in the old G2 / new G1. */ atomic_fetch_add_relaxed (cond->__data.__g_signals + g1, - cond->__data.__g_size[g1] << 1); + cond->__data.__g_size[g1]); cond->__data.__g_size[g1] = 0; /* TODO Only set it if there are indeed futex waiters. */ do_futex_wake = true; diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index 64531e809f..99640968f1 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -208,9 +208,9 @@ __condvar_switch_g1 (pthread_cond_t *cond, uint64_t wseq, behavior. Note that this works correctly for a zero-initialized condvar too. */ unsigned int old_orig_size = __condvar_get_orig_size (cond); - uint64_t old_g1_start = __condvar_load_g1_start_relaxed (cond) >> 1; - if (((unsigned) (wseq - old_g1_start - old_orig_size) - + cond->__data.__g_size[g1 ^ 1]) == 0) + uint64_t old_g1_start = __condvar_load_g1_start_relaxed (cond); + uint64_t new_g1_start = old_g1_start + old_orig_size; + if (((unsigned) (wseq - new_g1_start) + cond->__data.__g_size[g1 ^ 1]) == 0) return false; /* We have to consider the following kinds of waiters: @@ -221,16 +221,10 @@ __condvar_switch_g1 (pthread_cond_t *cond, uint64_t wseq, are not affected. * Waiters in G1 have already received a signal and been woken. */ - /* Update __g1_start, which closes this group. The value we add will never - be negative because old_orig_size can only be zero when we switch groups - the first time after a condvar was initialized, in which case G1 will be - at index 1 and we will add a value of 1. Relaxed MO is fine because the - change comes with no additional constraints that others would have to - observe. */ - __condvar_add_g1_start_relaxed (cond, - (old_orig_size << 1) + (g1 == 1 ? 1 : - 1)); - - unsigned int lowseq = ((old_g1_start + old_orig_size) << 1) & ~1U; + /* Update __g1_start, which closes this group. Relaxed MO is fine because + the change comes with no additional constraints that others would have + to observe. */ + __condvar_add_g1_start_relaxed (cond, old_orig_size); /* At this point, the old G1 is now a valid new G2 (but not in use yet). No old waiter can neither grab a signal nor acquire a reference without @@ -242,13 +236,13 @@ __condvar_switch_g1 (pthread_cond_t *cond, uint64_t wseq, g1 ^= 1; *g1index ^= 1; - /* Now advance the new G1 g_signals to the new lowseq, giving it + /* Now advance the new G1 g_signals to the new g1_start, giving it an effective signal count of 0 to start. */ - atomic_store_release (cond->__data.__g_signals + g1, lowseq); + atomic_store_release (cond->__data.__g_signals + g1, (unsigned)new_g1_start); /* These values are just observed by signalers, and thus protected by the lock. */ - unsigned int orig_size = wseq - (old_g1_start + old_orig_size); + unsigned int orig_size = wseq - new_g1_start; __condvar_set_orig_size (cond, orig_size); /* Use and addition to not loose track of cancellations in what was previously G2. */ diff --git a/nptl/pthread_cond_signal.c b/nptl/pthread_cond_signal.c index 97316b2579..bdc1e82466 100644 --- a/nptl/pthread_cond_signal.c +++ b/nptl/pthread_cond_signal.c @@ -80,7 +80,7 @@ ___pthread_cond_signal (pthread_cond_t *cond) release-MO store when initializing a group in __condvar_switch_g1 because we use an atomic read-modify-write and thus extend that store's release sequence. */ - atomic_fetch_add_relaxed (cond->__data.__g_signals + g1, 2); + atomic_fetch_add_relaxed (cond->__data.__g_signals + g1, 1); cond->__data.__g_size[g1]--; /* TODO Only set it if there are indeed futex waiters. */ do_futex_wake = true; diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 0beafce4ed..d42cc1c650 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -84,7 +84,7 @@ __condvar_cancel_waiting (pthread_cond_t *cond, uint64_t seq, unsigned int g, not hold a reference on the group. */ __condvar_acquire_lock (cond, private); - uint64_t g1_start = __condvar_load_g1_start_relaxed (cond) >> 1; + uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); if (g1_start > seq) { /* Our group is closed, so someone provided enough signals for it. @@ -259,7 +259,6 @@ __condvar_cleanup_waiting (void *arg) * Waiters fetch-add while having acquire the mutex associated with the condvar. Signalers load it and fetch-xor it concurrently. __g1_start: Starting position of G1 (inclusive) - * LSB is index of current G2. * Modified by signalers while having acquired the condvar-internal lock and observed concurrently by waiters. __g1_orig_size: Initial size of G1 @@ -280,11 +279,9 @@ __condvar_cleanup_waiting (void *arg) * Reference count used by waiters concurrently with signalers that have acquired the condvar-internal lock. __g_signals: The number of signals that can still be consumed, relative to - the current g1_start. (i.e. bits 31 to 1 of __g_signals are bits - 31 to 1 of g1_start with the signal count added) + the current g1_start. (i.e. g1_start with the signal count added) * Used as a futex word by waiters. Used concurrently by waiters and signalers. - * LSB is currently reserved and 0. __g_size: Waiters remaining in this group (i.e., which have not been signaled yet. * Accessed by signalers and waiters that cancel waiting (both do so only @@ -390,9 +387,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, too. */ unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; - if (seq < (g1_start >> 1)) + if (seq < g1_start) { /* If the group is closed already, then this waiter originally had enough extra signals to @@ -405,13 +401,13 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, by now, perhaps in the process of switching back to an older G2, but in either case we're allowed to consume the available signal and should not block anymore. */ - if ((int)(signals - lowseq) >= 2) + if ((int)(signals - (unsigned int)g1_start) > 0) { /* Try to grab a signal. See above for MO. (if we do another loop iteration we need to see the correct value of g1_start) */ if (atomic_compare_exchange_weak_acquire ( cond->__data.__g_signals + g, - &signals, signals - 2)) + &signals, signals - 1)) break; else continue; From patchwork Mon Jul 7 12:11:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dora, Sunil Kumar" X-Patchwork-Id: 115750 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 DAF81385AC0A for ; Mon, 7 Jul 2025 12:15:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAF81385AC0A X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by sourceware.org (Postfix) with ESMTPS id 24C423857B91 for ; Mon, 7 Jul 2025 12:12:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24C423857B91 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=windriver.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 24C423857B91 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.178.238 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890322; cv=pass; b=Zv+26AOUMSjqqIbEr+vJ6UqqKOFp1QB1OLyGkle3FYeM6REldQlTZ9TAu4Sh8Zrh++AdKyDh01RwT7FYZXxN0cC4Mls/2wK3MTZ0p7Ym09JtlR4p56Blp3VZ3PziyPd9RCqoicrL5nWEiJfjZEHmH4Bs25q7b32WVA3ZH1bEpRE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1751890322; c=relaxed/simple; bh=6J5nXQCEtMPTTWCs2gXs3dktzGat7BeYS6W+bAAGNzc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=U68mVRBN+yA4korCGakoVIlT0dnev/WRMAylbwVziXb3vVkiZ5Mlupo8cuA9EKnYVE62Zd8bVBOVm6zOQ6skTniURtyCUjRf0EGxbAH7djVu4ORZzGAM80bnRgGl4yX+Gd5JZwQkW52McCtIXC3wEPb8/HCkVMR5pS+ltX+oe9s= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24C423857B91 Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5674KD0J000662; Mon, 7 Jul 2025 12:11:56 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04on2067.outbound.protection.outlook.com [40.107.100.67]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 47pu19hkd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Jul 2025 12:11:55 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qa+p6u+Zcu3fwY0lQEdXVOOVFzc6xjTqR1LlX507kgtenaLaCM01x802XMahResh+hU3J5BLzUxut4NASQCY5KC100kPyKdtNzpZ9upEHZgZoK+3EcUPW9/ASJsMUvcjqvjws203bI3vJ2PFfIY0nvfp23i//Ftz6RvfI/2nrY6j5DPLjQmcBrdvLzkoMTJ/rwp96bgu2LPHnXKjLG+y+6s46kDiKx+QKjU4LvS0/DHRYY/I5V4mnblbd2dDDUHA7Bs+2w5Z5Y4GgBK72VT2gkS1A+NzVQE9H74uelcqHsKIv0h3IEH3MFJztXS0G78NDeXDAzLGJuniV+gJdfXnLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=LOULSW7TlGdRnfgOfszsX6+m1SwBvKD1zrQ2Av6Ss+U=; b=xY05RXsXLkgW/CFtZ93nidx/GEA6CawZwAz2bwvZHt86aLN/j/35A7yPQu89Xqdes97xWPQuJdWzRwRObhKWfziUbekrIFFUV4C2/g0nXA1lssSPUW5tnd3K7gJ0PnGw03Pfpg8bbLyNWqNghP4n3vBkeCMPfErccCfH/LqMPqUO/xyenwqatXsC590ErwVJ63z7O9ifRffVP2Qei711BTZcl//IJXVPrwYpCicODmQByr7zQLQXpICBQQFwB7j1nrr/PkoUNUSmDG6FswrnfD5njQvPkX19svb7JsmCNLN3OKcycjG9TZ8xW9HkyGSamrya73pzMilrp8L5UihvfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Received: from DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) by PH0PR11MB5126.namprd11.prod.outlook.com (2603:10b6:510:3a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8901.24; Mon, 7 Jul 2025 12:11:54 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%4]) with mapi id 15.20.8901.023; Mon, 7 Jul 2025 12:11:54 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: carlos@redhat.com, SunilKumar.Dora@windriver.com, Sundeep.Kokkonda@windriver.com, fweimer@redhat.com, frankbarrus_sw@shaggy.cc, malteskarupke@fastmail.fm Subject: [PATCH 10/10] [2.37] nptl: PTHREAD_COND_INITIALIZER compatibility with pre-2.41 versions (bug 32786) Date: Mon, 7 Jul 2025 05:11:05 -0700 Message-ID: <20250707121105.2226766-11-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> References: <20250707121105.2226766-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: TYAPR01CA0135.jpnprd01.prod.outlook.com (2603:1096:404:2d::27) To DS0PR11MB7901.namprd11.prod.outlook.com (2603:10b6:8:f4::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7901:EE_|PH0PR11MB5126:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a195408-2d78-4bce-8570-08ddbd4f7628 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: 6deXH6iNotTSTD8fpiQ20TE1BoW1SxCq//V9Z2g5ocz/mJ0cT5OoLjoqA8tV8tjQyqqXNvdVxjP1599pPTykHMuw21BJowMbYKic6hsNfA+kfa1RxszcdNfPoT3HVpMvZVDaW3A6lSDkeYbz9XSTDt4cWppraqCbjo6aZiPfTx/1Q0WGy5CSyCULkBDfRULuf6wXXUSTnHyqGG5Wa6NjfwW5eKoHLepVKAspepu4/efT725h/aVcp0sVVxV+gW6VX/VhMvZdNTO5VSZYYcRdrS94UfITMmda65JStyJy/t04u8sBXmXBsYge1T96X5ax0Wu6zszRqzutwWSxuVuFCAaKAjExw11lcuD0BedtPqayZwnPHsfnjqheuaJeft8fOp72Xzuu8PGoiUUToFge4Xbzya3PyOm3psxQ28VYRl6veVokL9z4on054TtWPQrX+XQP3C0TG8sR9rgD7VjsFBH8kRtI5ok0jBZYmW9bWDgoirUBdPO8xeD5i/tZR/1H7v5V6cfw5UkPQgaQZpcGbc+cBA5BOxIbVPpL3DzzZ1BDatNFtWcSb3eMWrndvT9+anYDWg7nvUi80uFovqxbdVA1c46D9elbi8TwXiXafanqcARwymZLKgkZ/H/PQPxq9ZJ/GgNB4iNFcflC5hvnpS3KIZY+jdOk0Sgtg8c0EbRt4+fS0FJg0s+j9TC8krBwtkEFrOpIoTESjvOtQuT+NpiFxbTm62EduKfR+y/c8YAuoL7p3vuYPJl30bxYZTtkfqeMFIZq5+PW8N3aOy4KyERYYqLkD+E+OO6MA7gJzF+w5cKZrpIriRQKrGUISk05Wvdy5anhAw9Fa6yKSY90PYdB4umOExAkqK3v5INbfFhZrzFLfazDUqX01hb5MOVzupBjNlKSzRH3ykOng21XoW1GWcPh3jwq+cwDCDHE/xwtT8CkDhwR/5KTv1zVLN4a38PDL/oQdqOmh9AUuv5im+ECN3VRpLYd3nyWwRs7WGQAUMoADgArXP7OYvUsP2bnzaEoDbdHGEK445uqVviiLWwCN27+lj2fjlDBoLKrMJWgePAqwxH5evxLgdKKKc0FbQmhACvjVir+zh2Glt6M5DDrh81Dr+JllyQI0SgsKPSnjpzTqICcw5exJGTdB/k7aZtCg3FUPG7c+dLwLVO/FVnukLPvuK5ltggBNNQ+rH3knz5oHl8yRzQa/bNolDQqKcA3h2/UWc2JDhwiFlMpxN1BJc8G3BnnVaEDhiNBE/YnI9R8bvayNOdvarkH2r02vK2GWSH9omg3z9Da6iS1OfkoqnxaWZ8JUOTWdUhrIILxckVGYPPpoA976hazhiDsIqn+Z/rwkklPuTXczt+UQyiYY9bp2hJWzERYACH11/zCMpbVvroTIR+6K3ZEaKaCQY3PdcniG6YC4FlsBZd4sPB769sdmO7XKaUZ+QZOU8cdbTRP6u6dUScl9uej7wsyzx3RTHisnV9pxGPtSisY+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7901.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WShKqlIBQsH+6/E2TTMKl9eSFFFhMpAkld6+jtXVqYxtPo6Ozf+M+DowVzyWtsHfsZtRl9hLTh0iW6tEA05FxQe5RbYeP8oSe6QHU5ec5AvjG6CutLJA/DDqx4VB5uKlbdlWRHy/j7NS5sJRI32adgP5lZ2sI2UYXGm03eEu9dxQysl66u7MSmcdzlbjHcBh+3Cx4ii3AvUFezc08D68slkkReuCik11ggcW+GEycPbUIhzgCjHTTjmJpKWVEWCTTPYXKnDO0pgqexrj2btQfUtwMauIkQqNMSLjCQUwGUD2nF6S0Al+pa7HdNLGOvhJuPs8YFlhTiP7X25HcNIZz6/5MbQCg5w1voXJqsgx0Df0qClpwhQnOUUTusTuBHgO9P2XnvFibxU5YZKq8K756/SeXqe6+1jAtaXjwQWShVqFY0DvUfOGRJlfda7Fg4Si6ZaXKtOoeV5oFnTzPUF9rYb7R6F9CVZbokQggHgpp/8bnjH1lG6QQMUVQ8IhobTQ8/LNxr/lEx8iftVGEQP9mBD1P8g7nB9AWsKIj6mXM266TvzSew6xaQn1pTMB0IAnS0pi0II9gExCfsBUDGFdLviZO7FizluYwweJAsnBAoZOxGq+jAzrRsISY7Rkmavykn2GQE0JXUd9PMCy+YL768lw1tiNIF4TkId6jKD5oml/d2V3duuo1rpE93jbmbLi5iPd0W9OCyWrSP0JBpZSrnPQL5uvg72PVi0Hs69kVNXtEZmnA3FVGJWhXiRjWByG60qzPhWYgyV201iYfphGvVe/IIM1pHKudVa/xRS+tSAFpP9yTg8eMGztIPJV+vu0OvkGiQc/cGdC1PY87qAYYaQzlSqbVSjRYfHyfpfvoHcUvyvpEhmaRFmjJNGoURTxTy013b8R3+YnCEsyVty7BXf8igLftCcSBIbpomeg7sctz0aYbV7H7kValDlGEQ2YvfZEfLuPUIjGxAqTTleSwZ6jeehxqgoYrmsOFc8R1DoWU208kM/d2by1DpkPmQeguiCL6Q+RrTGUoIk95ibWIJsVQ9XgfqEEvnTQmwTrNp49aw2vMmH+Ktf+/LKw9khFK6/hdZmbH2IUE5qmf2FkChj8lKnMmFwTz5sFC80mSqdfj0A5CzlADAl54zP28B1JM+QF1UfXiljcXVIOUN+v0t9Fg2Y1hr2yjeX0PVJ4mvvhSKxNQY81zZzCBArzxsMU2SsMVpKy0tLcBI9N9oRY4gFAHzSomYiEEucpQfkgGlGFLTXLdYrMJ7aMnS8U6z0X0Z0Xxi/EDQ1rEcvw80l518TgFxjIvTHkenxmEIkXJiL+buKwcuoc2ZpC0x+v8j7n/YWCVWv0e+rq3lujeXyHOdj2spj8g+hl0UFppKDOLatxJVnHC9bHz+1ayB+T0dEsSO/YQmvc3TyMkSKKpJHkhDE+EnXlOE1FGtW+nieNvZLMsrrVjNS0x54A4ctUqGkTKBl1K5CQhghZmTjeLMVhsGAnRIyCE4feN8LOLbFvdOWIWIfqri2qvyvJ4PCQBiWXL/JUwq3kb5vClK3+JXUi1CZnAVzR5aDa6I9IAs7MmM/c/uE2u7gdyvYmQQce62OHoT9BpoK+e8PrM1bO9vl0Vw== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a195408-2d78-4bce-8570-08ddbd4f7628 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2025 12:11:54.1286 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FxHyKQvCHAQUrKRtqIAh9pa5OwS6p6+StZ5Ojuv9Nviyn3uBTJI+7JW7jFwDZVEjViqxapsr5IBn+Suvk9M2eHOjOMy1DLhxaMPDq6kzYiQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5126 X-Proofpoint-ORIG-GUID: LshNZkR88Cj-9wgqU49XfJJOuAsYW-bo X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzA3MDA3MSBTYWx0ZWRfX0NKXB4vm1BMW kxc+49zenY9I8I1pktsXTvXP+yPnmpZ6qwM1i3yQIYTCnpO+p6M56gHEBlEiJvPbH2k2T80qB7Y c+TrnpNOENsqBpQ0ON3suLJQRBTh6wZYWUW3lUK6cLaycke0lTS6g5cnXuV4uplQkGyX0rO8eGe AhYvROdb+M/0nnpBB8H+iNUTDzC3IBYg7B6aii5D7N9wBP6dJmSOsKKggFMutif2qrovKouxdNL G69gaxi60sOuS+wnufb3DRcygt4Gb54NuEa++/qHgzrIgHlHDRRtM7of/fSX80SF6Utqt3VDZP0 ++dtqsKYCaHU3VuwCGO0p2XpdH054UCSgTtgI3pJCOqDPDWA4I4szm4JhkURcmq5OkdN/ch+NYg UgF5ZavKsbnyzmpMsFZYpTjYxdEIS5eKIhcS265rJjMIVPURnk1c0lugFT7LkpXQmJAI7OIt X-Authority-Analysis: v=2.4 cv=ZrntK87G c=1 sm=1 tr=0 ts=686bb98b cx=c_pps a=1Lp4faRsmQVBxcp4yw9jAw==:117 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=wKuvFiaSGQ0qltdbU6+NXLB8nM8=:19 a=Ol13hO9ccFRV9qXi2t6ftBPywas=:19 a=xqWC_Br6kY4A:10 a=Wb1JkmetP80A:10 a=20KFwNOVAAAA:8 a=t7CeM3EgAAAA:8 a=-19NeAzmKmSCPNEsnM0A:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: LshNZkR88Cj-9wgqU49XfJJOuAsYW-bo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-07_03,2025-07-07_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=783 clxscore=1015 phishscore=0 suspectscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2505280000 definitions=main-2507070071 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, 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 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 From: Florian Weimer [BZ #25847] The new initializer and struct layout does not initialize the __g_signals field in the old struct layout before the change in commit c36fc50781995e6758cae2b6927839d0157f213c ("nptl: Remove g_refs from condition variables"). Bring back fields at the end of struct __pthread_cond_s, so that they are again zero-initialized. Signed-off-by: Sunil Dora (cherry picked from commit dbc5a50d12eff4cb3f782129029d04b8a76f58e7) --- sysdeps/nptl/bits/thread-shared-types.h | 2 ++ sysdeps/nptl/pthread.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h index 59f9adc59a..3fe5d4afc0 100644 --- a/sysdeps/nptl/bits/thread-shared-types.h +++ b/sysdeps/nptl/bits/thread-shared-types.h @@ -99,6 +99,8 @@ struct __pthread_cond_s unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; + unsigned int __unused_initialized_1; + unsigned int __unused_initialized_2; }; typedef unsigned int __tss_t; diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index 9d2eb4d512..4df2ab374d 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -152,7 +152,7 @@ enum /* Conditional variable handling. */ -#define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, 0, 0, {0, 0} } } +#define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, 0, 0, {0, 0}, 0, 0 } } /* Cleanup buffers */