Re: [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset
From: Andrew Morton
Date: Mon Mar 03 2025 - 17:24:35 EST
On Mon, 3 Mar 2025 14:49:08 +0100 Mateusz Guzik <mjguzik@xxxxxxxxx> wrote:
> Clearing is an atomic op and the flag is not set most of the time.
>
> When creating and destroying threads in the same process with the
> pthread family, the primary bottleneck is calls to sigprocmask which
> take the process-wide sighand lock.
>
> Avoiding the atomic gives me a 2% bump in start/teardown rate at 24-core
> scale.
>
Neat. Perhaps add an unlikely() also?
--- a/kernel/signal.c~signal-avoid-clearing-tif_sigpending-in-recalc_sigpending-if-unset-fix
+++ a/kernel/signal.c
@@ -177,7 +177,7 @@ static bool recalc_sigpending_tsk(struct
void recalc_sigpending(void)
{
if (!recalc_sigpending_tsk(current) && !freezing(current)) {
- if (test_thread_flag(TIF_SIGPENDING))
+ if (unlikely(test_thread_flag(TIF_SIGPENDING)))
clear_thread_flag(TIF_SIGPENDING);
}
}
_