diff --git a/CHANGELOG.md b/CHANGELOG.md index b23eece99..9210ffb64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ hashes are given where a change is easiest to understand by reading the commit. ## November 2026 +### jitv2 interrupts + +- Under jitv2, software interrupts are taken as soon as they are enabled, not + at the next hardware interrupt, on every machine. On the Tezro, quake's + timedemo no longer freezes for up to a second at a time. + ### jitv2 flushes - Under jitv2, a single-processor machine no longer hangs when the CPU runs out diff --git a/clanker/INDEX.md b/clanker/INDEX.md index 2a9bf26d3..9d756ffc0 100644 --- a/clanker/INDEX.md +++ b/clanker/INDEX.md @@ -91,6 +91,7 @@ The MIPS JIT (`src/cpu/jitv2/`): design, Cranelift codegen, delay slots, invalid | [inlined-slot-pc-bd-bracket.md](jitv2/inlined-slot-pc-bd-bracket.md) | rule | The inlined delay slot's `core.pc` / `in_delay_slot` bracket | | [instructions-jitv2-still-interprets.md](jitv2/instructions-jitv2-still-interprets.md) | history | What jitv2 still interprets, and which of it is worth compiling | | [gpr-cache.md](jitv2/gpr-cache.md) | rule | Guest registers are cached in host registers only inside loops, and written through: the rule for callouts, the load/store join, suite and IRIX measurements, what was dropped, and compile time as the bigger lever | +| [software-interrupts-must-show-in-the-pending-word.md](jitv2/software-interrupts-must-show-in-the-pending-word.md) | rule | Cause IP0/IP1 must be mirrored into `hot.interrupts`: compiled code polls only that word, so a pending software interrupt waited for the next hardware interrupt; Tezro quake froze up to 1.3 s on IRIX's deferred wake-up | | [interrupt-check-frequency-gates-gpr-forwarding.md](jitv2/interrupt-check-frequency-gates-gpr-forwarding.md) | measure | The pending-interrupt check, not block structure, is what blocks GPR forwarding | | [j2_per_instruction_category_toggle.md](jitv2/j2_per_instruction_category_toggle.md) | design | j2 per-instruction/category enable toggle | | [jit-page-probe-must-be-retired-on-drop.md](jitv2/jit-page-probe-must-be-retired-on-drop.md) | history | The jitv2 dirty-page probe must be retired when its cache dies | diff --git a/clanker/jitv2/software-interrupts-must-show-in-the-pending-word.md b/clanker/jitv2/software-interrupts-must-show-in-the-pending-word.md new file mode 100644 index 000000000..41db218e1 --- /dev/null +++ b/clanker/jitv2/software-interrupts-must-show-in-the-pending-word.md @@ -0,0 +1,37 @@ +# Software interrupts must show in the pending word + +Status: fixed 2026-11-22 (`MipsCore::sync_soft_interrupts`). + +**Symptom.** On the Tezro (4 x R16000, jitv2), quake's `timedemo demo1` +froze for 0.3 to 1.3 s several times a run, at random; scores varied +16 to 29 fps. The guest's clock was fine (UST never went back, no system +gap). Quake was asleep in the kernel outside any system call, at a +libGLcore PC, on a wait address inside `rrm_pane` (the Rendering Resource +Manager). The VPro board was idle for the whole stall: swap armed, latched +at the next retrace, retrace interrupt delivered. + +**What the trace showed.** Perfetto's per-CPU `interrupt taken` events: +for the whole stall one CPU took `ip 0x81` (IP7 clock plus software +interrupt IP0) every 10 ms, and the stall ended the moment that CPU took +`ip 0x1` alone. IRIX had posted deferred work (the wake-up) as a software +interrupt; its clock handler services IP7 and returns. + +**Cause.** Compiled code polls only `core.hot.interrupts` for a pending +interrupt (`emit_pending_interrupt_preamble`, `emit_entry_interrupt_bail`). +Software interrupts lived only in `cp0_cause`, which the interpreter's +`step_preamble!` reads but compiled code does not. A software interrupt +left pending across an `eret` into compiled code was taken only when a +hardware interrupt next sent the CPU through the interpreter's check, and +when that was the clock, the handler left IP0 pending again. + +**Rule.** Every write of Cause IP0/IP1 (guest `mtc0`, snapshot and state +restores) mirrors them into `hot.interrupts` through +`MipsCore::sync_soft_interrupts`. The interpreter merges only the external +bits (IP2-IP7) back into Cause, so the mirror only makes the word nonzero; +delivery still reads Cause. Anything new that sets Cause's software bits +must call it. + +**Tools that found it.** A small guest watcher sampling the process from `/proc` every 50 ms +(state, wait channel, `pr_syscall`, user PC; `pr_syscall` reads one above +`sys.s`), kernel symbols from `/unix` for the wait address, and a perfetto +trace (`all,-prim,-jit`) with frame gaps taken from `swap arm` slices. diff --git a/debug.md b/debug.md index 0f4b94b22..3bbb41e66 100644 --- a/debug.md +++ b/debug.md @@ -674,7 +674,7 @@ controller's accesses and values nothing establishes. |---|---| | `perf snapshot` | Performance counters (Indy, Indigo2 and the Bedrock machines) | | `locks` | Every registered lock, whether it is held, and by which thread and call site (for `SpinLock`s); Indy and Indigo2 | -| `perfetto start FILE [cats=LIST] [clock=host\|guest]` | Start a Perfetto trace (`--features perfetto`; Indy, Indigo2, O2 and Octane) | +| `perfetto start FILE [cats=LIST] [clock=host\|guest]` | Start a Perfetto trace (`--features perfetto`; Indy, Indigo2, O2, Octane, Origin 200/2000, Fuel, Tezro and Origin 3000) | | `perfetto cats LIST` / `perfetto status` / `perfetto stop` | Change categories / show / stop | | `idleprof ...` | See [history and tracing](#history-undo-and-tracing) | diff --git a/docs/perfetto.md b/docs/perfetto.md index c1deefe52..1806d26f7 100644 --- a/docs/perfetto.md +++ b/docs/perfetto.md @@ -31,7 +31,7 @@ event that belongs to several categories is recorded when any of them is on. |---|---| | `cpu` | Interrupts taken by the CPU (also `irq`). | | `irq` | IOC/INT2 interrupt lines, the CPU's IP2-IP7 pins, interrupts taken. | -| `timer` | The 8254 slow and fast ticks and Count/Compare (IP7); these are also `irq`. | +| `timer` | The 8254 slow and fast ticks, Count/Compare (IP7) and the IP35 PI real-time clock; these are also `irq`. | | `dma` | HPC3 PDMA channels, VDMA (also `gfx`), IMPACT host DMA (also `gfx`). | | `scsi` | WD33C93A commands, CDBs and chip interrupts. | | `net` | Ethernet frames sent, received, refused and filtered. | @@ -71,7 +71,8 @@ host thread's name. | Where | Track / thread | Events | |---|---|---| | Interrupts | `L0 *`, `L1 *`, `map *` | One slice per assertion of each IOC/INT2 status bit (raw, before masking), from raise to clear. `slow tick (8254 timer 0)` and `fast tick (8254 timer 1)` are latches, so their slices measure tick-to-acknowledge latency. | -| CPU interrupt pins | `IP2`…`IP6`, `IP7 (count/compare)` | The CPU's interrupt inputs. IP7 runs from the Count/Compare match to the guest's Compare write. `IP7 masked (Status)` is a slice while the guest has the clock masked (Status IE or IM7 clear); `IP7 pending, held` while IP7 is pending and the CPU cannot take it (arg at the start: Status << 32 \| PC). | +| CPU interrupt pins | `IP2`…`IP6`, `IP7 (count/compare) cpu N` | The CPU's interrupt inputs. Each processor (0 to 7) has its own IP7 tracks. IP7 runs from the Count/Compare match to the guest's Compare write. `IP7 masked (Status)` is a slice while the guest has the clock masked (Status IE or IM7 clear); `IP7 pending, held` while IP7 is pending and the CPU cannot take it (arg at the start: Status << 32 \| PC). | +| IP35 clock | `RT clock cpu 0`…`3` | The Fuel, Tezro and Origin 3000 schedule from each processor's PI real-time comparator, not Count/Compare. A `rt tick` slice runs from the comparator latching to the guest clearing its pending bit: its length is the tick-to-acknowledge latency, and a gap is a missed tick. Both nodes of a two-node machine share the tracks. | | `MIPS-CPU` | thread | `interrupt taken` (arg: pending & enabled IP bits); jitv2 `compile request` and `hot request` (arg: PC); `pool flush (CPU thread)` and `track page (CPU thread)`, the jitv2 work that runs on the CPU thread with no guest code running. | | DMA | `PDMA pbus0-7`, `PDMA scsi0/1`, `PDMA enet rx/tx` | HPC3 channel `active` slices (arg: first descriptor), `desc` per data descriptor (arg: byte count/flags), `int` on completion interrupts. PBUS channels carry HAL2 audio. | | DMA | `VDMA` | MC graphics DMA: `mem -> gio`, `gio -> mem`, `fill` (arg: bytes). | @@ -87,8 +88,9 @@ host thread's name. | Graphics | `IMPACT status`, `IMPACT flags`, `IMPACT vc3` | Every STATUS read with its value (bit 2 is vertical blank); flags raised (arg: raster entries queued << 32 \| bits) and cleared by the host; VC3 register and SRAM writes (the window-ID tables) and current-line reads. | | Graphics | `IMPACT irq` | The board's three interrupt lines (arg: line << 1 \| level: 0 FIFO, 1 general, 2 retrace). On the Octane, the interrupt packets sent to HEART (arg: vector << 1 \| set) and the kernel's acknowledgements (arg: offset << 32 \| bits). | | Graphics | `VPro cfifo level` | The command-FIFO level STATUS0 is built from (words queued, not yet run), sampled at slice start and end and at STATUS0 reads. | -| Graphics | `VPro irq` | `cfifo low water` (the level fell below the mark as a store retired), `dma done`, and an `interrupt packet` per packet sent to HEART (arg: routed-source shift << 9 \| vector << 1 \| set). | +| Graphics | `VPro irq` | `cfifo high water` (the level reached the driver's mark as a store was queued, arg: level), `enable/flags write` (the driver's writes to the interrupt enables and flags, arg: enables << 32 \| flags), `cfifo low water` (the low-water flag latched: the level fell below the mark as a store retired, with the flag clear), `dma done`, and an `interrupt packet` per packet sent to HEART (arg: routed-source shift << 9 \| vector << 1 \| set). | | Graphics | `Display vblank`, `Display frame` | The display refresh thread, for every board: a `vblank` slice from vblank start to vblank end (arg: field), then on the frame track `capture` (the board taking the frame from its live state), `compose` and `present`, or `capture refused` when the board is not ready (Newport's fence). | +| Graphics | `VPro irq line`, `VPro flow control` | `flag interrupt` while an enabled flag is set (arg: flags & enables); `low-water enabled` while the driver has the low-water interrupt enabled, that is, while its flow control waits for the command FIFO to drain. | | Graphics | `VPro display`, `VPro capture`, `VPro present` | `swap arm` (the driver's flip request, arg: mask), `retrace` (flips latched, arg: displayed-buffer bits); the refresh thread resolving the frame and handing it to the window. Inside a capture, `frame planes` on `Display-Refresh` is the part that composes the whole frame from board memory, with no lock and no wait for the raster unit. | | Graphics | `VPro access busy` | One processor access answered busy, from its first refusal until it completes (arg: aperture offset). The processor takes its enabled interrupts in between. | | `odyssey-work` | thread | `slice` per run of queued stores on the front-end thread (arg: stores waiting), `dma descriptor` per page-table transfer (arg: table address). A processor access that drains the queue shows `drain` on its own thread. | diff --git a/src/cpu/mips_core.rs b/src/cpu/mips_core.rs index be5760c1f..e6eee8b09 100644 --- a/src/cpu/mips_core.rs +++ b/src/cpu/mips_core.rs @@ -105,7 +105,7 @@ pub const NS_PER_GUEST_CYCLE: u64 = 10; /// next Compare write re-arms it via `MipsCore::arm_ip7_sequence`, which is /// exactly the guest's acknowledgement. #[inline] -fn claim_ip7(seq: &AtomicU64, ticket: u64, irq: &AtomicU64, fasttick: &AtomicU64) -> bool { +fn claim_ip7(seq: &AtomicU64, ticket: u64, irq: &AtomicU64, fasttick: &AtomicU64, _cpu: u8) -> bool { if ticket == IP7_SEQ_CONSUMED { return false; } @@ -117,7 +117,11 @@ fn claim_ip7(seq: &AtomicU64, ticket: u64, irq: &AtomicU64, fasttick: &AtomicU64 { irq.fetch_or(CAUSE_IP7 as u64, Ordering::SeqCst); seq.store(IP7_SEQ_CONSUMED, Ordering::SeqCst); - crate::pf_level!(crate::perfetto::events::IP7_LEVEL, crate::perfetto::events::IP7_COMPARE, true); + crate::pf_level!( + crate::perfetto::events::IP7_LEVEL[_cpu as usize % crate::perfetto::events::IP7_CPUS], + crate::perfetto::events::IP7_COMPARE[_cpu as usize % crate::perfetto::events::IP7_CPUS], + true + ); #[cfg(feature = "idle-pause")] crate::cpu::idle_park::wake(); fasttick.fetch_add(1, Ordering::Relaxed); @@ -1856,6 +1860,7 @@ impl MipsCore { self.ip7_seq, &self.hot.interrupts, &self.fasttick_count, + self.cpu_id, ); #[cfg(feature = "developer_ip7")] if won { @@ -1968,6 +1973,7 @@ impl MipsCore { let fasttick = self.fasttick_count.clone(); let ticket = self.ip7_seq; let seq_ref = self.ip7_seq_shared.clone(); + let cpu = self.cpu_id; // After firing, hardware would next match Compare again after a // full 32-bit Count wrap — self-reschedule that far out. In // practice the guest's interrupt handler writes Compare long @@ -1977,8 +1983,8 @@ impl MipsCore { ); self.timer_id = Some(tm.add_one_shot( std::time::Duration::from_nanos(ns), - (irq, fasttick, wrap, ticket, seq_ref), - |(irq, fasttick, wrap, ticket, seq_ref)| { + (irq, fasttick, wrap, ticket, seq_ref, cpu), + |(irq, fasttick, wrap, ticket, seq_ref, cpu)| { // SAFETY: points into the MipsCore owned by the executor's // top-level Arc>, which outlives the armed timer // (Drop for MipsCore removes it). Same contract as @@ -1988,7 +1994,7 @@ impl MipsCore { // Compare write since this one-shot was scheduled has // already issued a new ticket, so this claim fails and the // interrupt the guest just acked is not re-asserted. - let won = claim_ip7(seq_ref, *ticket, irq_ref, fasttick); + let won = claim_ip7(seq_ref, *ticket, irq_ref, fasttick, *cpu); if !won { return crate::hptimer::TimerReturn::Delete; } @@ -1998,6 +2004,25 @@ impl MipsCore { } } + /// Mirror the software interrupts (Cause IP0 and IP1) into + /// `hot.interrupts`. Compiled code polls only that word for a pending + /// interrupt, so a software interrupt kept in Cause alone was not taken + /// under the JIT until a hardware interrupt happened to send the CPU + /// through the interpreter's check: IRIX posts deferred work (such as + /// waking a process blocked on the graphics pipe) as a software + /// interrupt, and the Tezro's quake froze for most of a second at a time + /// while it sat pending behind clock ticks the handler serviced alone. + /// The interpreter merges only the external bits back into Cause, so the + /// mirror only makes the word nonzero; delivery still reads Cause. + pub fn sync_soft_interrupts(&self) { + let mask = (CAUSE_IP0 | CAUSE_IP1) as u64; + let soft = self.cp0_cause as u64 & mask; + self.hot.interrupts.fetch_and(!(mask & !soft), Ordering::SeqCst); + if soft != 0 { + self.hot.interrupts.fetch_or(soft, Ordering::SeqCst); + } + } + /// ci_clock: raise IP7 once `hot.cycles` has reached the Compare /// deadline. A threshold, not an edge, so a caller that looks late still /// delivers it, once. @@ -2010,7 +2035,7 @@ impl MipsCore { let wrap_ns = ((1u128 << 32) * 1_000_000_000) / self.count_hz as u128; self.count_fire_cycle = self.hot.cycles.saturating_add(wrap_ns as u64 / NS_PER_GUEST_CYCLE); self.hot.interrupts.fetch_or(CAUSE_IP7 as u64, Ordering::SeqCst); - crate::pf_level!(crate::perfetto::events::IP7_LEVEL, crate::perfetto::events::IP7_COMPARE, true); + crate::pf_level!(crate::perfetto::events::IP7_LEVEL[self.cpu_id as usize % crate::perfetto::events::IP7_CPUS], crate::perfetto::events::IP7_COMPARE[self.cpu_id as usize % crate::perfetto::events::IP7_CPUS], true); self.fasttick_count.fetch_add(1, Ordering::Relaxed); } } @@ -2063,7 +2088,7 @@ impl MipsCore { self.arm_ip7_sequence(); self.reanchor_count_and_reschedule(); if self.cp0_cause & CAUSE_IP7 != 0 { - claim_ip7(&self.ip7_seq_shared, self.ip7_seq, &self.hot.interrupts, &self.fasttick_count); + claim_ip7(&self.ip7_seq_shared, self.ip7_seq, &self.hot.interrupts, &self.fasttick_count, self.cpu_id); } else { self.hot.interrupts.fetch_and(!(CAUSE_IP7 as u64), Ordering::SeqCst); } @@ -2191,7 +2216,7 @@ impl MipsCore { // re-raise it). self.cp0_cause &= !CAUSE_IP7; self.hot.interrupts.fetch_and(!(CAUSE_IP7 as u64), Ordering::SeqCst); - crate::pf_level!(crate::perfetto::events::IP7_LEVEL, crate::perfetto::events::IP7_COMPARE, false); + crate::pf_level!(crate::perfetto::events::IP7_LEVEL[self.cpu_id as usize % crate::perfetto::events::IP7_CPUS], crate::perfetto::events::IP7_COMPARE[self.cpu_id as usize % crate::perfetto::events::IP7_CPUS], false); // Now classify what the guest actually asked for. Count here // is virtual and materialized in lumps from the wall clock, @@ -2250,6 +2275,7 @@ impl MipsCore { ticket, &self.hot.interrupts, &self.fasttick_count, + self.cpu_id, ); #[cfg(feature = "developer_ip7")] if won { self.ip7_late_fires += 1; } @@ -2329,6 +2355,7 @@ impl MipsCore { // Cause register: Only IP0 and IP1 are writable software interrupts let mask = CAUSE_IP0 | CAUSE_IP1; self.cp0_cause = (self.cp0_cause & !mask) | ((value as u32) & mask); + self.sync_soft_interrupts(); } 14 => { // A guest write of a 32-bit value here is where a 64-bit @@ -2950,10 +2977,27 @@ mod ip7_ticket_tests { let shared = core.ip7_seq_shared.load(Ordering::SeqCst); assert_ne!(shared, IP7_SEQ_CONSUMED, "the restored deadline was armed with the delivered sentinel"); assert_eq!(shared, core.ip7_seq, "the armed one-shot's ticket must be the live sequence"); - assert!(claim_ip7(&core.ip7_seq_shared, core.ip7_seq, &core.hot.interrupts, &core.fasttick_count), + assert!(claim_ip7(&core.ip7_seq_shared, core.ip7_seq, &core.hot.interrupts, &core.fasttick_count, core.cpu_id), "the restored deadline's one-shot could not deliver IP7"); } + /// A software interrupt the guest posts in Cause shows in the pending + /// word compiled code polls, and clearing it there leaves the hardware + /// lines alone. Kept only in Cause, it went untaken under the JIT until + /// a hardware interrupt passed through the interpreter's check. + #[test] + fn a_software_interrupt_shows_in_the_pending_word() { + let mut core = MipsCore::default(); + core.hot.interrupts.store(CAUSE_IP7 as u64, Ordering::SeqCst); + core.write_cp0(13, CAUSE_IP0 as u64); + assert_eq!(core.hot.interrupts.load(Ordering::SeqCst), (CAUSE_IP7 | CAUSE_IP0) as u64); + core.write_cp0(13, CAUSE_IP1 as u64); + assert_eq!(core.hot.interrupts.load(Ordering::SeqCst), (CAUSE_IP7 | CAUSE_IP1) as u64); + core.write_cp0(13, 0); + assert_eq!(core.hot.interrupts.load(Ordering::SeqCst), CAUSE_IP7 as u64); + assert_eq!(core.cp0_cause & (CAUSE_IP0 | CAUSE_IP1), 0); + } + fn ip7_pending(core: &MipsCore) -> bool { core.hot.interrupts.load(Ordering::SeqCst) as u32 & CAUSE_IP7 != 0 } @@ -3006,7 +3050,7 @@ mod ip7_ticket_tests { } if ticket != tried.load(Ordering::SeqCst) { // SAFETY: the core outlives the scope, as it does the armed timer. - claim_ip7(&seq, ticket, unsafe { &*irq.0 }, &fasttick); + claim_ip7(&seq, ticket, unsafe { &*irq.0 }, &fasttick, 0); tried.store(ticket, Ordering::SeqCst); } std::thread::yield_now(); diff --git a/src/cpu/mips_exec.rs b/src/cpu/mips_exec.rs index c7dda7850..2b70d4052 100644 --- a/src/cpu/mips_exec.rs +++ b/src/cpu/mips_exec.rs @@ -2635,8 +2635,8 @@ macro_rules! step_preamble { // For the trace: IP7 pending and not deliverable here. crate::pf_level!( - crate::perfetto::events::IP7_HELD_LEVEL, - crate::perfetto::events::IP7_HELD, + crate::perfetto::events::IP7_HELD_LEVEL[$self.core.cpu_id as usize % crate::perfetto::events::IP7_CPUS], + crate::perfetto::events::IP7_HELD[$self.core.cpu_id as usize % crate::perfetto::events::IP7_CPUS], pending as u32 & crate::cpu::mips_core::CAUSE_IP7 != 0 && !($self.core.interrupts_enabled() && $self.core.cp0_status & crate::cpu::mips_core::CAUSE_IP7 != 0), (($self.core.cp0_status as u64) << 32) | (pc & 0xffff_ffff) @@ -3996,8 +3996,8 @@ va={:#018x} phys={:#010x} (code pfn {:#x}, page {:#010x}, word {}/{})", // The clock interrupt's mask, for the trace (IE and IM7; see // events::IP7_MASKED). crate::pf_level!( - crate::perfetto::events::IP7_MASKED_LEVEL, - crate::perfetto::events::IP7_MASKED, + crate::perfetto::events::IP7_MASKED_LEVEL[self.core.cpu_id as usize % crate::perfetto::events::IP7_CPUS], + crate::perfetto::events::IP7_MASKED[self.core.cpu_id as usize % crate::perfetto::events::IP7_CPUS], self.core.cp0_status & crate::cpu::mips_core::STATUS_IE == 0 || self.core.cp0_status & (1 << (crate::cpu::mips_core::STATUS_IM_SHIFT + 7)) == 0 ); #[cfg(feature = "cache-ecc")] @@ -9567,6 +9567,7 @@ va={:#018x} phys={:#010x} (code pfn {:#x}, page {:#010x}, word {}/{})", self.core.cp0_compare = snapshot.cp0_compare; self.core.cp0_status = snapshot.cp0_status; self.core.cp0_cause = snapshot.cp0_cause; + self.core.sync_soft_interrupts(); self.core.cp0_epc = snapshot.cp0_epc; self.core.cp0_prid = snapshot.cp0_prid; self.core.cp0_config = snapshot.cp0_config; @@ -10253,6 +10254,7 @@ impl LockstepSnapshot { exec.core.pc = self.pc; exec.core.cp0_status = self.status; exec.core.cp0_cause = self.cause; + exec.core.sync_soft_interrupts(); exec.core.cp0_epc = self.epc; exec.core.fpr = self.fpr; exec.core.fpu_fcsr = self.fcsr; @@ -11243,6 +11245,7 @@ impl MipsCpu { exec.core.cp0_compare = digest.cp0_compare; exec.core.cp0_status = digest.cp0_status; exec.core.cp0_cause = digest.cp0_cause; + exec.core.sync_soft_interrupts(); exec.core.cp0_epc = digest.cp0_epc; exec.core.cp0_badvaddr = digest.cp0_badvaddr; exec.core.cp0_entryhi = digest.cp0_entryhi; @@ -12016,6 +12019,7 @@ impl Saveable for MipsCpu // thread) so the live UI matches the restored core state. c.count_hz_atomic.store(c.count_hz, std::sync::atomic::Ordering::Relaxed); ld32!(cp0_status); ld32!(cp0_cause); ld32!(cp0_prid); + c.sync_soft_interrupts(); ld32!(cp0_config); ld64!(cp0_lladdr); ld32!(cp0_watchlo); ld32!(cp0_watchhi); ld32!(cp0_ecc); ld32!(cp0_cacheerr); ld64!(cp0_taglo); ld32!(cp0_taghi); ld64!(cp0_entrylo0); ld64!(cp0_entrylo1); ld64!(cp0_context); diff --git a/src/dev/bedrock/pi.rs b/src/dev/bedrock/pi.rs index e40e1e478..01b58238a 100644 --- a/src/dev/bedrock/pi.rs +++ b/src/dev/bedrock/pi.rs @@ -445,6 +445,8 @@ impl Pi { for slot in 0..2 { if u128::from(time) >= t.rt_due[slot] { self.rt_status[slot].store(1, SeqCst); + let _cpu = (usize::from(self.interface) * 2 + slot) & 3; + crate::pf_level!(crate::perfetto::events::PI_RT_TICK_LEVEL[_cpu], crate::perfetto::events::PI_RT_TICK[_cpu], true); self.arm_rt(t, &o, slot, now); latched = true; } @@ -669,7 +671,10 @@ impl Pi { reg::RT_INT_PEND_A::OFFSET | reg::RT_INT_PEND_B::OFFSET => { // Latch a deadline that has passed first, so the clear takes it. self.catch_up(clock()); - self.rt_status[index(reg::RT_INT_PEND_A::OFFSET)].store(0, SeqCst); + let slot = index(reg::RT_INT_PEND_A::OFFSET); + self.rt_status[slot].store(0, SeqCst); + let _cpu = (usize::from(self.interface) * 2 + slot) & 3; + crate::pf_level!(crate::perfetto::events::PI_RT_TICK_LEVEL[_cpu], crate::perfetto::events::PI_RT_TICK[_cpu], false); } reg::PROF_INT_PEND_A::OFFSET | reg::PROF_INT_PEND_B::OFFSET => { self.catch_up(clock()); diff --git a/src/dev/odyssey/fifo.rs b/src/dev/odyssey/fifo.rs index daa9004bc..277418f96 100644 --- a/src/dev/odyssey/fifo.rs +++ b/src/dev/odyssey/fifo.rs @@ -377,6 +377,7 @@ impl CommandFifo { // the enable mask says. let mut f = front.lock(); f.intr_flags |= intr::FIFO_HIGH_WATER; + crate::pf_instant!(crate::perfetto::events::ODSY_CFIFO_HIGH_WATER, after); f.update_irq(); } self.wake(); @@ -421,8 +422,12 @@ impl CommandFifo { let before = self.levels.words.fetch_sub(words, SeqCst); debug_assert!(before >= words, "the level counts every store before the ring shows it (push)"); if before >= cfifo::LOW_WATER && before - words < cfifo::LOW_WATER { + // Traced when the flag latches, not on every crossing with it + // already set (hundreds of thousands a second under GL). + if f.intr_flags & intr::FIFO_LOW_WATER == 0 { + crate::pf_instant!(crate::perfetto::events::ODSY_CFIFO_LOW_WATER, before - words); + } f.intr_flags |= intr::FIFO_LOW_WATER; - crate::pf_instant!(crate::perfetto::events::ODSY_CFIFO_LOW_WATER, before - words); f.update_irq(); } } else { diff --git a/src/dev/odyssey/interface.rs b/src/dev/odyssey/interface.rs index f6dd01b30..d33948473 100644 --- a/src/dev/odyssey/interface.rs +++ b/src/dev/odyssey/interface.rs @@ -348,6 +348,12 @@ impl HostInterface { pub fn update_irq(&mut self) { let level = (self.intr_flags & self.intr_enable) != 0; + crate::pf_level!(crate::perfetto::events::ODSY_IRQ_LINE_LEVEL, crate::perfetto::events::ODSY_IRQ_LINE, level, self.intr_flags & self.intr_enable); + crate::pf_level!( + crate::perfetto::events::ODSY_LOW_WATER_WAIT_LEVEL, + crate::perfetto::events::ODSY_LOW_WATER_WAIT, + self.intr_enable & intr::FIFO_LOW_WATER != 0 + ); if level != self.interrupt_asserted { self.interrupt_asserted = level; @@ -464,14 +470,17 @@ impl HostInterface { Some(ODSY_ERROR_COMMAND) => self.error_command = 0, Some(intr::CLEAR) => { self.intr_flags &= !(value as u32); + crate::pf_instant!(crate::perfetto::events::ODSY_INTR_WRITE, (self.intr_enable as u64) << 32 | self.intr_flags as u64); self.update_irq(); } Some(intr::ENABLE_SET) => { self.intr_enable |= value as u32; + crate::pf_instant!(crate::perfetto::events::ODSY_INTR_WRITE, (self.intr_enable as u64) << 32 | self.intr_flags as u64); self.update_irq(); } Some(intr::ENABLE_CLEAR) => { self.intr_enable &= !(value as u32); + crate::pf_instant!(crate::perfetto::events::ODSY_INTR_WRITE, (self.intr_enable as u64) << 32 | self.intr_flags as u64); self.update_irq(); } Some(intr::FLAGS) => { @@ -483,6 +492,7 @@ impl HostInterface { // registers (set enables, clear enables, clear flags) make a // set-only write the competing reading. self.intr_flags = value as u32; + crate::pf_instant!(crate::perfetto::events::ODSY_INTR_WRITE, (self.intr_enable as u64) << 32 | self.intr_flags as u64); self.update_irq(); } Some(ODSY_SW_TOKEN) => self.sw_token = value as u32, diff --git a/src/perfetto/events.rs b/src/perfetto/events.rs index 258f86bd2..37799310b 100644 --- a/src/perfetto/events.rs +++ b/src/perfetto/events.rs @@ -51,11 +51,31 @@ pub static IOC_LINES: [EventDef; 32] = [ pin("IP6 (bus error)"), pin("unused 29"), pin("unused 30"), pin("unused 31"), ]; +/// Per-CPU tracks for the clock interrupt: one each for processors 0 to 7 +/// (`MipsCore::cpu_id`; a higher number shares track `id & 7`). +pub const IP7_CPUS: usize = 8; +macro_rules! per_cpu { + ($ctor:ident, $base:literal) => { + [ + $ctor(concat!($base, " cpu 0")), $ctor(concat!($base, " cpu 1")), $ctor(concat!($base, " cpu 2")), $ctor(concat!($base, " cpu 3")), + $ctor(concat!($base, " cpu 4")), $ctor(concat!($base, " cpu 5")), $ctor(concat!($base, " cpu 6")), $ctor(concat!($base, " cpu 7")), + ] + }; +} +const fn ip7_compare(track: &'static str) -> EventDef { + EventDef::new("IP7 (count/compare)", cat::IRQ | cat::TIMER).on_track(track).in_group(PIN_GROUP) +} +const fn ip7_masked(track: &'static str) -> EventDef { + EventDef::new("IP7 masked (Status)", cat::CPU | cat::IRQ).on_track(track).in_group(PIN_GROUP) +} +const fn ip7_held(track: &'static str) -> EventDef { + EventDef::new("IP7 pending, held", cat::CPU | cat::IRQ).on_track(track).in_group(PIN_GROUP).with_arg("status<<32|pc") +} + /// CP0 Count/Compare match, asserted by the timer thread, ended by the /// guest's Compare write. -pub static IP7_COMPARE: EventDef = - EventDef::new("IP7 (count/compare)", cat::IRQ | cat::TIMER).on_track("IP7 (count/compare)").in_group(PIN_GROUP); -pub static IP7_LEVEL: crate::PfLevel = crate::PfLevel::new(); +pub static IP7_COMPARE: [EventDef; IP7_CPUS] = per_cpu!(ip7_compare, "IP7 (count/compare)"); +pub static IP7_LEVEL: [crate::PfLevel; IP7_CPUS] = [const { crate::PfLevel::new() }; IP7_CPUS]; /// The CPU took an interrupt exception (arg: Cause.IP & Status.IM >> 8). pub static INT_TAKEN: EventDef = EventDef::new("interrupt taken", cat::CPU | cat::IRQ).with_arg("ip"); @@ -64,14 +84,26 @@ pub static INT_TAKEN: EventDef = EventDef::new("interrupt taken", cat::CPU | cat /// (IRIX's spl levels; EXL and ERL, held only for an exception's entry, are /// left out to keep the edge rate down). A slice here while IP7 is raised is /// the guest's own hold-off of its clock tick. -pub static IP7_MASKED: EventDef = EventDef::new("IP7 masked (Status)", cat::CPU | cat::IRQ).on_track("IP7 masked (Status)").in_group(PIN_GROUP); -pub static IP7_MASKED_LEVEL: crate::PfLevel = crate::PfLevel::new(); +pub static IP7_MASKED: [EventDef; IP7_CPUS] = per_cpu!(ip7_masked, "IP7 masked (Status)"); +pub static IP7_MASKED_LEVEL: [crate::PfLevel; IP7_CPUS] = [const { crate::PfLevel::new() }; IP7_CPUS]; /// IP7 is pending but the CPU cannot take it (interrupts disabled by IE, /// EXL or ERL, or IM7 clear), seen at the instruction boundaries where a /// pending interrupt is examined (arg at the rising edge: Status << 32 | the /// PC's low 32 bits). -pub static IP7_HELD: EventDef = EventDef::new("IP7 pending, held", cat::CPU | cat::IRQ).on_track("IP7 pending, held").in_group(PIN_GROUP).with_arg("status<<32|pc"); -pub static IP7_HELD_LEVEL: crate::PfLevel = crate::PfLevel::new(); +pub static IP7_HELD: [EventDef; IP7_CPUS] = per_cpu!(ip7_held, "IP7 pending, held"); +pub static IP7_HELD_LEVEL: [crate::PfLevel; IP7_CPUS] = [const { crate::PfLevel::new() }; IP7_CPUS]; + +const fn rt_tick(track: &'static str) -> EventDef { + EventDef::new("rt tick", cat::IRQ | cat::TIMER).on_track(track).in_group(PIN_GROUP) +} +/// IP35 (Fuel, Tezro, Origin 3000): a processor's PI real-time comparator, +/// the IRIX scheduler clock on these machines, indexed by interface * 2 + +/// slot. A slice runs from the comparator latching to the guest clearing +/// RT_INT_PEND, so its length is tick-to-acknowledge latency and a missing +/// slice is a missed tick. Both nodes of a two-node machine share the tracks. +pub static PI_RT_TICK: [EventDef; 4] = + [rt_tick("RT clock cpu 0"), rt_tick("RT clock cpu 1"), rt_tick("RT clock cpu 2"), rt_tick("RT clock cpu 3")]; +pub static PI_RT_TICK_LEVEL: [crate::PfLevel; 4] = [const { crate::PfLevel::new() }; 4]; // ── HPC3 peripheral DMA ────────────────────────────────────────────────────── @@ -297,6 +329,17 @@ pub static MGRAS_HQ4_ACK: EventDef = EventDef::new("hq4 ack", cat::GFX).on_track /// by the hundred thousand. pub static ODSY_CFIFO_LEVEL: EventDef = EventDef::new("VPro cfifo level", cat::GFX).in_group(GFX_GROUP); /// The FIFO fell below the low-water mark as a store retired (arg: level). +/// The level reached the driver's high-water mark (the 0x6b2 value) as a store was queued. +pub static ODSY_CFIFO_HIGH_WATER: EventDef = EventDef::new("cfifo high water", cat::GFX).on_track("VPro irq").in_group(GFX_GROUP).with_arg("level"); +/// A write to the interrupt enables or flags (arg: enables << 32 | flags after it). +pub static ODSY_INTR_WRITE: EventDef = EventDef::new("enable/flags write", cat::GFX | cat::IRQ).on_track("VPro irq").in_group(GFX_GROUP).with_arg("enable<<32|flags"); +/// The flag interrupt line: raised while an enabled flag is set (arg: flags & enables). +pub static ODSY_IRQ_LINE: EventDef = EventDef::new("flag interrupt", cat::GFX | cat::IRQ).on_track("VPro irq line").in_group(GFX_GROUP).with_arg("flags&enable"); +pub static ODSY_IRQ_LINE_LEVEL: crate::PfLevel = crate::PfLevel::new(); +/// The driver has the low-water interrupt enabled: its flow control is +/// waiting for the command FIFO to drain. +pub static ODSY_LOW_WATER_WAIT: EventDef = EventDef::new("low-water enabled", cat::GFX | cat::IRQ).on_track("VPro flow control").in_group(GFX_GROUP); +pub static ODSY_LOW_WATER_WAIT_LEVEL: crate::PfLevel = crate::PfLevel::new(); pub static ODSY_CFIFO_LOW_WATER: EventDef = EventDef::new("cfifo low water", cat::GFX).on_track("VPro irq").in_group(GFX_GROUP).with_arg("level"); /// One slice of the board's front-end thread running queued stores (arg: /// stores waiting when it began), and an access draining the queue on its own diff --git a/src/sn.rs b/src/sn.rs index 82f6093de..6fe522b39 100644 --- a/src/sn.rs +++ b/src/sn.rs @@ -805,6 +805,12 @@ impl Machine for device in &io.monitor { monitor.register_device(device.clone()); } + // The guest timeline follows the first CPU's retired instructions. + #[cfg(feature = "perfetto")] + { + crate::perfetto::set_guest_cycles(Some(first.cycles_ptr())); + monitor.register_device(Arc::new(crate::perfetto::PerfettoMonitor)); + } let mut nat = None; let net = GatewayConfig::from_network(&cfg.network()); if let Some(link) = Link::with_gateway(net.clone())? { @@ -860,6 +866,9 @@ impl Worksta for c in self.cpus() { c.clone().as_device().stop(); } + // The guest clock points into this machine's first CPU. + #[cfg(feature = "perfetto")] + crate::perfetto::set_guest_cycles(None); for d in self.io.devices.iter().rev() { d.stop(); }