public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] /proc/stat idle field for idle cpus
@ 2009-04-14 12:18 Martin Schwidefsky
  2009-04-17 23:02 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Schwidefsky @ 2009-04-14 12:18 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Benjamin Herrenschmidt, Heiko Carstens, Paul Mackerras, Tony Luck,
	Hidetoshi Seto, Jeremy Fitzhardinge, Peter Zijlstra, Ingo Molnar

From: Martin Schwidefsky <schwidefsky@de.ibm.com>

The cpu idle field in the output of /proc/stat is too small for cpus
that have been idle for more than a tick. Add the architecture hook
arch_idle_time that allows to add the not accounted idle time of a
sleeping cpu without waking the cpu.

The s390 implementation of arch_idle_time uses the already existing
s390_idle_data per_cpu variable to find the sleep time of a neighboring
idle cpu.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---

 arch/s390/include/asm/cputime.h |    4 ++++
 arch/s390/kernel/vtime.c        |   16 ++++++++++++++++
 fs/proc/stat.c                  |    8 ++++++--
 3 files changed, 26 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/s390/include/asm/cputime.h
===================================================================
--- linux-2.6.orig/arch/s390/include/asm/cputime.h
+++ linux-2.6/arch/s390/include/asm/cputime.h
@@ -174,4 +174,8 @@ cputime64_to_clock_t(cputime64_t cputime
        return __div(cputime, 4096000000ULL / USER_HZ);
 }
 
+cputime64_t s390_get_idle_time(int cpu);
+
+#define arch_idle_time(cpu) s390_get_idle_time(cpu)
+
 #endif /* _S390_CPUTIME_H */
Index: linux-2.6/arch/s390/kernel/vtime.c
===================================================================
--- linux-2.6.orig/arch/s390/kernel/vtime.c
+++ linux-2.6/arch/s390/kernel/vtime.c
@@ -238,6 +238,22 @@ void vtime_stop_cpu(void)
 	}
 }
 
+cputime64_t s390_get_idle_time(int cpu)
+{
+	struct s390_idle_data *idle;
+	unsigned long long now, idle_time, idle_enter;
+
+	idle = &per_cpu(s390_idle, cpu);
+	spin_lock(&idle->lock);
+	now = get_clock();
+	idle_time = 0;
+	idle_enter = idle->idle_enter;
+	if (idle_enter != 0ULL && idle_enter < now)
+		idle_time = now - idle_enter;
+	spin_unlock(&idle->lock);
+	return idle_time;
+}
+
 /*
  * Sorted add to a list. List is linear searched until first bigger
  * element is found.
Index: linux-2.6/fs/proc/stat.c
===================================================================
--- linux-2.6.orig/fs/proc/stat.c
+++ linux-2.6/fs/proc/stat.c
@@ -18,6 +18,9 @@
 #ifndef arch_irq_stat
 #define arch_irq_stat() 0
 #endif
+#ifndef arch_idle_time
+#define arch_idle_time(cpu) 0
+#endif
 
 static int show_stat(struct seq_file *p, void *v)
 {
@@ -39,7 +42,8 @@ static int show_stat(struct seq_file *p,
 		user = cputime64_add(user, kstat_cpu(i).cpustat.user);
 		nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
 		system = cputime64_add(system, kstat_cpu(i).cpustat.system);
-		idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
+		idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle +
+				     arch_idle_time(i));
 		iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
 		irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
 		softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
@@ -68,7 +72,7 @@ static int show_stat(struct seq_file *p,
 		user = kstat_cpu(i).cpustat.user;
 		nice = kstat_cpu(i).cpustat.nice;
 		system = kstat_cpu(i).cpustat.system;
-		idle = kstat_cpu(i).cpustat.idle;
+		idle = kstat_cpu(i).cpustat.idle + arch_idle_time(i);
 		iowait = kstat_cpu(i).cpustat.iowait;
 		irq = kstat_cpu(i).cpustat.irq;
 		softirq = kstat_cpu(i).cpustat.softirq;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] /proc/stat idle field for idle cpus
  2009-04-14 12:18 [RFC][PATCH] /proc/stat idle field for idle cpus Martin Schwidefsky
@ 2009-04-17 23:02 ` Andrew Morton
  2009-04-20  7:15   ` Martin Schwidefsky
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2009-04-17 23:02 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: linux-kernel, linux-arch, benh, heiko.carstens, paulus, tony.luck,
	seto.hidetoshi, jeremy, a.p.zijlstra, mingo, Alexey Dobriyan

On Tue, 14 Apr 2009 14:18:51 +0200
Martin Schwidefsky <schwidefsky@de.ibm.com> wrote:

> --- linux-2.6.orig/fs/proc/stat.c
> +++ linux-2.6/fs/proc/stat.c
> @@ -18,6 +18,9 @@
>  #ifndef arch_irq_stat
>  #define arch_irq_stat() 0
>  #endif
> +#ifndef arch_idle_time
> +#define arch_idle_time(cpu) 0
> +#endif
>  
>  static int show_stat(struct seq_file *p, void *v)
>  {
> @@ -39,7 +42,8 @@ static int show_stat(struct seq_file *p,
>  		user = cputime64_add(user, kstat_cpu(i).cpustat.user);
>  		nice = cputime64_add(nice, kstat_cpu(i).cpustat.nice);
>  		system = cputime64_add(system, kstat_cpu(i).cpustat.system);
> -		idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle);
> +		idle = cputime64_add(idle, kstat_cpu(i).cpustat.idle +
> +				     arch_idle_time(i));
>  		iowait = cputime64_add(iowait, kstat_cpu(i).cpustat.iowait);
>  		irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
>  		softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
> @@ -68,7 +72,7 @@ static int show_stat(struct seq_file *p,
>  		user = kstat_cpu(i).cpustat.user;
>  		nice = kstat_cpu(i).cpustat.nice;
>  		system = kstat_cpu(i).cpustat.system;
> -		idle = kstat_cpu(i).cpustat.idle;
> +		idle = kstat_cpu(i).cpustat.idle + arch_idle_time(i);
>  		iowait = kstat_cpu(i).cpustat.iowait;
>  		irq = kstat_cpu(i).cpustat.irq;
>  		softirq = kstat_cpu(i).cpustat.softirq;

Looks OK to me.  Please merge it via the s390 tree.

Do other architectures need to fix this?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] /proc/stat idle field for idle cpus
  2009-04-17 23:02 ` Andrew Morton
@ 2009-04-20  7:15   ` Martin Schwidefsky
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Schwidefsky @ 2009-04-20  7:15 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-arch, benh, heiko.carstens, paulus, tony.luck,
	seto.hidetoshi, jeremy, a.p.zijlstra, mingo, Alexey Dobriyan

On Fri, 17 Apr 2009 16:02:11 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:

> Looks OK to me.  Please merge it via the s390 tree.
> 
> Do other architectures need to fix this?

Thanks Andrew for the quick review. Other architecture might want to
implement this as well, with tick-less the idle numbers in /proc/stat
are just way off. The implementation of the arch_idle_time is not easy
I'm afraid, the sleep time of each cpu needs to be measured in a way
that it can be read from neighbouring cpus (and it should better be a
precise). Not something I would want to have to implement for x86.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-20  7:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-14 12:18 [RFC][PATCH] /proc/stat idle field for idle cpus Martin Schwidefsky
2009-04-17 23:02 ` Andrew Morton
2009-04-20  7:15   ` Martin Schwidefsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox