mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Ian King <colin.i.king@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH][next] signal: improve performance of tgkill and do_rt_tgsigqueueinfo
Date: Wed, 12 Feb 2025 16:07:34 +0000	[thread overview]
Message-ID: <20250212160734.527199-1-colin.i.king@gmail.com> (raw)

Adding an unlikely() hint on a couple of unlikely error return
paths improves run-time performance of tgkill and do_rt_tgsigqueueinfo.

Benchmarking on an i9-12900 shows an improvement of ~5% on a tgkill
on a process and ~3% improvement on sigqueue. Results based on running
20 tests and taking geometric mean of number of calls per second. Used
signal number 0 to check if process exists.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 kernel/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 081f19a24506..4ae848ce3a7a 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -4165,7 +4165,7 @@ static int do_tkill(pid_t tgid, pid_t pid, int sig)
 SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid_t, pid, int, sig)
 {
 	/* This is only valid for single tasks */
-	if (pid <= 0 || tgid <= 0)
+	if (unlikely(pid <= 0 || tgid <= 0))
 		return -EINVAL;
 
 	return do_tkill(tgid, pid, sig);
@@ -4233,7 +4233,7 @@ COMPAT_SYSCALL_DEFINE3(rt_sigqueueinfo,
 static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, kernel_siginfo_t *info)
 {
 	/* This is only valid for single tasks */
-	if (pid <= 0 || tgid <= 0)
+	if (unlikely(pid <= 0 || tgid <= 0))
 		return -EINVAL;
 
 	/* Not even root can pretend to send signals from the kernel.
-- 
2.47.2


                 reply	other threads:[~2025-02-12 16:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250212160734.527199-1-colin.i.king@gmail.com \
    --to=colin.i.king@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®