Re: [PATCH] selftests/futex: Retry the wake in futex_wait instead of sleeping
From: Thomas Gleixner
Date: Mon Nov 30 2026 - 15:54:46 EST
On Sun, Nov 08 2026 at 09:34, Mathieu Desnoyers wrote:
> On 2026-11-08 09:23, Mathieu Desnoyers wrote:
>> Each futex_wait test starts a waiter thread, which calls futex_wait()
>> with a 30ms timeout. The main thread sleeps 10ms, then expects
>> futex_wake() to wake one waiter. So the test assumes that the waiter
>> reaches futex_wait() within 10ms, and that the main thread runs again
>> within 30ms.
>>
>> A busy machine breaks both. The built-in locktorture at times holds a
>> spinlock for 100ms with preemption off. With it, private_futex failed in
>> about 0.5% of the runs in 8-CPU VMs, on v7.4-rc1.
>> Timestamps showed two cases. The waiter started up to 75ms late, after
>> the wake. Or the main thread woke up to 105ms late, after the waiter
>> had timed out.
>>
>> Fix this by retrying futex_wake() every millisecond until it wakes the
>> waiter, for up to 5s. Give the waiter a timeout of 10s, so that it
>> outlasts the retries. The tests then wait for the waiter, instead of
>> assuming when it runs.
>>
>> With this patch, private_futex passed 6000 runs of 6000 in the same VMs,
>> and the three tests 2000 runs of 2000.
> Self-nack. That's flaky as well. A bounded retry can still fail. This
> needs a proper synchronization flag. Will respin a v2.
See:
6c4a1b972643 ("selftests/futex: Provide thread creation and synchronization helpers")
23dd3f884926 ("selftests/futex: Use thread synchronization helpers instead of usleep()")