Many Managers: Arbitration and the Bus Matrix
A chip with one manager never argues over the bus. Add a second, and two blocks want the same memory at the same clock edge. Something must choose, and choose fairly.
You Will Be Able To
- Say which requests a bus matrix can serve in the same cycle, and which it cannot.
- Tell a granted request from a served one.
- Compare fixed priority with round robin, and explain starvation.
- Lesson
- S4.4
- Time
- 26 min
- Runs on
- Your browser
- Check
- 5 questions
A program reads a word from memory in two cycles all day. Then a second block starts copying data, and the same read sometimes takes four. Nothing is faulty. The read had to wait its turn.
Before You Start
You need the manager, the subordinate and the wait state of S0.3. You need the decoder of Address Decode and Aliases, and the way back from One Manager, Many Subordinates.
| Question | |
|---|---|
| 1 | Why does a second manager make an arbiter necessary? |
| 2 | What can two managers do on a bus matrix that they cannot do on one shared bus? |
| 3 | What is the difference between a request that is granted and one that is served? |
| 4 | How do fixed priority and round robin choose the winner of a tie? |
| 5 | What is starvation, and which rule prevents it? |
The Idea: Where Requests Meet, Something Must Choose
Until now, one manager started every transfer. Real chips have more. The usual second one is a DMA block, for direct memory access. It copies data between memory and a device by itself, so the processor need not move every word.
Two managers can ask for the same thing in the same cycle. A subordinate serves one transfer at a time, so one request must wait. Choosing is called arbitration, and the block that chooses is an arbiter.
The first question is where to choose. A shared bus has one set of wires for everybody. One arbiter gives the whole bus to one manager, and the other waits even when it wants a different block. A bus matrix gives each manager its own path to every destination. Requests then meet only at a destination that both want.
The second question is whom to choose. If the same manager always wins, the other may never be served. That is starvation, and a fair rule prevents it.
New Words
| Word | Meaning |
|---|---|
| DMA | Direct memory access: a block that copies data by itself. It is a manager, like the processor. |
| Arbiter | The block that chooses which request goes first. What it does is called arbitration. |
| Grant | The answer of an arbiter to one manager: you may go. |
| Shared bus | One set of bus wires for all managers. One manager uses it in a cycle. |
| Bus matrix | A path from every manager to every destination, with an arbiter at each destination. |
| Tie | Two requests for the same destination in the same cycle. |
| Fixed priority | A rule for ties: the same manager always wins. |
| Round robin | A rule for ties: the manager that was served last waits. |
| Starvation | A request that is never served, because another manager always wins. |
One Picture: Two Managers, Two Destinations
- Processor
- Peripheral
- Bus
- Memory
- One manager
With the processor alone, no choice is ever needed. Each destination has at most one request.
- A second manager
DMA starts transfers of its own. Now two requests can arrive in the same cycle.
- Different destinations
The processor reads ROM while DMA reads SRAM. Each request has a path of its own, so both are served in the same cycle.
- The same destination
Both ask for SRAM. SRAM can serve one of them. Its arbiter grants one request and makes the other wait.
- The next cycle
The request that lost is still there. The arbiter now has to be fair to it, or it may wait for ever.
Read the diagram as text
- Processor: the first manager
- DMA: a second manager: it copies data by itself
- Arbiter at ROM: chooses among the requests for ROM
- Arbiter at SRAM: chooses among the requests for SRAM
- Boot ROM: serves one transfer in a cycle
- SRAM: serves one transfer in a cycle
- Processor → Arbiter at ROM: request
- Processor → Arbiter at SRAM: request
- DMA → Arbiter at ROM: request
- DMA → Arbiter at SRAM: request
- Arbiter at ROM → Boot ROM: the winner
- Arbiter at SRAM → SRAM: the winner
This arrangement, with a path from every manager to every destination, is a bus matrix. The way back is not drawn.
A destination here is a subordinate seen from the matrix. Each one keeps the single port it always had. The matrix and its arbiters sit in front of that port.
The Smallest Example, Worked by Hand: Four Requests
The processor wants ROM and then SRAM. DMA wants SRAM twice. Every destination is ready, and every transfer takes one cycle. Count the cycles on a shared bus, and then on a bus matrix.
| Cycle 1 | Cycle 2 | Cycle 3 | Cycle 4 | |
|---|---|---|---|---|
| Shared bus | processor to ROM | DMA to SRAM | processor to SRAM | DMA to SRAM |
| Bus matrix | processor to ROM, and DMA to SRAM | processor to SRAM | DMA to SRAM |
The shared bus needs four cycles, one for each transfer. The matrix needs three. In cycle 1 the two requests go to different destinations, so both are served.
Cycle 2 on the matrix is a tie at SRAM. Suppose it goes on: both managers ask for SRAM in every cycle. Who is served?
| Rule | Tie 1 | Tie 2 | Tie 3 | Tie 4 | Tie 5 | Tie 6 |
|---|---|---|---|---|---|---|
| Fixed priority, processor first | processor | processor | processor | processor | processor | processor |
| Round robin | processor | DMA | processor | DMA | processor | DMA |
Under fixed priority DMA is never served while the processor keeps asking. Under round robin it waits one turn at most.
The Rules
Rule 1: A destination serves one transfer in a cycle.
Two managers are served in the same cycle only when they want different destinations, and each has a path of its own.
Rule 2: Arbitrate where the requests meet.
In a bus matrix every destination has its own arbiter. It sees only the requests meant for that destination.
Rule 3: Granted is not served.
A grant says "you may go". The transfer happens only if the destination is also ready. Count progress by transfers served.
Rule 4: Under fixed priority, one manager wins every tie.
It never waits for the other. The other waits for as long as the first keeps asking, and can starve.
Rule 5: Under round robin, the manager served last loses the next tie.
A turn is used up only by a transfer that was served. With two managers, nobody loses two ties in a row.
Sources for These Rules
Arm AMBA AHB Protocol Specification, document IHI 0033, issue C, section 4.1. It says that a system with several managers needs an interconnect that arbitrates and routes. It leaves the arbitration rule and the structure to the designer.
The older shared AHB bus had one central arbiter, with a request wire and a grant wire for each manager. Arm AMBA Specification, revision 2.0, document IHI 0011, issue A, section 3.11.
Fixed priority and round robin are common practice, not rules of AHB. The arbiter in the lab is our own.
Now Run It
The lab at the end of this page has two managers, ROM and SRAM, and an arbiter at each destination. The managers are test code. Each has a list of requests and asks for one at a time, until it is served. In this run the tie rule is round robin, and SRAM is busy for one cycle. The lab calls the processor cpu and the DMA block dma.
e0 cpu wants nothing, dma wants nothing | granted: nobody | served: nobody
e1 cpu wants ROM, dma wants SRAM | granted: cpu and dma | served: cpu and dma
e2 cpu wants SRAM, dma wants SRAM | granted: cpu | served: cpu
e3 cpu wants SRAM, dma wants SRAM | granted: dma | served: nobody
e4 cpu wants SRAM, dma wants SRAM | granted: dma | served: dma
e5 cpu wants SRAM, dma wants SRAM | granted: cpu | served: cpu
e6 cpu wants SRAM, dma wants SRAM | granted: dma | served: dma
e7 cpu wants SRAM, dma wants SRAM | granted: cpu | served: cpu
e8 cpu wants nothing, dma wants SRAM | granted: dma | served: dma
e9 cpu wants nothing, dma wants nothing | granted: nobody | served: nobody
cpu: served 4, longest wait 2 | dma: served 4, longest wait 2Rule 1 at work: e1 serves both managers, one at ROM and one at SRAM. Rule 3 at work: at e3 DMA is granted and nobody is served, because SRAM is busy. At e4 the grant is still DMA's. It did not move while nothing was served.
Rule 5 at work: from e4 to e7 the served manager alternates: DMA, processor, DMA, processor. Neither waits more than two edges, and one of those two was SRAM's own busy cycle.
Now change the two constants at the top of the lab, one at a time, and compare the last lines.
| Run | Longest wait, processor | Longest wait, DMA | Last edge that serves a transfer |
|---|---|---|---|
| Bus matrix, round robin | 2 | 2 | e8 |
| Bus matrix, fixed priority | 1 | 4 | e8 |
| Shared bus, round robin | 2 | 2 | e9 |
Recorded from the lab with ROTATE and MATRIX changed. Waits are counted in clock edges.
Rule 4 at work: fixed priority cuts the processor's longest wait to one edge, SRAM's busy cycle. DMA pays for it with a wait of four. On the shared bus the same work ends one edge later, because the first two requests could not go together.
This lab leaves things out. Its managers hand over a request and get a "served" back, with no address phase and no data phase. Every transfer is a single one. The next lesson adds transfers that must stay together.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| A bus matrix | One shared bus | Transfers to different destinations do not wait for each other. It costs an arbiter and a multiplexer at every destination, and many more wires. |
| Round robin | Fixed priority | Every manager is served within a known number of turns. No manager can be made faster than the others. |
| Fixed priority | Round robin | One urgent manager never waits for the others. The others can starve. |
| A turn counts only when a transfer is served | Move the turn at every grant | A busy destination does not use up a manager's turn. The arbiter must look at "ready". |
Real arbiters often mix the two rules: a few priority levels, and round robin among the managers of one level.
The Trap: Fast on Average, Starved in Fact
A team gives the processor fixed priority at SRAM, since the processor is what the user feels. Every test passes, and the average wait at SRAM is short.
Then one program runs a tight loop that reads SRAM in every cycle. DMA was filling a buffer for a display. It stops, for as long as the loop runs, and the picture freezes. The second recorded run above shows it in small: DMA waits four edges while the processor waits one.
An average hides this. Ask for the longest wait, and ask what bounds it. Under fixed priority the answer is "nothing, unless the winner stops asking".
At Scale
This section looks ahead. The lab has two managers and two destinations. ap_soc has three managers, and a large chip has dozens.
Transfers that must stay together
Some transfers come in runs, and some pairs must not be split. Then the arbiter may not change its grant at every cycle. The next lesson, on transfers that belong together, covers both.
A bound in time
Round robin bounds the number of turns a manager waits. A bound in clock cycles also needs a limit on how long one turn can last.
The circuit
Another track of this site builds both arbiters gate by gate, in Round-robin and priority arbiters. The Protocols track shows the manager's side on AHB, in Many managers.
Try It
Run the lab. For each row, say who is granted and who is served before you read the right-hand side.
Set ROTATE to 0. Predict the last line, then run.
Set ROTATE back to 1 and MATRIX to 0. Find the first row that differs from the first run, and say why.
Give DMA a ROM request in place of its first SRAM request. Predict what e1 shows.
e0 cpu wants nothing, dma wants nothing | granted: nobody | served: nobody e1 cpu wants ROM, dma wants SRAM | granted: cpu and dma | served: cpu and dma e2 cpu wants SRAM, dma wants SRAM | granted: cpu | served: cpu e3 cpu wants SRAM, dma wants SRAM | granted: dma | served: nobody e4 cpu wants SRAM, dma wants SRAM | granted: dma | served: dma e5 cpu wants SRAM, dma wants SRAM | granted: cpu | served: cpu e6 cpu wants SRAM, dma wants SRAM | granted: dma | served: dma e7 cpu wants SRAM, dma wants SRAM | granted: cpu | served: cpu e8 cpu wants nothing, dma wants SRAM | granted: dma | served: dma e9 cpu wants nothing, dma wants nothing | granted: nobody | served: nobody cpu: served 4, longest wait 2 | dma: served 4, longest wait 2Check Yourself
Common Mistakes
Wrong Count every granted cycle as progress.
The destination can be busy while a request holds the grant.
Fix Count the cycles in which a transfer was served.
Wrong Use one arbiter for the whole chip.
Requests for different destinations then wait for each other.
Fix Put an arbiter at each destination, where the requests really meet.
Wrong Judge an arbiter by its average wait.
A starved manager can hide behind a good average.
Fix Find the longest wait, and what bounds it.
Remember
- A second manager means two requests can meet at one subordinate; an arbiter chooses.
- A bus matrix serves requests for different destinations in the same cycle; a shared bus cannot.
- A grant is not a transfer: progress is counted in transfers served.
- Fixed priority never makes the winner wait, and can starve the loser.
- Round robin makes the manager served last wait, so every manager gets its turn.