The Trace Network at Scale: Budget, Backlog and Loss
Eight cores write their history into one narrow port. The rates add up, the excess piles up, and what finds no place is lost. A good trace network says where, and when.
You Will Be Able To
- Add up the trace of many sources, point by point, and find the excess at the sink.
- Work out how long a buffer lasts in a burst, and say where it must sit.
- Say where records are lost when a sink is slow, and why each loss must leave a mark.
- Lesson
- S10.17
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
A phone hangs. This time the trace was on, so the last second of all eight cores is on your screen.
Core 5 shows nothing for the last twenty milliseconds. Was it idle, or did its records never arrive?
Before You Start
You need Trace: Rebuilding the Path of a Program: a trace source, and what its packets say.
You need Trace Transport: Funnel, Flush and Buffer: the funnel, the source ID, valid and ready, a stall, the circular buffer.
You need Finding the Bottleneck and Sizing Buffers: backlog, burst and bottleneck.
| Question | |
|---|---|
| 1 | Eight cores send trace toward one port. How do you find the rate that arrives there? |
| 2 | More arrives than the port carries. How long does a buffer last? |
| 3 | A sink is slow. Where are the records lost? |
| 4 | Why must every lost record leave a mark? |
| 5 | The sink of the lab is slow for 4 ticks, not 8. What does the last row say? |
The Idea: Add, Pile up, Mark
On the small chip one trace source shared a link with one other source. A funnel took turns, and a small buffer kept the newest bytes. That was the whole of trace transport.
A phone has eight cores, and each has a trace source. All of it must reach one place, because a history of eight cores is only useful on one time line. So the funnels form a tree. The tree ends in a sink: a port of a few pins, or a buffer in RAM.
First idea: rates add. A funnel does not make trace smaller. What leaves it is the sum of what enters it. So the rate at the sink is the sum of all sources, and a designer adds it up point by point. That sum is the budget.
Second idea: the excess piles up. A port of a few pins carries less than eight busy cores produce. The difference is a backlog, and it grows for as long as the burst lasts. A buffer holds it for a while. How long is one division.
Third idea: a loss must leave a mark. When no place is free, a record is dropped. If nothing says so, the gap looks like a core that did nothing. A trace with silent gaps is worse than no trace, because you believe it.
New Words
| Word | Meaning |
|---|---|
| Trace network | The funnels and trace links that bring the trace of every source to one place. |
| Record of a trace source | One message of a trace source, with the source ID and a time stamp. Record for short. |
| Time stamp of a record | A number in a record that says when its event happened. Every source reads it from one shared counter. Time stamp for short. |
| Trace port | A few pins that carry trace off the chip, to a recorder on the bench. |
| Trace buffer | A memory on the chip that keeps trace until a debugger reads it. |
| Trace sink | The place where trace ends: a trace port or a trace buffer. Sink for short. |
| Trace budget | The sum of the rates at each point of the trace network, set against what the next stage can carry. |
| Excess rate | What arrives at a point, less what leaves it, when more arrives. Excess for short. |
| Loss mark | A flag that says: records were dropped here. It travels with the trace or is kept in a register. |
Units on this page: MB/s is a million bytes in a second, and kB is a thousand bytes. So 1 MB/s for 1 millisecond (ms) is 1 kB.
One Picture: The Trace Network
- Processor
- Debug
- Pads
- Memory
- Four busy cores
Each core has a trace source. In this burst, four cores are busy and send 3 MB/s each. Funnel A passes on the sum: 12.
- Four quiet cores
The other four send 1 MB/s each. Funnel B passes on 4.
- The last funnel
The two streams meet. After the last funnel the rate is 12 and 4: 16 MB/s.
- The port
The trace port carries 10 MB/s to a recorder outside. It is the bottleneck: 6 MB/s have no way out.
- The buffer
What the port cannot carry goes to a buffer in RAM. The buffer buys time. It does not make the port faster.
Read the diagram as text
- Cores 0 to 3: busy: 3 MB/s of trace each
- Cores 4 to 7: quiet: 1 MB/s of trace each
- Funnel A: four inputs
- Funnel B: four inputs
- Last funnel: two inputs
- Trace port: pins; carries 10 MB/s off the chip
- Trace buffer: 60 kB of RAM on the chip
- Cores 0 to 3 → Funnel A: 4 x 3
- Cores 4 to 7 → Funnel B: 4 x 1
- Funnel A → Last funnel: 12
- Funnel B → Last funnel: 4
- Last funnel → Trace port: 10 of the 16
- Last funnel → Trace buffer: the other 6
The trace network of the exercise chip ap_phone in one burst. Decimal units: 1 MB is a million bytes, 1 kB is a thousand.
The Smallest Example, Worked by Hand
No simulator yet. First the budget of the picture, as a table. Work from the cores toward the sink, and add at every funnel.
| Point | Sum | Rate |
|---|---|---|
| After funnel A | 4 cores at 3 MB/s | 12 MB/s |
| After funnel B | 4 cores at 1 MB/s | 4 MB/s |
| After the last funnel | 12 and 4 | 16 MB/s |
| Carried by the trace port | 10 MB/s | |
| Excess | 16 less 10 | 6 MB/s |
The excess of 6 MB/s is 6 kB in each millisecond. The trace buffer has 60 kB. It is full after 10 milliseconds. A burst of 10 milliseconds just fits. In the 11th millisecond something must be lost.
Now a small funnel, to see where a loss happens. It has four sources. Each source has one place for a waiting record, and the funnel has one output place. That is room for five records.
Eight events arrive, one on each tick: sources 0, 1, 2, 3 and then 0, 1, 2, 3 again. The sink takes nothing for a while.
| Event | Source | Where its record goes |
|---|---|---|
| 0 | 0 | To the output place. It waits there for the sink |
| 1, 2, 3 | 1, 2, 3 | Each to the place of its own source |
| 4 | 0 | To the place of source 0, which is free: its first record moved on |
| 5, 6, 7 | 1, 2, 3 | Nowhere. The place of each source is still full: lost |
Five records are held and three are lost. Notice where. The sink was the slow part, at the far end. The records died at the sources, at the near end.
The Rules
Rule 1: Rates add where streams meet.
A funnel passes on the sum of its inputs. It makes nothing smaller.
Rule 2: The excess at a point is what arrives less what leaves.
While it is above zero, a backlog grows there.
Rule 3: A buffer lasts its size divided by the excess.
After that time a record is lost, however large the average looked.
Rule 4: A record that waits is one record.
The same record on several rows with ready at 0 has not moved.
Rule 5: A record is lost where no place is free for it.
That can be far before the slow stage. A buffer helps only where the backlog forms.
Rule 6: Every loss leaves a mark, and every record carries its source ID and its time stamp.
Then a gap can be told from silence, and records of several cores can be put in order.
Sources for These Rules
Rule 4, a transfer only when valid and ready are both 1, and a sender that holds its data during a stall: Arm AMBA ATB Protocol Specification, IHI 0032 issue C, sections 3.1 and 3.2. The source ID: section 4.1.
The parts of a trace network, with a funnel between sources and sinks: the same specification, section 1.2. It names two kinds of sink, a buffer on the chip and a port to the pins.
Rules 1 to 3 are arithmetic. Rule 5 is what the lab shows. Rule 6 is design practice: the time stamp and the loss mark are not part of ATB.
Every rate and size on this page is an exercise value.
Now Run It
The lab at the end of this page prints the budget first. Then it runs the small funnel of the second hand table, with a sink that is not ready for 8 ticks.
funnel_a=12 funnel_b=4 joined=16 port=10 excess=6
buffer=60 kB grows 6 kB each ms, full after 10 ms
tick=2 ready=0 source=0 stamp=0
tick=3 ready=0 source=0 stamp=0
tick=4 ready=0 source=0 stamp=0
tick=5 ready=0 source=0 stamp=0
tick=5 lost_mask=0010
tick=6 ready=0 source=0 stamp=0
tick=6 lost_mask=0100
tick=7 ready=0 source=0 stamp=0
tick=7 lost_mask=1000
tick=8 ready=1 source=0 stamp=0
tick=9 ready=1 source=1 stamp=1
tick=10 ready=1 source=2 stamp=2
tick=11 ready=1 source=3 stamp=3
tick=12 ready=1 source=0 stamp=4
records delivered=5 lost=3Rules 1 and 2 at work, in the first row: funnel_a=12 and funnel_b=4 give joined=16, and excess=6 against a port of 10. Rule 3, in the second row: 60 kB at 6 kB each millisecond is full after 10.
Rule 4, at ticks 2 to 7. The record of source 0 with stamp 0 is printed six times with ready=0. That is one record that waits, not six.
Rule 5, in the three lost_mask rows. At tick 5 the mask is 0010: the second event of source 1 found its place full. Sources 2 and 3 follow at ticks 6 and 7.
From tick 8 the sink is ready and takes stamps 0, 1, 2, 3 and 4. Stamps 5, 6 and 7 never appear. The last row counts it: delivered=5, lost=3.
Run the same events with a sink that is always ready, and the last row says delivered=8 lost=0. The funnel was not too small. The sink was too slow, and the loss showed up at the other end.
This lab leaves things out. Its sources hold one record each, where real ones hold a few. And it has no trace buffer: the 60 kB of the budget are a sum, not a memory.
Why It Is Built This Way
| Choice | The alternative | Its cost |
|---|---|---|
| A buffer on the chip beside the port | A port wide enough for every burst | Pins are few, and fast pins are costly. Most of the time the wide port would carry nothing. |
| A tree of small funnels | One funnel with eight inputs | Long wires from every corner of the chip to one block, and one large mux on a fast path. |
| A loss mark at each place | Count on enough room | One burst that nobody planned for leaves a gap that looks like an idle core. |
| One shared counter for time stamps | A counter in each source | The counters drift apart. Records of two cores could no longer be put in order. |
When a buffer is full there is still a choice. Stop, and the start of the story is kept. Overwrite the oldest record, and the end is kept. For a hang you want the end. For a fault during the start of the chip you want the beginning.
The Trap: The Quiet Twenty Milliseconds
Back to core 5 and its silence. The engineer first reads it as proof: core 5 was idle, so the bug is elsewhere. Two days go into the other cores.
Then somebody adds up the burst. In those twenty milliseconds four cores were busy at once. The buffer was full after ten, and the records of core 5 were dropped at its own source. Core 5 had been running the code with the bug all along. No loss mark was kept, so nothing on the screen said so.
The second trap is the average. Over the whole second the port was half empty. A budget made with averages says that all is well. Rule 3 is about the burst, not the average.
The third trap is the bigger memory. The team doubles the trace buffer, and the records of core 5 are still missing in a longer burst. The buffer sits behind the last funnel. The loss happens before the first one.
At Scale
This section looks ahead, to what a trace network must also survive on a chip that sleeps and that keeps secrets.
Send less
The cheapest fix for an excess is at the source. Trace only the cores, or only the stretch of the program, that the question needs.
A core that sleeps
A trace source lives in the power domain of its core. Before that domain goes off, a flush moves out what the source still holds.
Trace that wakes a clock
A funnel whose clock is stopped cannot take a record. ATB has a wire that says that trace is coming, for a clock controller to act on.
Trace is a side door
A trace shows every address that a program ran. So turning it on, and reading the buffer, each need the permission of the debug port.
Try It
Run the lab. The first two rows are the budget. The rest is a small funnel behind a sink that is not ready for 8 ticks.
Set SLOW_TICKS to 0. Predict the last row, and say which rows disappear.
Set PORT_RATE to 16. Predict the first two rows.
Names Printed by the Lab
| Name | Meaning |
|---|---|
| funnel_a, funnel_b, joined | The rates that leave funnel A, funnel B and the last funnel, in MB/s. |
| port, excess | What the trace port carries, and what is left over, in MB/s. |
| tick | The number of a clock edge of the small funnel. |
| ready | The ready wire of the sink at that edge. |
| source | The source ID of the record at the output of the funnel. |
| stamp | The time stamp of that record: the tick of its event. |
| lost_mask | One bit for each source, source 3 on the left. 1 means: an event of this source was dropped at this tick. |
| delivered, lost | Records that the sink took, and events that were dropped. |
Sources and What the Lab Leaves Out
The budget rows are sums in test code. The funnel rows come from a small circuit, trace_funnel, with four sources and one output.
Each source of that circuit has one place for a waiting record. A real trace source has a small queue of its own.
The lab has no trace buffer and no trace port. Its sink is one ready wire that the bench holds at 0.
funnel_a=12 funnel_b=4 joined=16 port=10 excess=6 buffer=60 kB grows 6 kB each ms, full after 10 ms tick=2 ready=0 source=0 stamp=0 tick=3 ready=0 source=0 stamp=0 tick=4 ready=0 source=0 stamp=0 tick=5 ready=0 source=0 stamp=0 tick=5 lost_mask=0010 tick=6 ready=0 source=0 stamp=0 tick=6 lost_mask=0100 tick=7 ready=0 source=0 stamp=0 tick=7 lost_mask=1000 tick=8 ready=1 source=0 stamp=0 tick=9 ready=1 source=1 stamp=1 tick=10 ready=1 source=2 stamp=2 tick=11 ready=1 source=3 stamp=3 tick=12 ready=1 source=0 stamp=4 records delivered=5 lost=3Read included file: soc-s1011-funnel.sv
// Each event source has one capture slot. A held output owns a separate slot.
module trace_funnel (
input logic clk, reset_n,
input logic [3:0] events,
input logic [7:0] stamp,
input logic ready,
output logic valid,
output logic [1:0] source_id,
output logic [7:0] captured,
output logic [3:0] lost
);
logic [3:0] pending;
logic [7:0] stamps [4];
logic [1:0] first, chosen;
logic found;
always_comb begin
found = 0;
chosen = first;
for (int offset = 0; offset < 4; offset++) begin
if (!found && pending[2'(first + offset)]) begin
chosen = 2'(first + offset);
found = 1;
end
end
end
always_ff @(posedge clk) begin
if (!reset_n) begin
pending <= 0;
first <= 0;
valid <= 0;
lost <= 0;
source_id <= 0;
captured <= 0;
end else begin
lost <= 0;
if (!valid || ready) begin
valid <= found;
if (found) begin
source_id <= chosen;
captured <= stamps[chosen];
first <= chosen + 1'b1;
pending[chosen] <= 0;
end
end
for (int i = 0; i < 4; i++) begin
if (events[i]) begin
if (!pending[i] || ((!valid || ready) && found && chosen == i)) begin
pending[i] <= 1;
stamps[i] <= stamp;
end else lost[i] <= 1;
end
end
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Plan the trace port with the average rate.
A burst is far above the average, and the buffer fills during the burst.
Fix Add up the rates of the worst burst, and divide the buffer by the excess.
Wrong Read a gap in the trace as an idle core.
The records may have been dropped for lack of room.
Fix Look for the loss mark first.
Wrong Add memory behind the last funnel to stop a loss at a source.
A buffer helps only where the backlog forms.
Fix Find the place where the first record was dropped, and give that place room.
Remember
- Rates add where streams meet. Budget the trace point by point, for the worst burst.
- A buffer lasts its size divided by the excess. It buys time and no speed.
- A record is lost where no place is free, which can be far before the slow stage.
- Every loss leaves a mark. Every record carries its source ID and its time stamp.