All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kernel: refactor: shorten has_pending_signals
@ 2026-05-20  6:28 Andrea Calabrese
  2026-05-21 12:50 ` Oleg Nesterov
  0 siblings, 1 reply; 6+ messages in thread
From: Andrea Calabrese @ 2026-05-20  6:28 UTC (permalink / raw)
  To: brauner, oleg, akpm, peterz, tglx, kexinsun, adrianhuang0701,
	elver, linux-kernel
  Cc: linux-amarula, Andrea Calabrese

In has_pending_signals there was a switch/case used for optimizations.
However, today's compilers perform loop unrolling efficiently, thus it
is not needed anymore.
put i inside the for declaration so we do not risk its escape from the
scope. Moreover, i starts now from 0 and counts up, as it is a more
usual pattern.

Signed-off-by: Andrea Calabrese <andrea.calabrese@amarulasolutions.com>
---
The difference with V1 is in the description, now accurate thanks to the
review.
As before, the patch has been tested on gcc x86 and generates the same
code.

kernel/signal.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 2d102e025883..799ee98cf03e 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -130,28 +130,10 @@ static bool sig_ignored(struct task_struct *t, int sig, bool force)
  */
 static inline bool has_pending_signals(sigset_t *signal, sigset_t *blocked)
 {
-	unsigned long ready;
-	long i;
-
-	switch (_NSIG_WORDS) {
-	default:
-		for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
-			ready |= signal->sig[i] &~ blocked->sig[i];
-		break;
-
-	case 4: ready  = signal->sig[3] &~ blocked->sig[3];
-		ready |= signal->sig[2] &~ blocked->sig[2];
-		ready |= signal->sig[1] &~ blocked->sig[1];
-		ready |= signal->sig[0] &~ blocked->sig[0];
-		break;
-
-	case 2: ready  = signal->sig[1] &~ blocked->sig[1];
-		ready |= signal->sig[0] &~ blocked->sig[0];
-		break;
-
-	case 1: ready  = signal->sig[0] &~ blocked->sig[0];
-	}
-	return ready !=	0;
+	unsigned long ready = 0;
+	for (long i = 0; i < _NSIG_WORDS; i++)
+		ready |= signal->sig[i] & ~blocked->sig[i];
+	return ready != 0;
 }
 
 #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-22 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20  6:28 [PATCH v2] kernel: refactor: shorten has_pending_signals Andrea Calabrese
2026-05-21 12:50 ` Oleg Nesterov
2026-05-21 13:34   ` Andrea Calabrese
2026-05-21 14:35     ` Andrea Calabrese
2026-05-22 15:24       ` Oleg Nesterov
2026-05-22 17:24         ` Andrea Calabrese

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.