linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Lei <zhaolei@cn.fujitsu.com>
To: <linux-kernel@vger.kernel.org>, Tejun Heo <htejun@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Zhao Lei <zhaolei@cn.fujitsu.com>
Subject: [PATCH v4 3/4] cpuacct: Show possible_cpu in cpuacct
Date: Tue, 22 Mar 2016 16:37:07 +0800	[thread overview]
Message-ID: <a11d56cef12d0b4807f8be3a46bf9798c3014d59.1458635566.git.zhaolei@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1458635566.git.zhaolei@cn.fujitsu.com>

Current code show stats of online cpus in cpuacct.statcpus,
show stats of present cpus in cpuacct.usage(_percpu), and using
present cpus for setting cpuacct.usage.

It will cause inconsistent result when a cpu is online or offline
or hotpluged.

We should always use possible cpus to avoid above problem.

Content of cpuacct.usage_percpu changed after this patch:
(On a 4 cpu system with maxcpus=32)
Before patch:
 # cat cpuacct.usage_percpu
 2456565 411435 1052897 832584
After patch:
 # cat cpuacct.usage_percpu
 2456565 411435 1052897 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 kernel/sched/cpuacct.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 434c2fa..4399850 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -138,7 +138,7 @@ static u64 cpuusage_read(struct cgroup_subsys_state *css, struct cftype *cft)
 	u64 totalcpuusage = 0;
 	int i;
 
-	for_each_present_cpu(i)
+	for_each_possible_cpu(i)
 		totalcpuusage += cpuacct_cpuusage_read(ca, i);
 
 	return totalcpuusage;
@@ -159,7 +159,7 @@ static int cpuusage_write(struct cgroup_subsys_state *css, struct cftype *cft,
 		goto out;
 	}
 
-	for_each_present_cpu(i)
+	for_each_possible_cpu(i)
 		cpuacct_cpuusage_write(ca, i, 0);
 
 out:
@@ -172,7 +172,7 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)
 	u64 percpu;
 	int i;
 
-	for_each_present_cpu(i) {
+	for_each_possible_cpu(i) {
 		percpu = cpuacct_cpuusage_read(ca, i);
 		seq_printf(m, "%llu ", (unsigned long long) percpu);
 	}
@@ -191,7 +191,7 @@ static int cpuacct_stats_show(struct seq_file *sf, void *v)
 	int cpu;
 	s64 val = 0;
 
-	for_each_online_cpu(cpu) {
+	for_each_possible_cpu(cpu) {
 		struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
 		val += kcpustat->cpustat[CPUTIME_USER];
 		val += kcpustat->cpustat[CPUTIME_NICE];
@@ -200,7 +200,7 @@ static int cpuacct_stats_show(struct seq_file *sf, void *v)
 	seq_printf(sf, "%s %lld\n", cpuacct_stat_desc[CPUACCT_STAT_USER], val);
 
 	val = 0;
-	for_each_online_cpu(cpu) {
+	for_each_possible_cpu(cpu) {
 		struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
 		val += kcpustat->cpustat[CPUTIME_SYSTEM];
 		val += kcpustat->cpustat[CPUTIME_IRQ];
-- 
1.8.5.1

  parent reply	other threads:[~2016-03-22  8:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22  8:37 [PATCH v4 0/4] cpuacct: split usage into user_usage and sys_usage Zhao Lei
2016-03-22  8:37 ` [PATCH v4 1/4] cpuacct: rename parameter in cpuusage_write for readability Zhao Lei
2016-03-22  8:37 ` [PATCH v4 2/4] cpuacct: small restruct for cpuacct Zhao Lei
2016-03-22  8:37 ` Zhao Lei [this message]
2016-03-31  9:27   ` [tip:sched/core] sched/cpuacct: Show all possible CPUs in cpuacct output tip-bot for Zhao Lei
2016-03-22  8:37 ` [PATCH v4 4/4] cpuacct: split usage into user_usage and sys_usage Zhao Lei
2016-03-31  9:27   ` [tip:sched/core] sched/cpuacct: Split usage accounting " tip-bot for Dongsheng Yang
2016-04-04 14:03     ` Srikar Dronamraju
2016-04-06  6:54       ` Ingo Molnar
2016-04-06  7:47         ` Zhao Lei
2016-04-06  7:50           ` Peter Zijlstra
2016-04-06 10:32         ` Anton Blanchard
2016-04-06 11:08           ` Peter Zijlstra
2016-04-06 11:43             ` Zhao Lei
2016-04-06 11:59             ` [PATCH] sched/cpuacct: Check for NULL when using task_pt_regs() Anton Blanchard
2016-04-06 13:26               ` Srikar Dronamraju
2016-04-06 17:05                 ` Zhao Lei
2016-04-13  7:43                 ` Ingo Molnar
2016-04-13 11:01                   ` Michael Ellerman
2016-04-13 11:21                     ` Ingo Molnar
2016-04-11  6:16               ` Ping? " Michael Ellerman
2016-04-13 11:49               ` [tip:sched/core] " tip-bot for Anton Blanchard
2016-03-22  9:44 ` [PATCH v4 0/4] cpuacct: split usage into user_usage and sys_usage Peter Zijlstra

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=a11d56cef12d0b4807f8be3a46bf9798c3014d59.1458635566.git.zhaolei@cn.fujitsu.com \
    --to=zhaolei@cn.fujitsu.com \
    --cc=htejun@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).