diff options
| author | Sunil Dora <sunilkumar.dora@windriver.com> | 2025-10-14 07:43:43 -0700 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2025-10-17 07:27:24 -0700 |
| commit | 2105de9c82c73310516d78271d7bcbfa98e1c24e (patch) | |
| tree | 55b4525e226e365ab38e6871081ecb07054e1afc | |
| parent | dd624cec3bf42b3fe75b1a34fbf59bf96a3453d6 (diff) | |
| download | poky-2105de9c82c73310516d78271d7bcbfa98e1c24e.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
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=929a4764ac90382616b6a21f099192b2475da674
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002279.html
(From OE-Core rev: 75bbc8cb3a94640120d778916abb2edf78b89fd0)
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-6.patch | 103 | ||||
| -rw-r--r-- | meta/recipes-core/glibc/glibc_2.35.bb | 1 |
2 files changed, 104 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0026-PR25847-6.patch b/meta/recipes-core/glibc/glibc/0026-PR25847-6.patch new file mode 100644 index 0000000000..7d5c4fda5f --- /dev/null +++ b/meta/recipes-core/glibc/glibc/0026-PR25847-6.patch | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | From bbd7c84a1a14bf93bf1e5976d8a1540aabbf901b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Malte Skarupke <malteskarupke@fastmail.fm> | ||
| 3 | Date: Tue, 14 Oct 2025 06:19:02 -0700 | ||
| 4 | Subject: [PATCH] nptl: Use a single loop in pthread_cond_wait instaed of a | ||
| 5 | nested loop | ||
| 6 | |||
| 7 | The loop was a little more complicated than necessary. There was only one | ||
| 8 | break statement out of the inner loop, and the outer loop was nearly empty. | ||
| 9 | So just remove the outer loop, moving its code to the one break statement in | ||
| 10 | the inner loop. This allows us to replace all gotos with break statements. | ||
| 11 | |||
| 12 | The following commits have been cherry-picked from Glibc master branch: | ||
| 13 | Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 | ||
| 14 | commit: 929a4764ac90382616b6a21f099192b2475da674 | ||
| 15 | |||
| 16 | Upstream-Status: Submitted | ||
| 17 | [https://sourceware.org/pipermail/libc-stable/2025-July/002279.html] | ||
| 18 | |||
| 19 | Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> | ||
| 20 | --- | ||
| 21 | nptl/pthread_cond_wait.c | 41 +++++++++++++++++++--------------------- | ||
| 22 | 1 file changed, 19 insertions(+), 22 deletions(-) | ||
| 23 | |||
| 24 | diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c | ||
| 25 | index 8a9219e0..c8c99bbf 100644 | ||
| 26 | --- a/nptl/pthread_cond_wait.c | ||
| 27 | +++ b/nptl/pthread_cond_wait.c | ||
| 28 | @@ -382,17 +382,15 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 29 | return err; | ||
| 30 | } | ||
| 31 | |||
| 32 | - /* Now wait until a signal is available in our group or it is closed. | ||
| 33 | - Acquire MO so that if we observe (signals == lowseq) after group | ||
| 34 | - switching in __condvar_quiesce_and_switch_g1, we synchronize with that | ||
| 35 | - store and will see the prior update of __g1_start done while switching | ||
| 36 | - groups too. */ | ||
| 37 | - unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); | ||
| 38 | - | ||
| 39 | - do | ||
| 40 | - { | ||
| 41 | + | ||
| 42 | while (1) | ||
| 43 | { | ||
| 44 | + /* Now wait until a signal is available in our group or it is closed. | ||
| 45 | + Acquire MO so that if we observe (signals == lowseq) after group | ||
| 46 | + switching in __condvar_quiesce_and_switch_g1, we synchronize with that | ||
| 47 | + store and will see the prior update of __g1_start done while switching | ||
| 48 | + groups too. */ | ||
| 49 | + unsigned int signals = atomic_load_acquire (cond->__data.__g_signals + g); | ||
| 50 | uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); | ||
| 51 | unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; | ||
| 52 | |||
| 53 | @@ -401,7 +399,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 54 | /* If the group is closed already, | ||
| 55 | then this waiter originally had enough extra signals to | ||
| 56 | consume, up until the time its group was closed. */ | ||
| 57 | - goto done; | ||
| 58 | + break; | ||
| 59 | } | ||
| 60 | |||
| 61 | /* If there is an available signal, don't block. | ||
| 62 | @@ -410,7 +408,16 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 63 | G2, but in either case we're allowed to consume the available | ||
| 64 | signal and should not block anymore. */ | ||
| 65 | if ((int)(signals - lowseq) >= 2) | ||
| 66 | - break; | ||
| 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 | |||
| 78 | // Now block. | ||
| 79 | struct _pthread_cleanup_buffer buffer; | ||
| 80 | @@ -431,19 +438,9 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 81 | /* If we timed out, we effectively cancel waiting. */ | ||
| 82 | __condvar_cancel_waiting (cond, seq, g, private); | ||
| 83 | result = err; | ||
| 84 | - goto done; | ||
| 85 | + break; | ||
| 86 | } | ||
| 87 | - | ||
| 88 | - /* Reload signals. See above for MO. */ | ||
| 89 | - signals = atomic_load_acquire (cond->__data.__g_signals + g); | ||
| 90 | } | ||
| 91 | - } | ||
| 92 | - /* Try to grab a signal. See above for MO. (if we do another loop | ||
| 93 | - iteration we need to see the correct value of g1_start) */ | ||
| 94 | - while (!atomic_compare_exchange_weak_acquire (cond->__data.__g_signals + g, | ||
| 95 | - &signals, signals - 2)); | ||
| 96 | - | ||
| 97 | - done: | ||
| 98 | |||
| 99 | /* Confirm that we have been woken. We do that before acquiring the mutex | ||
| 100 | to allow for execution of pthread_cond_destroy while having acquired the | ||
| 101 | -- | ||
| 102 | 2.49.0 | ||
| 103 | |||
diff --git a/meta/recipes-core/glibc/glibc_2.35.bb b/meta/recipes-core/glibc/glibc_2.35.bb index e744260e87..3034461e9e 100644 --- a/meta/recipes-core/glibc/glibc_2.35.bb +++ b/meta/recipes-core/glibc/glibc_2.35.bb | |||
| @@ -67,6 +67,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ | |||
| 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 | file://0026-PR25847-5.patch \ |
| 70 | file://0026-PR25847-6.patch \ | ||
| 70 | \ | 71 | \ |
| 71 | file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ | 72 | file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ |
| 72 | file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ | 73 | file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ |
