Skip to content

Commit 9a6963e

Browse files
cbf123Dinh Nguyen
authored andcommitted
sched/cputime: Fix steal_account_process_tick() to always return jiffies
[ Upstream commit f9c904b ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 035ddec commit 9a6963e

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
@@ -259,21 +259,21 @@ static __always_inline bool steal_account_process_tick(void)
259259
#ifdef CONFIG_PARAVIRT
260260
if (static_key_false(&paravirt_steal_enabled)) {
261261
u64 steal;
262-
cputime_t steal_ct;
262+
unsigned long steal_jiffies;
263263

264264
steal = paravirt_steal_clock(smp_processor_id());
265265
steal -= this_rq()->prev_steal_time;
266266

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

275-
account_steal_time(steal_ct);
276-
return steal_ct;
275+
account_steal_time(jiffies_to_cputime(steal_jiffies));
276+
return steal_jiffies;
277277
}
278278
#endif
279279
return false;

0 commit comments

Comments
 (0)