[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211208073836.70619-1-zhouchengming@bytedance.com>
Date: Wed, 8 Dec 2021 15:38:36 +0800
From: Chengming Zhou <zhouchengming@...edance.com>
To: mingo@...hat.com, peterz@...radead.org
Cc: juri.lelli@...hat.com, vincent.guittot@...aro.org,
dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
mgorman@...e.de, bristot@...hat.com, linux-kernel@...r.kernel.org,
Chengming Zhou <zhouchengming@...edance.com>,
Xuan Lu <luxuan.windniw@...edance.com>,
Minye Zhu <zhuminye@...edance.com>,
Qiang Wang <wangqiang.wq.frank@...edance.com>
Subject: [PATCH] sched/cpuacct: fix percpu time accounting
The usage percpu data is the CPU time consumed on each CPU by all tasks
in this cgroup (including tasks lower in the hierarchy). When cpuacct_charge
called from other CPUs, we should use the CPU of task, not this CPU.
e.g.
cpuacct_charge+1
update_curr+332
enqueue_entity+70
enqueue_task_fair+169
activate_task+57
attach_task+46
load_balance+1512
run_rebalance_domains+451
__do_softirq+282
sysvec_apic_timer_interrupt+159
asm_sysvec_apic_timer_interrupt+18
native_safe_halt+11
default_idle+10
default_enter_idle+45
cpuidle_enter_state+130
cpuidle_enter+47
do_idle+489
cpu_startup_entry+25
start_secondary+261
secondary_startup_64_no_verify+176
Reported-by: Xuan Lu <luxuan.windniw@...edance.com>
Reported-by: Minye Zhu <zhuminye@...edance.com>
Co-developed-by: Qiang Wang <wangqiang.wq.frank@...edance.com>
Signed-off-by: Qiang Wang <wangqiang.wq.frank@...edance.com>
Signed-off-by: Chengming Zhou <zhouchengming@...edance.com>
---
kernel/sched/cpuacct.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 893eece65bfd..aab51c88bd34 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -341,6 +341,7 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
struct cpuacct *ca;
int index = CPUACCT_STAT_SYSTEM;
struct pt_regs *regs = get_irq_regs() ? : task_pt_regs(tsk);
+ unsigned int cpu = task_cpu(tsk);
if (regs && user_mode(regs))
index = CPUACCT_STAT_USER;
@@ -348,7 +349,7 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
rcu_read_lock();
for (ca = task_ca(tsk); ca; ca = parent_ca(ca))
- __this_cpu_add(ca->cpuusage->usages[index], cputime);
+ per_cpu_ptr(ca->cpuusage, cpu)->usages[index] += cputime;
rcu_read_unlock();
}
--
2.11.0
Powered by blists - more mailing lists