From mboxrd@z Thu Jan 1 00:00:00 1970 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 5236F3EF0A4; Tue, 9 Jun 2026 08:32:54 +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=1780993975; cv=none; b=S1mkZf67KQ/fBd17dEH5eAjbEM2Rxh1JPP1K9S78ZGzPSS0hVO0n0EB6lspUyUlxkLRLCPDOpx2jpI0uI5MTnkz/uFBVJuWgSYo4kCYQkUimjWeNuq6Zym0Js+OB+nRt8cOhinOrq0g76pqKu8wYcBA+0JRxlatjRN84aMBghHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780993975; c=relaxed/simple; bh=Ymua/SKpKZzTq6LqChs7s6nDgZrNFiw1SOIpPRjcXfw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=UTo2mt38v6Hnt0AYxJjfLeUp+gGP2vQlNLpSJLKRifi6pql8x8dMoftZtFrdmgDq73DqXuo74NowNcUE3fl6H7pcBW4HBl6rTTXugwekU/vtbXe2PomrSU0vFoNosUvJ0sTvEQN7uesWLd/05T+Z3I2k3A6TkhPev5ZRa29bXQY= 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=yg1/GPWy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yf5FDFeP; 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="yg1/GPWy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yf5FDFeP" Date: Tue, 09 Jun 2026 08:32:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780993972; 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=U4JW4ozar3jLlhWy/aaE2TKGYb3BfptJsOhraM8fWM4=; b=yg1/GPWy/cHGfpF/x9L0Lm9UVcpf12g/jXDtJQ9O1UVGHG1ny/FVpH9DLMTJ237bDGtAuh plBFs/ESNQthyQoSEfIGP8gl2TRQL1dj7QgevaX7sAUlL0RN1NHHkq7DfV0LJ1BKXpln6Z HtNJI9JyFNmQpOhrGCwPVJi57QOyM7NLwrHBzvauyqxJaSNOyxtv71EJUu2EdxeAQX7lTY 85i4qrW593IgO1WKde4wqmngr90bFStYLw/MrwGNBJEjwM+wuHf6uZl61wF7o/HZqAQjFP Iha8aIG1cEFNI/wwqUgE3//NpEV6I3DT4oGX4vu4Z/Z+MGNjtjJxGHhqHuvWcA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780993972; 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=U4JW4ozar3jLlhWy/aaE2TKGYb3BfptJsOhraM8fWM4=; b=yf5FDFeP8XTKnWhVL61QmIrAaqkIslKLTRiPP3dQV+VY/MSeuNi7jgLTzzG0ufJRT3B2f+ hgjCVF4eFfyTBmBQ== From: "tip-bot2 for Hongyan Xia" 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: Fix cpu_util runnable_avg arithmetic Cc: Hongyan Xia , "Peter Zijlstra (Intel)" , Vincent Guittot , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260605094318.37931-1-hongyan.xia@transsion.com> References: <20260605094318.37931-1-hongyan.xia@transsion.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178099397124.529383.18382218290491037623.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: 29922fdfc2a4008d66418bedd0ebf5038fc54efa Gitweb: https://git.kernel.org/tip/29922fdfc2a4008d66418bedd0ebf5038fc= 54efa Author: Hongyan Xia AuthorDate: Fri, 05 Jun 2026 09:43:39=20 Committer: Peter Zijlstra CommitterDate: Tue, 09 Jun 2026 10:28:08 +02:00 sched/fair: Fix cpu_util runnable_avg arithmetic If we take runnable_avg in max(runnable_avg, util_avg) in cpu_util(), we should then add or subtract task runnable_avg, but the arithmetic below is still with task util_avg. This mixes runnable_avg with util_avg which is incorrect. Fix by always doing arithmetic with runnable_avg and only take max(runnable_avg, util_avg) at the last step. Fixes: 7d0583cf9ec7 ("sched/fair, cpufreq: Introduce 'runnable boosting'") Signed-off-by: Hongyan Xia Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Vincent Guittot Link: https://patch.msgid.link/20260605094318.37931-1-hongyan.xia@transsion.c= om --- kernel/sched/fair.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index f4ed841..1b23e73 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8968,25 +8968,32 @@ static int select_idle_sibling(struct task_struct *p,= int prev, int target) static unsigned long cpu_util(int cpu, struct task_struct *p, int dst_cpu, int boost) { + bool add_task =3D p && task_cpu(p) !=3D cpu && dst_cpu =3D=3D cpu; + bool sub_task =3D p && task_cpu(p) =3D=3D cpu && dst_cpu !=3D cpu; struct cfs_rq *cfs_rq =3D &cpu_rq(cpu)->cfs; unsigned long util =3D READ_ONCE(cfs_rq->avg.util_avg); unsigned long runnable; =20 - if (boost) { - runnable =3D READ_ONCE(cfs_rq->avg.runnable_avg); - util =3D max(util, runnable); - } - /* * If @dst_cpu is -1 or @p migrates from @cpu to @dst_cpu remove its * contribution. If @p migrates from another CPU to @cpu add its * contribution. In all the other cases @cpu is not impacted by the * migration so its util_avg is already correct. */ - if (p && task_cpu(p) =3D=3D cpu && dst_cpu !=3D cpu) - lsub_positive(&util, task_util(p)); - else if (p && task_cpu(p) !=3D cpu && dst_cpu =3D=3D cpu) + if (add_task) util +=3D task_util(p); + else if (sub_task) + lsub_positive(&util, task_util(p)); + + if (boost) { + runnable =3D READ_ONCE(cfs_rq->avg.runnable_avg); + if (add_task) + runnable +=3D READ_ONCE(p->se.avg.runnable_avg); + else if (sub_task) + lsub_positive(&runnable, + READ_ONCE(p->se.avg.runnable_avg)); + util =3D max(util, runnable); + } =20 if (sched_feat(UTIL_EST)) { unsigned long util_est;