From patchwork Tue Jul 22 14:58:12 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: 116784 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 EC994384A8AA for ; Tue, 22 Jul 2025 15:03:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC994384A8AA 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 A16713858D1E for ; Tue, 22 Jul 2025 14:58:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A16713858D1E 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 A16713858D1E 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=1753196321; cv=pass; b=Qih+8DP5qXGL3uZObeZ8/INp+PJforKx3UCr8ucCBcJmELN7Fl2xb9aDc3kDAru3s+kbtjL6y+kaIwyx0vY/QvBjoq+YZ9c/P7qakAPbNkiKsyY2by/KHON8GIy2nQ/24XPMw6Nu4Uh0bhtQ3R7jBzuxqBApofm2X4Z34Qa71VI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196321; c=relaxed/simple; bh=7W0KdpxZ7iGD3PqYmEHD0gDDcTIEjgeVGZWJT6/GkAQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tvHCfoUlFimDhcwBDFg5BaAOeA6YQrubYo1MYeG8sOL2sbCtJWD7SexwIF3OxHMEyiVyajej+ASJI7j/5QlKrO804PHDpXIhpYORn1MwpJ6UKfYj/XJ5ieHd/Sy6fy3XjQN4/zqMUdjuVZgXfxeI7592dy2VRg27+I68lMaxISE= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A16713858D1E Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wV3558072; Tue, 22 Jul 2025 14:58:39 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:39 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XcHq4Y01iNYD6iaBzzpuLEVBSbCKmFh/kJ0xRoP/+LV4n+GA4b4f+6exAh8dIbRUEPBGmiGvWJtQiepkX4EeY6C1mOZiLYBwEfVJmVeqBVGta0OPyAPaz65xB3WoPk+DG8jbvFxXXyeoSYYdTH6MKrGnjF6ErkmIZpZD9iLQi2umk0NMzs07xg8X6SberC3K4O+kJF1Rc6zPIXEFWB1GwZiRHMZRTGJYufhTBpEMG0WYu7/jO88/0fbbCnlP63jSzb9A0NiBkp7ISVKIsBjaZvVmfMbdFrMjmcO81Wdvx797OVNdZ/1Gr/PED/GuYTmf4TjFfO5iQ0hrROW9RuRKIw== 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=kQQhgnm+urKZM24qLStqtAG6fkkpta2GIO+Ms+xpk8E=; b=APcg33IilHLv5oeEbyxcMxFoCUsrKbsuL8HZtOQqqxnAffRaHoqT1w0TLw7dsx/rk8SJjH07RUhXHaWz659yAn+Fu41fGTstbqXTh4fSUlI5eSelRQyVgWZGr/BmFzoboESIngckAaa0YT8iXvJhWwiOu4j/z4Z5l89VWyJ0M250tAjUPdemahMu/wdWxeTuETafe4Dyp4Mp5jWUUDrEvzQir5BUbiOxtS2cSX3noKO6IvGlVAZGrqQEiEK0G+LrJIXYizvXMbe/0sucVucLHhqUQj49GgLaPGUsOCtB2AmG4PjnG+tk/F/LL6y0mIkz7JzMzaHdjosXTDAl+LFt5Q== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:36 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:36 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 01/10] [2.36] pthreads NPTL: lost wakeup fix 2 Date: Tue, 22 Jul 2025 07:58:12 -0700 Message-ID: <20250722145821.2214847-2-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 68a12f02-377d-4ad3-f723-08ddc9303bd6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: ZEsvQLoP++wfqgJkSCb6H5RsuISPMwYr0gDUEZW1hU3KBYOhwA+4z0sbfWOTw9tuNlzhNbWTFlb5gyIuOYi9mxM6M1FFBhU+zuchW+LriH2Q73YBT59TbTM/FgGaa8rOalqxQRvdGZaB+SzKefnFjgj6dxW0vYDjPXNJDhm6ETJJChpwS94sCO5KhoZu5ZC18FoA+CSy/YZh0xLCn1EC6zkUm/ZI06BFvPmYNLgd9COMIgUqMDHS84ZvGE3hc2WvAFAj3wy4sMZyRvwlBmgjcmW8ziwKmLiTtI7r4627JLko+Ys1zvvrkykowAksG8j4CKowY5Ty7AgxG1JteKxqSlBFcrbqYhLITw/WVQZ3gy5wcXi07+4bogy3mVp7NI+F9GQAs3tDneB8eSINKO1e+gBfNK4QciRQMJJUmPDheWKOOWoNN2P7gPaHU/GKrfwHxSZySr86sECG/lUcyFYqfSS0u2DBxS1NZJDON4za4h+jV/IVZQfMRigiwcyX8eeY0AeEoze9RB2PHd24QiUQ0Wh5lFME89ukqTmaebpDdN1yhJ8hyRTeaQ74d1jB1vsp0pjM3juJQDjwyJJbrsQ5asPSwKtWCD5O9kSmB4rbnc/ZHWclm9rvBGPJZZ7xUbuxqWWI9g9r7etf5f/Dfy3wdOzyBTwBHR+Rr7mj884BNAie2kHMjjxMbrqXzRODlBbZfxce9/37zWHfpR28J2BLXgDaJkni6GXHM0Tt/nv2QgDHthfc1SN4zB4xiUuVSfbmhy1DW456ei8KBZ+JqzsDGJToE5jOthOwi5LkxAxrdBIFaJS8ZNLbrJZtgZQ0sAiTu6/LUoEpp5f0mebrRiw4Vuy8kN8vekoouhX6EZJl3W/SVDzRb2g7YnBKcxcGWvcdyrJPzFHD8iZw23LMvH/QSgP3u/YtGXLtoUt3fQT/hE7xJjT7eFz4pps4Y22SGDMwr/nX+VCv/6zm00sjo5bN6JUflgDnSLdub5gcqqWb9yZQHWx/V4Nh1DzQkgtbTiuQKoCoxhmPn+UWWpCMyaEW0CHwU4ks1tLWA3zynNjs6NNj5p31XLX7DTD1XXFgfuHeGUdMY5onUbMWCccPSTcyV+zYCHE5n+botalShHn8zgwsWTsbMAPACLfPqIO/4teqTfFNKwmm6NppJwGUUY+jjPI7/PovRirdCgqi8LeGcE/ZOnY3CHpP4CSKErrEWXa6kG8bjrcR2LnZSVesDeCcOn+yUqdsRp6CLacIn2roJ/Vcl+5l5bliSoHBku2gnlwggDUm8oULzgRq/VzVseJkLVTO61yTIil8vvPp7UDz3lugoydZYur3cNHLxbOwnlDAxAwgXOEuOUFFXpuXi+lyjtDpz2YCQhhaLCmPmJ7EbuF1Aa67wzovUPG27oNQSzMUogd2+dZpcilDgep3OtGr4DJKjculIVi0llWS8B5HfH0hyTqRCGCYMt/YZRMmQ0wywC7UDT3K7q9nuveYKG1Q/A== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HraZAoOqUvgz+B5FKtW53YGvaq6yZzcJ+Zp0ea3mfxyttSk66ykzkuIG84TCkqTG2wjjPuCndnowS/Snt5TXwVspysrruyk///2VhfVqlEih8HfOylXAYRaKhBszcWH/3NP1xhgGfSQZEv/W4xTSvmuhoO4oFxuWF/6lA6RYIVhdiUXyvdVWSjQW71SO8XkoGo3UwmKeqChqukngKjfRw93Y1kWi8T6Agntq1eaFTfVBFJrzJI4O+9MFgad1SyRz5zIe3MvZh6T3eV5QsGn7jRDDiiViEO0rGyTn9rM9LpbzYW2+TVjD5VhzNvG5EN/UJgzvvbiZFekNGqEdSGXAavjqjru/o0/gCGOOUSJChU504m0IWNXRZpVcuPeznvvDikjLymSSGm/CFF8i6nCB6hFZWryt839ruyCdGzlWt/WFddhwkJPmGL2/+P8KIBpm7Wz8NmTTSpDZseM176EtU2wiSFeGqbzxaPhcz1kydwWh8Vp0ItMwUhvLyN4FY5MvO+/df1H/Zy6bfk9rkbYqZ25020P1o4msMZFDrVnX8W7B+ysSaGCXDQpG+x443WTmdkE31xMojA4dBoWAAtjg2x436Ex08I+8OzDb70yzxvLU5RFNqg/0WDbNyCWwuWsy9KD9m2FszLcYMMRM4DFxK/NuYh64c7IOJ8Cas+ErDa4ayFfMzIgHQb8vLB7LrUD0Ls22MOzQNZr2+APCA8VhivzZwW8vdymQfYxRzXSFfUxF9WvK1WGn8SfE0KUa7JNawDqISWHpglMfYOvBGk4w/fWfazYepU+xcfQYDAOtb3bJZxMfjScSSB5l+qBSaY+NijAwpMpo4yoXDr0zMbENNGPCUWBfmYrLi7QhcR49PXtB5Y4A5s+KvLqE1DKewr839Yk5fOd2VmmVlQMJY+xoUHecbYA3DHOIoUfcy8LQwL86RskXvuXdQY6rVM2qC/hmLlOu17xM1Y4InuqycLYdA1el1vaRJAxr1rQzx2uKQ8OMxCr6/omwHMs+ow2kkiHCb85z0i+BKPtpwUdGp06z8d6m6LUhXrEt41JlSB+uqgwQPxiHOWMVqiRSwMpMdDLaocvAQCcNUo1ngao5hwcqEeFXMI2VffbwvyOQYq1tTl0I5IVuBriZUL+G+z7Ke5+8vS4HjhRv0pxVkpP2Odls1fWGxKPJ/59sQZl+mVNVVvw6pr3E++Dif4UeZ1KajvMjWONx3nAngXmi6TCji371KN66IP6PilU5f63rVt2AqoCiv1iMK0bi+LTFuabqUR5wiE+H6Gs8K8TyuJEar3IVEf6c4dWZqi6gCbPwHFsHK2pk+rmROnAsInTg7X5M7/Avzidu7EghuJTtc1FKtRUoMfaobC9jQSvJEqqFJDRAeHAfpVO0L1LyTONQc3HMbQ1FnahHKDdKd1IJNPdgQCcanV3wtg6JTKkS7SFBA7yFusa79aYnej2UT1UGiJdj19IDy94QNp6b0+4C0VelQfeRUy0J38NP7GeaOqvxtgCvegUF+uhIF2vJh9ynevA3sG875tvoKmnOQoyRhCoiPQwSjnMKS20kvmj1J5RN5nrmVNHUkBRLNhfvfvcOu8R11gEPmtGziAE+coNX9NwIFZSlvdqZQ0/dnfgfCU2VeedfPMc= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68a12f02-377d-4ad3-f723-08ddc9303bd6 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:35.9401 (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: XzdebVVoQoEpD2zC0Or6srZrZ0z/bJjJAq1v4dEx3OS/wmaC8Ezxq90D+DYxgc6viuMfKfJjARqB2nsZOOROE9aThI1aLrYd3gWX6gvWUPs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: 8fCp4qdcSQWx0KJU7PRQTfgooDvgHahq X-Proofpoint-ORIG-GUID: 8fCp4qdcSQWx0KJU7PRQTfgooDvgHahq X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa71f cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX0nVgsLMXXgTS 7wCbNK18bq/VULY6HZymAYnlCj1H8Fhwr7N0qSDvCsNF6Rnc2vngv5f6W82gxO8vTtKCXO4oatF AxHfyp7jY5xIEKcunODR3+eE1qoFW92CWXD+miuuKf/zm+k/ydwVl0LXnA53dHs3CZG8ra89ZVw N7rQaTzHEPD4uv8y+XojcnU2jYPaBJYLBzN+ilILqnFJ8KUuuHok7XX7FYIGCsu2mnlRDzeQI/q SzAQnxuhrwxcbeZGGdLMa5sb8B6T/XZzX5E5xmmntwPzOYsNxYmPNG4KUYNFo9/oqfMNetplfs/ V5jTaDsNbqy4t2XCXj/kECoRytwUI21GIBD2yHwVy4okm6ICLxkVZzmkvbsKFBXRtVvYqGSi4Iw xs58PSkb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit 1db84775f831a1494993ce9c118deaf9537cc50a) Signed-off-by: Sunil Dora --- 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 fb035f72c3..a55eee3e6b 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 20c348a503..1cb3dbf7b0 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 Tue Jul 22 14:58:13 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: 116776 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 040623858C48 for ; Tue, 22 Jul 2025 14:59:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 040623858C48 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 C8A533858CDA for ; Tue, 22 Jul 2025 14:58:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8A533858CDA 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 C8A533858CDA 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=1753196323; cv=pass; b=p75gumEtWFQoKpaMUFJa+F6aepvEMTuj63fZx8hWgDDYRlw5ol0fo9OEzcJ2Gph64Bjx6HSlF+UGuKvf+5kUKeiIlT2gkB0+Bf28cIEWb1LF7v5jGImr9aoc82IwE7p/0K9CjRCwH42PSSMXLuj7+1LOJStPDP9Y6pt7hSq0oMQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196323; c=relaxed/simple; bh=Lvl7djokOREto+79fwYHHDnZDyNjByETV1nyHVaMMI0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KEiGXn7ixxkdBZsJYMQUEtJx/3PruLk5Cp4vI4uxSeaGg07ujSxqjRF3C45jleNGriIjdPcgnvL4bFniG9GKVwiXOFlCtcpKSV+iqseCF7EegjiuPqxOXBUZGjcpBQKCtmzefpJJTlOoGlTMOEhgzuUGTkTiJb1tQK4k13EtzV4= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8A533858CDA Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wW3558072; Tue, 22 Jul 2025 14:58:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-2 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:40 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GU0GBY+I+QyYZNJ5BcbxXAegkZglTJ5gjXeKk0eSMnfa6RRZEOstB6kLvoiOSOQwtW4xqi/+7F6gG5Q0S+e48d66am5qgsgppuJfr+f78mnixo3/gsgLD0lEteLNQfRQL4rsUoGkJT6x9uZrKn2Mb7WqQr5/jixH1QXraf5w5Mwn8HcXEYVqMXpdIokGWmKTdLsI/NKU64y+4MbMbX1kyc5jnTOjcBo81yJx5dzrZJa7RUXZKCU72H0BgIjP0SxZjct00cQTOSIp8aPFkukTv817s3+8DVEDzlTTtIGlSNM4IsH/MK0NAvjVeAXhYE8Zxz/nqopX0+C6vT6FWqTJbw== 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=0KJuWHVQV11DIPhHERCgSiBWLfIljEHqlyc6CuSgVlw=; b=x6MEuAAgxUgrgbVg8IBfqxOOPV3lQ9Lpz4cRQf8joeDnSA9xBbozABxedjfMpst3R1Ej3Ysy1hA91uetn17+bFtstD0eufkF0ThL1Zamh0utM8qLZLsHRcKtrP1CkpXiIgcyE4u+rFu8eDu/vSzhrCK1J4xDEysYkn0aMWd0d/WxuCgWbcTYR1Ta7HCsTSNYa6IlrHmOsrwFRjKQ2o/dwRnDmQHaIskx9XKT+7mPtdUpnpX3eCK7gllTtWT4mi0U55mq8Xko0XsjAXMfyQYw9Q5H9iBXiqrZY8oQLwpbqYoDAlYUKyfb8TzwMu/Xwg5+Cn0WIWGKwfUaWiiteueVrQ== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:36 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:36 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 02/10] [2.36] nptl: Update comments and indentation for new condvar implementation Date: Tue, 22 Jul 2025 07:58:13 -0700 Message-ID: <20250722145821.2214847-3-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 551cce48-4f70-4b57-9169-08ddc9303c59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: E4q1I53DJZQMN54PK+0FtvmLDOvQJged+PzC1K9SuEs5VcqCdvUUyPSEZXMluQDj8kuqRNfSwu99Iv8iUVf5wcasYD03riMEOWp7zhwIsezTAtRAa2/LKHNxiruwkGiMRU+4bIP5D0/KsSEUtnzb6ctKu4We168IgVur1mplEONCMfOXe5gXpOUWncsec2OWX+wOefkxCeYbbWdizTDH22T3ftxoT/uAf/KZCHsyRRhSYiCsTmDH4CqSr9vyL//9eZq3m9N3Ps1KE+lmMl/dHRXPKoc6V23xneyQaw7SAbBq7qCSjsSdFbri2Aw8PLisE/5GQ7k2i9Quy6Tq31ObDPmepFXfwP2OArj2+lle+L0dy2gaI9Fb6u2LYrxVCe075kP9hbB3zHTGGWq7wXvheW68y76b1KKp25AOuz3Igt1OwXX133NZB7VMqo+dnhCoZudND/nwcbK38kF/hHx2tMJZMp9NOwH0iVuPxCl362MQinWUV0nXn+nkZqeDuZTaRC/0If6oNdX83o7vrHQZGD+IKOapJ1BRgJOPo8yHhQ4K3Bd4Jg9Wl8q/UCk5yP0pgIs/WGRYVa4CbnaWd7DWy2wr5TcvMWr5+OhJX5c21Q08GQJLUsOYX55jk7Z6ESSjOay7vd8PQ8oL401dsKeHb/G751axM+JyYtheJraKLH869hxDLxMgt0m5m8/e32ihIaB/O3RrL8PfJwVXa7B7E8w+LitQhhDufE6aeLALBGbU9X4aMLp6R7cnbLdX0s+qJnf7M1YNH62vOuQkcJFN8A9IZnVkykPb6qdpti1Fn1ZjwC0B6PvQUvUD9yZta1mbE1bM/DuDkKutYOWDl0f+OZOcMx4W/g7DPM2E6Z98DsnASwfcslelW3y+WMng8LHStnIzmncTPuZVY9Gn1GhIkVAS8x8Z6yKZf/mpJp0nOfXOV19xJf1rgx/sQ5QxNfg0KkPfa7/KUuI+xzVrdm3repf92J8SVvxRDHfwK487RhBS+EfAgX1vqrtBj0pn49lE0KTP2B1Xjk7KKqUjHRiLa64eLgTjr+lCKC8sDYzrJgvIm4vOm5HklEfwxeYOak/wor/C+AeHESAND8XMySdNrgdi88PP8qXq5DoRSdn6gUywebj0vshFqsMTKt7lGcoLGOBRHS7fVn6obcmuBmEy5wC3180+knekuagB36yEWZcaTUcr5V7AHah9hcu2o+sVlhFJHbkofOnADCXeLLT5wr6zbEpl0Y3u73Kbim/KMRQFcw7NARmAufyGof+gJsbarY4UPy3WMj/gzKRmvZZpL5eKKZyZFWL5ZHB0apqX+gVswR6QANF5tJsjGZNfljO2WHFlOyraWnv7MtKIiV2TDGK3vQkdTYYDbw7JQ8DUpanduPtjAIE62o9M/LRH9faNg/dBuG99zVYFFMW0VpshldYwRJuuiloNfa3YHqkjTbeZOftUprcma6BWmdqAsv8VIsp3MZ58bpZjcBBqo4bX3g== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e1tJ8AdBYzn4kmufxqK+oxA4wDrrHMWR7h4hUHGDSNnJHNIETTYS9FhVVi8TF5ypDxmHSREL9RKpwGdfB9pmJ+AKyj6eQc1Kj1sf7NYTJ8IDpMtvm72tUItkKHRtRn8GKynBGEtCKxkXgRwIlzOcieIDFcfrvNb3ozKMKyg/kdg4veBwyyWK1v796tpFDhejj7yUX6Opr8kq5fkP6NA8zyYUZtIXSQblaaMBXkABmOZ2+4GSTQQnHQZUA/KScBw7MWUyW0QOxflJVdyqa4wJvU7oLs3NqnzZL12Ki41y98jsSa4p6lfEao8H2jDVJCt/KCrqJTiKTL0Nek8EZadB2/JwrwAjLTSBv2KN1kPp9Z+IdDv8dPjzF1FZMKtxMnGux61dHUdHETGrxgub5a8U7vD+P6gkPAg8LgeMdG0ZdPxM4OtGQoyr5dpj/CYqqwftBx3wGmeCnqOwjHCTzbv9mW5agxB+nqdgnZCSOce37k/D6Nc9J4m9+WBdXiDDwf5e7umsUpF4OjSfCZ9VkS/YmocvLXsDp1bJjFSmVrTKK9SUKtijCZMgSO3JZdkSxEJJojPa47jY5cYa2abOEudf4y+Q/HbRIRIkx8A5LkJHiOiCs5L+ScXA0yoZru4v3PA3rFYDHDG9ckoryzE0ccLRHb8Tt9R0sNiSkdpmSsTFhtJWQaRsIIGF4kITK/H3qF/FdtQaYyZSZRO1CKPz3e5rs/kfbZVq6ZxEqPZURylKoj/qla2zFjdxt3W9SXXkyYOjTbMPZI+M1VxKICiXQkccNoedNJUwiPSH8G5fDw6rvgRl3ktBPkaoUbComg02IXO2ChbkYKK4q5BXKek6U8rEoVHdLcAruOUAfcmt0JgcfCQ0vlxkM+cZayIR1+yKl482tnU4Jvat6HpE0UpePOhho0SPLrEzwHCvzr1Fy9IoSVd6jvkfnK7e92A+rengpnlqCcLKKJg2QKyjrs12JXyAEacetAwUi557jYhTom+qYwQnGxWF3KV5hQixdziJceNqf/A27+Upv0LAHe/bWuf09XIONhsrnir68QopWRpGWZQA9JO5cPwt/j2ph4fJXXFbWubEXMk+V73aBTjtjpYP/R8igtzs3KRLnDmPIsxwlZ14JiERU4uEz/wC0FZFcvKLH0H3WRBzCgF/bGRMcuMmh1HWXa6vcygRokMiC3pe5MhGEbN1vMPotAckWfFJxC6TBiSR52rOzppTL/u4FnV/uVbE6g98tpCFjMCl1IKI5nnYOrrJAE9Pl3FrtGJAak6NO92bG/ugK/9RI4PBi+KqCowtsgGO4ux/sCNyi48j6jpD3saOCVxAgNid+OjUZ3qM5K8rRLpkc7DnLENZ4sYbPbPmd/c+tA1KIqLCCUXgELRITEMw5gWzokd43zud7MetzCCLIdBgc8FSrrvwC7TQT4GGtWT0j/pgmVAiB+IxRBXBN+vulW6dmbM6j86/BNM73wKTMVyeVvWrLc0qnelEkczlOV3pHdEQkdmuLgNBPV6Rgem4Bwk0Ika+lGtW7SdLpwjhRbJf+JfAyHOwhTER3ta+i8/XlEV5xsUmVYEe0ojiwQF5/BgSO0QsYaQp62VgEsXWJtbpLQGrRIcXnK/Q9qyuydDfxLFnjoiBt6ZVUJE= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 551cce48-4f70-4b57-9169-08ddc9303c59 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:36.6427 (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: 25E45heWRjmsN2fqO5ucBSLXkkSOj6v0tf852zzsn/j8Huu/DrruP456wo2IuJmx+weSwo+tkbtNqgOl+DV2o84L2NFdAXvJizG83isRof0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: ctQSpcZH38SL-fAv9oKgNu0Qz-P4CljW X-Proofpoint-ORIG-GUID: ctQSpcZH38SL-fAv9oKgNu0Qz-P4CljW X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa720 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX5siSNoR2arXU 8J6y1cWtePksqGex1ohCx7wd2/neEvvFR/EfAfin0Q+MsM3BlAUoTRTIYgsyIl4uEDFkfaphquF jj93wfaA5yzBEcWhHCfi+OoN74bOLtg/PScIPJ/NBUx7xNsOO8VA0RcsAuTmN7/a/i4wIkSmjvD Q9iRPb+wBGgw6xWWhm8QzoY1SCm+03hxrTaUXGNcSAYN9/5UOStGwuUNkBVUcF3sT1a7phwDQaP XdbDJFet9ebe1919DmWHyWEuSJKfE3cdOux5rr0270uygthCgiBbBQFKAl+Q1WKEDPb306oGW7n JiPqhV2F40PsbfE/qGWaPjHu8r1qk26ll5Tr2VzLJmlJeo8xqwOwirtO7Qv7f3b1nvJGkwdn6Nf 8z+gyIk/ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit 0cc973160c23bb67f895bc887dd6942d29f8fee3) Signed-off-by: Sunil Dora --- 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 a55eee3e6b..350a16fab2 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 1cb3dbf7b0..cee1968756 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 Tue Jul 22 14:58:14 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: 116777 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 54BD93857BBB for ; Tue, 22 Jul 2025 14:59:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54BD93857BBB 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 511653858CD1 for ; Tue, 22 Jul 2025 14:58:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 511653858CD1 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 511653858CD1 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=1753196323; cv=pass; b=s4NQ5YknmjaIr77SJFlszkW6agXK0EAoY+QSn7OSYLcDLB0x3gC9OIZSn+g7WD0taB2X3KgqgwG3kfSlfZuQqhpq/3H4b5kymK/WsHalcKlQEmOXelb72XrpdJXhtDv+slpkoT1yerh7vr9tOkRdhUrqlDpzGIH2zyZ05pfhZaQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196323; c=relaxed/simple; bh=SKDenB5hSvgfWMkJ2IIu8k/T5tz06W5TsDKHtf9tyDI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=rv96+4gYhqnCeae5ycqgTcVyQFMjItjmI4eFFDBR7VtBtCdBgijnTnySjVKLHeMPc0tQ+rUf7aQVNcHHGQGARgEVWy1tFX8fg+4vuW95Oiua3AJBqqVwCUggcrz2obM/q9VItHXJU+DBnam+AWY1OqbNTk3LHi8ggiHOMXaCOFs= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 511653858CD1 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wY3558072; Tue, 22 Jul 2025 14:58:41 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-4 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:41 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SnTDrGVWUv4heYyYqRLvoRLV5uHumAxNDDaLRi1EtzLqi1pC0wEN7cpfbhSNZMiE/tG88MpKfbgrcoYMkpSPQSvJ6lPg6R5qDlb/QMupxJoLEVcTgBj9G2OML/xfoXGnBWShXCAxQOgvIPTolvXusAJ/VSf3Io8kJ9OphTHKHvayTQonALujOyrjKBVU+uwOycHf6TemZmSf/KS2OVq7s0AfYnnvIgXgB1+MTmh8ZqFGnBjRa4cc/ljmcRTaWPjyosPhTgxzrHuP4TYaodNIukL//pmVmix8OgvcwGj1oSUoo662Eg+3EhtrYDjRuwNNurVX/FTzANppmkwCOdkzyA== 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=ALGaJDsr+M3ubyaWzLPFvDiYsIIE6soCIczxi+RVklU=; b=Y4Vs/8SjeaCWKjl/Ebffqr/1jh243DnSgQch1ahyg4foa0OsMVNgRw8WCQlnQ+r01OEZV73a93bBT7La4OGeEv1n/+saf5L8ZslrS8WaYaSbvIv/b89xR8EJnpjr2+ctK4n5XMsahelInBEwQhU7gFxhZLfWgIDUTYMWSn77Ei+mt06Tnvzcf/S54V2Pjv9mJvhMSpmYqU8P3fLzwA620OxN5Xa56ZokJua5pWQgaGGy7PL5d+VN2ux7LOJ9wsnCqZsptDxZ035fXzk6+ueIS61iguXC2FkXsJhPHebWxkwRmtDwU47N+IXebZBbGQlUZgSlriF2rbTZG20jdKxFpw== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58: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%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:37 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 03/10] [2.36] nptl: Remove unnecessary catch-all-wake in condvar group switch Date: Tue, 22 Jul 2025 07:58:14 -0700 Message-ID: <20250722145821.2214847-4-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 8dcbf117-dbee-4e43-efb5-08ddc9303cc8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: NrMqwSwsSJChM+CTpis6dP255wtgjWfRR+bEI7UwtxtlujpD9ji9y7+kRqCKMyTEgbUMM5EjluHhJdTaN7EBNRI3WBUQC8IvDyB6WxckPAo2+hCy4io1EV2buUCXXYxSmJY+SW/YAvCLa3rhqb8L2sKhah7AYdO1+iR/HcEzYnCJsLMWEL5a9luYRKEShiFsg98IC9r90j3isnM+QuS8r7SB+NtoIiT1DOMGP16P08dEtwCFPmpkyGlzSWZ4PqVi6hI9whYlQWwhRT9Xrbqww/NJVXaKvtdklBDv6eAFD2V0gBRbZcHBGfpkkoh22jL+mlvfgHgjnE34AmDpdVqd/mTxSS3vVaObrE0grlt+FdO1Ga/iqMilNcPrnr9WHI7SAPXqwSA4VE/aIDDuxRsxNKhPmrKg7aUIEgjLF1+ETLLKMAP306vg2PaBAvNXJ5HoWdqtwTOgvfQj17bOmUbdMzktlNply/et3jyhPqnQtjfP5MhOGoAaY2KFtYBWwkwOLqv7YQE4RX3FmzETpxv3gT9MH4dye/kf20/FJbOWZt2TlIFGh8ceGndwC/xu6r5KBlvmtMw/7kWm1hecKBWchRd4fPkI/XkNRIW8jFyGEtTfC8lxtkVczB2dox04l6qYmrjwI2eTE19zM6ePHz8GGb+htVsBu7ztmnVtGPpSpaW7zEdYfbIJRm4Zmr/IHUCAxRmdModF3icqcN/8M+fkhQeld8wAUtuJ2al0iES2UTHTJsh/VPXA1qf/XzQx7vj9dyVlouR7ZbC96SXxPq1aV3Pm30x1SbE96hdeVZE96xSNaiZtE/aLp0+rYz4z1MG/2LBvULU/qLlPmFFNhgw4GBr7LmfXXkwpe31B1a3+zJhCjjrXetakz64idnboWIVi65T2dVz+cT1ObseG65zKZV50Js6O1+gQ4heOql/M8FWXjkd1H5OoYmrd+WXfZlmyQZ1FzOonllV9OBVhheoNwP0Zk1T5IccuvdAheDbbkU2FUaGbVNkXBD0NZLyWBPwZPYTuspE0MrhnDytT+C42G1LEEChNQhmOkwx5ou1IYURGcbIMEEH67DUyNNB9dCAtnhtQa5BJ0HUOAf32XWbuHukLZB8u5co6Sf9vuR5Ag/CK+Zdbq+3DdG2klJxH89QkjsjQQ8pHGXttbK0wVzndb7iuqmhBrTGVb8a71SrBNxTnE4ORW8YBuEG0eT6o0pC0PfQc3BzOM/GGmARr9PnUR2xfY9rQ0HeYrS1zLQMUMV96swl8vOpzitGLX3MbgqwdyzKN2vP5+zEaxLvNeTu5+qoMX1GWORttWxxHZmqGtSvSXl1anHC1o+hOElOOGBvR1cQ87EHXaUx2ge5RUVnRLUpzJAvZYmDunoO/3KNpg6BMZboKI1JDrv7mGNxaTqClIg47/tpqkpuEhdMZm2GY17ASPz95/zs5wn5mCZzrOlYQYnMEPHI4IIplh4ivfWWTbXGoDqPTxHqc8sCp4uFTCg== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N55S8eTIhdf5RrS7tNLs0+T+M6EfMV/3YU3VC9LhNuhLkmxBMUsvnvrtAINsc0jtFRAytKGtLjOD+mZq/eaUbCeCBahH9o6BIiCT8C8hs1GDD4wT66Ide2EJGFOqghNMUdQUfctnX2HlY2XP0X6We4RS9W05K3LyIwqXPUabSTa4Svf9lDs49dt/F0B5UcVXRzddL1NPEmWz1Gb4v4BiLq3Hs928PDAGEyM4fCvFyLy5yFDDNq9hyUabIujbVqrYtOoJFYnW8SE178Zx3wCbuTwx2BIcZCvscNyBTYtVFfG8CRoEBkyyjLVHiIoZsLoIc3wg/wkNft1ZSFNYhrOWIRA9mvDsRx/6OrmQAUO3LZMlJ8iyaT5VsDHs+2kvIBWA9HZSZLvPAR6uFNfaEIo8DaSSlHJgl6TKDC9UbyrO47PLyPlsVh265F9L6GRu5d8K3c/aQtplK6b0XbPyRIwUjx0YYjkfgUHT0axrUrEQWF89k8MXNCcJQdIYjYngdz1pbNBQseGgjH3of//jn+IaqPchv9cdwSYlb6bHeiLDs1zu+dnr++xId8m2uqOtMJGzd9maqc8QiEfXB75yMdJsnUR+TO3fzjai3Uxzis07GcqHtrnAr49DCCyMyiQXPO8t2ktF9GifGmHugqeqI18HLIqYmu51eK+c0fIs0RGnbEdL7id4oegtQ74PdDCbzpQPctKfEK9lYk3Bux8pdav5Nkc3my1GyXAwppw7uYCEwPJ+5yf+GCIOISSGyw85ohXjtv40Cu18knmADFm6iDoBKIngYafjdGSxbq7hsrQQMVMzbyM48782HudIkq779BXiqeEFY19kElF/IcrUzz7ovLjrkK23B3XGIJaKFDu2UUdfV30h8iJrBlX+bOOxQ+6TTYOz0MTXsHv8nIPmjwbhHdn7y8BlgwRRGr1yZEU4KjKB0Nz0/VxphT91xlknKoYky8nBYSbZHHpBeO+xykGlPIrRGNC3OlJF0NX6muYM6kIx9au7+UpFR7x29rskYg9sQBq0+otgnzsuZYRlLz4/I2JudZbkCUYj9ZTFVHzUOao5EDYMDKEN6oj1U3w/TIj6kJ+Ot2Ibs2qzp13bNNzAcTnz0vwVJ8C3mN6f1a/+jWSdmZTd6/0Rg/+M/GCg/W4S/VsbE3QV5ksmWNPcyZyEu7T7QxW/pnYQawPpCE+9sNE3+VHY7bcqWKpehHszxZW6nwrDukRU6MkfsgbWN5a4335xqPbblYOIWSohMd5oCRxf+Bde2wrZVRCEciWN1P60YQl1MDUVttBJMtrGvatD9VzQl0+O1TXwgrvx3YCaGAsOMPs1gZF7V2/5+xZ17n3OuOAInOZW7GkvBwWOftlFAZXmWhzikDb2cyDCm1blC54yd9oSRyjt9suVpfiQNSe6PmtAKhj4nY+cT8qoA4cckns7xTsZYyzLAUHvqxolRvwk2VKgyKMCZfHMg/Pai5Odsbpljc1oa4bzuVFa9e1W4SD6TGBEKSC6XlCQhnNWCLuXiud3BJyTwm9pvc+no2Kox/uU5GLTWFHqZkXbh5Yx1y2JG+2+7ExFLcEZ1RVgTIN8V14m5/qOKVIq1s26jietqSTK89cHPhuxwbqQTVQdrg== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dcbf117-dbee-4e43-efb5-08ddc9303cc8 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:37.3340 (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: SCQ3Xp9OU/+GJxhVYtJOC+hsMfDYENlhHGgW2EYRTK79mlQxcvRnEdblTqNZ6Gq3Q79H7sH11D29ePofHBhcMx/PIV3B7H8jkS4CXC5d8bE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: Lhb16HdzpaLzdDzEkLe0jj2Dqbcve-Th X-Proofpoint-ORIG-GUID: Lhb16HdzpaLzdDzEkLe0jj2Dqbcve-Th X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa721 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX1WeFclDaY3/p urgS+tO8CbHRR6XZEmwoKjEqqgagR7eIrqoqPgt2sSQBRHUhXCJ1Cx76KnScGoa1ZiD1sb334G6 td2NW3fc5iD/DIxHd/32droCXKZlNfp/9UcEpC7KtQe8k+Tbq9Qyg66VqNvqR9OeLGZvdEuFjOA OjvaupiPiUK9JJdqtkwCiAvv4SWzsQ5ZrOraP8sYLt8sJHeIoz+k6Wpx6sLowOPXd+HAi9+khc5 BSFL+3p24ftdUCc0MMctim0u0lmWKwD6WnPy6F0ezZOkPCGLrNtJdEzBrLZEBC5ZbEMXLinXfgO ffj1l+OodrBDpOkQC+CzsDi99+zswMrUXqcfwuv2k/RzAkBD7sSFltCkVRfgLxLPrFxYr0WJj+3 3U1yqZPW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit b42cc6af11062c260c7dfa91f1c89891366fed3e) Signed-off-by: Sunil Dora --- 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 350a16fab2..f976a533a1 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 Tue Jul 22 14:58:15 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: 116785 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 49213384F01C for ; Tue, 22 Jul 2025 15:03:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49213384F01C 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 986273858C51 for ; Tue, 22 Jul 2025 14:58:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 986273858C51 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 986273858C51 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=1753196325; cv=pass; b=jjBwSJEheoCp7aaMXuOUbCY81IG/OS8u84+NOI/1WQU75YZEHI8Pa7oF5yfFGcnMEShMl8b3F8R/8BKA/sVT8Y2wbIKC4RH/aVP302JHdDJ0sYdGvJPF58/l+5E+8QKkj5uKgTM81uWVWTaM8pwmJwHms8btuvLENiQzpw/GP88= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196325; c=relaxed/simple; bh=h5/Zw3Ro8FS6LKIiG2T2rHx9RKx4m8XbaLou0aRoF+I=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UWQ48/UCoqIPSPeySisP60TjmtDCuFIzwDV24g/C7cARL3wTxGE8rlnLS75NzbpyjaZEYLooGizpVAiTZBZkB4f/h0lh0Iez8B7w5mBQJTYRflZweU2T/GmDC62lkhnRMtq3NHB7Ugj7OQIWuFn1qUDEbmA4/O0+b+7wYEQ+KD4= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 986273858C51 Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56MBxodL4141957; Tue, 22 Jul 2025 07:58:42 -0700 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 481vqv0wrw-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 07:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lrUYUZcJLN9cnYVzCxEiFWqDrtgeiILlqEkJg8aFpBgp4ymxjApxIraKgN5kM24gAvcrhLakohOdN2v3kihG3WCDQGb5kMblBTPKvIc7XtGwdX+CWx2Jf0rjaIS4SknIVjIgtxyqXmoimk19sqwSWQRbpF4WigkfrhUE3oYfcIkgk4p+FP2Qo03XXSBA+hYzi30IEjgA56lY41ot5y5m7DCED6WrO2qKXXc9m6dm6Wx8GdrX7Oe7tfAxXK5wmAOqu5/CUvxdkjZjmKeXXOighwbbjvv9qLiX2c39AwNwiGqihTwTmh+Cii8BaZM1TznIN/+6+SuQW2jsMO4EK8MQ0Q== 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=nBJkBt3peNwBvwm//2wOfSzQ7esDXhcdAYLP/eIoNXY=; b=y+ZaMgccz9AMApvqGF8Qbqm1NFJUF1dTF3x8b7atDzaUdc9LyV2Bicm+1j4dRYXQvbGPCTgq3EkoFqON5tFZdFHMK0Dc8GhCN1w9eL2cGBNigFSfiossud0g6X0BOIP1AKJcIOuZ2f0Mush03RGlXMv6ZYRIFuek5ql9Ebfv278OJpulYwlBz2l10fGHgGzIpX3hrzN7lYWgQd91QTPadLBIYD1qH9XLY/whowGQD3I66tlX43Rzm/LWFwJ3UpbOp0mrmz0h1lAYghI77kjebK5R2NeVe8S38biwAuz82CBTv/j0xHJbIqFU985Bhjrlym4t9TCDCQqddE34j3YDGQ== 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 DM3PPF4AE904FD9.namprd11.prod.outlook.com (2603:10b6:f:fc00::f1d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.30; Tue, 22 Jul 2025 14:58:38 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:38 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 04/10] [2.36] nptl: Remove unnecessary quadruple check in pthread_cond_wait Date: Tue, 22 Jul 2025 07:58:15 -0700 Message-ID: <20250722145821.2214847-5-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|DM3PPF4AE904FD9:EE_ X-MS-Office365-Filtering-Correlation-Id: f2fff380-7bbf-4baa-9eda-08ddc9303d3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: 9KQGr5VWXeK2YY7KixcDbIlm97BXKm5X4cc0mA0LdumQe3LWesvQA5HNcAluhec5q6kmNIz/0CZKkn5phtPlUuGrTQdp9FLOB6xzlgVX5PAPIPkBPuhIwB/2r4dxe4tpU1Z+MbtDZYeRkvKZiwPEz3Gvj+U8o71qOJF0W1CkH+0MKspzRsut4L9WjATHDq/XSsuFNPqXCsBamCy3kkXIG63EQ7a1Sap6C1ZWCMZz9EEkDphczJf3wrkO6/SGAJRcnST6YdAWXaln7aASha4HeykDlvgn6GM1Wd5gaTjBX7zAV+p6bSiXe7+40k8FYUYc7dhawl6IavCsSZiCSu3mD/BgHWXXFFU5sW35a7TUm1lXSFaquxeihRzA8pvNfi/sit/zxVM5Cyp7GSyV8gJ9C7J4XL0hNTs3fz3KxvCRjL3ysG0vcqUt/wIIul55knxZP2QRlcA9wst2d85BAyRZLy3mUJHBvPTtsc/yAOyfh+e2u9Ygsuvk02sRflR01pAJuw3GRNg0D5KsG+9Cun4cQP7YcSCU4L64xOBKnQtuiv/xqzkVmQxtoIRM/rQa+3qU0RZZ9te2FGJQC3QZXWtsSysKj5jg0gjBHm8JqfAAsJ/ZOYZIYmnYPuHOtu6ViPl8WqQHGppFY6Xa9DZjajA8VUS2lYUbgcvhtGGGsZxHwyGc0O/fajq8LkI9XkXnnmQchIssV/COhy1CEkK4Uk8bUI7q0dXASLsH5mHJH1A6awAVS2yS2/LZ/vL8k6JmcvE+KSqIUKdagKo6FcBCOlzS1WYb3ZA/BIVuh/JZBH/5+C94bWsd1L/l+b/8rrr0O8t8FEkCy2QoribU0Jd5ED5ArOK70QSPZFpXbe7EHZxr73u6GOjxIOKEgfCMcbYaxBj4j5dcbPyCRe7wKz+tf3xzh/5zOnnXbfLZJT5DfHPQTlHudNvzj6On7hwYu1G5S9yrPY5MuIFJabVXkyIeuV5+ZHtvs4L7Tvs3hx846ESeSzsXIxCGaYDEiUN+A7bDOhWgDfBoJoKVSQbYT61j7kfc+Id/IAJWbSS1dRKKJv9d1Uy6Ug61XslMaxCS632PNveAtWbL4mFrS5SFp1FyHWh3vkT2HVq33oDb4D9G/ZywDL9stMuUUnkk2BzwwYlb/rPp0V0aF+JBNqJj5xIyzUnd4JopFmmZyzqCc3+JYoU41aub3CjbZH4fNqMuVQEFZCGyPkzhn+xZyVh7IaXTy6gk8El7X8QYh9XhdGhy60CMtONgcT9cbHmUMKvHgpv60EAWupF21IbBGqaj16T+Hcwsu0MVUtCa/bAavSDMbw2FZ3Da6rTi/iH+ClGStKnk4sgsjxrmpNneqdLKDwmsj3G/ftwS2x857IUQw9mAoXkRS6FNNjIdy5QZIryZF1A0AcEqsFSnkBJRqY32jriwagpDMUmxh70kVFx3B8aPMA6JNd5mQACHWagqZEmH1MKtSnvZ4InJKjDRJo1nB2HEzrDnKQ== 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)(366016)(1800799024)(376014)(52116014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 56MGDparzE/kFwUg3WNNavsrCbKszIdeAFdpb6VyOmB8MaCqAo58fIf8seMgusfICI0+qX0b/CYqArzksZBRdwDf1A3xKZIx0jcUTDepF6PGOOq5MvKR3QsHT3xoc9LJdvFSFPcGwGrjq5+GzmJeYr+hKCgvVHHQ/2lFSp6N6HEfWmTMRWnFxR99WmW3xsr50HerdHDkx8t36qSl+LLvmwmnZ60j5fmlvsaASihBs2/Nmi3qHcByftfHyf4mbsHoR6M5xO+C5c9LY/Tz9/cvyrciwa9HPzgmz2+8E0IcohDN+mjJlO+hUzBmZDRaf9A3W1dDxlGRoTmEIdfAm3stkgO+BVmhUItnWtRz9Nwd84WgXhH83mfJenycx/b0RVrVfthTjJvVtp+h9XYB7qNpRuKvSppxENJpqsDBYui9FL2fuD418uxSVUS8dynmEbCJlMiXPxLKz2kBs5lkW/XgnpKjH2mDtRcymn7+RQRTzlaxBdCJMOAeeg04GqC0RFC+vw5KGvcarj2Y9uCkjgz0EEfuXdh0QLXusyQaNvUjBs992l+Z6x6pm3KRymZpbl1xNg2rbnwIzestTsjWHabnHBsq6fZ0U55dPnCiFPnXA10cyhXue0bYgVGAcSbLrTYpqircfh7lOGw86tzE+FFNs1oNex8SRLt/trbdaM+8NgH5PcjqCDcNK2P7CjQcLBTBBDHE+c9XjxEb6wmNskpnyxgOBNnnajYz54Uv0/hKct6+wBhmbPLNTcknoRgAWzQ+3P7rD5ZaYA86jI1xYDxkmVpXuAhSgnMCDbLR4aFLX6AHSyWU++vO7vNMtrLh2uEGhuPqD5V7e5xR7n63zPzRlGtg1HFhSu9E39Mdge6mEaDG3nGn5UBaH49TgKlqxHgVWwnQmP00zZvh0hG9bqthe80f4me3t5Wi7Hxr1WVpGXo8f0KiOWaJz7Chnd5Kj7KC3ddryjYc2ncEa4bL2WLI3dsMsIs6Sq7y9na268fomUqNYoNNS/aXXU9jq/EV/dCG/GlJn8mz4Oa066GGmvQXeR/mf57Qhrdi1A+74b2kjQzVPwSwr4Uopmd/e9L04mGs6iTQYeZbVl5RnCfaoreUjvMDeOgPjHvAP8yEUBRFg2RTRN8EL0mkG++7nuSALAPid9gI9iqYRo61wR+ekWC4bkxce9wcBjLO5n3dbkbh2k8sBGpIkAAEBM1qQJlj1iwSzbH0gKOpoElyN+qTDVhR5TqbhxPmWhCVa5OuKmojXRWNZXo/lZwLd8Mt3I9XVD/JfJsPaPDKUetPmEoPBo+qhFyiNQcfgX2Rt7Z/Z2bZb5QALX+KHlSHZxIWB1FZAVZXMv7pd6LXRs3Iv4B9zm646PhmfN5j5Ewx3U24jatD34UD33c2ZksjH66rH2f45KrAa4SedJy2qP6eryc8qanWUc8Nm2SuKTm64/vypoqLRhWnUgtXl8um4r2FLtZgPqwcHSwVJzX01/E50ULldxEd1Lof04IV6K4Hqp002/WLpC5TSjDdyfj0qKkz2qXkgHwgWwXjtyikr+utVOdkINJ+3flx5SqD1cQFZc8cvrRsJ6QhzXyqHzanls/GXzATpvTs7OyLX2c2uFHHCfo207XaXQ== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2fff380-7bbf-4baa-9eda-08ddc9303d3b X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:38.0764 (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: hNLOknLVSgrigNa0MJzUWf+VgWxs+i83RGJa+fLYdplyKO/pSEFfn2jR5DpDx68+6pGtMHyoGnzqafxW+sH6CjghTiqcjHjuHVzRzHFkFgQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PPF4AE904FD9 X-Proofpoint-ORIG-GUID: Nz-vq3rlKTg1UCJeMe_9z4STrM87u9wB X-Authority-Analysis: v=2.4 cv=coubk04i c=1 sm=1 tr=0 ts=687fa722 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=t7CeM3EgAAAA:8 a=A8Pz68axzIWmibrE1SYA:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: Nz-vq3rlKTg1UCJeMe_9z4STrM87u9wB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX+3V7wDGpif9V Ts6PVKsExNqF2bC6SpmjFOZQADrTw7kD/PjWAm5AEnxILSkgPo95Ac526xBo6vxcJ0fKwIh9ew6 vHEdjl2XeJsPpEDSQPifIxjmhYyZD0BYkn1A+5Efy6Ax+kd83FxzSWfHfI4ICQzinQs9ZgG3R87 b+rgPdxvOPUJPpQHQBfim/KPBHXyzEO+n6dh8zCKJEb316fjwFLU7CPqcUMbi7fYhUhGQD1ePoX PArNIs4sk3Y3QlyL/AvTSxWIT9SC66k4n9gwBrFhrLbDkMSW6lhbJm0DsU4SB3Bw4PLA1x44XZm mCY4sXSm/G3kCr/qvhQofhdCAAjBT/aYrbdU8CNSguLWuHnI/t/IJVxkzqxNLo1P0BXnr2ywAiY wm+D28Yr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 suspectscore=0 clxscore=1015 phishscore=0 adultscore=0 spamscore=0 bulkscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.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] 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. (cherry picked from commit 4f7b051f8ee3feff1b53b27a906f245afaa9cee1) Signed-off-by: Sunil Dora --- 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 cee1968756..47e834cade 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 Tue Jul 22 14:58:16 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: 116781 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 42367385B532 for ; Tue, 22 Jul 2025 15:01:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42367385B532 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 9659F3858C41 for ; Tue, 22 Jul 2025 14:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9659F3858C41 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 9659F3858C41 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=1753196324; cv=pass; b=nexmqxVlzPMerHpM9lVlECIOiuu5y+qnbNcyVwT+7ZuTwWGVuVd+PF6wrVNWvNGBc/X/N2Le2X3pKBY7lNhMGe7K0MVBHXAWs+5ezVOYvyzYE+s2rVCO7QPhHwI7NGD/lpJGQx+lQc8RiGjUZ8SOEM/aqWfS6xxAtoPUMzbwMWA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196324; c=relaxed/simple; bh=DlIGhqvbIZ6FJeFRu1eZVwY86mb3bNO+cgnVU5vai0E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=GToz7aVWHNXDRuOK7ncR9gB9e2+iaoD29MQrZNHolCt55mPx+CoT45qUxBcPOBM58jQNfxyZ5sy6w4Rk/BwrHxLQefXRMJcthF36rE5zIU0x9V15RMPu5QDlFwqBq5TnUkzVh4NA3u7h+tJCzUNk/OR1XwIcnBovgQU/NbmBK4A= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9659F3858C41 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wZ3558072; Tue, 22 Jul 2025 14:58:42 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-5 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:42 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X5OjYPWPfh52jLCF/kcDxgDQ12ckKqPftX1dBlaWn/lzg29ops/OC4ROSAxN2Z5SLgtnmBHypo5verNWD1TYbYZxV1KHDy+JeK9C/8h75C8uX7a0rNQ+oSt3OoJFUdLZh+bZu84sEuIRugUTZ/U1jwkOjxrGMjqDZJObwkTQtmCsme9hg8DDqr74OrXzvV8hyK5fTBJyuHnr4NxNkIwt7W5u4H/kGMpbAWKo/22VS4LxCo5iewNzksqMdX+SDb2o/dGXgB3Wh4wrS97D2hunGVgIWuSk3SI/irVB5zjf4865lnak6a+HRxw4nlEUvpYGQl6DxBoqCkce2vkDiyZ1Ww== 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=AF+ZbBx5niUDHGknJN4sNqqhQMTq0G5L4LqNo61qlPQ=; b=cxN2DE9rFbe+MVU0sILjhHOm+N5rQozf1SZelCeBUOVMcdAPOF0dB+q6Gn+ErLEbsfqQOzRpi0FdJtTOxdNvZryS283fGFRzuEBpJjnLtkj07GfgkTXrn//s5mf4asZM5Vfh53bTcIusSK2JigCvzrbkl4DSHRDmp+dKrnEUFM/olibWmCqmr5t4qFr9OQZLvcK3E0nZXqD3N+w+5j2+7ttKDXLUnCx4iHMY7XESIe03iABqw9KCycKJWKKYeOCjkIAbQuNeZdaSjIzD4o4LHCGD3RJvYaxSClHtOHKV9QuGp6c7a0miSUxSBcyIsNGVGViY58TzaXKTbDSO5WwYlg== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:38 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:38 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 05/10] [2.36] nptl: Remove g_refs from condition variables Date: Tue, 22 Jul 2025 07:58:16 -0700 Message-ID: <20250722145821.2214847-6-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: a020923d-5885-49c2-9f68-08ddc9303da0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: IzuHIRU8zOWuUDZGTwJgWDBADFZAKBWhqtcA/jZih3tCof9lWwGu2kLcWV3PexrjJ0pNlfeAT2JVuTZHYeIcJmad7Ks4GnUVOspC/KfT7MsKCgjP8EBTy8qVi/D2rSsNOEolOOcKuqlpwf0OaqgnOb7L+oCe8Q/fBAUFk3MlBH9Z+q7XE23yAH8qVgE4jqQ7eqY9Je84uBn7hSsxc2GDpdS0ExpgpBwtAGp2PFTZv6CD+7POTHGFwqzLylokSTOp83fiiparDL1AP/jZQrU84IYQE97hWlYozxhhPKd1NUlGcXIsOlGKjwJmfXD+bZyEh40W9Ma/Tvk/KvphXU3aA+lrNbv/zorisgfYG7W03kaWFDK/LPygaVt8FltGUJx507MvZWdXRC6jMoyLnj9B1amrQV9ow0/WCSEkhD6NflYRZh/xm+fllzKQRZ2O3gvVv1w0od4PwdRGS8V/QbZGpZ3vO7mV16RJXtZL1auW/J41hvjkEnieoqQXxdUJowLPCB8VFBicFztjPJQkWIAaDborSaxBnyADs2Tm3l+xoseC9tPGombrqaAfZCmVawO17L+VQ/ilmPGXcPPlBiYLouFKjMquCWQE8vzAM/YJXozLEXAhwVjGSxP5tus72XP3WUsCEjuFGbNNZnN1x/B/D+exKhC9Ux8CJQ+jsKb0xbVg6NRpCg4x9YAAqnpktB4MzjEeLGpCZ4IvCdlXyIgih7Znm5u7gEZqfu26vdNCgEFyYdvv7ZkWrG7GIUoRPo9finZ7+gJs/bU8gGebzhm4oisF4IAi2Go1kEFR9CNSQgtBNxOqi9yX3d/jefQ+qooZ3fl7kxrBAkusdOzkaa00WgsE1KLIz/ADqdBbHEvTBybZ9Ba/E7Ml6KfzP5eLztMqDJCqfprGaTYeMQCwvxG7LSooLR2kLazUnUUFT0k3Dza3P0r72yHd0IKdbznjn+w8PeAApCEpD15b3wcGSD/o0Ykmtsr+YdQ/BDpmJ+ecZne2dx9Kzx/sq6QllVitDFwbJoMWmvw6mLslwYdj9QKplUXdsN4Gk3CRoTMRcmB+YmCECkeX1fgqRs8LVlwOYQEA4Wtn2UYzYTz4SgDY/yFUpYSb6ZvvvHbbuTgkMlPFxb5f27835ErJNBGfOGojSf+YMRu7V1vWBGio9cWSZR12vLfiHfsLlEiiorgGacy925C9SPyk8oOOMzgDik/xEbCol9LGV7JD4Cqmff6fv3Qv0GJ4k12WLtJaq4PEio2di2LXNUnfV05J9fPbzBjFA161hnqpp5Xpa8mQmagnQcuZyBhqz2tjzI/WoD+2MfgP2NfnmdvyXfgK32jnLh288OUUNd7qYzCc3nVPUQU9TWd4umsbwWnDd332hDmnbYWkSeeYoYB///WXbQJctnkh68bpvyAQpL2mmNu2Sg88aJtSztK36GsvrLiqgOG7AZbFdFuTfEoYG/+PdJopZL7u5z9SiiytPXm16AmuO+4+Y+f6mw== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xQ3jpKYfgGxsQF8qD0ULmA8tsiEo5PLgQkkdYYDq37RAiEzQAiHvFser+iYWOcWcYwkU5UWEH6YRH1OjTJS4VpZ4TzVj/294R4TlVfS92uXpskwqKshaBqCooX5MkUMNaovZqHfMSmod8gZdztXiTtxW6wk5F356xgOleMXhI1evRLdr0iUtPsNoRiA4Wps+mM/i7bjrMoCrBmTSNlFpwDUe8d2le1cbrgvHcQnilgs6OGUUzS0miP7t3dPx3ZZG8JVDJ+QvrcTqWnfKlLPfQ4s6yqlM/nlHOkvPmD3J++wtj53U8LiulsyYLXcD0cvKz43PqNp1eu809t9QXj6hAsFOjHtqpA5+jgYFZv0w58oGvMhdXY7LCBz6s9M5+uivn3ZAwF6nAdRq5I5dUx8N7VVqJYZplcQ6vIEmy84FOsWpwLpiYaoScmz8o5pCFuscUY+90vT6Yky1T7Fl29XFKymXPHJTiuZH36BFfITn5a5AJeclQVRNNINzZMVHAtFl8Cj2AdOXbsn8zeCkFA/IF7S7MhqFNIqy6VqePF9IIc5sY/VA95KC7A6hcN/UMYyk1CDVZa3q3g5FI0oad9h72T1s/Cm2Vb2DQI1faaUOVAQt7uOjrbWGCdz6KlS8mt1kimTPskzQtPrztsRXfPA5y+/qmrc6oZLPXW7jjHv2cokc2T3FHvFRB+vGTelT4am6vhgRTPDdcn63For3Xg35VWbJw6eJ55hz7FqFw0GSt8SAWIsG4298H4jpOyr9HthEAB8d6iY0kwCeH7rDYXkmjxE1uxmzX9OVfiLLojE8RM3HIcIUQVosmQg2M47avse/E6c0jpDHdoMgCpekWQQDWGQaDf/epxfN5M3+9DvTNnWxeQ9sLFpS2fwVSLnGydLy1Ugd8gd4A+itrRPcFVZrwMVaX3Ru8eYarN0v2l6D/SAheNvQovEBAxa4vDs1SLZfUsdihO97sefPxhITM8u203zI0fP4AIzFCF8dfxpYcwJ1V5M9ZLM7ZBuHFSmY2iVY3qOHzwIY5NagR8s2kogrR7zH8jMzXklSAzxdWKWsnKSvnmIxdopC9w6XyDRFZhr4Pdg0R/GhEpye+VAtPrub9NvR7MaLzjQ9VMV1iNlZUM+KD8DQrnv4O8SyAYlfMVLvxxjtYOShobMN8KV1n3g4hQ+TLqIe4d1HTgRzKQaO5frISJcXg93jnwHxgVAEltBqCcXgXb7BaWBmcMUJUZ+nHTQ2pHKD1l1p+051i9aPCQP/Z2WcqqFYz/9UAbrts78Dsi0QUQDmTCT+wr3H6f75Rrf00MAnagZ41nM+ST4slT7nld45O47J9BZEyqLc4GB79idZUBIxHx2jmSse3NcLVKnk5WNBGatg2DjcNdpYtAL8g4t1s6Zsu52CunBQvuu1r7VxokYR5K5Tr/Jw7rwOjxpffdTCxT276DUF8rUHCBL5NS5dGH/wGitydVTYxR+MAear+nO+u9gDpV869IH+r/XCgnQb8/DoX/kl55l8HjMYQNYdP583/4pf0NCY7ZjSnz6bd6uy7vfLXob0Ncc60WStr+zxHfaNKIobd4ffiCPPweP+oy2fzIyhx/X3CfLL2EfS4mwUF8MNPtKfus3kug== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: a020923d-5885-49c2-9f68-08ddc9303da0 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:38.7717 (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: 06Xs3k24VMTbLAPqy/WudpMkgXcKJuHH0h2LqLzQ3xO/XF7y6d5TOu70YPfSu1zb5bz79nwDsgYdFP4SsB7PgHbmEZBJLSkPi9ox88p+GVI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: aa4zdZmbwThX9v_9by-ztKLS30mLp7pR X-Proofpoint-ORIG-GUID: aa4zdZmbwThX9v_9by-ztKLS30mLp7pR X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa722 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX9itnzAV/cuyl JTciGrNUKeOEU9hr1ExqJgMQO8XM9R9PJoFNYnleT+Ani+JnTB8IBM1l1OC4yTrbZavMepg7dn7 LkzzYp4+syjp+khOlgMIuBZ4RKz1DshZ9EdqCHQvMbqtqQoj/gBeJSe130GMNHt2V/bvLhCXkaK iFrmz1CLNwyoeOHwkmMBMD/FH2He3Q4xqLSkkQ3ZLFR1Wy2YbOi6oGlCiZv0XeGnhPEV36GEbEG a30aUCxi6iSPhnH0SDtFnhg00npxpbwnB8vw1Q66z2omF10QvXtk53Hki7+eHz6iIK7Bbj8io6S dKt8p5hvENlB5zNpdycwY2pzuvd3L/AeQ+YgVtwrd6fNgM2mPRHpTIhryu9xf2iQB2kc8QW3j4s DoPGUQE2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit c36fc50781995e6758cae2b6927839d0157f213c) Signed-off-by: Sunil Dora --- 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 47e834cade..8a9219e064 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 5653507e55..6f17afa473 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 dedad4ec86..bbb365407e 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 Tue Jul 22 14:58:17 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: 116778 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 DE0593857BA7 for ; Tue, 22 Jul 2025 14:59:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE0593857BA7 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 C526D3858C50 for ; Tue, 22 Jul 2025 14:58:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C526D3858C50 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 C526D3858C50 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=1753196324; cv=pass; b=GmJKKqs292pFDMZeYKsZ7x+noSxbawCuq90STOKK3d4aX6ygfO/cGuj3u6zcoOXEkyu9rQOkhmKOdJkM9GJPCdhbgMqTn8tMmTmf9EVPgzXuTe/QvPLux5JBtLGXjAVxYGZxNzencJ4lZKLo4c0yXVkUwfM6FUuC2RWZ9XD8wYM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196324; c=relaxed/simple; bh=eGDnUx/v4NZC18GTSmt2WRLZ8VtNFqPycmNGalqDtCQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kE9bu0fCGxSJkJwhrU6rukuFvOS+vWfTsMqBZo0RrpvD2lhgh7N6LfLbeSTGYWOpULASLbDggXpah/gjdr1zlS2GBVA314/ZKGdum09/xTbGckcc9zgcnfzQYwRykmJWzf4qJqf7+EgpknjYiv/5o50T2N+DpU5wMTuJw/sAK2s= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C526D3858C50 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wa3558072; Tue, 22 Jul 2025 14:58:43 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-6 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:43 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=W+ElJahBeQ5kn34jG48VEc+JTb1vyiBmPu4UhobUNMrnIMDVQtWZZ5qy6yZwyop4JPOKeW84GpuQNjsPVuZ+49PMguEbcN9QJmLq8PfOuWkSsJTAufAIIv1ko9xVy/mSChfHW0QCy5og0G1djwq7QjX9nXk4EP5o0ZCUIrKUKH8ydERIpcE63+03FovijZi4wP9Yfh0iM94p6+9/vW4dKBlNWpTY+XFG9XklywSOgPpFnufjXY/znmfb7ZG8lcgUWMkPK8grMyvRozV7deOApLo6c8TtcHwoc/Y9ZXbqRhGctkRCABqfBBbGML8jGojftSeRLF8B0UKMZ2rwAz9zJg== 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=G5yBnlIGDV3KSAmi61m6dOg8PHjMz/8uXJD1Q7buq3s=; b=bZl3sq+fSfPkrIoLC4DA+n0kW0msNYcn6URD6XdALtZQQotcRbUFCY3baGx6tj6eWKNKfzbakI61S17CGHieaPCPEjIbGLTzBclHn5YE6TptXUo7t6qhWvOH3JR/VgKiq8Wv50t7VRrEjW3Ipk+G6vYllPIeRZOb27vZOjIj1FRNU1kLy5qu+kOR/wRz0AW/9uQ/kwOVEgbTjqn0reeLulNchG7+EBNWXYZpyNU6wDrIBS2siyzLVJZnt4KLBSHQCg0x9mQ5H9Tpa1v9O9TPQvZni0Zf/sO7HkoSoXW38DJIaVqhUEU8FmJQZFB0qRheZYF5fhWAj74qEs2rd5l7tQ== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58: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%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:40 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 06/10] [2.36] nptl: Use a single loop in pthread_cond_wait instaed of a nested loop Date: Tue, 22 Jul 2025 07:58:17 -0700 Message-ID: <20250722145821.2214847-7-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ca712d6-6104-4e70-dab8-08ddc9303e3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: LAzq3VZcF5CfKIgB9hTOdMrcDXIEAUmPLA7uMpb8w751Dzgg7i9qVG790aMnieDhs2A82gEy1tfP7Ut8aAh0SS3X6powhSp0e1/BSRChtqkfhE8LUpVSkSjk92Lkx8ieOYcs1C0zwN45VekzVrYGjXlMs7c9McGo8eOR6JcQjuY0/1ewZVgjgedYDKl5vM0rRG34xldBvySMMAqOKST6MSDd3WnQz54IWy1uL9Cy+5xkx0XdlXYBA9ySskCfKIdhHbsBDNwnQ535XSoXQ3UJNti3A9glSA2T5DLkCC5Ea5733A4cEa5Zk8O2IWXQgqqiH35I1GAiwhhUUTTyEti9nHWGPDMAAALuuev2Rdx9cEkFXQMoQacBwCegkTpgafpzUrFGx61pKngUXcWHxBRG76Run8slI4mWh5fimpOmDUc50D52/lnTrM+twc6UFl3gsNfQL97A3F6Qyg7FNPa+/zS2U6mWat0eZqoP+V0r8FqoiZYncyKz3okS4Zy4M5UoVbAoGogrmmFGPPZKcDqIDilxgI4m1IiT9RRR4k+rzFZZdB8sCMK7i+xq035V75Q6A93+C6wjCo3bvRWERXXXtVAuXIs2vkPwrvyc3J3dJtqUhNwizeCQGMkifccJpqUP+SuPkjmwhUN1oi6oVjBtC+M4+xVozDwr5lrTgJQjVrJmuGwMSV/BDonEWZVcaBlZGi9kgyDLfz0XH8FidoHvwgkbfuK35ehj/Rax1LJS51oJOKL1nPcZpjSAXzRe2BrY5bPdgI1sU2BQmySUgt4MYGhAfqHG2FBrZucm+cGNX3icJhoAYaoTl6IWQyDNdO/zS1b6GZcIdIoPFHVkHiKYFmEAW8o3gIqAhWMOliyOQBTd6fVn7No1CpUUSO0EQLlMnezcei7ZcMGFD6LOf9OpA9gJCxfVU/TjCH2BtBH7rph8/p7d3CRQbMpC4LyFIjpPajwi3gZ23rxFpXYoWxZICHDCm97IcfhhjiKFP1tlN78PPclGf/TyaieqvjfOf3/N9lXobqtbm68KOWUyv7XC8rsOFev6oE0OdTBSfhpJenFofTTKnWO7ff0nmjhKOUu/hL7pxfAJMPlPeNtwxk//VOgENeG0608lgIy5OTYbwVRSWfGAKOhqOFqTwqiN6DPUibXg/mmTeQAfzzx2PaE9dQyydyc7uK+mITqNZ9/KrkUOSYkCm+5QIuSt0IgBe/+eRHFJ1592eAm75QJdHX4SEme7jLVExPcHOHJinNREWWJec08YbtiPTBzcyzvkArP14OPE0YYdF326FVrnEIDe2aB+nD3hO5qZpF5c755QYKCoQiWyoV9RiYmq8LwgmmyhXpRW53DV/4w9H0bIxMlX4fxsix51FfIZLq/Fae9yq9lH1R1vGHgRgr6GNTBi7Jtfvu53Bdtxo8AJi+AuELB+5CM9XL71Us8Xx+dVzhy7WMYHldVv545ZkixHG9XGA2O819k2ILybAxWh7RQSB5SY3g== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k5EQsgq2QNvyN6yNbHnXh8UXu1KED/ItZNE8ZBIjCOBx40L4hOopmD+wRgUmQiZV6JY5mZ8NpORdmR9kK13Cj4pWNwJSZAsstnqhiDb0OaF0s8bS2+j336HPEz9qirrnDPWg6cljtFhQoKbkIeaPiRKZSTpqhSFvAVl1IqYSjrwT4vmaIk2/v7jq0zep5oJLISpsh43n4UoyS6msk2mAOLz7VMjTKYwcexYITLZW6ekT7ldgkzQnm4yJQRsGhqiED5IOPVOoxpe/oniHj5oi7RcyAm0d5vIjgIAnht4aS98Mm7jvjclXgYbaJvQb4vr579jUytf7dk3yx75Rn9CXsbKkEoV1sA2aBwLnIFdYhJKRtRZPyOgCt9KhGSkGY+6dLmB36IENI+R1liU2xjxlcFLtDmH7cfvY6vU9VW2OWkM2YhTTBH79kEzMxszdaLh7i+Xr+Zt/BM5uey07zz2pFfq+M2ByaRvLVYWbavW2Oj2QOEYh9KJwQ3EycvpJ+53m8yE1X0tmIEOdTmC596dMATsnWWtgOtqlVNiIPyBgKs++SDU7UxpE/TLlyRmQ5kMiNlWEcIdSOWwmvNGeZiApLlfOFve6wqiwF7hHxpBJb1HP7q4NclyHiddcy7pSjjqjl07IC19GBBrqIbo7Vg6ccy5o5oighbmjjnQVa4UFhpnBNYi6HJsmcJAalgnwMvDv4W2qOztimrG/lSyVfIFBjwhP1nlC0Y74nmf2KkGlFXV+uxX5WOlTmqi7fH0PjBg/nVaSPtMx38O9PyAhkzmx+wZbBlue5/cBHXyJOYE+PeCAH2Id+HmXwn1455/bQZRirtAmBMS3htjuKlrZO83145aw29FTbyPzpGdxKbfcdmvdR/T+ZXSa9RSkSJH5S7Zm8eC/YS7FdsbNOYr5E6TjOCxj/kuElT0n3LHvqwLGCeUyLSzxVFpXEwzVraTOYsyYg4WAvtwP4O8gJcqu3DfBtyG5y4QTiBOzpBPhlNnLezLPtiEBo98O/fh1i/fons+0di3rxQqAMmBYr6inGDyh7EsHxQP1SKD1WXXcaukHL95/6kMFXomU/IJIKNEJ18oaRnQX+E6xcrvefoDG+Vit7x8G1gdWnw3zsuX1WVjYtmRovxOqOIsT4Wu+aViw3d6dT3CkSe+TBQAblmms3Cnkj3XMhguYFr5kDMAofEaY0FtsWYXFkQmYjs/kFvg/juqOYKDbOVCXJIqCPM36k58rCEptE2NFZAVVYyWg+C+gzJTbrp7IHSMeqTKSaEO3eCCTJRmso69uQ56wMsxgyloNigOHRwld7en69dm5stQCo0dvGkvMOK50+5240sW0URxrbtmKeKCAhoDkU15KecR06f+FPemZdVg65FIHOEVw0HQ+vYyq/BhW4glH7i/C77w62oUj9mSrGUoCBoGeZkvDGg35FI1VIATHgbttuRX38cjTMqsfwFdC2NAJdRUyN+/vH1UIkvufpa9d4s4abm+5JKb6Ne9lgYVZPyqpfAlOv0cKb7nz5y+FvAbrD7Shtx3PwQm4zxCbyYDSwMRAu63QGvyqZPYknEGG9twCllSoxUonajhTKfXdmLhppD/PT3KT8C2aeSfIF26ENjBZaFL1JQ== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ca712d6-6104-4e70-dab8-08ddc9303e3f X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:39.8199 (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: 80ZT+/c297+/OAcc/jb4IuNDCS1ClRSNRrrI2IsL5N6VYzX4AN8ukK2FBX9OJf+EdGwdLi3sz7a50OYloX9/mrzTUmAVeaCtaRR8WANV+6s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: rq852jfQTcIGBhg7b1JgePcGBG2OhXk7 X-Proofpoint-ORIG-GUID: rq852jfQTcIGBhg7b1JgePcGBG2OhXk7 X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa723 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfXyBnvWAP5K1B4 hfkIsADyZBtOk8AdLdGPJAO1Me6XpT3G3HukOZF3loAVF8Gr0/jYc7/3AmnVZdm1lf2O5MZ3NB/ 7NxaZfWmLHf0ZthhNYBc74qtTc06kMwhbzSx9Fm8kwSEaXa3ZanLu+AWJkAtkCdNcBOE/24Gase eVDbPxd5Gk0XNmjGpbuE1QP8C9nr8CqgTSfYbe5CMoc0QRYyN/B4/axsJ8ER8NkC5VRZZ4/D2OS SGvQxJ8GT7ljeFgqHjTHZKUAXnt8Ubaq4WLJ89ClcGaCos4qODUx8oQDWtOQ/HkctPCLIVqfnza zF8aB9VSGx/lkyJ3lDsoeXR5orroPZwrhlarqPfuqPjRyThwdeY5G2r5qeK5VRoEuYYRBKvE7ky obu9jv56 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit 929a4764ac90382616b6a21f099192b2475da674) Signed-off-by: Sunil Dora --- 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 8a9219e064..c8c99bbf2c 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 Tue Jul 22 14:58:18 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: 116779 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 9A83E385B535 for ; Tue, 22 Jul 2025 15:00:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A83E385B535 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 8D99C3858C48 for ; Tue, 22 Jul 2025 14:58:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D99C3858C48 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 8D99C3858C48 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=1753196325; cv=pass; b=g8etz+9M75w77lVnJBXJQOf5M56wYeklmJLkMWbWK9+Kp63ob3yH7fisqqS6R7VkSEVxh5PzT8RMGFrscZTV6SbILsryUnXlO2pvEXKdYhw4Ea098XW5/oVdg12brZ/nygBobqwVE25x9Cly0z9Bta/D56gqF8Lr9S4lCuIlIJo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196325; c=relaxed/simple; bh=luXOoOLxPeONuUHOim7bRPFv1YOhLUfNLaSryPwq2Ks=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=PBmvV6B8y2N7r5FdFGpKTrbkf33UCc9qMHAlvvaFRFO/6WKyx8+UcA/hDO/xeC+ENVcCf9SUAV6PFmtPdvoayJZyS2FRZFfmAqD7lzvH+vOTDAP8PIxyZ8P3dpZl5+K3et10guxfUOhxkKU9F2Ox1EpKKVUR+8W+F/a79BghuO4= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D99C3858C48 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wb3558072; Tue, 22 Jul 2025 14:58:43 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-7 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:43 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=neYsqAJZ0NZrHZUbBdIlNKKYT8liLT+guUEgrfMMzVkdPoUiry2eGVnnahW9kH8VsBujyu/SOCkxWtEUclNz5eTWCqOhk5Ypfrgo0v5YcBa7fQHuuH2SfzWdXFpk4SKwZmOLwOq12W4FJb/GR9XY0UdVJjKRLmM5xunQ12Nw8/RSziAtqtNj+baurZlwBKq0qpwzQqFqHQPCXOOz0Runn/CgJ+xDxMSA3n/iW1VT7hnqURbWbvcOnyZ/nQehSJel3hCNA2aZ48qoZFxzdVfuMZjawI61uvO45nJeY+ftRgR05CzuZo0APY8+zHnlQ92T47cddNb2rBxYzYzxAHlQYA== 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=ZdBS2dlpovo0s7Ii492zk6DtBGQ1ojfjHHfV9RrZ4zE=; b=jia52aZqO3M50oV+WS6ZSacPhtsAl7Cxmzq/YNWtvS1yMysOVHlQQxzKhnb0HQ7FaoXt2+1bq5kD1tybyehvi1SFoX+5v0CbcY6WNFyHN9bTaVvUzPGD4debOxxpNUnWD/+vFoBrMSW/EHhCbflmcc44T0lxGuW4Kbndys/RxhDkvxLURTrj11roRDwvWmk9o/VOwqY6SXY3bL+SGfkg9MVSC2Lk9yLQZ9W0q/VHULO5VUBXdzz++5U+xSrbZmoovnyy1n7/FqCx636BvjlwqLJI/9zaDoHxgbaygKqR3BdFHKDtr2vwKf2PeA6sjRQsZfjBp5fd6+TJXe9a14pDlA== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58: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%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:40 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 07/10] [2.36] nptl: Fix indentation Date: Tue, 22 Jul 2025 07:58:18 -0700 Message-ID: <20250722145821.2214847-8-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ba96064-3711-4db7-1d03-08ddc9303eb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: FRPt7dPVR+jAOgBOojoZMK1OfyjQUJUADRxfv4OYtmyGS1qaxgrPkOnmlRyIIlHZshqvRwOKx0nxHQ62MTqyUeI2Asyo5jAr7ZO5BcN/d8ySche2Pfg/1cHSG7LB6fYhiLCcesqa0vcpCudOCxi2R91B6eHDc4Rqj2IDRNfxPQ8DeJ0jWBXEFA5lgbwrHDlpoiZL+Sll2iG7IIgSheszUiEvVc/AVhDYvl/mPXIBb8WAVIfCQlLw4cMVCo6b42F/9w4KN2oJj36Tcsc4jVUmqYicoSjPc/e+kYm0/D1d0RKGdSdc+z1D+U72HKUl5v/2ph6Ca62ncII19yk+HlKDoij/fruSoVqwNjMKHlvexv0WatRxNiH0gq4vsiN9WirQt3vQCHPwnTgJyhpOBmRFBUI/eap21Bys09dtk8zDOhSM133Hep9gZFtDGil3lNrut8qpGUC+/gz0GQWNkrkBJp8LYu4EAElLG5n8BB2n7YK9xzXfmEvmTQo6tga2s/CJwwHCs3meMowRFU9NHmeKbbjmEfdSlnEETZ5jaliTctPvMtAR6sDOFqs2hA9ZOt3U2YlRsnefxgj46NlOsIuDrocf25m+GwiWQSGiPBsAcLEJxfn1Jodxf3irHEbx/5w8yeDcX1Ybmoi+I2D2nAQeALDRgXb0x5jGqR7LWH5+kf/Sl5xItEt5z7jsU0F/IIHCrFJc6L5vHJjBKI4NFhcWE93FxA/WTW1k370mU9XSy8K6yBw/rRS//vPmd2vuUBiK1URzhZ+NE0bBhXRNPb8QskGGAK3WCOh/gwKZOtuXJTswJOquHKWsNbbXcDtz5qpQZXpbWtbCALoBWY+z3f2ltmOucEHI+My/5hBx4y63xsMhS5mXk2st8TAxxdMVWLMoO4rpgo/LQdOizpSQZGzwQxIvnxO5x5J8CegvPUGiqZ8yaM02t5VxRRGCX7immZsMT7esGr82i2wHSRM8E9d6AXzS5g9M7hXqVR4JQEAeYmcISUFnb0DcGayz1jSoNnRxzpa9k9l/xR4xJ7Aa3lEd0vc5m57NzDC0qsem+NFbScj+XjQAWpmBaB90JfcjqRZyg1nU5xFLcdb69u1gov7wPG+5iMJ1E8isutNnXDSqeA2IfSM86v9CHzQwzD3ur4wuiAZbHGdNcNs4lKaeFlecqTZykXV5GTxtr08YY2l5bgLQD5OP227hDCKRmfnpCRndzl44koyJ4J2SD/LOo44b0FJohDrXU40KY2shWYlgSh26AK83Pgvk2la35oMzTzgdtbhiY0lGSzhyM3G1ioNtFSZDupGulqN7D0jvutCM03Ml4q2NDMPdGxJ8ZScy0g4Y1AZoqRsAklqNDnmjZSHjeYEHYJHc62V2owXp1967zXdXe9fo3jVMGtMRz0RWSbE+WUfZI7yJCRqQ+dLpLC6KbVzVWRUALTikB0vteXA4rRpl4DrpXmMxMnPLncNywx2mFCDDMOhCxQcbiTs1SSFBnw== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 18OopKL8YGl87WhXEWvPwv+Gdn83N2co4DI2yeqau1jwEg0gVfDX70ZcHjy0n4vN5lor4sSC11CbuNjgGV6uF2iRNbyUWkvCxf2pHAtTy36bfk7sGNJfsGhaXACNyzR8WGESyGHP41Sz5DurARGHV4Bv//qSmE3ej80Qh78lgNI8oa62jECQismS4QGvzIsNWSq1apPy8GDl9E14nrBgQiiCbooYuTErqbVaN/fn5nVaIdbPIc5C4TRpqX1Qy8Ygwg5Td7OwdTWgcGxGZk37YI0M1+stna+vc8bODuh7KBV9h2xPRFq68rTMskf0ju+OdXcy82byKi4b8fg4QL7GQoDHvlNU4tzUrYC7nWVgikOnT708wuqlnRshhvvvQ4PkctwTqgRdkOTIA3VRPuqLxiZkA4Y5S3Sbz0sAEXDTWJEg0YLEEXSkWql+vg77achNjnfAbRTQ2jyWsDQGQnl+VrtUYGRg6PYGRmCRNX4xHIKrmboRHfWhDwCjrRFlbDW3khs3Iw7i4QdcAfGQNWQXJwZMZhjhlg/roAg93g5xLYkldGuuS6mcSo59uSSCLwDRtflmWR1lXmgOjUH6x4MJXhfEWDmXyTjawikJx/BITXEG55kxk61ATmFs7IrsFPQ2NDFLpwJkoPydvAtY4jWjS0ldfqRO2vu1LGRrkYYMM8cqRASA2qbE53/kuc8omS1jToYuJ7VX+cv9l1mGV9WZZwqdKvFiFZ5jDtDcCjLq+8ilrCIcEuLNvQAY78Y4Qlwke/UrGFvR6SO1bBSC21Fog4lJKWTjHqWkrXbVxnG9XXcAjiF4fG1UdwBpWWpL5Dpub3DDtrDM2XlrJkaIvhTGNLJ4RdZB6j4SQooO0lFHTQ6lpe2gC8ZdHlpsMyPh4zXocIpnpsk6yRtIeT3ls/qGg/NwGi3JuqJLUKykIPwv3s423FFBS3tErOad0EkW7FH9OL0M9pHqeC1ZxLaB4K1S8sLBy18qDI8DY+wTtdo3mJQC5SkR4fa78IrmeCAXxZlHF14ScBsmK1MtRD6e9L0dFkhRq4UTXifmAUUC9oKisMj5i5r60Mfi76qx0pZodOCl8rpoyc2VQRzhKpOakP8e1HBaVf6fzHrhY14j3q0taiGSF43uYo5L1Bw8BmHH0iLseawu9Kgnu8UlehIlTu2SGWS2QSZy2eNlFAL7ZawvdZMBHZimAX23vkmeL5y/+wcxt7Ir8SrSv8xistFxxzqtaNWORy89GnTyJGgMS76KRGf+3idP+lbU6TuQxnhn/IVshHP1utr30+wRqc7q0VTo7cj0hmlOaZfCtyRbw5CyTxFEP+XrrnmtcQc9Ti7y019TlucsgpkbWXVNLjThqWR/eQcHKyO6QRGJMg1tn+ygqYHBGjbHeJifqZXsQK+cMJweoSqMKX0hrTef237aGQu1vJAfSM0JiMsXwuXrrIlLhwmWBQaI3CGdtxiiY6KxLya2SPiy0Y2hGHSGwfBBiiDMRVPW2nUy60yKW47OBEx1nNUtbLVzpcNIaW/tyj0hmBUk37XN2oJE6OvYKHJLtIoq4rXLYrPZwBch0xfiEiPn/wkSofWoKJ+lOvHI1t6Vgl9XI4owjeNAa6zuF/jDfeIbSA== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ba96064-3711-4db7-1d03-08ddc9303eb6 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:40.5902 (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: orZyL5JOnb77WE2SHTMCEZt5gGIZXcqHZihjMYzbe1KNF8B+ifb51Sd/0Cj3kh7Pem+BN4tXbHnFmZiq2i9B359SyBVRC4aofuHPFcTDlyY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: uI2bPV7m-Qf1AzD5HPFa515bl9HTs3fa X-Proofpoint-ORIG-GUID: uI2bPV7m-Qf1AzD5HPFa515bl9HTs3fa X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa723 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX7tFa73g8Xrzm 14lsz/Nne6tFXo0mAFKh6B+AoEwAZcFnfLLFoH0EJ8hR0r7Bp6HsAoWk801qvxyC9iB19ahST93 eWvvD/2P7v49KM69QtbhE4vQMMe0vwSIvykIYzDwuYnVnN2razQ9/2C9wnFFGgbdJxeADwjkNYV dDXx6Yhdczwd2LftM60Do5fnBUc807WSJ85wOzYDoVkwzVvH0MOKJ/MhT5FLSHTALAUabrzQrhE ROWwQC/hqxyJbiA1PPxuHsScGT36X+B1epCb+AMEG6zab25hb1O8uqElWEyvh0dB6s3x0ZuBc15 eaXxK6o22FX92E1D62EdldiVpIRg48O5+S3JpHnuDMEGHOfOWUk3TtrSr1f4gTMtrLjsPHaaXmP DZInOrGu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit ee6c14ed59d480720721aaacc5fb03213dc153da) Signed-off-by: Sunil Dora --- nptl/pthread_cond_wait.c | 110 +++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index c8c99bbf2c..987f1c454a 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -383,65 +383,65 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, } - 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 Tue Jul 22 14:58:19 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: 116782 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 613E9384BC32 for ; Tue, 22 Jul 2025 15:02:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 613E9384BC32 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 3F78F3858C53 for ; Tue, 22 Jul 2025 14:58:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F78F3858C53 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 3F78F3858C53 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=1753196326; cv=pass; b=DD+epzsmpFS6DDUKqtVI7AtgHBldAEMGD5Mnbnhg7TNHDjbgZmmXjOckP2gyCZ2NQhBn9oMEi/iuNP/N6osf+SWDJ3TxlAt3Dp5iWCUFWJpIlbNS63cF3XbI1MWTRm0HtsYARoB5sk1IEX+4TMI4DLkKuRrkOxTziTdQC9cLDNc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196326; c=relaxed/simple; bh=yYJAM4EcS6FmNGo+2hVcxVGkvPpswVMIahb5W87Cw/g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=KhVWBvpO2Q6gMZVIMi/MHlgcNmi3U2oaacoZx1ZuZ2OkGpfbciSqLBXK3ysBHpXdnXqLeCka5Atn1v36TjKAWoJJG62uid9ztHcpqCQwvUlsfBIVZwn6zJJZIAKXdbaq70z+GJ2pdHEU3t+H0MALERtbZao2h6O9qDvPu7Vg3TA= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F78F3858C53 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wc3558072; Tue, 22 Jul 2025 14:58:44 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-8 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:44 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pZ8qzLslFuq/BIRLLh7S4rw9YRk8RFuvfao0CTB+1yHBD5imvHNeSVEu7LbQPzdZLGDiQGtPLRNz69V2k5NH9vP3bzZ4PWVjef4ktnw/CkM0gJo5jEp+GI99yBI/YM4Lrq45JFoOYCR+vWdNdb1bOb2PVwVeYryGHckRn/B5hWumRrCba54W/zJB0c7udxRTJmeFl3SM8YknKN0TYJllENt/1CX9pchp0VS+M/xK/rtlxXBCsRJGZEmFqBn54YqD37h2BdLaxomzNbaZXS/2SEv1aHzOh2dJtBpwAZK+pVjdZ4CmE+BfCx3TOs/+Zpwg9QZFhKhH5LnlBKFsKqGzIg== 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=yEvzTHHbrNVoplAYZNEDGE4RDMjYt9wkOe5dIA4+xfg=; b=JKkocYdZSqT6fz237O9bAtIDlD6RgTfgA5sm29Cfjek9ZYLbJEx5K/HQ/msizPYl12OJ8WU1f82kQxabgUDsJIuF9Csgew3JmMVTuJ3bB4yq40zsVax7Ck7GGB1VmS6J/vracnAWo1I/a0tTO5bsnGL6edgyUWEbXogEholm+wxZAC+XbH8Ziw3uoiTEbisPbjxMADXDtswT5wpj1IPmygvP5dFKcpMruqL+KXacrWci6dbp4SLSfnvjX1isTkQw4jlQLUaVp3ySd4PEQyp09X14iuMRNn91R+loJQ2i5JfwgSBpsdPlxCmnbMGJwsN+CA8it0zFndqJUiPG8Ja5gw== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:41 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:41 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 08/10] [2.36] nptl: rename __condvar_quiesce_and_switch_g1 Date: Tue, 22 Jul 2025 07:58:19 -0700 Message-ID: <20250722145821.2214847-9-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: b9d4f953-6ce1-4d7c-1410-08ddc9303f27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: Q5KZOspIVDcD2TxAzk8DbWhxURfo8hY9zE85jfXlkOuSv6wVYWDmyJZqJNlhw0GNLUFPhslAohETVErOnkx6qVPnIbIlMF1p8pxbVY/0vO1O9OGru9kteDBL0t+EzaRz1cWUKbNegJWTJqYigX1jdZ1tKHOCV8Cqu8uyjlfmRek9ZKnhpYJ9bJaczXow0KzP6DRSbnY2XpBJGzFkSO0AeDx2n02dIjI4KEMs1m/AaX1bRmMB1x4ib9LwVW/s6m98vybeSN+ORSL/8avGy6qYL7kCaBHSQ4HLF066/6khdDcYoboiD4ustU9fo7iEgrqQBvYnOPhfrS4WbjydYy6xhuJsPrm2ZBBbEK4B2rXg+bgYHKyf97z8Y24uVVb5TmO4Z2YQ6OHSod54gj+MNVDnqK9l6LAzgX0T6wR9Ed0jBfFrWfy2nVmH4YTifZxoK9AYDImCgftsGRp8PWJjTw5G43a0DJVLrzMZ9v0fTLqKKiTO9xNrzp8z/N8p4MFCEpJmY0AjsJAGbqeJuYnh8gSiP5nZvSBxKv7xYSRkadubrzC+MIIyWzO1tGel5KZVqmTMzuqOeyYSsM+DY7JMdL7puastVF4PZGec6efzAILfLyAvemECEB/l5D/nBe9Y+mouHSqfX4qSqBvCyVX4/h5Wll4ttTTiAfxz+Rkux4FC/ln/jL6KlJ3r8ZiCwpGwtJVxP9gkoSiNza5Z5gwnJQr0i0HLJtEcIle7UBE2TAb7rk87La7AiJxhshfj2VM4rCQD0p024khlNiOq8Q8ZI/a0O4Svn6TcWUcKKWK+e3XQ8NGl51AbKE0Zv8qHDnwpyBCuaykDxcG6SObS9uUmQTiq8drrvbol1XH0a4cjk96qzDeRYyi0s3l14+SwkWnE0eXrkXdT2TbaQ3QVcpZZZMSkuDtWq02Hki1y51DQmRkYfScAX8O5cGvfGoZqqe6XdCSrdwGeXc2hTzltV/9wtLJY6vhLT1z872Op8m9gmFPk5CtvvXsUhMyd86HOK3/uwXxe2X2VOI9o6jlgv9msF7uZ+Da8Ejel7coLf7m5j2ZOMD38c3XzcL1XDUDl647HYAbq1bVLt9Ge34p5/bedohLYFQi4wRpmQQ23FnaK1WkOLEKnFNjHf9SYxFTiGNvakxDYXWPS6pvdK09vMT14HcmWqvKRF2Knx53Eaf36Ijzn+t2rkma8B/7BLd7pGmkkZI6OHhqg/KMUePRfFMKyWeeMSjPhrsc47sLqV6/FMjj1/Jt2iElEdxyeOwUO1nk1TqsmGBGWbO4SIY7ZgtvDuyodwF2UdW0xMrbAJOf5RSgFdMlFWMXcsX7IfkO610CL2JqH9/3pIZAjsG+wN6FZiW06O8HYn11QrwajXtwOE2d4seCQi+2C0YGa2VOWkZdouuq59ejQ9VpnwGFaPNq7n9uRHO6CapfBI+2p9ranBRwt+zUdyw7qW8jwa7Uvhpwm4DZNZE0n6tiIUQkSiht3kvl1gQ== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EI8JliYfwqGHNvFvssQerTb+SfqqgdhamSkuKXZ9WQ7dOEfebSbzYP9xzLk9MGuESVTBIdQJCZajLWBSREj4HnbNr0NgxDc+zMm/kagg9m25bZZf8ix2OBViLgl/AxdCZWa2KxFu3oPiE2YB7hvsBOJrRj+JaCYv+ZaLEES794704mJaUw08lXIGd614EJFj/mGCf7iib7QGtQgoj7S1Y3Sxcpqi6EIi31CmgsTareEmMGxT6+BWBFvneupZPe0KXjd/aLpsyMW+6TPix0Js9VNyxQ0rU4BeU04hEdAVXhoQ2spbIklZs+1PNKHpSS76lXJb2MOCPAM2fXgjVsE/j1aztbbhKiPb2/lIZNxGfWv6xV8LgC9hgzaP4SUM0xOYiNnPC8zzmqYmnuazynidpmWr5PhYUZKhZu9LJXRV8f3NQyQE1DFGwlE+fQVoAZA0G+O+6LFuyZF2YJeKZ+S3EZoAwxDLMz0J89PHPKBEh3BVbMUbN9+MHgQ8BOlAAetfo9YdF4NW9zMBaQm6SvIAtKZE/N0vrnIZEdP+Dwq4nAlxcE9GqRBW+94rOdFH7QmCGZJs07DwMfp50GumD38tSD7zbMNcKBmxcl61OHOBFXut7PQ4s5xd5hb1fRbZbxZgLnYYyYF4uO9lu/9UmnRIfSw8x/PJHIY2M+yhKu3IHN1htma5mGEUa1hTovaP/bfiCll7U2qiTj+ciX0sGcyJL0/757ejpTJg+/77/gfc3O3DQa9tXCkfAm5nuUUhTqKB0dDGekj7XlD69yxvG8k+mi5313rqugvexte3WkBD9H0DCRCEtEGBagjviVS/RX5yQYE0jcPI7oeWypSwnn1479vUWzbaQd7yC6NJ0aA7giuWKcDuRwsDGuDigoEbYM3P7ZkS/do//j4XlOPjizaZv3ZvAz3PPdbujdJmJ1L5WooUqDMRk4AYT6WwO3ClfOQ+z0dBJvhGVoishqypLSSKpYBUsoJa13kEy3s1ybQYbWYs8Bb4yltLdV6QUUi7QlCTX5t+EnAmdbOnFOSMfxofdr0F8OTYlxh1Toh5DXTtWJQgxyj/T7ufSozSebgTf32GLrTYv5T1Y3a48POXf9dzHEzCNk/mTkQDSNvrOfdd3fgeMsnHKD27X6/07XtzJdk7Dsun9WGuwUafDq0PnSHBJmmuSi6h9YB6NnAyXcCQTSRlifjs18aTZRXXEZcSbmTQQ69ozNsbk+sTxTiw2Fd+Xv09ypG6PyJJC/13Cq6Xj/6LKQTSpwvFMMKf1wMIemuV1L6lTMDoluABbxydb97Rq34DWgWrdZYXZKFgovk1UoqCLvpBnVab/YhmvC6rcnnaeSwDNVnGVyA0APywJS8SPwrqPVt4m1KcwLXSDtEHp7rqcN1dYIs4EpTAaA/R2qYQVNSxSGEgPBKeKJzobn6QcCYUaWuryLBhvHaijaHYbpfDZI0pcJPA8UcSbnncKfdHe0f/cdINaC8f8dFbupeW3KLLnEJDBsMLHg6xx7bFfX/XvjBu8gf+RHcj4Gy03KIp1Usg4PFMBUTvzk8gABmjxktZ3v37OLVYEr0+4pL2CKQeK20CzRVaXpoJWxjRBvbwbbfk81WkVSxs40wzFNqogQ== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9d4f953-6ce1-4d7c-1410-08ddc9303f27 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:41.3942 (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: IuqS/ukI55fORymar+TAa8ijkOTLeF6iVBxdQS2XYULhTAMzMBQ9aeYtOpY9E8jrtuVYvpMirmfULYPQasbzXRduqR5uchctw27J7VM0jOk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: -gpWGUOkEtDIfnUwpYHGm2m-AfadbH_9 X-Proofpoint-ORIG-GUID: -gpWGUOkEtDIfnUwpYHGm2m-AfadbH_9 X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa724 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX5/aASVHk37Da 8kdZ4IwBTDtYVIEtpB8Nyw65taUOFOlRCxnySSrj0pmvDS1+OFtwwjjoYEWoqyZKZUfGpQN4osJ ne0tKRSCFqZMwP4874WmmxWB/yZUu2IflFaj4i8oVtBdHF+G3sgXE2/5hwncX5lTpsaxXGJ+d/Q GFI7+cgZUq8ipfEf/89h77n7CnA9CG4H77yGkcrRY4g/fZ99LcvJlqsSJN1XogyGHcQKXofsl4N UuT/E88dI8lerIFHc984bb2OHar9hcWPAsjyg0XwHbplsc85c8OpFo545ZdynitpY//My1F+UiO xDqLcU6ORGHt1FOHj3zZWMLuHWdsj/WqUG7llp0o84PonnDlUyCnLo2Mv/Q06G2mp8hOeNTKTpe 15qy5qju X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 (cherry picked from commit 4b79e27a5073c02f6bff9aa8f4791230a0ab1867) Signed-off-by: Sunil Dora --- 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 5ae141ac81..a07435589a 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 f976a533a1..3baac4dabc 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 14800ba00b..a9bc10dcca 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 987f1c454a..1d4213eab9 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. */ @@ -387,9 +386,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 Tue Jul 22 14:58:20 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: 116786 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 ED784385084D for ; Tue, 22 Jul 2025 15:05:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED784385084D 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 EF21B3858C39 for ; Tue, 22 Jul 2025 14:58:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF21B3858C39 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 EF21B3858C39 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=1753196328; cv=pass; b=uAwwNifm1UP4O8Y3MfXCEf5WMWlI9folqHU2PBx3b0zw3OTTTk3E88LGu0tfeCIzoL8NqotDnPLF8etgrsHB3eYGz0nxELbHvjROzMc1ec4pAbYFNc+amNnJ+a+o0FCGus7wjCxStXC646KUNXX5/M0w9ruFTyTu1+N3J3tjxd4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196328; c=relaxed/simple; bh=t7bvbUNrjCiRXvutiNiKw6GcQoHlvVcJeFTTxbQzMc8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A1/dVbMxaMG9dtdVg72LDS4NitmkLvKByynaaEKoyvXHFVgiMztnlg1mXIG/XvtphIwxCN0rVU4noxSEsPt3pw8k5DT2yomE4QSCmUGjSEbcdA54uUJUJP4llN91ijQPLKnJmRWQljfI3/lsUcHq06C68A8eZELNZgA2POo1stA= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF21B3858C39 Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M5f5wd3558072; Tue, 22 Jul 2025 14:58:45 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqu8xc9-9 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:44 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OhF10GylFq+TGRKgDko/7mZZQYvHNDvKrjQrrflZv6hKXDRAxh/ehms171ZLWSmwt5KRvEzvdUlxaiC+eGQlCoFrsurCQNC2z5aoanp7Ex96rbJYkm1+OOBC4b9j37SknWzmF9x9yuHsgfaVNzZoNmf4qGSa+7kUMb3vFbTB2S0RX9fKwn1fux69l8Xef0W7P6Mxiq7Wyrir9nREmBD9XXCcKQJ7+rHhgqo/zQ3vq0p2D6KrO2sSckKYGMWCpXMTPIF/3iIXcA/WT8sBm8+CmaHv0dZ2X47jAuOheI+Apix0FjQc9TDkGOdVj4I5cHHCT+4/8VHR0GUkq/3IJA3UyA== 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=j2DmjQrnjs9T82nNpAb9rShu8lA7HUGXIiNmLEM5nPE=; b=v2YgBK818F6xsKi0d9YsLWNDu4SrW4x4IZI8gDKKbd35DnWJww5Ny+NTNGBFJ8qa/XtDlzBQRgyTN9XDzN2HpbiBtXxRUrRtHv9EZCfliTmygDQbmU2QqIq4W73ImOnNfkZw6uMhWOGUatHG5niTz0fPyQV+b0D2NzYeml2WDslpS1x+EXqKTmGtLfA1c9UsEayvxCfoy0/ZQtctX5vPfZD294nsH6n6dBcoKetNxiF29xIn4PLWSbmNOfINmTjLaWxgAVss0F3W44S4lf8Lp8WCKZEh8lVH1dK6RTb9D7HX+bPLmldEOnycoQuve/UP8raqoa5v81DSnwR5E3zX1Q== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:42 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:42 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 09/10] [2.36] nptl: Use all of g1_start and g_signals Date: Tue, 22 Jul 2025 07:58:20 -0700 Message-ID: <20250722145821.2214847-10-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e4034d3-9687-4857-2193-08ddc9303fa5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: UggwJ36FD3WpG89x4gCDFlGSGB/hPTqCdA02pYm+Wag3WbcqwSwgDuDK/0QYjSJOyh4WL95cWz6knebVB4ULEH0IHwRa1/RO0E1HVR6w7at6SN87/kNh6kp2aaGLugUrdNivclN0tKeJuY3ZbLySADWvy+z2IHxLtnzoVMHAzliBiYgm1ikAcB2/qU21wu/sijJXDwzA2k3MTGhsLq1lbkKA9CAPh2i/Vhbn88cQXQS9K8ldSq9aEQwPjoXVceThg23zP/os1D0mShPVVAr5Wt//cAS8V9DJ3DnN5hO+SUrpfTeoD2iQVxO8a8xNoQgTPV8DudyynhGInvwCq9yZQc5ueyxJhMVb1qAd0Mkcrha2tynaZQzysSZ+w36pE/TWDYt7YwbJ0PNmntSy9ZNd9mmG27UEK+D6HvrCUYR9wJ7VaXqQAc0hiNtO2eafSdFFMCOlhuruVyY3Lp7XILCbkFiumF2XgOlK3woUDNr9HTbtjWF4xCf+5zmPv/49jdIwblpghNzRAy7SGtY9n8qNXXgxvRF3rGpFSsJCBLLVeebkU27EFcT87GTB0Raqct2l9MOkvaPlWAuEx2Rc6mPxbg+emMTz6EiTDVTF0JSoTjRTMaunMp8f6+XmurtrjEkqmBPqndSSSiH0MMFmmvlDpVJJ6IfkNQJlMJB5NL2xmqcB60+saJ8hzM6PcMnCz93XEcnfrE1533SkIRSkTlUyO+T5WjDMh73Zkc6/fYsW2pBl2VkfRNh9QAOz0dZiQBQGw3TvPTRxeszYJ9rQcs9+PeH/c1MjlY+oi7g6g2gJEl070ZSF2HNecc4bhfSRFZ6WI7kDAj1R1IPIU8ZOlYuKtmNbRTILwgJj1lrF9QBeG6bYdOtZn2+esNqr14jOPPUIpOjMf4pLznAxJ3YpOSgpDgBXi3SICksWZkJlEzjWibXxlEunCLvTbOUr2l7ePu6SAXzKSDhn+AJSVy2KI2qkxtaiGaqPKC9qLP4+zkYQSW0RL7xu3NkpgNmgogBtytTrK2LaF2ObIF/kl9+jfxXf0MqEMpiPg/2H/aF27o3vp67ztA/5nLbkItZ7aVYrQmPv/UvgT6fK8W4tofDDTzxs+7q6DlSR5a/haQX97wimpWsRXNMLwiUfpK7ayd8kl531dEIpkPHEc0AQ30nUqMMfl1DBtbu9wDa7FEckML2EG0O/qPdgw4rrMJcRy6sfjRI40iVKT86xeiwPAv9JbYFNAt2U4ATQF+sqXL0Fmaix/cQTjmT+BqW4eJDVds8kJ/1IZeRu89jeYGbVQowFe6EYf8QYERv8CkNWNVgcC5hyA/7a7rAixS3++f7CzLXvYFqtDTgQzvNwpzHWOIVFcsW1i9mp4flGmrGj9Hxu3++tj3/DMyjrdSX8MPeASzZ1ynEK49XH+2B4o01u6NkCuIQZb2Z9JXfyKkjsl4NqH+HZ558SnnQJiIwihTxUjG4dC6dregzU1dfVDfLemBFvOCnHPQ== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J7AIrncNeKbz+Ju482Zq4BseJdkJe5tJ5iLhW5HalWXlEhpsMObG+Sq1SY58ghDqgrWRp90nRLypj0EAb01w4t3tIGkXf3OFwlotNUuvac2U4ovDjpk2CA6hJk4lhS2t/LaULp+5Zj5UPOpu5fD5hMOA/oQMntkiLb3Q99VWxlLylmoqzbEZGhgFFRUZhODiZTnpKgCqoGIwRU93nb8j8usqyF+13sMk0FYEUFrmo3Q9brGIaPgVGLKsmAvkcFfUyunTKR2pxDCFkzzD8otbdmxtqeshz+U1anVV6/tknnsEGO15MTSdGdIxWChvC4i3isoujR+9TaJYtU8E0I27vwJvi+XkKJ7ZDMrCMJQJ7Tn9XdRKwaxK9Q5pxXTzgfKt+ejJOpQrtmkn5GLzEQurXDowGON6cE8hg97SMrQkT4inqLGOCvSQ9CNQHv5ONQOyM5EC4D0ClawJLRLlQ4Vz0RApb+eQCuP2bnHv0jT1V7gbgfKy2/h7mLXz24BOQl9Fl/ZuJYDDu9FGedbm4ACgnWMUjABo9+/LrVmjZWJampGMnx52BRAyT/3oQb+C/9anhD46vmaNdDJylH/j2eu4h0VdzqPfoFQg8dNYfrZ8LGZIZPupmO0MiYTkqd/DHi+lmmwrUAu3mz3yTKEgxQQM9IjKkIiHTWBEtisvWUkz6sgEi/InzT3S372p0/QnyR4ZyfeNBSwePinD5SbFDfSSsQeR6n5E+ps0Mtno/a1OaoDwzqc5LdjJHP8kjeA8fqpeiomc1TIXj+jxybj+slgTug1Pdx35WYzXBjhKR+dvSys+rhXTGIbrHySTmk7bTIIqETEHpHOmOvIsqFIRgpXzElpRlRy4XugHTHk5irpno7qDu27cDQuB/NqOe6Z5TRSxOuCYLoWfhSti8CFyGdkZYXsVvpXouCnCXUbWbaOL/hQ8LI9c8jomWlw0KsaFIyelSCKPc7kHFpP1gIZH/J1iLexb8KlekpyVgR3QPYY1ZypLaCLLtS03VpSPbHNDLX8S7M5JV1w05DpQ8brCoCDl5FCjawL+7fO+VeDTUuQy2wkg7JOldONbD53GmbD7shF9gTusitWDcUEjpGnhcs23PXZI0o+GAV4aFAUX9J0bfM3gmL9ZUIXCD/kpCnZo+iSg1S2qhSXnDpQ1lHtwYWwjlS7DkkOV8YE77VxT7EhptjMg8P6Iu7AqmoHr4BcnnUBQWPVH9hLpUtOR6e69e7IwelRj7NElfY8pCCZGMmOi+gpJM70cHP+0nAIZjmB5hkBqUK1nisyWEtayvNChtZl46GZI+8fEv5Mq+x7tNMATdYF1ykY04iEdBK7SrkBDniqDfBprxUxJ7dCsbJFgtidEgx+JhrWmQhtal6C1kKVnLUwAH0jiGvlSXQHjgcZzCVwe2tvLEEbV+JOoe7gUSijjvBruwQ0uTbp1Vq4zsbjYIvXi6Oyxmz0BELli39+MyBbUg9EgSQRcVbLGUH7MsnKAXNukUeBOw+kaHGRBcnyTiBMkXHN3CQh8X4jninVoMW8mt2lNYLOqAsCVOL3n0jzO1mWS50qwDnXcZ6qhB2ZuYewI0WajQ+3V+jqjAWLt1fw/v5kwPGTGiHQqN6n27dT6ow== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e4034d3-9687-4857-2193-08ddc9303fa5 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:42.1372 (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: kleL/w8Qpk+yRnsudW3l26RDlDcuqbLHAUoAcyzIZrvWwIJ9j1scpkSayWWUnFv3fpjJpDfvuHO2vnq9JP1ZUuBaAM/D5sWMt00ifc+5LXc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-GUID: SdrE6FUT5GCavIYKvWyD6KRIcZ3_W6Xj X-Proofpoint-ORIG-GUID: SdrE6FUT5GCavIYKvWyD6KRIcZ3_W6Xj X-Authority-Analysis: v=2.4 cv=AbqxH2XG c=1 sm=1 tr=0 ts=687fa725 cx=c_pps a=7j0Ltmo+QGRCGvpdpD29zg==: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-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfX5uq6OWnDynL/ /yNtk089crlwSDXIzzUQX9LuY3266AlK5Wf74dItoIjkru6GWGMbaJJv11pMkP0moTlBXm/tWIV wN8Zb0EqG0lNm5+sCAAU0KAOBhkHUQjKuIOf9uqXhYoIEWcEue+qx0QH+YJi9AotWanz2f9W4Dg W25wsv63AjKb8DYkSxwYQNCcfSAXlNN4zwH5Zggs1/OuwCiz41z0EEB4jlQMiI4jVEZ6qDNVjz/ GLCGoAxRksbbfJEUrJuhGG4lf01mK2gdXoLx8ELUUjrHEkDNq7/PST8XK75pf3hVDD03OVpMdKk 0jN9pnpXPsowePArjvce65N0QI/vsFVMiJf2VYMJKquMmFCPIPsMsRYCuq16z4S4L46dqABPK7R Yo0IwrNd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 bulkscore=0 priorityscore=1501 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit 91bb902f58264a2fd50fbce8f39a9a290dd23706) Signed-off-by: Sunil Dora --- 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 a07435589a..ef0943cdc5 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 3baac4dabc..e48f914321 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 a9bc10dcca..07427369aa 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 1d4213eab9..05cd76a3b5 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 @@ -391,9 +388,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 @@ -406,13 +402,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 Tue Jul 22 14:58:21 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: 116780 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 169593851A8D for ; Tue, 22 Jul 2025 15:00:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 169593851A8D 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 04CDF3857BA5 for ; Tue, 22 Jul 2025 14:58:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04CDF3857BA5 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 04CDF3857BA5 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=1753196330; cv=pass; b=h5a0p1WKPQsEQ1+EE09LlQ92ZxhNVwkySShwfz+WzTsZMadkzbzI/jyOkdr/faaYtsyQOX2TzvcFd9pqAzCi1zqL4EaYpYDoBDa43KeIhba8sjHYHswHSg0e+vIPeXDU1YwvFS/yMs8UF7zFirU7DsApm1STHi4vd1fxiCVpcMg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1753196330; c=relaxed/simple; bh=Na91W3EUHrNR1OSsv+kh8mlGz2hhjdCO7YQHNU4gj40=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=XuLwbPCMN+63tCeZAMOip326zYj0h7xcOHBAb89Ji2AnU7s0/z+ER5EqRKFnFHUHk5mAC2zuaChPWQTODVAyjaymU2Zp1lTZ38/bTXIp91Cf57EWONq2TrG1/eu2Y+2eup9I/N/+UkkW09YF0SsK3ErFfs5xN6dzZXP1CJAv0Zo= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 04CDF3857BA5 Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.8/8.18.1.8) with ESMTP id 56M6kgKJ3577214; Tue, 22 Jul 2025 14:58:48 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12on2077.outbound.protection.outlook.com [40.107.244.77]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 481vqmrxby-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 22 Jul 2025 14:58:47 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=G3nPorQthVctijmD11I10wczR+VogPVR0nxH1IBaqa+cjdS0vHRTqiZyZdYUghl0hT8UUKVVSu3juaPok9z7e25sykmJkI/wGNin+PlW1tj6dk3kb9W6T6UMoVqf3C5yWKqNnnDHJqAVmqiDwo8mdKNJ3FsQiaaYx/4RAYISWF4geutHYieQR/Yt59nX5gBxwWWzEPk59ckRvTjFTn9WywShWkyIoeK2XMmuwodEFEBaXkTH0t0TwHoMytzj/MGySe9otjnir4bOymXLOiIaNE2vJbB64B+sqHb3INDK71MyCoAWiRAHwUytrDk2NMGY6Kt/Th2VS1nbHGFWpaOQcA== 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=+AducFPwamMQ/PbV+RgsC+NHzK8DeXJ6rFcViz97AjQ=; b=qfJzqYsRuGEy9Vh7NTqlOBSzY3/izYjWUKNBxPq10JOEDA94aZxB94DIT4l7L99r2CTXMgmkR37z+YMWNJ52ODAN29b7Sbd3/Tq5CE2LREQP8PhW91bj0c+By0v57f2ZBvWX/KaxGi0KPo4bnVmpZgFR1IPOemKFLxBBvzsuvOyhlzxQpiy/4HWrcqw7TPZpP1oDgcFPoMjJwrvYTZldEhU60M7bHBbADFdPYJicVeiZHJ5TvE7fy42PCrZSy6hdVi/XJk6n/Y3VqWnFWSu6PC9G+rOZ6XRXSb2aKiwDrt1gYugY++nglcJFM3lJTlKSFN1TiIs7jZRT0E3w6Ifd6Q== 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 BL3PR11MB6313.namprd11.prod.outlook.com (2603:10b6:208:3b0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.29; Tue, 22 Jul 2025 14:58:42 +0000 Received: from DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d]) by DS0PR11MB7901.namprd11.prod.outlook.com ([fe80::9fa:eb3f:cf26:264d%3]) with mapi id 15.20.8943.029; Tue, 22 Jul 2025 14:58:42 +0000 From: sunilkumar.dora@windriver.com To: libc-alpha@sourceware.org Cc: sunilkumar.dora@windriver.com, carlos@redhat.com, fweimer@redhat.com, Sundeep.Kokkonda@windriver.com Subject: [PATCH 10/10] [2.36] nptl: PTHREAD_COND_INITIALIZER compatibility with pre-2.41 versions (bug 32786) Date: Tue, 22 Jul 2025 07:58:21 -0700 Message-ID: <20250722145821.2214847-11-sunilkumar.dora@windriver.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> References: <20250722145821.2214847-1-sunilkumar.dora@windriver.com> X-ClientProxiedBy: SJ0PR13CA0232.namprd13.prod.outlook.com (2603:10b6:a03:2c1::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_|BL3PR11MB6313:EE_ X-MS-Office365-Filtering-Correlation-Id: 32156e07-d236-4363-b7fd-08ddc930400c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: P6fO3f9c770AWbaL0gOp6Y958Bgryu6/fIYBviGH/fzdkh7fb1k3BgifRg0o/J1x/p9ll8UZNsxOr0JVNBgJl6eS8MTb/JyLjDPrEj1JboexkqdnTLpcfgM9KMcA0tmQu8pmmKqQlNRYWwX6uCqCh/fIRMsNB5MaOfsyRxGmGco3sLfMH1g8Mz08a8Zz0Fqoc0MAdxAFE1PGlgKc/plWmc47O6syJ0lVCnBGa8AIaoW88tIPiIelGs+HfLWr0ah0ueqrdHS1SlSAjpV2MRU1aeva8tWJNBJyFTntRbt3g/g7ShCzB/yCoeM6/qnpfdlAqQ4TLvpl+327vI4bZ5rmFFuz8tgHy/37Y4dYC96BY9V7qlM1vAbwaULxUz3fS0FBwzZtpUcEnqz6IxB8l3ljgsZIm2YrQNGg5pLW/1mzCvfKwjFxEHMFsnXiF7MLQdI1H6m+F+LNR7wSeAhcixn7mKWmOU4BAA44s+9vJeAHAHLmK1xgKr0a8L17N9jDe7a0z44zxVzHctjV129aNAItrqXN9AP1Bbi9Jn3iwen0Nfnv+81csxJ/zKxL+sr5hnEnSJrztyHmmCboVJaBQCPcIWjp2YyLJSPmh42EXTexIxRfy+/IoMIFnln4/K1Glf9VOMWWWL2RKaCuUAVxvMMA+HpSpxxbEmXFMT01yIS1P93pfEgHpD1qhfnfCcII8OTxW7qfcm0a+pjZysQHzflK7e4LCJF9SOmlsnxabo1OqCuhe7y+FCkfpn5joDepjP5kpZvH3L6tjfDeeouHxMxinQjJVWhq6pY+xt2x9k1tRv5Utw37MDQ4v5XLXl///oEnpI3THMur7kN+X3n5Z8kPBAJPgrCWVOF9dzl3jQf08qGQxAk5bEhjzECG8cPVDWXrTZ+GGZnpdPXBCgXgWU/G8zq0xgQlHkWZ/51j63ERS73iJ1/1i9F7eEaDPmhomHApBDHpkS5VQRkTWNUgoBHmHGLJlB67WBLNOYkkUOIkynfE+0HYb3zUerlcd3O3QtdWTpeLUahoV3dC9KpaOIwpoqAt+YjYXxZCOwsW6OUB+smHqd27gUsdlo3VeVxOVZZqceq+VjjoKc4YpZbNGZcPkdgFq615CIqcUlp+HYJY0Lfv6XsAWZaPFiJbnI3ieus6wnlu1cEH/dMIW+Jz0++52jzqtk7xmHWQ6rRyede6JnImT8+ATrb4FscNWTJktTVXUt2KynxulMowV/o6+r32LQyzuZH9EkCJNiDu/TM2t1KwUQW8j+Gwuhte0iG0duTuYuoHFGtV2ZT2fao1verCiUXx40yYjnYmZm9y+NfJv8xnBqL4ygmc6hT8ucf2/Wkf1J3Tw1Uy6LiHXs7DedaPRx6Pl2UhziT6PQ7KoSjDHtlJaHvLQ34/owGvKxe91uF7JVaA2i/lQQdTD4OAyDXwTbj9Fwp5zhID1L8B9sqVpmHELdzbiQVNJS2HY+zBJSKXdqcO7C8+daPyl4lBXS6qwQ== 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)(376014)(52116014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UEjBDzdXT4ltCI2SHvV0cyclPk2+HcJLrL3vL2Qcch8DqaQDod0pivxSAffJP9F57FTLWSlADr1cr0DVjq8QBsQuGL2s9nJoNz9oCsm/Y57mWnhnlRIS5B6RC30r//xHUb2CuPPVgBtVAZ6O+FFliBMxZzkTJVIkon3y8mSA0aaeCQdvNaXp8u4K9or8DI2z4UzVDfaBbVphQV2wQJvs/0jmrLuM3v0udzN0HTlMH8lscxFcX5NI9pjhyh8ZiSV+WO21WzE3Mwf7sBv5T6iV2s+8fZyiiDS4NVnBrieJHIDMZRWnA7j/2zDeoIwJ7QXY2VlTgp0TRi8AHmZZifrL+66bWYqdRRIMMJ2RvKTfzD62GawuOFqS8SnjCmbFJ8dFyjOQpyakPXdVB7ORkjrelesHVWAgCGj9/RFP9Tb7arsTkukCyxugb6G9XjZs++pp4hLTv5zcJZamR9nKa9H8FKGuxCcEYUg5KaNDELH6wOClkRvs+uEEGG3X9F+dCi0CAojVgocXBsECXKp5BxS5ISQm/nJsARrG2j39He8CjIr1cpCymBvPC4Q9VlebNIxQSmZVHIcqkVc4Kg1t2c8AuW9TtU9HurFI4FtT+IO2BtpdJInO6u5W5gPsbRWj8zsTPq9FsgYUUsOdjRlinbE493O7dAXVuUqooaPjcSnT4uRn+pBAV8P9KvPK+yBt5hjQRDGqG6o27MnTI7wo5EMmmhFVLJDGx/mLXm6CKWIvc1HSFeKCW2BAED+FOS/3ULxON10LzrvRlrAv2hlgLnGtv30pXpyD9cMUzOKu7HI1B2YLrnPIMwOZ2GgTnhk6+FWrToUW94qUmxB8iVBIIYmQHAAmTYeeJpfBDX5wE1t9khnV3aXifxJMjJqq58M308t1tz9lcwYu0zhr3gd4dQCBesq0pb6raDogZx4MVT2WmMPQi9snsma5GJ7wSsJzmDFLzRASVOffBIGS3W7e7urysRTyOruHpMHfeJ/0ohmZcEWkBJhEcixjiNkgGo3YyxmEpyFfhUaWcOdXgUNQIcKZOM1ZHiyQz/LS97fiqBobvQfX0Y33tU5blTqhlP3pv2d1IWdS/H2KQGtDbPeFRaBRC49sca/peT//I6hETpclGwImhJNBtnsJga2e2nCrRAqmHb3ATCdnZ4ikx3UUYEwyzRNlrTWVI1/iUseHGXlEVAT1hwpo7NrC8Skb3BM+cj9pLdt7Q6dmyr7wMu/XAin+QQjRlTrkW/dnb/dQPxPQpMZGTozWLBZrramXayYEnvkIpKgpeXe6RimBwWFOBtLnys3/uH3nbQoclCPlCeGdNPusIvqeivkoFeJNZk6J9CoMxQNMnqIjjcOwh5jbUDrrfLOrxyb989pS/dca4Sti5TgkpHmMKZMMvzQONvhLY6AaxpDFZTZva4LSPWYRd39aQqwAPv9G+QKKiSqqE/Cx5oeEgVsXgYJSJlNSzO9bPNBzZWFDCyoJnVqfR/xXQ+gqdzf7zrmQ82x312IzEHJzluHhCfaUvqTiyAAV7AMQ1DROJYxMkjBbmIPZpF2fyQ7fW+7jkElTh7OrAhAY7JxoIGKONy3Ak0Qn7S7AjDxyr71PUQ7b1F+jq626WGCFJQyIzQ== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32156e07-d236-4363-b7fd-08ddc930400c X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7901.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2025 14:58:42.7808 (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: fmZzCEpjGFEvYis7Z+48PHSlm91TGdrh2g0bWwOtCzhnOBUHpX2PudlOID3SePf7NXycjvUY91Zgh+UNxAhc2Zv+PK5LVklGoi5STR2DQdk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6313 X-Proofpoint-ORIG-GUID: OPKFHyYTjC08FFHZXnBM59hLCF2yCI6R X-Proofpoint-GUID: OPKFHyYTjC08FFHZXnBM59hLCF2yCI6R X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzIyMDEyNCBTYWx0ZWRfXyx2RNsKNoaku CxfMH+2sDFpZE7i4a3SRtE0KzEzD1fBzPin8TdoafzZPLFYib6UyiRLaK9hDbhlnbqdkjSv5E+x r5qG349phWVbtUc7qQU9zSsgZyV19EDTIWNCZO2WaBEmPw/B9IckaiNbN4L5wj0BZtPF5+FbQV/ 1nQ59WJGPYqZgfqkULlk92dWwWCyFkdrZoXsTeH9CxuRhPNnjJJt3J/z+zknwZlX1g5EDgbWpE3 yiV4t6BcDPNkhMKLafC3eGp2m6C7vvNQIzFkrdkv1PGLSBmF4yLmO5hg1+mjTPO24BTdHwX2kgN +hNl/xJqCH5Gimx/eBzFVZ/vHaGZBZjAkRb9+7x2lS6+VfXfxx2IAszPDsV13aoZ64WQVfd9GOz XFpobPHL X-Authority-Analysis: v=2.4 cv=BbrY0qt2 c=1 sm=1 tr=0 ts=687fa727 cx=c_pps a=KSl2iKJTvN9PEcZNCff+AA==: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=vJ1LVuWRcRFP2V54Mt8A:9 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-22_02,2025-07-21_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 impostorscore=0 phishscore=0 suspectscore=0 spamscore=0 priorityscore=1501 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2507210000 definitions=main-2507210183 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. (cherry picked from commit dbc5a50d12eff4cb3f782129029d04b8a76f58e7) Signed-off-by: Sunil Dora --- 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 6f17afa473..2354ea219f 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 bbb365407e..8d6d24ff87 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 */