Patch review
cover Patch review
Please review this set of changes for kirkstone and have comments back by end of day Thursday, October 16
Passed a-full on autobuilder:
https://autobuilder.yoctoproject.org/valkyrie/#/builders/29/builds/2585
The following changes since commit 0d11c9103f072841baf39166efc133f2a20fc4dc:
oeqa/sdk/cases/buildcpio.py: use gnu mirror instead of main server (2025-10-09 07:35:42 -0700)
are available in the Git repository at:
https://git.openembedded.org/openembedded-core-contrib stable/kirkstone-nut
https://git.openembedded.org/openembedded-core-contrib/log/?h=stable/kirkstone-nut
Peter Marko (3):
qemu: patch CVE-2024-8354
binutils: patch CVE-2025-11082
binutils: patch CVE-2025-11083
Sunil Dora (11):
glibc: Remove partial BZ#25847 backport patches
glibc: pthreads NPTL lost wakeup fix 2
glibc: nptl Update comments and indentation for new condvar
implementation
glibc: nptl Remove unnecessary catch-all-wake in condvar group switch
glibc: nptl Remove unnecessary quadruple check in pthread_cond_wait
glibc: Remove g_refs from condition variables
glibc: nptl Use a single loop in pthread_cond_wait instaed of a nested
loop
glibc: nptl Fix indentation
glibc: nptl rename __condvar_quiesce_and_switch_g1
glibc: nptl Use all of g1_start and g_signals
glibc: : PTHREAD_COND_INITIALIZER compatibility with pre-2.41 versions
(bug 32786)
.../glibc/glibc/0026-PR25847-1.patch | 24 +- .../glibc/glibc/0026-PR25847-10.patch | 54 ++++ .../glibc/glibc/0026-PR25847-2.patch | 13 +- .../glibc/glibc/0026-PR25847-3.patch | 18 +- .../glibc/glibc/0026-PR25847-4.patch | 11 +- .../glibc/glibc/0026-PR25847-5.patch | 237 ++++++++++----- .../glibc/glibc/0026-PR25847-6.patch | 220 +++++--------- .../glibc/glibc/0026-PR25847-7.patch | 277 +++++++++--------- .../glibc/glibc/0026-PR25847-8.patch | 269 ++++++++--------- .../glibc/glibc/0026-PR25847-9.patch | 193 ++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 2 + .../binutils/binutils-2.38.inc | 2 + .../binutils/0044-CVE-2025-11082.patch | 46 +++ .../binutils/0045-CVE-2025-11083.patch | 77 +++++ meta/recipes-devtools/qemu/qemu.inc | 1 + .../qemu/qemu/CVE-2024-8354.patch | 75 +++++ 16 files changed, 974 insertions(+), 545 deletions(-) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-10.patch create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-9.patch create mode 100644 meta/recipes-devtools/binutils/binutils/0044-CVE-2025-11082.patch create mode 100644 meta/recipes-devtools/binutils/binutils/0045-CVE-2025-11083.patch create mode 100644 meta/recipes-devtools/qemu/qemu/CVE-2024-8354.patch
Signature · 1 line
2.43.0
PATCH 1/14 qemu: patch CVE-2024-8354
From: Peter Marko <[email protected]>
Pick commit per [1].
--- meta/recipes-devtools/qemu/qemu.inc | 1 + .../qemu/qemu/CVE-2024-8354.patch | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 meta/recipes-devtools/qemu/qemu/CVE-2024-8354.patch
meta/recipes-devtools/qemu/qemu.inc +1 -0
@@ -128,6 +128,7 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \ file://CVE-2024-3446-0005.patch \ file://CVE-2024-3446-0006.patch \ file://CVE-2024-3447.patch \ + file://CVE-2024-8354.patch \ " UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar"
meta/recipes-devtools/qemu/qemu/CVE-2024-8354.patch new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 2/14 binutils: patch CVE-2025-11082
In reply to Steve SakomanFrom: Peter Marko <[email protected]>
Pick patch per link in NVD report.
--- .../binutils/binutils-2.38.inc | 1 + .../binutils/0044-CVE-2025-11082.patch | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 meta/recipes-devtools/binutils/binutils/0044-CVE-2025-11082.patch
meta/recipes-devtools/binutils/binutils-2.38.inc +1 -0
@@ -80,5 +80,6 @@ SRC_URI = "\ file://0042-CVE-2025-5245.patch \ file://0043-CVE-2025-7546.patch \ file://0043-CVE-2025-7545.patch \ + file://0044-CVE-2025-11082.patch \ " S = "${WORKDIR}/git"
meta/recipes-devtools/binutils/binutils/0044-CVE-2025-11082.patch new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 3/14 binutils: patch CVE-2025-11083
In reply to Steve SakomanFrom: Peter Marko <[email protected]>
Pick patch per link in NVD report.
--- .../binutils/binutils-2.38.inc | 1 + .../binutils/0045-CVE-2025-11083.patch | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 meta/recipes-devtools/binutils/binutils/0045-CVE-2025-11083.patch
meta/recipes-devtools/binutils/binutils-2.38.inc +1 -0
@@ -81,5 +81,6 @@ SRC_URI = "\ file://0043-CVE-2025-7546.patch \ file://0043-CVE-2025-7545.patch \ file://0044-CVE-2025-11082.patch \ + file://0045-CVE-2025-11083.patch \ " S = "${WORKDIR}/git"
meta/recipes-devtools/binutils/binutils/0045-CVE-2025-11083.patch new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 4/14 glibc: Remove partial BZ#25847 backport patches
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
To facilitate a clean backport of the full 10-commit series addressing the pthread condition variable lost wakeup issue (BZ#25847) in glibc 2.35, remove the existing 8 patches that were applied as a partial backport.
The previous partial backport excluded commit:c36fc50781995e6758cae2b6927839d0157f213c ("nptl: Remove g_refs from condition variables") based on guidance from glibc maintainer Florian Weimer(#comment #74)
This exclusion was recommended for stable branches to avoid altering the layout of pthread_cond_t, which could introduce ABI incompatibilities. Additionally, the dependent commit dbc5a50d12eff4cb3f782129029d04b8a76f58e7 was not needed in the partial backport.
To align with upstream mainline, per maintainer Carlos O'Donell (comment #75), apply the complete 10-commit series for consistency.
By removing these patches first, we ensure the subsequent application of the full 10 commits results in cleaner, more reviewable changes without intermixed conflicts or overlaps.
Removed patches and corresponding upstream commits:
- 0026-PR25847-1.patch: 1db84775f831a1494993ce9c118deaf9537cc50a
- 0026-PR25847-2.patch: 0cc973160c23bb67f895bc887dd6942d29f8fee3
- 0026-PR25847-3.patch: b42cc6af11062c260c7dfa91f1c89891366fed3e
- 0026-PR25847-4.patch: 4f7b051f8ee3feff1b53b27a906f245afaa9cee1
- 0026-PR25847-5.patch: 929a4764ac90382616b6a21f099192b2475da674
- 0026-PR25847-6.patch: ee6c14ed59d480720721aaacc5fb03213dc153da
- 0026-PR25847-7.patch: 4b79e27a5073c02f6bff9aa8f4791230a0ab1867
- 0026-PR25847-8.patch: 91bb902f58264a2fd50fbce8f39a9a290dd23706
Bug reference: https://sourceware.org/bugzilla/show_bug.cgi?id=25847
This change prepares the branch for the full backport in follow-up commits.
--- .../glibc/glibc/0026-PR25847-1.patch | 455 ------------------ .../glibc/glibc/0026-PR25847-2.patch | 144 ------ .../glibc/glibc/0026-PR25847-3.patch | 77 --- .../glibc/glibc/0026-PR25847-4.patch | 117 ----- .../glibc/glibc/0026-PR25847-5.patch | 105 ---- .../glibc/glibc/0026-PR25847-6.patch | 169 ------- .../glibc/glibc/0026-PR25847-7.patch | 160 ------ .../glibc/glibc/0026-PR25847-8.patch | 192 -------- meta/recipes-core/glibc/glibc_2.35.bb | 8 - 9 files changed, 1427 deletions(-) delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-1.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-2.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-3.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-4.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-5.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-6.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-7.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0 -455
@@ -1,455 +0,0 @@ -From 31d9848830e496f57d4182b518467c4c63bfd4bd Mon Sep 17 00:00:00 2001 -From: Frank Barrus <[email protected]> -Date: Mon, 16 Jun 2025 22:37:54 -0700 -Subject: [PATCH] pthreads NPTL: lost wakeup fix 2 - -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. - -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=1db84775f831a1494993ce9c118deaf9537cc50a] - -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_common.c | 106 +++++++++------------------ - nptl/pthread_cond_wait.c | 144 ++++++++++++------------------------- - 2 files changed, 81 insertions(+), 169 deletions(-) - -diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c -index fb035f72c3..8dd7037923 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,85 +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 - noticing that __g1_start is larger. -@@ -311,6 +271,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 --- -2.49.0 -
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0 -144
144 lines not on this page · raw message
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0 -77
77 lines not on this page · raw message
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0 -117
117 lines not on this page · raw message
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0 -105
105 lines not on this page · raw message
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0 -169
169 lines not on this page · raw message
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0 -160
160 lines not on this page · raw message
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0 -192
192 lines not on this page · raw message
meta/recipes-core/glibc/glibc_2.35.bb +0 -8
@@ -62,14 +62,6 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0022-sysdeps-gnu-configure.ac-Set-libc_cv_rootsbindir-onl.patch \ file://0023-timezone-Make-shell-interpreter-overridable-in-tzsel.patch \ file://0024-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \ - file://0026-PR25847-1.patch \ - file://0026-PR25847-2.patch \ - file://0026-PR25847-3.patch \ - file://0026-PR25847-4.patch \ - file://0026-PR25847-5.patch \ - file://0026-PR25847-6.patch \ - file://0026-PR25847-7.patch \ - file://0026-PR25847-8.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 5/14 glibc: pthreads NPTL lost wakeup fix 2
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=1db84775f831a1494993ce9c118deaf9537cc50a
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002277.html
--- .../glibc/glibc/0026-PR25847-1.patch | 455 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 456 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch new file +455 -0
@@ -0,0 +1,455 @@ +From 0402999b82f697011de388f61bad68da26060bef Mon Sep 17 00:00:00 2001 +From: Frank Barrus <[email protected]> +Date: Tue, 14 Oct 2025 03:55:17 -0700 +Subject: [PATCH] pthreads NPTL: lost wakeup fix 2 + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +Commit : 1db84775f831a1494993ce9c118deaf9537cc50a + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002277.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 fb035f72..a55eee3e 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 20c348a5..1cb3dbf7 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 +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -62,6 +62,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0022-sysdeps-gnu-configure.ac-Set-libc_cv_rootsbindir-onl.patch \ file://0023-timezone-Make-shell-interpreter-overridable-in-tzsel.patch \ file://0024-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \ + file://0026-PR25847-1.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 6/14 glibc: nptl Update comments and indentation for new condvar implementation
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=0cc973160c23bb67f895bc887dd6942d29f8fee3
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002275.html
--- .../glibc/glibc/0026-PR25847-2.patch | 145 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 146 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch new file +145 -0
@@ -0,0 +1,145 @@ +From 306ea7810f5f6709ef3942a7be75077203b5d201 Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 04:27:19 -0700 +Subject: [PATCH] nptl: Update comments and indentation for new condvar + implementation + +Some comments were wrong after the most recent commit. This fixes that. +Also fixing indentation where it was using spaces instead of tabs. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: 0cc973160c23bb67f895bc887dd6942d29f8fee3 + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002275.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 a55eee3e..350a16fa 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 1cb3dbf7..cee19687 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)); + +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -63,6 +63,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0023-timezone-Make-shell-interpreter-overridable-in-tzsel.patch \ file://0024-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \ file://0026-PR25847-1.patch \ + file://0026-PR25847-2.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 7/14 glibc: nptl Remove unnecessary catch-all-wake in condvar group switch
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=b42cc6af11062c260c7dfa91f1c89891366fed3e
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002274.html
--- .../glibc/glibc/0026-PR25847-3.patch | 79 +++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 80 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-3.patch
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch new file +79 -0
@@ -0,0 +1,79 @@ +From 5f22e8cf95cf6b3b2e16ddb03820ae3e77fd420d Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 04:47:48 -0700 +Subject: [PATCH] nptl: Remove unnecessary catch-all-wake in condvar group + switch + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: b42cc6af11062c260c7dfa91f1c89891366fed3e + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002274.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 350a16fa..f976a533 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. +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -64,6 +64,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0024-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \ file://0026-PR25847-1.patch \ file://0026-PR25847-2.patch \ + file://0026-PR25847-3.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 8/14 glibc: nptl Remove unnecessary quadruple check in pthread_cond_wait
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=4f7b051f8ee3feff1b53b27a906f245afaa9cee1
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002276.html
--- .../glibc/glibc/0026-PR25847-4.patch | 118 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 119 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch new file +118 -0
@@ -0,0 +1,118 @@ +From d714165c8bb3cac420077cfa61e3df87ea7f8b2c Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 05:34:06 -0700 +Subject: [PATCH] nptl: Remove unnecessary quadruple check in pthread_cond_wait + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: 4f7b051f8ee3feff1b53b27a906f245afaa9cee1 + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002276.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 cee19687..47e834ca 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) */ +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -65,6 +65,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-1.patch \ file://0026-PR25847-2.patch \ file://0026-PR25847-3.patch \ + file://0026-PR25847-4.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 9/14 glibc: Remove g_refs from condition variables
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=c36fc50781995e6758cae2b6927839d0157f213c
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002278.html
--- .../glibc/glibc/0026-PR25847-5.patch | 188 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 189 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch new file +188 -0
@@ -0,0 +1,188 @@ +From f904a81ff8d0469ceaf3220329e716c03fcbd2d3 Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 05:59:02 -0700 +Subject: [PATCH] nptl: Remove g_refs from condition variables + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +cmmit: c36fc50781995e6758cae2b6927839d0157f213c + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002278.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 47e834ca..8a9219e0 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 1336e9c7..bdcb45c5 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 5653507e..6f17afa4 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 dedad4ec..bbb36540 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 */ +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -66,6 +66,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-2.patch \ file://0026-PR25847-3.patch \ file://0026-PR25847-4.patch \ + file://0026-PR25847-5.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 10/14 glibc: nptl Use a single loop in pthread_cond_wait instaed of a nested loop
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=929a4764ac90382616b6a21f099192b2475da674
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002279.html
--- .../glibc/glibc/0026-PR25847-6.patch | 103 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 104 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch new file +103 -0
@@ -0,0 +1,103 @@ +From bbd7c84a1a14bf93bf1e5976d8a1540aabbf901b Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 06:19:02 -0700 +Subject: [PATCH] nptl: Use a single loop in pthread_cond_wait instaed of a + nested loop + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: 929a4764ac90382616b6a21f099192b2475da674 + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002279.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 8a9219e0..c8c99bbf 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 +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -67,6 +67,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-3.patch \ file://0026-PR25847-4.patch \ file://0026-PR25847-5.patch \ + file://0026-PR25847-6.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 11/14 glibc: nptl Fix indentation
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=ee6c14ed59d480720721aaacc5fb03213dc153da
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002280.html
--- .../glibc/glibc/0026-PR25847-7.patch | 149 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 150 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch new file +149 -0
@@ -0,0 +1,149 @@ +From 1077953950d1e8864c63222967141c67f51297f8 Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 06:27:04 -0700 +Subject: [PATCH] nptl: Fix indentation + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: ee6c14ed59d480720721aaacc5fb03213dc153da + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002280.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 c8c99bbf..adf26a80 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. */ +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -68,6 +68,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-4.patch \ file://0026-PR25847-5.patch \ file://0026-PR25847-6.patch \ + file://0026-PR25847-7.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 12/14 glibc: nptl rename __condvar_quiesce_and_switch_g1
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=4b79e27a5073c02f6bff9aa8f4791230a0ab1867
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002281.html
--- .../glibc/glibc/0026-PR25847-8.patch | 161 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 162 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch new file +161 -0
@@ -0,0 +1,161 @@ +From 20d84dfa0b9a32f88259269bbeaae588744ae4ae Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 06:33:50 -0700 +Subject: [PATCH] nptl: rename __condvar_quiesce_and_switch_g1 + +This function no longer waits for threads to leave g1, so rename it to +__condvar_switch_g1 + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: 4b79e27a5073c02f6bff9aa8f4791230a0ab1867 + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002281.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 5ae141ac..a0743558 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 f976a533..3baac4da 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 14800ba0..a9bc10dc 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 adf26a80..40a74342 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; +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -69,6 +69,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-5.patch \ file://0026-PR25847-6.patch \ file://0026-PR25847-7.patch \ + file://0026-PR25847-8.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 13/14 glibc: nptl Use all of g1_start and g_signals
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=91bb902f58264a2fd50fbce8f39a9a290dd23706
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002283.html
--- .../glibc/glibc/0026-PR25847-9.patch | 193 ++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 194 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-9.patch
meta/recipes-core/glibc/glibc/0026-PR25847-9.patch new file +193 -0
@@ -0,0 +1,193 @@ +From c2677e68956bb9677d8de4ee6c5341b1a744d490 Mon Sep 17 00:00:00 2001 +From: Malte Skarupke <[email protected]> +Date: Tue, 14 Oct 2025 06:40:57 -0700 +Subject: [PATCH] nptl: Use all of g1_start and g_signals + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: 91bb902f58264a2fd50fbce8f39a9a290dd23706 + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002283.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 a0743558..ef0943cd 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 3baac4da..e48f9143 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 a9bc10dc..07427369 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 40a74342..d7e073ab 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; +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -70,6 +70,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-6.patch \ file://0026-PR25847-7.patch \ file://0026-PR25847-8.patch \ + file://0026-PR25847-9.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
PATCH 14/14 glibc: : PTHREAD_COND_INITIALIZER compatibility with pre-2.41 versions (bug 32786)
In reply to Steve SakomanFrom: Sunil Dora <[email protected]>
The following commits have been cherry-picked from Glibc master branch:
[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=dbc5a50d12eff4cb3f782129029d04b8a76f58e7
[2] https://sourceware.org/pipermail/libc-stable/2025-July/002282.html
--- .../glibc/glibc/0026-PR25847-10.patch | 54 +++++++++++++++++++ meta/recipes-core/glibc/glibc_2.35.bb | 1 + 2 files changed, 55 insertions(+) create mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-10.patch
meta/recipes-core/glibc/glibc/0026-PR25847-10.patch new file +54 -0
@@ -0,0 +1,54 @@ +From 4f78382dd671f381db6d1f452e6f1593d17b177e Mon Sep 17 00:00:00 2001 +From: Florian Weimer <[email protected]> +Date: Tue, 14 Oct 2025 06:53:40 -0700 +Subject: [PATCH] nptl: PTHREAD_COND_INITIALIZER compatibility with pre-2.41 + versions (bug 32786) + +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. + +The following commits have been cherry-picked from Glibc master branch: +Bug : https://sourceware.org/bugzilla/show_bug.cgi?id=25847 +commit: dbc5a50d12eff4cb3f782129029d04b8a76f58e7 + +Upstream-Status: Submitted +[https://sourceware.org/pipermail/libc-stable/2025-July/002282.html] + +Signed-off-by: Sunil Dora <[email protected]> +--- + 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 6f17afa4..2354ea21 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 bbb36540..8d6d24ff 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 */ +-- +2.49.0 +
meta/recipes-core/glibc/glibc_2.35.bb +1 -0
@@ -71,6 +71,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0026-PR25847-7.patch \ file://0026-PR25847-8.patch \ file://0026-PR25847-9.patch \ + file://0026-PR25847-10.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \
Signature · 1 line
2.43.0
Re: [OE-core][kirkstone 04/14] glibc: Remove partial BZ#25847 backport patches
In reply to Steve Sakomanare these backports being done in glibc 2.35 release as well ?
Quoted 1,559 lines · Steve Sakoman via lists.openembedded.org
From: Sunil Dora <[email protected]>
To facilitate a clean backport of the full 10-commit series addressing the pthread condition variable lost wakeup issue (BZ#25847) in glibc 2.35, remove the existing 8 patches that were applied as a partial backport.
The previous partial backport excluded commit:
c36fc50781995e6758cae2b6927839d0157f213c("nptl: Removeg_refsfrom condition variables") based on guidance from glibc maintainer Florian Weimer(#comment #74)This exclusion was recommended for stable branches to avoid altering the layout of
pthread_cond_t, which could introduce ABI incompatibilities. Additionally, the dependent commitdbc5a50d12eff4cb3f782129029d04b8a76f58e7was not needed in the partial backport.To align with upstream mainline, per maintainer Carlos O'Donell (comment #75), apply the complete 10-commit series for consistency.
By removing these patches first, we ensure the subsequent application of the full 10 commits results in cleaner, more reviewable changes without intermixed conflicts or overlaps.
Removed patches and corresponding upstream commits:
- 0026-PR25847-1.patch:1db84775f831a1494993ce9c118deaf9537cc50a
- 0026-PR25847-2.patch:0cc973160c23bb67f895bc887dd6942d29f8fee3
- 0026-PR25847-3.patch:b42cc6af11062c260c7dfa91f1c89891366fed3e
- 0026-PR25847-4.patch:4f7b051f8ee3feff1b53b27a906f245afaa9cee1
- 0026-PR25847-5.patch:929a4764ac90382616b6a21f099192b2475da674
- 0026-PR25847-6.patch:ee6c14ed59d480720721aaacc5fb03213dc153da
- 0026-PR25847-7.patch:4b79e27a5073c02f6bff9aa8f4791230a0ab1867
- 0026-PR25847-8.patch:91bb902f58264a2fd50fbce8f39a9a290dd23706Bug reference: https://sourceware.org/bugzilla/show_bug.cgi?id=25847
This change prepares the branch for the full backport in follow-up commits.Signed-off-by Sunil Dora <[email protected]>Signed-off-by Steve Sakoman <[email protected]>--- .../glibc/glibc/0026-PR25847-1.patch | 455 ------------------ .../glibc/glibc/0026-PR25847-2.patch | 144 ------ .../glibc/glibc/0026-PR25847-3.patch | 77 --- .../glibc/glibc/0026-PR25847-4.patch | 117 ----- .../glibc/glibc/0026-PR25847-5.patch | 105 ---- .../glibc/glibc/0026-PR25847-6.patch | 169 ------- .../glibc/glibc/0026-PR25847-7.patch | 160 ------ .../glibc/glibc/0026-PR25847-8.patch | 192 -------- meta/recipes-core/glibc/glibc_2.35.bb | 8 - 9 files changed, 1427 deletions(-) delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-1.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-2.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-3.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-4.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-5.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-6.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-7.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-8.patchmeta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-455@@ -1,455 +0,0 @@ -From 31d9848830e496f57d4182b518467c4c63bfd4bd Mon Sep 17 00:00:00 2001 -From: Frank Barrus <[email protected]> -Date: Mon, 16 Jun 2025 22:37:54 -0700 -Subject: [PATCH] pthreads NPTL: lost wakeup fix 2 - -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. - -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=1db84775f831a1494993ce9c118deaf9537cc50a] - -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_common.c | 106 +++++++++------------------ - nptl/pthread_cond_wait.c | 144 ++++++++++++------------------------- - 2 files changed, 81 insertions(+), 169 deletions(-) - -diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c -index fb035f72c3..8dd7037923 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,85 +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 - noticing that __g1_start is larger. -@@ -311,6 +271,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 --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-144@@ -1,144 +0,0 @@ -From 6aab1191e35a3da66e8c49d95178a9d77c119a1f Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:17:53 -0700 -Subject: [PATCH] nptl: Update comments and indentation for new condvar - implementation - -Some comments were wrong after the most recent commit. This fixes that. -Also fixing indentation where it was using spaces instead of tabs. - -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=0cc973160c23bb67f895bc887dd6942d29f8fee3] - -Signed-off-by: Sunil Dora <[email protected]> ---- - 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 8dd7037923..306a207dd6 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)); - --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-77@@ -1,77 +0,0 @@ -From 28a5082045429fdc5a4744d45fdc5b5202528eaa Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:29:49 -0700 -Subject: [PATCH] nptl: Remove unnecessary catch-all-wake in condvar group - switch - -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. - -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=b42cc6af11062c260c7dfa91f1c89891366fed3e] - -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_common.c | 30 +----------------------------- - 1 file changed, 1 insertion(+), 29 deletions(-) - -diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c -index 306a207dd6..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,28 +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. --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-117@@ -1,117 +0,0 @@ -From 16b9af737c77b153fca4f36cbdbe94f7416c0b42 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:38:40 -0700 -Subject: [PATCH] nptl: Remove unnecessary quadruple check in pthread_cond_wait - -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. - -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] - -Signed-off-by: Sunil Dora <[email protected]> ---- - 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) */ --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-105@@ -1,105 +0,0 @@ -From d9ffb50dc55f77e584a5d0275eea758c7a6b04e3 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:53:35 -0700 -Subject: [PATCH] nptl: Use a single loop in pthread_cond_wait instaed of a - nested loop - -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. - -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] - -Signed-off-by: Sunil Dora <[email protected]> ---- - 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 47e834cade..5c86880105 100644 ---- a/nptl/pthread_cond_wait.c -+++ b/nptl/pthread_cond_wait.c -@@ -410,17 +410,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; - -@@ -429,7 +427,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. -@@ -438,8 +436,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; -+ } - /* 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 -@@ -479,21 +485,12 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, - the lock during cancellation is not possible. */ - __condvar_cancel_waiting (cond, seq, g, private); - result = err; -- goto done; -+ break; - } - else - __condvar_dec_grefs (cond, g, private); - -- /* 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 --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-169@@ -1,169 +0,0 @@ -From a2faee6d0dac6e5232255da9afda4d9ed6cfb6e5 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Tue, 17 Jun 2025 01:37:12 -0700 -Subject: [PATCH] nptl: Fix indentation - -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. - -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=ee6c14ed59d480720721aaacc5fb03213dc153da] - -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_wait.c | 132 ++++++++++++++++----------------------- - 1 file changed, 54 insertions(+), 78 deletions(-) - -diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c -index 5c86880105..104ebd48ca 100644 ---- a/nptl/pthread_cond_wait.c -+++ b/nptl/pthread_cond_wait.c -@@ -410,87 +410,63 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, - return err; - } - -- -- 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; -- } -- /* 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; -- 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)) -- { -- __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. */ -- __condvar_cancel_waiting (cond, seq, g, private); -- result = err; - break; -- } -- else -- __condvar_dec_grefs (cond, g, private); -- -+ 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 --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-160@@ -1,160 +0,0 @@ -From 2a601ac9041e2ca645acad2c174b1c545cfceafe Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Tue, 17 Jun 2025 01:53:25 -0700 -Subject: [PATCH] nptl: rename __condvar_quiesce_and_switch_g1 - -This function no longer waits for threads to leave g1, so rename it to -__condvar_switch_g1 - -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=4b79e27a5073c02f6bff9aa8f4791230a0ab1867] - -Signed-off-by: Sunil Dora <[email protected]> ---- - 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 104ebd48ca..bb46f3605d 100644 ---- a/nptl/pthread_cond_wait.c -+++ b/nptl/pthread_cond_wait.c -@@ -382,8 +382,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. */ -@@ -414,9 +413,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; --- -2.49.0 -meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-192@@ -1,192 +0,0 @@ -From fc074de88796eb2036fbe9bade638e00adfd5cb2 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Tue, 17 Jun 2025 02:08:36 -0700 -Subject: [PATCH] nptl: Use all of g1_start and g_signals - -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. - -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=91bb902f58264a2fd50fbce8f39a9a290dd23706] - -Signed-off-by: Sunil Dora <[email protected]> ---- - 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 bb46f3605d..430cbe8a35 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. -@@ -278,7 +278,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 -@@ -299,11 +298,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 -@@ -418,9 +415,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 -@@ -433,13 +429,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; --- -2.49.0 -meta/recipes-core/glibc/glibc_2.35.bb +0
-9@@ -62,14 +62,6 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ file://0022-sysdeps-gnu-configure.ac-Set-libc_cv_rootsbindir-onl.patch \ file://0023-timezone-Make-shell-interpreter-overridable-in-tzsel.patch \ file://0024-fix-create-thread-failed-in-unprivileged-process-BZ-.patch \ - file://0026-PR25847-1.patch \ - file://0026-PR25847-2.patch \ - file://0026-PR25847-3.patch \ - file://0026-PR25847-4.patch \ - file://0026-PR25847-5.patch \ - file://0026-PR25847-6.patch \ - file://0026-PR25847-7.patch \ - file://0026-PR25847-8.patch \ \ file://0001-Revert-Linux-Implement-a-useful-version-of-_startup_.patch \ file://0002-get_nscd_addresses-Fix-subscript-typos-BZ-29605.patch \ --2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#224858): https://lists.openembedded.org/g/openembedded-core/message/224858
Mute This Topic: https://lists.openembedded.org/mt/115762087/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [OE-core][kirkstone 04/14] glibc: Remove partial BZ#25847 backport patches
Quoted 2 lines · Khem Raj
are these backports being done in glibc 2.35 release as well
Sunil, can you respond to Khem's question?
Steve
Quoted 1,929 lines
Quoted 36 lines · Steve Sakoman via lists.openembedded.org
From: Sunil Dora <[email protected]>
To facilitate a clean backport of the full 10-commit series addressing the pthread condition variable lost wakeup issue (BZ#25847) in glibc 2.35, remove the existing 8 patches that were applied as a partial backport.
The previous partial backport excluded commit:
c36fc50781995e6758cae2b6927839d0157f213c("nptl: Removeg_refsfrom condition variables") based on guidance from glibc maintainer Florian Weimer(#comment #74)This exclusion was recommended for stable branches to avoid altering the layout of
pthread_cond_t, which could introduce ABI incompatibilities. Additionally, the dependent commitdbc5a50d12eff4cb3f782129029d04b8a76f58e7was not needed in the partial backport.To align with upstream mainline, per maintainer Carlos O'Donell (comment #75), apply the complete 10-commit series for consistency.
By removing these patches first, we ensure the subsequent application of the full 10 commits results in cleaner, more reviewable changes without intermixed conflicts or overlaps.
Removed patches and corresponding upstream commits:
- 0026-PR25847-1.patch:1db84775f831a1494993ce9c118deaf9537cc50a
- 0026-PR25847-2.patch:0cc973160c23bb67f895bc887dd6942d29f8fee3
- 0026-PR25847-3.patch:b42cc6af11062c260c7dfa91f1c89891366fed3e
- 0026-PR25847-4.patch:4f7b051f8ee3feff1b53b27a906f245afaa9cee1
- 0026-PR25847-5.patch:929a4764ac90382616b6a21f099192b2475da674
- 0026-PR25847-6.patch:ee6c14ed59d480720721aaacc5fb03213dc153da
- 0026-PR25847-7.patch:4b79e27a5073c02f6bff9aa8f4791230a0ab1867
- 0026-PR25847-8.patch:91bb902f58264a2fd50fbce8f39a9a290dd23706Quoted 2 lines
Bug reference: https://sourceware.org/bugzilla/show_bug.cgi?id=25847
This change prepares the branch for the full backport in follow-upcommits.
Quoted 23 lines
Signed-off-by Sunil Dora <[email protected]>Signed-off-by Steve Sakoman <[email protected]>--- .../glibc/glibc/0026-PR25847-1.patch | 455 ------------------ .../glibc/glibc/0026-PR25847-2.patch | 144 ------ .../glibc/glibc/0026-PR25847-3.patch | 77 --- .../glibc/glibc/0026-PR25847-4.patch | 117 ----- .../glibc/glibc/0026-PR25847-5.patch | 105 ---- .../glibc/glibc/0026-PR25847-6.patch | 169 ------- .../glibc/glibc/0026-PR25847-7.patch | 160 ------ .../glibc/glibc/0026-PR25847-8.patch | 192 -------- meta/recipes-core/glibc/glibc_2.35.bb | 8 - 9 files changed, 1427 deletions(-) delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-1.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-2.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-3.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-4.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-5.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-6.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-7.patch delete mode 100644 meta/recipes-core/glibc/glibc/0026-PR25847-8.patchReview
Quoted 1 line
(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-1.patchmeta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 8
Quoted 13 lines
deleted file mode 100644
index 44a2b6772c..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-8@@ -1,455 +0,0 @@ -From 31d9848830e496f57d4182b518467c4c63bfd4bd Mon Sep 17 00:00:00 2001 -From: Frank Barrus <[email protected]> -Date: Mon, 16 Jun 2025 22:37:54 -0700 -Subject: [PATCH] pthreads NPTL: lost wakeup fix 2 - -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 signalstealing,
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-7-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-bitvalue
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-7-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 theG1/G2
Quoted 38 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-38-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 themeta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-10-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. - -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=1db84775f831a1494993ce9c118deaf9537cc50a
]Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-9- -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_common.c | 106 +++++++++------------------ - nptl/pthread_cond_wait.c | 144 ++++++++++++------------------------- - 2 files changed, 81 insertions(+), 169 deletions(-) - -diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c -index fb035f72c3..8dd7037923 100644meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-10---- 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. Theexpression may
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 90
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-@@ -222,85 +221,46 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t*cond,
uint64_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 91
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- * New waiters arriving concurrently with the group switching willall go
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 92
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- into G2 until we atomically make the switch. Waiters existingin G2
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 94
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2- are not affected. -- * Waiters in G1 will be closed out immediately by setting a flagin
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 95
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- __g_signals, which will prevent waiters from blocking using afutex on
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 96
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- __g_signals and also notifies them that the group is closed.As a
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 97
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- result, they will eventually remove their group reference,allowing us
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-- to close switch group roles. */ -- -- /* First, set the closed flag on __g_signals. This tells waitersthat are
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 102
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- about to wait that they shouldn't do that anymore. This basically -- serves as an advance notificaton of the upcoming change to
__g1_start;meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 104
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- waiters interpret it as if __g1_start was larger than their waiter -- sequence position. This allows us to change __g1_start afterwaiting
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 105
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- for all existing waiters with group references to leave, which inturn
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 106
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- makes recovery after stealing a signal simpler because it thencan be
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 107
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- skipped if __g1_start indicates that the group is closed(otherwise,
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 108
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- we would have to recover always because waiters don't know howbig their
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-- 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-oroperation
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 113
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- injects us into the modification order of __g_refs; release MOensures
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 114
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- that waiters incrementing __g_refs after our fetch-or see theprevious
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 115
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- changes to __g_signals and to __g1_start that had to happenbefore we can
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 116
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- switch this G1 and alias with an older group (we have two groups,so
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 117
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- aliasing requires switching group roles twice). Note that nobodyelse
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 118
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- can have set the wake-request flag, so we do not have to act uponit.
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 120
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- -- Also note that it is harmless if older waiters or waiters fromthis G1
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 121
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- get a group reference after we have quiesced the group because itwill
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 122
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- remain closed for them either because of the closed flag in
__g_signalsmeta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 123
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- or the later update to __g1_start. New waiters will never arrivehere
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-5-- 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--)
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-7-- { -- /* TODO Back off. */ -- r = atomic_load_relaxed (cond->__data.__g_refs + g1); -- } -- if ((r >> 1) > 0) -- { -- /* There is still a waiter after spinning. Set thewake-request
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 136
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- flag and block. Relaxed MO is fine because this is justabout
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-- this futex word. -- -- Update r to include the set wake-request flag so that theupcoming
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 140
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- futex_wait only blocks if the flag is still set (otherwise,we'd
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 142
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- violate the basic client-side futex protocol). */ -- r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1) |1;
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-- -- if ((r >> 1) > 0) -- futex_wait_simple (cond->__data.__g_refs + g1, r, private); -- /* Reload here so we eventually see the most recent value evenif we
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-5-- do not spin. */ -- r = atomic_load_relaxed (cond->__data.__g_refs + g1); -- } -- } -- /* Acquire MO so that we synchronize with the release operation thatwaiters
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 152
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- use to decrement __g_refs and thus happen after the waiters wewaited
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-- 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),meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-+ 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 valuewe add
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 163
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- will never be negative because old_orig_size can only be zerowhen we
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 164
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- switch groups the first time after a condvar was initialized, inwhich
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 165
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- case G1 will be at index 1 and we will add a value of 1. Seeabove for
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-8-- 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 usingthe
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 174
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- futex controlled by __g_signals. Release MO so that observersthat see
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 175
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- no signals (and thus can block) also see the write __g1_start andthus
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 176
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- that this is now a new group (see __pthread_cond_wait_common forthe
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-- 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 beblocked),
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 183
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-+ then wake them all up now and prevent any running ones fromblocking.
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 185
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-+ This is effectively a catch-all for any possible current or future -+ bugs that can allow the group size to reach 0 before all G1waiters
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 187
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-+ have been awakened or at least given signals to consume, or any -+ other case that can leave blocked (or about to block) olderwaiters.. */
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 188
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-+ if ((atomic_fetch_or_release (cond->__data.__g_refs + g1, 0) >> 1) >0)
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 190
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-+ { -+ /* First advance signals to the end of the group (i.e. enoughsignals
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-+ 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 enoughmeta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-10-+ 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 useyet).
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 205
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- No old waiter can neither grab a signal nor acquire a referencewithout
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 207
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2- noticing that __g1_start is larger. -@@ -311,6 +271,10 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t*cond,
uint64_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-8- 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 protectedby the
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-10- 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 waitersthat
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 226
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- are using the group's futex. Before a group can change its role,the
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 227
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- reference count must show that no waiters are using the futexanymore; this
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-- prevents ABA issues on the futex word. -+ are using the group's futex. - - To represent which intervals in the waiter sequence the groupscover (and
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 232
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- thus also which group slot contains G1 or G2), we use a 64b counterto
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-@@ -300,11 +298,12 @@ __condvar_cleanup_waiting (void *arg) - last reference. - * Reference count used by waiters concurrently with signalersthat have
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3- 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
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-+ 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 waitersand
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 243
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2- signalers. -- * LSB is true iff this group has been completely signaled (i.e.,it is
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-5-- 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 doso only
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 250
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-@@ -328,18 +327,6 @@ __condvar_cleanup_waiting (void *arg) - sufficient because if a waiter can see a sufficiently large value,it could
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3- have also consume a signal in the waiters group. - -- Waiters try to grab a signal from __g_signals without holding areference
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 254
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- count, which can lead to stealing a signal from a more recent groupafter
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 255
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- their own group was already closed. They cannot always detectwhether they
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 257
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- 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; ifthey
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 258
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- did so unnecessarily, all that happens is a spurious wake-up. Tomake this
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 259
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- even less likely, __g1_start contains the index of the current g2too,
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 260
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- which allows waiters to check if there aliasing on the group slots;if
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 261
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- there wasn't, they didn't steal from the current G1, which meansthat the
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 262
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- G1 they stole from must have been already closed and they do notneed to
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-- fix anything. -- - It is essential that the last field in pthread_cond_t is__g_signals[1]:
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 266
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- The previous condvar used a pointer-sized field in pthread_cond_t,so a
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 268
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2- 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,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-5- { - while (1) - { -+ uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); -+ unsigned int lowseq = (g1_start & 1) == g ? signals :
g1_start& ~1U;meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-5-+ - /* 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,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 279
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- having to compare against the current time seems to be theright
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 280
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- choice from a performance perspective for most use cases.*/
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-5- 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 alreadymeta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-10- 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);
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-+ 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 onsignals,
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-8-- 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)) -+ {meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-10-+ /* 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 theavailable
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-+ 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 forthat so
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 327
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2- that we synchronize with the dummy read-modify-write in - __condvar_quiesce_and_switch_g1 if we read from that. Inturn,
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 328
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- in this case this will make us see the closed flag on
__g_signalsmeta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 329
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- that designates a concurrent attempt to reuse the group'sslot.
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 330
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-+ in this case this will make us see the advancement of
__g_signalsmeta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-+ 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,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 337
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- an atomic read-modify-write operation and thus extend therelease
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3- sequence. */ - atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); -- if (((atomic_load_acquire (cond->__data.__g_signals + g) & 1)!= 0)
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-8-- || (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 mightbe
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-9-- 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 grabbedthe refcount */
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-8-+ __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,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 366
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- __pthread_cleanup_push (&buffer, __condvar_cleanup_waiting,&cbuffer);
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4- - err = __futex_abstimed_wait_cancelable64 ( -- cond->__data.__g_signals + g, 0, clockid, abstime, private); -+ cond->__data.__g_signals + g, signals, clockid, abstime,private);
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4- - __pthread_cleanup_pop (&buffer, 0); - -@@ -524,6 +533,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-7- 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 anup-to-date value
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 383
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2- 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,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 384
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1- while (!atomic_compare_exchange_weak_acquire(
cond->__data.__g_signals+ g,meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3- &signals, signals - 2)); - -- /* We consumed a signal but we could have consumed from a morerecent group
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 388
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- that aliased with ours due to being in the same group slot. Ifthis
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-- 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 wedo not
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 396
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- know which group we really consumed from. -- We do not care about groups older than current G1 because theyare
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-- 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 reallyintended
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 400
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- for G2 because G2 never receives signals (until it becomesG1). We
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 401
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- could have stolen a signal from G2 that was conservativelyadded by a
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 402
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- previous waiter that also thought it stole a signal -- butgiven that
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 403
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- that signal was added unnecessarily, it's not a problem if westeal
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 405
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- it. -- Thus, the remaining case is that we could have stolen from thecurrent
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 406
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- G1, where "current" means the __g1_start value we observed.However,
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 407
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- if the current G1 does not have the same slot index as we do,we did
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 408
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- not steal from it and do not need to undo that. This is thereason
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-- 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 ofstealing
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 414
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- a signal. We can stop trying to do that when the current G1 -- changes because other spinning waiters will notice this tooand
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 415
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- __condvar_quiesce_and_switch_g1 has checked that there areno
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 417
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- futex waiters anymore before switching G1. -- Relaxed MO is fine for the __g1_start load because we needto
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3-- 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 whetherthe
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 421
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- current G1 gets closed? This might be worthwhile if thegroup is
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 423
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- small or close to being closed. */ -- unsigned int s = atomic_load_relaxed (cond->__data.__g_signals+ g);
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-4-- 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. Ifthe
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 428
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- group is in the process of being closed (LSB is true),this
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-6-- 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-upon
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 435
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- the futex. We also need to do that if we skippedadding
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 437
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-2-- a signal because the group is being closed because -- while __condvar_quiesce_and_switch_g1 could haveclosed
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 438
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- the group, it might stil be waiting for futexwaiters to
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch line 439
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-1-- leave (and one of those waiters might be the one westole
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch
Quoted 13 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-13-- 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 themutex
Review
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-1.patch deleted +0
-3--- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-2.patchQuoted 9 lines
deleted file mode 100644
index cb89431769..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-4@@ -1,144 +0,0 @@ -From 6aab1191e35a3da66e8c49d95178a9d77c119a1f Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:17:53 -0700 -Subject: [PATCH] nptl: Update comments and indentation for new condvarmeta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 14
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-10- implementation - -Some comments were wrong after the most recent commit. This fixes that. -Also fixing indentation where it was using spaces instead of tabs. - -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=0cc973160c23bb67f895bc887dd6942d29f8fee3
]meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 12 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-12- -Signed-off-by: Sunil Dora <[email protected]> ---- - 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 8dd7037923..306a207dd6 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_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 27
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- * New waiters arriving concurrently with the group switching willall go
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 28
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- into G2 until we atomically make the switch. Waiters existingin G2
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-3- 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),meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 32
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-+ * Waiters in G1 have already received a signal and been woken. Ifthey
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 33
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-+ haven't woken yet, they will be closed out immediately by theadvancing
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 34
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-+ of __g_signals to the next "lowseq" (low 31 bits of the new
g1_start),meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-9- 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 beencompletely
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 44
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- signaled (i.e., if the current G1 starts at a later position thatthe
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 45
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- waiter's position). Waiters cannot determine whether they arecurrently
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 46
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-- in G2 or G1 -- but they do not have too because all they areinterested in
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 47
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-+ in G2 or G1 -- but they do not have to because all they areinterested in
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 48
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- is whether there are available signals, and they always start in G2(whose
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 49
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- group slot they know because of the bit in the waiter sequence.Signalers
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 50
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- will simply fill the right group until it is completely signaledand can
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 51
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-@@ -412,7 +412,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-4- } - - /* 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 aftergroup
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 57
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-2-+ Acquire MO so that if we observe (signals == lowseq) after group - switching in __condvar_quiesce_and_switch_g1, we synchronize withthat
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 58
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1- store and will see the prior update of __g1_start done whileswitching
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 60
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-2- groups too. */ -@@ -422,8 +422,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-5- { - while (1) - { -- uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); -- unsigned int lowseq = (g1_start & 1) == g ? signals :
g1_start& ~1U;meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 67
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-2-+ uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); -+ unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start& ~1U;
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 71
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-4- - /* 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,meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 74
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-3- - /* Reload signals. See above for MO. */ - signals = atomic_load_acquire (cond->__data.__g_signals +g);
Quoted 13 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-13-- 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 tometa/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-10- 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 theavailable
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 99
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-2- signal and should not block anymore. */ -@@ -483,22 +483,23 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-10- 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))meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-10- { -- /* 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 grabbedthe refcount */
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 120
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-1-+ /* a signal showed up or G1/G2 switched after we grabbedthe
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-9-+ 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,meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-4- if (seq < (__condvar_load_g1_start_relaxed (cond) >> 1)) - goto done; - } -- /* Try to grab a signal. Use acquire MO so that we see anup-to-date value
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch line 135
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-2-- of __g1_start below (see spinning above for a similar case). In -- particular, if we steal from a more recent group, we will alsosee a
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-4-- 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,Review
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-2.patch deleted +0
-5- &signals, signals - 2)); - --- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-3.patchmeta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 4
Quoted 9 lines
deleted file mode 100644
index 4cfcca846c..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-4@@ -1,77 +0,0 @@ -From 28a5082045429fdc5a4744d45fdc5b5202528eaa Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:29:49 -0700 -Subject: [PATCH] nptl: Remove unnecessary catch-all-wake in condvargroup
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-3- switch - -This wake is unnecessary. We only switch groups after every sleeper ina group
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 8
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-has been woken. Sure, they may take a while to actually wake up and maystill
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 9
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-hold a reference, but waking them a second time doesn't speed that up.Instead
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-3-this just makes the code more complicated and may hide problems. - -In particular this safety wake wouldn't even have helped with the bugthat was
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 13
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-fixed by Barrus' patch: The bug there was that pthread_cond_signalwould not
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 14
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-switch g1 when it should, so we wouldn't even have entered this codepath.
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 20
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-6- -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=b42cc6af11062c260c7dfa91f1c89891366fed3e
]meta/recipes-core/glibc/glibc/0026-PR25847-3.patch
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-11- -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_common.c | 30 +----------------------------- - 1 file changed, 1 insertion(+), 29 deletions(-) - -diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c -index 306a207dd6..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_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 32
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1- * New waiters arriving concurrently with the group switching willall go
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 33
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1- into G2 until we atomically make the switch. Waiters existingin G2
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 35
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-2- are not affected. -- * Waiters in G1 have already received a signal and been woken. Ifthey
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 36
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-- haven't woken yet, they will be closed out immediately by theadvancing
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 37
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-- of __g_signals to the next "lowseq" (low 31 bits of the new
g1_start),meta/recipes-core/glibc/glibc/0026-PR25847-3.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-7-- 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 valuewe add
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 45
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1- will never be negative because old_orig_size can only be zerowhen we
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 46
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-@@ -240,28 +234,6 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t*cond,
uint64_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-3.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-4- - unsigned int lowseq = ((old_g1_start + old_orig_size) << 1) & ~1U; - -- /* If any waiters still hold group references (and thus could beblocked),
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 51
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-- then wake them all up now and prevent any running ones fromblocking.
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 53
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-2-- This is effectively a catch-all for any possible current or future -- bugs that can allow the group size to reach 0 before all G1waiters
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 55
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-2-- have been awakened or at least given signals to consume, or any -- other case that can leave blocked (or about to block) olderwaiters.. */
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 56
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1-- if ((atomic_fetch_or_release (cond->__data.__g_refs + g1, 0) >> 1) >0)
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 58
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-2-- { -- /* First advance signals to the end of the group (i.e. enoughsignals
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-4-- 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 enoughmeta/recipes-core/glibc/glibc/0026-PR25847-3.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-10-- 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 useyet).
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch line 73
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-1- No old waiter can neither grab a signal nor acquire a referencewithout
Review
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-3.patch deleted +0
-4- noticing that __g1_start is larger. --- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-4.patchmeta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 4
Quoted 9 lines
deleted file mode 100644
index f8674d62ae..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-4@@ -1,117 +0,0 @@ -From 16b9af737c77b153fca4f36cbdbe94f7416c0b42 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:38:40 -0700 -Subject: [PATCH] nptl: Remove unnecessary quadruple check in
pthread_cond_waitmeta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 6
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-2- -pthread_cond_wait was checking whether it was in a closed group no lessthan
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-3-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 hasbeen
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 11
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-2- for years. -2. Before deciding to go to sleep, and before incrementing grefs: Ikept this
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 12
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1-3. After incrementing grefs. There is no reason to think that the groupwould
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 13
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1- close while we do an atomic increment. Obviously it could close atany
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 14
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1- point, but that doesn't mean we have to recheck after every step.This
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 16
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-2- 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 gethere after
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 17
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1- we check that we're not in a closed group. There is no need to checkagain.
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 18
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1- The check would only have helped in cases where the compare_exchangein the
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 19
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1- next line would also have failed. Relying on the compare_exchange isfine.
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-8- -Removing the duplicate checks clarifies the code. - -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
]meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 12 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-12- -Signed-off-by: Sunil Dora <[email protected]> ---- - 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,
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-7- 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,meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 48
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-2- uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start& ~1U;
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-5- -- /* 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 callerprovides
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 55
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-2-- an absolute timeout that is clearly in the past). However, -- (1) spurious wake-ups are allowed, (2) it seems unlikelythat a
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-3-- 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 theright
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 59
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1-- choice from a performance perspective for most use cases.*/
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 12 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-12-- 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);
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-9-- 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,meta/recipes-core/glibc/glibc/0026-PR25847-4.patch line 81
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-1- an atomic read-modify-write operation and thus extend therelease
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-6- 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; --meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-10-- 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 grabbedthe
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-8-- 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,Review
Quoted 13 lines
meta/recipes-core/glibc/glibc/0026-PR25847-4.patch deleted +0
-12- /* 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) */ --- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-5.patchmeta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 4
Quoted 9 lines
deleted file mode 100644
index 16fe6f8460..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-4@@ -1,105 +0,0 @@ -From d9ffb50dc55f77e584a5d0275eea758c7a6b04e3 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Mon, 16 Jun 2025 23:53:35 -0700 -Subject: [PATCH] nptl: Use a single loop in pthread_cond_wait instaedof a
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-3- nested loop - -The loop was a little more complicated than necessary. There was onlyone
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 8
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-break statement out of the inner loop, and the outer loop was nearlyempty.
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 9
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-So just remove the outer loop, moving its code to the one breakstatement in
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 10
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-the inner loop. This allows us to replace all gotos with breakstatements.
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 16
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-6- -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
]meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-11- -Signed-off-by: Sunil Dora <[email protected]> ---- - 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 47e834cade..5c86880105 100644 ---- a/nptl/pthread_cond_wait.c -+++ b/nptl/pthread_cond_wait.c -@@ -410,17 +410,15 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-6- 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 withthat
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 34
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-- store and will see the prior update of __g1_start done whileswitching
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 36
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-2-- groups too. */ -- unsigned int signals = atomic_load_acquire (cond->__data.__g_signals+ g);
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-7-- -- do -- { -+ - while (1) - { -+ /* Now wait until a signal is available in our group or it isclosed.
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 44
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-+ Acquire MO so that if we observe (signals == lowseq) aftergroup
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 45
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-+ switching in __condvar_quiesce_and_switch_g1, wesynchronize with that
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 46
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-+ store and will see the prior update of __g1_start donewhile switching
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 48
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-2-+ groups too. */ -+ unsigned int signals = atomic_load_acquire(
cond->__data.__g_signals+ g);meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 50
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-2- uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start& ~1U;
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 52
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-2- -@@ -429,7 +427,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-9- /* 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. -@@ -438,8 +436,16 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 62
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1- G2, but in either case we're allowed to consume theavailable
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-6- signal and should not block anymore. */ - if ((int)(signals - lowseq) >= 2) -- break; -- -+ { -+ /* Try to grab a signal. See above for MO. (if we doanother loop
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 69
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1-+ iteration we need to see the correct value of
g1_start) */meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-9-+ if (atomic_compare_exchange_weak_acquire ( -+ cond->__data.__g_signals + g, -+ &signals, signals - 2)) -+ break; -+ else -+ continue; -+ } - /* No signals available after spinning, so prepare to block. - We first acquire a group reference and use acquire MO forthat so
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 80
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-2- that we synchronize with the dummy read-modify-write in -@@ -479,21 +485,12 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-6- the lock during cancellation is not possible. */ - __condvar_cancel_waiting (cond, seq, g, private); - result = err; -- goto done; -+ break; - }meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-10- else - __condvar_dec_grefs (cond, g, private); - -- /* 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,meta/recipes-core/glibc/glibc/0026-PR25847-5.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-5-- &signals, signals - 2)); -- -- done: - - /* Confirm that we have been woken. We do that before acquiring themutex
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch line 102
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-1- to allow for execution of pthread_cond_destroy while havingacquired the
Review
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-5.patch deleted +0
-3--- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-6.patchmeta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 6
Quoted 11 lines
deleted file mode 100644
index cf87e21ddd..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-6@@ -1,169 +0,0 @@ -From a2faee6d0dac6e5232255da9afda4d9ed6cfb6e5 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Tue, 17 Jun 2025 01:37:12 -0700 -Subject: [PATCH] nptl: Fix indentation - -In my previous change I turned a nested loop into a simple loop. I'mdoing
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 7
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-the resulting indentation changes in a separate commit to make the diffon
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-7-the previous commit easier to review. - -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=ee6c14ed59d480720721aaacc5fb03213dc153da
]meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-11- -Signed-off-by: Sunil Dora <[email protected]> ---- - nptl/pthread_cond_wait.c | 132 ++++++++++++++++----------------------- - 1 file changed, 54 insertions(+), 78 deletions(-) - -diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c -index 5c86880105..104ebd48ca 100644 ---- a/nptl/pthread_cond_wait.c -+++ b/nptl/pthread_cond_wait.c -@@ -410,87 +410,63 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-7- return err; - } - -- -- while (1) -- { -- /* Now wait until a signal is available in our group or it isclosed.
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 33
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- Acquire MO so that if we observe (signals == lowseq) aftergroup
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 34
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- switching in __condvar_quiesce_and_switch_g1, wesynchronize with that
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 35
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- store and will see the prior update of __g1_start donewhile switching
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 37
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-2-- groups too. */ -- unsigned int signals = atomic_load_acquire(
cond->__data.__g_signals+ g);meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 39
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-2-- uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); -- unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start& ~1U;
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 13 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-13-- -- 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 theavailable
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-4-- signal and should not block anymore. */ -- if ((int)(signals - lowseq) >= 2) -- { -- /* Try to grab a signal. See above for MO. (if we doanother loop
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 57
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- iteration we need to see the correct value of
g1_start) */meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-5-- 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 isclosed.
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 63
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-+ Acquire MO so that if we observe (signals == lowseq) aftergroup
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 64
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-+ switching in __condvar_quiesce_and_switch_g1, we synchronizewith that
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 65
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-+ store and will see the prior update of __g1_start done whileswitching
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 67
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-2-+ groups too. */ -+ unsigned int signals = atomic_load_acquire(
cond->__data.__g_signals+ g);meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 69
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-2-+ uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); -+ unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start &~1U;
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-7-+ -+ 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;meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-10-+ } -+ -+ /* 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 doanother loop
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-10-+ 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; -- } -- /* No signals available after spinning, so prepare to block. -- We first acquire a group reference and use acquire MO forthat so
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 98
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-2-- that we synchronize with the dummy read-modify-write in -- __condvar_quiesce_and_switch_g1 if we read from that. Inturn,
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 99
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- in this case this will make us see the advancement of
__g_signalsmeta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-6-- 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 weuse
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 106
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- an atomic read-modify-write operation and thus extend therelease
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-11-- sequence. */ -- atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); -- -- // 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);
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-3-- -- err = __futex_abstimed_wait_cancelable64 ( -- cond->__data.__g_signals + g, signals, clockid, abstime,private);
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-7-- -- __pthread_cleanup_pop (&buffer, 0); -- -- if (__glibc_unlikely (err == ETIMEDOUT || err == EOVERFLOW)) -- { -- __condvar_dec_grefs (cond, g, private); -- /* If we timed out, we effectively cancel waiting. Notethat
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 128
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1-- we have decremented __g_refs before cancellation, sothat a
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-11-- 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. */ -- __condvar_cancel_waiting (cond, seq, g, private); -- result = err; - break; -- } -- else -- __condvar_dec_grefs (cond, g, private); -- -+ elsemeta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-10-+ 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);
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-3-+ -+ err = __futex_abstimed_wait_cancelable64 ( -+ cond->__data.__g_signals + g, signals, clockid, abstime,private);
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch
Quoted 13 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-13-+ -+ __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 themutex
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch line 166
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-1- to allow for execution of pthread_cond_destroy while havingacquired the
Review
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-6.patch deleted +0
-3--- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-7.patchQuoted 8 lines
deleted file mode 100644
index a9e9cc7c48..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-3@@ -1,160 +0,0 @@ -From 2a601ac9041e2ca645acad2c174b1c545cfceafe Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Tue, 17 Jun 2025 01:53:25 -0700meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 13
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-10-Subject: [PATCH] nptl: rename __condvar_quiesce_and_switch_g1 - -This function no longer waits for threads to leave g1, so rename it to -__condvar_switch_g1 - -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=4b79e27a5073c02f6bff9aa8f4791230a0ab1867
]meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-10- -Signed-off-by: Sunil Dora <[email protected]> ---- - 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.cQuoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-5-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);meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-10- 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 inG2, in
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-5- 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 / newG1. */
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-10- 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 futexwaiters to
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 54
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- leave G1, converts G1 into a fresh G2, and then switches grouproles so that
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 55
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- the former G2 becomes the new G1 ending at the current __wseq valuewhen we
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 56
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- eventually make the switch (WSEQ is just an observation of __wseqby the
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 58
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2-- signaler). -+/* This closes G1 (whose index is in G1INDEX), converts G1 into afresh G2,
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 59
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ and then switches group roles so that the former G2 becomes the newG1
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 60
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ ending at the current __wseq value when we eventually make theswitch
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 62
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2-+ (WSEQ is just an observation of __wseq by the signaler). - If G2 is empty, it will not switch groups because then it wouldcreate an
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 63
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1- empty G1 which would require switching groups again on the nextsignal.
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-8- 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_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-4- + cond->__data.__g_size[g1 ^ 1]) == 0) - return false; - -- /* Now try to close and quiesce G1. We have to consider thefollowing kinds
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-4-- 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 gettinglarger.
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 80
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1- * New waiters arriving concurrently with the group switching willall go
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 81
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-@@ -223,12 +221,12 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t*cond,
uint64_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-4- are not affected. - * Waiters in G1 have already received a signal and been woken. */ - -- /* Update __g1_start, which finishes closing this group. The valuewe add
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 86
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- will never be negative because old_orig_size can only be zerowhen we
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 87
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- switch groups the first time after a condvar was initialized, inwhich
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-4-- 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 addwill never
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 92
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ be negative because old_orig_size can only be zero when we switchgroups
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 93
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ the first time after a condvar was initialized, in which case G1will be
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 94
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ at index 1 and we will add a value of 1. Relaxed MO is finebecause the
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 95
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ change comes with no additional constraints that others wouldhave to
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 12 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-12-+ 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. Ifnot, we
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 108
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- check if G2 has waiters, and if so, quiesce and switch G1 to theformer
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 109
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- G2; if this results in a new G1 with waiters (G2 might havecancellations
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 110
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- already, see __condvar_quiesce_and_switch_g1), we put the signalin the
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 112
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2-- new G1. */ -+ check if G2 has waiters, and if so, switch G1 to the former G2;if this
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 113
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ results in a new G1 with waiters (G2 might have cancellationsalready,
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-6-+ 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 notneed to
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 120
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- establish a happens-before relation (see above). We do notmask the
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-3-- 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 releasesequence. */
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 124
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ establish a happens-before relation (see above). We do notmask the
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 125
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ release-MO store when initializing a group in
__condvar_switch_g1meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 126
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ because we use an atomic read-modify-write and thus extendthat
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-9-+ 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 104ebd48ca..bb46f3605d 100644 ---- a/nptl/pthread_cond_wait.c -+++ b/nptl/pthread_cond_wait.c -@@ -382,8 +382,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 136
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1- because we do not need to establish any happens-before relationwith
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 138
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2- signalers (see __pthread_cond_signal); modification order alone - establishes a total order of waiters/signals. We do need acquireMO
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-3-- to synchronize with group reinitialization in -- __condvar_quiesce_and_switch_g1. */ -+ to synchronize with group reinitialization in
__condvar_switch_g1. */meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 143
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2- uint64_t wseq = __condvar_fetch_add_wseq_acquire (cond, 2); - /* Find our group's index. We always go into what was G2 when weacquired
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 145
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2- our position. */ -@@ -414,9 +413,9 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 147
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2- { - /* Now wait until a signal is available in our group or it isclosed.
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 148
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1- Acquire MO so that if we observe (signals == lowseq) aftergroup
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 149
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- switching in __condvar_quiesce_and_switch_g1, we synchronizewith that
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 150
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-- store and will see the prior update of __g1_start done whileswitching
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 152
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2-- groups too. */ -+ switching in __condvar_switch_g1, we synchronize with thatstore and
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 153
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-1-+ will see the prior update of __g1_start done while switchinggroups
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 155
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2-+ too. */ - unsigned int signals = atomic_load_acquire(
cond->__data.__g_signals+ g);meta/recipes-core/glibc/glibc/0026-PR25847-7.patch line 157
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-2- uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); - unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start &~1U;
Review
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-7.patch deleted +0
-3--- -2.49.0 -(quoted diff) +0
-0
b/meta/recipes-core/glibc/glibc/0026-PR25847-8.patchmeta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 6
Quoted 11 lines
deleted file mode 100644
index 8ea0c784ef..0000000000meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-6@@ -1,192 +0,0 @@ -From fc074de88796eb2036fbe9bade638e00adfd5cb2 Mon Sep 17 00:00:00 2001 -From: Malte Skarupke <[email protected]> -Date: Tue, 17 Jun 2025 02:08:36 -0700 -Subject: [PATCH] nptl: Use all of g1_start and g_signals - -The LSB of g_signals was unused. The LSB of g1_start was used toindicate
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 7
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-which group is G2. This was used to always go to sleep in
pthread_cond_waitmeta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 8
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-if a waiter is in G2. A comment earlier in the file says that this isnot
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 3 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-3-correct to do: - - "Waiters cannot determine whether they are currently in G2 or G1 --but they
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4- 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
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 16
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-chose to get rid of the check. In fact I don't quite know why it wasthere.
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 17
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-There will never be available signals for group G2, so we didn't needthe
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 18
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-special case. Even if there were, this would just be a spurious wake.This
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 20
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2-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 toforce a
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 9 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-9-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. - -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=91bb902f58264a2fd50fbce8f39a9a290dd23706
]meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-10- -Signed-off-by: Sunil Dora <[email protected]> ---- - 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.cQuoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-5-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) - {meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 10 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-10- /* 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 / newG1. */
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-11- 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_twseq,
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 67
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2- behavior. - Note that this works correctly for a zero-initialized condvartoo. */ > - 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)meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4-- + 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)
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4- return false; - - /* We have to consider the following kinds of waiters: -@@ -221,16 +221,10 @@ __condvar_switch_g1 (pthread_cond_t *cond,
uint64_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 79
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4- are not affected. - * Waiters in G1 have already received a signal and been woken. */ - -- /* Update __g1_start, which closes this group. The value we addwill never
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 80
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-- be negative because old_orig_size can only be zero when we switchgroups
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 81
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-- the first time after a condvar was initialized, in which case G1will be
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 82
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-- at index 1 and we will add a value of 1. Relaxed MO is finebecause the
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 83
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-- change comes with no additional constraints that others wouldhave to
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 6 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-6-- 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 finebecause
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 90
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-+ the change comes with no additional constraints that others wouldhave
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4-+ 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 useyet).
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 95
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1- No old waiter can neither grab a signal nor acquire a referencewithout
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 96
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-@@ -242,13 +236,13 @@ __condvar_switch_g1 (pthread_cond_t *cond,
uint64_twseq,meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-8- 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);
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 106
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2- - /* These values are just observed by signalers, and thus protectedby the
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 12 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-12- 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_g1meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 119
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1- because we use an atomic read-modify-write and thus extendthat
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 11 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-11- 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 bb46f3605d..430cbe8a35 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_tseq, unsigned int g,meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 8 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-8- 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 forit.
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 140
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2-@@ -278,7 +278,6 @@ __condvar_cleanup_waiting (void *arg) - * Waiters fetch-add while having acquire the mutex associatedwith the
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4- 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 thecondvar-internal lock
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4- and observed concurrently by waiters. - __g1_orig_size: Initial size of G1 -@@ -299,11 +298,9 @@ __condvar_cleanup_waiting (void *arg) - * Reference count used by waiters concurrently with signalersthat have
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 150
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2- acquired the condvar-internal lock. - __g_signals: The number of signals that can still be consumed,relative to
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 4 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-4-- 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 waitersand
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 5 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-5- 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 doso only
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 160
Quoted 1 line
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-1-@@ -418,9 +415,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 162
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2- too. */ - unsigned int signals = atomic_load_acquire(
cond->__data.__g_signals+ g);meta/recipes-core/glibc/glibc/0026-PR25847-8.patch line 164
Quoted 2 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-2- uint64_t g1_start = __condvar_load_g1_start_relaxed (cond); -- unsigned int lowseq = (g1_start & 1) == g ? signals : g1_start &~1U;
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-7- -- if (seq < (g1_start >> 1)) -+ if (seq < g1_start) - { - /* If the group is closed already, - then this waiter originally had enough extra signals to -@@ -433,13 +429,13 @@ __pthread_cond_wait_common (pthread_cond_t *cond,
pthread_mutex_t*mutex,meta/recipes-core/glibc/glibc/0026-PR25847-8.patch
Quoted 7 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-7- 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 doanother loop
Review
Quoted 12 lines
meta/recipes-core/glibc/glibc/0026-PR25847-8.patch deleted +0
-11- 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; --- -2.49.0 -(quoted diff) +0
-0b/meta/recipes-core/glibc/glibc_2.35.bb
meta/recipes-core/glibc/glibc_2.35.bb SRC_URI =
Quoted 4 lines
index
265dcb9129..ca7f630699100644meta/recipes-core/glibc/glibc_2.35.bb +0
-0@@ -62,14 +62,6 @@ SRC_URI ="${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
Quoted 1 line
file://0022-sysdeps-gnu-configure.ac-Set-libc_cv_rootsbindir-onl.patch \
Quoted 1 line
file://0023-timezone-Make-shell-interpreter-overridable-in-tzsel.patch \
Quoted 1 line
file://0024-fix
Re: [kirkstone 04/14] glibc: Remove partial BZ#25847 backport patches
In reply to Khem RajQuoted 2 lines · Khem Raj
are these backports being done in glibc 2.35 release as well ?
Hi Khem,
Yes, I’ve submitted the backported patches for this pthread issue to glibc upstream for the following stable
branches: 2.38, 2.37, 2.36, and 2.35. You can find the submission here:
https://sourceware.org/pipermail/libc-stable/2025-July/thread.html
Carlos(Glibc maintainer) has already taken the patches into 2.38 and mentioned that he will review the others (including 2.35) as well. The long-term aim is to get these accepted into glibc 2.35 upstream too, so that we can eventually drop our local backports in Yocto through regular branch updates.
Thanks,
Sunil Dora
Re: [OE-core] [kirkstone 04/14] glibc: Remove partial BZ#25847 backport patches
Quoted 7 lines · Sunil Kumar via lists.openembedded.org
On Wed, Oct 15, 2025 at 04:27 AM, Khem Raj wrote:
are these backports being done in glibc 2.35 release as well ?
Hi Khem,
Quoted 8 lines
Yes, I’ve submitted the backported patches for this pthread issue to glibc upstream for the following stable
branches: 2.38, 2.37, 2.36, and 2.35. You can find the submission here:
https://sourceware.org/pipermail/libc-stable/2025-July/thread.htmlCarlos(Glibc maintainer) has already taken the patches into 2.38 and mentioned that he will review the others (including 2.35) as well. The long-term aim is to get these accepted into glibc 2.35 upstream too, so that we can eventually drop our local backports in Yocto through regular branch updates.
Thanks for the info. I am good with these patches.
Quoted 13 lines
Thanks,
Sunil Dora-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#224872): https://lists.openembedded.org/g/openembedded-core/message/224872
Mute This Topic: https://lists.openembedded.org/mt/115762087/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-