Part B · Lesson 4
Cores meet: the board hub
Each core runs its own program on its own clock copy. When a bit measured on one core decides a pulse on another, the cores need a shared place to leave bits, a way to wait for each other, and one common time to start from. On RISC-Q that place is the board hub. This lesson follows the measured bit of the feed-forward program through it.
You should know posted writes (B1), the lead (B2) and how a result reaches a core (B3). Lesson A1 ended with the question this lesson answers: why the conditioned gate waits.
1Why cores need to meet
Core q0 has the bit. Core q2 must play the pulse. How does q2 learn the bit, and when may it start?
Two problems hide in that question. The first is data: q2 cannot read q0's registers or RAM. The second is time: every core's schedule is counted from a time base, and the times in segment 1 must mean the same batch on every core, although each core reached the end of segment 0 at a different moment.
The board hub solves both (RISC-Q PutHub.scala and
PutHub.md). It offers three services, all reached by posted writes into the put window, beyond the 16
nodes of a core's own channels:
| Service | Write to | Read from | What it does |
|---|---|---|---|
| Shared bits | node 16 + g: 0x110000 + g · 0x10000 | 0x4300 + 4g (board) | Sets one bit of group word g (4 groups of 32 bits) and sends the word to every core |
| Counted barriers | node 20 + b: 0x150000 + b · 0x10000 | 0x4320 (release) | Counts arrivals at barrier b (16 barriers); the last one releases all with one common time |
| Mailboxes | node 36 + core | 0x4340, 0x4360 | Delivers one word to one mailbox of one core |
On the receiving side the words land in the core's inbox, a set of core-local registers next to its
sinks. In the trace, hub events are frames of the part hub
and deliveries are frames of q0.inbox, q1.inbox and so on.
2Publishing a bit
In this section: the write that shares a bit, and how long it takes to reach every core.
After its result read returns (lesson B3), core q0 publishes the bit with one store
(publish in riscq/firmware.mjs). The data word carries the bit in bit 0 and the slot
number above it:
data = bit | (slot << 1)
The hub sets bit slot of the group word to bit and sends the whole word to the board register of every
core. The model charges two latencies from PutHub.md, both written in terms of the link depth
L:
- down to the hub: bridge 1 + link L + queue and arbiter 2 + decode and dispatch 4 = L + 7;
- up to every inbox: replica and link 1 + L + core merge 2 + link L + inbox 1 = 2L + 4.
From the store to every core's board register that is 3L + 11 batches when the arbiter is free. RISC-Q
documents 23 batches for a publish; that is the value at L = 4, and the conformance tests check it
(tests/riscq-limits.test.mjs). The x6y3 build of the ring has L = 2.
publish frame. Its state shows group 0, slot 0, bit 1 and the new word.
Step forward to see eight board frames, one per core, at the same batch.In the feed-forward run, how many batches pass from q0's publish store to the moment the bit is in every core's board register?
board frames are at 1,110 (2L + 4 = 8 more). 3 · 2 + 11 = 17 batches, 34 ns.How many batches would the same publish take on a build with a link depth of 4, with the arbiter free?
- 17
- 23
- 25
- 34
PutHub.md states, and what the limit test
publishBurst(1) measures: dispatched after 11 batches, at every board after 23.Which 32-bit data word must a core store to publish the bit 1 into slot 3 of a group?
ori t1, rs, 6, where
rs holds the bit.3Barriers and one common time
In this section: how cores agree on when the next segment starts.
A bit in the board register is not enough: q2 must also know that it is there, and must start its pulse on a batch
that means the same to every core. Each segment of the compiled program therefore begins with a
barrier. A core stores the number of members to the barrier's node,
then loads release. The load stalls. The hub counts arrivals; when the count reaches the number of
members, it sends its own batch time, the same value to every member. In q0's firmware the sequence is six words:
addi x6, x0, 3 # three members
lui x5, 0x150 # barrier 0 is node 20: 0x150000
sw x6, 0(x5) # arrive
lw x10, 800(x9) # 0x4320 release: stall until the hub answers
addi x6, x0, 128 # SYNC_LEAD = 96 + 32
add x8, x10, x6 # time base of the segment = release time + 128
The time base is the release time plus 128 batches: the lead of 96 plus 32 for delivering the release to the cores
(SYNC_LEAD in riscq/firmware.mjs). Every start time in the segment is counted from it,
so a pulse at offset 0 opens exactly 128 batches after the release on every core.
In the feed-forward run, segment 1 starts with barrier 1. Cores q1 and q2 have nothing left to do in segment 0
and arrive at the hub at batches 1,079 and 1,081. Core q0 arrives last, after its result read and its publish: the
hub releases the barrier at batch 1,111. The release reaches all three inboxes at 1,119; q2 then reads its board
register, finds the bit, and fires its x to start at 1,111 + 128 = 1,239.
release frame for barrier 1, with t0 = 1,111. The three
released frames follow at batch 1,119.How many batches after the release time of barrier 1 does the conditioned x open its window?
SYNC_LEAD. The x is the first and only operation of segment 1, at
offset 0, and its segment needed no preroll. The bit was in q2's board register a batch before the release, so the
barrier, not the bit, sets the start.4One message per batch: the arbiter
The hub serves the whole board through one arbiter. Every message to it (a publish, a barrier arrival, a mailbox
word) first joins a queue of eight for its source core. In every batch the arbiter grants one message, scanning the
cores round robin from the one after the last it granted (PutHub.md; that the first scan starts at core
0 is a model assumption). A message into a full queue is dropped and reported as a fault. One more rule: a barrier
arrival directly behind another arrival at the same barrier waits one extra batch for that barrier's state.
The repetition-code example shows the rule. Its first barrier has six members, and the arrivals of five of them reach
the hub at the same batch. The hub counts them two batches apart, and the trace records a wait frame for each
message held behind another, with waited counting the batches.
arrive frames at batches 181, 183, 185 and 187.In the repetition-code run (example superconducting-repetition), at which batch does the hub release
barrier 0?
Lean proves two properties of the arbiter's grant function nextSource
(QControl/RiscQ/Soc.lean): nextSource_waiting, it grants only a core that has a message
waiting, and nextSource_isSome, it grants one in every batch in which any core has a message waiting.
Together they say the hub is never idle while work waits and never invents work. They do not bound how long one
message waits; that comes from the tests.
The tests of riscq/limits.mjs run hand-written firmware on a hub build with link depth 4 at 500 MHz:
- Eight cores publish one bit on the same batch. The bits reach every board after 23, 24, …, 30 batches, in core order: one bit per batch for the whole board, 500 bits per µs.
- Eight cores arrive at one barrier together. The arrivals are counted 2 batches apart, and every core holds the common time after 23 + 2 · 7 = 37 batches at link depth 4, which is 74 ns at a 500 MHz clock.
- A core can issue a publish every 4 batches. Four cores publishing without pause fill the hub exactly and lose nothing; eight overflow its queues and messages are dropped.
These are results of the model, following the statements of RISC-Q's PutHub.md, not traces of the RTL.
What does nextSource_isSome guarantee?
- Every message is delivered within eight batches.
- Barrier arrivals are counted in core order.
- No queue ever overflows.
- If any core has a message waiting, the arbiter grants a message in that batch.
5Mailboxes
Shared bits go to every core. A mailbox carries a 32-bit word to one core. Each core has two mailboxes, at
0x4340 and 0x4360. A load from a mailbox stalls until a word arrives and empties it. The
compiled examples of this course do not use mailboxes; they are exercised by RISC-Q's own firmware
xcore.elf, which the conformance test runs unmodified: both cores get the same barrier time, core 1's
mailbox receives the word 0x77, and core 1 opens its pulse at that time plus 1,024
(tests/riscq-firmware.test.mjs).
6The whole path of the bit
docs/riscq-controller.md
as system-call measurements. Schematic drawing, positions to scale.Read left to right: 34 ns for the decoder and the report, 36 ns for the stalled load to return, the host store and the publish to reach the hub, 16 ns for the hub to deliver the bit to every core. Then the cores still have to meet and leave one lead of room: the pulse opens 344 ns after the window closed. Lesson E1 breaks this feedback latency down further and asks which parts a different program or build could shorten.
How many nanoseconds after the acquisition window closes is the measured bit in every core's board register?
board frames are at 1,110: 43 batches, 86 ns.
It is the same in every core because the hub sends one word to all of them at once.What to remember
- The hub offers shared bits, counted barriers and mailboxes, all reached by posted writes.
- A publish reaches every core after 3L + 11 batches with the arbiter free: 17 on the ring, 23 at link depth 4.
- A barrier returns one common time; each segment starts 128 batches after it.
- One arbiter passes one message per batch for the whole board; simultaneous arrivals at one barrier are counted 2 batches apart.
- Lean proves the arbiter only grants waiting messages and grants one whenever any wait. Waiting times and overflows are tested, not proved.