[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20231118043842.45047-1-CruzZhao@linux.alibaba.com>
Date: Sat, 18 Nov 2023 12:38:42 +0800
From: Cruz Zhao <CruzZhao@...ux.alibaba.com>
To: mingo@...hat.com, peterz@...radead.org, juri.lelli@...hat.com,
vincent.guittot@...aro.org, dietmar.eggemann@....com,
rostedt@...dmis.org, bsegall@...gle.com, mgorman@...e.de,
bristot@...hat.com, vschneid@...hat.com, joel@...lfernandes.org
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH v2] sched/core: fix incorrect cpustat[CPUTIME_FORCEIDLE] update
In function __account_forceidle_time(), task_group_account_field()
is called to update kernel_cpustat.cpustat[CPUTIME_FORCEIDLE].
However, p may be not running on current cpu, so update cpustat with
this_cpu_add() is incorrect.
To fix this problem, we get the cpu of p first, and then add delta
to kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE].
Fixes: 1fcf54deb767 ("sched/core: add forced idle accounting for cgroups")
Signed-off-by: Cruz Zhao <CruzZhao@...ux.alibaba.com>
---
kernel/sched/cputime.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index af7952f12e6c..843d6cabae59 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -239,9 +239,12 @@ void account_idle_time(u64 cputime)
*/
void __account_forceidle_time(struct task_struct *p, u64 delta)
{
+ unsigned int cpu = task_cpu(p);
+
__schedstat_add(p->stats.core_forceidle_sum, delta);
- task_group_account_field(p, CPUTIME_FORCEIDLE, delta);
+ kcpustat_cpu(cpu).cpustat[CPUTIME_FORCEIDLE] += delta;
+ cgroup_account_cputime_field(p, CPUTIME_FORCEIDLE, tmp);
}
#endif
--
2.39.3
Powered by blists - more mailing lists