Skip to content

Commit 1a5d349

Browse files
ColinIanKingPeter Zijlstra
authored andcommitted
sched: Add unlikey branch hints to several system calls
Adding an unlikely() hint on early error return paths improves the run-time performance of several sched related system calls. Benchmarking on an i9-12900 shows the following per system call performance improvements: before after improvement sched_getattr 182.4ns 170.6ns ~6.5% sched_setattr 284.3ns 267.6ns ~5.9% sched_getparam 161.6ns 148.1ns ~8.4% sched_setparam 1265.4ns 1227.6ns ~3.0% sched_getscheduler 129.4ns 118.2ns ~8.7% sched_setscheduler 1237.3ns 1216.7ns ~1.7% Results are based on running 20 tests with turbo disabled (to reduce clock freq turbo changes), with 10 second run per test based on the number of system calls per second. The % standard deviation of the measurements for the 20 tests was 0.05% to 0.40%, so the results are reliable. Tested on kernel build with gcc 14.2.1 Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b796ea8 commit 1a5d349

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/sched/syscalls.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)
875875
{
876876
struct sched_param lparam;
877877

878-
if (!param || pid < 0)
878+
if (unlikely(!param || pid < 0))
879879
return -EINVAL;
880880
if (copy_from_user(&lparam, param, sizeof(struct sched_param)))
881881
return -EFAULT;
@@ -984,7 +984,7 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr,
984984
struct sched_attr attr;
985985
int retval;
986986

987-
if (!uattr || pid < 0 || flags)
987+
if (unlikely(!uattr || pid < 0 || flags))
988988
return -EINVAL;
989989

990990
retval = sched_copy_attr(uattr, &attr);
@@ -1049,7 +1049,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, pid, struct sched_param __user *, param)
10491049
struct task_struct *p;
10501050
int retval;
10511051

1052-
if (!param || pid < 0)
1052+
if (unlikely(!param || pid < 0))
10531053
return -EINVAL;
10541054

10551055
scoped_guard (rcu) {
@@ -1085,8 +1085,8 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
10851085
struct task_struct *p;
10861086
int retval;
10871087

1088-
if (!uattr || pid < 0 || usize > PAGE_SIZE ||
1089-
usize < SCHED_ATTR_SIZE_VER0 || flags)
1088+
if (unlikely(!uattr || pid < 0 || usize > PAGE_SIZE ||
1089+
usize < SCHED_ATTR_SIZE_VER0 || flags))
10901090
return -EINVAL;
10911091

10921092
scoped_guard (rcu) {

0 commit comments

Comments
 (0)