Throughput, Latency and Back-Pressure Across a System
Latency is the time of one item. Throughput is a count of items over a window. Back-pressure is how a slow stage at the end of a path makes the source wait at the start.
You Will Be Able To
- Measure the latency of one item between two named events.
- Measure throughput over a stated window, and say why it is not one divided by the latency.
- Follow back-pressure from the stage that causes it to the source that feels it.
- Lesson
- S8.7
- Time
- 27 min
- Runs on
- Your browser
- Check
- 5 questions
Eight letters arrive at UART0, on their way to memory. The first is stored three clock edges after it came in. The fifth needs five. Nothing is broken, the memory has room, and yet at one edge the sender is told to wait.
Before You Start
You need DMA: a DMA moves one byte at a time. It holds the byte between its read and its write.
You need Serial Peripherals: The UART: the receive queue of UART0, with two places.
You need A Bus in Six Wires: a transfer happens only on an edge where both sides agree.
| Question | |
|---|---|
| 1 | Which two events does the latency of an item lie between? |
| 2 | What must you state before a throughput means anything? |
| 3 | Why is throughput not one divided by the latency? |
| 4 | What is back-pressure, and in which direction does it travel? |
| 5 | A slow memory bank becomes faster: on which edge is the last byte stored? |
The Idea: One Item, All Items, and a Refusal
Data crosses a chip in steps. A byte from a serial line waits in a queue, is picked up by the DMA, and is written to memory. Each step is a stage of the path, and each stage has its own speed. To talk about such a path you need three ideas.
The first is latency. Pick one byte and two events: it comes in, it is stored. The time between them is the latency of that byte. The second is throughput. Pick a window of time and count how many bytes were stored in it. Latency is about one item. Throughput is about all of them.
The two are not two views of one number. Several bytes are on the path at once, so many can finish in the time that one needs.
The third idea explains why latency grows. A stage that cannot pass its byte on has no room for the next one, so it refuses it. The stage before it fills, and refuses too. This refusal, moving against the data, is called back-pressure. Without it, a full stage would have to drop bytes. With it, the wait moves upstream until it reaches someone who can wait.
New Words
| Word | Meaning |
|---|---|
| Stage of a path | One step that data passes through on its way. It can hold a fixed number of items. This page calls it a stage. |
| Latency of an item | The time between two named events in the life of one item: here, a byte comes in and is stored. |
| Throughput of a path | The number of items that complete in a window of time, divided by the length of that window. |
| Back-pressure on a source | The refusal of a stage that has no room. It passes from stage to stage, against the data, until the source must wait. |
| Source of a path | The place where the items of a path start. Here it is the sender of the bytes. |
| Head-of-line blocking | An item at the front of a queue that cannot move, and so holds back items behind it that could. |
| Memory bank | One part of a memory with a port of its own. This page calls it a bank. |
One Picture: Data One Way, Refusal the Other
- Peripheral
- Bus
- Memory
- The path
A byte passes three stages on its way to memory. Each stage can hold only so many bytes.
- Latency
Follow one byte. Note the edge on which it comes in, and the edge on which SRAM stores it. The difference is the latency of that byte.
- Throughput
Stand at the end of the path and count. The bytes stored in a window, divided by the length of the window, is the throughput.
- A stage says "not now"
The slow bank is busy. The DMA cannot pass its byte on, so it cannot take the next one from the queue.
- Back-pressure
The queue fills, and then it refuses the sender. The "not now" has travelled from the memory to the source.
Read the diagram as text
- Sender: offers one byte after another
- Receive queue: two places, in UART0
- DMA: holds one byte between its read and its write
- SRAM: two banks; one of them is free only now and then
- Sender → Receive queue: a byte comes in
- Receive queue → DMA: the DMA takes it
- DMA → SRAM: SRAM stores it
- SRAM → DMA: not now
- DMA → Receive queue: not now
- Receive queue → Sender: not now
The path of the lab. Data moves to the right. A refusal moves to the left.
The Smallest Example, Worked by Hand
Take four bytes, numbered 0 to 3. No simulator yet. The path has three rules. The receive queue has two places. The DMA holds one byte. SRAM has two banks. Bytes with an odd number go to a bank that is always free. Bytes with an even number go to a bank that is free only on edges 0, 3, 6 and so on.
A byte can move into a place that is freed on the same edge. The sender offers a new byte on every edge.
| Edge | Enters the queue | Taken by the DMA | Stored in SRAM | What holds things up |
|---|---|---|---|---|
| 0 | Byte 0 | none | none | |
| 1 | Byte 1 | Byte 0 | none | |
| 2 | Byte 2 | none | none | The DMA holds byte 0. Its bank is free again on edge 3. |
| 3 | Byte 3 | Byte 1 | Byte 0 | |
| 4 | none | Byte 2 | Byte 1 | |
| 5 | none | none | none | The DMA holds byte 2. Its bank is free again on edge 6. |
| 6 | none | Byte 3 | Byte 2 | |
| 7 | none | none | Byte 3 |
Latency first. Byte 0 came in on edge 0 and was stored on edge 3: a latency of 3 edges. Byte 2 came in on edge 2 and was stored on edge 6: a latency of 4. The later byte waited longer, in the queue.
Now throughput. From edge 0 to edge 7 there are 8 edges, and 4 bytes were stored: half a byte for each edge. One divided by a latency of 3 would say a third. That is wrong, because bytes 0, 1 and 2 were on the path together.
Look at edge 2. The DMA cannot store byte 0, so it cannot take byte 1. The queue now holds two bytes and is full. One more byte from the sender on edge 3 would have been refused, had the DMA not moved on that same edge.
The Rules
Rule 1: Latency belongs to one item.
Name the item and the two events. Without both events the number means nothing.
Rule 2: Throughput belongs to a window.
Count the items that completed, and state where the window starts and ends.
Rule 3: Throughput is not one divided by the latency.
Several items are on the path at once.
Rule 4: A stage that cannot pass its item on takes no new one.
It has no room. Taking one would overwrite an item that is still owed.
Rule 5: The refusal travels upstream, stage by stage.
Each full stage refuses the one before it, until the source itself must wait. That is back-pressure.
Rule 6: Back-pressure needs a source that can wait.
A sender that cannot be stopped keeps sending, and the first full stage loses data.
Sources for These Rules
Response time against throughput as two different measures: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 1.6. Several instructions in a pipeline at once, so that the rate is not one over the time of each: section 4.5.
A transfer happens only when the sender offers and the receiver accepts: the valid and ready rule of P1.6.
The words back-pressure and head-of-line blocking are common practice. Our reference library has no source that defines them.
The DMA that holds one byte between its read and its write is the one of the DMA lesson. The two banks and the edges on which the slow one is free are choices of this lab alone.
Now Run It
The lab at the end of this page sends eight bytes down the same path. The letters a to h are bytes 0 to 7. Step through the picture, then read the rows below it.
- Peripheral
- Bus
- Memory
A lit wire carries a 1. A pill is a transfer in that cycle; slots are the entries held.
- Cycle 0
Byte 0 enters the receive queue.
- Cycle 1
The DMA takes byte 0. Byte 1 enters the queue.
- Cycle 3
SRAM stores byte 0, three edges after it came in. Two other bytes move on the same edge.
- Cycle 5
Nothing moves. The DMA holds byte 2 for the slow bank, the queue is full, and the sender is refused.
- Cycle 6
SRAM stores byte 2. That frees the DMA, then a place in the queue, then the sender: all on one edge.
- Cycle 13
SRAM stores byte 7. The path is empty.
Recorded by the lab at rising edges e0 to e13. The three upper lanes say that a byte moved. The three lower lanes say which byte. An x means that none did.
e0 rx_in=0 dma_in=-1 ram_id=-1 fifo=1 dma=0 latency=-1
e1 rx_in=1 dma_in=0 ram_id=-1 fifo=1 dma=1 latency=-1
e3 rx_in=3 dma_in=1 ram_id=0 fifo=2 dma=1 latency=3
e4 rx_in=4 dma_in=2 ram_id=1 fifo=2 dma=1 latency=3
e5 rx_in=-1 dma_in=-1 ram_id=-1 fifo=2 dma=1 latency=-1
e6 rx_in=5 dma_in=3 ram_id=2 fifo=2 dma=1 latency=4
RAM=abcdefgh bytes=8 sampled_edges=14Rule 1 at work, in rows e0 and e3. Byte 0 enters the queue at e0 and is stored at e3, and the row says latency=3.
Rule 2, in the last row: 8 bytes in 14 sampled edges, e0 to e13. That window includes the empty start of the path.
Rule 3, in rows e3 and e4. Two bytes are stored on two edges in a row, while each of them needed three.
Rules 4 and 5, in row e5. Nothing moves. The DMA holds byte 2 for the slow bank, so it takes nothing. The queue shows fifo=2, so it takes nothing either: rx_in=-1. The sender has been told to wait.
Row e6 shows the release. SRAM stores byte 2, the DMA takes byte 3, and the queue lets byte 5 in, all on one edge. Byte 2 has latency=4. Later bytes reach 5: they paid for the wait.
This lab leaves things out. No processor and no serial line are here: a model moves numbered bytes between stages. Its sender holds a refused byte and offers it again. A real serial sender does not wait, which is rule 6.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Every stage may say "not now" | A stage must always accept | No byte is lost inside the chip. The wait moves to the source, which must be able to wait. |
| Bytes stay in the order of arrival | A queue for each bank, so that one byte may pass another | Memory fills in order, and a half-finished copy is easy to reason about. A free bank can stand unused. |
| A receive queue of two places | A queue of four places | Little area. With four places the sender is done at e7 in place of e9, and the last byte is still stored at e13. |
The last row is worth a second look. A deeper queue moved the wait from the sender into the chip. It did not make the memory faster. How deep a queue must be, and when depth cannot help, is the subject of Finding the Bottleneck and Sizing Buffers.
The Trap: A Free Bank That Nobody Used
A performance report said that the fast bank of the memory was idle a third of the time. So the memory was fast enough, the report concluded, and the fault must be elsewhere.
Look at row e5 once more. The fast bank is free, and byte 3 is meant for it. But byte 3 sits in the queue behind byte 2, and byte 2 waits in the DMA for the slow bank. The free slot goes unused. This is head-of-line blocking. An idle resource does not prove that there is enough of it.
A second trap is the sum that rule 3 forbids. Someone measures a latency of 3 edges and promises a third of a byte for each edge. In the busy part of our run, the path stores two bytes every three edges.
The third is rule 6. On the bench the test sender waited politely, and nothing was lost. In the field the other end of the serial line kept sending. The queue of two places filled, and the next byte was an overrun.
At Scale
This section looks ahead. One stream becomes many, and the stages are no longer under one roof.
The worst item, not the average
An average latency hides the one byte that waited longest. A deadline cares about that one. Quality of Service and Latency Bounds puts a limit on it.
A refusal takes time too
Across a long wire or a clock crossing, "not now" arrives late. Bytes already on the way need a place: see credits in P1.6 and the skid buffer in R4.4.
Shared stages
When two streams share a memory, one stream feels the back-pressure that the other caused. Measure each stream apart.
Sources that cannot wait
A camera, a radio or a serial line does not stop. For those the queue must be deep enough, or data is lost.
Try It
Run the lab. Follow byte 2: find the three rows in which rx_in, dma_in and ram_id are 2.
Change PERIOD from 3 to 2. The slow bank is now free every second edge. On which edge is the last byte stored?
Change DEPTH from 2 to 4. Which numbers change, and which stay?
Names Printed by the Lab
| Name | Meaning |
|---|---|
| e0, e1, ... | Rising edges of the clock. A row shows what moved on that edge. |
| rx_in | The number of the byte that entered the receive queue on this edge. Bytes are numbered from 0. A value of -1 means that none did. |
| dma_in | The number of the byte that the DMA took from the queue. |
| ram_id | The number of the byte that SRAM stored. |
| fifo, dma | How many bytes wait in the receive queue, and in the DMA, after the edge. |
| latency | For the byte that was stored: the edges from its entry into the queue to this edge. |
e0 rx_in=0 dma_in=-1 ram_id=-1 fifo=1 dma=0 latency=-1 e1 rx_in=1 dma_in=0 ram_id=-1 fifo=1 dma=1 latency=-1 e2 rx_in=2 dma_in=-1 ram_id=-1 fifo=2 dma=1 latency=-1 e3 rx_in=3 dma_in=1 ram_id=0 fifo=2 dma=1 latency=3 e4 rx_in=4 dma_in=2 ram_id=1 fifo=2 dma=1 latency=3 e5 rx_in=-1 dma_in=-1 ram_id=-1 fifo=2 dma=1 latency=-1 e6 rx_in=5 dma_in=3 ram_id=2 fifo=2 dma=1 latency=4 e7 rx_in=6 dma_in=4 ram_id=3 fifo=2 dma=1 latency=4 e8 rx_in=-1 dma_in=-1 ram_id=-1 fifo=2 dma=1 latency=-1 e9 rx_in=7 dma_in=5 ram_id=4 fifo=2 dma=1 latency=5 e10 rx_in=-1 dma_in=6 ram_id=5 fifo=1 dma=1 latency=4 e11 rx_in=-1 dma_in=-1 ram_id=-1 fifo=1 dma=1 latency=-1 e12 rx_in=-1 dma_in=7 ram_id=6 fifo=0 dma=1 latency=5 e13 rx_in=-1 dma_in=-1 ram_id=7 fifo=0 dma=0 latency=4 RAM=abcdefgh bytes=8 sampled_edges=14Check Yourself
Common Mistakes
Wrong Divide one by a latency to get the throughput.
Several items are on the path at once.
Fix Count the items that completed in a stated window.
Wrong Quote a throughput without its window.
An empty start or a quiet end changes the number.
Fix Say where the window starts and where it ends.
Wrong Read an idle resource as a sign that there is enough of it.
The item that could use it may be stuck behind another.
Fix Look at what the item at the front is waiting for.
Remember
- Latency: one item, two named events.
- Throughput: completed items in a stated window. It is not one divided by the latency.
- A stage with no room refuses the next item, and the refusal travels to the source.
- Back-pressure works only if the source can wait.