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.

Five questions this page answers
Question
1Which two events does the latency of an item lie between?
2What must you state before a throughput means anything?
3Why is throughput not one divided by the latency?
4What is back-pressure, and in which direction does it travel?
5A 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

New words on this page
WordMeaning
Stage of a pathOne 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 itemThe time between two named events in the life of one item: here, a byte comes in and is stored.
Throughput of a pathThe number of items that complete in a window of time, divided by the length of that window.
Back-pressure on a sourceThe 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 pathThe place where the items of a path start. Here it is the sender of the bytes.
Head-of-line blockingAn item at the front of a queue that cannot move, and so holds back items behind it that could.
Memory bankOne part of a memory with a port of its own. This page calls it a bank.

One Picture: Data One Way, Refusal the Other

One Path, Three MeasuresStep through the picture. It follows bytes from a sender to memory, then shows what each of the three measures looks at.
  • Peripheral
  • Bus
  • Memory
One Path, Three MeasuresStep through the picture. It follows bytes from a sender to memory, then shows what each of the three measures looks at. component Sender offers one byteafter another component Receive queue two places, in UART0 component DMA holds one bytebetween its read andits write component SRAM two banks; one ofthem is free only nowand then a byte comes inthe DMA takes itSRAM stores itnot nownot nownot now
  1. component Senderoffers one byte after another
    • a byte comes in → Receive queue
  2. component Receive queuetwo places, in UART0
    • the DMA takes it → DMA
    • not now → Sender
  3. component DMAholds one byte between its read and its write
    • SRAM stores it → SRAM
    • not now → Receive queue
  4. component SRAMtwo banks; one of them is free only now and then
    • not now → DMA
  1. The path

    A byte passes three stages on its way to memory. Each stage can hold only so many bytes.

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

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

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

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

Four bytes, edge by edge
EdgeEnters the queueTaken by the DMAStored in SRAMWhat holds things up
0Byte 0nonenone
1Byte 1Byte 0none
2Byte 2nonenoneThe DMA holds byte 0. Its bank is free again on edge 3.
3Byte 3Byte 1Byte 0
4noneByte 2Byte 1
5nonenonenoneThe DMA holds byte 2. Its bank is free again on edge 6.
6noneByte 3Byte 2
7nonenoneByte 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

  1. Rule 1: Latency belongs to one item.

    Name the item and the two events. Without both events the number means nothing.

  2. Rule 2: Throughput belongs to a window.

    Count the items that completed, and state where the window starts and ends.

  3. Rule 3: Throughput is not one divided by the latency.

    Several items are on the path at once.

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

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

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

Eight Bytes from UART0 to SRAM
  • Peripheral
  • Bus
  • Memory
admittakestoreSenderReceive queueDMASRAM
admit→ Receive queuetake→ DMAstore→ SRAMSenderReceive queueDMASRAM

A lit wire carries a 1. A pill is a transfer in that cycle; slots are the entries held.

012345678910111213clkadmittakestoreadmitByte01234x56x7xtakeBytex0x12x34x56x7xstoreBytex01x23x45x67
Scroll horizontally ↔
  1. Cycle 0

    Byte 0 enters the receive queue.

  2. Cycle 1

    The DMA takes byte 0. Byte 1 enters the queue.

  3. Cycle 3

    SRAM stores byte 0, three edges after it came in. Two other bytes move on the same edge.

  4. Cycle 5

    Nothing moves. The DMA holds byte 2 for the slow bank, the queue is full, and the sender is refused.

  5. Cycle 6

    SRAM stores byte 2. That frees the DMA, then a place in the queue, then the sender: all on one edge.

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

Seven of the fifteen rows printed by the lab on Icarus. A value of -1 means that nothing moved, or that no byte was stored.
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=14

Rule 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 choiceThe alternativeWhat the choice buys, and costs
Every stage may say "not now"A stage must always acceptNo byte is lost inside the chip. The wait moves to the source, which must be able to wait.
Bytes stay in the order of arrivalA queue for each bank, so that one byte may pass anotherMemory fills in order, and a half-finished copy is easy to reason about. A free bank can stand unused.
A receive queue of two placesA queue of four placesLittle 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 page1 stream, 3 stages
A phone chiphundreds of streams

This section looks ahead. One stream becomes many, and the stages are no longer under one roof.

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

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

  3. Shared stages

    When two streams share a memory, one stream feels the back-pressure that the other caused. Measure each stream apart.

  4. 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
NameMeaning
e0, e1, ...Rising edges of the clock. A row shows what moved on that edge.
rx_inThe 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_inThe number of the byte that the DMA took from the queue.
ram_idThe number of the byte that SRAM stored.
fifo, dmaHow many bytes wait in the receive queue, and in the DMA, after the edge.
latencyFor the byte that was stored: the edges from its entry into the queue to this edge.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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=14

Check Yourself

Predict the outputIn this run the slow bank is free on every second edge: e0, e2, e4 and so on. What is the last row? Its form is: RAM=abcdefgh bytes=8 sampled_edges=..
`timescale 1ns/1ns
module tb;
  // Transaction-level BFM. One byte per slot. Bank selects model SRAM service.
  localparam DEPTH = 2, BYTES = 8, PERIOD = 2;
  bit clk;
  always #5 clk = !clk;
  int rx [DEPTH], arrival [BYTES];
  byte ram [BYTES], rx_data [DEPTH], dma_data;
  int sent = 0, taken = 0, saved = 0, held = -1, edge_no = 0;
  int pushed, moved, written, latency;
  bit pop, push, store, bank_ready;
  initial begin
    while (saved < BYTES) begin
      @(posedge clk);
      // Even byte addresses use a slow bank. Odd addresses are always serviceable.
      bank_ready = held >= 0 && (held % 2 == 1 || edge_no % PERIOD == 0);
      store = bank_ready;
      pop = sent > taken && (held < 0 || store);
      push = sent < BYTES && (sent-taken < DEPTH || pop);
      pushed = -1; moved = -1; written = -1; latency = -1;
      if (store) begin
        written = held;
        ram[held] = dma_data;
        latency = edge_no - arrival[held];
        saved++;
        held = -1;
      end
      if (pop) begin
        held = rx[taken % DEPTH];
        dma_data = rx_data[taken % DEPTH];
        moved = held;
        taken++;
      end
      if (push) begin
        pushed = sent;
        rx[sent % DEPTH] = sent;
        rx_data[sent % DEPTH] = "a" + sent;
        arrival[sent] = edge_no;
        sent++;
      end
      $display("e%0d rx_in=%0d dma_in=%0d ram_id=%0d fifo=%0d dma=%0d latency=%0d",
               edge_no,pushed,moved,written,sent-taken,held>=0,latency);
      edge_no++;
    end
    $write("RAM=");
    for (int i=0; i<BYTES; i++) $write("%c",ram[i]);
    $display(" bytes=%0d sampled_edges=%0d",saved,edge_no);
    $finish;
  end
endmodule
ConceptWhich two events does the latency of a byte lie between on this page?
ConceptWhat must you state before a throughput means anything?
ConceptWhy is throughput not one divided by the latency?
ConceptIn which direction does back-pressure travel?

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.

Practice

Report a problem with this page