Skip to content

Commit 74eec63

Browse files
vingu-linaroPeter Zijlstra
authored andcommitted
sched/fair: Fix NO_RUN_TO_PARITY case
EEVDF expects the scheduler to allocate a time quantum to the selected entity and then pick a new entity for next quantum. Although this notion of time quantum is not strictly doable in our case, we can ensure a minimum runtime for each task most of the time and pick a new entity after a minimum time has elapsed. Reuse the slice protection of run to parity to ensure such runtime quantum. Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20250708165630.1948751-3-vincent.guittot@linaro.org
1 parent 9cdb4fe commit 74eec63

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

include/linux/sched.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,15 @@ struct sched_entity {
583583
u64 sum_exec_runtime;
584584
u64 prev_sum_exec_runtime;
585585
u64 vruntime;
586-
s64 vlag;
586+
union {
587+
/*
588+
* When !@on_rq this field is vlag.
589+
* When cfs_rq->curr == se (which implies @on_rq)
590+
* this field is vprot. See protect_slice().
591+
*/
592+
s64 vlag;
593+
u64 vprot;
594+
};
587595
u64 slice;
588596

589597
u64 nr_migrations;

kernel/sched/fair.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -882,23 +882,35 @@ struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq)
882882
}
883883

884884
/*
885-
* HACK, stash a copy of deadline at the point of pick in vlag,
886-
* which isn't used until dequeue.
885+
* Set the vruntime up to which an entity can run before looking
886+
* for another entity to pick.
887+
* In case of run to parity, we protect the entity up to its deadline.
888+
* When run to parity is disabled, we give a minimum quantum to the running
889+
* entity to ensure progress.
887890
*/
888891
static inline void set_protect_slice(struct sched_entity *se)
889892
{
890-
se->vlag = se->deadline;
893+
u64 slice = se->slice;
894+
u64 vprot = se->deadline;
895+
896+
if (!sched_feat(RUN_TO_PARITY))
897+
slice = min(slice, normalized_sysctl_sched_base_slice);
898+
899+
if (slice != se->slice)
900+
vprot = min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se));
901+
902+
se->vprot = vprot;
891903
}
892904

893905
static inline bool protect_slice(struct sched_entity *se)
894906
{
895-
return se->vlag == se->deadline;
907+
return ((s64)(se->vprot - se->vruntime) > 0);
896908
}
897909

898910
static inline void cancel_protect_slice(struct sched_entity *se)
899911
{
900912
if (protect_slice(se))
901-
se->vlag = se->deadline + 1;
913+
se->vprot = se->vruntime;
902914
}
903915

904916
/*
@@ -937,7 +949,7 @@ static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq)
937949
if (curr && (!curr->on_rq || !entity_eligible(cfs_rq, curr)))
938950
curr = NULL;
939951

940-
if (sched_feat(RUN_TO_PARITY) && curr && protect_slice(curr))
952+
if (curr && protect_slice(curr))
941953
return curr;
942954

943955
/* Pick the leftmost entity if it's eligible */
@@ -1156,11 +1168,8 @@ static inline void update_curr_task(struct task_struct *p, s64 delta_exec)
11561168
cgroup_account_cputime(p, delta_exec);
11571169
}
11581170

1159-
static inline bool did_preempt_short(struct cfs_rq *cfs_rq, struct sched_entity *curr)
1171+
static inline bool resched_next_slice(struct cfs_rq *cfs_rq, struct sched_entity *curr)
11601172
{
1161-
if (!sched_feat(PREEMPT_SHORT))
1162-
return false;
1163-
11641173
if (protect_slice(curr))
11651174
return false;
11661175

@@ -1248,7 +1257,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
12481257
if (cfs_rq->nr_queued == 1)
12491258
return;
12501259

1251-
if (resched || did_preempt_short(cfs_rq, curr)) {
1260+
if (resched || resched_next_slice(cfs_rq, curr)) {
12521261
resched_curr_lazy(rq);
12531262
clear_buddies(cfs_rq, curr);
12541263
}

0 commit comments

Comments
 (0)