Skip to content

Commit 66f21ee

Browse files
Hongyan Xiagregkh
authored andcommitted
sched/fair: Fix cpu_util runnable_avg arithmetic
[ Upstream commit 29922fd ] 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: 7d0583c ("sched/fair, cpufreq: Introduce 'runnable boosting'") Signed-off-by: Hongyan Xia <hongyan.xia@transsion.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://patch.msgid.link/20260605094318.37931-1-hongyan.xia@transsion.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6abaa8e commit 66f21ee

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

kernel/sched/fair.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7711,25 +7711,32 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
77117711
static unsigned long
77127712
cpu_util(int cpu, struct task_struct *p, int dst_cpu, int boost)
77137713
{
7714+
bool add_task = p && task_cpu(p) != cpu && dst_cpu == cpu;
7715+
bool sub_task = p && task_cpu(p) == cpu && dst_cpu != cpu;
77147716
struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs;
77157717
unsigned long util = READ_ONCE(cfs_rq->avg.util_avg);
77167718
unsigned long runnable;
77177719

7718-
if (boost) {
7719-
runnable = READ_ONCE(cfs_rq->avg.runnable_avg);
7720-
util = max(util, runnable);
7721-
}
7722-
77237720
/*
77247721
* If @dst_cpu is -1 or @p migrates from @cpu to @dst_cpu remove its
77257722
* contribution. If @p migrates from another CPU to @cpu add its
77267723
* contribution. In all the other cases @cpu is not impacted by the
77277724
* migration so its util_avg is already correct.
77287725
*/
7729-
if (p && task_cpu(p) == cpu && dst_cpu != cpu)
7730-
lsub_positive(&util, task_util(p));
7731-
else if (p && task_cpu(p) != cpu && dst_cpu == cpu)
7726+
if (add_task)
77327727
util += task_util(p);
7728+
else if (sub_task)
7729+
lsub_positive(&util, task_util(p));
7730+
7731+
if (boost) {
7732+
runnable = READ_ONCE(cfs_rq->avg.runnable_avg);
7733+
if (add_task)
7734+
runnable += READ_ONCE(p->se.avg.runnable_avg);
7735+
else if (sub_task)
7736+
lsub_positive(&runnable,
7737+
READ_ONCE(p->se.avg.runnable_avg));
7738+
util = max(util, runnable);
7739+
}
77337740

77347741
if (sched_feat(UTIL_EST)) {
77357742
unsigned long util_est;

0 commit comments

Comments
 (0)