Skip to content

Commit 173be9a

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/cputime: Fix NO_HZ_FULL getrusage() monotonicity regression
Mike reports: Roughly 10% of the time, ltp testcase getrusage04 fails: getrusage04 0 TINFO : Expected timers granularity is 4000 us getrusage04 0 TINFO : Using 1 as multiply factor for max [us]time increment (1000+4000us)! getrusage04 0 TINFO : utime: 0us; stime: 179us getrusage04 0 TINFO : utime: 3751us; stime: 0us getrusage04 1 TFAIL : getrusage04.c:133: stime increased > 5000us: And tracked it down to the case where the task simply doesn't get _any_ [us]time ticks. Update the code to assume all rtime is utime when we lack information, thus ensuring a task that elides the tick gets time accounted. Reported-by: Mike Galbraith <umgwanakikbuti@gmail.com> Tested-by: Mike Galbraith <umgwanakikbuti@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Fredrik Markstrom <fredrik.markstrom@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Radim <rkrcmar@redhat.com> Cc: Rik van Riel <riel@redhat.com> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Cc: Wanpeng Li <wanpeng.li@hotmail.com> Cc: stable@vger.kernel.org # 4.3+ Fixes: 9d7fb04 ("sched/cputime: Guarantee stime + utime == rtime") Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3684b03 commit 173be9a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/sched/cputime.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,19 +614,25 @@ static void cputime_adjust(struct task_cputime *curr,
614614
stime = curr->stime;
615615
utime = curr->utime;
616616

617-
if (utime == 0) {
618-
stime = rtime;
617+
/*
618+
* If either stime or both stime and utime are 0, assume all runtime is
619+
* userspace. Once a task gets some ticks, the monotonicy code at
620+
* 'update' will ensure things converge to the observed ratio.
621+
*/
622+
if (stime == 0) {
623+
utime = rtime;
619624
goto update;
620625
}
621626

622-
if (stime == 0) {
623-
utime = rtime;
627+
if (utime == 0) {
628+
stime = rtime;
624629
goto update;
625630
}
626631

627632
stime = scale_stime((__force u64)stime, (__force u64)rtime,
628633
(__force u64)(stime + utime));
629634

635+
update:
630636
/*
631637
* Make sure stime doesn't go backwards; this preserves monotonicity
632638
* for utime because rtime is monotonic.
@@ -649,7 +655,6 @@ static void cputime_adjust(struct task_cputime *curr,
649655
stime = rtime - utime;
650656
}
651657

652-
update:
653658
prev->stime = stime;
654659
prev->utime = utime;
655660
out:

0 commit comments

Comments
 (0)