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:

ServiceWrite toRead fromWhat it does
Shared bitsnode 16 + g: 0x110000 + g · 0x100000x4300 + 4g (board)Sets one bit of group word g (4 groups of 32 bits) and sends the word to every core
Counted barriersnode 20 + b: 0x150000 + b · 0x100000x4320 (release)Counts arrivals at barrier b (16 barriers); the last one releases all with one common time
Mailboxesnode 36 + core0x4340, 0x4360Delivers 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:

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.

Step 410: the hub's 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?

The store is at batch 1,093, the hub dispatches it at 1,102 (L + 7 = 9) and the eight 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?

  1. 17
  2. 23
  3. 25
  4. 34
3 · 4 + 11 = 23, the figure RISC-Q's 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?

1 | (3 << 1) = 1 + 6 = 7. The firmware builds it with 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.

Step 421: the hub's 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?

128 = 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.

Step 510 of the repetition-code run: the sixth arrival releases barrier 0. Step back through the 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?

The decoder core arrived long before. Cores q0 to q4 arrive together; the arbiter counts q0 at 181 and the others at 183, 185, 187 and 189. The last one, q4, releases the barrier at 189 after waiting 8 batches.

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:

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?

  1. Every message is delivered within eight batches.
  2. Barrier arrivals are counted in core order.
  3. No queue ever overflows.
  4. If any core has a message waiting, the arbiter grants a message in that batch.
It is a progress property of one batch. Overflow is possible (eight cores publishing without pause drop messages), and the order and the waiting times are results of the round-robin scan, measured by the tests.

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

window closes1,067 · 0 ns result1,084 · 34 at hub1,102 · 70 every board1,110 · 86 segment 1 time base = release 1,111 + 128 x opens1,239 · 344 ns Batches of the feed-forward run (c = 1) and nanoseconds after the acquisition window closes. Horizontal scale is linear in batches.
From readout to conditioned pulse. The same figures appear in 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?

The window closes at batch 1,067 and the 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

  1. The hub offers shared bits, counted barriers and mailboxes, all reached by posted writes.
  2. A publish reaches every core after 3L + 11 batches with the arbiter free: 17 on the ring, 23 at link depth 4.
  3. A barrier returns one common time; each segment starts 128 batches after it.
  4. One arbiter passes one message per batch for the whole board; simultaneous arrivals at one barrier are counted 2 batches apart.
  5. Lean proves the arbiter only grants waiting messages and grants one whenever any wait. Waiting times and overflows are tested, not proved.