public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Turner <pjt@google.com>
To: Glauber Costa <glommer@parallels.com>
Cc: linux-kernel@vger.kernel.org, paul@paulmenage.org,
	lizf@cn.fujitsu.com, daniel.lezcano@free.fr,
	a.p.zijlstra@chello.nl, jbottomley@parallels.com,
	fweisbec@gmail.com
Subject: Re: [PATCH v2 03/14] Move /proc/stat logic inside sched.c
Date: Fri, 11 Nov 2011 17:35:10 -0800	[thread overview]
Message-ID: <4EBDCD4E.1060801@google.com> (raw)
In-Reply-To: <1320182360-20043-4-git-send-email-glommer@parallels.com>

On 11/01/2011 02:19 PM, Glauber Costa wrote:
> This patch moves all of the /proc/stat display code inside
> sched.c. The goal is to later on, have a different version
> of it per-cgroup. In containers environment, this is useful
> to give each container a different and independent view of
> the statistics displayed in this file.
>
> Signed-off-by: Glauber Costa<glommer@parallels.com>
> ---
>   fs/proc/stat.c        |  139 +-----------------------------------------------
>   include/linux/sched.h |    1 +
>   kernel/sched.c        |  142 +++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 144 insertions(+), 138 deletions(-)
>

This feels a little contrived.  sched.c isn't the right place for much of this 
code.  Why do you want to move it all instead of exporting the functionality 
(e.g. remove static?).

> diff --git a/kernel/sched.c b/kernel/sched.c
> index e78e1aa..3f42916 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -71,6 +71,7 @@
>   #include<linux/ctype.h>
>   #include<linux/ftrace.h>
>   #include<linux/slab.h>
> +#include<linux/tick.h>
>
>   #include<asm/tlb.h>
>   #include<asm/irq_regs.h>
> @@ -9494,6 +9495,147 @@ struct cgroup_subsys cpu_cgroup_subsys = {
>
>   #endif	/* CONFIG_CGROUP_SCHED */
>
> +#ifndef fi
> +#define arch_irq_stat_cpu(cpu) 0
> +#endif
> +#ifndef arch_irq_stat
> +#define arch_irq_stat() 0
> +#endif
> +#ifndef arch_idle_time
> +#define arch_idle_time(cpu) 0
> +#endif
> +
> +static u64 get_idle_time(int cpu)
> +{
> +	u64 idle, idle_time = get_cpu_idle_time_us(cpu, NULL);
> +
> +	if (idle_time == -1ULL) {
> +		/* !NO_HZ so we can rely on cpustat.idle */
> +		idle = kstat_cpu(cpu).cpustat[IDLE];
> +		idle += arch_idle_time(cpu);
> +	} else
> +		idle = usecs_to_cputime(idle_time);
> +
> +	return idle;
> +}
> +
> +static u64 get_iowait_time(int cpu)
> +{
> +	u64 iowait, iowait_time = get_cpu_iowait_time_us(cpu, NULL);
> +
> +	if (iowait_time == -1ULL)
> +		/* !NO_HZ so we can rely on cpustat.iowait */
> +		iowait = kstat_cpu(cpu).cpustat[IOWAIT];
> +	else
> +		iowait = usecs_to_cputime(iowait_time);
> +
> +	return iowait;
> +}
> +
> +int cpu_cgroup_proc_stat(struct seq_file *p)
> +{
> +	int i, j;
> +	unsigned long jif;
> +	u64 user, nice, system, idle, iowait, irq, softirq, steal;
> +	u64 guest, guest_nice;
> +	u64 sum = 0;
> +	u64 sum_softirq = 0;
> +	unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
> +	struct timespec boottime;
> +
> +	user = nice = system = idle = iowait =
> +		irq = softirq = steal = 0;
> +	guest = guest_nice = 0;
> +	getboottime(&boottime);
> +	jif = boottime.tv_sec;
> +
> +	for_each_possible_cpu(i) {
> +		user += kstat_cpu(i).cpustat[USER];
> +		nice += kstat_cpu(i).cpustat[NICE];
> +		system += kstat_cpu(i).cpustat[SYSTEM];
> +		idle += get_idle_time(i);
> +		iowait += get_iowait_time(i);
> +		irq += kstat_cpu(i).cpustat[IRQ];
> +		softirq += kstat_cpu(i).cpustat[SOFTIRQ];
> +		steal += kstat_cpu(i).cpustat[STEAL];
> +		guest += kstat_cpu(i).cpustat[GUEST];
> +		guest_nice += kstat_cpu(i).cpustat[GUEST_NICE];
> +
> +		for (j = 0; j<  NR_SOFTIRQS; j++) {
> +			unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
> +
> +			per_softirq_sums[j] += softirq_stat;
> +			sum_softirq += softirq_stat;
> +		}
> +	}
> +	sum += arch_irq_stat();
> +
> +	seq_printf(p, "cpu  %llu %llu %llu %llu %llu %llu %llu %llu %llu "
> +		"%llu\n",
> +		(unsigned long long)cputime64_to_clock_t(user),
> +		(unsigned long long)cputime64_to_clock_t(nice),
> +		(unsigned long long)cputime64_to_clock_t(system),
> +		(unsigned long long)cputime64_to_clock_t(idle),
> +		(unsigned long long)cputime64_to_clock_t(iowait),
> +		(unsigned long long)cputime64_to_clock_t(irq),
> +		(unsigned long long)cputime64_to_clock_t(softirq),
> +		(unsigned long long)cputime64_to_clock_t(steal),
> +		(unsigned long long)cputime64_to_clock_t(guest),
> +		(unsigned long long)cputime64_to_clock_t(guest_nice));
> +	for_each_online_cpu(i) {
> +		/* Copy values here to work around gcc-2.95.3, gcc-2.96 */

GCC 3.2 is the listed current minimum requirement.  If this code is being 
revisited this could be cleaned up.

> +		user = kstat_cpu(i).cpustat[USER];
> +		nice = kstat_cpu(i).cpustat[NICE];
> +		system = kstat_cpu(i).cpustat[SYSTEM];
> +		idle = get_idle_time(i);
> +		iowait = get_iowait_time(i);
> +		irq = kstat_cpu(i).cpustat[IRQ];
> +		softirq = kstat_cpu(i).cpustat[SOFTIRQ];
> +		steal = kstat_cpu(i).cpustat[STEAL];
> +		guest = kstat_cpu(i).cpustat[GUEST];
> +		guest_nice = kstat_cpu(i).cpustat[GUEST_NICE];
> +		seq_printf(p,
> +			"cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu "
> +			"%llu\n",
> +			i,
> +			(unsigned long long)cputime64_to_clock_t(user),
> +			(unsigned long long)cputime64_to_clock_t(nice),
> +			(unsigned long long)cputime64_to_clock_t(system),
> +			(unsigned long long)cputime64_to_clock_t(idle),
> +			(unsigned long long)cputime64_to_clock_t(iowait),
> +			(unsigned long long)cputime64_to_clock_t(irq),
> +			(unsigned long long)cputime64_to_clock_t(softirq),
> +			(unsigned long long)cputime64_to_clock_t(steal),
> +			(unsigned long long)cputime64_to_clock_t(guest),
> +			(unsigned long long)cputime64_to_clock_t(guest_nice));
> +	}
> +	seq_printf(p, "intr %llu", (unsigned long long)sum);
> +
> +	/* sum again ? it could be updated? */
> +	for_each_irq_nr(j)
> +		seq_printf(p, " %u", kstat_irqs(j));
> +
> +	seq_printf(p,
> +		"\nctxt %llu\n"
> +		"btime %lu\n"
> +		"processes %lu\n"
> +		"procs_running %lu\n"
> +		"procs_blocked %lu\n",
> +		nr_context_switches(),
> +		(unsigned long)jif,
> +		total_forks,
> +		nr_running(),
> +		nr_iowait());
> +
> +	seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
> +
> +	for (i = 0; i<  NR_SOFTIRQS; i++)
> +		seq_printf(p, " %u", per_softirq_sums[i]);
> +	seq_putc(p, '\n');
> +
> +	return 0;
> +}
> +
>   #ifdef CONFIG_CGROUP_CPUACCT
>
>   /*


  reply	other threads:[~2011-11-12  1:35 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-01 21:19 [PATCH v2 00/14] per-cgroup /proc/stat Glauber Costa
2011-11-01 21:19 ` [PATCH v2 01/14] trivial: initialize root cgroup's sibling list Glauber Costa
2011-11-11 21:34   ` Paul Turner
2011-11-14 19:44     ` Glauber Costa
2011-11-14 21:44       ` Peter Zijlstra
2011-11-18 23:42   ` [tip:sched/core] sched, trivial: Initialize " tip-bot for Glauber Costa
2011-11-01 21:19 ` [PATCH v2 02/14] Change cpustat fields to an array Glauber Costa
2011-11-01 21:19 ` [PATCH v2 03/14] Move /proc/stat logic inside sched.c Glauber Costa
2011-11-12  1:35   ` Paul Turner [this message]
2011-11-12 10:27     ` Glauber Costa
2011-11-01 21:19 ` [PATCH v2 04/14] split kernel stat in two Glauber Costa
2011-11-01 21:19 ` [PATCH v2 05/14] Display /proc/stat information per cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 06/14] Make total_forks per-cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 07/14] per-cgroup boot time Glauber Costa
2011-11-01 21:19 ` [PATCH v2 08/14] Report steal time for cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 09/14] Keep nr_iowait per cgroup Glauber Costa
2011-11-10 10:27   ` Andrew Wagin
2011-11-01 21:19 ` [PATCH v2 10/14] Keep number of context switches per-cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 11/14] provide a version of cpuacct statistics inside cpu cgroup Glauber Costa
2011-11-01 21:19 ` [PATCH v2 12/14] Keep number of running processes per-cgroup Glauber Costa
2011-11-14 14:42   ` Andrew Wagin
2011-11-01 21:19 ` [PATCH v2 13/14] provide a version of cpuusage statistics inside cpu cgroup Glauber Costa
2011-11-09 11:51   ` Andrew Wagin
2011-11-09 11:58     ` Glauber Costa
2011-11-09 14:18       ` Andrew Wagin
2011-11-09 15:30         ` Peter Zijlstra
2011-11-09 16:51         ` Glauber Costa
2011-11-10  8:59           ` Andrew Wagin
2011-11-01 21:19 ` [PATCH v2 14/14] Change CPUACCT to default n Glauber Costa
2011-11-11 21:33   ` Paul Turner
2011-11-12 10:29     ` Glauber Costa
2011-11-15 11:02       ` Paul Turner
2011-11-16 10:21         ` Balbir Singh
2011-11-16 23:52           ` KAMEZAWA Hiroyuki
2011-11-17  2:49             ` Glauber Costa
2011-11-17  2:58               ` Balbir Singh
2011-11-17 15:58                 ` Glauber Costa
2011-11-21  1:59                   ` KAMEZAWA Hiroyuki
2011-11-24 13:24                     ` Peter Zijlstra
2011-11-24 16:07                       ` Glauber Costa
2011-11-24 16:29                         ` Peter Zijlstra
2011-11-24 16:38                           ` Glauber Costa
2011-11-24 16:58                             ` Peter Zijlstra
2011-11-25  5:38                             ` Balbir Singh
2011-11-25 10:19                               ` Peter Zijlstra
2011-11-26 13:18                                 ` Paul Turner
2011-11-28  8:29                                   ` Balbir Singh
2011-11-25  2:05         ` Li Zefan
2011-11-25 10:09           ` Peter Zijlstra
2011-11-26 13:07           ` Paul Turner

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=4EBDCD4E.1060801@google.com \
    --to=pjt@google.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=daniel.lezcano@free.fr \
    --cc=fweisbec@gmail.com \
    --cc=glommer@parallels.com \
    --cc=jbottomley@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=paul@paulmenage.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