linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/cpuacct: fix percpu time accounting
@ 2021-12-08  7:38 Chengming Zhou
  2021-12-20  7:38 ` Chengming Zhou
  0 siblings, 1 reply; 2+ messages in thread
From: Chengming Zhou @ 2021-12-08  7:38 UTC (permalink / raw)
  To: mingo, peterz
  Cc: juri.lelli, vincent.guittot, dietmar.eggemann, rostedt, bsegall,
	mgorman, bristot, linux-kernel, Chengming Zhou, Xuan Lu,
	Minye Zhu, Qiang Wang

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@bytedance.com>
Reported-by: Minye Zhu <zhuminye@bytedance.com>
Co-developed-by: Qiang Wang <wangqiang.wq.frank@bytedance.com>
Signed-off-by: Qiang Wang <wangqiang.wq.frank@bytedance.com>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sched/cpuacct: fix percpu time accounting
  2021-12-08  7:38 [PATCH] sched/cpuacct: fix percpu time accounting Chengming Zhou
@ 2021-12-20  7:38 ` Chengming Zhou
  0 siblings, 0 replies; 2+ messages in thread
From: Chengming Zhou @ 2021-12-20  7:38 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann
  Cc: rostedt, bsegall, mgorman, bristot, linux-kernel, Xuan Lu,
	Minye Zhu, Qiang Wang

Ping guys. Any comments or suggestions?

On 2021/12/8 3:38 下午, Chengming Zhou wrote:
> 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@bytedance.com>
> Reported-by: Minye Zhu <zhuminye@bytedance.com>
> Co-developed-by: Qiang Wang <wangqiang.wq.frank@bytedance.com>
> Signed-off-by: Qiang Wang <wangqiang.wq.frank@bytedance.com>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.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();
>  }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-20  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08  7:38 [PATCH] sched/cpuacct: fix percpu time accounting Chengming Zhou
2021-12-20  7:38 ` Chengming Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).