linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Zhao Lei <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: hpa@zytor.com, torvalds@linux-foundation.org,
	zhaolei@cn.fujitsu.com, peterz@infradead.org, mingo@kernel.org,
	tglx@linutronix.de, kosaki.motohiro@jp.fujitsu.com,
	linux-kernel@vger.kernel.org
Subject: [tip:sched/core] sched/cpuacct: Introduce cpuacct.usage_all to show all CPU stats together
Date: Sat, 9 Jul 2016 10:53:54 -0700	[thread overview]
Message-ID: <tip-277a13e4f0d661678a7084bf97ed96a99c7dac21@git.kernel.org> (raw)
In-Reply-To: <7744460969edd7caaf0e903592ee52353ed9bdd6.1466415271.git.zhaolei@cn.fujitsu.com>

Commit-ID:  277a13e4f0d661678a7084bf97ed96a99c7dac21
Gitweb:     http://git.kernel.org/tip/277a13e4f0d661678a7084bf97ed96a99c7dac21
Author:     Zhao Lei <zhaolei@cn.fujitsu.com>
AuthorDate: Mon, 20 Jun 2016 17:37:20 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 9 Jul 2016 13:56:15 +0200

sched/cpuacct: Introduce cpuacct.usage_all to show all CPU stats together

In current code, we can get cpuacct data from several files,
but each file has various limitations.

For example:

 - We can get CPU usage in user and kernel mode via cpuacct.stat,
   but we can't get detailed data about each CPU.

 - We can get each CPU's kernel mode usage in cpuacct.usage_percpu_sys,
   but we can't get user mode usage data at the same time.

This patch introduces cpuacct.usage_all, to show all detailed CPU
accounting data together:

 # cat cpuacct.usage_all
 cpu user system
 0 3809760299 5807968992
 1 3250329855 454612211
 ..

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/7744460969edd7caaf0e903592ee52353ed9bdd6.1466415271.git.zhaolei@cn.fujitsu.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/cpuacct.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 677cd1a..bc0b309c 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -240,6 +240,42 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)
 	return __cpuacct_percpu_seq_show(m, CPUACCT_STAT_NSTATS);
 }
 
+static int cpuacct_all_seq_show(struct seq_file *m, void *V)
+{
+	struct cpuacct *ca = css_ca(seq_css(m));
+	int index;
+	int cpu;
+
+	seq_puts(m, "cpu");
+	for (index = 0; index < CPUACCT_STAT_NSTATS; index++)
+		seq_printf(m, " %s", cpuacct_stat_desc[index]);
+	seq_puts(m, "\n");
+
+	for_each_possible_cpu(cpu) {
+		struct cpuacct_usage *cpuusage = per_cpu_ptr(ca->cpuusage, cpu);
+
+		seq_printf(m, "%d", cpu);
+
+		for (index = 0; index < CPUACCT_STAT_NSTATS; index++) {
+#ifndef CONFIG_64BIT
+			/*
+			 * Take rq->lock to make 64-bit read safe on 32-bit
+			 * platforms.
+			 */
+			raw_spin_lock_irq(&cpu_rq(cpu)->lock);
+#endif
+
+			seq_printf(m, " %llu", cpuusage->usages[index]);
+
+#ifndef CONFIG_64BIT
+			raw_spin_unlock_irq(&cpu_rq(cpu)->lock);
+#endif
+		}
+		seq_puts(m, "\n");
+	}
+	return 0;
+}
+
 static int cpuacct_stats_show(struct seq_file *sf, void *v)
 {
 	struct cpuacct *ca = css_ca(seq_css(sf));
@@ -294,6 +330,10 @@ static struct cftype files[] = {
 		.seq_show = cpuacct_percpu_sys_seq_show,
 	},
 	{
+		.name = "usage_all",
+		.seq_show = cpuacct_all_seq_show,
+	},
+	{
 		.name = "stat",
 		.seq_show = cpuacct_stats_show,
 	},

      reply	other threads:[~2016-07-09 17:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-20  9:37 [PATCH v4 0/3] cpuacct: Introduce cpuacct.usage_all to show all cpu stats together(was: [PATCH v2 0/3] cpuacct: Show all detail stats in one file) Zhao Lei
2016-06-20  9:37 ` [PATCH v4 1/3] cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index Zhao Lei
2016-07-09 17:52   ` [tip:sched/core] sched/cpuacct: Merge cpuacct_usage_index and cpuacct_stat_index enums tip-bot for Zhao Lei
2016-06-20  9:37 ` [PATCH v4 2/3] cpuacct: Use loop to avoid copies of the similar code in cpuacct_stats_show() Zhao Lei
2016-07-09 17:53   ` [tip:sched/core] sched/cpuacct: Use loop to consolidate " tip-bot for Zhao Lei
2016-06-20  9:37 ` [PATCH v4 3/3] cpuacct: Introduce cpuacct.usage_all to show all cpu stats together Zhao Lei
2016-07-09 17:53   ` tip-bot for Zhao Lei [this message]

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=tip-277a13e4f0d661678a7084bf97ed96a99c7dac21@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=zhaolei@cn.fujitsu.com \
    /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).