From: "tip-bot2 for Vincent Guittot" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Vincent Guittot <vincent.guittot@linaro.org>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/core] sched/fair: Fix NO_RUN_TO_PARITY case
Date: Thu, 10 Jul 2025 12:46:34 -0000 [thread overview]
Message-ID: <175215159451.406.1574940645817260327.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250708165630.1948751-3-vincent.guittot@linaro.org>
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 74eec63661d46a7153d04c2e0249eeb76cc76d44
Gitweb: https://git.kernel.org/tip/74eec63661d46a7153d04c2e0249eeb76cc76d44
Author: Vincent Guittot <vincent.guittot@linaro.org>
AuthorDate: Tue, 08 Jul 2025 18:56:26 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 09 Jul 2025 13:40:22 +02:00
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
---
include/linux/sched.h | 10 +++++++++-
kernel/sched/fair.c | 31 ++++++++++++++++++++-----------
2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4802fcf..5592138 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -583,7 +583,15 @@ struct sched_entity {
u64 sum_exec_runtime;
u64 prev_sum_exec_runtime;
u64 vruntime;
- s64 vlag;
+ union {
+ /*
+ * When !@on_rq this field is vlag.
+ * When cfs_rq->curr == se (which implies @on_rq)
+ * this field is vprot. See protect_slice().
+ */
+ s64 vlag;
+ u64 vprot;
+ };
u64 slice;
u64 nr_migrations;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 43fe5c8..8d288df 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -882,23 +882,35 @@ struct sched_entity *__pick_first_entity(struct cfs_rq *cfs_rq)
}
/*
- * HACK, stash a copy of deadline at the point of pick in vlag,
- * which isn't used until dequeue.
+ * Set the vruntime up to which an entity can run before looking
+ * for another entity to pick.
+ * In case of run to parity, we protect the entity up to its deadline.
+ * 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 sched_entity *se)
{
- se->vlag = se->deadline;
+ u64 slice = se->slice;
+ u64 vprot = se->deadline;
+
+ if (!sched_feat(RUN_TO_PARITY))
+ slice = min(slice, normalized_sysctl_sched_base_slice);
+
+ if (slice != se->slice)
+ vprot = min_vruntime(vprot, se->vruntime + calc_delta_fair(slice, se));
+
+ se->vprot = vprot;
}
static inline bool protect_slice(struct sched_entity *se)
{
- return se->vlag == se->deadline;
+ return ((s64)(se->vprot - se->vruntime) > 0);
}
static inline void cancel_protect_slice(struct sched_entity *se)
{
if (protect_slice(se))
- se->vlag = se->deadline + 1;
+ se->vprot = se->vruntime;
}
/*
@@ -937,7 +949,7 @@ static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq)
if (curr && (!curr->on_rq || !entity_eligible(cfs_rq, curr)))
curr = NULL;
- if (sched_feat(RUN_TO_PARITY) && curr && protect_slice(curr))
+ if (curr && protect_slice(curr))
return curr;
/* 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)
cgroup_account_cputime(p, delta_exec);
}
-static inline bool did_preempt_short(struct cfs_rq *cfs_rq, struct sched_entity *curr)
+static inline bool resched_next_slice(struct cfs_rq *cfs_rq, struct sched_entity *curr)
{
- if (!sched_feat(PREEMPT_SHORT))
- return false;
-
if (protect_slice(curr))
return false;
@@ -1248,7 +1257,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
if (cfs_rq->nr_queued == 1)
return;
- if (resched || did_preempt_short(cfs_rq, curr)) {
+ if (resched || resched_next_slice(cfs_rq, curr)) {
resched_curr_lazy(rq);
clear_buddies(cfs_rq, curr);
}
next prev parent reply other threads:[~2025-07-10 12:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 16:56 [PATCH v3 0/6] sched/fair: Manage lag and run to parity with different slices Vincent Guittot
2025-07-08 16:56 ` [PATCH v3 1/6] sched/fair: Use protect_slice() instead of direct comparison Vincent Guittot
2025-07-10 12:46 ` [tip: sched/core] " tip-bot2 for Vincent Guittot
2025-07-08 16:56 ` [PATCH v3 2/6] sched/fair: Fix NO_RUN_TO_PARITY case Vincent Guittot
2025-07-09 9:17 ` Peter Zijlstra
2025-07-09 9:32 ` Vincent Guittot
2025-07-10 12:46 ` tip-bot2 for Vincent Guittot [this message]
2025-07-08 16:56 ` [PATCH v3 3/6] sched/fair: Remove spurious shorter slice preemption Vincent Guittot
2025-07-10 12:46 ` [tip: sched/core] " tip-bot2 for Vincent Guittot
2025-07-08 16:56 ` [PATCH v3 4/6] sched/fair: Limit run to parity to the min slice of enqueued entities Vincent Guittot
2025-07-10 6:59 ` Madadi Vineeth Reddy
2025-07-10 10:40 ` Vincent Guittot
2025-07-10 12:34 ` Peter Zijlstra
2025-07-13 18:17 ` Madadi Vineeth Reddy
2025-07-20 10:57 ` Madadi Vineeth Reddy
2025-07-21 9:11 ` Vincent Guittot
2025-07-21 15:22 ` Madadi Vineeth Reddy
2025-07-21 9:06 ` Vincent Guittot
2025-07-10 12:46 ` [tip: sched/core] " tip-bot2 for Vincent Guittot
2025-07-08 16:56 ` [PATCH v3 5/6] sched/fair: Fix entity's lag with run to parity Vincent Guittot
2025-07-10 12:46 ` [tip: sched/core] " tip-bot2 for Vincent Guittot
2025-07-08 16:56 ` [PATCH v3 6/6] sched/fair: Always trigger resched at the end of a protected period Vincent Guittot
2025-07-10 12:46 ` [tip: sched/core] " tip-bot2 for Vincent Guittot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=175215159451.406.1574940645817260327.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.