Background · Chapter 4
Deterministic timing
A control core is a processor with branches, stalls and shared buses, and its timing wanders. The pulses it schedules must not. This chapter explains how RISC-Q separates the two: the firmware issues every write well ahead of its start time, and the hardware next to the converter lands it on exactly the right batch. It states what the Lean proofs guarantee, and what the simulator measures where proofs stop.
You need the channel, pulse table, fire and timed queue of chapter 3. The theorems quoted
here are in QControl/RiscQ/Timing.lean, which you can open and read beside this
page. Lesson B2 works through the same ideas with exercises on live runs.
1Why schedule ahead
If the core is fast, why not just write fire at the moment the pulse should start?
In this section: the sources of timing variation between a store instruction and the converter, and the idea that removes them.
Count what lies between a store instruction and the DAC. The store crosses the bridge and the link, 1 + L batches. The channel pushes the fired entry into its queues, 2 more. Each parameter then crosses its part of the pulse generator, from 2 batches for the duration to 35 for the phase. The samples cross the adder tree to the DAC port, 6 more on the ring. And before any of this, the core itself has to reach the store: a taken branch costs 5 extra batches in the model's cost model, a load or store 1, a read of a measurement result stalls until the result has settled, and a message to the hub can wait behind other cores' messages. If the start of a pulse depended on all of that, it would move whenever the program changed.
RISC-Q's answer is to make the start time data instead of a moment. The firmware writes the start time into the channel's
startTime register and then fires; the channel's timed queues hold
every parameter until its own release batch, startTime − lead. Writing early is harmless; the value just waits in a
queue. Writing late is the only failure. The firmware therefore issues each write a fixed number of batches before its start
time, the lead.
x90 of the feed-forward run on qubit 0: the core waits until
batch 217, stores the phase offset, the start time 320 and the fire, and the fire reaches q0.gate at batch 230.
The entry waits in the queues until each parameter's release batch; the phase, the slowest, is released 35 batches early.
The window opens at batch 320 and reaches the DAC port at 326. Times are from the run's trace; the bar lengths are to scale
in batches.2The lead of 96 batches
What does the lead have to cover?
RISC-Q's own software issues each timed write 96 batches ahead (LEAD in map.py; LEAD = 96 in
riscq/soc.mjs). Its comment says what the number covers: the link, the slowest fired queue lead, and core jitter. On the
x6y3 build the deterministic part is small:
| Stage | Batches on x6y3 (L = 2) | Source |
|---|---|---|
| Bridge and link | 1 + 2 = 3 | PutBridge.md, PutLink.md |
| Fire to queue push | 2 | PulseParamBuffer.md |
| Push to earliest pop | 3 | TimedQueue.scala |
| Phase lead, the slowest fired parameter | 35 | derived, default_leads |
| Sum | 43 | |
| Remaining for core jitter, the core's time lag and several stores per pulse | 53 | 96 − 43 |
The remainder pays for what the core does between reading the time and the last store of a pulse: a pulse that sets a phase
offset and a start time and then fires takes three stores and the arithmetic around them, and the core's copy of the time lags the
converter edge (assumed equal to L). The simulator's firmware uses the same 96 (riscq/firmware.mjs imports
LEAD). After a barrier it adds 32 more batches for the delivery of the release time: the first start time of a segment
is the barrier's release time plus SYNC_LEAD = LEAD + 32 = 128.
How much margin is left is something the simulator measures. deepestLink in riscq/limits.mjs issues one
pulse 96 batches ahead on a 100 MHz build and deepens the link one stage at a time. Run for this chapter, it reports: on time up to
13 link stages; at 14 "pulse parameters did not land on the same batch". The phase lands late while the window still opens on
time. This number depends on the assumed core time lag, which grows with L, so it is a property of the model, not of a RISC-Q
bitstream.
3What is proved: landing exactly
What exactly does "early enough" mean, and what happens otherwise?
In this section: the model of one timed queue, and the three theorems about when its entry lands.
The model
Timing.lean models one queue entry with five numbers, all in dspClk cycles: offset, the batch-time
register's value at cycle 0; push, the cycle the entry enters the queue; startTime, the batch at which the
parameter must take effect; lead, the parameter's pipeline latency; and prev, the cycle of the previous pop
of the same queue, if any. From them:
def pushMargin : Nat := 3 -- FIFO write, head register, registered compare
def popInterval : Nat := 2 -- a queue pops at most every other cycle
def readyCycle (push : Nat) (prev : Option Nat) : Nat :=
max (push + pushMargin) (match prev with | some q => q + popInterval | none => 0)
def popCycle (offset push startTime lead : Nat) (prev : Option Nat) : Nat :=
let ready := readyCycle push prev
ready + dueWait (ready + offset) startTime lead
def landCycle (offset push startTime lead : Nat) (prev : Option Nat) : Nat :=
popCycle offset push startTime lead prev + lead
dueWait is the registered due test of the RTL, signed(time − (startTime − lead)) ≥ 0, computed modulo 2³²
because the time register is 32 bits wide. An entry pops at the first cycle at which it is both ready and due, and the parameter
takes effect lead cycles later. Units: every quantity is a count of dspClk cycles, one batch each.
The three theorems
land_exact. If the entry is ready no later than lead cycles before its start time
(readyCycle push prev + offset + lead ≤ startTime), and the start time is less than 2³¹ cycles away, then the
parameter lands exactly when the time register reads startTime:
landCycle offset push startTime lead prev + offset = startTime. The arrival cycle does not appear in the result.land_independent_of_arrival. Two writes that both meet that margin, with any push cycles
push, push' and any previous pops prev, prev', produce the same landing cycle:
landCycle offset push startTime lead prev = landCycle offset push' startTime lead prev'. This is why the posted link can
be pipelined freely.land_late. A write that misses the margin
(startTime < readyCycle push prev + offset + lead) by less than 2³¹ cycles pops as soon as it is ready and lands late
by exactly the amount it missed: landCycle offset push startTime lead prev = readyCycle push prev + lead.
Two more theorems bound the queue itself: popCycle_ge_push (an entry never pops sooner than 3 cycles after its push)
and popCycle_spacing (consecutive pops of one queue are at least 2 cycles apart). Each statement is proved in Lean by
unfolding the definitions and deciding the resulting linear arithmetic with omega; read them in
Timing.lean.
Read the hypotheses carefully, because they say what the theorems do not cover. They are about one queue entry and one
parameter. They assume the start time is within 2³¹ cycles of the entry's ready time, the half-range of the wrapping
comparison; at 500 MHz that is more than four seconds. They do not say that the firmware issues its writes early enough. That
is a property of each program, and the simulator checks it on every run: every pulse frame carries onTime and
aligned flags, and the channel timeline draws late or misaligned pulses in red.
A phase entry becomes ready 7 cycles after the latest cycle that would still meet land_exact's margin. By how many
batches does the phase land late?
land_late: the entry pops as soon as it is ready and takes effect lead cycles later,
so it lands at readyCycle + lead, exactly 7 cycles after startTime. Lateness never compounds or
rounds; it equals the miss.pulse_sched.elf runs unmodified in the model and opens its gate pulse on DAC 8 exactly at its start time for six
batches, as RISC-Q's RTL simulation asserts. The link-depth limit above is neither: it is a measurement of the model.4Queue depth and the shortest pulse in a train
How fast can one channel play pulse after pulse?
Each fire pushes one entry into each parameter queue of its channel, and each queue holds the build's queue depth plus one
entry. The firmware cannot issue a fire whose queue is still full of entries that have not started, so a long back-to-back train
is limited by how quickly entries drain. Two effects combine: the core can issue only so many writes per batch, and the queues
can only hold so many issued-but-not-started pulses. The generator in riscq/firmware.mjs enforces the second limit and
rejects a schedule that would overflow, with a message naming the channel and both batches:
Channel q0.gate cannot take this write on time: the core must issue it at batch …, before the entry 5 places
ahead of it starts at batch …. The schedule exceeds the queue depth or the issue rate of the core.
shortestTrainPulse in riscq/limits.mjs finds the shortest pulse that a train of 60 back-to-back pulses on one
channel can use and still be accepted. Run for this chapter on its 100 MHz test build:
| Queue depth | 1 | 4 | 8 | 32 |
|---|---|---|---|---|
| Shortest pulse (batches) | 48 | 31 | 29 | 16 |
Model result, riscq/limits.mjs, 60 pulses on one channel at 100 MHz with the table-loop issue cost. Not a hardware measurement.
A deeper queue lets the core work further ahead, so the shortest pulse approaches the issue cost of the loop. The x6y3 build has a queue depth of 32; the ion and atom builds of the simulator use the default of 4.
5Issue rate and preroll
What if sixteen pulses must start on the same batch?
In this section: how fast one core issues writes, and how a segment starts later when it must issue a wide burst.
A core issues one write at a time. The simulator's firmware issues a segment of plain timed writes with a loop over a four-word
table (issue time, start time, register address, data), budgeted at 32 core cycles per write (TABLE_COST in
riscq/firmware.mjs); other segments are issued inline at a cost of 20 cycles plus 5 per extra field and 4 for a
condition. Each timed write is at least two posted writes, startTime and fire. The measured peak at 100 MHz
is 29 posted writes per microsecond per core (docs/riscq-controller.md; the system-call report of the atom run,
computed for this chapter, gives a peak of 29 puts per µs on each AOD core).
When n writes start on the same batch, the last can be issued at the lead, but the others have to be issued earlier, one
issue cost apart. A backward pass in issueOrder moves each issue early enough for the ones after it. If the earliest
issue then falls before the segment's time base, the whole segment starts later, by the preroll:
concurrency in riscq/limits.mjs, run for this chapter, confirms it: 0, 32, 96 and 480 batches of preroll for 1, 2,
4 and 16 pulses, and in every case all pulses open on the same batch. On the real examples: the ion loop rotation starts 24 waveforms at
once on three transport cores, eight per core, and its segment starts (8 − 1) · 32 = 224 batches (2.24 µs) late. The transmon
feed-forward run has a preroll of 7 batches (14 ns) in its first segment: core q0 must issue the x90 at the segment's
start, with its phase offset, at least one inline issue cost before the CZ tone that starts 18 batches later. A run records the preroll of each segment in its bundle.
Run the feed-forward program. What is the preroll of its first segment, in batches?
preroll lists one value per segment. The first segment starts 7 batches later than the
barrier's release plus SYNC_LEAD, so that the core can issue all of its first writes on time. In the trace, qubit 0's
first x90 is issued at batch 217 for a start at 320: 96 + 7 batches ahead.One core must open four pulses on four of its channels on the same batch, issued by the table loop. How many batches of preroll does the segment need?
6Segments, barriers and the common time base
All of this assumes that the cores agree on the time base their start times are relative to. They do because every segment starts
with a barrier in the board hub: each active core arrives, the last arrival releases all of them with one release time, and each
core sets its time base to that release time plus SYNC_LEAD. In the feed-forward run the three active cores arrive at
barrier 0 at batches 181, 183 and 185 (two batches apart, as the hub counts arrivals) and all receive the release time 185 at batch
193. A barrier costs time, but it is the only point where the cores' schedules have to be synchronized; between barriers each core
follows its own table.
7Timing on the way back
If writes are issued ahead, how does the core handle a result that does not exist yet?
A measurement reverses the direction of the problem. The core cannot schedule a result ahead of time; it has to wait for it. RISC-Q
handles this with a stalling read: a load of the result sink's res register does not return until the current window's
result has settled. RISC-Q's software waits READOUT_LEAD = 48 batches after a demodulation start before such a read
returns the new window rather than the previous one (map.py; the result latch holds the previous window until this one
opens). The simulator's firmware budgets READ_SETTLE = 40 batches from the close of the window until the stalled read has
returned, an assumed value (riscq/firmware.mjs).
While a core is stalled on a read it cannot issue anything else. issueOrder therefore treats every result read, and every
photon-count loop, as a hold: a result read holds the core from 48 batches after its window starts until the window's end plus the settle time,
and a count loop from the start of its window until 8 batches after its end. A write whose issue time
falls inside a hold is moved to before the hold begins, with a margin of 25 batches. This is safe because of
land_independent_of_arrival: issuing a write earlier never changes when it lands, only how long it waits in its queue.
It costs queue space, and the queue-depth check of section 4 still applies to the moved write.
One more boundary is the width of the time register. It counts dspClk cycles in 32 bits and wraps after 2³² batches: about 8.6 seconds
at 500 MHz and 43 seconds at 100 MHz. The queue's due test and the firmware's own time comparisons (countEdges compares a
signed difference) are written to be correct across the wrap, and the theorems carry the matching hypothesis that a start time is
less than 2³¹ batches from the moment its entry is ready.
8What is guaranteed and what is measured
| Statement | Kind | Where |
|---|---|---|
| A write that meets the margin lands exactly on its start time, independent of arrival | Proved about the model | land_exact, land_independent_of_arrival |
| A write that misses it lands late by exactly the miss | Proved about the model | land_late |
| Queue pops 3 after push, 2 apart | Proved about the model | popCycle_ge_push, popCycle_spacing |
| The leads are 34, 35, 36, 52, 11, 2 | Proved from cited block latencies | default_leads |
| The model's queue matches RISC-Q's RTL | Conformance test | pulse_sched.elf, tests/riscq-firmware.test.mjs |
| Every pulse of a run is on time and aligned | Checked per run | onTime, aligned in each pulse frame |
| 96 batches suffice up to 13 link stages | Model measurement, depends on an assumed lag | deepestLink |
| Shortest train pulse, preroll per burst | Model measurement | shortestTrainPulse, concurrency |
| Core instruction timing | Assumed cost model | riscq/soc.mjs, redirectPenalty, busPenalty |
What to remember
- The core's timing varies; pulse timing must not. The start time is written as data, and the hardware waits for it.
- Each write is issued 96 batches ahead, the lead of RISC-Q's software. On x6y3 the fixed path needs 43 of them.
land_exact: a write ready one lead before its start time lands exactly on it.land_independent_of_arrival: when it arrived does not matter.land_late: a write that misses the margin lands late by exactly the miss.- A queue pops at least 3 batches after a push and 2 after the previous pop; its depth limits how short a pulse train can be.
- One core issues one write at a time: n simultaneous writes from one core delay the segment by (n − 1) · 32 batches.
- Proofs are about the model; conformance tests tie the model to RISC-Q; limit sweeps are measurements of the model.