Quality of Service and Latency Bounds
A deadline does not care how fast a bus is on average. It asks how long one read can be kept waiting at worst. This page turns that question into a number, and says what the number rests on.
You Will Be Able To
- Tell a QoS value, which is a request, from a service policy, which decides.
- Tell an observed maximum from a bound, and derive the bound of a weighted round robin.
- Name the assumptions a bound rests on, and say who must enforce each.
- Lesson
- S4.8
- Time
- 28 min
- Runs on
- Your browser
- Check
- 5 questions
On a quiet board the timer handler meets its deadline every time. Start a large copy by DMA, and the handler starts to miss. The interrupt still arrives on time. The delay is on the way to memory.
Before You Start
You need arbiters, fixed priority, round robin and starvation from Many Managers. You need bursts from Bursts, Locks and the Waiting Request.
One signal on this page belongs to AXI, which the Protocols track teaches. Start with AXI in one picture. The signal itself is in a later lesson of that track. The arbitration on this page works the same on any bus.
| Question | |
|---|---|
| 1 | What does a QoS value on a request promise? |
| 2 | Why is the longest wait in a recording not a bound? |
| 3 | How do you derive the worst-case wait of a weighted round robin? |
| 4 | What does a rate limit on one manager buy, and what does it leave unsolved? |
| 5 | Which assumptions does a bound rest on? |
The Idea: A Promise Needs a Bound
The lesson on many managers gave a yes-or-no answer. Fixed priority can starve a manager, and round robin cannot. A system with a deadline needs more than that. It needs a number: the longest time one request can wait.
Quality of service, or QoS, means treating some traffic better than other traffic, on purpose. On AXI every request can carry a four-bit QoS value. A larger value asks for better treatment. It only asks. The policy of the arbiter decides what the value is worth.
There are two ways to get a number for the wait. You can run the system and write down the longest wait you saw. That is an observed maximum. Or you can argue from the policy, over everything the other managers are allowed to do. That gives a latency bound: a wait that cannot be exceeded. This page says "bound" for short.
The two can be far apart. A recording ends. A request that is still waiting at the end has only waited so far.
New Words
| Word | Meaning |
|---|---|
| QoS | Short for quality of service: treating some traffic better than other traffic, on purpose. |
| QoS value | A four-bit number on an AXI request. A larger value asks for better treatment. |
| Slot | One turn of the port: here, one word for one manager. |
| Latency | The time from a request being ready to its being served. This page counts it in slots. |
| Observed maximum | The longest wait seen in one run. |
| Latency bound | A wait that no allowed behaviour of the other managers can exceed. |
| Weighted round robin | A round robin in which a manager may own more than one slot of the round. |
| Rate limit | A rule that hides a manager from the arbiter for a set time after it was served. |
| ARQOS | The AXI wires that carry the QoS value of a read. |
| AWQOS | The AXI wires that carry the QoS value of a write. |
The lab prints one letter for each manager, as the picture below shows.
One Picture: One Port and Three Policies
- Processor
- Peripheral
- Debug
- Clock / reset
- Bus
- Memory
- One slot, three requests
The port serves one word in a slot. Each manager asks again as soon as it is served. So in every slot the arbiter has three requests.
- Policy 0: the highest QoS value wins
DMA has the value 12, and it always asks. It wins every slot. The processor and the debug port are starved.
- Policy 1: a weighted round robin
The round has four slots: one for the processor, two for DMA, one for the debug port. The pointer only moves forward, so every manager gets its turn.
- The worst moment
A word of the processor becomes ready just after its own slot. Two DMA slots and one debug slot pass first. That wait of three slots is its bound.
- Policy 2: a rate limit, then priority
After each DMA grant, the rate limit hides DMA for two slots. The highest value among the others wins those slots. That is the processor, both times.
Read the diagram as text
- Processor: C in the lab. QoS value 4. Its handler has a deadline
- DMA: D in the lab. QoS value 12. It copies a large block
- Debug port: J in the lab. QoS value 1. A person is looking at memory
- Rate limit: policy 2 only: hides DMA for two slots after each DMA grant
- Arbiter: gives each slot to one manager, by the policy in force
- SRAM port: one word in each slot
- Processor → Arbiter: request
- DMA → Rate limit: request
- Rate limit → Arbiter: request, if allowed
- Debug port → Arbiter: request
- Arbiter → SRAM port: the winner of the slot
Each arrow stands for a group of wires. The QoS values, the weights and the two-slot limit are choices of this lab.
The same three managers and the same requests give three very different services. Only the policy changed.
The Smallest Example, Worked by Hand: The Worst Moment to Arrive
Take policy 1. The round is C, D, D, J, and it repeats. Every manager always has a request, and every slot serves one word. A word of the processor becomes ready just before some slot. How many slots pass before it is served?
| It becomes ready just before | Slots that pass first | Wait in slots |
|---|---|---|
| the slot of C | none | 0 |
| the first slot of D | D, D, J | 3 |
| the second slot of D | D, J | 2 |
| the slot of J | J | 1 |
The worst case is to just miss your own slot. Then every slot of the others passes once: 2 + 1 = 3. Nothing the others do can make it 4, because the pointer never goes back.
That 3 is a count of slots, and a slot was one word. Now let each DMA slot carry a burst of four words. The same turns then last longer.
| Each DMA slot carries | Words that pass before C | Bound for the processor |
|---|---|---|
| 1 word | 1 + 1 + 1 | 3 words |
| a burst of 4 words | 4 + 4 + 1 | 9 words |
| a burst with no limit | no limit | none |
The Rules
Rule 1: A QoS value is a request, not a promise.
It says how a manager would like to be treated. Only the policy of each arbiter on the way turns it into service.
Rule 2: Order comes before QoS.
An arbiter may use QoS only to choose among requests that the ordering rules of the bus leave free.
Rule 3: An observed maximum is not a bound.
A recording shows one run of one length. A bound must hold for every allowed behaviour of the other managers.
Rule 4: A bound is a count of turns, times the longest turn.
Count the turns others can take before yours. Give each its longest time at the port. Add the work that is ahead in your own queue.
Rule 5: A bound is as good as its weakest assumption.
Each number in it is a weight, a longest burst or a longest wait. Hardware must enforce every one, or the bound is a hope.
Sources for These Rules
Arm AMBA AXI Protocol Specification, document IHI 0022, issue L, section A4.8.1. The QoS value is four bits wide, optional, and 0 by default. The specification does not fix its use. It recommends a priority, where a higher value means a higher priority. It states that the ordering rules of AXI come before QoS, and expects interconnects to offer registers that set the values.
Rules 3 to 5 are engineering practice, not specification text. The difference between response time and throughput is in Patterson and Hennessy, Computer Organization and Design, ARM edition, chapter 1, section 1.6.
The QoS values 12, 4 and 1 and the weights 1, 2 and 1 are choices of this lab. So is the rate limit of two slots.
Now Run It
The lab at the end of this page keeps all three managers asking for SRAM in every slot, for twelve slots. The managers are test code. It runs the three policies of the picture, one after the other.
Recorded from the lab: the winner of each of twelve slots. C is the processor, D is DMA and J is the debug port.
policy=0 grants=DDDDDDDDDDDD
served C/D/J=0/12/0 max_wait=12/0/12
policy=1 grants=CDDJCDDJCDDJ
served C/D/J=3/6/3 max_wait=3/2/3
policy=2 grants=DCCDCCDCCDCC
served C/D/J=8/4/0 max_wait=1/2/12Rule 1 at work: under policy 0 the processor carries the value 4 and is never served. Its max_wait is 12, which is simply the length of the run.
Rule 3 at work: run the same lab for 24 slots. Some of the printed waits grow, and some stay where they are.
| Policy | Run of 12 slots | Run of 24 slots | What the numbers are |
|---|---|---|---|
| 0: highest QoS value | 12, 0, 12 | 24, 0, 24 | C and J grow with the run: no bound exists |
| 1: weighted round robin | 3, 2, 3 | 3, 2, 3 | all three stay: each equals its bound |
| 2: rate limit, then priority | 1, 2, 12 | 1, 2, 24 | C and D stay, J grows: no bound for J |
Recorded from the lab with SLOTS at 12 and at 24.
Rule 4 at work: policy 1 prints 3 for the processor. That is the hand count of the last section. DMA waits 2 at most, for J and C. The debug port waits 3, for C and two slots of D.
Policy 2 is the tempting one. The grant row repeats D, C, C. The processor never waits more than one slot, which beats the weighted round robin. The debug port is never served. Limiting one manager frees slots. Priority still decides who gets them.
This lab leaves things out. Every grant is one word, and SRAM is always ready. No request has older work ahead in its own queue. A real bound must add all three.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| A weighted round robin | The highest QoS value always wins | Every manager gets a bound. The most urgent traffic is no longer always first. |
| A rate limit on the greedy manager, then priority | Weights for everybody | The urgent manager waits one slot at most. Whoever is last in the priority order has no bound at all. |
| QoS values set in registers of the interconnect | Values fixed inside each manager | One place holds the policy of the whole chip. Somebody must program it, and check it. |
No row is best for every chip. A chip with one hard deadline may choose the second row. A chip where every manager needs some service chooses the first.
The Trap: A Bound in a Spreadsheet
A team derives a bound for its timer handler. It assumes that DMA bursts are four words long. The bound fits the deadline with room to spare, and the test runs agree.
A year later a new driver programs DMA for bursts of sixteen words, to copy faster. No hardware objects, because nothing ever enforced the four. The handler now waits four times as long behind each DMA turn. The misses appear in the field, under load, and never in the lab.
The bound was arithmetic on an assumption. When you sign off a bound, write next to each number what enforces it. A register that cannot be set higher counts. So does a counter in the arbiter. "The driver will not do that" does not.
At Scale
This section looks ahead. One port and three managers give a bound you can count on your fingers. A path through a large chip crosses many shared places.
Name the two ends
Say where the clock starts and stops: the interrupt, the request, the grant, or the data coming back. A quick grant can hide a long wait in a queue before it.
One term for each shared place
Every arbiter, bridge and memory port on the path adds its own count of turns. The bound is their sum.
Test the worst moment
Start the urgent request just after its turn, and keep every rival busy. Compare the measured wait with the bound. A measured wait above the bound means an assumption is false.
The signal and the hardware
The Protocols track shows the QoS wires in its lesson on protection and QoS. A later track builds the arbiters, in round robin and priority arbiters.
Try It
Run the lab. In each grant row, find the longest stretch without a C, and compare it with the first number after max_wait.
Change SLOTS from 12 to 24. Before you run, say which of the nine waits will double.
In the test code, change the requests from 3'b111 to 3'b101, so that DMA never asks. Predict the three grant rows.
policy=0 grants=DDDDDDDDDDDD served C/D/J=0/12/0 max_wait=12/0/12 policy=1 grants=CDDJCDDJCDDJ served C/D/J=3/6/3 max_wait=3/2/3 policy=2 grants=DCCDCCDCCDCC served C/D/J=8/4/0 max_wait=1/2/12Read included file: qos_arbiter.sv
// One accepted word consumes one slot. Manager numbers are CPU=0, DMA=1, debug=2.
module qos_arbiter(input logic clk, reset_n,
input logic [1:0] policy, input logic [2:0] request,
input logic [3:0] qos[3], output logic [2:0] grant);
// Grouped weighted round robin. Skip slots whose owner has no request.
function automatic int owner(input int slot);
case (slot)
0: return 0;
1,2: return 1;
default: return 2;
endcase
endfunction
logic [1:0] cursor, next_slot, cooldown;
always_comb begin
int winner, slot, candidate;
winner = -1;
slot = 0;
candidate = 0;
next_slot = cursor;
if (policy == 1) begin
for (int distance=0; distance<4; distance++) begin
slot = (cursor + distance) % 4;
candidate = owner(slot);
if (winner < 0 && request[candidate]) begin
winner = candidate;
next_slot = (slot + 1) % 4;
end
end
end else begin
for (int m=0; m<3; m++)
if (request[m] && !(policy == 2 && m == 1 && cooldown != 0))
if (winner < 0 || qos[m] > qos[winner]) winner = m;
end
grant = 0;
if (winner >= 0) grant[winner] = 1;
end
always_ff @(posedge clk) begin
if (!reset_n) begin
cursor <= 0;
cooldown <= 0;
end else begin
cursor <= next_slot;
if (grant[1]) cooldown <= 2;
else if (cooldown != 0) cooldown <= cooldown - 1'b1;
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Quote the longest wait of a recording as a guarantee.
A request that is still waiting when the run ends has only waited so far.
Fix Derive the bound from the policy, over everything the other managers may do.
Wrong Count one cycle for each turn of another manager.
A turn may be a burst, or may meet wait states.
Fix Give each turn its longest time at the port.
Wrong Expect a high QoS value to make a request fast.
The value is a request. The policy of each arbiter decides.
Fix Read the policy of every arbiter on the path.
Remember
- A QoS value is a request; the policy of each arbiter decides what it is worth.
- An observed maximum is the longest wait of one run; a bound holds for every allowed run.
- A bound is a count of the turns of others, times the longest turn, plus the work ahead in your own queue.
- A rate limit frees slots; priority still decides who gets them.
- A bound is as good as its weakest assumption, and hardware must enforce each one.