diff options
| author | Sunil Dora <sunilkumar.dora@windriver.com> | 2025-06-17 03:08:51 -0700 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2025-06-20 08:06:30 -0700 |
| commit | 5cb3b16aa96438ca9a20b5d987ac6965ebd4c93d (patch) | |
| tree | 046908457c063b7ba473610b6c0ec4b784211974 | |
| parent | cdd974ba56aa5266e5e391ff53a0c19e3b225a18 (diff) | |
| download | poky-5cb3b16aa96438ca9a20b5d987ac6965ebd4c93d.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
Upstream-Status: Backport
[https://sourceware.org/git/?p=glibc.git;a=commit;h=4f7b051f8ee3feff1b53b27a906f245afaa9cee1]
(From OE-Core rev: 761758340002f9dbff8e0668f4883ff623b232a0)
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.patch | 117 | ||||
| -rw-r--r-- | meta/recipes-core/glibc/glibc_2.35.bb | 1 |
2 files changed, 118 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..f8674d62ae --- /dev/null +++ b/meta/recipes-core/glibc/glibc/0026-PR25847-4.patch | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | From 16b9af737c77b153fca4f36cbdbe94f7416c0b42 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Malte Skarupke <malteskarupke@fastmail.fm> | ||
| 3 | Date: Mon, 16 Jun 2025 23:38:40 -0700 | ||
| 4 | Subject: [PATCH] nptl: Remove unnecessary quadruple check in pthread_cond_wait | ||
| 5 | |||
| 6 | pthread_cond_wait was checking whether it was in a closed group no less than | ||
| 7 | four times. Checking once is enough. Here are the four checks: | ||
| 8 | |||
| 9 | 1. While spin-waiting. This was dead code: maxspin is set to 0 and has been | ||
| 10 | for years. | ||
| 11 | 2. Before deciding to go to sleep, and before incrementing grefs: I kept this | ||
| 12 | 3. 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. | ||
| 16 | 4. 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 | |||
| 21 | Removing the duplicate checks clarifies the code. | ||
| 22 | |||
| 23 | The following commits have been cherry-picked from Glibc master branch: | ||
| 24 | Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 | ||
| 25 | |||
| 26 | Upstream-Status: Backport | ||
| 27 | [https://sourceware.org/git/?p=glibc.git;a=commit;h=4f7b051f8ee3feff1b53b27a906f245afaa9cee1] | ||
| 28 | |||
| 29 | Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com> | ||
| 30 | --- | ||
| 31 | nptl/pthread_cond_wait.c | 49 ---------------------------------------- | ||
| 32 | 1 file changed, 49 deletions(-) | ||
| 33 | |||
| 34 | diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c | ||
| 35 | index cee1968756..47e834cade 100644 | ||
| 36 | --- a/nptl/pthread_cond_wait.c | ||
| 37 | +++ b/nptl/pthread_cond_wait.c | ||
| 38 | @@ -366,7 +366,6 @@ static __always_inline int | ||
| 39 | __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 40 | clockid_t clockid, const struct __timespec64 *abstime) | ||
| 41 | { | ||
| 42 | - const int maxspin = 0; | ||
| 43 | int err; | ||
| 44 | int result = 0; | ||
| 45 | |||
| 46 | @@ -425,33 +424,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 47 | uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); | ||
| 48 | unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; | ||
| 49 | |||
| 50 | - /* Spin-wait first. | ||
| 51 | - Note that spinning first without checking whether a timeout | ||
| 52 | - passed might lead to what looks like a spurious wake-up even | ||
| 53 | - though we should return ETIMEDOUT (e.g., if the caller provides | ||
| 54 | - an absolute timeout that is clearly in the past). However, | ||
| 55 | - (1) spurious wake-ups are allowed, (2) it seems unlikely that a | ||
| 56 | - user will (ab)use pthread_cond_wait as a check for whether a | ||
| 57 | - point in time is in the past, and (3) spinning first without | ||
| 58 | - having to compare against the current time seems to be the right | ||
| 59 | - choice from a performance perspective for most use cases. */ | ||
| 60 | - unsigned int spin = maxspin; | ||
| 61 | - while (spin > 0 && ((int)(signals - lowseq) < 2)) | ||
| 62 | - { | ||
| 63 | - /* Check that we are not spinning on a group that's already | ||
| 64 | - closed. */ | ||
| 65 | - if (seq < (g1_start >> 1)) | ||
| 66 | - break; | ||
| 67 | - | ||
| 68 | - /* TODO Back off. */ | ||
| 69 | - | ||
| 70 | - /* Reload signals. See above for MO. */ | ||
| 71 | - signals = atomic_load_acquire (cond->__data.__g_signals + g); | ||
| 72 | - g1_start = __condvar_load_g1_start_relaxed (cond); | ||
| 73 | - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; | ||
| 74 | - spin--; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | if (seq < (g1_start >> 1)) | ||
| 78 | { | ||
| 79 | /* If the group is closed already, | ||
| 80 | @@ -482,24 +454,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 81 | an atomic read-modify-write operation and thus extend the release | ||
| 82 | sequence. */ | ||
| 83 | atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); | ||
| 84 | - signals = atomic_load_acquire (cond->__data.__g_signals + g); | ||
| 85 | - g1_start = __condvar_load_g1_start_relaxed (cond); | ||
| 86 | - lowseq = (g1_start & 1) == g ? signals : g1_start & ~1U; | ||
| 87 | - | ||
| 88 | - if (seq < (g1_start >> 1)) | ||
| 89 | - { | ||
| 90 | - /* group is closed already, so don't block */ | ||
| 91 | - __condvar_dec_grefs (cond, g, private); | ||
| 92 | - goto done; | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - if ((int)(signals - lowseq) >= 2) | ||
| 96 | - { | ||
| 97 | - /* a signal showed up or G1/G2 switched after we grabbed the | ||
| 98 | - refcount */ | ||
| 99 | - __condvar_dec_grefs (cond, g, private); | ||
| 100 | - break; | ||
| 101 | - } | ||
| 102 | |||
| 103 | // Now block. | ||
| 104 | struct _pthread_cleanup_buffer buffer; | ||
| 105 | @@ -533,9 +487,6 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, | ||
| 106 | /* Reload signals. See above for MO. */ | ||
| 107 | signals = atomic_load_acquire (cond->__data.__g_signals + g); | ||
| 108 | } | ||
| 109 | - | ||
| 110 | - if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) | ||
| 111 | - goto done; | ||
| 112 | } | ||
| 113 | /* Try to grab a signal. See above for MO. (if we do another loop | ||
| 114 | iteration we need to see the correct value of g1_start) */ | ||
| 115 | -- | ||
| 116 | 2.49.0 | ||
| 117 | |||
diff --git a/meta/recipes-core/glibc/glibc_2.35.bb b/meta/recipes-core/glibc/glibc_2.35.bb index 5e1f45608e..bb5d22cfe8 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 \ |
