[tip: sched/core] sched/fair: Avoid redundant updates for unchanged default slices
From: tip-bot2 for Chengfeng Lin
Date: Wed Nov 18 2026 - 08:45:08 EST
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 9dc6cae4904ff34025704041d07c731937db10dc
Gitweb: https://git.kernel.org/tip/9dc6cae4904ff34025704041d07c731937db10dc
Author: Chengfeng Lin <lin2530632123@xxxxxxxxx>
AuthorDate: Mon, 19 Oct 2026 00:59:54 +08:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Wed, 18 Nov 2026 14:32:20 +01:00
sched/fair: Avoid redundant updates for unchanged default slices
For a fair task using the default slice, _sched_setscheduler() leaves
attr.sched_runtime at zero, while se.slice holds the actual duration.
Comparing them directly makes an unchanged sched_setparam() request take
the parameter-update path.
Compare default/custom mode before comparing the requested duration, as
suggested by Peter. For default-mode requests, also check that the task's
slice still matches the current default. Keep the update path outside the
fair class and when an implicit uclamp value needs resetting. Explicit
uclamp requests continue to use the existing update path.
This also handles two cases that an equal runtime alone does not cover:
a custom slice equal to the default must switch the task to custom mode,
and an unchanged legacy request may still need to reset an implicit clamp
after an RT-PI boost has ended.
On an i7-12700KF running v7.2, repeated sched_setparam(0, priority=0)
calls from a SCHED_OTHER, nice-0 task took 616.51 ns per call before this
change and 162.39 ns after it, saving 454.12 ns (73.66%). The existing
custom-slice fast path increased from 162.57 to 163.22 ns (0.40%).
These are syscall microbenchmark results, not an application speedup.
Signed-off-by: Chengfeng Lin <lin2530632123@xxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://lkml.iu.edu/2610.1/11150.html
Link: https://patch.msgid.link/CANGjgdmNCfm=SctvKZ44y8b5n8t_JSp4meX=DKGnG74B3g1vVw@xxxxxxxxxxxxxx
---
kernel/sched/syscalls.c | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c
index 2d77ca0..a78672b 100644
--- a/kernel/sched/syscalls.c
+++ b/kernel/sched/syscalls.c
@@ -490,6 +490,38 @@ req_priv:
return 0;
}
+static bool fair_params_changed(struct task_struct *p,
+ const struct sched_attr *attr)
+{
+ if (attr->sched_nice != task_nice(p))
+ return true;
+
+ /* Keep the full update path for PI-boosted and sched_ext tasks. */
+ if (p->sched_class != &fair_sched_class)
+ return true;
+
+ if (!!attr->sched_runtime != !!p->se.custom_slice)
+ return true;
+
+ if (attr->sched_runtime && attr->sched_runtime != p->se.slice)
+ return true;
+
+ if (!attr->sched_runtime &&
+ p->se.slice != READ_ONCE(sysctl_sched_base_slice))
+ return true;
+
+#ifdef CONFIG_UCLAMP_TASK
+ /* Equal fair parameters do not rule out an implicit clamp reset. */
+ if ((!p->uclamp_req[UCLAMP_MIN].user_defined &&
+ p->uclamp_req[UCLAMP_MIN].value != uclamp_none(UCLAMP_MIN)) ||
+ (!p->uclamp_req[UCLAMP_MAX].user_defined &&
+ p->uclamp_req[UCLAMP_MAX].value != uclamp_none(UCLAMP_MAX)))
+ return true;
+#endif
+
+ return false;
+}
+
int __sched_setscheduler(struct task_struct *p,
const struct sched_attr *attr,
bool user, bool pi)
@@ -588,9 +620,7 @@ recheck:
* but store a possible modification of reset_on_fork.
*/
if (unlikely(policy == p->policy)) {
- if (fair_policy(policy) &&
- (attr->sched_nice != task_nice(p) ||
- (attr->sched_runtime != p->se.slice)))
+ if (fair_policy(policy) && fair_params_changed(p, attr))
goto change;
if (rt_policy(policy) && attr->sched_priority != p->rt_priority)
goto change;