mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@parallels.com>
To: <linux-kernel@vger.kernel.org>
Cc: <cgroups@vger.kernel.org>, <devel@openvz.org>,
	Paul Turner <pjt@google.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Tejun Heo <tj@kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	handai.szj@gmail.com, Andrew.Phillips@lmax.com,
	Serge Hallyn <serge.hallyn@canonical.com>,
	Glauber Costa <glommer@parallels.com>
Subject: [PATCH v4 2/4] expose fine-grained per-cpu data for cpuacct stats
Date: Tue,  5 Jun 2012 18:49:39 +0400	[thread overview]
Message-ID: <1338907781-20904-3-git-send-email-glommer@parallels.com> (raw)
In-Reply-To: <1338907781-20904-1-git-send-email-glommer@parallels.com>

The cpuacct cgroup already exposes user and system numbers in a per-cgroup
fashion. But they are a summation along the whole group, not a per-cpu figure.
Also, they are coarse-grained version of the stats usually shown at places
like /proc/stat.

I want to have enough cgroup data to emulate the /proc/stat interface. To
achieve that, I am creating a new file "stat_percpu" that displays the
fine-grained per-cpu data. The original data is left alone.

The format of this file is as follows:

1line header
cpux val1 val2 ... valn.

It is the same format used for the cpu part /proc/stat, except for the header,
that may allow us to add fields in the future if they prove themselves needed.

Signed-off-by: Glauber Costa <glommer@parallels.com>
CC: Peter Zijlstra <a.p.zijlstra@chello.nl>
CC: Paul Turner <pjt@google.com>
---
 kernel/sched/core.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 220d416..c058189 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8178,6 +8178,39 @@ static int cpuacct_stats_show(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
+static inline void do_fill_seq(struct seq_file *m, struct cpuacct *ca,
+			       int cpu, int index)
+{
+	struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
+	u64 val;
+
+	val = cputime64_to_clock_t(kcpustat->cpustat[index]);
+	seq_put_decimal_ull(m, ' ', val);
+}
+
+static int cpuacct_stats_percpu_show(struct cgroup *cgrp, struct cftype *cft,
+				     struct seq_file *m)
+{
+	struct cpuacct *ca = cgroup_ca(cgrp);
+	int cpu;
+
+	seq_printf(m, "user nice system irq softirq guest guest_nice\n");
+
+	for_each_online_cpu(cpu) {
+		seq_printf(m, "cpu%d", cpu);
+		do_fill_seq(m, ca, cpu, CPUTIME_USER);
+		do_fill_seq(m, ca, cpu, CPUTIME_NICE);
+		do_fill_seq(m, ca, cpu, CPUTIME_SYSTEM);
+		do_fill_seq(m, ca, cpu, CPUTIME_IRQ);
+		do_fill_seq(m, ca, cpu, CPUTIME_SOFTIRQ);
+		do_fill_seq(m, ca, cpu, CPUTIME_GUEST);
+		do_fill_seq(m, ca, cpu, CPUTIME_GUEST_NICE);
+		seq_putc(m, '\n');
+	}
+
+	return 0;
+}
+
 static struct cftype files[] = {
 	{
 		.name = "usage",
@@ -8192,6 +8225,10 @@ static struct cftype files[] = {
 		.name = "stat",
 		.read_map = cpuacct_stats_show,
 	},
+	{
+		.name = "stat_percpu",
+		.read_seq_string = cpuacct_stats_percpu_show,
+	},
 	{ }	/* terminate */
 };
 
-- 
1.7.10.2


  parent reply	other threads:[~2012-06-05 14:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-05 14:49 [PATCH v4 0/4] per cgroup cpu statistics Glauber Costa
2012-06-05 14:49 ` [PATCH v4 1/4] account guest time per-cgroup as well Glauber Costa
2012-06-05 14:49 ` Glauber Costa [this message]
2012-06-05 14:49 ` [PATCH v4 3/4] mark whenever put_prev_task is called from context_switch Glauber Costa
2012-06-05 14:49 ` [PATCH v4 4/4] expose per-taskgroup schedstats in cgroup Glauber Costa
2012-06-14 12:18 ` [PATCH v4 0/4] per cgroup cpu statistics Glauber Costa

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=1338907781-20904-3-git-send-email-glommer@parallels.com \
    --to=glommer@parallels.com \
    --cc=Andrew.Phillips@lmax.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=cgroups@vger.kernel.org \
    --cc=devel@openvz.org \
    --cc=ebiederm@xmission.com \
    --cc=handai.szj@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pjt@google.com \
    --cc=serge.hallyn@canonical.com \
    --cc=tj@kernel.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

all inboxes | Powered by JetHome®