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.
| Question | |
|---|---|
| 1 | What does a timeout bound, and what does it leave as it was? |
| 2 | How long must the time limit be? |
| 3 | What happens to a reply that arrives after the timeout? |
| 4 | Why must the ID of a request that timed out stay closed for a while? |
| 5 | A 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
| Word | Meaning |
|---|---|
| Timeout | Giving up on a request because no reply came within a set number of cycles. |
| Time limit | That number of cycles. |
| Timeout unit | The block that counts the cycles and gives up. It sits between a manager and what it talks to. |
| Late reply | A reply that arrives after its request was given up. |
| Closed ID | An 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.
| In the lab | Meaning |
|---|---|
| offer | the request the manager is offering, or a dash |
| waiting | the ID the unit waits for, and its timer: the edges it has waited so far |
| closed | four bits, for the IDs 3, 2, 1 and 0. A 1 marks a closed ID |
| reply | the ID and the data of a reply that arrives at this edge, or a dash |
| TEMP | a register of the device that is slow to read. It holds the value d5 |
| START | a register of the device. A write to it starts a motor once more |
| COUNT | a register of the device that is fast to read. It holds how often the motor was started |
| LIMIT | a constant of the lab: the time limit, in edges |
| QUARANTINE | a constant of the lab. At 1, the unit closes the ID of a request that timed out |
| CHECK_FIRST | a constant of the lab. At 1, the manager reads COUNT before it repeats a write |
One Picture: The Request That Was Given Up
- Processor
- Bus
- Memory
- Peripheral
- 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.
- 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.
- 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.
- 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.
- 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.
| Edge | What happens |
|---|---|
| 0 | Read A, of the slow register, goes out with ID 1. |
| 4 | Timeout. The manager is told that read A failed. |
| 5 | Read B, of a fast register, goes out. It also carries ID 1. |
| 6 | The reply to read A arrives, with ID 1. The unit waits for ID 1. Read B gets the data of read A. |
| 7 | The 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.
| Edge | What happens |
|---|---|
| 4 | Timeout. ID 1 is closed. |
| 5 | Read B is offered with ID 1. The unit holds it. |
| 6 | The late reply arrives. The unit drops it, and opens ID 1. |
| 7 | Read B goes out. |
| 9 | Read 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.
| What the manager does | How often the motor starts |
|---|---|
| writes again at once | twice, if the device had taken the first write |
| reads the state first, and writes again only if nothing happened | once |
The Rules
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.
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.
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.
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.
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.
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 00Rule 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.
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.
| Run | Last 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 once | read B got d5, expected 00 | the motor was started 1 time(s) |
| CHECK_FIRST 0: the manager writes again without asking | read 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 choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Close the ID until the late reply has come | Free the ID at the timeout | No reply can reach the wrong request. A device that never answers keeps its ID closed for ever. |
| A time limit above the longest legal wait | A short limit, to fail fast | A slow device is not taken for a dead one. A dead device is noticed later. |
| The timeout in hardware, on the way | A timer in each driver | It 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 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.
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.
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.
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.
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.
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
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.