Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Weird clock behaviour with current (amd64) kernel



On Sun, Aug 14, 2022 at 02:38:07AM +0700, Robert Elz wrote:
>     Date:        Sat, 13 Aug 2022 17:41:05 +0200
>     From:        Michael van Elst <mlelstv%serpens.de@localhost>
>     Message-ID:  <YvfGEXBuss872Fwl%serpens.de@localhost>
> 
>   | If you boot the kernel in debug mode (netbsd -x),
> 
> I did.
> 
>   | you may see output like:
> 
> which was:
> 
> [     1.000003] cpu0: TSC freq CPUID 3417600000 Hz
> [     1.000003] cpu0: TSC freq from CPUID 3417600000 Hz
> [     1.064451] xhci0: hcc2=0x1fd<ETC_TSC,ETC,CIC,LEC,CTC,FSC,U3C>
> [     1.064451] xhci3: hcc2=0xfd<ETC_TSC,ETC,CIC,LEC,CTC,FSC,U3C>
> [     1.064451] cpu0: TSC freq from HPET 9007294000 Hz
> [     1.064451] cpu0: TSC freq CPUID 3417600000 Hz
> [     1.064451] cpu0: TSC freq calibrated 9007294000 Hz


So it's the HPET calibration that goes wrong.


The calibration works like:

Fetch hpet and tsc at attach time.

        (void)cpu_counter();
        val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_MCOUNT_LO);
        hpet_attach_tsc = cpu_counter();
        hpet_attach_val = val;


When calibtrating, make sure that hpet has counted for at
least 0.1 seconds:

        hd = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_MCOUNT_LO);
        hd -= hpet_attach_val;
        if (hd < (uint64_t)100000 * 1000000000 / sc->sc_period)
                hpet_delay(100000);


Fetch hpet and tsc again

        s = splhigh();
        (void)cpu_counter();
        hd = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_MCOUNT_LO);
        td = cpu_counter();
        splx(s);


Compute tsc frequency from hpet frequency.

        hd -= hpet_attach_val;
        val = ((uint64_t)hd * sc->sc_period - sc->sc_adj) / 100000000;
        freq = (td - hpet_attach_tsc) * 10000000 / val;
        return rounddown(freq + 500, 1000);


In your case, you say it takes ~6 minutes between attachment and
calibration and your hpet runs at 19.2MHz.

This is enough for HPET_MCOUNT_LO to overflow.


Greetings,
-- 
                                Michael van Elst
Internet: mlelstv%serpens.de@localhost
                                "A potential Snark may lurk in every tree."



Home | Main Index | Thread Index | Old Index