Repository navigation
cpu: recognise IRIX 6.5's idle loop and park it - #339
Merged
Merged
Conversation
IRIX 6.5 never parked under idle-pause. The detector hashed PC+GPRs and required an exact repeat, but 6.5's idle path is a ~470-byte scheduler loop (~89 instructions) with calls to spl and the ll/sc lock and stores to kernel globals; its registers evolve every iteration, so the hash never repeated. It also matched short device-poll loops (lbu/andi/bne -3 on a SCSI bit) that must keep running. Replace it with a PC-cluster sample. The batch loop calls sample after each ten-instruction group; sample records the PC every 32 calls (~320 instructions per record, ~10,000 per ring of 32). update sorts the samples into PC-space clusters and parks when one kernel cluster holds at least 12 samples with 12 distinct PCs. User-mode samples are tolerated up to a quarter of the ring. Short DELAY/poll loops, the ll/sc lock spin and user code are never parked. All previous rules remain: IE/IM, pending-line wake, masked-wake back-off, Compare armed. Parking starts 60 s after the CPU thread starts (IRIS_IDLE_WARMUP_SECS overrides) so boot is not sliced. idle on|off|status switches parking at runtime and reports counters; idleprof stats prints the park counters. The ci_clock ip7 unit tests now advance Count by retired cycles, so the required ci_clock,idle-pause suite passes. Measured on IRIX 6.5 IP22 (R4400, fresh disk, lightning,idle-pause build): settled getty 1-2% host CPU; cold boot 35 s. ci_clock,idle-pause boot 52 s; its getty 16-19% (guest time is retired instructions). IRIX 5.3 not tested (no image).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This ports the IRIX 6.5 idle-loop detector from Jupiter Belic's
irix7/irisfork (PR #114, commitsee61088and52e5690) onto current upstream. With--features idle-pause, a settled IRIX 6.5 IP22 getty drops from ~100 % host CPU to ~1-2 %, and cold boots are not slowed.Why the old detector never fired on 6.5
idleprofat a settled 6.5 IP22 getty (upstream build, xdm/amstart killed) shows the idle path is not a tight branch: it is a ~470-byte scheduler loop (0x880daedc..0x880db0b4, ~89 instructions) with calls tospland the ll/sc lock and stores to kernel globals. The capture:Its registers evolve every iteration (the run-queue scan rotates state), so the PC+GPR hash never repeats exactly. The same hash did match a 3-instruction device-poll loop seen during boot (
lbu/andi/bne -3waiting on a SCSI bit), which must keep executing — parking it stalled the boot. The idle loop has no contiguous window covering half the samples (the helpers are far away), which is why the detector clusters the samples instead.Detector
The run loop calls
sampleafter each ten-instruction group;samplerecords the PC every 32 calls, so a record is ~320 guest instructions and the ring of 32 covers ~10,000.updatesorts the samples into PC clusters (consecutive PCs ≤256 bytes apart) and parks when one kernel cluster holds ≥12 of the 32 samples with ≥12 distinct PCs. User-mode samples are allowed up to a quarter of the ring (a syscall wake runs a few user instructions between kernel stretches), but a user-dominated ring is refused.That accepts IRIX 5.3's 14-instruction loop and 6.5's 89-instruction scheduler path while rejecting 2-instruction DELAY loops, 3-instruction device polls, the 8-instruction ll/sc lock spin and mixed work. The existing park rules are unchanged: interrupts enabled, a mask bit set, nothing pending, Compare armed; wake on any pending line; the masked-wake back-off (no re-park for ~20 ms after waking on a line the guest cannot take). Parking waits 60 s after the CPU thread starts (
IRIS_IDLE_WARMUP_SECSoverrides) so boot runs at full speed.New monitor commands:
idle on|off|status(runtime switch, park/sleep/wake counters, last window) andidleprof stats(the same counters).The
ci_clockip7 unit tests now advance Count by retired cycles instead of sleeping, so the required--features ci_clock,idle-pausesuite passes; no clock semantics change.Measurements
Host: 6-core i5-8500T @ 2.1 GHz. Guest: IRIX 6.5 IP22, R4400, fresh sparse copy of the rig disk per run,
nvram-rig.bin, headless, telnet forwarded;killall amstart; killall xdmafter boot, then settle. Release build features:lightning,idle-pauseunless noted.lightning,idle-pause, 4 × 10 slightning,ci_clock,idle-pausecold boot to loginci_clock,idle-pausegetty, 3 × 10 scpu stop; cpu startdateacross a parkNote on
ci_clock: guest time is retired instructions, so the timer handler is a much larger share of host time (~16-19 % here). The wall-clock build is the one the 1-2 % figure describes. A later wall-clock boot on the same host under load average ~14 (three other emulators running) took 101 s, so the 35 s figure is a quiet-host sample; parking itself was not the cause.Not tested: IRIX 5.3, because this rig has no 5.3 image. Its 14-instruction loop fits the cluster rules and the park/wake mechanics are unchanged.
Tests
cargo test --workspacejitv2cargo test --workspace --features jitv2idle-pausecargo test --workspace --features idle-pauseci_clock,idle-pausecargo test --workspace --features ci_clock,idle-pauseNew tests cover the 6.5 window, distant helper calls, short device polls, a 2-instruction DELAY loop, user-mode loops, a moving window, the masked-wake back-off, and wake on Compare under both clock models. The masked-interrupt park test now samples the PC as the run loop does.
Provenance
This port is derived from Jupiter Belic's work in irix7/iris: PR irix7#114, commit irix7@ee61088 and docs correction irix7@52e5690. Taken from that work: the PC-cluster detector, the 60 s warm-up, the masked-wake back-off, the park statistics and
idle/idleprof statscommands, the run-loop sampling points, and theci_clocktest adaptation. The capture and measurements were repeated here on upstream.