Re: [PATCH] tick/nohz: Fix wrong user and system time accouting against vtime sampling

From: Rik van Riel
Date: Thu Apr 06 2017 - 10:36:25 EST


On Wed, 2017-04-05 at 23:36 -0700, Wanpeng Li wrote:

> This patch offsets the tick to avert all ticks alignment in orderÂ
> that the vtime sampling does not end up "in phase" with the jiffiesÂ
> incrementing.
>
> Reported-by: Luiz Capitulino <lcapitulino@xxxxxxxxxx>
> Suggested-by: Rik van Riel <riel@xxxxxxxxxx>
> Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
> Cc: Rik van Riel <riel@xxxxxxxxxx>
> Cc: Mike Galbraith <efault@xxxxxx>
> Cc: Luiz Capitulino <lcapitulino@xxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Wanpeng Li <wanpeng.li@xxxxxxxxxxx>

Reviewed-by: Rik van Riel <riel@xxxxxxxxxx>

> +++ b/kernel/time/tick-sched.c
> @@ -1197,8 +1197,12 @@ void tick_setup_sched_timer(void)
> Â /* Get the next period (per-CPU) */
> Â hrtimer_set_expires(&ts->sched_timer,
> tick_init_jiffy_update());
> Â
> - /* Offset the tick to avert jiffies_lock contention. */
> - if (sched_skew_tick) {
> + /*
> + Â* Offset the tick to avert jiffies_lock contention, and all
> ticks
> + Â* alignment in order that the vtime sampling does not end
> up "in
> + Â* phase" with the jiffies incrementing.
> + Â*/

I feel like part of the explanation is missing from this
comment, but I am not sure how to make it better without
making it way too long :)

> + if (sched_skew_tick || tick_nohz_full_enabled()) {
> Â u64 offset = ktime_to_ns(tick_period) >> 1;
> Â do_div(offset, num_possible_cpus());
> Â offset *= smp_processor_id();