Re: [PATCH] sched/cputime: Fix using smp_processor_id() in preemptible
From: Peter Zijlstra
Date: Fri Jul 07 2017 - 04:12:03 EST
On Thu, Jul 06, 2017 at 08:18:41PM -0700, Wanpeng Li wrote:
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -683,7 +683,7 @@ static u64 vtime_delta(struct vtime *vtime)
> {
> unsigned long long clock;
>
> - clock = sched_clock_cpu(smp_processor_id());
> + clock = sched_clock();
> if (clock < vtime->starttime)
> return 0;
>
This is broken. sched_clock_cpu() and sched_clock() do not have the
exact same value :-/
So this ends up doing:
vtime->starttime = sched_clock_cpu(cpu);
/* ... */
clock = sched_clock();
delta = clock - vtime->starttime;
And you compute a delta using two different clocks.