Skip to content

Commit dbe9337

Browse files
Muchun SongPeter Zijlstra
authored andcommitted
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: Muchun Song <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 04f5c36 commit dbe9337

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/sched/cpuacct.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Based on the work by Paul Menage ([email protected]) and Balbir Singh
66
77
*/
8+
#include <asm/irq_regs.h>
89
#include "sched.h"
910

1011
/* 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)
339340
{
340341
struct cpuacct *ca;
341342
int index = CPUACCT_STAT_SYSTEM;
342-
struct pt_regs *regs = task_pt_regs(tsk);
343+
struct pt_regs *regs = get_irq_regs() ? : task_pt_regs(tsk);
343344

344345
if (regs && user_mode(regs))
345346
index = CPUACCT_STAT_USER;

0 commit comments

Comments
 (0)