From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBFC34192F2 for ; Fri, 5 Jun 2026 09:23:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780651394; cv=none; b=mCsmjnuJrbm2t4f9nN0zn8cDcO535esrybSvRFdgJHg2iEZDPCnLD13P5NEOGSdR1W2kPE0zkK6D/AGAkY0INj+4PyoUsbRU9O1JAV6xY7wlM/gK2Kq3HakVRqnwzvNbESsbfT+bUq3le4UYjaDF91Mnhl4IHHqP0EwXKSNcNXM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780651394; c=relaxed/simple; bh=kbUVYKMVGepbAJFPpx+XTelF+yLPl+a3dADMJHMMnho=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=pKFVh0qFFuSeqJubpytNrZyvGoOcJ/9VkX9nEg9jcZAbr2cE1BIdTz9m5A8JxgRmbpldzvqe11TfVZiXCLFcFiFf0CMR0A5NjFnvI6N8lfExjAz05fK/KXwU04lweDZbPq9RAHZsQZb2GJhFxyTF2bsbj904sPSxnwFOZiDRLMg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=QCzuGBXB; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="QCzuGBXB" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 629374AB3; Fri, 5 Jun 2026 02:23:07 -0700 (PDT) Received: from [10.1.38.38] (unknown [10.1.38.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BBDC93F86F; Fri, 5 Jun 2026 02:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1780651392; bh=kbUVYKMVGepbAJFPpx+XTelF+yLPl+a3dADMJHMMnho=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=QCzuGBXBsGTSX6XVI1BZ0UNd+1uuFjggiuTwFv1VdMopKLIY68jNmXHg7MZ8CkOtl yo4GHomICTyoAnAx1RrmhsNT1G8Qz0CS3qS4r3Q5vvrTRVvdiPM3kjYmHMjTwvjJ3q dBEHsY4xKYmJx3Nk3kcxtymOF2X5aoMeW4KAMLp8= Message-ID: Date: Fri, 5 Jun 2026 10:23:07 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/fair: Fix cpu_util runnable_avg arithmetic From: Christian Loehle To: Vincent Guittot , Hongyan Xia Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Jiazi Li , "linux-kernel@vger.kernel.org" References: <20260605070103.1832-1-hongyan.xia@transsion.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/5/26 10:21, Christian Loehle wrote: > On 6/5/26 09:51, Vincent Guittot wrote: >> On Fri, 5 Jun 2026 at 09:01, Hongyan Xia wrote: >>> >>> From: Hongyan Xia >>> >>> 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 >>> --- >>> kernel/sched/fair.c | 22 ++++++++++++++-------- >>> 1 file changed, 14 insertions(+), 8 deletions(-) >>> >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>> index 69361c63353a..050bce06efea 100644 >>> --- a/kernel/sched/fair.c >>> +++ b/kernel/sched/fair.c >>> @@ -8231,25 +8231,31 @@ 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 = p && task_cpu(p) != cpu && dst_cpu == cpu; >>> + bool sub_task = p && task_cpu(p) == cpu && dst_cpu != cpu; >>> struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs; >>> unsigned long util = READ_ONCE(cfs_rq->avg.util_avg); >>> unsigned long runnable; >>> >>> - if (boost) { >>> - runnable = READ_ONCE(cfs_rq->avg.runnable_avg); >>> - util = 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) == cpu && dst_cpu != cpu) >>> - lsub_positive(&util, task_util(p)); >>> - else if (p && task_cpu(p) != cpu && dst_cpu == cpu) >>> + if (add_task) >>> util += task_util(p); >>> + else if (sub_task) >>> + lsub_positive(&util, task_util(p)); >>> + >>> + if (boost) { >>> + runnable = READ_ONCE(cfs_rq->avg.runnable_avg); >>> + if (add_task) >>> + runnable += task_runnable(p); >> >> Where did you get the task_runnable() function? I can't find it in >> tip/sched/core so either create it or call >> READ_ONCE(p->se.avg.runnable_avg) directly > > It's there for me on tip/sched/core at > 7675361ff9a1 sched: deadline: Cleanup goto label in pick_earliest_pushable_dl_task > but also 7.1-rc6? nevermind....