All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Li RongQing <lirongqing@baidu.com>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.co, linux-kernel@vger.kernel.org,
	songmuchun@bytedance.com
Subject: Re: [PATCH][RFC] sched/cpuacct: Fix cpuacct charge
Date: Thu, 29 Jul 2021 12:19:57 +0200	[thread overview]
Message-ID: <YQKAzWT/bdwgepbU@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210720060441.22550-1-lirongqing@baidu.com>

On Tue, Jul 20, 2021 at 02:04:41PM +0800, Li RongQing wrote:
> get_irq_regs only work for current running cpu, but the task, whose
> cpuacct will be charged, maybe run different cpu, like Cpu 2 wake
> up a kernel thread to CPU 3, cause CPU 3 task are charged with the
> following stack
> 
>   cpuacct_charge+0xd8/0x100
>   update_curr+0xe1/0x1e0
>   enqueue_entity+0x144/0x6e0
>   enqueue_task_fair+0x93/0x900
>   ttwu_do_activate+0x4b/0x90
>   try_to_wake_up+0x20b/0x530
>   ? update_dl_rq_load_avg+0x10f/0x210
>   swake_up_locked.part.1+0x13/0x40
>   swake_up_one+0x27/0x40
>   rcu_process_callbacks+0x484/0x4f0
>   ? run_rebalance_domains_bt+0x5a/0x180
>   __do_softirq+0xe3/0x308
>   irq_exit+0xf0/0x100
>   smp_apic_timer_interrupt+0x74/0x160
>   apic_timer_interrupt+0xf/0x20
>   </IRQ>
>  RIP: 0033:0x456947
> 
> so define a get_irq_regs_cpu which returns the required cpu irq registers
> 
> BUT it should be not safe, and do not know what it should be like in MIPS?
> 
> Fixes: dbe9337109c2 "(sched/cpuacct: Fix charge cpuacct.usage_sys)"
> Co-developed-by: Zhao Jie <zhaojie17@baidu.com>
> Signed-off-by: Zhao Jie <zhaojie17@baidu.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  include/asm-generic/irq_regs.h | 5 +++++
>  kernel/sched/cpuacct.c         | 3 ++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/asm-generic/irq_regs.h b/include/asm-generic/irq_regs.h
> index 2e7c6e8..93e2579 100644
> --- a/include/asm-generic/irq_regs.h
> +++ b/include/asm-generic/irq_regs.h
> @@ -21,6 +21,11 @@ static inline struct pt_regs *get_irq_regs(void)
>  	return __this_cpu_read(__irq_regs);
>  }
>  
> +static inline struct pt_regs *get_irq_regs_cpu(int cpu)
> +{
> +	return per_cpu(__irq_regs, cpu);
> +}

This primitive just cannot be right... it'll get you some random data.

  parent reply	other threads:[~2021-07-29 10:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20  6:04 [PATCH][RFC] sched/cpuacct: Fix cpuacct charge Li RongQing
2021-07-20 18:11 ` kernel test robot
2021-07-21  4:23 ` kernel test robot
2021-07-29 10:19 ` Peter Zijlstra [this message]
2021-07-30  8:16   ` 答复: " Li,Rongqing
2021-08-16 16:21     ` Daniel Jordan
2021-08-17  3:55       ` 答复: " Li,Rongqing
2021-08-18 15:33         ` Daniel Jordan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YQKAzWT/bdwgepbU@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bristot@redhat.co \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=songmuchun@bytedance.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.