Crossbar Contention and the Decode Error

A crossbar serves two managers at once only while they want different subordinates. Two cases remain: both want the same one, or one of them wants an address that nobody owns.

You Will Be Able To

  • Say when a crossbar can serve two managers in the same cycles, and when one must wait.
  • Explain why each subordinate has its own arbiter, and what a tie costs the loser.
  • Follow a request that nobody owns to the default subordinate and its DECERR reply.
Lesson
S4.14
Time
24 min
Runs on
Your browser
Check
5 questions

A team replaces a shared bus with a crossbar, to make a copy job faster. The copy runs no faster at all. Both managers were reading the same memory, and a crossbar cannot make one memory answer twice at once.

Before You Start

This is a senior page, and the second half of Inside an AXI Crossbar. Like that page, it stands on the Protocols lessons AXI in one picture, the handshake and a write on three channels.

From this module you need arbiters and fixed priority from Many Managers. You also need the default subordinate from the lesson on the two-cycle error.

Five questions this page answers
Question
1When can a crossbar serve two managers in the same cycles?
2Where does a crossbar arbitrate, and why not once for the whole crossbar?
3What does a tie cost the manager that loses it?
4Who answers a request to an address that nobody owns, and with which reply?
5What must still happen to the write data of a write that nobody owns?

The Idea: Paths Meet at a Subordinate

The last lesson followed requests that never met. Each had its own entrance, its own route and its own subordinate. That is the good case of a crossbar, and it is why crossbars are built.

Entrances are never shared, so two requests can only meet at the far end. A subordinate answers one request at a time. When two managers want the same one, there is contention. An arbiter must choose, and the other request waits.

A crossbar places that arbiter at each subordinate. A tie at SRAM then costs nothing to a manager that wants the console.

One more case needs an answer. An address may match no subordinate at all. On AXI the manager then waits for a reply that no real subordinate will send. So the crossbar holds a default subordinate, as an AHB bus does. It answers with an error named DECERR, a decode error.

New Words

New words on this page
WordMeaning
ContentionTwo requests that want the same subordinate at the same time.
TieOne clock edge at which an arbiter has more than one request to choose from.
Response codeA few bits in every AXI reply that say how the request ended.
OKAYThe response code for success: 00 in this lab.
DECERRThe response code for "the address decodes to nobody": 11 in this lab.
SLVERRThe response code for "a subordinate was reached, and it failed": 10 in the two-bit form.

The channel names are those of the last lesson. AR carries a read address, and R carries the read data with its response code. B carries the response code of a write.

One Picture: Three Cases

Where Two Requests MeetStep through the picture. It shows three cases, one after the other.
  • Processor
  • Peripheral
  • Bus
  • Memory
Where Two Requests MeetStep through the picture. It shows three cases, one after the other. component Manager 0 the processor, atentrance 0 component Manager 1 DMA, at entrance 1 component Console arbiter chooses amongrequests for theconsole only component SRAM arbiter chooses amongrequests for SRAMonly component Console register a subordinate: oneregister at0x1000_0000 component SRAM word a subordinate: oneword at0x8000_0000 component Defaultsubordinate answers everyaddress that nobodyowns, with an error to the consoleto SRAMto SRAMthe winnerthe winnerno owner
  1. component Manager 0the processor, at entrance 0
    • to the console → Console arbiter
    • to SRAM → SRAM arbiter
    • no owner → Default subordinate
  2. component Manager 1DMA, at entrance 1
    • to SRAM → SRAM arbiter
  3. component Console arbiterchooses among requests for the console only
    • the winner → Console register
  4. component SRAM arbiterchooses among requests for SRAM only
    • the winner → SRAM word
  5. component Console registera subordinate: one register at 0x1000_0000
  6. component SRAM worda subordinate: one word at 0x8000_0000
  7. component Default subordinateanswers every address that nobody owns, with an error
  1. Different subordinates

    Manager 0 reads the console and manager 1 reads SRAM. Each request meets an arbiter with nobody else in front of it. Both are served in the same cycles.

  2. The same subordinate

    Both read SRAM. The SRAM arbiter serves one and makes the other wait. The console arbiter has nothing to do, and could serve a third manager meanwhile.

  3. Nobody owns the address

    Manager 0 reads an address that no decoder entry matches. Its entrance sends the request to the default subordinate, which answers with an error.

Read the diagram as text
  • Manager 0: the processor, at entrance 0
  • Manager 1: DMA, at entrance 1
  • Console arbiter: chooses among requests for the console only
  • SRAM arbiter: chooses among requests for SRAM only
  • Console register: a subordinate: one register at 0x1000_0000
  • SRAM word: a subordinate: one word at 0x8000_0000
  • Default subordinate: answers every address that nobody owns, with an error
  • Manager 0 → Console arbiter: to the console
  • Manager 1 → SRAM arbiter: to SRAM
  • Manager 0 → SRAM arbiter: to SRAM
  • Console arbiter → Console register: the winner
  • SRAM arbiter → SRAM word: the winner
  • Manager 0 → Default subordinate: no owner

Each arrow stands for a group of wires. The routes from manager 1 to the console and to the default subordinate exist too, and are not drawn.

The picture has two arbiters and no third one in front of them. That is the design decision of this page.

The Smallest Example, Worked by Hand: Who Waits?

Take two managers and the two subordinates of the picture. Both managers send a read address at the same edge. Work out, for each pair of destinations, who is served at once.

Two reads sent at the same edge
Manager 0 readsManager 1 readsArbiters with a tieWho waits
the consoleSRAMnonenobody
SRAMthe consolenonenobody
SRAMSRAMthe SRAM arbiterone of the two
an address nobody ownsthe consolenonenobody: the default subordinate answers manager 0

Now compare with one arbiter for the whole crossbar. It would give out one grant at a time. In rows 1, 2 and 4 a manager would then wait for a subordinate it never wanted.

Requests served at once, of two
DesignDifferent subordinatesThe same subordinate
One arbiter for the whole crossbar11
An arbiter at each subordinate21

The Rules

  1. Rule 1: Requests for different subordinates do not wait for each other.

    Each has its own entrance and meets its own arbiter.

  2. Rule 2: Each subordinate has its own arbiter.

    It chooses only among the requests for that subordinate. How it chooses is the design choice of the last lessons: fixed priority, round robin, or more.

  3. Rule 3: The loser of a tie waits for the winner, and for nothing else.

    Its request stays stored in its entrance. It is served when the subordinate is free again.

  4. Rule 4: A request that decodes to nobody gets a DECERR reply.

    The crossbar sends it to a default subordinate, which gives that reply.

  5. Rule 5: Every transfer of a failed request still happens.

    A write that nobody owns still hands over its write data, and only then gets its B reply. A failed read still returns data, and that data must not be used.

Sources for These Rules

Arm AMBA AXI Protocol Specification, document IHI 0022, issue L. The response codes, and DECERR for an address that decodes to nothing valid: section A3.3, Tables A3.28 and A3.31. Issue L writes the codes with three bits (OKAY 000, SLVERR 010, DECERR 011); earlier issues and this lab use two.

The default subordinate is the recommended source of DECERR. Every data transfer of a request must still be completed on an error. Both are in the Arm AMBA AXI and ACE Protocol Specification, IHI 0022, issue H.c, section A3.4.5.

Rules 1 to 3 are design practice. The AXI specification describes the interfaces and leaves the inside of an interconnect to its designer. In this lab each arbiter prefers the lower entrance. A subordinate takes the next read when the reply to the last one has gone.

Now Run It

The lab at the end of this page is the crossbar of the last lesson, with its read IDs switched off. In its output, m0 and m1 are the two managers. Each row is one handshake. The rows below start after the two writes of the last lesson.

Printed by the lab. An AR row is a read address taken at that edge. An R row is the reply: the data, and the response code as resp.
e4 AR m0 addr=10000000
e4 AR m1 addr=80000000
e6 R  m0 data=00000068 resp=00
e6 R  m1 data=000000d1 resp=00
e7 AR m0 addr=80000000
e7 AR m1 addr=80000000
e9 R  m0 data=000000d1 resp=00
e11 R  m1 data=000000d1 resp=00
e12 AR m0 addr=10007000
e14 R  m0 data=00000000 resp=11

Rule 1 at work: at e4 the two managers read different subordinates. Both replies come at e6. Neither waited for the other.

Rules 2 and 3 at work: at e7 both read the SRAM word. The arbiter of SRAM serves m0 first, and its reply comes at e9. The reply to m1 comes at e11, two edges later. Both get the same data, d1.

Rule 4 at work: at e12 m0 reads 0x1000_7000, which nobody owns. The reply at e14 has resp=11, which is DECERR. Its data is zero, and rule 5 says what that zero is worth: nothing.

This lab leaves things out. Each arbiter always prefers m0, which is the fixed priority that can starve. Every request is a single transfer. The managers are test code.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
An arbiter at each subordinateOne arbiter for the whole crossbarTraffic to different subordinates never waits for each other. It costs one arbiter for each subordinate.
A default subordinateNo reply to an address nobody ownsA wrong address ends with an error the program can handle. Without it the manager waits for ever.
An error as a code in the replyAn error as extra cycles, as on AHBThe reply needs no special timing, and other requests keep moving. The manager must check the code of every reply.

The last row is where AXI and AHB part. An AHB error takes two cycles, so that the manager can cancel the request behind it. An AXI error is one more value in a reply that had to come anyway.

The Trap: Two Entrances, One Memory

Back to the copy job that did not get faster. On the old shared bus, the processor and DMA took turns. The team counted two entrances on the new crossbar, and expected both to run at full speed.

Both managers spent nearly all their time in SRAM. The crossbar gave each its own way in, and then both ways ended at one arbiter. The picture of the recorded run at e7 applied to every transfer.

A crossbar removes waiting between managers that want different things. Before buying one, write down where each manager sends most of its requests. If the lists are the same, the money belongs in a second memory port.

At Scale

This page2 managers, 2 arbiters
A large chipdozens of managers, an arbiter at every subordinate

This section looks ahead. One tie between two managers costs two edges here. A large chip has dozens of managers and long bursts in front of each memory.

  1. How long can a loser wait?

    With fixed priority, for ever. The lesson on quality of service turns a policy into a number you can promise.

  2. Waits that never end

    A request can wait for a reply that waits for the request. The lesson on ordering in an interconnect shows how to find such a loop.

  3. The error codes

    The Protocols track covers every response code, and the special reads and writes that add to them, in responses and exclusive access.

Try It

Run the lab. Mark each R row with the edge of its AR row, and write down how many edges lie between.

In the test code, find the line that sends both managers to SRAM at e7. Change the address of m0 there to the console. Predict the edges of both replies, then run.

In the last read of the test code, change the address 10007000 to 10000000. Predict the data and the response code of the last row.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e0 AW m0 addr=10000000 e0 AW m1 addr=80000000 e1 W m0 data=00000068 e1 W m1 data=000000d1 e3 B m0 resp=00 e3 B m1 resp=00 e4 AR m0 addr=10000000 e4 AR m1 addr=80000000 e6 R m0 data=00000068 resp=00 e6 R m1 data=000000d1 resp=00 e7 AR m0 addr=80000000 e7 AR m1 addr=80000000 e9 R m0 data=000000d1 resp=00 e11 R m1 data=000000d1 resp=00 e12 AR m0 addr=10007000 e14 R m0 data=00000000 resp=11
Read included file: axi_pair.sv
// Two AXI4-Lite manager ports, two one-word register targets and a default.
// Protection is fixed by the BFM. TAG_READ adds a single-beat AXI read-ID path.
// Each port admits one read and one write at a time. Each target arbitrates
// locally. Its read response register holds the payload until the owner takes it.
module axi_pair #(parameter bit TAG_READ = 0) (
  input logic clk, reset_n,
  input logic [1:0] awvalid, wvalid, bready, arvalid, rready,
  output logic [1:0] awready, wready, bvalid, arready, rvalid,
  input logic [31:0] awaddr[0:1],
  input logic [31:0] wdata[0:1],
  input logic [31:0] araddr[0:1],
  input logic [3:0] wstrb[2],
  input logic [1:0] arid[2],
  output logic [1:0] rid[0:1],
  output logic [1:0] rresp[0:1],
  output logic [1:0] bresp[0:1],
  output logic [31:0] rdata[2]
);
  function automatic logic [1:0] decode(input logic [31:0] address);
    case (address)
      32'h10000000: return 0; // console scratch word in this experiment
      32'h80000000: return 1; // first SRAM word
      default: return 2;
    endcase
  endfunction

  logic [1:0] have_aw, have_w, queued, reading;
  logic [1:0] write_target[2], read_target[2], local_id[2];
  logic [31:0] payload[2], word_q[2];
  logic [3:0] lanes[2];
  logic [2:0] occupied;
  logic lite_owner[3];
  logic [2:0] tag[3];
  logic [31:0] reply[3];
  wire owner[3];
  for (genvar t=0; t<3; t++)
    assign owner[t] = TAG_READ ? tag[t][2] : lite_owner[t];

  assign awready = ~have_aw & ~bvalid;
  assign wready = ~have_w & ~bvalid;
  assign arready = ~reading;

  always_comb begin
    rvalid = 0;
    for (int m=0; m<2; m++) begin
      rid[m] = 0;
      rresp[m] = 0;
      rdata[m] = 0;
    end
    for (int t=0; t<3; t++) begin
      if (occupied[t]) begin
        rvalid[owner[t]] = 1;
        rdata[owner[t]] = reply[t];
        rid[owner[t]] = TAG_READ ? tag[t][1:0] : 0;
        rresp[owner[t]] = t == 2 ? 2'b11 : 0;
      end
    end
  end

  always_ff @(posedge clk) begin
    if (!reset_n) begin
      have_aw <= 0;
      have_w <= 0;
      bvalid <= 0;
      queued <= 0;
      reading <= 0;
      occupied <= 0;
      word_q[0] <= 0;
      word_q[1] <= 0;
    end else begin
      for (int m=0; m<2; m++) begin
        if (awvalid[m] && awready[m]) begin
          write_target[m] <= decode(awaddr[m]);
          have_aw[m] <= 1;
        end
        if (wvalid[m] && wready[m]) begin
          payload[m] <= wdata[m];
          lanes[m] <= wstrb[m];
          have_w[m] <= 1;
        end
        if (bvalid[m] && bready[m]) bvalid[m] <= 0;
        if (arvalid[m] && arready[m]) begin
          read_target[m] <= decode(araddr[m]);
          local_id[m] <= arid[m];
          queued[m] <= 1;
          reading[m] <= 1;
        end
      end
      for (int t=0; t<3; t++) begin
        logic wrote, issued;
        wrote = 0;
        issued = 0;
        if (occupied[t] && rready[owner[t]]) begin
          occupied[t] <= 0;
          reading[owner[t]] <= 0;
        end
        // Fixed port order resolves ties independently at each target.
        for (int m=0; m<2; m++) begin
          if (!wrote && have_aw[m] && have_w[m] && write_target[m] == t) begin
            wrote = 1;
            if (t < 2)
              for (int b=0; b<4; b++)
                if (lanes[m][b]) word_q[t][8*b+:8] <= payload[m][8*b+:8];
            bresp[m] <= t == 2 ? 2'b11 : 0;
            bvalid[m] <= 1;
            have_aw[m] <= 0;
            have_w[m] <= 0;
          end
          if (!occupied[t] && !issued && queued[m] && read_target[m] == t) begin
            issued = 1;
            occupied[t] <= 1;
            queued[m] <= 0;
            lite_owner[t] <= m[0];
            tag[t] <= {m[0],local_id[m]};
            reply[t] <= t < 2 ? word_q[t] : 0;
          end
        end
      end
    end
  end
endmodule

Check Yourself

Predict the outputThe test code is changed. After the two writes, there is one pair of reads at e4. Manager 0 reads the SRAM word, and manager 1 reads 0x1000_7000, which nobody owns. The run ends when both replies have come. What is the last line the lab prints?
module tb;
  parameter bit TAG_READ = 0;
  bit clk, reset_n;
  always #5 clk = !clk;
  logic [1:0] awvalid=0, wvalid=0, bready=3, arvalid=0, rready=3;
  wire [1:0] awready, wready, bvalid, arready, rvalid;
  logic [31:0] awaddr[2], wdata[2], araddr[2];
  logic [3:0] wstrb[2];
  logic [1:0] arid[2];
  wire [1:0] rid[2], rresp[2], bresp[2];
  wire [31:0] rdata[2];
  axi_pair #(TAG_READ) fabric(.*);
  int edge_no;
  task automatic tick;
    @(posedge clk);
    for (int m=0; m<2; m++) begin
      if (awvalid[m] && awready[m]) $display("e%0d AW m%0d addr=%08h",edge_no,m,awaddr[m]);
      if (wvalid[m] && wready[m]) $display("e%0d W  m%0d data=%08h",edge_no,m,wdata[m]);
      if (bvalid[m] && bready[m]) $display("e%0d B  m%0d resp=%b",edge_no,m,bresp[m]);
      if (arvalid[m] && arready[m]) $display("e%0d AR m%0d addr=%08h",edge_no,m,araddr[m]);
      if (rvalid[m] && rready[m]) begin
        if (TAG_READ)
          $display("e%0d R  m%0d target_tag=%03b rid=%02b data=%08h resp=%b",
            edge_no,m,fabric.tag[fabric.read_target[m]],rid[m],rdata[m],rresp[m]);
        else $display("e%0d R  m%0d data=%08h resp=%b",edge_no,m,rdata[m],rresp[m]);
      end
    end
    @(negedge clk);
    edge_no++;
  endtask
  initial begin
    @(negedge clk);
    reset_n=1;
    awaddr[0]='h10000000; awaddr[1]='h80000000;
    wdata[0]='h68; wdata[1]='hd1; wstrb[0]=1; wstrb[1]=15;
    awvalid=3; tick();
    awvalid=0; awaddr[0]='h80000000; wvalid=3; tick();
    wvalid=0; repeat (2) tick();
    // Manager 0 reads SRAM. Manager 1 reads an address that nobody owns.
    araddr[0]='h80000000; araddr[1]='h10007000; arvalid=3; tick();
    arvalid=0; repeat (2) tick();
    $finish;
  end
endmodule
Read included file: axi_pair.sv
// Two AXI4-Lite manager ports, two one-word register targets and a default.
// Protection is fixed by the BFM. TAG_READ adds a single-beat AXI read-ID path.
// Each port admits one read and one write at a time. Each target arbitrates
// locally. Its read response register holds the payload until the owner takes it.
module axi_pair #(parameter bit TAG_READ = 0) (
  input logic clk, reset_n,
  input logic [1:0] awvalid, wvalid, bready, arvalid, rready,
  output logic [1:0] awready, wready, bvalid, arready, rvalid,
  input logic [31:0] awaddr[0:1],
  input logic [31:0] wdata[0:1],
  input logic [31:0] araddr[0:1],
  input logic [3:0] wstrb[2],
  input logic [1:0] arid[2],
  output logic [1:0] rid[0:1],
  output logic [1:0] rresp[0:1],
  output logic [1:0] bresp[0:1],
  output logic [31:0] rdata[2]
);
  function automatic logic [1:0] decode(input logic [31:0] address);
    case (address)
      32'h10000000: return 0; // console scratch word in this experiment
      32'h80000000: return 1; // first SRAM word
      default: return 2;
    endcase
  endfunction

  logic [1:0] have_aw, have_w, queued, reading;
  logic [1:0] write_target[2], read_target[2], local_id[2];
  logic [31:0] payload[2], word_q[2];
  logic [3:0] lanes[2];
  logic [2:0] occupied;
  logic lite_owner[3];
  logic [2:0] tag[3];
  logic [31:0] reply[3];
  wire owner[3];
  for (genvar t=0; t<3; t++)
    assign owner[t] = TAG_READ ? tag[t][2] : lite_owner[t];

  assign awready = ~have_aw & ~bvalid;
  assign wready = ~have_w & ~bvalid;
  assign arready = ~reading;

  always_comb begin
    rvalid = 0;
    for (int m=0; m<2; m++) begin
      rid[m] = 0;
      rresp[m] = 0;
      rdata[m] = 0;
    end
    for (int t=0; t<3; t++) begin
      if (occupied[t]) begin
        rvalid[owner[t]] = 1;
        rdata[owner[t]] = reply[t];
        rid[owner[t]] = TAG_READ ? tag[t][1:0] : 0;
        rresp[owner[t]] = t == 2 ? 2'b11 : 0;
      end
    end
  end

  always_ff @(posedge clk) begin
    if (!reset_n) begin
      have_aw <= 0;
      have_w <= 0;
      bvalid <= 0;
      queued <= 0;
      reading <= 0;
      occupied <= 0;
      word_q[0] <= 0;
      word_q[1] <= 0;
    end else begin
      for (int m=0; m<2; m++) begin
        if (awvalid[m] && awready[m]) begin
          write_target[m] <= decode(awaddr[m]);
          have_aw[m] <= 1;
        end
        if (wvalid[m] && wready[m]) begin
          payload[m] <= wdata[m];
          lanes[m] <= wstrb[m];
          have_w[m] <= 1;
        end
        if (bvalid[m] && bready[m]) bvalid[m] <= 0;
        if (arvalid[m] && arready[m]) begin
          read_target[m] <= decode(araddr[m]);
          local_id[m] <= arid[m];
          queued[m] <= 1;
          reading[m] <= 1;
        end
      end
      for (int t=0; t<3; t++) begin
        logic wrote, issued;
        wrote = 0;
        issued = 0;
        if (occupied[t] && rready[owner[t]]) begin
          occupied[t] <= 0;
          reading[owner[t]] <= 0;
        end
        // Fixed port order resolves ties independently at each target.
        for (int m=0; m<2; m++) begin
          if (!wrote && have_aw[m] && have_w[m] && write_target[m] == t) begin
            wrote = 1;
            if (t < 2)
              for (int b=0; b<4; b++)
                if (lanes[m][b]) word_q[t][8*b+:8] <= payload[m][8*b+:8];
            bresp[m] <= t == 2 ? 2'b11 : 0;
            bvalid[m] <= 1;
            have_aw[m] <= 0;
            have_w[m] <= 0;
          end
          if (!occupied[t] && !issued && queued[m] && read_target[m] == t) begin
            issued = 1;
            occupied[t] <= 1;
            queued[m] <= 0;
            lite_owner[t] <= m[0];
            tag[t] <= {m[0],local_id[m]};
            reply[t] <= t < 2 ? word_q[t] : 0;
          end
        end
      end
    end
  end
endmodule
ConceptWhen can a crossbar serve two managers in the same cycles?
ConceptIn the recorded run, both managers read SRAM at e7. Why does m1 get its reply at e11 and not at e9?
ConceptWhy does each subordinate have its own arbiter?
ConceptA write goes to an address that nobody owns. What happens to its write data?

Common Mistakes

Wrong Expect a crossbar to double the speed of two managers that use the same memory.

Both paths end at one arbiter, and the memory answers one request at a time.

Fix Count the subordinates the managers share before counting entrances.

Wrong Put one arbiter in front of the whole crossbar.

Managers that want different subordinates would then wait for each other.

Fix Arbitrate at each subordinate, among the requests for that subordinate.

Wrong Use the data of a read whose reply says DECERR.

The default subordinate returned it, and it means nothing.

Fix Check the response code of every reply before using the data.

Remember

  • Two requests can only meet at a subordinate; with different destinations a crossbar serves both at once.
  • Each subordinate has its own arbiter, so a tie there delays nobody else.
  • The loser of a tie waits for the winner and for nothing else.
  • A request that decodes to nobody goes to the default subordinate and gets a DECERR reply.
  • Every transfer of a failed request still happens, and the data of a failed read must not be used.

Practice

Report a problem with this page