Stage MC-0a: per-core block on one core -- current VM moves behind the per-CPU register (FABRIC-3.10.8 §3.1)

- New sk_percpu_t { self, core_id, current_vm }, reached via GS base
  (amd64, %gs:0), TPIDR_EL1 (aarch64), tp (riscv64). Boot core's block is
  one static object installed right after arch_early_init(); secondary
  cores' blocks come with MC-1.
- switch.c's global g_switch_current_vm is gone; current VM is
  sk_percpu()->current_vm, re-read after resume in the context switch.
- Probe (removed): normal path and every heartbeat ISR found core 0's
  block on all three ISAs (ISR ok 889/1877/1625, bad 0).
- Standard sequence on amd64/aarch64/riscv64: hashes unchanged from O-C,
  G A=40 B=40, MINT/WIREBIND/USE ok, conservation true, 0 idle growth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Robert Allan James
2026-09-25 13:56:48 -04:00
co-authored by Claude Opus 5.5
parent 8d33f7a959
commit 8409e376cf
17 changed files with 55013 additions and 8 deletions
+13 -7
View File
@@ -34,6 +34,7 @@
#include "starkernel/hal/hal.h" /* sk_hal_panic() */
#include "starkernel/capsule_vm_switch_signal.h" /* FABRIC-3.8.md §3.13.3 -- the decision */
#include "starkernel/vm/bootstrap/sk_vm_bootstrap.h" /* sk_get_mama_vm() -- the idle root */
#include "starkernel/percpu.h" /* FABRIC-3.10.8 MC-0a -- this core's current VM */
#include <stdint.h>
/* Arch-specific (switch.S in each arch dir). sk_vm_switch_prime() builds
@@ -70,11 +71,14 @@ static VM *g_switch_entry_vm;
* Seeded once at boot via sk_vm_switch_set_current() for whichever VM is
* running before any switch has ever happened (Hera, at Stage 3
* registration time -- kernel_main.c). */
static VM *g_switch_current_vm;
/* FABRIC-3.10.8 Stage MC-0a: "who is running" is per core now, held in this
* core's per-core block (starkernel/percpu.h) instead of the file-scope
* global g_switch_current_vm this comment used to describe. Same semantics
* on one core; with more, each core answers for itself. */
VM *sk_vm_switch_current_vm(void) { return g_switch_current_vm; }
VM *sk_vm_switch_current_vm(void) { return sk_percpu()->current_vm; }
void sk_vm_switch_set_current(VM *vm) { g_switch_current_vm = vm; }
void sk_vm_switch_set_current(VM *vm) { sk_percpu()->current_vm = vm; }
/**
* sk_vm_switch_entry - trampoline for a VM's first-ever entry.
@@ -219,7 +223,7 @@ void sk_vm_switch_checkpoint(VM *vm) {
* mail or pending console input, or is returned to by a trampoline with
* nothing left to do. */
void sk_vm_idle_point(int may_drain_self) {
VM *self = g_switch_current_vm;
VM *self = sk_percpu()->current_vm;
VM *next;
if (!self || self != (VM *)sk_get_mama_vm()) return;
@@ -274,14 +278,16 @@ int sk_vm_context_switch(VM *from, VM *to) {
capsule_vm_set_state(to->stadium_vm_id, VM_STATE_LIVE);
capsule_vm_set_state(from->stadium_vm_id, VM_STATE_SWITCHED_OUT);
sk_vm_switch_signal_note_parked(from->stadium_vm_id); /* §3.13.3 wait stamp */
g_switch_current_vm = to;
sk_percpu()->current_vm = to;
sk_vm_switch_to(&from->native_stack_saved_sp, new_sp);
/* Resumes here only once something later switches back to `from` --
* from `from`'s own point of view, this call simply took a while. */
* from `from`'s own point of view, this call simply took a while.
* sk_percpu() is read fresh here, not cached from before the switch:
* once workers migrate (MC-3), `from` may resume on a different core. */
capsule_vm_set_state(from->stadium_vm_id, VM_STATE_LIVE);
g_switch_current_vm = from;
sk_percpu()->current_vm = from;
return 0;
}