aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
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 */