From nobody Mon Feb 9 13:01:38 2026 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AF04396B97 for ; Wed, 21 Jan 2026 16:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769012889; cv=none; b=BWv3By9ePGukNkRGPhtREzO2yACBKRs3mtHMm8ZC1+MQPBvcHsUjbjd2FWAKtGfojiqoDTpFncqNO1QNs6XkPSzZf+Sz3+ywnCAQVyTJt6TjtHmllqyAtYSZYEV3dJlzts2qpPGuIERnw5NcbTuEQp8F9siTLd2TlN3oRlbrn1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769012889; c=relaxed/simple; bh=QtrqkoYJsnIkuOBMGJHP+36/t+zPVCwOWnlALYPggR0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UgyVQMxU25dFO8F9S79n4uOOPNW+gjlA7Ij8oFPNgP1V6WimtuNgR756a5/E+XrTwXnxhFdQ8GWFnoOBkBIBJt4rHtee/FGEODddK2P/S8b91q/TqNafrq7mRCKNk2ioj65grgAnoENPuW5elCxiv/5eHbmN1uk//4XJ/uGuNdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lcgpKNd5; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lcgpKNd5" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=gqLEudNvaPfbSGEvzjBZ0OxAdYIj1wUbWbu4Ls3as1s=; b=lcgpKNd5yn0oyXe8tnvWUaow8P p2vALDJ6mfHtNTrA3WkUgZ8dRjFCiFzAMwU/x6izoLH76xEcx4DgT0SoHYTHd07wCPZXySBodRYYM hhiOsDtU0hE8NepTGUFMA1meyanGs3Mcf9KRmLptQbNlZjnsga63sDLe64Ww49qoJ3y/W8XDfCTTG w/LwhwaqkEZz2dZtZUpCMOoWKm8K1PCr9g3paBXii6t38vzA/vIP/u9CBtA4ceMQJK+OxCU9AqSrI 81MZGfHwTzWYP14G7XvgPc6b+Lh4fcwLLgMKsjllFbmDyxiYBYBUKz91mXGYgNNLd4IUnZQpeYR8B cAXcyhpA==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vib3k-0000000GawQ-40kG; Wed, 21 Jan 2026 16:27:57 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id D2424300328; Wed, 21 Jan 2026 17:27:55 +0100 (CET) Message-ID: <20260121162507.525037175@infradead.org> User-Agent: quilt/0.68 Date: Wed, 21 Jan 2026 17:20:11 +0100 From: Peter Zijlstra 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 References: <20260121162010.647043073@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) Reviewed-by: Juri Lelli --- 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 } =20 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 } =20 =20 @@ -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 =3D &p->se; + unsigned long scale =3D 1024; + unsigned long util =3D 0; + u64 vdelta; + u64 delta; =20 WARN_ON_ONCE(task_rq(p) !=3D rq); =20 - if (rq->cfs.h_nr_queued > 1) { - u64 ran =3D se->sum_exec_runtime - se->prev_sum_exec_runtime; - u64 slice =3D se->slice; - s64 delta =3D 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 <=3D 1) + return; + + /* + * Compute time until virtual deadline + */ + vdelta =3D se->deadline - se->vruntime; + if ((s64)vdelta < 0) { + if (task_current_donor(rq, p)) + resched_curr(rq); + return; + } + delta =3D (se->load.weight * vdelta) / NICE_0_LOAD; + + /* + * Correct for instantaneous load of other classes. + */ + util +=3D cpu_util_dl(rq); + util +=3D cpu_util_rt(rq); + util +=3D cpu_util_irq(rq); + if (util && util < 1024) { + scale *=3D 1024; + scale /=3D (1024 - util); } + + hrtick_start(rq, (scale * delta) / 1024); } =20 /* @@ -13373,7 +13380,7 @@ static void task_tick_fair(struct rq *rq =20 for_each_sched_entity(se) { cfs_rq =3D cfs_rq_of(se); - entity_tick(cfs_rq, se, queued); + entity_tick(cfs_rq, se); } =20 if (queued) {