提交 004b3ba9 编写于 作者: S Shanpei Chen 提交者: Yihao Wu

alinux: sched/cputime: Fix guest cputime of cpuacct.proc_stat

to #26424323

For container only cases, since guest cputime is always 0, we don't
calculate it and return 0 directly before.

Howerver, when running vm inside a cgroup, we expect the cgroup to
maintain guest cputime correctly.
Tested-by: NYihao Wu <wuyihao@linux.alibaba.com>
Signed-off-by: NShanpei Chen <shanpeic@linux.alibaba.com>
Reviewed-by: NShanpei Chen <shanpeic@linux.alibaba.com>
Signed-off-by: NYihao Wu <wuyihao@linux.alibaba.com>
上级 8ab45c97
...@@ -360,7 +360,8 @@ static void __cpuacct_get_usage_result(struct cpuacct *ca, int cpu, ...@@ -360,7 +360,8 @@ static void __cpuacct_get_usage_result(struct cpuacct *ca, int cpu,
res->steal = se->statistics.wait_sum; res->steal = se->statistics.wait_sum;
else else
res->steal = 0; res->steal = 0;
res->guest = res->guest_nice = 0; /* currently always 0 */ res->guest = kcpustat->cpustat[CPUTIME_GUEST];
res->guest_nice = kcpustat->cpustat[CPUTIME_GUEST_NICE];
} }
static int cpuacct_proc_stats_show(struct seq_file *sf, void *v) static int cpuacct_proc_stats_show(struct seq_file *sf, void *v)
...@@ -392,6 +393,7 @@ static int cpuacct_proc_stats_show(struct seq_file *sf, void *v) ...@@ -392,6 +393,7 @@ static int cpuacct_proc_stats_show(struct seq_file *sf, void *v)
softirq += res.softirq; softirq += res.softirq;
steal += res.steal; steal += res.steal;
guest += res.guest; guest += res.guest;
guest += res.guest_nice;
iowait += res.iowait; iowait += res.iowait;
idle += res.idle; idle += res.idle;
} }
...@@ -406,6 +408,7 @@ static int cpuacct_proc_stats_show(struct seq_file *sf, void *v) ...@@ -406,6 +408,7 @@ static int cpuacct_proc_stats_show(struct seq_file *sf, void *v)
irq += kcpustat->cpustat[CPUTIME_IRQ]; irq += kcpustat->cpustat[CPUTIME_IRQ];
softirq += kcpustat->cpustat[CPUTIME_SOFTIRQ]; softirq += kcpustat->cpustat[CPUTIME_SOFTIRQ];
guest += kcpustat->cpustat[CPUTIME_GUEST]; guest += kcpustat->cpustat[CPUTIME_GUEST];
guest += kcpustat->cpustat[CPUTIME_GUEST_NICE];
idle += get_idle_time(cpu); idle += get_idle_time(cpu);
iowait += get_iowait_time(cpu); iowait += get_iowait_time(cpu);
steal += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; steal += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
......
...@@ -137,8 +137,6 @@ void account_user_time(struct task_struct *p, u64 cputime) ...@@ -137,8 +137,6 @@ void account_user_time(struct task_struct *p, u64 cputime)
*/ */
void account_guest_time(struct task_struct *p, u64 cputime) void account_guest_time(struct task_struct *p, u64 cputime)
{ {
u64 *cpustat = kcpustat_this_cpu->cpustat;
/* Add guest time to process. */ /* Add guest time to process. */
p->utime += cputime; p->utime += cputime;
account_group_user_time(p, cputime); account_group_user_time(p, cputime);
...@@ -146,11 +144,11 @@ void account_guest_time(struct task_struct *p, u64 cputime) ...@@ -146,11 +144,11 @@ void account_guest_time(struct task_struct *p, u64 cputime)
/* Add guest time to cpustat. */ /* Add guest time to cpustat. */
if (task_nice(p) > 0) { if (task_nice(p) > 0) {
cpustat[CPUTIME_NICE] += cputime; task_group_account_field(p, CPUTIME_NICE, cputime);
cpustat[CPUTIME_GUEST_NICE] += cputime; task_group_account_field(p, CPUTIME_GUEST_NICE, cputime);
} else { } else {
cpustat[CPUTIME_USER] += cputime; task_group_account_field(p, CPUTIME_USER, cputime);
cpustat[CPUTIME_GUEST] += cputime; task_group_account_field(p, CPUTIME_GUEST, cputime);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册