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.

Five questions this page answers
Question
1Eight cores send trace toward one port. How do you find the rate that arrives there?
2More arrives than the port carries. How long does a buffer last?
3A sink is slow. Where are the records lost?
4Why must every lost record leave a mark?
5The 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

New words on this page
WordMeaning
Trace networkThe funnels and trace links that bring the trace of every source to one place.
Record of a trace sourceOne message of a trace source, with the source ID and a time stamp. Record for short.
Time stamp of a recordA number in a record that says when its event happened. Every source reads it from one shared counter. Time stamp for short.
Trace portA few pins that carry trace off the chip, to a recorder on the bench.
Trace bufferA memory on the chip that keeps trace until a debugger reads it.
Trace sinkThe place where trace ends: a trace port or a trace buffer. Sink for short.
Trace budgetThe sum of the rates at each point of the trace network, set against what the next stage can carry.
Excess rateWhat arrives at a point, less what leaves it, when more arrives. Excess for short.
Loss markA 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

Eight Streams into One PortStep through the picture. It starts at four cores and ends at the two places where trace can go. The numbers are rates in MB/s.
  • Processor
  • Debug
  • Pads
  • Memory
Eight Streams Into One PortStep through the picture. It starts at four cores and ends at the two places where trace can go. The numbers are rates in MB/s. component Cores 0 to 3 busy: 3 MB/s oftrace each component Cores 4 to 7 quiet: 1 MB/s oftrace each component Funnel A four inputs component Funnel B four inputs component Last funnel two inputs component Trace port pins; carries 10MB/s off the chip component Trace buffer 60 kB of RAM on thechip 4 x 34 x 112410 of the 16the other 6
  1. component Cores 0 to 3busy: 3 MB/s of trace each
    • 4 x 3 → Funnel A
  2. component Funnel Afour inputs
    • 12 → Last funnel
  3. component Cores 4 to 7quiet: 1 MB/s of trace each
    • 4 x 1 → Funnel B
  4. component Funnel Bfour inputs
    • 4 → Last funnel
  5. component Last funneltwo inputs
    • 10 of the 16 → Trace port
    • the other 6 → Trace buffer
  6. component Trace portpins; carries 10 MB/s off the chip
  7. component Trace buffer60 kB of RAM on the chip
  1. 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.

  2. Four quiet cores

    The other four send 1 MB/s each. Funnel B passes on 4.

  3. The last funnel

    The two streams meet. After the last funnel the rate is 12 and 4: 16 MB/s.

  4. The port

    The trace port carries 10 MB/s to a recorder outside. It is the bottleneck: 6 MB/s have no way out.

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

The trace budget of one burst, by hand
PointSumRate
After funnel A4 cores at 3 MB/s12 MB/s
After funnel B4 cores at 1 MB/s4 MB/s
After the last funnel12 and 416 MB/s
Carried by the trace port10 MB/s
Excess16 less 106 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.

Eight events and five places, by hand
EventSourceWhere its record goes
00To the output place. It waits there for the sink
1, 2, 31, 2, 3Each to the place of its own source
40To the place of source 0, which is free: its first record moved on
5, 6, 71, 2, 3Nowhere. 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

  1. Rule 1: Rates add where streams meet.

    A funnel passes on the sum of its inputs. It makes nothing smaller.

  2. Rule 2: The excess at a point is what arrives less what leaves.

    While it is above zero, a backlog grows there.

  3. Rule 3: A buffer lasts its size divided by the excess.

    After that time a record is lost, however large the average looked.

  4. Rule 4: A record that waits is one record.

    The same record on several rows with ready at 0 has not moved.

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

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

Printed by the lab on Icarus. A lost_mask row marks an event that found the place of its source full.
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=3

Rules 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

ChoiceThe alternativeIts cost
A buffer on the chip beside the portA port wide enough for every burstPins are few, and fast pins are costly. Most of the time the wide port would carry nothing.
A tree of small funnelsOne funnel with eight inputsLong wires from every corner of the chip to one block, and one large mux on a fast path.
A loss mark at each placeCount on enough roomOne burst that nobody planned for leaves a gap that looks like an idle core.
One shared counter for time stampsA counter in each sourceThe 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

ap_soc2 sources, 1 funnel
ap_phone8 sources, 3 funnels, 2 sinks

This section looks ahead, to what a trace network must also survive on a chip that sleeps and that keeps secrets.

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

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

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

  4. 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
NameMeaning
funnel_a, funnel_b, joinedThe rates that leave funnel A, funnel B and the last funnel, in MB/s.
port, excessWhat the trace port carries, and what is left over, in MB/s.
tickThe number of a clock edge of the small funnel.
readyThe ready wire of the sink at that edge.
sourceThe source ID of the record at the output of the funnel.
stampThe time stamp of that record: the tick of its event.
lost_maskOne bit for each source, source 3 on the left. 1 means: an event of this source was dropped at this tick.
delivered, lostRecords 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.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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=3
Read 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

Predict the outputIn this run the sink is not ready for 4 ticks, not 8. Count the places of the small funnel against the events that arrive in that time. What is the last line? Its form is: records delivered=.. lost=..
module tb;
  // The trace network of ap_phone in a burst: four busy cores, four quiet ones. Rates in MB/s.
  localparam int BUSY_RATE = 3, QUIET_RATE = 1;
  localparam int PORT_RATE = 10;        // what the trace port can carry off the chip
  localparam int BUFFER_KB = 60;      // the trace buffer in RAM, for what the port cannot take
  localparam int SLOW_TICKS = 4;       // ticks for which the sink of the small funnel is not ready

  logic clk = 0, reset_n = 0;
  logic [3:0] events = 0;
  logic [7:0] stamp = 0;
  logic ready = 0;
  wire valid;
  wire [1:0] source_id;
  wire [7:0] captured;
  wire [3:0] lost;
  int delivered = 0, dropped = 0;
  trace_funnel funnel (clk, reset_n, events, stamp, ready, valid, source_id, captured, lost);
  always #5 clk = !clk;

  initial begin
    int a, b, joined, excess;
    // Rates add where streams meet.
    a = 4 * BUSY_RATE;
    b = 4 * QUIET_RATE;
    joined = a + b;
    excess = joined > PORT_RATE ? joined - PORT_RATE : 0;
    $display("funnel_a=%0d funnel_b=%0d joined=%0d port=%0d excess=%0d", a, b, joined, PORT_RATE, excess);
    // 1 MB/s for 1 ms is 1 kB.
    if (excess == 0) $display("buffer=%0d kB never fills", BUFFER_KB);
    else $display("buffer=%0d kB grows %0d kB each ms, full after %0d ms", BUFFER_KB, excess, BUFFER_KB / excess);

    // A small funnel: four sources, one place for a waiting record in each, one output.
    // One event on each tick, two rounds of the four sources. The stamp is the tick of the event.
    repeat (2) @(negedge clk);
    reset_n = 1;
    for (int tick = 0; tick < 16; tick++) begin
      @(negedge clk);
      events = tick < 8 ? 4'b0001 << (tick % 4) : 0;
      stamp = tick;
      ready = tick >= SLOW_TICKS;
      @(posedge clk);
      if (valid) $display("tick=%0d ready=%b source=%0d stamp=%0d", tick, ready, source_id, captured);
      if (valid && ready) delivered++;
      #1;
      if (lost != 0) begin
        $display("tick=%0d lost_mask=%04b", tick, lost);
        dropped += $countones(lost);
      end
    end
    $display("records delivered=%0d lost=%0d", delivered, dropped);
    $finish;
  end
endmodule
Read 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
ConceptEight cores send trace toward one port. How do you find the rate that arrives there?
ConceptMore arrives than the port carries. How long does a buffer last?
ConceptA sink is slow. Where are the records lost?
ConceptWhy must every lost record leave a mark?

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.

Practice

Report a problem with this page