Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make local apic actually local #499

Merged
merged 6 commits into from
Dec 31, 2024
Merged

Conversation

hawkw
Copy link
Owner

@hawkw hawkw commented Dec 31, 2024

No description provided.

This commit adds a `Deferred` utility to `mycelium-util` for making drop
guards. I wanted to use this to add a quick "`cli` at the top of a scope
and `sti` when exiting the scope" utility in the `hal-x86_64` interrupt
module.
As described in #495, each CPU core in a SMP x86 system has its own
local APIC. Currently, the mycelium HAL's interrupt code will just only
ever know about the boot processor's local APIC. This is wrong.

This commit reworks this to use the `%GS` local storage mechanism to
store the state of the local APIC separately for each CPU core. I've
added code for initializing the local APIC state on non-boot processors,
which we will call when we bring up other cores.

Fixes #495
Currently, we have some code for reading MSRs that emits a tracing event
for every `rdmsr` instruction you execute. This was a stupid thing to
do, and I only did it because I was being excessively cutesy. Now that
we read the `FS_GS_BASE` MSR in ISRs to access local data, this can
deadlock the kernel :upside_down:

So, this commit removes it.
1 Hz = 1 second. 1 ms = 1/1000 second. So we should multiply here
instead of dividing, lol.

The divide accidentally makes us consider the LAPIC frequency to be 0,
and then we just "don't ever have a timer". Whoopsie.
hawkw added a commit that referenced this pull request Dec 31, 2024
The current code for sleeping using the PIT one-shot timer has a bunch
of tracing in it. This adds overhead which makes the sleep duration way
less accurate, making PIT calibration for the local APIC timer way
sloppier. This commit removes the tracing. PIT calibration accuracy
still sucks, but it sucks less now.
@hawkw hawkw force-pushed the eliza/make-local-apic-actually-local branch from 671a09d to 94f8984 Compare December 31, 2024 20:06
@hawkw hawkw marked this pull request as ready for review December 31, 2024 20:06
@hawkw hawkw requested a review from iximeow December 31, 2024 20:06
@hawkw hawkw enabled auto-merge (rebase) December 31, 2024 20:06
This commit changes the local APIC calibration code to attempt PIT
calibration even when we find CPUID leaves indicating the frequency.
This way, we can cross-check them and see how sloppy the PIT calibration
is. It turns out its pretty bad.
hawkw added a commit that referenced this pull request Dec 31, 2024
The current code for sleeping using the PIT one-shot timer has a bunch
of tracing in it. This adds overhead which makes the sleep duration way
less accurate, making PIT calibration for the local APIC timer way
sloppier. This commit removes the tracing. PIT calibration accuracy
still sucks, but it sucks less now.
@hawkw hawkw force-pushed the eliza/make-local-apic-actually-local branch from 94f8984 to 4a9327f Compare December 31, 2024 20:07
The current code for sleeping using the PIT one-shot timer has a bunch
of tracing in it. This adds overhead which makes the sleep duration way
less accurate, making PIT calibration for the local APIC timer way
sloppier. This commit removes the tracing. PIT calibration accuracy
still sucks, but it sucks less now.
@hawkw hawkw force-pushed the eliza/make-local-apic-actually-local branch from 4a9327f to 8d51ac7 Compare December 31, 2024 20:08
@hawkw
Copy link
Owner Author

hawkw commented Dec 31, 2024

for the record, i knew that putting tracing in the PIT sleep functions would trash their accuracy when i wrote that code, but i did it anyway because we weren't actually using it for calibration at the time...

@hawkw hawkw merged commit e58cdd1 into main Dec 31, 2024
18 checks passed
@hawkw hawkw deleted the eliza/make-local-apic-actually-local branch December 31, 2024 20:29
hawkw added a commit that referenced this pull request Dec 31, 2024
This commit adds a `Deferred` utility to `mycelium-util` for making drop
guards. I wanted to use this to add a quick "`cli` at the top of a scope
and `sti` when exiting the scope" utility in the `hal-x86_64` interrupt
module.
hawkw added a commit that referenced this pull request Dec 31, 2024
As described in #495, each CPU core in a SMP x86 system has its own
local APIC. Currently, the mycelium HAL's interrupt code will just only
ever know about the boot processor's local APIC. This is wrong.

This commit reworks this to use the `%GS` local storage mechanism to
store the state of the local APIC separately for each CPU core. I've
added code for initializing the local APIC state on non-boot processors,
which we will call when we bring up other cores.

Fixes #495
hawkw added a commit that referenced this pull request Dec 31, 2024
Currently, we have some code for reading MSRs that emits a tracing event
for every `rdmsr` instruction you execute. This was a stupid thing to
do, and I only did it because I was being excessively cutesy. Now that
we read the `FS_GS_BASE` MSR in ISRs to access local data, this can
deadlock the kernel :upside_down:

So, this commit removes it.
hawkw added a commit that referenced this pull request Dec 31, 2024
1 Hz = 1 second. 1 ms = 1/1000 second. So we should multiply here
instead of dividing, lol.

The divide accidentally makes us consider the LAPIC frequency to be 0,
and then we just "don't ever have a timer". Whoopsie.
hawkw added a commit that referenced this pull request Dec 31, 2024
This commit changes the local APIC calibration code to attempt PIT
calibration even when we find CPUID leaves indicating the frequency.
This way, we can cross-check them and see how sloppy the PIT calibration
is. It turns out its pretty bad.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant