Commit dbe93371 authored by Muchun Song's avatar Muchun Song Committed by Peter Zijlstra

sched/cpuacct: Fix charge cpuacct.usage_sys

The user_mode(task_pt_regs(tsk)) always return true for
user thread, and false for kernel thread. So it means that
the cpuacct.usage_sys is the time that kernel thread uses
not the time that thread uses in the kernel mode. We can
try get_irq_regs() first, if it is NULL, then we can fall
back to task_pt_regs().
Signed-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200420070453.76815-1-songmuchun@bytedance.com
parent 04f5c362
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Based on the work by Paul Menage (menage@google.com) and Balbir Singh * Based on the work by Paul Menage (menage@google.com) and Balbir Singh
* (balbir@in.ibm.com). * (balbir@in.ibm.com).
*/ */
#include <asm/irq_regs.h>
#include "sched.h" #include "sched.h"
/* Time spent by the tasks of the CPU accounting group executing in ... */ /* Time spent by the tasks of the CPU accounting group executing in ... */
...@@ -339,7 +340,7 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime) ...@@ -339,7 +340,7 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
{ {
struct cpuacct *ca; struct cpuacct *ca;
int index = CPUACCT_STAT_SYSTEM; int index = CPUACCT_STAT_SYSTEM;
struct pt_regs *regs = task_pt_regs(tsk); struct pt_regs *regs = get_irq_regs() ? : task_pt_regs(tsk);
if (regs && user_mode(regs)) if (regs && user_mode(regs))
index = CPUACCT_STAT_USER; index = CPUACCT_STAT_USER;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment