Skip to contentSkip to conversation

signal: improve performance of tgkill and do_rt_tgsigqueueinfo

PATCH New Colin Ian King 1 participant 1 message Feb 12, 2025 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 signal: improve performance of tgkill and do_rt_tgsigqueueinfo

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.

---
 kernel/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/signal.c +2 -2
index 081f19a24506..4ae848ce3a7a 100644
@@ -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.
Signature · 1 line
2.47.2