[PATCH v2 2/5] sched/eevdf: Share the slice protection calculation

From: Christian Loehle

Date: Thu Oct 01 2026 - 09:59:33 EST


set_protect_slice() and update_protect_slice() duplicate the slice
selection and vprot limiting rules. Merge the calculation into
set_protect_slice().

No functional change intended.

Suggested-by: Elif Topuz <elif.topuz@xxxxxxx>
Signed-off-by: Christian Loehle <christian.loehle@xxxxxxx>
---
kernel/sched/fair.c | 39 +++++++++++++++------------------------
1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 85bf02570473..3f881ded5457 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1119,43 +1119,34 @@ struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq)
* When run to parity is disabled, we give a minimum quantum to the running
* entity to ensure progress.
*/
-static inline void set_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
+static inline void set_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity *se,
+ bool update)
{
u64 slice = normalized_sysctl_sched_base_slice;
+ u64 vruntime = se->vruntime;
u64 vprot = se->deadline;

+ if (update) {
+ vruntime = min_vruntime(se->vruntime, avg_vruntime(cfs_rq));
+ vprot = se->vprot;
+ }
+
if (sched_feat(RUN_TO_PARITY))
slice = cfs_rq_min_slice(cfs_rq);

- slice = min(slice, se->slice);
+ if (!update)
+ slice = min(slice, se->slice);

/* If there are shorter slices than se's one */
- if (slice != se->slice) {
- vprot = min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se));
- if (sched_feat(PREEMPT_SHORT))
+ if (update || slice != se->slice) {
+ vprot = min_vruntime(vprot, vruntime + calc_delta_fair(slice, se));
+ if (sched_feat(PREEMPT_SHORT) && slice != se->slice)
vprot = min_vruntime(vprot, ineligible_vruntime(cfs_rq));
}

se->vprot = vprot;
}

-static inline void update_protect_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
-{
- u64 vruntime = min_vruntime(se->vruntime, avg_vruntime(cfs_rq));
- u64 slice = normalized_sysctl_sched_base_slice;
- u64 vprot;
-
- if (sched_feat(RUN_TO_PARITY))
- slice = cfs_rq_min_slice(cfs_rq);
-
- vprot = min_vruntime(se->vprot, vruntime + calc_delta_fair(slice, se));
-
- if (sched_feat(PREEMPT_SHORT) && slice != se->slice)
- vprot = min_vruntime(vprot, ineligible_vruntime(cfs_rq));
-
- se->vprot = vprot;
-}
-
static inline bool protect_slice(struct sched_entity *se)
{
return vruntime_cmp(se->vruntime, "<", se->vprot);
@@ -10268,7 +10259,7 @@ static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_f
if (sched_feat(RUN_TO_PARITY)) {
u64 old_vprot = se->vprot;

- update_protect_slice(cfs_rq, se);
+ set_protect_slice(cfs_rq, se, true);
if (hrtick_enabled_fair(rq) && se->vprot != old_vprot) {
/* The enqueue may have armed the timer before this update. */
if (protect_slice(se))
@@ -15576,7 +15567,7 @@ static void set_next_task_fair(struct rq *rq, struct task_struct *p, enum snt_e
if (on_rq) {
reweight_eevdf(cfs_rq, se, weight, se->on_rq);
if (first)
- set_protect_slice(cfs_rq, se);
+ set_protect_slice(cfs_rq, se, false);
}

if (task_on_rq_queued(p)) {
--
2.34.1