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.
| Question | |
|---|---|
| 1 | When can a crossbar serve two managers in the same cycles? |
| 2 | Where does a crossbar arbitrate, and why not once for the whole crossbar? |
| 3 | What does a tie cost the manager that loses it? |
| 4 | Who answers a request to an address that nobody owns, and with which reply? |
| 5 | What 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
| Word | Meaning |
|---|---|
| Contention | Two requests that want the same subordinate at the same time. |
| Tie | One clock edge at which an arbiter has more than one request to choose from. |
| Response code | A few bits in every AXI reply that say how the request ended. |
| OKAY | The response code for success: 00 in this lab. |
| DECERR | The response code for "the address decodes to nobody": 11 in this lab. |
| SLVERR | The 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
- Processor
- Peripheral
- Bus
- Memory
- 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.
- 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.
- 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.
| Manager 0 reads | Manager 1 reads | Arbiters with a tie | Who waits |
|---|---|---|---|
| the console | SRAM | none | nobody |
| SRAM | the console | none | nobody |
| SRAM | SRAM | the SRAM arbiter | one of the two |
| an address nobody owns | the console | none | nobody: 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.
| Design | Different subordinates | The same subordinate |
|---|---|---|
| One arbiter for the whole crossbar | 1 | 1 |
| An arbiter at each subordinate | 2 | 1 |
The Rules
Rule 1: Requests for different subordinates do not wait for each other.
Each has its own entrance and meets its own arbiter.
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.
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.
Rule 4: A request that decodes to nobody gets a DECERR reply.
The crossbar sends it to a default subordinate, which gives that reply.
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.
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=11Rule 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 choice | The alternative | What the choice buys, and costs |
|---|---|---|
| An arbiter at each subordinate | One arbiter for the whole crossbar | Traffic to different subordinates never waits for each other. It costs one arbiter for each subordinate. |
| A default subordinate | No reply to an address nobody owns | A wrong address ends with an error the program can handle. Without it the manager waits for ever. |
| An error as a code in the reply | An error as extra cycles, as on AHB | The 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 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.
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.
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.
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.
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=11Read 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
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.