Timeouts and Late Replies

Some devices do not answer in time. A time limit lets the caller go on, but the request it gave up is still out there. This page is about what comes back late, and what was already done.

You Will Be Able To

  • Say what a timeout bounds, and how its time limit relates to the longest legal wait.
  • Explain why an ID stays closed after a timeout, and what a late reply does otherwise.
  • Decide what a manager must find out before it repeats a write that timed out.
Lesson
S4.15
Time
24 min
Runs on
Your browser
Check
5 questions

A driver waits for a device that has gone quiet. A timer runs out, and the driver asks again. This time the answer comes at once. It is the answer to the first request, and the driver cannot tell.

Before You Start

You need a request, a reply and a wait from A Bus in Six Wires. An ID is a small number carried by a request and its reply. See AXI IDs and same-ID order. You need the slow wait and the deadlock from Ordering and Deadlock.

The lab on this page uses a small bus of its own. So the page needs no AXI signal names.

Five questions this page answers
Question
1What does a timeout bound, and what does it leave as it was?
2How long must the time limit be?
3What happens to a reply that arrives after the timeout?
4Why must the ID of a request that timed out stay closed for a while?
5A write timed out. What must the manager find out before it writes again?

The Idea: A Request Given up Is Still Outstanding

The last lesson told two kinds of waiting apart. A slow wait ends by itself. A deadlock never ends, and good design prevents it. A third kind is left. The device is stuck, switched off, or far slower than anyone promised. No design of the bus can make it answer.

For that case, a block on the way counts the clock cycles. When the count reaches a limit, it tells the manager that the request failed. That is a timeout. The manager is free again.

The request itself is not undone. The device may still be at work on it. Two things can follow, and each is a fault waiting to happen.

First, the reply may still come. It is now a late reply, and it carries an ID that the manager may have used again. Second, the device may already have done the work. A write that timed out may have happened.

New Words

New words on this page
WordMeaning
TimeoutGiving up on a request because no reply came within a set number of cycles.
Time limitThat number of cycles.
Timeout unitThe block that counts the cycles and gives up. It sits between a manager and what it talks to.
Late replyA reply that arrives after its request was given up.
Closed IDAn ID that no new request may use, because a late reply with it can still come.

The lab on this page prints these names at each clock edge.

Lab names
In the labMeaning
offerthe request the manager is offering, or a dash
waitingthe ID the unit waits for, and its timer: the edges it has waited so far
closedfour bits, for the IDs 3, 2, 1 and 0. A 1 marks a closed ID
replythe ID and the data of a reply that arrives at this edge, or a dash
TEMPa register of the device that is slow to read. It holds the value d5
STARTa register of the device. A write to it starts a motor once more
COUNTa register of the device that is fast to read. It holds how often the motor was started
LIMITa constant of the lab: the time limit, in edges
QUARANTINEa constant of the lab. At 1, the unit closes the ID of a request that timed out
CHECK_FIRSTa constant of the lab. At 1, the manager reads COUNT before it repeats a write

One Picture: The Request That Was Given Up

A Timeout Unit Between a Manager and a DeviceStep through the picture. It follows one request that is given up, and its reply.
  • Processor
  • Bus
  • Memory
  • Peripheral
A Timeout Unit Between a Manager and a DeviceStep through the picture. It follows one request that is given up, and its reply. component Manager sends one request ata time, each with an ID component Timeout unit counts the edges arequest has waited,and gives up at thetime limit component Closed IDs one bit for each ID: 1while a late reply withthat ID can still come component Device three registers, andone of them is slow request, IDrequest, if its ID isopenreply, IDreply, or "failed"closes and opens
  1. component Managersends one request at a time, each with an ID
    • request, ID → Timeout unit
  2. component Timeout unitcounts the edges a request has waited, and gives up at the time limit
    • request, if its ID is open → Device
    • reply, or "failed" → Manager
    • closes and opens → Closed IDs
  3. component Devicethree registers, and one of them is slow
    • reply, ID → Timeout unit
  4. component Closed IDsone bit for each ID: 1 while a late reply with that ID can still come
  1. A request goes out

    The manager offers a request with ID 1. The unit passes it on to the device, and starts to count clock edges.

  2. The time limit is reached

    No reply has come. The unit tells the manager that the request failed. The manager is free to go on.

  3. The request is still out there

    The device knows nothing of the timeout. It is still at work, and its reply is still on the way.

  4. The ID is closed

    The unit sets the bit of ID 1 in its list. While that bit is set, it holds every new request with ID 1 at its door.

  5. The late reply arrives

    It carries ID 1, and nobody waits for it. The unit drops it, clears the bit, and ID 1 is open again.

Read the diagram as text
  • Manager: sends one request at a time, each with an ID
  • Timeout unit: counts the edges a request has waited, and gives up at the time limit
  • Closed IDs: one bit for each ID: 1 while a late reply with that ID can still come
  • Device: three registers, and one of them is slow
  • Manager → Timeout unit: request, ID
  • Timeout unit → Device: request, if its ID is open
  • Device → Timeout unit: reply, ID
  • Timeout unit → Manager: reply, or "failed"
  • Timeout unit → Closed IDs: closes and opens

Each arrow stands for a group of wires. On a real chip the unit sits in the interconnect, or in a bridge.

Steps 3 to 5 are the part that is easy to forget. For the manager the story ended at step 2. For the device it did not.

The Smallest Example, Worked by Hand: An ID Used Again

The time limit is 4 edges. The slow register needs 6 edges to answer, and a fast one needs 2. First let the manager use ID 1 again at once.

ID 1 is used again at once
EdgeWhat happens
0Read A, of the slow register, goes out with ID 1.
4Timeout. The manager is told that read A failed.
5Read B, of a fast register, goes out. It also carries ID 1.
6The reply to read A arrives, with ID 1. The unit waits for ID 1. Read B gets the data of read A.
7The reply to read B arrives. Nobody waits for it.

Every block did what it was built to do, and read B returned a wrong value with no error. Now let the unit close the ID.

ID 1 is closed until the late reply has come
EdgeWhat happens
4Timeout. ID 1 is closed.
5Read B is offered with ID 1. The unit holds it.
6The late reply arrives. The unit drops it, and opens ID 1.
7Read B goes out.
9Read B gets its own reply.

The price is two edges. Read B is answered at edge 9, where its own reply could have come at edge 7. The same care is needed for a write. Suppose a write to a register starts a motor, and that write times out.

After a write that timed out
What the manager doesHow often the motor starts
writes again at oncetwice, if the device had taken the first write
reads the state first, and writes again only if nothing happenedonce

The Rules

  1. Rule 1: A timeout bounds the wait of the caller, and nothing else.

    The request is still outstanding at the device. Its work and its reply may still come.

  2. Rule 2: The time limit must be longer than the longest legal wait.

    A shorter limit fails requests that were only slow. So every device on the way needs a known longest wait.

  3. Rule 3: After a timeout, the ID stays closed until its late reply has arrived.

    While it is closed, no new request may carry it. The late reply is dropped when it comes.

  4. Rule 4: A write that timed out may have happened.

    Before it writes again, the manager reads the state of the device. It repeats only what is safe to repeat.

  5. Rule 5: A timeout is reported as an error.

    The manager must not get made-up data and a success. Software then decides what to do.

Sources for These Rules

These rules are design practice. No AMBA specification defines a time limit, or a way to cancel a request that has been sent. The Arm AMBA AXI Protocol Specification, IHI 0022 issue L, has neither. Issue H.c, section A3.4.5, requires every data transfer of a request to be completed even on an error.

For rule 2, the Arm AMBA AHB Protocol Specification, IHI 0033 issue C, has a note in section 5.1.2. It says that subordinates should in general have a known greatest number of wait states. It gives no number and no means to enforce one.

The lab is a teaching model: one request at a time, on a bus of its own.

Now Run It

The lab at the end of this page is the hand example as a circuit. The manager is test code. It reads TEMP with ID 1, and then COUNT with the same ID. The lab sets the time limit too low on purpose: 4 edges, for a register that needs 6. That is the simplest way to get a late reply.

Printed by the lab. Each row that starts with e is what one rising clock edge sees. Its last field says what that edge does.
e0 offer=READ TEMP id1 | waiting=- | closed=0000 | reply=- | passed on.
e1 offer=- | waiting=id1 timer=0 | closed=0000 | reply=- | -
e2 offer=- | waiting=id1 timer=1 | closed=0000 | reply=- | -
e3 offer=- | waiting=id1 timer=2 | closed=0000 | reply=- | -
e4 offer=- | waiting=id1 timer=3 | closed=0000 | reply=- | TIMEOUT.
read A (TEMP, id1): timeout
e5 offer=READ COUNT id1 | waiting=- | closed=0010 | reply=- | held.
e6 offer=READ COUNT id1 | waiting=- | closed=0010 | reply=id1 d5 | held. late reply dropped.
e7 offer=READ COUNT id1 | waiting=- | closed=0000 | reply=- | passed on.
e8 offer=- | waiting=id1 timer=0 | closed=0000 | reply=- | -
e9 offer=- | waiting=id1 timer=1 | closed=0000 | reply=id1 00 | reply delivered.
read B (COUNT, id1): got 00, expected 00

Rule 1 at work: e4 is the timeout, and the manager is told at once. The device goes on. Its reply arrives at e6, two edges after the manager gave up.

Rule 3 at work: at e5 and e6 the read of COUNT is offered and held, because the closed bits read 0010. At e6 the late reply is dropped. At e7 the read goes out, and at e9 it gets its own value, 00.

The next rows are the write of the same run. After them, a table shows what the constants QUARANTINE and CHECK_FIRST are for.

The same run, continued: a write to START with ID 2, and the read that follows it.
e10 offer=WRITE START id2 | waiting=- | closed=0000 | reply=- | passed on.
e11 offer=- | waiting=id2 timer=0 | closed=0000 | reply=- | -
e12 offer=- | waiting=id2 timer=1 | closed=0000 | reply=- | -
e13 offer=- | waiting=id2 timer=2 | closed=0000 | reply=- | -
e14 offer=- | waiting=id2 timer=3 | closed=0000 | reply=- | TIMEOUT.
write (START, id2): timeout
e15 offer=READ COUNT id3 | waiting=- | closed=0100 | reply=- | passed on.
e16 offer=- | waiting=id3 timer=0 | closed=0100 | reply=id2 00 | late reply dropped.
e17 offer=- | waiting=id3 timer=1 | closed=0000 | reply=id3 01 | reply delivered.
read COUNT (id3): got 01
read B got 00, expected 00 | the motor was started 1 time(s)

Rule 4 at work: the write goes out at e10, and the device starts the motor at that edge. Its reply would come six edges later. At e14 the unit gives up. The manager reads COUNT with a fresh ID, sees 01, and does not write again.

Three runs of the same requests
RunLast line of the lab
QUARANTINE 1, CHECK_FIRST 1 (the run above)read B got 00, expected 00 | the motor was started 1 time(s)
QUARANTINE 0: the ID is used again at onceread B got d5, expected 00 | the motor was started 1 time(s)
CHECK_FIRST 0: the manager writes again without askingread B got 00, expected 00 | the motor was started 2 time(s)

Recorded from the lab.

Rule 2 at work: with the constant LIMIT at 8, nothing times out. The first read then prints "read A (TEMP, id1): got d5".

This lab leaves things out. The manager sends one request at a time. The device always answers in the end, where a broken one may never answer. The unit drops a late reply in silence, where a real one would count it for the people who debug the chip.

Why It Is Built This Way

Design choiceThe alternativeWhat the choice buys, and costs
Close the ID until the late reply has comeFree the ID at the timeoutNo reply can reach the wrong request. A device that never answers keeps its ID closed for ever.
A time limit above the longest legal waitA short limit, to fail fastA slow device is not taken for a dead one. A dead device is noticed later.
The timeout in hardware, on the wayA timer in each driverIt covers every manager, also those that run no software. Software sees an ordinary error.

The cost in the first row is real. Each device that never answers uses up one ID. A chip that must survive that also needs a way to reset the device, or to cut it off.

The Trap: The Answer That Came Too Early

Back to the driver that asked again and got its answer at once. It was pleased with the fast reply. The reply was the old one, to a request that the driver had long given up.

The fault had passed every test. In the tests the two reads asked for the same register, so the old answer and the new answer were equal. It also needs unlucky timing. The late reply must arrive while the newer request is waiting. A little earlier or later, and it meets nobody.

A bug that needs a rare timing and a differing value will be found by a customer. When a design has a timeout, ask one question in the review: where does the late reply go?

At Scale

This page1 manager, 1 device, 1 request at a time
A large chipdozens of managers, many requests outstanding

This section looks ahead. One manager, one device and one request at a time fit in a table. A large chip has many requests outstanding, and devices that can lose power.

  1. IDs that never open

    A device that never answers keeps its ID closed. Count the closed IDs, and plan how to reset or cut off a device before they run out.

  2. A timeout can hide a deadlock

    If timeouts appear under load and vanish on a quiet chip, look for a loop first. Draw the picture of the last lesson.

  3. Where the limit comes from

    The time limit rests on the longest wait of every arbiter and device on the way. That is the bound of the lesson on latency bounds.

  4. The last resort

    When software itself stops, no bus timeout helps. A chip has one more timer for that case, in The Watchdog.

Try It

Run the lab. For each row, say why the request was passed on or held, and why the reply was delivered or dropped.

Set QUARANTINE to 0. Predict the value that read B gets from the first hand table, then run.

Set QUARANTINE back to 1 and CHECK_FIRST to 0. Find the edge at which the motor starts for the second time.

Set LIMIT to 8. Say which rules of this page the lab no longer needs, and why.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: e0 offer=READ TEMP id1 | waiting=- | closed=0000 | reply=- | passed on. e1 offer=- | waiting=id1 timer=0 | closed=0000 | reply=- | - e2 offer=- | waiting=id1 timer=1 | closed=0000 | reply=- | - e3 offer=- | waiting=id1 timer=2 | closed=0000 | reply=- | - e4 offer=- | waiting=id1 timer=3 | closed=0000 | reply=- | TIMEOUT. read A (TEMP, id1): timeout e5 offer=READ COUNT id1 | waiting=- | closed=0010 | reply=- | held. e6 offer=READ COUNT id1 | waiting=- | closed=0010 | reply=id1 d5 | held. late reply dropped. e7 offer=READ COUNT id1 | waiting=- | closed=0000 | reply=- | passed on. e8 offer=- | waiting=id1 timer=0 | closed=0000 | reply=- | - e9 offer=- | waiting=id1 timer=1 | closed=0000 | reply=id1 00 | reply delivered. read B (COUNT, id1): got 00, expected 00 e10 offer=WRITE START id2 | waiting=- | closed=0000 | reply=- | passed on. e11 offer=- | waiting=id2 timer=0 | closed=0000 | reply=- | - e12 offer=- | waiting=id2 timer=1 | closed=0000 | reply=- | - e13 offer=- | waiting=id2 timer=2 | closed=0000 | reply=- | - e14 offer=- | waiting=id2 timer=3 | closed=0000 | reply=- | TIMEOUT. write (START, id2): timeout e15 offer=READ COUNT id3 | waiting=- | closed=0100 | reply=- | passed on. e16 offer=- | waiting=id3 timer=0 | closed=0100 | reply=id2 00 | late reply dropped. e17 offer=- | waiting=id3 timer=1 | closed=0000 | reply=id3 01 | reply delivered. read COUNT (id3): got 01 read B got 00, expected 00 | the motor was started 1 time(s)

Check Yourself

Predict the outputBoth constants are now 0: the ID is used again at once, and the manager writes again without asking. What is the last line the lab prints?
// One manager, a timeout unit and one device. The manager is test code.
// Every request carries a small number, its ID. The reply carries the same ID back.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;

  localparam int LIMIT       = 4;   // the unit gives up after this many edges without a reply
  localparam bit QUARANTINE  = 0;   // 1: after a timeout, the ID stays closed until its late reply has come
  localparam bit CHECK_FIRST = 0;   // 1: after a failed write, the manager reads COUNT before it tries again
  localparam int SLOW = 6, FAST = 2;   // edges the device needs for a slow register and for a fast one

  // ---- The three registers of the device ----
  localparam logic [7:0] TEMP  = 8'h40;   // read: a temperature, d5. Slow.
  localparam logic [7:0] START = 8'h44;   // write: start the motor once more. Acts at once, answers slowly.
  localparam logic [7:0] COUNT = 8'h48;   // read: how often the motor was started. Fast.

  // ---- The request: offered by the manager until the unit passes it on ----
  logic       offer = 0;   // 1: the manager has a request
  logic       wr;          // 1: a write. 0: a read
  logic [7:0] addr;
  logic [1:0] id;

  // ---- The device ----
  int starts = 0;                          // how often the motor was started
  int slow_left = 0, fast_left = 0;        // edges until the slow reply and the fast reply are due
  logic [1:0] slow_id, fast_id;
  logic [7:0] slow_data, fast_data;
  wire        reply      = (slow_left == 1) || (fast_left == 1);   // a reply arrives at this edge
  wire  [1:0] reply_id   = (slow_left == 1) ? slow_id   : fast_id;
  wire  [7:0] reply_data = (slow_left == 1) ? slow_data : fast_data;

  // ---- The timeout unit ----
  logic       waiting = 0;   // a request was passed on and has no reply yet
  logic [1:0] wait_id;       // its ID
  int         timer = 0;     // edges it has waited
  logic [3:0] closed = 0;    // one bit for each ID: 1 while a late reply with that ID can still come
  wire pass     = offer && !waiting && !closed[id];           // the request reaches the device at this edge
  wire answered = waiting && reply && (reply_id == wait_id);  // the reply carries the ID the unit waits for
  wire expired  = waiting && !answered && (timer + 1 == LIMIT);
  logic       took = 0, done = 0, failed = 0;                 // what the manager is told
  logic [7:0] got;

  always @(posedge clk) begin
    // the device
    if (slow_left != 0) slow_left <= slow_left - 1;
    if (fast_left != 0) fast_left <= fast_left - 1;
    if (pass && addr == COUNT) begin
      fast_left <= FAST;  fast_id <= id;  fast_data <= 8'(starts);
    end else if (pass) begin
      slow_left <= SLOW;  slow_id <= id;  slow_data <= (addr == TEMP) ? 8'hd5 : 8'h00;
      if (wr && addr == START) starts <= starts + 1;          // the motor starts now, long before the reply
    end
    // the timeout unit
    took <= pass;  done <= answered || expired;
    if (pass) begin
      waiting <= 1;  wait_id <= id;  timer <= 0;
    end else if (answered) begin
      waiting <= 0;  failed <= 0;  got <= reply_data;
    end else if (expired) begin
      waiting <= 0;  failed <= 1;
      if (QUARANTINE) closed[wait_id] <= 1;                   // remember that a reply with this ID is still out
    end else if (waiting) timer <= timer + 1;
    if (reply && closed[reply_id]) closed[reply_id] <= 0;     // the late reply has come: drop it, open the ID
  end

  // ---- One printed row for each rising edge: what that edge sees, and what it does ----
  int e = 0;
  function string what();
    string s;
    s = "";
    if (pass)                         s = {s, " passed on."};
    else if (offer)                   s = {s, " held."};
    if (answered)                     s = {s, " reply delivered."};
    else if (reply && closed[reply_id]) s = {s, " late reply dropped."};
    else if (reply)                   s = {s, " reply dropped: nobody waits."};
    if (expired)                      s = {s, " TIMEOUT."};
    if (s == "")                      s = " -";
    return s;
  endfunction
  function string show_offer();         // the request as text
    string kind, register;
    if (!offer) return "-";
    kind = "READ";       if (wr) kind = "WRITE";
    register = "COUNT";  if (addr == TEMP) register = "TEMP";  if (addr == START) register = "START";
    return $sformatf("%s %s id%0d", kind, register, id);
  endfunction
  function string show_wait();
    if (!waiting) return "-";
    return $sformatf("id%0d timer=%0d", wait_id, timer);
  endfunction
  function string show_reply();
    if (!reply) return "-";
    return $sformatf("id%0d %h", reply_id, reply_data);
  endfunction
  always @(posedge clk) begin
    $display("e%0d offer=%s | waiting=%s | closed=%b | reply=%s |%s", e, show_offer(), show_wait(), closed, show_reply(), what());
    e++;
  end

  // ---- The manager: test code. One request at a time ----
  task automatic request(input logic w, input logic [7:0] a, input logic [1:0] i, output logic bad, output logic [7:0] data);
    offer = 1;  wr = w;  addr = a;  id = i;
    do @(negedge clk); while (!took);    // offer it until the unit has passed it on
    offer = 0;
    do @(negedge clk); while (!done);    // then wait for the reply, or for the timeout
    bad = failed;  data = got;
  endtask

  function string outcome(input logic bad);     // a word for the printed line
    if (bad) return "timeout";
    return "done";
  endfunction
  logic bad, bad_b, bad_w;
  logic [7:0] data, data_b, count;
  initial begin
    request(0, TEMP, 1, bad, data);             // read A: the slow register, with ID 1
    if (bad) $display("read A (TEMP, id1): timeout");
    else     $display("read A (TEMP, id1): got %h", data);
    request(0, COUNT, 1, bad_b, data_b);        // read B: a fast register, with the same ID
    if (bad_b) $display("read B (COUNT, id1): timeout");
    else       $display("read B (COUNT, id1): got %h, expected 00", data_b);
    request(1, START, 2, bad_w, data);          // the write: start the motor once
    $display("write (START, id2): %s", outcome(bad_w));
    if (bad_w && CHECK_FIRST) begin
      request(0, COUNT, 3, bad, count);         // ask the device what it did
      $display("read COUNT (id3): got %h", count);
      if (count == 0) request(1, START, 3, bad, data);
    end else if (bad_w) begin
      request(1, START, 3, bad, data);          // try again without asking
      $display("write again (START, id3): %s", outcome(bad));
    end
    while (slow_left != 0 || fast_left != 0) @(negedge clk);   // let every late reply arrive
    $display("read B got %h, expected 00 | the motor was started %0d time(s)", data_b, starts);
    $finish;
  end
endmodule
ConceptWhat does a timeout bound?
ConceptThe longest legal wait on a path is 40 cycles. Which time limit is sound?
ConceptA request with ID 1 timed out. When may ID 1 be used again?
ConceptA write that starts a motor timed out. What does the manager do first?

Common Mistakes

Wrong Treat a request that timed out as a request that never happened.

The device may still act on it, and may still answer it.

Fix Plan for the late reply and for the work already done.

Wrong Use the ID of a timed-out request again at once.

Its late reply can arrive while the new request waits, and answer it.

Fix Keep the ID closed until the late reply has come.

Wrong Repeat every command that timed out.

The command may have taken effect before its reply was lost.

Fix Read the state of the device first. Repeat only what is safe to repeat.

Remember

  • A timeout bounds the wait of the caller; the request is still outstanding at the device.
  • The time limit must be longer than the longest legal wait on the way.
  • After a timeout the ID stays closed until its late reply has arrived and been dropped.
  • A write that timed out may have happened: read the state before writing again.
  • A timeout is reported as an error, never as data.

Practice

Report a problem with this page