sched: fix user time incorrectly accounted as system time on 32 bit
PATCH v2 1/1 sched: fix user time incorrectly accounted as system time on 32 bit
We have 32 bit variable overflow possibility when multiply in task_times() and thread_group_times() functions. If overflow happens calculated scaled utime value become wrongly small and scaled stime wrongly big.
Reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=633037
https://bugzilla.kernel.org/show_bug.cgi?id=16559
---
v1 -> v2
Fix mail recipients.
kernel/sched.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
kernel/sched.c +4 -4
@@ -3507,9 +3507,9 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st) rtime =nsecs_to_cputime (p->se.sum_exec_runtime);if (total) { -u64 temp; +u64 temp = rtime; - temp = (u64)(rtime * utime); + temp *= utime;do_div (temp, total); utime = (cputime_t )temp; }else
@@ -3540,9 +3540,9 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st) rtime =nsecs_to_cputime (cputime.sum_exec_runtime);if (total) { -u64 temp; +u64 temp = rtime; - temp = (u64)(rtime * cputime.utime); + temp *= cputime.utime;do_div (temp, total); utime = (cputime_t )temp; }else
Signature · 1 line
1.7.1
Quoted 4 lines · Stanislaw Gruszka
We have 32 bit variable overflow possibility when multiply in
task_times()andthread_group_times()functions. If overflow happens calculated scaled utime value become wrongly small and scaled stime wrongly big.
Ah, right, (u64)foo * bar would have worked too I guess, but yeah, the used (u64)(foo * bar) is wrong.
Quoted 10 lines
Reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=633037
https://bugzilla.kernel.org/show_bug.cgi?id=16559Reported-by Michael Chapman <[email protected]>Reported-by Ciriaco Garcia de Celis <[email protected]>Cc Hidetoshi Seto <[email protected]>Cc Peter Zijlstra <[email protected]>Cc <[email protected]> # 2.6.32.19+ (partially) and 2.6.33+Signed-off-by Stanislaw Gruszka <[email protected]>
Thanks, got it.
[tip:sched/urgent] sched: Fix user time incorrectly accounted as system time on 32-bit
In reply to Stanislaw GruszkaCommit-ID: e75e863dd5c7d96b91ebbd241da5328fc38a78cc Gitweb: http://git.kernel.org/tip/e75e863dd5c7d96b91ebbd241da5328fc38a78cc Author: Stanislaw Gruszka <[email protected]> AuthorDate: Tue, 14 Sep 2010 16:35:14 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 15 Sep 2010 10:41:36 +0200
sched: Fix user time incorrectly accounted as system time on 32-bit
We have 32-bit variable overflow possibility when multiply in task_times() and thread_group_times() functions. When the overflow happens then the scaled utime value becomes erroneously small and the scaled stime becomes i erroneously big.
Reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=633037
https://bugzilla.kernel.org/show_bug.cgi?id=16559
LKML-Reference: <[email protected]>
--- kernel/sched.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
kernel/sched.c +4 -4
@@ -3513,9 +3513,9 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st) rtime =nsecs_to_cputime (p->se.sum_exec_runtime);if (total) { -u64 temp; +u64 temp = rtime; - temp = (u64)(rtime * utime); + temp *= utime;do_div (temp, total); utime = (cputime_t )temp; }else
@@ -3546,9 +3546,9 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st) rtime =nsecs_to_cputime (cputime.sum_exec_runtime);if (total) { -u64 temp; +u64 temp = rtime; - temp = (u64)(rtime * cputime.utime); + temp *= cputime.utime;do_div (temp, total); utime = (cputime_t )temp; }else