* [PATCH] signal: simplify next_signal()
@ 2026-12-01 20:31 Bradley Morgan
2026-12-02 9:40 ` Oleg Nesterov
2026-12-03 10:26 ` Oleg Nesterov
0 siblings, 2 replies; 5+ messages in thread
From: Bradley Morgan @ 2026-12-01 20:31 UTC (permalink / raw)
To: Oleg Nesterov, Andrew Morton
Cc: Christian Brauner, Thomas Gleixner, Andrea Calabrese,
linux-kernel, Bradley Morgan
Well, next_signal() has a switch over _NSIG_WORDS that special cases
the 1 and 2 word signal sets, but the generic loop already handles
both of them. The 2 word case is just the first iteration, and for 1
word the loop never runs at all, so none of that is needed.
_NSIG_WORDS is a compile time constant, so the compiler unrolls the
loop anyway and the switch is just duplicate code. Same thing commit
b7a8d7589a632 ("kernel: refactor: shorten has_pending_signals")
removed.
Signed-off-by: Bradley Morgan <bradley.morgan@linux.dev>
---
kernel/signal.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index dd770e68faee0..c119411aa9ed3 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -184,7 +184,7 @@ void calculate_sigpending(void)
int next_signal(struct sigpending *pending, sigset_t *mask)
{
- unsigned long i, *s, *m, x;
+ unsigned long *s, *m, x;
int sig = 0;
s = pending->signal.sig;
@@ -194,7 +194,7 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
* Handle the first word specially: it contains the
* synchronous signals that need to be dequeued first.
*/
- x = *s &~ *m;
+ x = *s & ~*m;
if (x) {
if (x & SYNCHRONOUS_MASK)
x &= SYNCHRONOUS_MASK;
@@ -202,26 +202,11 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
return sig;
}
- switch (_NSIG_WORDS) {
- default:
- for (i = 1; i < _NSIG_WORDS; ++i) {
- x = *++s &~ *++m;
- if (!x)
- continue;
- sig = ffz(~x) + i*_NSIG_BPW + 1;
- break;
- }
- break;
-
- case 2:
- x = s[1] &~ m[1];
+ for (unsigned long i = 1; i < _NSIG_WORDS; i++) {
+ x = s[i] & ~m[i];
if (!x)
- break;
- sig = ffz(~x) + _NSIG_BPW + 1;
- break;
-
- case 1:
- /* Nothing to do */
+ continue;
+ sig = ffz(~x) + i * _NSIG_BPW + 1;
break;
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] signal: simplify next_signal()
2026-12-01 20:31 [PATCH] signal: simplify next_signal() Bradley Morgan
@ 2026-12-02 9:40 ` Oleg Nesterov
2026-12-02 16:01 ` Bradley Morgan
2026-12-03 10:26 ` Oleg Nesterov
1 sibling, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2026-12-02 9:40 UTC (permalink / raw)
To: Bradley Morgan
Cc: Andrew Morton, Christian Brauner, Thomas Gleixner,
Andrea Calabrese, linux-kernel
On 12/01, Bradley Morgan wrote:
>
> _NSIG_WORDS is a compile time constant, so the compiler unrolls the
> loop anyway and the switch is just duplicate code. Same thing commit
> b7a8d7589a632 ("kernel: refactor: shorten has_pending_signals")
> removed.
Looks correct at first glance, I'll recheck...
But let me ask... Since you simplify this function anyway, perhaps
__ffs(x) make more sense than ffz(~x) ?
Oleg.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] signal: simplify next_signal()
2026-12-02 9:40 ` Oleg Nesterov
@ 2026-12-02 16:01 ` Bradley Morgan
2026-12-03 10:16 ` Oleg Nesterov
0 siblings, 1 reply; 5+ messages in thread
From: Bradley Morgan @ 2026-12-02 16:01 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Christian Brauner, Thomas Gleixner,
Andrea Calabrese, linux-kernel
On 2 December 2026 09:40:54 GMT, Oleg Nesterov <oleg@redhat.com> wrote:
>On 12/01, Bradley Morgan wrote:
>>
>> _NSIG_WORDS is a compile time constant, so the compiler unrolls the
>> loop anyway and the switch is just duplicate code. Same thing commit
>> b7a8d7589a632 ("kernel: refactor: shorten has_pending_signals")
>> removed.
>
>Looks correct at first glance, I'll recheck...
cheers.
>
>But let me ask... Since you simplify this function anyway, perhaps
>__ffs(x) make more sense than ffz(~x) ?
could this be follow up? Or do you want a V2 with this.
>
>Oleg.
>
>
--- Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] signal: simplify next_signal()
2026-12-02 16:01 ` Bradley Morgan
@ 2026-12-03 10:16 ` Oleg Nesterov
0 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2026-12-03 10:16 UTC (permalink / raw)
To: Bradley Morgan
Cc: Andrew Morton, Christian Brauner, Thomas Gleixner,
Andrea Calabrese, linux-kernel
On 12/02, Bradley Morgan wrote:
>
> On 2 December 2026 09:40:54 GMT, Oleg Nesterov <oleg@redhat.com> wrote:
> >
> >But let me ask... Since you simplify this function anyway, perhaps
> >__ffs(x) make more sense than ffz(~x) ?
>
>
> could this be follow up? Or do you want a V2 with this.
Up to you, I won't insist.
Oleg.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] signal: simplify next_signal()
2026-12-01 20:31 [PATCH] signal: simplify next_signal() Bradley Morgan
2026-12-02 9:40 ` Oleg Nesterov
@ 2026-12-03 10:26 ` Oleg Nesterov
1 sibling, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2026-12-03 10:26 UTC (permalink / raw)
To: Bradley Morgan
Cc: Andrew Morton, Christian Brauner, Thomas Gleixner,
Andrea Calabrese, linux-kernel
On 12/01, Bradley Morgan wrote:
>
> _NSIG_WORDS is a compile time constant, so the compiler unrolls the
> loop anyway and the switch is just duplicate code. Same thing commit
> b7a8d7589a632 ("kernel: refactor: shorten has_pending_signals")
> removed.
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
>
> Signed-off-by: Bradley Morgan <bradley.morgan@linux.dev>
> ---
> kernel/signal.c | 27 ++++++---------------------
> 1 file changed, 6 insertions(+), 21 deletions(-)
>
> diff --git a/kernel/signal.c b/kernel/signal.c
> index dd770e68faee0..c119411aa9ed3 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -184,7 +184,7 @@ void calculate_sigpending(void)
>
> int next_signal(struct sigpending *pending, sigset_t *mask)
> {
> - unsigned long i, *s, *m, x;
> + unsigned long *s, *m, x;
> int sig = 0;
>
> s = pending->signal.sig;
> @@ -194,7 +194,7 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
> * Handle the first word specially: it contains the
> * synchronous signals that need to be dequeued first.
> */
> - x = *s &~ *m;
> + x = *s & ~*m;
> if (x) {
> if (x & SYNCHRONOUS_MASK)
> x &= SYNCHRONOUS_MASK;
> @@ -202,26 +202,11 @@ int next_signal(struct sigpending *pending, sigset_t *mask)
> return sig;
> }
>
> - switch (_NSIG_WORDS) {
> - default:
> - for (i = 1; i < _NSIG_WORDS; ++i) {
> - x = *++s &~ *++m;
> - if (!x)
> - continue;
> - sig = ffz(~x) + i*_NSIG_BPW + 1;
> - break;
> - }
> - break;
> -
> - case 2:
> - x = s[1] &~ m[1];
> + for (unsigned long i = 1; i < _NSIG_WORDS; i++) {
> + x = s[i] & ~m[i];
> if (!x)
> - break;
> - sig = ffz(~x) + _NSIG_BPW + 1;
> - break;
> -
> - case 1:
> - /* Nothing to do */
> + continue;
> + sig = ffz(~x) + i * _NSIG_BPW + 1;
> break;
> }
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 10:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 20:31 [PATCH] signal: simplify next_signal() Bradley Morgan
2026-12-02 9:40 ` Oleg Nesterov
2026-12-02 16:01 ` Bradley Morgan
2026-12-03 10:16 ` Oleg Nesterov
2026-12-03 10:26 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®