A switch that does not complete, a trigger whose register writes were
refused, or a low-ring job left waiting with the high ring idle ends the
second ring for good. recover() then starts from the oldest job that never
ran and replays it on the first ring, whichever ring it sat on, so a
broken switch costs the background work and not the session.
Ring 0 is the high ring: ring 1 is only switched to when ring 0 has no
pending job, or the low job has waited PreemptAgingUs. Only priorities 2
and 3 take ring 1.
A ring the CP does not run keeps its write pointer for the switch to
give, and every framed submission on a ring with a preemption record ends
with the yield.
The preemption record keeps what the CP saved into it; only the write
pointer is rewritten before a switch.
The switch log records the registers and both records around each switch,
and a switch that times out carries the CP's IB state.
Add hardware CP context switch via CP_CONTEXT_SWITCH_CNTL on a second
ring. Use a conservative BO-disjoint rule: only allow a queued job to
preempt the running ring when their buffer sets share no handle. Two
4192 KiB preemption records and two a7xx_cp_smmu_info pages are mapped
at fixed IOVAs. Ring priority comes from the kernel GPU role of the
submitting task (BACKGROUND/UTILITY → ring 1, UI/focal/realtime → ring 0).
Diagnostics gated on sheng-diag=1; feature gated on sheng-gpu-preempt=1.