Skip to content

Commit f9c904b

Browse files
cbf123Ingo Molnar
authored andcommitted
sched/cputime: Fix steal_account_process_tick() to always return jiffies
The callers of steal_account_process_tick() expect it to return whether a jiffy should be considered stolen or not. Currently the return value of steal_account_process_tick() is in units of cputime, which vary between either jiffies or nsecs depending on CONFIG_VIRT_CPU_ACCOUNTING_GEN. If cputime has nsecs granularity and there is a tiny amount of stolen time (a few nsecs, say) then we will consider the entire tick stolen and will not account the tick on user/system/idle, causing /proc/stats to show invalid data. The fix is to change steal_account_process_tick() to accumulate the stolen time and only account it once it's worth a jiffy. (Thanks to Frederic Weisbecker for suggestions to fix a bug in my first version of the patch.) Signed-off-by: Chris Friesen <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 72f9f3f commit f9c904b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

kernel/sched/cputime.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,21 @@ static __always_inline bool steal_account_process_tick(void)
262262
#ifdef CONFIG_PARAVIRT
263263
if (static_key_false(&paravirt_steal_enabled)) {
264264
u64 steal;
265-
cputime_t steal_ct;
265+
unsigned long steal_jiffies;
266266

267267
steal = paravirt_steal_clock(smp_processor_id());
268268
steal -= this_rq()->prev_steal_time;
269269

270270
/*
271-
* cputime_t may be less precise than nsecs (eg: if it's
272-
* based on jiffies). Lets cast the result to cputime
271+
* steal is in nsecs but our caller is expecting steal
272+
* time in jiffies. Lets cast the result to jiffies
273273
* granularity and account the rest on the next rounds.
274274
*/
275-
steal_ct = nsecs_to_cputime(steal);
276-
this_rq()->prev_steal_time += cputime_to_nsecs(steal_ct);
275+
steal_jiffies = nsecs_to_jiffies(steal);
276+
this_rq()->prev_steal_time += jiffies_to_nsecs(steal_jiffies);
277277

278-
account_steal_time(steal_ct);
279-
return steal_ct;
278+
account_steal_time(jiffies_to_cputime(steal_jiffies));
279+
return steal_jiffies;
280280
}
281281
#endif
282282
return false;

0 commit comments

Comments
 (0)