Re: [PATCH] x86/apic: Handle missing global clockevent gracefully
From: Thomas Gleixner
Date: Mon Aug 12 2019 - 13:11:38 EST
On Mon, 12 Aug 2019, Aubrey Li wrote:
> On Mon, Aug 12, 2019 at 8:25 PM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> >
> > On Mon, 12 Aug 2019, Li, Aubrey wrote:
> > > On 2019/8/9 20:54, Thomas Gleixner wrote:
> > > > + local_irq_disable();
> > > > /*
> > > > * Setup the APIC counter to maximum. There is no way the lapic
> > > > * can underflow in the 100ms detection time frame
> > > > */
> > > > __setup_APIC_LVTT(0xffffffff, 0, 0);
> > > >
> > > > - /* Let the interrupts run */
> > > > - local_irq_enable();
> > > > + /*
> > > > + * Methods to terminate the calibration loop:
> > > > + * 1) Global clockevent if available (jiffies)
> > > > + * 2) TSC if available and frequency is known
> > > > + */
> > > > + jif_start = READ_ONCE(jiffies);
> > > > +
> > > > + if (tsc_khz) {
> > > > + tsc_start = rdtsc();
> > > > + tsc_perj = div_u64((u64)tsc_khz * 1000, HZ);
> > > > + }
> > > > +
> > > > + while (lapic_cal_loops <= LAPIC_CAL_LOOPS) {
> > >
> > > Is this loop still meaningful, can we just invoke the handler twice
> > > before and after the tick?
> >
> > And that solves what?
> >
> I meant, can we do this one time?
> - lapic_cal_t1 = read APIC counter
> - /* Wait for a tick to elapse */
> - lapic_cal_t2 = read APIC counter
Sure, but how does this work with randomly broken hardware, e.g. PIT
running at the wrong frequency/
The calibration code is trying to verify against as many and as reliable
references and it served us well so far.
> I'm not clear why we still need this loop, to use the
> existing lapic_cal_handler()?
A single tick is way too small to get a proper calibration. Sure, this can
be optimized by avoiding the loop and have a longer delay, but you
definitely want to use the rest of the calibration code as is.
Aside of that this was the minial fix I came up with which might be
suitable for backporting. These platforms seem to come out of the woods
right now, so we definitely want support for them in LTS kernels as well.
Thanks,
tglx