aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Neuling <mikey@neuling.org>2008-02-06 04:36:12 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-06 13:41:00 -0500
commit06b8e878a9bc9301201cffe186eba99c4185f20a (patch)
tree857434ed559cdb001177e81283be6f0b5693a781
parentd9afa43532adf8a31b93c4c7601fda3f423d8972 (diff)
taskstats scaled time cleanup
This moves the ability to scale cputime into generic code. This allows us to fix the issue in kernel/timer.c (noticed by Balbir) where we could only add an unscaled value to the scaled utime/stime. This adds a cputime_to_scaled function. As before, the POWERPC version does the scaling based on the last SPURR/PURR ratio calculated. The generic and s390 (only other arch to implement asm/cputime.h) versions are both NOPs. Also moves the SPURR and PURR snapshots closer. Signed-off-by: Michael Neuling <mikey@neuling.org> Cc: Jay Lan <jlan@engr.sgi.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/powerpc/kernel/time.c12
-rw-r--r--include/asm-generic/cputime.h1
-rw-r--r--include/asm-powerpc/cputime.h14
-rw-r--r--include/asm-powerpc/paca.h2
-rw-r--r--include/asm-s390/cputime.h1
-rw-r--r--kernel/timer.c10
6 files changed, 28 insertions, 12 deletions
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 5cd3db5cae41..3b26fbd6bec9 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -66,6 +66,7 @@
66#include <asm/smp.h> 66#include <asm/smp.h>
67#include <asm/vdso_datapage.h> 67#include <asm/vdso_datapage.h>
68#include <asm/firmware.h> 68#include <asm/firmware.h>
69#include <asm/cputime.h>
69#ifdef CONFIG_PPC_ISERIES 70#ifdef CONFIG_PPC_ISERIES
70#include <asm/iseries/it_lp_queue.h> 71#include <asm/iseries/it_lp_queue.h>
71#include <asm/iseries/hv_call_xm.h> 72#include <asm/iseries/hv_call_xm.h>
@@ -189,6 +190,8 @@ u64 __cputime_sec_factor;
189EXPORT_SYMBOL(__cputime_sec_factor); 190EXPORT_SYMBOL(__cputime_sec_factor);
190u64 __cputime_clockt_factor; 191u64 __cputime_clockt_factor;
191EXPORT_SYMBOL(__cputime_clockt_factor); 192EXPORT_SYMBOL(__cputime_clockt_factor);
193DEFINE_PER_CPU(unsigned long, cputime_last_delta);
194DEFINE_PER_CPU(unsigned long, cputime_scaled_last_delta);
192 195
193static void calc_cputime_factors(void) 196static void calc_cputime_factors(void)
194{ 197{
@@ -257,8 +260,8 @@ void account_system_vtime(struct task_struct *tsk)
257 } 260 }
258 account_system_time(tsk, 0, delta); 261 account_system_time(tsk, 0, delta);
259 account_system_time_scaled(tsk, deltascaled); 262 account_system_time_scaled(tsk, deltascaled);
260 get_paca()->purrdelta = delta; 263 per_cpu(cputime_last_delta, smp_processor_id()) = delta;
261 get_paca()->spurrdelta = deltascaled; 264 per_cpu(cputime_scaled_last_delta, smp_processor_id()) = deltascaled;
262 local_irq_restore(flags); 265 local_irq_restore(flags);
263} 266}
264 267
@@ -276,10 +279,7 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
276 get_paca()->user_time = 0; 279 get_paca()->user_time = 0;
277 account_user_time(tsk, utime); 280 account_user_time(tsk, utime);
278 281
279 /* Estimate the scaled utime by scaling the real utime based 282 utimescaled = cputime_to_scaled(utime);
280 * on the last spurr to purr ratio */
281 utimescaled = utime * get_paca()->spurrdelta / get_paca()->purrdelta;
282 get_paca()->spurrdelta = get_paca()->purrdelta = 0;
283 account_user_time_scaled(tsk, utimescaled); 283 account_user_time_scaled(tsk, utimescaled);
284} 284}
285 285
diff --git a/include/asm-generic/cputime.h b/include/asm-generic/cputime.h
index 09204e40d663..1c1fa422d18a 100644
--- a/include/asm-generic/cputime.h
+++ b/include/asm-generic/cputime.h
@@ -18,6 +18,7 @@ typedef unsigned long cputime_t;
18#define cputime_lt(__a, __b) ((__a) < (__b)) 18#define cputime_lt(__a, __b) ((__a) < (__b))
19#define cputime_le(__a, __b) ((__a) <= (__b)) 19#define cputime_le(__a, __b) ((__a) <= (__b))
20#define cputime_to_jiffies(__ct) (__ct) 20#define cputime_to_jiffies(__ct) (__ct)
21#define cputime_to_scaled(__ct) (__ct)
21#define jiffies_to_cputime(__hz) (__hz) 22#define jiffies_to_cputime(__hz) (__hz)
22 23
23typedef u64 cputime64_t; 24typedef u64 cputime64_t;
diff --git a/include/asm-powerpc/cputime.h b/include/asm-powerpc/cputime.h
index 310804485208..f42e623030ee 100644
--- a/include/asm-powerpc/cputime.h
+++ b/include/asm-powerpc/cputime.h
@@ -52,12 +52,26 @@ typedef u64 cputime64_t;
52 * Convert cputime <-> jiffies 52 * Convert cputime <-> jiffies
53 */ 53 */
54extern u64 __cputime_jiffies_factor; 54extern u64 __cputime_jiffies_factor;
55DECLARE_PER_CPU(unsigned long, cputime_last_delta);
56DECLARE_PER_CPU(unsigned long, cputime_scaled_last_delta);
55 57
56static inline unsigned long cputime_to_jiffies(const cputime_t ct) 58static inline unsigned long cputime_to_jiffies(const cputime_t ct)
57{ 59{
58 return mulhdu(ct, __cputime_jiffies_factor); 60 return mulhdu(ct, __cputime_jiffies_factor);
59} 61}
60 62
63/* Estimate the scaled cputime by scaling the real cputime based on
64 * the last scaled to real ratio */
65static inline cputime_t cputime_to_scaled(const cputime_t ct)
66{
67 if (cpu_has_feature(CPU_FTR_SPURR) &&
68 per_cpu(cputime_last_delta, smp_processor_id()))
69 return ct *
70 per_cpu(cputime_scaled_last_delta, smp_processor_id())/
71 per_cpu(cputime_last_delta, smp_processor_id());
72 return ct;
73}
74
61static inline cputime_t jiffies_to_cputime(const unsigned long jif) 75static inline cputime_t jiffies_to_cputime(const unsigned long jif)
62{ 76{
63 cputime_t ct; 77 cputime_t ct;
diff --git a/include/asm-powerpc/paca.h b/include/asm-powerpc/paca.h
index f6dfce025adf..748b35ab37b5 100644
--- a/include/asm-powerpc/paca.h
+++ b/include/asm-powerpc/paca.h
@@ -115,8 +115,6 @@ struct paca_struct {
115 u64 system_time; /* accumulated system TB ticks */ 115 u64 system_time; /* accumulated system TB ticks */
116 u64 startpurr; /* PURR/TB value snapshot */ 116 u64 startpurr; /* PURR/TB value snapshot */
117 u64 startspurr; /* SPURR value snapshot */ 117 u64 startspurr; /* SPURR value snapshot */
118 u64 purrdelta; /* FIXME: document */
119 u64 spurrdelta; /* FIXME: document */
120}; 118};
121 119
122extern struct paca_struct paca[]; 120extern struct paca_struct paca[];
diff --git a/include/asm-s390/cputime.h b/include/asm-s390/cputime.h
index 4b3ef7cad115..133ce054fc89 100644
--- a/include/asm-s390/cputime.h
+++ b/include/asm-s390/cputime.h
@@ -54,6 +54,7 @@ __div(unsigned long long n, unsigned int base)
54#define cputime_lt(__a, __b) ((__a) < (__b)) 54#define cputime_lt(__a, __b) ((__a) < (__b))
55#define cputime_le(__a, __b) ((__a) <= (__b)) 55#define cputime_le(__a, __b) ((__a) <= (__b))
56#define cputime_to_jiffies(__ct) (__div((__ct), 1000000 / HZ)) 56#define cputime_to_jiffies(__ct) (__div((__ct), 1000000 / HZ))
57#define cputime_to_scaled(__ct) (__ct)
57#define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (1000000 / HZ)) 58#define jiffies_to_cputime(__hz) ((cputime_t)(__hz) * (1000000 / HZ))
58 59
59#define cputime64_zero (0ULL) 60#define cputime64_zero (0ULL)
diff --git a/kernel/timer.c b/kernel/timer.c
index 9fbb472b8cf0..70b29b59343f 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -818,12 +818,14 @@ unsigned long next_timer_interrupt(void)
818#ifndef CONFIG_VIRT_CPU_ACCOUNTING 818#ifndef CONFIG_VIRT_CPU_ACCOUNTING
819void account_process_tick(struct task_struct *p, int user_tick) 819void account_process_tick(struct task_struct *p, int user_tick)
820{ 820{
821 cputime_t one_jiffy = jiffies_to_cputime(1);
822
821 if (user_tick) { 823 if (user_tick) {
822 account_user_time(p, jiffies_to_cputime(1)); 824 account_user_time(p, one_jiffy);
823 account_user_time_scaled(p, jiffies_to_cputime(1)); 825 account_user_time_scaled(p, cputime_to_scaled(one_jiffy));
824 } else { 826 } else {
825 account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1)); 827 account_system_time(p, HARDIRQ_OFFSET, one_jiffy);
826 account_system_time_scaled(p, jiffies_to_cputime(1)); 828 account_system_time_scaled(p, cputime_to_scaled(one_jiffy));
827 } 829 }
828} 830}
829#endif 831#endif