The Network-on-Chip: CHI, Routing and Quality of Service

A crossbar needs a path for every pair of blocks, and a large chip has too many pairs. A network of small routers takes its place. Distance is then counted in hops, and time in hops plus waiting.

You Will Be Able To

  • Compare what a crossbar and a mesh cost as the count of blocks grows.
  • Route a packet through a mesh by hand, and count its hops.
  • Explain a late packet with credit, and with the choice at a busy output.
Lesson
S10.3
Time
25 min
Runs on
Your browser
Check
5 questions

The first read of an interrupt handler crosses two links of the network, and it takes four clock periods.

Distance explains two of them. No wire on the route was slow, so where did the other two go?

Before You Start

You need From Microcontroller to Application Processor: pairs that grow as a product, a router, and ap_phone.

You need Many Managers: Arbitration and the Bus Matrix: the bus matrix, the arbiter, fixed priority and starvation.

It helps to have read Cache Coherence: MSI and MESI, for the last section only.

Five questions this page answers
Question
1Why does one crossbar stop working when a chip has a hundred blocks?
2How does a packet find its way through a mesh?
3What is a hop, and why can two hops take four clock periods?
4What does a credit allow, and what does it not say?
5The home node moves one link away, and credit is missing for one period. Which row reports the arrival?

A crossbar is the bus matrix under its general name: every input has a path to every output. Give it 3 managers and 5 subordinates, and it has 15 pairs. Give it 100 inputs and 100 outputs, and it has 10,000. Each pair is a wire across the chip, and each output needs a multiplexer with 100 inputs.

A network on chip spends its wires differently. Each block is joined to a small router beside it, and each router to its neighbours only. A message crosses the chip from router to router. It travels as a packet that carries the number of its destination. So every router can decide alone where to send it next.

Distance now has a unit. Each link that a packet crosses is one hop. A read that crosses two links has a route of two hops, whatever else happens.

Time is another matter. A router may send only when the next router has room, and only when no other packet has that link. So time is hops plus waiting, and the waiting is where late packets are made.

New Words

New words on this page
WordMeaning
CrossbarA block that gives every input a path to every output. The bus matrix is one.
Network packetA message that carries the number of its destination. This page says packet.
Network linkThe wires between two neighbouring routers. This page says link.
Hop of a packetOne crossing of a link, hop for short.
MeshRouters in rows and columns. Each has a link to the routers beside, above and below it.
Row-first routingA fixed rule for every router: send along the row until the column is right, then along the column.
Link creditA promise from the receiver of a link: it has room for one more transfer. This page says credit.
FlitThe unit that crosses a link in one transfer. In CHI one packet is one flit.
CHICoherent Hub Interface: the Arm protocol for large chips with caches. It defines the messages between nodes.
Node of a networkAn end point with a role: a block that sends or answers messages. A router is not a node.
Request node (RN)The node that starts a read or a write, such as a core with its cache.
Home node (HN)The node that receives every request for a range of addresses, and decides who answers.
Subordinate node (SN)A node that only answers the home node, such as a memory controller.
QoSShort for quality of service. On this page: a mark on a packet that says how urgent it is. In CHI it is a value of 4 bits.

One Picture: Four Routers and One Read

Four Routers and One ReadStep through the picture. It starts with two blocks that are far apart, and ends with a request and its reply.
  • Processor
  • Bus
  • Memory
Four Routers and One ReadStep through the picture. It starts with two blocks that are far apart, and ends with a request and its reply. component Request node a core that needs oneword component Router 0 column 0, row 0 component Router 1 column 1, row 0 component Router 2 column 0, row 1 component Router 3 column 1, row 1 component Home node decides who answersthe read request ineastsouthrequest outwestnorth
  1. component Request nodea core that needs one word
    • request in → Router 0
  2. component Home nodedecides who answers the read
  3. component Router 0column 0, row 0
    • east → Router 1
  4. component Router 3column 1, row 1
    • request out → Home node
    • west → Router 2
  5. component Router 1column 1, row 0
    • south → Router 3
  6. component Router 2column 0, row 1
    • north → Router 0
  1. Two blocks, far apart

    A core needs a word, and the block that can supply it is at the other end of the chip. A direct wire for every such pair is what a crossbar costs.

  2. A router beside each block

    Each block talks to the router next to it, and to nothing else.

  3. Neighbours only

    Each router has a short link to the routers beside it. Four routers in a square need four links.

  4. The request: along the row first

    The packet for router 3 goes east until its column is right, then south. That is two hops.

  5. The reply: the same rule

    The reply for router 0 also travels along its row first. So it goes west, then north, and comes home by the other two sides.

Read the diagram as text
  • Request node: a core that needs one word
  • Router 0: column 0, row 0
  • Router 1: column 1, row 0
  • Router 2: column 0, row 1
  • Router 3: column 1, row 1
  • Home node: decides who answers the read
  • Request node → Router 0: request in
  • Router 0 → Router 1: east
  • Router 1 → Router 3: south
  • Router 3 → Home node: request out
  • Router 3 → Router 2: west
  • Router 2 → Router 0: north

The mesh of the lab: four routers, and a link between each two neighbours. A real mesh has many more routers and the same kind of link.

The Smallest Example, Worked by Hand

No simulator yet. First count wires. Take n blocks that must all reach each other. A crossbar needs n times n pairs. A square mesh with k routers on a side has 2 × k × (k − 1) links between routers.

Pairs of a crossbar against links of a mesh
BlocksCrossbar pairsMeshLinks between routers
4162 by 22 × 2 × 1 = 4
9813 by 32 × 3 × 2 = 12
162564 by 42 × 4 × 3 = 24
10010,00010 by 102 × 10 × 9 = 180

Each link carries packets in both directions. Each router also has one short link to its own block.

The pairs grow with the square of the blocks. The links grow about as fast as the blocks themselves, and every link is short.

Now route one packet in the mesh of the picture. A request goes from router 0 to router 3, by row-first routing. For the first two clock periods, router 0 has no credit for its link.

One request in a mesh of four routers
PeriodThe packet is inCredit for the next linkWhat happens
0Router 0noIt waits.
1Router 0noIt waits.
2Router 0yesIt crosses east: hop 1.
3Router 1yesIts column is right now. It crosses south: hop 2.
4Router 3It has arrived: 2 hops in 4 periods.

Two hops and four periods. The route was never longer than two links. The other two periods were spent in router 0, waiting for room.

The Rules

  1. Rule 1: A crossbar pays for every pair, a mesh for every neighbour.

    n blocks give n times n pairs. A mesh of n routers has fewer than 2 times n links between them.

  2. Rule 2: A packet follows one fixed rule at every router.

    Here the rule is row first: along the row until the column is right, then along the column.

  3. Rule 3: A hop is one crossing of a link.

    A packet that sits in a router, or is put into one by its block, has made no hop.

  4. Rule 4: A sender needs a credit for every transfer.

    A credit says that the receiver has room. It says nothing about the answer to the request.

  5. Rule 5: When two packets want one output, an arbiter chooses.

    With fixed priority the lower class can starve, as on any bus.

  6. Rule 6: A node has a role, and a router has none.

    The home node decides who answers a read. The routers only carry packets.

Sources for These Rules

A fully connected network, a mesh and the cost of each: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 6.8.

Crossbar, ring or mesh, by the size of the system: Arm AMBA CHI Architecture Specification, IHI 0050 issue G, section B1.2.

Packets, flits and the kinds of node: the same specification, sections B1.3 and B1.6. The address map that picks the home node: sections B3.1 and B3.3.

Credits on a link: the same specification, section B14.2. The QoS value of 4 bits: section B11.1.

Row-first routing, one place for a packet in each router and the timing of the credit are choices of this lab. CHI does not define the routers.

Now Run It

The lab at the end of this page is the hand example. It has four routers in a square, and one packet at a time. A bus-functional model stands in for the core. It is test code that puts a request into router 0, and later a reply into router 3.

Where the Handler’s Read WaitsStep through the four-router Icarus run. Each occupied bit names a router holding the packet.
  • Processor
  • Bus
  • Memory
eastsouthwestnorthRequester (0,0)Router (1,0)Router (0,1)Home (1,1)
east→ Router (1,0)north→ Requester (0,0)south→ Home (1,1)west→ Router (0,1)Requester (0,0)Router (0,1)Router (1,0)Home (1,1)

A lit wire carries a 1. A pill is a transfer in that cycle.

01234567slots00010010100001000001eastsouthwestnorth
Scroll horizontally ↔
  1. Cycle 0

    The requester has the packet. Its first link has no credit yet.

  2. Cycle 1

    The requester has the packet. Its first link has no credit yet.

  3. Cycle 2

    The request takes the east link on the next edge.

  4. Cycle 3

    The request takes the south link on the next edge.

  5. Cycle 4

    The request has arrived. This ends its measured leg.

  6. Cycle 5

    The reply takes the west link on the next edge.

  7. Cycle 6

    The reply takes the north link on the next edge.

  8. Cycle 7

    The reply has arrived. This ends its measured leg.

Recorded packet observations. Each leg starts at injection. The endpoint interval between legs is omitted.

Printed by the lab on Icarus. In slots and in moves, the right-hand bit is router 0.
request t=0 slots=0001 moves=0000
request t=1 slots=0001 moves=0000
request t=2 slots=0001 moves=0001
request t=3 slots=0010 moves=0010
request arrive=4 hops=2 slots=1000
reply t=0 slots=1000 moves=1000
reply t=1 slots=0100 moves=0100
reply arrive=2 hops=2 slots=0001
strict grants urgent=8 bulk=0

Rule 4 at work, in the first two rows. slots=0001 says that router 0 holds the packet, and moves=0000 says that nothing is sent. The lab keeps credit away for 2 periods.

Rule 2, at t=2 and t=3. First moves=0001: router 0 sends east. Then slots=0010 and moves=0010: router 1 holds the packet and sends it south.

Rule 3, in the two rows that say arrive. The request has hops=2 and arrive=4. The reply has hops=2 and arrive=2, because nothing made it wait.

Rule 5, in the last row. It is a separate experiment at one output. An urgent class and a bulk class have 8 flits each, and fixed priority hands out 8 grants. The row says urgent=8 bulk=0.

This lab leaves things out. A router holds one packet, and credit is one input that the test code drives. No CHI message is sent: the reply is put in by test code, where a home node would work first.

Why It Is Built This Way

ChoiceThe alternativeIts cost
A mesh of routersOne crossbarA wire for every pair, across the whole chip, and a wide multiplexer at every output.
One fixed routeRouters that pick any free linkPackets can then wait for each other in a circle. A fixed rule is easy to check, but it cannot take a free detour.
CreditsA ready wire back over the linkThe answer must cross the link within the same cycle, and that limits how long a link may be.

The mesh has a price too. On a crossbar every pair is one step apart. In a mesh a far block is many hops away, and every hop can add waiting.

The Trap: A Credit Read as an Answer

A bring-up log shows a credit that comes back one cycle after the request left. The note beside it says "memory answered at once". It did not. The credit said only that the next router had room, as rule 4 warns. The answer was still many hops away.

The second trap is the hop that was never made. Count the routers that a packet touches, and a route of two links looks like three hops. Count the links.

The third trap is a promise made from a class. The camera stream is marked urgent, and it never stops. The copy job behind it has credit, and it loses every grant, as in the last row of the lab. Give the copy every fourth turn and it moves again. The urgent class pays for that turn.

At Scale

This lab4 routers
A large chip100 routers

This section looks ahead, to a mesh with a hundred blocks and caches at its edges.

  1. Who answers a coherent read

    The newest copy of a block may sit in the cache of another core. The home node finds it by snooping, and the data may come from that cache or from memory.

  2. Time stamps on one read

    Mark the same read when it enters the mesh, when it reaches the home node and when its data comes back. The gap that grew shows where to look.

  3. The busy cut

    Draw a line that splits the mesh in two. Everything that crosses it shares a few links, however short each route is.

Cache coherence explains when another cache holds the newest copy.

Try It

Run the lab. Then set HOLD to 0 and compare the two rows that report an arrival.

Set HOME_TILE to 2, so that the home node sits below the requester. Predict which move is no longer needed.

Names Printed by the Lab
NameMeaning
request, replyThe packet that the row is about. Each starts its own count of clock periods at t=0.
slotsOne bit for each router: 1 when it holds the packet. The right-hand bit is router 0.
movesOne bit for each router: 1 when it sends the packet over a link on the next clock edge.
arriveThe count of clock periods at which the packet is in the router of its destination.
hopsHow many links the packet crossed.
strict grantsA second, separate experiment at one output: 8 grants under fixed priority, for two classes of traffic.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: request t=0 slots=0001 moves=0000 request t=1 slots=0001 moves=0000 request t=2 slots=0001 moves=0001 request t=3 slots=0010 moves=0010 request arrive=4 hops=2 slots=1000 reply t=0 slots=1000 moves=1000 reply t=1 slots=0100 moves=0100 reply arrive=2 hops=2 slots=0001 strict grants urgent=8 bulk=0
Read included file: router.sv
// One slot per router, one packet in flight across the teaching mesh.
// Router addresses use {y,x}. Links cross one coordinate boundary.
module teaching_router #(parameter logic [1:0] SITE = 0) (
  input logic clk, clear, incoming, link_credit,
  input logic [1:0] incoming_dest,
  output logic [1:0] destination,
  output logic occupied, cross_x, cross_y
);
  assign cross_x = occupied && SITE[0] != destination[0] && link_credit;
  assign cross_y = occupied && SITE[0] == destination[0]
                            && SITE[1] != destination[1] && link_credit;

  always_ff @(posedge clk) begin
    if (clear) begin
      occupied <= 0;
      destination <= 0;
    end else if (incoming) begin
      occupied <= 1;
      destination <= incoming_dest;
    end else if (cross_x || cross_y || SITE == destination) occupied <= 0;
  end
endmodule

Check Yourself

Predict the outputIn this run the home node sits at router 1, one link from the requester, and credit is missing for one period. Which row reports that the request has arrived? Its form is: request arrive=.. hops=.. slots=....
module tb;
  parameter HOLD = 1;
  parameter HOME_TILE = 1; // Coordinate {y,x} in the 2-by-2 mesh.
  bit clk, clear;
  always #5 clk = !clk;
  bit [3:0] inject, credit;
  wire [3:0] occupied, cross_x, cross_y;
  bit [1:0] injection_dest;
  wire [1:0] destination [0:3];
  for (genvar i=0; i<4; i++) begin : tile
    wire incoming = inject[i] || cross_x[i ^ 1] || cross_y[i ^ 2];
    wire [1:0] incoming_dest = inject[i] ? injection_dest :
                               cross_x[i ^ 1] ? destination[i ^ 1] : destination[i ^ 2];
    teaching_router #(i) router(
      .clk(clk), .clear(clear), .incoming(incoming), .link_credit(credit[i]),
      .incoming_dest(incoming_dest), .destination(destination[i]),
      .occupied(occupied[i]), .cross_x(cross_x[i]), .cross_y(cross_y[i])
    );
  end

  // Bus-functional requester and home endpoint. No processor is needed.
  task automatic packet(input string label_text, input int src, dst, stalls);
    int elapsed, hops;
    injection_dest = dst;
    inject = 1 << src;
    @(negedge clk);
    inject = 0;
    elapsed = 0;
    hops = 0;
    while (!occupied[dst]) begin
      credit = elapsed < stalls ? 0 : 4'b1111;
      #1;
      $display("%s t=%0d slots=%04b moves=%04b",label_text,elapsed,
               occupied,cross_x | cross_y);
      if (|(cross_x | cross_y)) hops++;
      @(negedge clk);
      elapsed++;
      if (elapsed > 32) $fatal(1,"packet timed out");
    end
    $display("%s arrive=%0d hops=%0d slots=%04b",label_text,elapsed,hops,occupied);
  endtask

  int urgent_left, bulk_left;
  initial begin
    clear = 1;
    @(negedge clk);
    clear = 0;
    packet("request",0,HOME_TILE,HOLD);
    @(negedge clk); // Endpoint consumes the request and prepares its reply.
    packet("reply",HOME_TILE,0,0);
    // Independent output-port experiment: both classes always have a flit.
    urgent_left = 8;
    bulk_left = 8;
    repeat (8) begin
      @(posedge clk);
      if (urgent_left > 0) urgent_left--;
      else if (bulk_left > 0) bulk_left--;
    end
    $display("strict grants urgent=%0d bulk=%0d",8-urgent_left,8-bulk_left);
    $finish;
  end
endmodule
Read included file: router.sv
// One slot per router, one packet in flight across the teaching mesh.
// Router addresses use {y,x}. Links cross one coordinate boundary.
module teaching_router #(parameter logic [1:0] SITE = 0) (
  input logic clk, clear, incoming, link_credit,
  input logic [1:0] incoming_dest,
  output logic [1:0] destination,
  output logic occupied, cross_x, cross_y
);
  assign cross_x = occupied && SITE[0] != destination[0] && link_credit;
  assign cross_y = occupied && SITE[0] == destination[0]
                            && SITE[1] != destination[1] && link_credit;

  always_ff @(posedge clk) begin
    if (clear) begin
      occupied <= 0;
      destination <= 0;
    end else if (incoming) begin
      occupied <= 1;
      destination <= incoming_dest;
    end else if (cross_x || cross_y || SITE == destination) occupied <= 0;
  end
endmodule
ConceptWhy does one crossbar stop working when a chip has a hundred blocks?
ConceptWhat does one link credit allow?
ConceptA request crosses 2 links and waits 2 periods for credit. How many hops is that, and how many periods?
ConceptA packet is in the right column and in the wrong row. Where does row-first routing send it?

Common Mistakes

Wrong Count a hop when a packet is put into its first router.

It has crossed no link yet.

Fix Count the links that it crosses.

Wrong Read a credit as the answer to a read.

A credit says only that the receiver has room.

Fix Follow the reply itself back to the requester.

Wrong Promise a deadline from the class of a packet alone.

Missing credit and other packets of that class still make it wait.

Fix Budget every shared link and every node on the route.

Remember

  • A crossbar pays for every pair. A mesh pays for every neighbour, with short links.
  • Distance is counted in hops. Time is hops plus waiting.
  • A credit says that a receiver has room. It is not the answer.
  • A node has a role. A router only carries packets.

Practice

Report a problem with this page