Re: [PATCH RFC -rcu/dev] hazptrtorture: Release all deferred hazard pointers before stopping
From: Andrea Parri
Date: Fri Oct 23 2026 - 08:08:12 EST
On Thu, Oct 22, 2026 at 03:55:44PM -0700, Paul E. McKenney wrote:
> On Thu, Oct 22, 2026 at 02:55:55PM +0200, Andrea Parri wrote:
[...]
> Then let's please keep the torture_must_stop() check. Yes, there is
> still a window between the return from torture_must_stop() and the
> call to torture_hrtimeout_ms(), but maybe that is something to take
> care of later on.
Will do.
[...]
> Yes, agreed, almost:
>
> o Keep the hazptr_torture_do_pending() do-while loop as it
> is, but add the for_each_possible_cpu() after loop exit.
>
> o Stop the readers first, stop hazptr_torture_do_pending()
> to flush out anything left from the readers, then stop
> the writer.
>
> However, for the "almost", note that the "while (!torture_must_stop())"
> needs to become "while (!kthread_should_stop())". If this change is
> not made, then hazptr_torture_do_pending() will exit its do-while loop
> as soon as hazptr_torture_cleanup() calls torture_cleanup_begin().
> This will of course defeat the reordering.
>
> Does that work, or am I still missing something?
do_pending does leave the loop then, but the final pass goes after
torture_kthread_stopping(), not right after the loop:
} while (!torture_must_stop());
torture_kthread_stopping("hazptr_torture_do_pending");
/* The readers have stopped, so nothing new can be deferred. */
for_each_possible_cpu(cpu)
hazptr_torture_do_one_pending(cpu, &rand);
return 0;
torture_kthread_stopping() sleeps HZ/20 at a time until
kthread_should_stop(), so the pass runs only once
hazptr_torture_cleanup() stops do_pending, after the readers.
With "while (!kthread_should_stop())" and the torture_must_stop()
check before the sleep, do_pending would instead spin without sleeping
from torture_cleanup_begin() until it is stopped.
> Alternatively, you could keep the current do-while condition and place
> a loop around your post-do-while code like this:
>
> while (!kthread_should_stop())
> for_each_possible_cpu(cpu)
> hazptr_torture_do_one_pending(cpu, &rand);
>
> But changing the do-while condition looks cleaner to me.
That loop would spin too.
> This code will also need adjustment when something like a call_hazptr()
> is added, presumably along with a hazptr_barrier(), but we can worry
> about that when it happens.
Agreed.
I have been running this version locally, with the rest of v1: a
30-minute PREEMPT run, and a 30-minute NOPREEMPT run with
torture_type=hazptr, pass. With kthread_do_pending_ms=10000, the
shutdown still takes less than 150ms. If it works for you, v1 will
have it.
Thanks,
Andrea