All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/cpuacct: Fix charge cpuacct.usage_sys incorrently.
@ 2020-04-16 14:18 Muchun Song
  2020-04-16 15:35 ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Muchun Song @ 2020-04-16 14:18 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, mingo
  Cc: linux-kernel, Muchun Song

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
use get_irq_regs() instead of task_pt_regs() to fix it.

Signed-off-by: Muchun Song <songmuchun@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 6448b0438ffb2..edfc62554648e 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -5,6 +5,7 @@
  * Based on the work by Paul Menage (menage@google.com) and Balbir Singh
  * (balbir@in.ibm.com).
  */
+#include <asm/irq_regs.h>
 #include "sched.h"
 
 /* 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)
 {
 	struct cpuacct *ca;
 	int index = CPUACCT_STAT_SYSTEM;
-	struct pt_regs *regs = task_pt_regs(tsk);
+	struct pt_regs *regs = get_irq_regs();
 
 	if (regs && user_mode(regs))
 		index = CPUACCT_STAT_USER;
-- 
2.11.0


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

end of thread, other threads:[~2020-04-17  3:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16 14:18 [PATCH] sched/cpuacct: Fix charge cpuacct.usage_sys incorrently Muchun Song
2020-04-16 15:35 ` Steven Rostedt
2020-04-16 16:01   ` Steven Rostedt
2020-04-17  3:11     ` [External] " Muchun Song
2020-04-17  3:07   ` Muchun Song

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.