From nobody Mon May 25 00:09:51 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 805883C3BFF; Wed, 20 May 2026 08:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266057; cv=none; b=G+6nYWQQks4kzvqjY0kcar6mdbYzYguZ/fPJH0VMgMYppaV7ZDaLmaG1nVzgmKyTUkA/1PFLb6939xgeIhPg2nvgpBdkT9p/JAaLDwy/5AjsygJmFf/yYXXuQ8Va4GJm+1ceaM8iWtZtFFDXUD8EDoNDtwPm7bLAph9Im8vhlpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266057; c=relaxed/simple; bh=MPL4XoF+CHHy/RJGAhJXO+OFI8RTUUP8/yDAXLYlXiM=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=oJoB5O4KLHkHpx3gqJ/3JuqRyMa0OdDaknf4aFDGmb1eJHDuox06GKwYG8vceo5bxp/O2n8fLNmKy5sE68tFenKDuw9FQ3LbSBaBtd8+tLqpoDslMeVZPG6AYVUqEUfXw+HzHd+RN8ObSf+pI5dYAZdlgB0efxqHuD7QKDCW0i4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KafOR6Yp; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OVI6J+z8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KafOR6Yp"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OVI6J+z8" Date: Wed, 20 May 2026 08:34:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779266054; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q+qD2+FHg2d2zOTOGOXuw08YNZLy21ud8oKIrZGy/dQ=; b=KafOR6YpZMIypNhhuKLv9c2LAkt1DqRapWx5pu/nLNCge7l83oaT3TZH5POtBkWrffp8YY LF6ewfT0kSFOKNAIDWelIlQaREloXK5PFodv8v/OoTZFxQwUHYCfRrnIEg/2PAxd8vu06V GV16wVxqlcevt4ugVzXU5xGjF7wIdfpEVAV8y76i6YnSTcRvVp3nxHcbO40TT7J1qP6GzY 48mHQpOf2gTKJ0cHA+dWtf4uLA4HKAEScuZX3qm2g061hErmBrh0LZiyV+/8zIq5lmKc1k FN4ns5x3b0putvR0BFM4HiSDFxD8wwMj+Awxurg2r4F5rGjKrlvreky65RUEVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779266054; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q+qD2+FHg2d2zOTOGOXuw08YNZLy21ud8oKIrZGy/dQ=; b=OVI6J+z8zcSxIuCjIvvGmEaL5DDXL//q5ZxidSRWLwgqaTIkjsELcivmCw0aYSBaibI739 pmB90vlkly0ex4AQ== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/fair: Update util_est after updating util_avg during dequeue Cc: Qais Yousef , Vincent Guittot , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260518102345.268452-1-vincent.guittot@linaro.org> References: <20260518102345.268452-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177926605249.711.15167193683244287853.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: 6d2051403d6c93832d3058a1b275c6aef2c97f44 Gitweb: https://git.kernel.org/tip/6d2051403d6c93832d3058a1b275c6aef= 2c97f44 Author: Vincent Guittot AuthorDate: Mon, 18 May 2026 12:23:45 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 19 May 2026 12:17:36 +02:00 sched/fair: Update util_est after updating util_avg during dequeue util_est_update() must be called after updating util_avg during the dequeue of a task and only when the task is not delayed dequeue. Move util_est_update() in update_load_avg(). Fixes: b55945c500c5 ("sched: Fix pick_next_task_fair() vs try_to_wake_up() = race") Closes: https://lore.kernel.org/all/20260512124653.305275-1-qyousef@layalin= a.io/ Reported-by: Qais Yousef Reviewed-and-tested-by: Qais Yousef Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20260518102345.268452-1-vincent.guittot@lina= ro.org --- kernel/sched/fair.c | 188 +++++++++++++++++++++---------------------- 1 file changed, 92 insertions(+), 96 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7289658..09d3acd 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4930,13 +4930,86 @@ static void detach_entity_load_avg(struct cfs_rq *c= fs_rq, struct sched_entity *s trace_pelt_cfs_tp(cfs_rq); } =20 +#define UTIL_EST_MARGIN (SCHED_CAPACITY_SCALE / 100) + +static inline void util_est_update(struct sched_entity *se) +{ + unsigned int ewma, dequeued, last_ewma_diff; + + if (!sched_feat(UTIL_EST)) + return; + + /* Get current estimate of utilization */ + ewma =3D READ_ONCE(se->avg.util_est); + + /* + * If the PELT values haven't changed since enqueue time, + * skip the util_est update. + */ + if (ewma & UTIL_AVG_UNCHANGED) + return; + + /* Get utilization at dequeue */ + dequeued =3D READ_ONCE(se->avg.util_avg); + + /* + * Reset EWMA on utilization increases, the moving average is used only + * to smooth utilization decreases. + */ + if (ewma <=3D dequeued) { + ewma =3D dequeued; + goto done; + } + + /* + * Skip update of task's estimated utilization when its members are + * already ~1% close to its last activation value. + */ + last_ewma_diff =3D ewma - dequeued; + if (last_ewma_diff < UTIL_EST_MARGIN) + goto done; + + /* + * To avoid underestimate of task utilization, skip updates of EWMA if + * we cannot grant that thread got all CPU time it wanted. + */ + if ((dequeued + UTIL_EST_MARGIN) < READ_ONCE(se->avg.runnable_avg)) + goto done; + + /* + * Update Task's estimated utilization + * + * When *p completes an activation we can consolidate another sample + * of the task size. This is done by using this value to update the + * Exponential Weighted Moving Average (EWMA): + * + * ewma(t) =3D w * task_util(p) + (1-w) * ewma(t-1) + * =3D w * task_util(p) + ewma(t-1) - w * ewma(t-1) + * =3D w * (task_util(p) - ewma(t-1)) + ewma(t-1) + * =3D w * ( -last_ewma_diff ) + ewma(t-1) + * =3D w * (-last_ewma_diff + ewma(t-1) / w) + * + * Where 'w' is the weight of new samples, which is configured to be + * 0.25, thus making w=3D1/4 ( >>=3D UTIL_EST_WEIGHT_SHIFT) + */ + ewma <<=3D UTIL_EST_WEIGHT_SHIFT; + ewma -=3D last_ewma_diff; + ewma >>=3D UTIL_EST_WEIGHT_SHIFT; +done: + ewma |=3D UTIL_AVG_UNCHANGED; + WRITE_ONCE(se->avg.util_est, ewma); + + trace_sched_util_est_se_tp(se); +} + /* * Optional action to be done while updating the load average */ -#define UPDATE_TG 0x1 -#define SKIP_AGE_LOAD 0x2 -#define DO_ATTACH 0x4 -#define DO_DETACH 0x8 +#define UPDATE_TG 0x01 +#define SKIP_AGE_LOAD 0x02 +#define DO_ATTACH 0x04 +#define DO_DETACH 0x08 +#define UPDATE_UTIL_EST 0x10 =20 /* Update task and its cfs_rq load average */ static inline void update_load_avg(struct cfs_rq *cfs_rq, struct sched_ent= ity *se, int flags) @@ -4979,6 +5052,9 @@ static inline void update_load_avg(struct cfs_rq *cfs= _rq, struct sched_entity *s if (flags & UPDATE_TG) update_tg_load_avg(cfs_rq); } + + if (flags & UPDATE_UTIL_EST) + util_est_update(se); } =20 /* @@ -5037,11 +5113,6 @@ static inline unsigned long task_util(struct task_st= ruct *p) return READ_ONCE(p->se.avg.util_avg); } =20 -static inline unsigned long task_runnable(struct task_struct *p) -{ - return READ_ONCE(p->se.avg.runnable_avg); -} - static inline unsigned long _task_util_est(struct task_struct *p) { return READ_ONCE(p->se.avg.util_est) & ~UTIL_AVG_UNCHANGED; @@ -5084,88 +5155,6 @@ static inline void util_est_dequeue(struct cfs_rq *c= fs_rq, trace_sched_util_est_cfs_tp(cfs_rq); } =20 -#define UTIL_EST_MARGIN (SCHED_CAPACITY_SCALE / 100) - -static inline void util_est_update(struct cfs_rq *cfs_rq, - struct task_struct *p, - bool task_sleep) -{ - unsigned int ewma, dequeued, last_ewma_diff; - - if (!sched_feat(UTIL_EST)) - return; - - /* - * Skip update of task's estimated utilization when the task has not - * yet completed an activation, e.g. being migrated. - */ - if (!task_sleep) - return; - - /* Get current estimate of utilization */ - ewma =3D READ_ONCE(p->se.avg.util_est); - - /* - * If the PELT values haven't changed since enqueue time, - * skip the util_est update. - */ - if (ewma & UTIL_AVG_UNCHANGED) - return; - - /* Get utilization at dequeue */ - dequeued =3D task_util(p); - - /* - * Reset EWMA on utilization increases, the moving average is used only - * to smooth utilization decreases. - */ - if (ewma <=3D dequeued) { - ewma =3D dequeued; - goto done; - } - - /* - * Skip update of task's estimated utilization when its members are - * already ~1% close to its last activation value. - */ - last_ewma_diff =3D ewma - dequeued; - if (last_ewma_diff < UTIL_EST_MARGIN) - goto done; - - /* - * To avoid underestimate of task utilization, skip updates of EWMA if - * we cannot grant that thread got all CPU time it wanted. - */ - if ((dequeued + UTIL_EST_MARGIN) < task_runnable(p)) - goto done; - - - /* - * Update Task's estimated utilization - * - * When *p completes an activation we can consolidate another sample - * of the task size. This is done by using this value to update the - * Exponential Weighted Moving Average (EWMA): - * - * ewma(t) =3D w * task_util(p) + (1-w) * ewma(t-1) - * =3D w * task_util(p) + ewma(t-1) - w * ewma(t-1) - * =3D w * (task_util(p) - ewma(t-1)) + ewma(t-1) - * =3D w * ( -last_ewma_diff ) + ewma(t-1) - * =3D w * (-last_ewma_diff + ewma(t-1) / w) - * - * Where 'w' is the weight of new samples, which is configured to be - * 0.25, thus making w=3D1/4 ( >>=3D UTIL_EST_WEIGHT_SHIFT) - */ - ewma <<=3D UTIL_EST_WEIGHT_SHIFT; - ewma -=3D last_ewma_diff; - ewma >>=3D UTIL_EST_WEIGHT_SHIFT; -done: - ewma |=3D UTIL_AVG_UNCHANGED; - WRITE_ONCE(p->se.avg.util_est, ewma); - - trace_sched_util_est_se_tp(&p->se); -} - static inline unsigned long get_actual_cpu_capacity(int cpu) { unsigned long capacity =3D arch_scale_cpu_capacity(cpu); @@ -5618,7 +5607,7 @@ static bool dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { bool sleep =3D flags & DEQUEUE_SLEEP; - int action =3D UPDATE_TG; + int action =3D 0; =20 update_curr(cfs_rq); clear_buddies(cfs_rq, se); @@ -5638,15 +5627,23 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_= entity *se, int flags) =20 if (sched_feat(DELAY_DEQUEUE) && delay && !entity_eligible(cfs_rq, se)) { - update_load_avg(cfs_rq, se, 0); + if (entity_is_task(se)) + action |=3D UPDATE_UTIL_EST; + update_load_avg(cfs_rq, se, action); update_entity_lag(cfs_rq, se); set_delayed(se); return false; } } =20 - if (entity_is_task(se) && task_on_rq_migrating(task_of(se))) - action |=3D DO_DETACH; + action =3D UPDATE_TG; + if (entity_is_task(se)) { + if (task_on_rq_migrating(task_of(se))) + action |=3D DO_DETACH; + + if (sleep && !(flags & DEQUEUE_DELAYED)) + action |=3D UPDATE_UTIL_EST; + } =20 /* * When dequeuing a sched_entity, we must: @@ -7409,7 +7406,6 @@ static bool dequeue_task_fair(struct rq *rq, struct t= ask_struct *p, int flags) if (!p->se.sched_delayed) util_est_dequeue(&rq->cfs, p); =20 - util_est_update(&rq->cfs, p, flags & DEQUEUE_SLEEP); if (dequeue_entities(rq, &p->se, flags) < 0) return false; =20