diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-09-06 16:51:57 +0200 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-09-06 16:51:57 +0200 |
commit | 7f79d852ed30a06eebf7497afe9334a726db3d40 (patch) | |
tree | 0057281f17501b635d3d88cda9a14203706f5dcc /kernel/sched.c | |
parent | aef745fca016aea45adae5c98e8698904dd8ad51 (diff) | |
parent | 70bb08962ea9bd50797ae9f16b2493f5f7c65053 (diff) | |
download | lwn-7f79d852ed30a06eebf7497afe9334a726db3d40.tar.gz lwn-7f79d852ed30a06eebf7497afe9334a726db3d40.zip |
Merge branch 'linus' into sched/devel
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index b112caaa400a..8626ae50ce08 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -4176,6 +4176,65 @@ void account_steal_time(struct task_struct *p, cputime_t steal) } /* + * Use precise platform statistics if available: + */ +#ifdef CONFIG_VIRT_CPU_ACCOUNTING +cputime_t task_utime(struct task_struct *p) +{ + return p->utime; +} + +cputime_t task_stime(struct task_struct *p) +{ + return p->stime; +} +#else +cputime_t task_utime(struct task_struct *p) +{ + clock_t utime = cputime_to_clock_t(p->utime), + total = utime + cputime_to_clock_t(p->stime); + u64 temp; + + /* + * Use CFS's precise accounting: + */ + temp = (u64)nsec_to_clock_t(p->se.sum_exec_runtime); + + if (total) { + temp *= utime; + do_div(temp, total); + } + utime = (clock_t)temp; + + p->prev_utime = max(p->prev_utime, clock_t_to_cputime(utime)); + return p->prev_utime; +} + +cputime_t task_stime(struct task_struct *p) +{ + clock_t stime; + + /* + * Use CFS's precise accounting. (we subtract utime from + * the total, to make sure the total observed by userspace + * grows monotonically - apps rely on that): + */ + stime = nsec_to_clock_t(p->se.sum_exec_runtime) - + cputime_to_clock_t(task_utime(p)); + + if (stime >= 0) + p->prev_stime = max(p->prev_stime, clock_t_to_cputime(stime)); + + return p->prev_stime; +} +#endif + +inline cputime_t task_gtime(struct task_struct *p) +{ + return p->gtime; +} + +/* * This function gets called by the timer code, with HZ frequency. * We call it with interrupts disabled. * |