aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2008-12-31 09:11:38 -0500
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2008-12-31 09:11:46 -0500
commit79741dd35713ff4f6fd0eafd59fa94e8a4ba922d (patch)
tree73c6b503fbd274cb3fcca7a0a68c6f636e3a53ad /arch
parent457533a7d3402d1d91fbc125c8bd1bd16dcd3cd4 (diff)
[PATCH] idle cputime accounting
The cpu time spent by the idle process actually doing something is currently accounted as idle time. This is plain wrong, the architectures that support VIRT_CPU_ACCOUNTING=y can do better: distinguish between the time spent doing nothing and the time spent by idle doing work. The first is accounted with account_idle_time and the second with account_system_time. The architectures that use the account_xxx_time interface directly and not the account_xxx_ticks interface now need to do the check for the idle process in their arch code. In particular to improve the system vs true idle time accounting the arch code needs to measure the true idle time instead of just testing for the idle process. To improve the tick based accounting as well we would need an architecture primitive that can tell us if the pt_regs of the interrupted context points to the magic instruction that halts the cpu. In addition idle time is no more added to the stime of the idle process. This field now contains the system time of the idle process as it should be. On systems without VIRT_CPU_ACCOUNTING this will always be zero as every tick that occurs while idle is running will be accounted as idle time. This patch contains the necessary common code changes to be able to distinguish idle system time and true idle time. The architectures with support for VIRT_CPU_ACCOUNTING need some changes to exploit this. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/ia64/kernel/time.c10
-rw-r--r--arch/powerpc/kernel/process.c1
-rw-r--r--arch/powerpc/kernel/time.c13
-rw-r--r--arch/s390/kernel/vtime.c20
-rw-r--r--arch/x86/xen/time.c10
5 files changed, 39 insertions, 15 deletions
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 4ee367817049..f0ebb342409d 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -93,7 +93,10 @@ void ia64_account_on_switch(struct task_struct *prev, struct task_struct *next)
93 now = ia64_get_itc(); 93 now = ia64_get_itc();
94 94
95 delta_stime = cycle_to_cputime(pi->ac_stime + (now - pi->ac_stamp)); 95 delta_stime = cycle_to_cputime(pi->ac_stime + (now - pi->ac_stamp));
96 account_system_time(prev, 0, delta_stime, delta_stime); 96 if (idle_task(smp_processor_id()) != prev)
97 account_system_time(prev, 0, delta_stime, delta_stime);
98 else
99 account_idle_time(delta_stime);
97 100
98 if (pi->ac_utime) { 101 if (pi->ac_utime) {
99 delta_utime = cycle_to_cputime(pi->ac_utime); 102 delta_utime = cycle_to_cputime(pi->ac_utime);
@@ -120,7 +123,10 @@ void account_system_vtime(struct task_struct *tsk)
120 now = ia64_get_itc(); 123 now = ia64_get_itc();
121 124
122 delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp)); 125 delta_stime = cycle_to_cputime(ti->ac_stime + (now - ti->ac_stamp));
123 account_system_time(tsk, 0, delta_stime, delta_stime); 126 if (irq_count() || idle_task(smp_processor_id()) != tsk)
127 account_system_time(tsk, 0, delta_stime, delta_stime);
128 else
129 account_idle_time(delta_stime);
124 ti->ac_stime = 0; 130 ti->ac_stime = 0;
125 131
126 ti->ac_stamp = now; 132 ti->ac_stamp = now;
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 51b201ddf9a1..fb7049c054c0 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -33,6 +33,7 @@
33#include <linux/mqueue.h> 33#include <linux/mqueue.h>
34#include <linux/hardirq.h> 34#include <linux/hardirq.h>
35#include <linux/utsname.h> 35#include <linux/utsname.h>
36#include <linux/kernel_stat.h>
36 37
37#include <asm/pgtable.h> 38#include <asm/pgtable.h>
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 92650ccad2e1..3be355c1cfa7 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -256,7 +256,10 @@ void account_system_vtime(struct task_struct *tsk)
256 delta += sys_time; 256 delta += sys_time;
257 get_paca()->system_time = 0; 257 get_paca()->system_time = 0;
258 } 258 }
259 account_system_time(tsk, 0, delta, deltascaled); 259 if (in_irq() || idle_task(smp_processor_id()) != tsk)
260 account_system_time(tsk, 0, delta, deltascaled);
261 else
262 account_idle_time(delta);
260 per_cpu(cputime_last_delta, smp_processor_id()) = delta; 263 per_cpu(cputime_last_delta, smp_processor_id()) = delta;
261 per_cpu(cputime_scaled_last_delta, smp_processor_id()) = deltascaled; 264 per_cpu(cputime_scaled_last_delta, smp_processor_id()) = deltascaled;
262 local_irq_restore(flags); 265 local_irq_restore(flags);
@@ -335,8 +338,12 @@ void calculate_steal_time(void)
335 tb = mftb(); 338 tb = mftb();
336 purr = mfspr(SPRN_PURR); 339 purr = mfspr(SPRN_PURR);
337 stolen = (tb - pme->tb) - (purr - pme->purr); 340 stolen = (tb - pme->tb) - (purr - pme->purr);
338 if (stolen > 0) 341 if (stolen > 0) {
339 account_steal_time(current, stolen); 342 if (idle_task(smp_processor_id()) != current)
343 account_steal_time(stolen);
344 else
345 account_idle_time(stolen);
346 }
340 pme->tb = tb; 347 pme->tb = tb;
341 pme->purr = purr; 348 pme->purr = purr;
342} 349}
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 07283aea2e56..4a4a34caec55 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -55,13 +55,19 @@ void account_process_tick(struct task_struct *tsk, int user_tick)
55 cputime = S390_lowcore.system_timer >> 12; 55 cputime = S390_lowcore.system_timer >> 12;
56 S390_lowcore.system_timer -= cputime << 12; 56 S390_lowcore.system_timer -= cputime << 12;
57 S390_lowcore.steal_clock -= cputime << 12; 57 S390_lowcore.steal_clock -= cputime << 12;
58 account_system_time(tsk, HARDIRQ_OFFSET, cputime, cputime); 58 if (idle_task(smp_processor_id()) != current)
59 account_system_time(tsk, HARDIRQ_OFFSET, cputime, cputime);
60 else
61 account_idle_time(cputime);
59 62
60 cputime = S390_lowcore.steal_clock; 63 cputime = S390_lowcore.steal_clock;
61 if ((__s64) cputime > 0) { 64 if ((__s64) cputime > 0) {
62 cputime >>= 12; 65 cputime >>= 12;
63 S390_lowcore.steal_clock -= cputime << 12; 66 S390_lowcore.steal_clock -= cputime << 12;
64 account_steal_time(tsk, cputime); 67 if (idle_task(smp_processor_id()) != current)
68 account_steal_time(cputime);
69 else
70 account_idle_time(cputime);
65 } 71 }
66} 72}
67 73
@@ -87,7 +93,10 @@ void account_vtime(struct task_struct *tsk)
87 cputime = S390_lowcore.system_timer >> 12; 93 cputime = S390_lowcore.system_timer >> 12;
88 S390_lowcore.system_timer -= cputime << 12; 94 S390_lowcore.system_timer -= cputime << 12;
89 S390_lowcore.steal_clock -= cputime << 12; 95 S390_lowcore.steal_clock -= cputime << 12;
90 account_system_time(tsk, 0, cputime, cputime); 96 if (idle_task(smp_processor_id()) != current)
97 account_system_time(tsk, 0, cputime, cputime);
98 else
99 account_idle_time(cputime);
91} 100}
92 101
93/* 102/*
@@ -107,7 +116,10 @@ void account_system_vtime(struct task_struct *tsk)
107 cputime = S390_lowcore.system_timer >> 12; 116 cputime = S390_lowcore.system_timer >> 12;
108 S390_lowcore.system_timer -= cputime << 12; 117 S390_lowcore.system_timer -= cputime << 12;
109 S390_lowcore.steal_clock -= cputime << 12; 118 S390_lowcore.steal_clock -= cputime << 12;
110 account_system_time(tsk, 0, cputime, cputime); 119 if (in_irq() || idle_task(smp_processor_id()) != current)
120 account_system_time(tsk, 0, cputime, cputime);
121 else
122 account_idle_time(cputime);
111} 123}
112EXPORT_SYMBOL_GPL(account_system_vtime); 124EXPORT_SYMBOL_GPL(account_system_vtime);
113 125
diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index c9f7cda48ed7..732e52dc991a 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -132,8 +132,7 @@ static void do_stolen_accounting(void)
132 *snap = state; 132 *snap = state;
133 133
134 /* Add the appropriate number of ticks of stolen time, 134 /* Add the appropriate number of ticks of stolen time,
135 including any left-overs from last time. Passing NULL to 135 including any left-overs from last time. */
136 account_steal_time accounts the time as stolen. */
137 stolen = runnable + offline + __get_cpu_var(residual_stolen); 136 stolen = runnable + offline + __get_cpu_var(residual_stolen);
138 137
139 if (stolen < 0) 138 if (stolen < 0)
@@ -141,11 +140,10 @@ static void do_stolen_accounting(void)
141 140
142 ticks = iter_div_u64_rem(stolen, NS_PER_TICK, &stolen); 141 ticks = iter_div_u64_rem(stolen, NS_PER_TICK, &stolen);
143 __get_cpu_var(residual_stolen) = stolen; 142 __get_cpu_var(residual_stolen) = stolen;
144 account_steal_time(NULL, ticks); 143 account_steal_ticks(ticks);
145 144
146 /* Add the appropriate number of ticks of blocked time, 145 /* Add the appropriate number of ticks of blocked time,
147 including any left-overs from last time. Passing idle to 146 including any left-overs from last time. */
148 account_steal_time accounts the time as idle/wait. */
149 blocked += __get_cpu_var(residual_blocked); 147 blocked += __get_cpu_var(residual_blocked);
150 148
151 if (blocked < 0) 149 if (blocked < 0)
@@ -153,7 +151,7 @@ static void do_stolen_accounting(void)
153 151
154 ticks = iter_div_u64_rem(blocked, NS_PER_TICK, &blocked); 152 ticks = iter_div_u64_rem(blocked, NS_PER_TICK, &blocked);
155 __get_cpu_var(residual_blocked) = blocked; 153 __get_cpu_var(residual_blocked) = blocked;
156 account_steal_time(idle_task(smp_processor_id()), ticks); 154 account_idle_ticks(ticks);
157} 155}
158 156
159/* 157/*