Fairness and Starvation
An arbitration policy is a promise about waiting. Round-robin promises a bound; fixed priority promises none. Read the promise from the RTL and measure each manager's waits on a real run. Then see why a test may never stretch the promise.
You Will Be Able To
- State an arbitration policy as a checkable promise with a bound.
- Read the waits of each manager from a recorded histogram.
- Explain why the same traffic gave the same waits under both rules on ap_soc.
- Say what traffic and which checker sites a fairness check needs.
- Lesson
- V7.4
- Time
- 24 min
- Runs on
- Your browser
- Check
- 5 questions
At stage E3, four random managers hammered the matrix. With round-robin, no waiting transfer saw more than 3 transfers of others go first. With fixed priority, on the same traffic, one saw 91.
| Manager and latency | Transfers | |
|---|---|---|
| Seat | 513 | |
| 1 cycle | 320 | ■■■■■■■■■■■■■■■■■■■■■■■■ |
| 2 cycles | 97 | ■■■■■■■ |
| 3 cycles | 96 | ■■■■■■■ |
| DMA | 192 | |
| 1 cycle | 192 | ■■■■■■■■■■■■■■■■■■■■■■■■ |
| Debug manager | 3 | |
| 1 cycle | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■ |
Latency of each SRAM transfer, from address phase taken to data phase ended, in one recorded run on ap_soc v1.5 (round-robin). The same bench on Icarus with a probe added to soc_tb (record-v7-labs.mjs, section fair, seed 7).
Before You Start
Read Stress: Random Concurrent Traffic, Many Managers: Arbitration and the Bus Matrix and Quality of Service and Latency Bounds first.
| Question | |
|---|---|
| 1 | What does each arbitration policy promise about waiting? |
| 2 | What is starvation, and how is it different from a long wait? |
| 3 | Why did both rules give ap_soc the same waits in the lab? |
| 4 | Which traffic stretches a fairness promise? |
| 5 | Where must a fairness checker look? |
The Idea: A Policy Is a Promise
When two managers want one target, the arbiter decides who waits. That decision follows a rule, and every such rule makes a promise about waiting. Fixed priority promises that the highest priority always wins. Round-robin promises that nobody waits more than one turn of the others.
Starvation is the broken promise: a manager that asks and is never served, while others keep going. A long wait is not starvation; a wait that never ends is. A good test turns the promise into a bound to check. One such bound: served before the target takes N transfers of others.
Which promise a chip makes is a design choice. ap_soc builds round-robin into each target's arbiter, and gives fixed priority the order debug, DMA, core data, core instruction. The rare askers come first, so they cannot be crowded out. They ask too rarely to crowd out the core (facts 27.7).
- Manager
- Control / FSM
- Memory
- Result
- Control
- Data
- Transaction / TLM
- Fixed priority
The lowest number that asks wins every time. A manager that always asks shuts out every manager above it.
- Round-robin
The search starts one above the manager served last and wraps. With four managers, a waiting one is served before three others have each gone once.
Read the diagram as text
- Requests: debug 0, DMA 1, core data 2, core instr 3
- Fixed priority: FAIR = 0: lowest number wins
- Round-robin: FAIR = 1: one above the last served
- Target: one transfer at a time
- The promise: at most 3 others go first
- No bound: a low priority may wait for ever
- Requests → Fixed priority: who asks
- Requests → Round-robin: who asks
- Fixed priority → Target: grant
- Round-robin → Target: grant
- Round-robin → The promise: bounded wait
- Fixed priority → No bound: if someone always asks
tools/soc/ap_soc/rtl/ap_ahb_matrix_out.sv; the parameter FAIR of ap_soc_fabric is 1 in ap_soc v1.5 (facts 27.7).
New Words
| Word | Meaning |
|---|---|
| Arbitration policy | The rule an arbiter uses to pick one of several requests. |
| Fixed priority | The highest-priority request always wins; on ap_soc, the lowest manager number. |
| Round-robin | The search for the next winner starts just after the last one served. |
| Starvation | A manager that keeps asking and is never served while others are. |
| Fairness bound | The most transfers of others that may go before a waiting one. |
| Histogram | A count of how many times each value occurred. |
The Smallest Example: Three Managers That Always Ask
Three managers ask in every cycle for a target that serves one transfer a cycle. Manager 0 has the highest priority. Work out the first six winners by hand.
| Cycle | Fixed priority | Round-robin (last served before cycle 0: manager 2) |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 2 | 0 | 2 |
| 3 | 0 | 0 |
| 4 | 0 | 1 |
| 5 | 0 | 2 |
The example below runs 30 cycles of each and prints the longest wait of each manager.
Under fixed priority, managers 1 and 2 are never served: starved, because manager 0 never stops asking. Under round-robin each waits two cycles at most. The rule alone does not starve anyone. A rule plus a manager that always asks does.
The Rules
Rule 1: State the arbiter's rule as a bound you can check.
Round-robin with four managers: a waiting transfer is served before three transfers of others. Write that number down.
Rule 2: Count waits in transfers, not cycles.
One slow APB transfer can take a dozen cycles. The rule bounds how many go first, not how long they take.
Rule 3: Check the bound with a passive checker, at two sites.
The manager's port says when it starts waiting; only the target's port says whom the target served meanwhile.
Rule 4: Make traffic that stretches the promise.
Beside the manager you watch, put managers that ask as often as they can, at the same target.
Rule 5: Look for starvation as a wait that never ends.
Watch each manager's progress: one that stops finishing transfers while the others go on is starved.
Rule 6: Treat fixed priority as a choice with a reason.
Then check the reason: that the low priorities still finish under the traffic the chip expects.
Sources for These Rules
ap_soc's arbiters, the manager order, FAIR = 1 and its reason: facts 27.7 and tools/soc/ap_soc/rtl/ap_ahb_matrix_out.sv. The waits of the E3 gate, 3 with FAIR = 1 and 91 with FAIR = 0: plan §3.10, stage E3.
AHB-Lite itself defines no arbiter. A system with several managers needs an interconnect that arbitrates, and the rule is its choice (AMBA AHB, IHI 0033C 4.1).
Preventing one block from dominating the others as a goal of performance analysis: MEHTA-DV 14.2.1.
The Lab: The Waits of Each Manager
The arbiter of each target is three lines of RTL. Read them, then read what they did on a run.
assign above = req & ~last_q;
assign pick = (FAIR && (above != '0)) ? (above & (~above + 1'b1)) : (req & (~req + 1'b1));
assign grant = kept_q ? kept_grant_q : pick;core w 80003200 2468ace0 ffffffff 00000000 0 1
core w 10006000 80003200 ffffffff 00000000 0 1
core w 10006004 80003a00 ffffffff 00000000 0 1
core w 10006008 00000060 ffffffff 00000000 0 1
core w 1000600c 00000001 ffffffff 00000000 0 1
jtag stream 80003200 00000003 00000002 2468ace0 0 1
core rq 80003200 00000000 ffffffff 2468ace0 0 512
core idle 00000000 00000000 ffffffff 00000000 0 1
core poll 10006014 00000fa0 00000007 00000002 0 1The histogram at the top is this run. The seat finished 513 SRAM transfers: 320 in 1 cycle, the rest in 2 or 3. A 2 is one DMA read that went first. A 3 is one DMA write that went first, plus the cycle SRAM waits when a read follows a write. So the seat never waited behind more than one transfer of others (rule 2). The DMA's 192 transfers all took 1 cycle.
| Build | Seat: worst, mean (cycles) | DMA: worst | Debug: worst | Result |
|---|---|---|---|---|
| FAIR = 1 (the chip) | 3, 1.56 | 1 | 1 | pass, 2742 cycles |
| FAIR = 0 (a build for this lab) | 3, 1.56 | 1 | 1 | pass, 2742 cycles |
The FAIR = 0 build sets the matrix parameter with a defparam on the Icarus bench. The recorder reads it back at time 0. ap_soc as built has FAIR = 1.
The two rows are identical, down to the cycle count. Both rules let the DMA win when it meets the seat. Fixed priority does because the DMA has the lower number. Round-robin does too: whenever the DMA asked, the seat was the manager served last. And the DMA never asks twice in a row, so the seat is never shut out. This traffic never stretched either promise (rule 4).
The E3 gate did stretch it. Its bench managers asked in almost every cycle. The worst wait was 3 transfers of others under round-robin, 91 under fixed priority. Here is the lesson for any fairness check: a checker proves only what its traffic tested. Watching polite traffic, it stays silent on an unfair arbiter too. With the managers of ap_soc's chip bench, no table can tell the two rules apart at SRAM. That is one reason the fabric has a bench of its own.
Why It Is Built This Way
Why round-robin, when fixed priority gave the same waits here? Because the chip must work with traffic its designers did not test. A DMA programmed for long bursts of SRAM traffic, or a debugger polling hard, would ask far more often. Round-robin's bound holds for any traffic; fixed priority's does not.
Why keep fixed priority as an option at all? Some managers need the shortest possible latency, such as a display that must not underflow. Fixed priority gives them that, at the price of no bound for the others. A parameter lets one fabric serve both kinds of chip.
Traps
The polite-traffic trap: the fairness test runs the chip's own managers and measures short waits, as this lab did. Then someone ships a fixed-priority fabric, and the first busy manager starves the core. Measure with traffic that pushes.
The cycles trap: the checker bounds the wait in cycles. A manager stuck behind three slow APB transfers waits 30 cycles under a perfect round-robin, and the checker cries wolf. Count transfers of others.
The one-site trap: a checker at the manager's port sees that it waits, but not whom the target served. It cannot tell a slow target from an unfair one. Watch the target's port too.
The silent-starvation trap: the starved manager's job never finishes, and the test waits for it until the cycle limit. The run fails with no message about who starved. A checker that counts each manager's progress names the victim.
At Scale
This section looks ahead. ap_soc has one round-robin arbiter per target and four managers.
Weights and classes
Large fabrics use weighted round-robin and traffic classes: a display gets more turns than a background copy. Each class has its own bound to check.
Quality of service
AXI managers mark transfers with a priority (QoS); the fabric may reorder by it. Nothing in the QoS field itself promises a bound: the arbiter's rule must.
Bandwidth regulators
Some fabrics cap each manager's share over a window. The checker then measures bytes per window, per manager.
Try It
Run it: under fixed priority, managers 1 and 2 are never served.
Switch to round-robin (the predict question below). What is the longest wait of manager 2?
Would manager 1 starve if manager 0 asked only every third cycle?
manager 0: served 30, longest wait 0 cycles manager 1: served 0, longest wait 30 cycles manager 2: served 0, longest wait 30 cyclesCheck Yourself
Common Mistakes
Wrong Measure fairness only with the chip's own managers.
Polite managers never stretch the arbiter's rule.
Fix Add traffic that asks as often as it can, at the same target.
Wrong Bound the wait in cycles.
Slow transfers ahead make a fair wait long.
Fix Bound the transfers of others that go first.
Wrong Check fairness at the manager's port alone.
It cannot see whom the target served.
Fix Use the manager's port and the target's port together.
Remember
- Every arbitration policy is a promise; round-robin's is a bound, fixed priority's is none.
- Count the wait in transfers of others, and check it at the manager's and the target's ports.
- ap_soc's own managers never stretched either rule in the lab: a fairness check needs traffic that pushes.
- Starvation is a wait that never ends while others progress.