sched/cpuacct: fix percpu time accounting
PATCH 1/1 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+176Reported-by Xuan Lu <[email protected]>
Reported-by Minye Zhu <[email protected]>
Co-developed-by Qiang Wang <[email protected]>
Signed-off-by Qiang Wang <[email protected]>
Signed-off-by Chengming Zhou <[email protected]>
--- kernel/sched/cpuacct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/cpuacct.c +2 -1
@@ -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 (); }
Signature · 1 line
2.11.0
Ping guys. Any comments or suggestions?
Quoted 56 lines · Chengming Zhou
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_chargecalled 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+176Reported-by Xuan Lu <[email protected]>Reported-by Minye Zhu <[email protected]>Co-developed-by Qiang Wang <[email protected]>Signed-off-by Qiang Wang <[email protected]>Signed-off-by Chengming Zhou <[email protected]>--- kernel/sched/cpuacct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/sched/cpuacct.c +2
-1@@ -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 (); }