[PATCH 1/8] perf bench futex: Retry futex_wait() when interrupted by a signal
From: Michal Pluta
Date: Sat Sep 26 2026 - 15:05:14 EST
The worker threads in 'futex wake' and 'futex wake-parallel' are meant
to go back to sleep when a signal interrupts futex_wait(), but the check
never works. futex_wait() returns -1 and sets errno, so comparing its
return value with EINTR is always true and the loop ends at the first
interruption.
The worker then exits without having been woken. 'futex wake' keeps
calling futex_wake() forever, because the number of woken threads never
reaches the total, while 'futex wake-parallel' finishes but shows the
wrong number of threads.
Check errno instead.
Fixes: 598adc5c9c1c ("perf bench futex: Handle spurious wakeups")
Fixes: d65817b4e707 ("perf bench futex: Support parallel waker threads")
Assisted-by: LLM
Signed-off-by: Michal Pluta <michalpl2003@xxxxxxxxx>
---
tools/perf/bench/futex-wake-parallel.c | 7 +++----
tools/perf/bench/futex-wake.c | 7 +++----
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
index 6aede7c46b33..a089d8ee4b02 100644
--- a/tools/perf/bench/futex-wake-parallel.c
+++ b/tools/perf/bench/futex-wake-parallel.c
@@ -139,10 +139,9 @@ static void *blocked_workerfn(void *arg __maybe_unused)
cond_wait(&thread_worker, &thread_lock);
mutex_unlock(&thread_lock);
- while (1) { /* handle spurious wakeups */
- if (futex_wait(&futex, 0, NULL, futex_flag) != EINTR)
- break;
- }
+ /* Retry if the wait was interrupted by a signal. */
+ while (futex_wait(&futex, 0, NULL, futex_flag) == -1 && errno == EINTR)
+ ;
pthread_exit(NULL);
return NULL;
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
index a31fc1563862..66d30ca91405 100644
--- a/tools/perf/bench/futex-wake.c
+++ b/tools/perf/bench/futex-wake.c
@@ -75,10 +75,9 @@ static void *workerfn(void *arg __maybe_unused)
cond_wait(&thread_worker, &thread_lock);
mutex_unlock(&thread_lock);
- while (1) {
- if (futex_wait(&futex1, 0, NULL, futex_flag) != EINTR)
- break;
- }
+ /* Retry if the wait was interrupted by a signal. */
+ while (futex_wait(&futex1, 0, NULL, futex_flag) == -1 && errno == EINTR)
+ ;
pthread_exit(NULL);
return NULL;
--
2.43.0