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.

A Wait-Time Histogram per Manager
Manager and latencyTransfers
Seat513
1 cycle320■■■■■■■■■■■■■■■■■■■■■■■■
2 cycles97■■■■■■■
3 cycles96■■■■■■■
DMA192
1 cycle192■■■■■■■■■■■■■■■■■■■■■■■■
Debug manager3
1 cycle3■■■■■■■■■■■■■■■■■■■■■■■■

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.

Five questions this page answers
Question
1What does each arbitration policy promise about waiting?
2What is starvation, and how is it different from a long wait?
3Why did both rules give ap_soc the same waits in the lab?
4Which traffic stretches a fairness promise?
5Where 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).

Two Rules, One ArbiterEach target of the matrix has its own arbiter. Fixed priority always takes the lowest manager number that asks. Round-robin starts the search one above the manager served last.
  • Manager
  • Control / FSM
  • Memory
  • Result
  • Control
  • Data
  • Transaction / TLM
Two Rules, One ArbiterEach target of the matrix has its own arbiter. Fixed priority always takes the lowest manager number that asks. Round-robin starts the search one above the manager served last. manager Requests debug 0, DMA 1, coredata 2, core instr 3 control Fixed priority FAIR = 0: lowestnumber wins control Round-robin FAIR = 1: one abovethe last served memory Target one transfer at atime result The promise at most 3 others gofirst result No bound a low priority may waitfor ever who askswho asksgrantgrantbounded waitif someone alwaysasks
  1. manager Requestsdebug 0, DMA 1, core data 2, core instr 3
    • who asks → Fixed priority
    • who asks → Round-robin
  2. control Fixed priorityFAIR = 0: lowest number wins
    • grant → Target
    • if someone always asks → No bound
  3. memory Targetone transfer at a time
  4. result No bounda low priority may wait for ever
  5. control Round-robinFAIR = 1: one above the last served
    • grant → Target
    • bounded wait → The promise
  6. result The promiseat most 3 others go first
  1. Fixed priority

    The lowest number that asks wins every time. A manager that always asks shuts out every manager above it.

  2. 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

New words on this page
WordMeaning
Arbitration policyThe rule an arbiter uses to pick one of several requests.
Fixed priorityThe highest-priority request always wins; on ap_soc, the lowest manager number.
Round-robinThe search for the next winner starts just after the last one served.
StarvationA manager that keeps asking and is never served while others are.
Fairness boundThe most transfers of others that may go before a waiting one.
HistogramA 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.

The first six cycles
CycleFixed priorityRound-robin (last served before cycle 0: manager 2)
000
101
202
300
401
502

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Three lines of ap_ahb_matrix_out.sv. Above holds the requests of managers above the one served last. Pick is the lowest of them (round-robin), or the lowest request of all. Grant keeps a choice the target has not taken yet.
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;
The lab's rows (record-v7-labs.mjs, section fair): a DMA copy inside SRAM, three debug reads, and 512 back-to-back seat reads, all at SRAM.
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 1

The 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.

The same traffic, both rules
BuildSeat: worst, mean (cycles)DMA: worstDebug: worstResult
FAIR = 1 (the chip)3, 1.5611pass, 2742 cycles
FAIR = 0 (a build for this lab)3, 1.5611pass, 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

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc has one round-robin arbiter per target and four managers.

  1. 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.

  2. 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.

  3. 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?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: manager 0: served 30, longest wait 0 cycles manager 1: served 0, longest wait 30 cycles manager 2: served 0, longest wait 30 cycles

Check Yourself

Predict the outputThe same three managers under round-robin. What is the last line printed?
// Three managers ask in every cycle for one target that serves one transfer a cycle. Manager 0 has the highest
// priority. fair = 1: 0 fixed priority, 1 round-robin (start the search one above the manager served last).
module tb;
  int last = 2, waited [3], longest [3], served [3];
  initial begin
    int pick;
    for (int c = 0; c < 30; c++) begin
      pick = 0;
      if (1) pick = (last + 1) % 3;   // every manager always asks, so the next one up wins
      for (int m = 0; m < 3; m++)
        if (m == pick) begin served[m]++; waited[m] = 0; end
        else begin waited[m]++; if (waited[m] > longest[m]) longest[m] = waited[m]; end
      last = pick;
    end
    for (int m = 0; m < 3; m++) $display("manager %0d: served %0d, longest wait %0d cycles", m, served[m], longest[m]);
  end
endmodule
ConceptIn the lab, why did fixed priority give the same waits as round-robin?
ConceptRound-robin with four managers promises what?
ConceptWhat makes a wait starvation?
ConceptWhy does a fairness checker need the target's port?

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.

Practice

Report a problem with this page