Repository navigation
ci_clock: make two runs of one PROM byte-identical, with the choice confined to the clock - #892
Open
jamesbraid wants to merge 5 commits into
Open
jamesbraid wants to merge 5 commits into
jamesbraid wants to merge 5 commits into
Conversation
Three things in the ci_clock build made the guest's time depend on how it read the clock, or on the host. Count kept no sub-tick remainder. Each read moved the cycle anchor on by the nanoseconds its whole ticks used, divided down to whole instructions. At 90 MHz a tick is 11.1 ns, so the anchor moved a full 10 ns instruction per tick and the rest was counted again on the next read. A guest that reads Count every other instruction, as a delay calibration does, saw one tick per instruction (100 MHz) instead of the R5000's 90 MHz. The remainder is now kept exactly, in nanoseconds times Hz, and the anchor advances to the current cycle on every read. A Count write, a re-anchor and a reset start it over. The host-clock path is unchanged. The Compare deadline check raised IP7 and bumped the tick counter without claiming the deadline's delivery ticket. The handler's next Count read then crossed Compare, found the ticket still armed and delivered it a second time, so the tick counter ran at 2000 Hz against the 1000 Hz the guest programmed. The check now claims the ticket, as the host timer does. Two tests armed the deadline without one, which no guest can do, and now arm it through a Compare write. A WAIT with interrupts enabled stalled inside one instruction, advancing time by host time until an interrupt arrived. Idle time was then a function of the host, and no deadline check ran while it waited. Under ci_clock WAIT now answers retry, as the masked case already does, until an interrupt the IM bits pass is pending; each retry is a dispatch, so time is counted per instruction. The stall loop is unreachable under ci_clock, so its Compare check goes, and the two tests of the stall's pacing apply only to the host-clock build. Production lines: +34 -14
jamesbraid
marked this pull request as draft
November 27, 2026 23:24
With ci_clock the Indy's and the O2's machine time is CPU 0's retired instructions, but the timers still ran on the host timer thread. Their callbacks (the 8254, the UARTs, the display's retrace and line events, the O2's device service pass) then fired at host-chosen instructions, so two runs of one PROM diverged. A manager on a counting clock now spawns no thread. CPU 0 runs TimerManager::run_expired between batches with the executor unlocked, so a callback that needs the executor cannot deadlock. It is the host thread's own loop, made generic over the time it reads and over having a waiter, so there is one scheduler. Deadlines are machine time, which is why add_recurring now takes a first delay as a Duration, as add_one_shot already does, in place of an Instant that could not be machine time. A batch is not the only place time must be checked. Compiled code stays in a region until the interrupt word is nonzero, and Compare is the only deadline it sees. A guest that never arms Compare (the IP28 kernel leaves it at zero) would spin in a compiled loop for a whole Count wrap. The cycle threshold that already ends such a spin for Compare is now the earlier of Compare and the manager's next deadline. Reaching a timer's deadline claims no IP7: it sets a free high bit in the interrupt word, kept out of Cause, WAIT and park wake like the park bit. Arming a timer from any thread sets the same bit, so the loop leaves its batch, runs the timers, clears the bit and sets the next deadline. Only the CPU thread writes the threshold. Machine setup shares one clock constructor, Clock::cpu_or_host, and set_cpu_cycles is now a no-op on a host clock, which removes the cfg pairs at those sites. The display refresh runs from the timers on a counting clock, composes a requested frame on the caller's thread while the CPU is stopped, and the O2 service pass is a recurring timer. CRIME reset, power-off and the flash save stay on the service thread because they stop and start the CPU. Battery clocks start at 2026-01-01 so the date does not depend on when the run is made, and idle-pause stays off on a counting machine because it paces the CPU on host time. The manager finds the CPU's interrupt word through a pointer it keeps under its own lock, set when the machine is built and cleared by the core's Drop before the word goes. The manager can outlive the core, as the display holds it too, so a late timer then wakes nothing. O2Machine now stops the machine clock when it drops, as Machine does, so nothing reads the CPU's cycle counter afterwards. Default builds only change in shape: add_recurring's argument, the generic timer loop and an unused run_expired. Production lines: +276 -64
jamesbraid
force-pushed
the
det-minimal
branch
2 times, most recently
from
November 30, 2026 11:05
3a8d9bd to
6c125cb
Compare
A SCSI channel caps how far the disk may read ahead of the CPU's last look at CBP, and forgets the look after 50 ms. That window was host time, so it kept running while the machine was stopped in the monitor or a debugger, and a guest that polled CBP just before a stop found the cap gone on resume. It now reads the machine clock, which holds still while the machine is stopped, and the window is exactly 50 ms of what the guest saw. It also removes a host-time read from the path a counting clock must keep out of, which the instruction-driven clock needs. A CBP poll now calls Clock::now() where it called Instant::now(); both are a few atomic loads and a clock read, and neither is per instruction. Each channel takes the clock at construction. Production lines: +9 -9
A DCB address-12 command holds STATUS.BACKBUSY up for 1 ms, which was 1 ms of host time. A machine stopped in the monitor, or a guest that ran slower than the host, then saw BACKBUSY end at a different point of its own execution each time. It now lasts 1 ms of the head's clock, which is machine time, so a run reads the same STATUS however long the host took. The instruction-driven clock needs this for repeatable runs. BACKBUSY was never cleared when it ran out, so once any DCB command had set it every later STATUS read compared against it. That read is now a weak upgrade and a boxed clock call, not an Instant::now(), so the read drops the deadline as soon as it has passed and the cost is paid only inside the 1 ms window after a command. Production lines: +10 -6
The MC's DMA engine, REX3's GFIFO processor, CRIME's rendering engine, the AIC-7880 and the WD33C93A each ran on a thread of their own. When such a thread finishes a transfer, or what a status read sees of it, depends on the host's scheduler, so two runs of one PROM diverged even with the timers already on CPU 0's instructions. Where the build counts instructions the five now run in the access that wakes them: no worker, and a kick runs the loop until nothing is left, as the AIC-7880 already does when it has no worker. REX3 and CRIME do so once started, and queue as before until then. They read clock::COUNTING, which is a constant false in a default build. The MC leaves RUN latched for one read after a trigger, because the Indy PROM wants it set on its first look and clear on its second. The machine constructors assert that a counting build gives these engines a counting manager. The WD33C93A cannot wait for its HPC3 channel inline. A driver that writes TRANSFER_INFO before it arms the channel used to be waited for up to 100 ms of host time, but inline the waiter is the CPU that would arm it. A counting chip skips the wait and takes the pause path it already has, which keeps the data and raises the unexpected-phase interrupt at once. A one-byte transfer pauses the same way instead of retrying. IRIX and the PROM arm first, so neither is affected. The chip's deferred status interrupt, which the worker raised after spinning 10000 cycles, is raised with the command, as --no-scsi-deferred-int does. The status reads of REX3 and CRIME report an engine that has finished, which an inline engine always has. A test runs the Indy's built-in PROM for 40 ms of machine time twice and compares the registers, Count, console log and NVRAM. It sets the JIT's compile mode to sync, as any run that compares runs must: compiled code sees a deadline only at its cycle flushes, so which regions are compiled by when decides where a timer lands. The Ethernet is not covered. The SEEQ's thread and the host network backend run on host time, so a run whose guest sends or receives packets can still differ; the PROM sends none in this window. In a default build this changes nothing but dead COUNTING branches. Production lines: +83 -12
jamesbraid
force-pushed
the
det-minimal
branch
from
November 30, 2026 12:41
6c125cb to
d50bc69
Compare
jamesbraid
marked this pull request as ready for review
November 30, 2026 12:56
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.
A
ci_clockbuild already counts Count and Compare in retired instructions, but timers, the display refresh and the device engines still ran on host time or their own threads. Two runs of one PROM diverged within a few thousand instructions, so a snapshot check could not tell a change from scheduling noise, and a PROM run could not be diffed against another emulator's.Now two runs of the Indy's or the O2's PROM that use no network agree on registers, Count, serial output and NVRAM, and in the two-run checks below the screen hash too. Only the uniprocessor Indy and O2 count; every other machine keeps host-time timers.
The commits, in order:
ci_clockget the guest's own rates: Count keeps its sub-tick remainder, the Compare check claims its delivery ticket, and WAIT counts idle time per instruction instead of stalling on host time.TimerManager::run_expired), with no timer thread.COUNTINGbranches, and adds the two-run test.Developer impact
A device author does nothing.
Timer,add_one_shotandadd_recurringtake the same callback and run on the CPU on a counting machine, on the timer thread elsewhere. The one switch isclock::COUNTING(constantfalseby default) orClock::is_counting: a device with its own thread tests it and runs inline instead.add_recurringtakes its first delay as aDuration, asadd_one_shotdoes.Default builds
The timer loop is generic over its time source,
add_recurringtakes aDuration, and each HPC3 channel holds a clock. Two behaviour changes, each in its own commit:Instant::now()), so it holds still while the machine is stopped.Known limits
--jitv2-compile sync): compiled code sees a deadline only at its cycle flushes, so which regions are compiled by when moves where a timer lands. The two-run test sets it.chime_tests::o2_mace_chimeis slow in a dev build.Review
run_expired: callbacks run with the manager unlocked, on the CPU thread, so a slow callback now stalls the CPU (ci_clockonly).TIMERS_BIT, kept out of Cause, WAIT and park wake like the park bit. Only the CPU thread writes the cycle threshold.Verification
cargo check --all-targetsclean on each commit, default (workspace) and--features ci_clock.jitv2,rex-jit,gputrace6,247 passed;cargo ci-clock23 passed. The newci_clock_two_runs_of_the_indy_prom_end_in_the_same_statebuilds the Indy, runs its built-in PROM for 40 ms of machine time twice, and compares registers, Count, console log and NVRAM.ci_clockbuild: two runs of the Indy PROM stopped at the 30,001st hit of one PROM address, and of the O2 PROM at the 50,001st hit of another, gave identical serial log, NVRAM, Count, screen hash and monitor status. The same Indy pair on a default build differs in NVRAM and status, and sometimes in screen hash. A 10-minute Indy run did not stay identical (NVRAM differed), which is the Ethernet limit above or a host-chosen stop; it is not claimed here.