Skip to content

devlog: finish the tracing cleanup - #937

Open
jamesbraid wants to merge 11 commits into
mainfrom
jb/trace-finish
Open

jamesbraid wants to merge 11 commits into
mainfrom
jb/trace-finish

Conversation

@jamesbraid

@jamesbraid jamesbraid commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Tracing still ran on private mechanisms next to log: a per-module file writer, ad hoc rate limiters on guest-driven stderr prints, and six debug commands with their own rings or files.

  • log writes every module's lines through one file writer, so log net,seeq file PATH works. The file is written out on log status, stop, exit and panic (and in the GUI's stop path); a killed process loses what was still buffered.
  • notice! says a message the first four times per place, then at powers of two, and replaces the per-device limiters (unknown VINO registers, unimplemented SCSI commands, bus errors, refused stores).
  • Removed scsi wdt, block debug, mc vdma, crime irqlog/o2 crimelog, pdma polls and the dead tlb debug. Each is now a trace point: log scsi, log rex3, log mc, crime trace FILE irq, log pdma.*, log mips.tlb.
  • IRIS_DISPLAY_VERIFY becomes a monitor command, display verify on|off: it changes what the display does, so it is a switch, not a trace point.
  • The Bridge's 17 log::debug! calls and the IOC3's three are dlog! now.
  • iris-checks follows calls made through relocated slots (its own commit). The hot-path check never saw them; the control test fails on the release-features build without it, and with it the check found formatting calls in breakpoint_hit_reason, which runs only once a breakpoint has matched, so it joins COLD.

The rings kept look-back with nothing turned on; their replacements are forward only. The CHANGELOG lines are in #932.

11 commits, net -242 lines (+382 -624). Nothing was added on a per-access path. Tested with nextest in the default and jitv2,rex-jit,gputrace sets and the release-features iris-checks run; per-commit cargo check --all-targets is clean.

Every guest read of a DMA channel's CBP register pushed a time stamped
entry onto a 64-entry ring, with a clock read, read back by an
undocumented `pdma polls N`. The same facts belong in the channel traces
`log pdma.scsi0` already gives.

A CBP read is now a line in a developer build when its channel is on
(`log pdma.hal0`, `log hpc3/c1`), and a plain build does nothing for it
beyond the poll counter `pdma status` shows. `pdma polls` is removed;
its ring of the last 64 polls could be read with nothing turned on, and
the trace is forward only.

Left alone: `pdma dump`, which writes the payload of each DMA transfer
to a `.bin` file in the current directory. That is a data capture to
open in other tools, not text, and `log` has no place for it.

Production lines: +1 -19
The `tlb` help and debug.md offered `tlb debug <on|off>` to log TLB
operations, but the command has no such subcommand: it answered
"Unknown TLB subcommand". TLB reads, writes and probes are logged by
`log mips.tlb on`, which debug.md now says.

Production lines: +2 -2
`block debug on` opened `block.log` in the current directory and
`log_block` and the HOSTRW paths wrote each draw, its colours and the
host words that feed it there, behind a mutex of their own and beside
the `dlog!(Rex3)` lines for the same draws.

They are `dlog!` on `rex3` now, so `log rex3 on` and `log rex3 file
PATH` carry them with the rest of the REX3 trace, in developer builds as
before. `block debug` and the file are removed. `rex3` is one point, so
the block lines come with the per-register lines; there is no way to ask
for the block lines alone.

Most of the diff is the `log_block` body moving out of its `if let`
(`git diff -w` shows it).

`draw debug` and `disp debug` draw an overlay on the framebuffer, a
display feature, and stay.

Production lines: +77 -130
The Bridge had 17 `log::debug!` calls next to its `dlog!(Bridge)` ones:
dropped interrupt packets, DMA with no translation entry, a link that is
down. They showed only with `RUST_LOG=debug`, so `log bridge on` missed
the very refusals it exists to find, and the host logger's switch
sat beside the trace one.

They are `dlog!` on `bridge` now, always built, as the existing ones
were. The `log::warn!` about a reset pin the guest dropped is a notice,
so it is rate limited with the others.

The IOC3's three `log::debug!` lines (unimplemented registers, a
parallel read with no peripheral) are `dlog!` on `ioc` likewise. The
Bridge warning and the IOC3's narrow-access warning printed nothing by
default before, because the host logger hides `warn`; as notices they now
show on stderr.

Production lines: +20 -20
`crime irqlog` kept an 8192-entry ring of the guest's accesses to the
four CRIME interrupt registers, read back by `crime irqlog n` and `o2
crimelog PATH`. `crime trace FILE irq` records those same registers,
with a time stamp, and is the one trace for the chip. The ring also put
a flag check in every CRIME register access of a non-`lightning` build.

The ring, its flag, the two commands and their test are removed. Two
things are lost: a record in a plain build (`crime trace` needs
`gputrace`, on with `developer`, as every board trace does), and
look-back, since the ring could be read after an interrupt storm with
nothing turned on and a trace is forward only.

Production lines: +3 -72
@jamesbraid
jamesbraid marked this pull request as draft November 29, 2026 23:03
@jamesbraid
jamesbraid force-pushed the jb/trace-finish branch 2 times, most recently from b1ef2bc to e38bb11 Compare November 30, 2026 00:07
Every trace point held its own `Mutex<Option<BufWriter<File>>>` and
flushed after each line, so a point that logged to a file cost a
syscall per line on the emulating thread, and `log X file` refused a
second module because two writers on one path overwrite each other.

The points now carry a flag, and one `TraceWriter` (the writer thread
the board traces already use) takes the lines of every flagged point,
in order. `log net,seeq file PATH` works; a second path is refused
while one is open, and the file closes with the last module sent to it
(`log all file off`). The writer thread takes a megabyte at a time, so the
file is forced out on `log status`, in `stop_and_flush` and `exit_process`
(before its early return), in the panic hook (a `try_lock`, so a panic
inside a write cannot deadlock) and in iris-gui's two machine stop
helpers, which Stop, Restart, SyncDisks and Quit all use. A killed
process still loses what was buffered; the old per-line flush kept it.

Production lines: +47 -25
The hot-path check decoded only direct calls (`call rel32`). A call
through a slot the loader fills (`call *slot(%rip)`, which the compiler
emits for some functions in the PIE binary) was skipped, so whatever it
reached was never checked, and a formatting call made that way left no
trace for the control test either.

The check now reads the executable's `R_X86_64_RELATIVE` relocations,
maps each slot to its target and follows the call. Once it could see
them it found four `alloc::fmt::format` calls in
`MipsExecutor::breakpoint_hit_reason`. That function builds the stop
note for a breakpoint that matched; its two callers, the monitor's run
loop and the step loop's `EXEC_BREAKPOINT` arm, call it once and break
out, so it is cold, and it joins the other print-by-design functions in
`COLD`. The check itself is no looser: it sees more, and the one new
exemption is justified by those call sites.

Measured on the release-features build (`lightning,jitv2,gpujit,idle-pause,hostgl`):
without this, `disassembly_shows_formatting_calls_in_control_methods` fails
("no formatting call in the control methods") once the bus-error report
prints through `notice!`; with it, all four `iris-checks` tests pass.

Production lines: +0 -0
Messages a guest can trigger over and over, and a user should see in
every build ("unknown VINO register", "unimplemented SCSI command",
"bus error on uncached read"), were bare `eprintln!`s that flood stderr
when the guest polls, or each carried its own limiter: a per-register
HashMap in REX3, a power-of-two counter field in the CPU, an
`AtomicBool` in the IOC3.

`notice!(key, ...)` replaces them. The first four times per call site
and key are said, then each power of two, with the count. The key tells
apart the things one site reports (a register, a PC and page); a site
with one thing to say passes `()`. Arguments are formatted only when a
notice is due, and the call sits only on paths that already failed. The
REX3 helper, the CPU's refused-store counter and the IOC3 flag are gone.
The notices go to stderr only: a monitor client is not told, and `log
status` does not list them.

Moved onto it: the five unknown-register prints in the VINO, the SCSI
unimplemented command, the two WD33C93A warnings, the CPU's four
bus-error reports and the refused posted store (keyed by PC and the
page of the bad address, so a probe loop at one instruction is limited
per page and a new page or instruction is not; the fetch error is keyed
by page). A probe loop's intermediate addresses are therefore no longer
all printed. The two `println!` warnings in the REX3 display code go to
stderr with their own once-per-change dedupe, which stays.

Behaviour change: REX3 said the first 8 per register and kind and now
says 4 and then powers of two; the refused-store count in its text now
comes from the helper's suffix. Left as they are: the HQ3 DMA counter
(it is saved in the board's snapshot state), the DS1685 NVRAM failure
(it re-arms on a successful save), the one-shot notice in the JIT cache
and the `jitv2_smc_check` report (a dedupe on a pair, not a rate), and the
hash-set de-duplications in the HQ4, mgras, crime-re and aic7880 notes,
which key on message text.

The release hot-path check's positive control read the formatting call in
`report_bus_error`. That call is now `notice_say`, so the check lists it
as a formatting target. `notice_say` is `#[inline(never)]` so that it
keeps a symbol of its own and the control cannot vanish by inlining.

Production lines: +58 -43
The WD33C93A kept its own 4000-entry ring of register accesses and
sequencer steps (`wdt!`, 28 sites), dumped by `scsi wdt [N]` or `scsi
wdt file PATH`, beside 44 `dlog!` sites on the same module. Two
switches for one device, and the ring was lost on a crash.

The 28 sites are `dlog_dev!` on the controller's module (`scsi` or
`scsi1`), so they cost nothing in a build without `developer`, as the
ring did, and now follow `log scsi on`, `log scsi file PATH` and slot
selection (`log scsi0/t1 on`). The ring's collapse of consecutive
identical lines into `(x N)` is gone: a polling loop now logs every
poll, so a long run makes a long file. The ring could also be read after
something went wrong with nothing turned on; the trace is forward only.
The ring's register-access lines repeated lines the module already
logged (`Read FIFO`, `Read ASR`, `Write AR`, `Write Reg`); those five are
dropped so `log scsi on` prints each access once. `scsi wdt` is removed.

Production lines: +27 -140
The check of the boards' "nothing changed" verdicts was switched on by
the `IRIS_DISPLAY_VERIFY` environment variable, read once at first use.
It changes what the display does (it composes every frame a board would
have left and compares it with the one on screen), so it is a switch,
not a trace point, and it belongs with the monitor's other switches.

`display verify on|off` sets an atomic that `verify::on()` reads, as the
variable's one read did; the findings stay on stderr. The variable is no
longer read. The command is served by `LogDevice`, which every machine
already registers.

Production lines: +18 -5
`mc vdma on` opened `vdma.log` in the current directory behind a mutex
of its own, and the transfer paths wrote the engine chosen, each chunk
and the host time into it: the same shape as `block debug` and `pdma
polls`, and a second switch beside the `dlog!(Mc)` lines.

The writes are `dlog!` on `mc`, always built as the file's were (the log
was meant for `lightning` builds, which have no `dlog_dev!`), and cost
the same one relaxed load per chunk that `vdma_debug_enabled` did. `mc
vdma`, the flag and the file are removed; the µTLB snapshot taken for
the transfer header follows `log mc` too.

The MEMCFG1 line printed on stderr when MEMCFG1 is synthesised for
extended RAM repeated the `dlog_dev!` written on the line before it; the
stderr copy goes.

Production lines: +45 -100
@jamesbraid
jamesbraid force-pushed the jb/trace-finish branch 2 times, most recently from e801947 to c6ad422 Compare November 30, 2026 12:05
@jamesbraid
jamesbraid marked this pull request as ready for review November 30, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant