Files
carlos 5bb9e04fda kernel: opt-in one-CPU DISPATCH gate, IRQs at safe points, 60 Hz vblank
On the console one CPU runs everything, and titles build their locks on
it: a thread at DISPATCH_LEVEL keeps every DPC and every other thread out,
and an interrupt preempts whatever runs and returns to it. Here threads
run in parallel and IRQL is only a number, so a DPC walked a list a thread
was relinking at DISPATCH and looped there, and an ISR ran beside the code
it should have frozen.

Everything below is opt-in. With none of the keys set the kernel behaves
as v0.14.0 does, RECOMP_VBLANK=1 included.

- RECOMP_DISPATCH_GATE=1: the raise to DISPATCH_LEVEL takes one
  process-wide gate and the lower gives it back. Queued DPCs run on the
  guest thread at its raise and at its release point, under the gate
  (RECOMP_DPC_ON_RAISE=0 leaves them to the timer thread). Device
  interrupts (APU, OHCI, vblank) are posted while the gate is held and run
  by the holder at its next safe point: a kernel call or a gate release
  (RECOMP_IRQ_SAFE_POINTS=0 brings back the bounded hold-off, keyed on the
  gate; RECOMP_IRQ_SAFE_FORCE / _MS bound how long a post may wait). A
  timer's DPC runs on the timer thread only while the gate is free and is
  queued otherwise. The configuration is read once (INIT_ONCE), since
  device threads and the title ask at boot at the same time, and the
  release point reads the pending word with a full barrier after leaving
  the gate, so a post that saw the gate held is not missed on arm64.
- RECOMP_VBLANK=paced (or the gate on top of any RECOMP_VBLANK): vblank
  runs on an absolute nanosecond 60 Hz schedule on a waitable
  high-resolution timer, honours PCRTC_INTR_EN_0 and PMC_INTR_EN_0, and
  the acknowledgement of the DPC's PCRTC write moves to its own thread, so
  a late DPC no longer loses the vblank to the NV2A ack loop. Plain
  RECOMP_VBLANK=1 keeps v0.14.0's tick (16 ms on GetTickCount64 checked
  on the timer thread's 10 ms sleep), which now logs its rate every 600
  vblanks and is otherwise unchanged. xbox_VblankMode is the pure choice.
- RECOMP_GUEST_LOCK=1 (already opt-in) becomes a ticket scheduler: a
  kernel call that returns at once barges back; one that blocks,
  NtYieldExecution and a thread exit hand the CPU to the next waiter; a
  turn longer than the quantum (RECOMP_GUEST_QUANTUM, 4 ms) sets
  g_xbox_guest_cpu_preempt, which code lifted with --back-edge-yield (a
  later commit) checks; a thread whose wait completed asks for the CPU at
  once, as the console's wait boost runs it first.
- RECOMP_GUEST_CPUS=one or =<n>: guest threads are pinned to one core, as
  the title's own spin locks assume no sibling on another core. Unset or
  =all, as before.
- platform/host_time: a monotonic nanosecond clock and a sleep that
  honours it, for the schedule and the scheduler.

Tests: irq_safe_points, dpc_order, vblank_ack (including the default,
tick and paced choices), guest_cpu and kernel_guest_cpu, on every host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 13:25:30 -07:00
..