aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched/cputime.c
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2012-11-21 18:58:35 -0500
committerFrederic Weisbecker <fweisbec@gmail.com>2012-11-28 11:08:10 -0500
commitd37f761dbd276790f70dcf73a287fde2c3464482 (patch)
tree302d4bda699ab2e159b3a180f253019a38bf8132 /kernel/sched/cputime.c
parente80d0a1ae8bb8fee0edd37427836f108b30f596b (diff)
cputime: Consolidate cputime adjustment code
task_cputime_adjusted() and thread_group_cputime_adjusted() essentially share the same code. They just don't use the same source: * The first function uses the cputime in the task struct and the previous adjusted snapshot that ensures monotonicity. * The second adds the cputime of all tasks in the group and the previous adjusted snapshot of the whole group from the signal structure. Just consolidate the common code that does the adjustment. These functions just need to fetch the values from the appropriate source. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'kernel/sched/cputime.c')
-rw-r--r--kernel/sched/cputime.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 7dc155371b95..220fdc4db770 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -516,14 +516,18 @@ static cputime_t scale_utime(cputime_t utime, cputime_t rtime, cputime_t total)
516 return (__force cputime_t) temp; 516 return (__force cputime_t) temp;
517} 517}
518 518
519void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st) 519static void cputime_adjust(struct task_cputime *curr,
520 struct cputime *prev,
521 cputime_t *ut, cputime_t *st)
520{ 522{
521 cputime_t rtime, utime = p->utime, total = utime + p->stime; 523 cputime_t rtime, utime, total;
522 524
525 utime = curr->utime;
526 total = utime + curr->stime;
523 /* 527 /*
524 * Use CFS's precise accounting: 528 * Use CFS's precise accounting:
525 */ 529 */
526 rtime = nsecs_to_cputime(p->se.sum_exec_runtime); 530 rtime = nsecs_to_cputime(curr->sum_exec_runtime);
527 531
528 if (total) 532 if (total)
529 utime = scale_utime(utime, rtime, total); 533 utime = scale_utime(utime, rtime, total);
@@ -533,11 +537,22 @@ void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
533 /* 537 /*
534 * Compare with previous values, to keep monotonicity: 538 * Compare with previous values, to keep monotonicity:
535 */ 539 */
536 p->prev_utime = max(p->prev_utime, utime); 540 prev->utime = max(prev->utime, utime);
537 p->prev_stime = max(p->prev_stime, rtime - p->prev_utime); 541 prev->stime = max(prev->stime, rtime - prev->utime);
542
543 *ut = prev->utime;
544 *st = prev->stime;
545}
538 546
539 *ut = p->prev_utime; 547void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
540 *st = p->prev_stime; 548{
549 struct task_cputime cputime = {
550 .utime = p->utime,
551 .stime = p->stime,
552 .sum_exec_runtime = p->se.sum_exec_runtime,
553 };
554
555 cputime_adjust(&cputime, &p->prev_cputime, ut, st);
541} 556}
542 557
543/* 558/*
@@ -545,24 +560,9 @@ void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
545 */ 560 */
546void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st) 561void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st)
547{ 562{
548 struct signal_struct *sig = p->signal;
549 struct task_cputime cputime; 563 struct task_cputime cputime;
550 cputime_t rtime, utime, total;
551 564
552 thread_group_cputime(p, &cputime); 565 thread_group_cputime(p, &cputime);
553 566 cputime_adjust(&cputime, &p->signal->prev_cputime, ut, st);
554 total = cputime.utime + cputime.stime;
555 rtime = nsecs_to_cputime(cputime.sum_exec_runtime);
556
557 if (total)
558 utime = scale_utime(cputime.utime, rtime, total);
559 else
560 utime = rtime;
561
562 sig->prev_utime = max(sig->prev_utime, utime);
563 sig->prev_stime = max(sig->prev_stime, rtime - sig->prev_utime);
564
565 *ut = sig->prev_utime;
566 *st = sig->prev_stime;
567} 567}
568#endif 568#endif