Re: [PATCH] Hyper-V: fix for unwanted manipulation of sched_clock when TSC marked unstable

From: Peter Zijlstra
Date: Tue Jul 13 2021 - 09:18:44 EST


On Tue, Jul 13, 2021 at 01:04:46PM +0000, Wei Liu wrote:
> On Tue, Jul 13, 2021 at 08:35:21AM +0530, Ani Sinha wrote:
> > Marking TSC as unstable has a side effect of marking sched_clock as
> > unstable when TSC is still being used as the sched_clock. This is not
> > desirable. Hyper-V ultimately uses a paravirtualized clock source that
> > provides a stable scheduler clock even on systems without TscInvariant
> > CPU capability. Hence, mark_tsc_unstable() call should be called _after_
> > scheduler clock has been changed to the paravirtualized clocksource. This
> > will prevent any unwanted manipulation of the sched_clock. Only TSC will
> > be correctly marked as unstable.
>
> Correct me if I'm wrong, what you're trying to address is that
> sched_clock remains marked as unstable even after Linux has switched to
> a stable clock source.
>
> I think a better approach will be to mark the sched_clock as stable when
> we switch to the paravirtualized clock source.

No.. unstable->stable transitions are unsound. You get to switch to your
paravirt clock earlier.