summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunil Dora <sunilkumar.dora@windriver.com>2025-06-17 03:08:52 -0700
committerSteve Sakoman <steve@sakoman.com>2025-06-20 08:06:30 -0700
commit548a08daabc1ab4120a188f13ee8112a1a7eca29 (patch)
tree78e690d4769dac35982106e49886b057dc85c27f
parent5cb3b16aa96438ca9a20b5d987ac6965ebd4c93d (diff)
downloadpoky-548a08daabc1ab4120a188f13ee8112a1a7eca29.tar.gz
glibc: nptl Use a single loop in pthread_cond_wait instaed of a nested loop
The following commits have been cherry-picked from Glibc master branch: Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 Upstream-Status: Backport [https://sourceware.org/git/?p=glibc.git;a=commit;h=929a4764ac90382616b6a21f099192b2475da674] (From OE-Core rev: eab44f7a027414ef29f6d07617997cc50fc515cd) 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-5.patch105
-rw-r--r--meta/recipes-core/glibc/glibc_2.35.bb1
2 files changed, 106 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0026-PR25847-5.patch b/meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
new file mode 100644
index 0000000000..16fe6f8460
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
@@ -0,0 +1,105 @@
1From d9ffb50dc55f77e584a5d0275eea758c7a6b04e3 Mon Sep 17 00:00:00 2001
2From: Malte Skarupke <malteskarupke@fastmail.fm>
3Date: Mon, 16 Jun 2025 23:53:35 -0700
4Subject: [PATCH] nptl: Use a single loop in pthread_cond_wait instaed of a
5 nested loop
6
7The loop was a little more complicated than necessary. There was only one
8break statement out of the inner loop, and the outer loop was nearly empty.
9So just remove the outer loop, moving its code to the one break statement in
10the inner loop. This allows us to replace all gotos with break statements.
11
12The following commits have been cherry-picked from Glibc master branch:
13Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847
14
15Upstream-Status: Backport
16[https://sourceware.org/git/?p=glibc.git;a=commit;h=929a4764ac90382616b6a21f099192b2475da674]
17
18Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
19---
20 nptl/pthread_cond_wait.c | 41 +++++++++++++++++++---------------------
21 1 file changed, 19 insertions(+), 22 deletions(-)
22
23diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c
24index 47e834cade..5c86880105 100644
25--- a/nptl/pthread_cond_wait.c
26+++ b/nptl/pthread_cond_wait.c
27@@ -410,17 +410,15 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
28 return err;
29 }
30
31- /* Now wait until a signal is available in our group or it is closed.
32- Acquire MO so that if we observe (signals == lowseq) after group
33- switching in __condvar_quiesce_and_switch_g1, we synchronize with that
34- store and will see the prior update of __g1_start done while switching
35- groups too. */
36- unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g);
37-
38- do
39- {
40+
41 while (1)
42 {
43+ /* Now wait until a signal is available in our group or it is closed.
44+ Acquire MO so that if we observe (signals == lowseq) after group
45+ switching in __condvar_quiesce_and_switch_g1, we synchronize with that
46+ store and will see the prior update of __g1_start done while switching
47+ groups too. */
48+ unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g);
49 uint64_t g1_start = __condvar_load_g1_start_relaxed (cond);
50 unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U;
51
52@@ -429,7 +427,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
53 /* If the group is closed already,
54 then this waiter originally had enough extra signals to
55 consume, up until the time its group was closed. */
56- goto done;
57+ break;
58 }
59
60 /* If there is an available signal, don't block.
61@@ -438,8 +436,16 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
62 G2, but in either case we're allowed to consume the available
63 signal and should not block anymore. */
64 if ((int)(signals - lowseq) >= 2)
65- break;
66-
67+ {
68+ /* Try to grab a signal. See above for MO. (if we do another loop
69+ iteration we need to see the correct value of g1_start) */
70+ if (atomic_compare_exchange_weak_acquire (
71+ cond->__data.__g_signals + g,
72+ &signals, signals - 2))
73+ break;
74+ else
75+ continue;
76+ }
77 /* No signals available after spinning, so prepare to block.
78 We first acquire a group reference and use acquire MO for that so
79 that we synchronize with the dummy read-modify-write in
80@@ -479,21 +485,12 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex,
81 the lock during cancellation is not possible. */
82 __condvar_cancel_waiting (cond, seq, g, private);
83 result = err;
84- goto done;
85+ break;
86 }
87 else
88 __condvar_dec_grefs (cond, g, private);
89
90- /* Reload signals. See above for MO. */
91- signals = atomic_load_acquire (cond->__data.__g_signals + g);
92 }
93- }
94- /* Try to grab a signal. See above for MO. (if we do another loop
95- iteration we need to see the correct value of g1_start) */
96- while (!atomic_compare_exchange_weak_acquire (cond->__data.__g_signals + g,
97- &signals, signals - 2));
98-
99- done:
100
101 /* Confirm that we have been woken. We do that before acquiring the mutex
102 to allow for execution of pthread_cond_destroy while having acquired the
103--
1042.49.0
105
diff --git a/meta/recipes-core/glibc/glibc_2.35.bb b/meta/recipes-core/glibc/glibc_2.35.bb
index bb5d22cfe8..04dcb22c3d 100644
--- a/meta/recipes-core/glibc/glibc_2.35.bb
+++ b/meta/recipes-core/glibc/glibc_2.35.bb
@@ -66,6 +66,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
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 file://0026-PR25847-4.patch \
69 file://0026-PR25847-5.patch \
69 \ 70 \
70 file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ 71 file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \
71 file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ 72 file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \