Re: [PATCH v2 1/1] arm64: Early boot time stamps

From: Pavel Tatashin
Date: Wed Dec 05 2018 - 11:02:07 EST


On 18-11-22 14:14:29, Marc Zyngier wrote:
> On Wed, 21 Nov 2018 17:58:41 +0000,
> Pavel Tatashin <pasha.tatashin@xxxxxxxxxx> wrote:
> >
> > On 18-11-21 17:47:07, Will Deacon wrote:
> > > > + /*
> > > > + * The arm64 boot protocol mandates that CNTFRQ_EL0 reflects
> > > > + * the timer frequency. To avoid breakage on misconfigured
> > > > + * systems, do not register the early sched_clock if the
> > > > + * programmed value if zero. Other random values will just
> > > > + * result in random output.
> > > > + */
> > > > + if (!freq)
> > > > + return;
> > > > +
> > > > + arch_timer_read_counter = arch_counter_get_cntvct;
> > >
> > > Why do you need to assign this here?
> > >
> > > > + sched_clock_register(arch_timer_read_counter, ARCH_TIMER_NBITS, freq);
> > >
> > > arch_timer_read_counter can be reassigned once the arm_arch_timer driver
> > > has probed; what stops this from being unused as the sched_clock after that
> > > has happened? I worry that toggling the function pointer could lead to
> > > sched_clock() going backwards.
> >
> > No reason, I will revert it back to use a local variable.
>
> I think the issue is that you are doing an assignment for something
> that the kernel has already statically initialized.
>
> > I agree, time can go backward for a period of time while we switch
> > to permanent clock later, if that clock is different.
>
> It is worse than that. You're setting up sched_clock with an
> unreliable clock source which can go backward at any point, not just
> at handover time.
>
> I'd rather we have the timestamping code be able to use another souce
> than sched_clock, and eventually switch to it once sched_clock is
> registered (and properly corrected.

Hi Marc,

The early sched clock is implemented the same way on SPARC and x86: it
uses the sched_clock() interface to get timestamps. In addition it can
be used be engineers to precisely measure and debug early boot problems
by directly inserting cheap sched_clock() calls into code. Ftrace might
also be extended in future to support early boot.

I am not sure it is a good idea to invent a different interface that
would be used by printk() only for timestamping early in boot.

During the hang over from unstable to stable the sched_clock_register()
does the right thing and calculates the offset where the last clock
ended and new started.

In unlikely even if on some broken chips time goes backward, it will
happen during early boot only. Do you know if there are arm64 chips
exist where time may go backward? We can either don't do early boot
clock on those chips, or modify sched_clock() to check for the last
return value, and make sure that it is always smaller than the new
return value.

Thank you,
Pasha