Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ hashes are given where a change is easiest to understand by reading the commit.

## November 2026

### jitv2 flushes

- Under jitv2, a single-processor machine no longer hangs when the CPU runs out
of JIT pages (or `j2 flush`, `j2 inline on` or a cache change on the O2 asks
for a flush) while a compile worker is flushing its full code arena. A
worker's flush no longer restarts a CPU the monitor has stopped.
### Linux file choosers

- The Linux AppImage of iris-gui now opens the desktop's file chooser through
Expand Down
15 changes: 14 additions & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,11 @@ one `Physical`. `src/cpu/smp.rs` holds what they share:
on. Two callers take turns, and the one waiting counts as parked. Remapping
memory and flushing jitv2 go through it. A remap that moved memory then asks
every CPU (`World::layout_changed`) to forget the addresses of its JIT code
pages; no compiled code is dropped for it (section 8).
pages; no compiled code is dropped for it (section 8). A CPU belongs to one
`World`: every machine hands its world to its CPUs' jitv2 pool
(`share_jitv2`, `attach_pool`), and a CPU built without one (in a test) gets
a world of one (`World::solo`, in `MipsCpu::new`), so its pool's flushes and
its own take turns the same way.

The monitor reaches CPUs through `CpuMonitor` (`src/cpu/cpu_monitor.rs`), on
every machine: it routes each command and the commands themselves live in
Expand Down Expand Up @@ -1408,6 +1412,15 @@ code into host code with Cranelift. The concepts:
and stores are plain host accesses, so on a multiprocessor a guest `SYNC`
compiles to a host fence on hosts that are not x86 (the interpreter's
`SYNC` does the same).
- **Flushes take turns through the CPU's world.** A CPU flushes from inside
`World::stop_others` and joins the compile workers there, holding the
`Jitv2` lock. A worker that leads a flush takes the world with `try_lead`,
parks the CPUs, and only then takes the `Jitv2` lock; it gives way if the
pool stops while it waits. So a worker never halts a CPU thread (which may
be joining that worker) and never waits on the lock a joining thread holds.
Workers get their start-up data (cache geometry, JIT constants) before they
spawn, for the same reason. A thread that runs no CPU stops the pool with
`Jitv2::stop_pool`, which joins with the lock released.
- **Uncached fetches the board decodes apart.** A frame table is indexed by
the physical address of the fetch. The IP35 reset PROM answers an uncached fetch
at 0x1fc00000 whatever RAM sits behind the cached view there, so a board whose
Expand Down
20 changes: 20 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,26 @@ registers where it stopped (on the O2, also the words at physical 0x1000 and
0x4000). [clanker/testing/ci-unattended-irix-boot.md](clanker/testing/ci-unattended-irix-boot.md)
has the details.

## jitv2 flush race

`tools/jitv2-flush-race.py` boots a single-CPU guest under `--ci` with
`IRIS_JIT_ARENA_FLUSH_MB=1`, so the compile workers fill their code arena and
flush it themselves many times during the boot, and meanwhile runs `stop`,
`j2 flush`, `start` at the monitor in a loop. Each `j2 flush` joins the compile
workers; one that waits on a worker leading a flush of its own never returns,
and the script fails with exit status 1 (and, given `--stacks`, saves every
thread's stack first). It passes when the race ran for `--seconds` with at
least `--min-worker-flushes` worker-led flushes, and reports how far the guest
got on its serial log.

```sh
tools/jitv2-flush-race.py --iris target/release/iris --config ci-ip28.toml \
--monitor-port 20300 --seconds 600 --serial-log console.log --stacks stacks.txt
```

The config is any `iris.toml` for a machine that boots by itself, its disks
with `overlay = true`: under `--ci` the overlay is kept in `$TMPDIR`, which is
what makes it safe for the script to kill an iris that hung.
### OpenBSD on the O2 (local)

`tests/openbsd/boot-openbsd69-o2.toml` boots an O2 disk with OpenBSD 6.9 on
Expand Down
1 change: 1 addition & 0 deletions clanker/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The MIPS JIT (`src/cpu/jitv2/`): design, Cranelift codegen, delay slots, invalid
| [code-size-does-not-predict-speed.md](jitv2/code-size-does-not-predict-speed.md) | measure | Emitted-code size did not predict speed — four changes, one marginal win |
| [codegen-gotchas.md](jitv2/codegen-gotchas.md) | rule | JIT v2 codegen gotchas |
| [compile-pool-size-on-small-hosts.md](jitv2/compile-pool-size-on-small-hosts.md) | rule | The compile pool is sized for the host as well as the guest: one worker per guest CPU, capped by the host's usable CPUs; the guest's own CPUs are not counted against it |
| [compile-workers-park-the-cpu-never-halt-it.md](jitv2/compile-workers-park-the-cpu-never-halt-it.md) | rule | A compile worker parks the CPU for a flush through the CPU's world, never halts it; every CPU has one world (`World::solo` when alone) |
| [compile-pool-starts-after-the-windows.md](jitv2/compile-pool-starts-after-the-windows.md) | rule | Start the compile pool after the ppmem windows: workers read the cache geometry once, and an early one compiles every load and store as a call out |
| [compile-workers-park-instead-of-polling.md](jitv2/compile-workers-park-instead-of-polling.md) | rule | The compile pool parks; the producer wakes it: an idle worker cost 1.4% of a core polling every 200µs |
| [compile-time-profile.md](jitv2/compile-time-profile.md) | measure | An IRIX boot is bound by how much jitv2 compiles: workers saturated, where a compile's time goes (regalloc 37%, egraph 20%), and why a faster allocator or `opt_level=none` only buys more recompiles |
Expand Down
57 changes: 57 additions & 0 deletions clanker/jitv2/compile-workers-park-the-cpu-never-halt-it.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# A compile worker parks the CPU for a flush; it never halts it

Status: rule (issue #306, November 2026).

**Symptom.** A single-CPU machine under jitv2 hangs: the CPU thread sits in
`CompileQueue::stop` (inside `flush_from_cpu_thread`, holding `Mutex<Jitv2>`),
joining a compile worker, and that worker sits in `run_leader_flush`, in
`cpu.stop()` → `MipsCpu::halt`, joining the CPU thread (or, when the monitor
holds the executor, waiting for the executor lock, or for `Mutex<Jitv2>`).

**Cause.** Two flushes, two leaders. The CPU flushes when its page pool runs
out (or for `j2 flush`, a cache-geometry change); a worker flushes when its
code arena fills. On a machine with several CPUs the two already took turns
through `World` (`stop_others` on the CPU side, `try_lead` plus a poll of the
pool's run flag on the worker side). A CPU with its own pool had no world, so
the worker stopped it with `Device::stop`, which joins the very thread that
may be joining the worker.

The start-up half of #306 (a worker taking `Mutex<Jitv2>` to read
`dc_geometry` / `jit_consts`) was fixed earlier, in 95031882: workers get those
values before they spawn.

**Rule.**

- Every `MipsCpu` has a world: `MipsCpu::new` gives it `World::solo(park)`
and sets it on the executor (`jitv2_world`) and on its own pool.
`share_jitv2` replaces it, on the pool too.
- A CPU belongs to one world. Two worlds would both hold it with
`HOLD_WORLD`, and one's release would let it run under the other. Every
machine now has a world of its own (bank remaps call `layout_changed` on
it), so every machine passes it through `share_jitv2` and `attach_pool`,
also to a lone CPU and to a node whose processor module has a pool of its
own (`share_pool`). The pool and the CPU must hold the same world: with two,
the CPU's `stop_others` and the worker's `try_lead` do not take turns and
the deadlock is back. `World::solo` remains for CPUs built without a
machine, in tests.
- A world finds the caller's slot by the CPU id the slot records
(`ParkSlot::new(cpu, ..)`), so a world of CPU 3 alone works too.
- A thread that runs no CPU stops the pool with `Jitv2::stop_pool`, which
joins with `Mutex<Jitv2>` released. `CompileQueue::stop` under the lock is
for the CPU side, inside `stop_others`.
- The `cpu.stop()`/`cpu.start()` branch of `run_leader_flush` remains only for
a bare `CompileQueue` in tests.

**Test.** `a_cpu_flush_inside_a_worker_led_flush_takes_its_turn` (jitv2.rs)
forces a worker flush (`PoolBarrier::force_flush`, test-only) against a fake
CPU that flushes the moment it is held. Without the world it deadlocks and the
test fails after 20 s.

**End to end.** `tools/jitv2-flush-race.py` (see `TESTING.md`) boots a guest
with `IRIS_JIT_ARENA_FLUSH_MB=1` and loops `stop` / `j2 flush` / `start` at the
monitor. On the Indigo2 R10000 with IRIX 6.5.22, before the fix `j2 flush`
hung after 22 rounds (73 s) and after 1 round (during PROM diagnostics): the
monitor thread in `CompileQueue::stop` joining `jitv2-compile-0`, the worker in
`MipsCpu::halt` waiting for the executor lock the monitor holds. With the fix
it ran 1115 rounds in 600 s, 1234 worker-led flushes, and the guest reached its
login prompt.
Loading
Loading