summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunil Dora <sunilkumar.dora@windriver.com>2025-10-14 07:43:41 -0700
committerSteve Sakoman <steve@sakoman.com>2025-10-17 07:27:24 -0700
commit2fdbec72e5a0c9619827e2951fb407992b9eb9c3 (patch)
tree7d405cc2a9be21a410872df23c5b91d09293bb7b
parent7b6bc5b49cbd138fb8cc44c10350b190f77be83a (diff)
downloadpoky-2fdbec72e5a0c9619827e2951fb407992b9eb9c3.tar.gz
glibc: nptl Remove unnecessary quadruple check in pthread_cond_wait
The following commits have been cherry-picked from Glibc master branch: Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 [1] https://sourceware.org/git/?p=glibc.git;a=commit;h=4f7b051f8ee3feff1b53b27a906f245afaa9cee1 [2] https://sourceware.org/pipermail/libc-stable/2025-July/002276.html (From OE-Core rev: e6cac5aef751d698327f6ebee966462644c6c6a8) Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-core/glibc/glibc/0026-PR25847-4.patch118
-rw-r--r--meta/recipes-core/glibc/glibc_2.35.bb1
2 files changed, 119 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0026-PR25847-4.patch b/meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
new file mode 100644
index 0000000000..475462c880
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
@@ -0,0 +1,118 @@
1From d714165c8bb3cac420077cfa61e3df87ea7f8b2c Mon Sep 17 00:00:00 2001
2From: Malte Skarupke <malteskarupke@fastmail.fm>
3Date: Tue, 14 Oct 2025 05:34:06 -0700
4Subject: [PATCH] nptl: Remove unnecessary quadruple check in pthread_cond_wait
5
6pthread_cond_wait was checking whether it was in a closed group no less than
7four times. Checking once is enough. Here are the four checks:
8
91. While spin-waiting. This was dead code: maxspin is set to 0 and has been
10 for years.
112. Before deciding to go to sleep, and before incrementing grefs: I kept this
123. After incrementing grefs. There is no reason to think that the group would
13 close while we do an atomic increment. Obviously it could close at any
14 point, but that doesn't mean we have to recheck after every step. This
15 check was equally good as check 2, except it has to do more work.
164. When we find ourselves in a group that has a signal. We only get here after
17 we check that we're not in a closed group. There is no need to check again.
18 The check would only have helped in cases where the compare_exchange in the
19 next line would also have failed. Relying on the compare_exchange is fine.
20
21Removing the duplicate checks clarifies the code.
22
23The following commits have been cherry-picked from Glibc master branch:
24Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847
25commit: 4f7b051f8ee3feff1b53b27a906f245afaa9cee1
26
27Upstream-Status: Submitted
28[https://sourceware.org/pipermail/libc-stable/2025-July/002276.html]
29
30Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
31---
32 nptl/pthread_cond_wait.c | 49 ----------------------------------------
33 1 file changed, 49 deletions(-)
34
35diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c
36index cee19687..47e834ca 100644
37--- a/nptl/pthread_cond_wait.c
38+++ b/nptl/pthread_cond_wait.c
39@@ -366,7 +366,6 @@ static __always_inline int
40 __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
41 clockid_t clockid, const struct __timespec64 *abstime)
42 {
43- const int maxspin = 0;
44 int err;
45 int result = 0;
46
47@@ -425,33 +424,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
48 uint64_t g1_start = __condvar_load_g1_start_relaxed (cond);
49 unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U;
50
51- /* Spin-wait first.
52- Note that spinning first without checking whether a timeout
53- passed might lead to what looks like a spurious wake-up even
54- though we should return ETIMEDOUT (e.g., if the caller provides
55- an absolute timeout that is clearly in the past). However,
56- (1) spurious wake-ups are allowed, (2) it seems unlikely that a
57- user will (ab)use pthread_cond_wait as a check for whether a
58- point in time is in the past, and (3) spinning first without
59- having to compare against the current time seems to be the right
60- choice from a performance perspective for most use cases. */
61- unsigned int spin = maxspin;
62- while (spin > 0 && ((int)(signals - lowseq) < 2))
63- {
64- /* Check that we are not spinning on a group that's already
65- closed. */
66- if (seq < (g1_start >> 1))
67- break;
68-
69- /* TODO Back off. */
70-
71- /* Reload signals. See above for MO. */
72- signals = atomic_load_acquire (cond->__data.__g_signals + g);
73- g1_start = __condvar_load_g1_start_relaxed (cond);
74- lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U;
75- spin--;
76- }
77-
78 if (seq < (g1_start >> 1))
79 {
80 /* If the group is closed already,
81@@ -482,24 +454,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
82 an atomic read-modify-write operation and thus extend the release
83 sequence. */
84 atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2);
85- signals = atomic_load_acquire (cond->__data.__g_signals + g);
86- g1_start = __condvar_load_g1_start_relaxed (cond);
87- lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U;
88-
89- if (seq < (g1_start >> 1))
90- {
91- /* group is closed already, so don't block */
92- __condvar_dec_grefs (cond, g, private);
93- goto done;
94- }
95-
96- if ((int)(signals - lowseq) >= 2)
97- {
98- /* a signal showed up or G1/G2 switched after we grabbed the
99- refcount */
100- __condvar_dec_grefs (cond, g, private);
101- break;
102- }
103
104 // Now block.
105 struct _pthread_cleanup_buffer buffer;
106@@ -533,9 +487,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
107 /* Reload signals. See above for MO. */
108 signals = atomic_load_acquire (cond->__data.__g_signals + g);
109 }
110-
111- if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1))
112- goto done;
113 }
114 /* Try to grab a signal. See above for MO. (if we do another loop
115 iteration we need to see the correct value of g1_start) */
116--
1172.49.0
118
diff --git a/meta/recipes-core/glibc/glibc_2.35.bb b/meta/recipes-core/glibc/glibc_2.35.bb
index 0787dfe236..f9086c0855 100644
--- a/meta/recipes-core/glibc/glibc_2.35.bb
+++ b/meta/recipes-core/glibc/glibc_2.35.bb
@@ -65,6 +65,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
65 file://0026-PR25847-1.patch \ 65 file://0026-PR25847-1.patch \
66 file://0026-PR25847-2.patch \ 66 file://0026-PR25847-2.patch \
67 file://0026-PR25847-3.patch \ 67 file://0026-PR25847-3.patch \
68 file://0026-PR25847-4.patch \
68 \ 69 \
69 file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ 70 file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \
70 file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ 71 file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \