Page MenuHomeFreeBSD

x86: Defer LAPIC calibration until after timecounters are available
ClosedPublic

Authored by markj on Nov 30 2021, 10:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 8 2024, 12:04 AM
Unknown Object (File)
Feb 7 2024, 1:12 AM
Unknown Object (File)
Jan 30 2024, 12:22 AM
Unknown Object (File)
Jan 25 2024, 2:57 PM
Unknown Object (File)
Jan 25 2024, 2:57 PM
Unknown Object (File)
Jan 25 2024, 2:57 PM
Unknown Object (File)
Dec 12 2023, 2:58 PM
Unknown Object (File)
Dec 8 2023, 2:49 AM
Subscribers
None

Details

Summary

This ensures that we have a good reference timecounter for performing
calibration.

Change lapic_setup to avoid configuring the timer when booting, and move
calibration and initial configuration to a new lapic routine,
lapic_calibrate_timer. This calibration will be initiated from
cpu_initclocks(), before an eventtimer is selected.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj created this revision.
markj added a parent revision: D33205: x86: Deduplicate clock.h.

Is Colin going to work on refining the actual calibration to not always take a full second? At the very least the calibration should probably be using sbinuptime() as the TSC calibration does instead of assuming the DELAY() waits exactly for a second. Seems sensible to refine the calibration in a separate commit though.

This revision is now accepted and ready to land.Nov 30 2021, 10:52 PM

Yes, I asked Mark to get this into the tree first so I could handle the TSC and LAPIC calibration at the same time.

In D33206#750402, @jhb wrote:

At the very least the calibration should probably be using sbinuptime() as the TSC calibration does instead of assuming the DELAY() waits exactly for a second.

Note that the next patch removes the use of sbinuptime(), since at SI_SUB_CLOCKS/SI_ORDER_FIRST we don't have usable timehands.

sys/x86/x86/local_apic.c
357

Not sure why this line is being deleted?

markj marked an inline comment as done.

Restore a lost comment.

This revision now requires review to proceed.Nov 30 2021, 11:35 PM
sys/x86/x86/local_apic.c
1008

I still want to see the herald line when we use deadline mode, in bootverbose dmesg.

1018–1019

Unless I misread the change, this function (and corresponding switch) is now only executed for BSP, while before it was performed for each CPU. This is perhaps fine, because lapic_et_start() would do whatever is needed to ignite the timecounter.

But then, do we need lapic_setup_timer() at all?

markj marked 2 inline comments as done.
  • Don't bother with timer setup during boot.
  • Restore a bootverbose message.
sys/x86/x86/local_apic.c
1018–1019

Hmm, I think calibrate_timer() does not need to call lapic_setup_timer() at all, indeed. Note that without the change, the body of lapic_setup_timer() is not executed at all during boot, as the timer mode is not yet initialized. (It was implicitly set to LAT_MODE_UNDEF before, and this change makes the initialization explicit.) The mode is UNDEF until the timer is started, and that will happen after calibration. So I can remove lapic_setup_timer() and restore the inline implementation in native_lapic_setup().

kib added inline comments.
sys/x86/x86/local_apic.c
925

I suggest to move intr_restore() right after lapic_calibrate_initcount().

This revision is now accepted and ready to land.Dec 1 2021, 1:26 PM
markj marked an inline comment as done.

Move a verbose printf out of an interrupts-disabled section.

This revision now requires review to proceed.Dec 1 2021, 1:59 PM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 6 2021, 4:23 PM
This revision was automatically updated to reflect the committed changes.