| Message ID | 20260520062849.183621-2-andrea.calabrese@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path:
<linux-amarula+bncBCXJZLUN74BRBO5KWXIAMGQEO7IFMLA@amarulasolutions.com>
X-Original-To: linux-amarula@patchwork.amarulasolutions.com
Delivered-To: linux-amarula@patchwork.amarulasolutions.com
Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com
[209.85.218.69])
by ganimede.amarulasolutions.com (Postfix) with ESMTPS id A755B3F0D7
for <linux-amarula@patchwork.amarulasolutions.com>;
Wed, 20 May 2026 08:31:24 +0200 (CEST)
Received: by mail-ej1-f69.google.com with SMTP id
a640c23a62f3a-bd52e4acb11sf311315966b.3
for <linux-amarula@patchwork.amarulasolutions.com>;
Tue, 19 May 2026 23:31:24 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1779258684; cv=pass;
d=google.com; s=arc-20240605;
b=NGgc9uk3b19ND6Aq+OULKb2UuuiEa7isBEdmUdwYd6yJrKzcmYhJHYG+a32MOV+1dI
q+ahv9b4NEKNbQ/Er5/Nu9iyIa5Py8mv6ceH7PBLsIFL/9sD3pxgil2RQcpfxAXGoiUb
g8uPqcE69HeITKWdlkQYTMhNU+Rp0/OYiOmwkJunvoiqIJdssTV76lcok7qwIqxQLF9M
JI2oRXDTXQC+9SPjA7G/5QjpQXxmkyMKZqwD4B2tPtga4gSsw//xlZH2WYxKz5R8hw+y
nirWMjqpB4bobE+E8fKOoXQaHtbtPrtOtpWX8DgzcIsE6DE5l+IpSURwKnuWFu6YO/dO
XtWA==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:mime-version:message-id:date:subject:cc:to
:from:dkim-signature;
bh=b4zmsId/hyjTXP4qkc30NGuDQrXR3RQ4gRzrRxIpcbw=;
fh=bflzbNI0v77MDoNR7PzFqNt8W/iVZ2C93OjoAeL0RFw=;
b=Fgh6wUhsae1k1QuwJB/oEXPSbsdjKtWJKVV33KuH8LgWMj8bBCkKKzMHuq1lsE99XD
vAJm94HKWO8uB+0sQkgMYjIL0GDHtBOVj+WCoMX1mUdHpEfhI+1Fe+EJNICVHoc56LLq
hUulRGrYnkogF0ZmU/+rxdoZgThYiqglHd7uGBmZGe3SGlvwLXleiSRh+6NLitALRq2f
DXKt2u6Uf2nucfOgueGAcqKDIj5cWzPWdq3+T1aQ7fa9MtR47Kds0IBWnR3nFqYIepl5
OU4FdmNP/51/+NQl9igF7tgv3MEbNPQiFFhrwLtswqz2/gOqPty2An4WgV0y6qznO/0c
p3zw==;
darn=patchwork.amarulasolutions.com
ARC-Authentication-Results: i=2; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=Ns+GYB5q;
spf=pass (google.com: domain of andrea.calabrese@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=andrea.calabrese@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=amarulasolutions.com; s=google; t=1779258684; x=1779863484;
darn=patchwork.amarulasolutions.com;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:x-original-authentication-results
:x-original-sender:mime-version:message-id:date:subject:cc:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=b4zmsId/hyjTXP4qkc30NGuDQrXR3RQ4gRzrRxIpcbw=;
b=ipQuQUVmgYiuKcz1SlfynUhvZ5LuANX1fN7ADP3WbypVV+NvWr8rSLE7lTrT6JqHHK
hUDoEb91u7BSMk3MelmOkmmn7hUCfzxNFRh3nDSCi1DyDV1HG79axVdg1PWB54hf6mx/
9uFUm8lbx8q5yAlT8YhhBewhd4XVi4XWj7Tbw=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20251104; t=1779258684; x=1779863484;
h=list-unsubscribe:list-archive:list-help:list-post
:x-spam-checked-in-group:list-id:mailing-list:precedence
:x-original-authentication-results:x-original-sender:mime-version
:message-id:date:subject:cc:to:from:x-gm-gg:x-beenthere
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=b4zmsId/hyjTXP4qkc30NGuDQrXR3RQ4gRzrRxIpcbw=;
b=YSWbV6lgzbkQXDWzB8bzZJ3X7FxO2AZED0kBY7npO0PHpENaEUOMSBNfh+Rdm9nILd
XVq6j5T8S1jJ9NHRTlNZ90hOTYFly7key0NJ4i6WeuVUlt95o61IY76DjoQFJEexdGfa
/IzdylJRVIymswCdwshzOXwTXMuZ7eJaKKkqiTVnkxOD1bAnzzKOHD54bAR17mfKqBJl
w4iSSUvOLS/vCcU7a20z6QRS2ti56c8XI3KryuzgVg+VSvSI7u/1h6qCcRlIOHo18yZU
yyTPjLiBcvMoGeVguNdKFsH853KLY2c4Lhe/UvTbqsSVk+iR733fmPVcSdkEmCnA5L1k
2X4Q==
X-Forwarded-Encrypted: i=2;
AFNElJ8whrFOp0faqCAzayyV4llIDKZZlgHhNshjd5fgZMRWox1WXVkMbgfjkVZNTiUgzOZ8fkw5wy7Nvg1t4Lnz@patchwork.amarulasolutions.com
X-Gm-Message-State: AOJu0YwuzxWALjaT8HAjTdpnpbwqvp1P6qicAYSNL+5vLWVatACT/2pr
apEtMkILOG/ce7tzMXiz3HYUScTrcKJrYDBiWliFmL8qG4oL4f3T8C/ZfMihvqnIpWwfEw==
X-Received: by 2002:a17:907:8748:b0:b9d:1673:9994 with SMTP id
a640c23a62f3a-bd51793014amr1390831666b.39.1779258683890;
Tue, 19 May 2026 23:31:23 -0700 (PDT)
X-BeenThere: linux-amarula@amarulasolutions.com;
h="AUV6zMN1QYBrq+BEyYBbdTQ7QC1BHVbh4e66oJK7J7GLY4ANig=="
Received: by 2002:aa7:d890:0:b0:679:ba2e:fbd2 with SMTP id
4fb4d7f45d1cf-6833038406fls2876934a12.1.-pod-prod-01-eu;
Tue, 19 May 2026 23:31:22 -0700 (PDT)
X-Received: by 2002:a17:907:6d21:b0:bd9:60d8:6609 with SMTP id
a640c23a62f3a-bd960d86896mr332624066b.13.1779258682114;
Tue, 19 May 2026 23:31:22 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1779258682; cv=none;
d=google.com; s=arc-20240605;
b=NvSCc/IzdktNPEcOB67zjyF3regB52qBJAEmnJPqvinPf2kwIBf1QdOYSbgOcalNaZ
GBbFqYrpInFWyz8CO3f8PMxw1jkK0hZoyB1fTazrZRini4NrjrR753FGGJzuV6VgHTTN
VhlWj3H1hXig7SvU0YZKks3FUUj86jGsKXrXM0Y6jczr8Z2nNvQHY7uC5cZk/B6hilST
0xGlBSkM17CTsCfGS5+pB2Bw2/MREa9u8tfj+4cakdlsSiCBuDmP6QHyXgAejpLenz6r
zYgRZ/eUtvDf6RK7Sn7lFwr/o3qZMS/wADk/eqhFotCnb9lprYEHsm1aY97ZK3ZLA4u7
kxxQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:dkim-signature;
bh=tJsm+vTaAtG3guEM9DFX3cDN+y8PVlBk+kArJ9s0GwU=;
fh=ykbBea1XW+IrdZde7E1qYXSEqdV7CGzzp6xgL7zWkEI=;
b=KJkN3+JmOXMwIOLy2YrHAVHgBO4e3y+15HMB6NZwo3RIf0sDkZ44nJIHP52mkcACkt
7e6iuyfHQLzresTODIMo1tSzjJlfSvd7HP0XTw2SyPvanreqtaRM0HyI6RrmLt1u2I9c
rDvtZt/6aPwgwEOLhAIHUrxegu9QuGweAf4wpDSvD0/ZWhwf1+pJLBc4i4pSfzrGdbZJ
i7jcHN62e3ck82MsJQ2mGV+F2PS0JWWocjAzt4dEcFuNC7plYNF9b8adxcIu6Q6SOwzB
XWHj5c3VLixyw/ZLVZn+ng+4ifv8G4az1dfnYWyr8+lD+ggAv1mOQBV4ly2HM2eaxA40
KUPw==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=Ns+GYB5q;
spf=pass (google.com: domain of andrea.calabrese@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=andrea.calabrese@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
Received: from mail-sor-f41.google.com (mail-sor-f41.google.com.
[209.85.220.41])
by mx.google.com with SMTPS id
a640c23a62f3a-bd58ddefdd9sor296162366b.13.2026.05.19.23.31.22
for <linux-amarula@amarulasolutions.com>
(Google Transport Security);
Tue, 19 May 2026 23:31:22 -0700 (PDT)
Received-SPF: pass (google.com: domain of
andrea.calabrese@amarulasolutions.com designates 209.85.220.41 as permitted
sender) client-ip=209.85.220.41;
X-Gm-Gg: Acq92OG6v963QOudAdrTlp4tAYUBWBFJMIwB6X2jQ77HISrr+sYYHyH89Ji8l/iNuup
Dg+cH3qr7vfN+VuRcmvRW5IUnhTCLkq/2X0etKdWvEnHeJrZ2XDPpRWf8yES425tRNY9qFsAMrk
9fM4bqNonaP4KX1BnyPorRQPa+vJi6ZB0zyShamRTR6chk/ouLylze9ZSB0H5c1h7W7fWwtYAGA
wyix4nwrv17UmzwUcLt2gLZIbf12vm0TP/IowCwTxT4HD14pc4TEn8vb2AFhCP408czVowzSFsh
p0Dd4LYnu4rML8v3Dp5lpz7Bh2RrZ2/G4iqBlnst4kVGzQfC1aU+F+c3ziCsVwwo2IH8M724qr+
liRSn7ArRz/zajqmWL1G2758Cn570SJtSfyCNVzdu14HKVmQjLQxMLagSzc1ZijNDJnDf9LQ9Ze
1++tbc5Ohe1VWwkBECVUWKRm90Zh8GKCWvnLpK+TsAhdJdG8Z8058Mih68o7yDqOrIbHfRr/+2D
6DZSP9/K6/OdwgKPG9xcCgMPw==
X-Received: by 2002:a17:906:6207:b0:bd2:2852:683b with SMTP id
a640c23a62f3a-bd5177c7dd5mr1325236266b.16.1779258681589;
Tue, 19 May 2026 23:31:21 -0700 (PDT)
Received: from fedora.tail032493.ts.net (98-215-98-95.ftth.glasoperator.nl.
[95.98.215.98])
by smtp.gmail.com with ESMTPSA id
a640c23a62f3a-bd4f4c314f5sm807572866b.23.2026.05.19.23.31.19
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 19 May 2026 23:31:20 -0700 (PDT)
From: Andrea Calabrese <andrea.calabrese@amarulasolutions.com>
To: brauner@kernel.org,
oleg@redhat.com,
akpm@linux-foundation.org,
peterz@infradead.org,
tglx@kernel.org,
kexinsun@smail.nju.edu.cn,
adrianhuang0701@gmail.com,
elver@google.com,
linux-kernel@vger.kernel.org
Cc: linux-amarula@amarulasolutions.com,
Andrea Calabrese <andrea.calabrese@amarulasolutions.com>
Subject: [PATCH v2] kernel: refactor: shorten has_pending_signals
Date: Wed, 20 May 2026 08:28:50 +0200
Message-ID: <20260520062849.183621-2-andrea.calabrese@amarulasolutions.com>
X-Mailer: git-send-email 2.54.0
MIME-Version: 1.0
X-Original-Sender: andrea.calabrese@amarulasolutions.com
X-Original-Authentication-Results: mx.google.com; dkim=pass
header.i=@amarulasolutions.com header.s=google header.b=Ns+GYB5q;
spf=pass (google.com: domain of andrea.calabrese@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=andrea.calabrese@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=neutral header.i=@amarulasolutions.com
Content-Type: text/plain; charset="UTF-8"
Precedence: list
Mailing-list: list linux-amarula@amarulasolutions.com;
contact linux-amarula+owners@amarulasolutions.com
List-ID: <linux-amarula.amarulasolutions.com>
X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com
X-Google-Group-Id: 476853432473
List-Post:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>,
<mailto:linux-amarula@amarulasolutions.com>
List-Help:
<https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>,
<mailto:linux-amarula+help@amarulasolutions.com>
List-Archive:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/>
List-Unsubscribe:
<mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>,
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe>
|
| Series |
[v2] kernel: refactor: shorten has_pending_signals
|
|
Commit Message
Andrea Calabrese
May 20, 2026, 6:28 a.m. UTC
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(-)
Comments
On 05/20, Andrea Calabrese wrote: > > 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; > } Note that with your patch the main loop doesn't stop when ready becomes != 0... OK, I guess the modern compilers doesn't need this hint even if _NSIG_WORDS > 1, so Acked-by: Oleg Nesterov <oleg@redhat.com> But since your patch is just a cleanup, you could do for (int i = 0; i < _NSIG_WORDS; i++) { if (signal->sig[i] & ~blocked->sig[i]) return true; } return false; but this is subjective, I won't insist. Oleg. To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
On Thu, 2026-05-21 at 14:50 +0200, Oleg Nesterov wrote: > On 05/20, Andrea Calabrese wrote: > > > > 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; > > } > > Note that with your patch the main loop doesn't stop when ready > becomes != 0... > > OK, I guess the modern compilers doesn't need this hint even if > _NSIG_WORDS > 1, so > > Acked-by: Oleg Nesterov <oleg@redhat.com> > > > But since your patch is just a cleanup, you could do > > for (int i = 0; i < _NSIG_WORDS; i++) { > if (signal->sig[i] & ~blocked->sig[i]) > return true; > } > > return false; > Good idea, I will send a v3 with this! > but this is subjective, I won't insist. > > Oleg. To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
On Thu, 2026-05-21 at 15:34 +0200, Andrea Calabrese wrote: > On Thu, 2026-05-21 at 14:50 +0200, Oleg Nesterov wrote: > > On 05/20, Andrea Calabrese wrote: > > > > > > 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; > > > } > > > > Note that with your patch the main loop doesn't stop when ready > > becomes != 0... > > > > OK, I guess the modern compilers doesn't need this hint even if > > _NSIG_WORDS > 1, so > > > > Acked-by: Oleg Nesterov <oleg@redhat.com> > > > > > > But since your patch is just a cleanup, you could do > > > > for (int i = 0; i < _NSIG_WORDS; i++) { > > if (signal->sig[i] & ~blocked->sig[i]) > > return true; > > } > > > > return false; > > > Good idea, I will send a v3 with this! > Looking for a suggestion here: I have the objdumps before and after, and I see that the assembly with this modification does change. I am not sure whether the new one is ok in terms of performance, as it adds one more instruction. Based on the objdumps, I have the situation before the change:
On 05/21, Andrea Calabrese wrote: > > Looking for a suggestion here: I have the objdumps before and after, > and I see that the assembly with this modification does change. OK, lets forget it, lets stay with V2. Oleg. To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
> Il giorno 22 mag 2026, alle ore 17:24, Oleg Nesterov <oleg@redhat.com> ha scritto: > > On 05/21, Andrea Calabrese wrote: >> >> Looking for a suggestion here: I have the objdumps before and after, >> and I see that the assembly with this modification does change. > > OK, lets forget it, lets stay with V2. > > Oleg. > Thank you! Andrea To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
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))