mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: tglx@linutronix.de
Cc: arnd@arndb.de, anna-maria@linutronix.de, frederic@kernel.org,
	peterz@infradead.org, luto@kernel.org, mingo@redhat.com,
	juri.lelli@redhat.com, vincent.guittot@linaro.org,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	linux-kernel@vger.kernel.org, oliver.sang@intel.com
Subject: [PATCH v2 1/6] sched/eevdf: Fix HRTICK duration
Date: Wed, 21 Jan 2026 17:20:11 +0100	[thread overview]
Message-ID: <20260121162507.525037175@infradead.org> (raw)
In-Reply-To: <20260121162010.647043073@infradead.org>

The nominal duration for an EEVDF task to run is until its deadline.
At which point the deadline is moved ahead and a new task selection is
done.

Try and predict the time 'lost' to higher scheduling classes. Since
this is an estimate, the timer can be both early or late. In case it
is early task_tick_fair() will take the !need_resched() path and
restarts the timer.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/sched/fair.c |   55 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5511,7 +5511,7 @@ static void put_prev_entity(struct cfs_r
 }
 
 static void
-entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
+entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 {
 	/*
 	 * Update run-time statistics of the 'current'.
@@ -5523,17 +5523,6 @@ entity_tick(struct cfs_rq *cfs_rq, struc
 	 */
 	update_load_avg(cfs_rq, curr, UPDATE_TG);
 	update_cfs_group(curr);
-
-#ifdef CONFIG_SCHED_HRTICK
-	/*
-	 * queued ticks are scheduled to match the slice, so don't bother
-	 * validating it and just reschedule.
-	 */
-	if (queued) {
-		resched_curr_lazy(rq_of(cfs_rq));
-		return;
-	}
-#endif
 }
 
 
@@ -6735,21 +6724,39 @@ static inline void sched_fair_update_sto
 static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
 {
 	struct sched_entity *se = &p->se;
+	unsigned long scale = 1024;
+	unsigned long util = 0;
+	u64 vdelta;
+	u64 delta;
 
 	WARN_ON_ONCE(task_rq(p) != rq);
 
-	if (rq->cfs.h_nr_queued > 1) {
-		u64 ran = se->sum_exec_runtime - se->prev_sum_exec_runtime;
-		u64 slice = se->slice;
-		s64 delta = slice - ran;
-
-		if (delta < 0) {
-			if (task_current_donor(rq, p))
-				resched_curr(rq);
-			return;
-		}
-		hrtick_start(rq, delta);
+	if (rq->cfs.h_nr_queued <= 1)
+		return;
+
+	/*
+	 * Compute time until virtual deadline
+	 */
+	vdelta = se->deadline - se->vruntime;
+	if ((s64)vdelta < 0) {
+		if (task_current_donor(rq, p))
+			resched_curr(rq);
+		return;
+	}
+	delta = (se->load.weight * vdelta) / NICE_0_LOAD;
+
+	/*
+	 * Correct for instantaneous load of other classes.
+	 */
+	util += cpu_util_dl(rq);
+	util += cpu_util_rt(rq);
+	util += cpu_util_irq(rq);
+	if (util && util < 1024) {
+		scale *= 1024;
+		scale /= (1024 - util);
 	}
+
+	hrtick_start(rq, (scale * delta) / 1024);
 }
 
 /*
@@ -13373,7 +13380,7 @@ static void task_tick_fair(struct rq *rq
 
 	for_each_sched_entity(se) {
 		cfs_rq = cfs_rq_of(se);
-		entity_tick(cfs_rq, se, queued);
+		entity_tick(cfs_rq, se);
 	}
 
 	if (queued) {



  reply	other threads:[~2026-01-21 16:28 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-21 16:20 [PATCH v2 0/6] hrtimer/sched: Improve hrtick Peter Zijlstra
2026-01-21 16:20 ` Peter Zijlstra [this message]
2026-01-22 10:53   ` [PATCH v2 1/6] sched/eevdf: Fix HRTICK duration Juri Lelli
2026-02-05  8:38   ` Peter Zijlstra
2026-01-21 16:20 ` [PATCH v2 2/6] hrtimer: Optimize __hrtimer_start_range_ns() Peter Zijlstra
2026-01-22 11:00   ` Juri Lelli
2026-02-02 12:28   ` Thomas Gleixner
2026-01-21 16:20 ` [PATCH v2 3/6] hrtimer,sched: Add fuzzy hrtimer mode for HRTICK Peter Zijlstra
2026-01-22 13:12   ` Juri Lelli
2026-01-23 20:04     ` Steven Rostedt
2026-02-02 14:02   ` Thomas Gleixner
2026-01-21 16:20 ` [PATCH v2 4/6] hrtimer: Re-arrange hrtimer_interrupt() Peter Zijlstra
2026-02-02 14:05   ` Thomas Gleixner
2026-01-21 16:20 ` [PATCH v2 5/6] entry,hrtimer: Push reprogramming timers into the interrupt return path Peter Zijlstra
2026-01-23 20:08   ` Steven Rostedt
2026-01-23 21:04     ` Peter Zijlstra
2026-02-02 14:37   ` Thomas Gleixner
2026-02-02 16:33     ` Peter Zijlstra
2026-02-02 23:28       ` Thomas Gleixner
2026-02-03  8:14         ` Thomas Gleixner
2026-02-04 13:58         ` Peter Zijlstra
2026-01-21 16:20 ` [PATCH v2 6/6] sched: Default enable HRTICK Peter Zijlstra
2026-01-21 22:24   ` Phil Auld
2026-01-22 11:40     ` Peter Zijlstra
2026-01-22 12:31       ` Phil Auld

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=20260121162507.525037175@infradead.org \
    --to=peterz@infradead.org \
    --cc=anna-maria@linutronix.de \
    --cc=arnd@arndb.de \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=oliver.sang@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®