aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
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 /kernel/sched.c
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 'kernel/sched.c')
-rw-r--r--kernel/sched.c80
1 files changed, 63 insertions, 17 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 5b03679ff712..635eaffe1e4c 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4139,7 +4139,6 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
4139 cputime_t cputime, cputime_t cputime_scaled) 4139 cputime_t cputime, cputime_t cputime_scaled)
4140{ 4140{
4141 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; 4141 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
4142 struct rq *rq = this_rq();
4143 cputime64_t tmp; 4142 cputime64_t tmp;
4144 4143
4145 if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) { 4144 if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
@@ -4158,37 +4157,84 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
4158 cpustat->irq = cputime64_add(cpustat->irq, tmp); 4157 cpustat->irq = cputime64_add(cpustat->irq, tmp);
4159 else if (softirq_count()) 4158 else if (softirq_count())
4160 cpustat->softirq = cputime64_add(cpustat->softirq, tmp); 4159 cpustat->softirq = cputime64_add(cpustat->softirq, tmp);
4161 else if (p != rq->idle)
4162 cpustat->system = cputime64_add(cpustat->system, tmp);
4163 else if (atomic_read(&rq->nr_iowait) > 0)
4164 cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
4165 else 4160 else
4166 cpustat->idle = cputime64_add(cpustat->idle, tmp); 4161 cpustat->system = cputime64_add(cpustat->system, tmp);
4162
4167 /* Account for system time used */ 4163 /* Account for system time used */
4168 acct_update_integrals(p); 4164 acct_update_integrals(p);
4169} 4165}
4170 4166
4171/* 4167/*
4172 * Account for involuntary wait time. 4168 * Account for involuntary wait time.
4173 * @p: the process from which the cpu time has been stolen
4174 * @steal: the cpu time spent in involuntary wait 4169 * @steal: the cpu time spent in involuntary wait
4175 */ 4170 */
4176void account_steal_time(struct task_struct *p, cputime_t steal) 4171void account_steal_time(cputime_t cputime)
4172{
4173 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
4174 cputime64_t cputime64 = cputime_to_cputime64(cputime);
4175
4176 cpustat->steal = cputime64_add(cpustat->steal, cputime64);
4177}
4178
4179/*
4180 * Account for idle time.
4181 * @cputime: the cpu time spent in idle wait
4182 */
4183void account_idle_time(cputime_t cputime)
4177{ 4184{
4178 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; 4185 struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
4179 cputime64_t tmp = cputime_to_cputime64(steal); 4186 cputime64_t cputime64 = cputime_to_cputime64(cputime);
4180 struct rq *rq = this_rq(); 4187 struct rq *rq = this_rq();
4181 4188
4182 if (p == rq->idle) { 4189 if (atomic_read(&rq->nr_iowait) > 0)
4183 p->stime = cputime_add(p->stime, steal); 4190 cpustat->iowait = cputime64_add(cpustat->iowait, cputime64);
4184 if (atomic_read(&rq->nr_iowait) > 0) 4191 else
4185 cpustat->iowait = cputime64_add(cpustat->iowait, tmp); 4192 cpustat->idle = cputime64_add(cpustat->idle, cputime64);
4186 else 4193}
4187 cpustat->idle = cputime64_add(cpustat->idle, tmp); 4194
4188 } else 4195#ifndef CONFIG_VIRT_CPU_ACCOUNTING
4189 cpustat->steal = cputime64_add(cpustat->steal, tmp); 4196
4197/*
4198 * Account a single tick of cpu time.
4199 * @p: the process that the cpu time gets accounted to
4200 * @user_tick: indicates if the tick is a user or a system tick
4201 */
4202void account_process_tick(struct task_struct *p, int user_tick)
4203{
4204 cputime_t one_jiffy = jiffies_to_cputime(1);
4205 cputime_t one_jiffy_scaled = cputime_to_scaled(one_jiffy);
4206 struct rq *rq = this_rq();
4207
4208 if (user_tick)
4209 account_user_time(p, one_jiffy, one_jiffy_scaled);
4210 else if (p != rq->idle)
4211 account_system_time(p, HARDIRQ_OFFSET, one_jiffy,
4212 one_jiffy_scaled);
4213 else
4214 account_idle_time(one_jiffy);
4215}
4216
4217/*
4218 * Account multiple ticks of steal time.
4219 * @p: the process from which the cpu time has been stolen
4220 * @ticks: number of stolen ticks
4221 */
4222void account_steal_ticks(unsigned long ticks)
4223{
4224 account_steal_time(jiffies_to_cputime(ticks));
4225}
4226
4227/*
4228 * Account multiple ticks of idle time.
4229 * @ticks: number of stolen ticks
4230 */
4231void account_idle_ticks(unsigned long ticks)
4232{
4233 account_idle_time(jiffies_to_cputime(ticks));
4190} 4234}
4191 4235
4236#endif
4237
4192/* 4238/*
4193 * Use precise platform statistics if available: 4239 * Use precise platform statistics if available:
4194 */ 4240 */