Repository navigation
feat(cpu): switch between ring-0 contexts, saving their extended state with the strongest XSAVE the processor offers - #806
Merged
MasterLaplace merged 12 commits intoNov 9, 2026
Conversation
…itch that saves no extended state yet
…e with the strongest XSAVE the processor offers
…nt takes the XSAVE path
# Conflicts: # kernel/arch/i386/cpu/extended_state.c # kernel/include/kernel/cpu/extended_state.h
…the registers saved there
… say when a context's entry returns
…ly, and share the probe's layout with its assembly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
cpu_context_switch(from, to)switches between two ring-0 contexts on one processor. It saves EBP, EBX, ESI, EDI, the stack pointer and the extended state.cpu_context_switch: every switch saves eagerly, never lazily through CR0.TS (LazyFP). A context that never touched its vector registers costs only the header.extended_state_preferred_savetakes the SDM's order: XSAVES, then XSAVEOPT, then XSAVE. FXSAVE is offered only while XCR0 enables nothing past SSE.cpu_context_preparestarts a context at its entry, from the initial state, on a 16-byte-aligned stack. An entry that returns is reported on COM1, then its processor halts.cpu_context_adoptmakes the running code a context. It ends with an XRSTOR of empty mask, so any area may be adopted, even the one the processor last restored from.tools/instructions.sh --cpunames QEMU's processor model, so a budget can count the XSAVE path.Specification: said, says, because
#85's criterion said "a test preempts a task". It now says a context finds its registers after another context ran, because no task exists yet; preemption moves to #259.
Verify
./build.sh --server, thenqemu-system-i386 -machine q35 -m 1G -smp 2 -kernel kernel/lpl.kernel -append lpl.test=context_switch.*, with-cpu maxor-accel kvm -cpu host:-cpu max871/0 with 2 and 4 processors, KVM 871/0, pc 862/0, KVM pc with 4 processors 864/0. Satellite:-cpu max721/0, KVM pc 714/0.context-switch.debug.budget: 58,852 instructions for 1,000 switches. Server tick unchanged.Not in it
Stacked on #805. Refs #85