Debug at Scale: Halting a Group of Cores

One debug port serves every hart of a large chip. Halt them one by one and they stop far apart. A halt group stops them on one event, and tells you when all of them have stopped.

You Will Be Able To

  • Say why harts that are halted one at a time do not show one moment of the system.
  • Describe a halt group: who sends the request, and when the group counts as halted.
  • Say what a debugger must be told about a member that has no supply.
Lesson
S10.11
Time
24 min
Runs on
Your browser
Check
5 questions

A phone hangs once in a few hundred starts, always just after one interrupt. You attach a debugger and halt core 0.

It stopped where you expected. But while your request travelled, the other seven cores ran on, and one of them cleared what you came to see.

Before You Start

You need Halt, Resume and Step: a halt request, the instruction boundary, and the next pc.

You need The Debug Module on the Bus: the debug module and the debug port.

You need More Than One Core: a hart, and several of them on one chip.

Five questions this page answers
Question
1Why is it not enough to halt eight harts one after another?
2What does a halt group change, and what does it leave as it was?
3Three of four members have reported. Is the group halted?
4A member has no supply when the event comes. What should the debugger be told?
5All four harts are members, and hart 2 needs 5 more ticks. What spread does the lab print?

The Idea: Stop Together, or See Nothing

On the small chip a halt was simple. There was one hart. It stopped at an instruction boundary, and its registers were a true picture of the program at that point.

A phone has eight harts and still one debug port. The debugger talks to one hart at a time. It names the hart, sends the halt request, and moves on to the next. Each visit takes time on the cable, and all that time the harts not yet visited keep running.

So the eight stops are not one moment. Hart 0 shows the system at one time and hart 7 shows it much later. A value that hart 0 was waiting for may have been changed by hart 7 after hart 0 stopped. The picture is made of pieces that never existed together.

The cure is to take the cable out of the timing. The debugger marks a set of harts in advance. Such a set is called a halt group. Then one event inside the chip sends the halt request to every member on the same clock edge.

Two things do not change. Each hart still stops at its own instruction boundary, so the stops are close but not equal. And a request is not a stop: the group is halted only when every member has said so.

That last point has a hard case. A member whose supply is off will never say so. The debugger must learn that, by name, and not wait for ever.

New Words

New words on this page
WordMeaning
Hart selectA field of the debug module. It holds the number of the hart that the debugger talks to.
Halt groupA set of harts that are to halt together.
Group maskOne bit for each hart. 1 means: this hart is a member of the halt group.
Group eventWhat starts the halt of a group: a member that halts, or a signal from another block. Event for short on this page.
Halt reportA signal from one hart to the debug module. 1 means: I have halted.
Halt spreadThe time from the first halt of a member to the last. Spread for short.
Unavailable hartA hart that cannot answer the debug module, because it has no supply or no clock.

One Picture: From One Port to a Group

One Port, Many HartsStep through the picture. It starts with the one debug port and ends with a group that stops on one event.
  • Pads
  • Debug
  • Processor
One Port, Many HartsStep through the picture. It starts with the one debug port and ends with a group that stops on one event. component Debugger on a laptop, at theend of a cable component Debug module one for the chip;holds the hart select component Halt group logic holds the group mask component Hart 0 a member component Hart 1 a member component Hart 2 not a member; runs on component Hart 3 a member debug portselectedeventhalt requesthalt requesthalt requestall have reported
  1. component Debuggeron a laptop, at the end of a cable
    • debug port → Debug module
  2. component Debug moduleone for the chip; holds the hart select
    • selected → Hart 0
  3. component Hart 0a member
    • event → Halt group logic
  4. component Hart 1a member
  5. component Hart 2not a member; runs on
  6. component Hart 3a member
  7. component Halt group logicholds the group mask
    • halt request → Hart 1
    • halt request → Hart 3
    • halt request → Hart 0
    • all have reported → Debug module
  1. One port

    The chip has one debug port and one debug module, however many harts it has. Everything the debugger does goes through this one door.

  2. One hart at a time

    The hart select names one hart. A halt request from the debugger reaches that hart. The others run on.

  3. A group

    The debugger marks some harts as a halt group, with one bit for each hart. Here harts 0, 1 and 3 are members.

  4. One event, one edge

    An event in hart 0 reaches the group logic. It sends a halt request to every member on the same clock edge. No cable is in the way.

  5. All have reported

    Each member halts at its own instruction boundary and reports. Only when every report is in does the debugger hear: the group is halted.

Read the diagram as text
  • Debugger: on a laptop, at the end of a cable
  • Debug module: one for the chip; holds the hart select
  • Halt group logic: holds the group mask
  • Hart 0: a member
  • Hart 1: a member
  • Hart 2: not a member; runs on
  • Hart 3: a member
  • Debugger → Debug module: debug port
  • Debug module → Hart 0: selected
  • Hart 0 → Halt group logic: event
  • Halt group logic → Hart 1: halt request
  • Halt group logic → Hart 3: halt request
  • Halt group logic → Hart 0: halt request
  • Halt group logic → Debug module: all have reported

Four of the eight harts of the exercise chip ap_phone. The hart select of the real chip has 3 bits, and the group mask has 8.

The Smallest Example, Worked by Hand

No simulator yet. Take four harts, and halt harts 0, 1 and 3. At the moment a request arrives, each hart is in the middle of an instruction. Hart 0 needs 1 more tick to finish it, hart 1 needs 3, and hart 3 needs 2.

First through the hart select, one at a time. Each visit of the debugger takes 4 ticks.

One at a time, by hand
HartRequest arrives atInstruction needsHalted at
0415
18311
312214

The first hart stops at 5 and the last at 14. The spread is 9 ticks. With eight harts and a real cable it is thousands of instructions.

Now as a group. One event sends all three requests at time 0.

As a group, by hand
HartRequest arrives atInstruction needsHalted at
0011
1033
3022

The spread is 2 ticks. It is not 0, and it never will be: each hart finishes the instruction it is in. The group is halted at tick 3, when the last report comes. At tick 1, with one report in, it is not.

The Rules

  1. Rule 1: The debugger talks to one hart at a time.

    It is the hart that the hart select names.

  2. Rule 2: A halt request through the hart select reaches one hart.

    Every other hart runs on while the debugger moves to the next.

  3. Rule 3: A halt group gets its request from one event, on one clock edge.

    The debugger sets the group mask in advance and takes no part in the timing.

  4. Rule 4: Each member still halts at its own instruction boundary.

    So the spread of a group is short, and it is not zero.

  5. Rule 5: A group is halted when every member has reported.

    The first report proves nothing about the others.

  6. Rule 6: A hart with no supply or no clock cannot report.

    It is shown as unavailable, and the group is not called halted.

Sources for These Rules

Rule 4 repeats a rule of the earlier lesson on halt, resume and step.

Rules 1 to 3, 5 and 6 follow the RISC-V External Debug Support specification, which has a hart select, halt groups and a status for a hart that is unavailable. That document is not in our reference library. The rules are given as common usage, not checked against it.

Arm chips do the same job with a block of their own for events between cores. No document on it is in the library either.

The 4 ticks of a visit, and the limit of 6 ticks, are lab choices.

Now Run It

The lab at the end of this page plays both hand tables. In the group part, t=0 is the event.

Printed by the lab on Icarus. Test code with no circuit.
select hart0: request at t=4 halted at t=5
select hart1: request at t=8 halted at t=11
select hart3: request at t=12 halted at t=14
one at a time: first=5 last=14 spread=9
t=1 halted=0001 group_halted=0
t=2 halted=1001 group_halted=0
t=3 halted=1011 group_halted=1
as a group: first=1 last=3 spread=2

Rules 1 and 2 at work, in the first four rows. The requests arrive at 4, 8 and 12, one visit apart. The last hart stops at 14, and spread=9.

Rules 3 and 4, in the last row. All three requests left at t=0. The halts still come at 1, 3 and 2, and spread=2.

Rule 5, in the three rows that start with t. At t=1 one bit of halted is set, at t=2 two, and group_halted stays 0. It is 1 only at t=3, with halted=1011.

Now the hard case. Hart 3 has lost its supply just before the event. Here is the group part of that run.

The same lab with the supply of hart 3 off. Only the group part is shown.
t=1 halted=0001 group_halted=0
t=2 halted=0001 group_halted=0
t=3 halted=0011 group_halted=0
t=4 halted=0011 group_halted=0
t=5 halted=0011 group_halted=0
t=6 halted=0011 group_halted=0
as a group: first=1 last=3 spread=2
gave up at t=6: missing=1000 powered=0111

Rule 6 at work. Harts 0 and 1 report as before. Hart 3 never does, so halted stays at 0011 and group_halted at 0. After 6 ticks the lab gives up and names the reason: missing=1000, and the powered digits show a 0 for hart 3.

This lab leaves things out. It is test code: no instruction runs, and a hart is only a count of ticks. It has four of the eight harts.

Why It Is Built This Way

ChoiceThe alternativeIts cost
The group request is made inside the chipA faster cableAny cable is slower than a clock edge. The spread would shrink and still be thousands of instructions.
Halted means all have reportedHalted at the first reportThe debugger would read registers of harts that still run. A value could change between two reads.
An unavailable hart is namedThe debugger just waitsA wait with no end looks like a broken tool. A limit with no reason looks like a broken chip.
A halted hart keeps its supplyThe power controller may switch it offIts registers are the evidence. Without power they are gone before anybody has read them.

A group has a price too. Its members must be chosen before the event. A hart that was left out runs on, like hart 2 of the picture, and can still change what the others share.

The Trap: The First Report

Back to the phone that hangs. You set up a halt group of all cores this time, and the event is the interrupt. The debugger shows the first halt report within a moment. It feels like success, and you start to read registers.

One core has not reported yet. It is still finishing a store. You read the memory word that it wrote. Its value is no longer the one that the other cores saw when they stopped. You are debugging a state that the system was never in.

The second trap is the core that sleeps. To save power, an idle core had been switched off just before the interrupt. The group can never be complete. A tool that says only "timeout" sends you looking for a hang in the debug logic. A tool that says "hart 3 is unavailable" sends you to the power controller.

The third trap follows from it. Somebody wakes the core and tries again. A report that was left over from an earlier try now counts as the answer. So every new request must first clear the old reports.

At Scale

ap_soc1 hart, no select
ap_phone8 harts, 3 select bits, a mask of 8 bits

This section looks ahead, to what eight harts and several kinds of block ask of a debug system.

  1. Resume together

    What holds for the halt holds for the resume. Harts that start one by one run against harts that still stand. A group can be resumed on one edge as well.

  2. Events from other blocks

    The event need not come from a hart. A comparator on the bus, or a block outside the cores, can start the halt of a group.

  3. Power and debug meet

    The debug module sits in a domain that stays on while cores sleep. It asks the power controller to keep a halted core powered, and to wake one that it needs.

  4. A halt shows where, not how

    A halted group shows where each hart stopped. How each got there is the job of the trace, and of the next lesson.

Try It

Run the lab. It halts harts 0, 1 and 3 twice: first one at a time, then as a group. Compare the two spreads.

Take the supply from hart 3: set the last number of the powered line to 0. Predict what the group part prints.

Make hart 2 a member: change GROUP to 1111. Predict the new spread of the group.

Names Printed by the Lab
NameMeaning
tThe time in ticks. In the group part, t=0 is the event.
select hartThe debugger names that hart in the hart select and writes a halt request. One such visit takes 4 ticks.
haltedOne bit for each hart, hart 3 on the left and hart 0 on the right. 1 means: this hart has reported its halt.
group_halted1 when every member of the group has reported.
first, last, spreadThe times of the first and of the last halt of a member, and the difference.
missingThe members that have not reported, as bits.
poweredOne digit for each hart, hart 3 on the left. 1 means: this hart has its supply.
Sources and What the Lab Leaves Out

The lab is test code with no circuit. A hart is a count of ticks until its next instruction boundary. No instruction runs.

It has no debug module and no cable. A visit of the debugger is a fixed 4 ticks. On a real cable one visit is many transfers.

It has four harts of the eight. Its debugger gives up 6 ticks after the event. That limit is a lab choice.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: select hart0: request at t=4 halted at t=5 select hart1: request at t=8 halted at t=11 select hart3: request at t=12 halted at t=14 one at a time: first=5 last=14 spread=9 t=1 halted=0001 group_halted=0 t=2 halted=1001 group_halted=0 t=3 halted=1011 group_halted=1 as a group: first=1 last=3 spread=2

Check Yourself

Predict the outputIn this run all four harts are members. Their instructions need 1, 3, 5 and 2 more ticks. What is the last line? Its form is: as a group: first=.. last=.. spread=..
module tb;
  // Four of the eight harts of ap_phone. A hart halts at its next instruction boundary, never earlier.
  localparam bit [3:0] GROUP = 4'b1111;   // bit i is hart i: the members of the halt group
  int left [4];          // ticks that the instruction in progress still needs
  bit powered [4];
  bit [3:0] halted;
  int halt_tick [4];
  int first, last, t;

  task automatic restart;
    halted = 0;
    left[0] = 1; left[1] = 3; left[2] = 5; left[3] = 2;
    powered[0] = 1; powered[1] = 1; powered[2] = 1; powered[3] = 1;
  endtask

  task automatic spread(input string label);
    first = 1000;
    last = 0;
    for (int h = 0; h < 4; h++) if (GROUP[h] && halted[h]) begin
      if (halt_tick[h] < first) first = halt_tick[h];
      if (halt_tick[h] > last) last = halt_tick[h];
    end
    $display("%s: first=%0d last=%0d spread=%0d", label, first, last, last - first);
  endtask

  initial begin
    // One at a time: the debugger selects a hart and sends a halt request. Each such visit takes
    // 4 ticks on the cable. The other harts run on in the meantime.
    restart;
    t = 0;
    for (int h = 0; h < 4; h++) if (GROUP[h]) begin
      t += 4;                                // select the hart, write the request
      if (powered[h]) begin
        halt_tick[h] = t + left[h];
        halted[h] = 1;
        $display("select hart%0d: request at t=%0d halted at t=%0d", h, t, halt_tick[h]);
      end else $display("select hart%0d: request at t=%0d no answer", h, t);
    end
    spread("one at a time");

    // As a group: one event sends the request to every member on the same tick, t=0.
    restart;
    for (t = 1; t <= 6 && (halted & GROUP) != GROUP; t++) begin
      for (int h = 0; h < 4; h++) if (GROUP[h] && powered[h] && !halted[h]) begin
        left[h]--;
        if (left[h] == 0) begin
          halted[h] = 1;
          halt_tick[h] = t;
        end
      end
      $display("t=%0d halted=%04b group_halted=%0d", t, halted, (halted & GROUP) == GROUP);
    end
    spread("as a group");
    if ((halted & GROUP) != GROUP)
      $display("gave up at t=6: missing=%04b powered=%0d%0d%0d%0d", GROUP & ~halted, powered[3], powered[2], powered[1], powered[0]);
  end
endmodule
ConceptWhy is it not enough to halt eight harts one after another?
ConceptWhat does a halt group change?
ConceptThree of four members have reported. Is the group halted?
ConceptA member has no supply when the event comes. What should the debugger be told?

Common Mistakes

Wrong Halt the cores one after another and read their registers as one picture.

Each core stopped at another time, and the later ones ran on.

Fix Put the cores in a halt group and let one event stop them.

Wrong Call the group halted at the first halt report.

The other members may still run and still write.

Fix Wait until every member has reported.

Wrong Wait without end for a member that is switched off.

A hart with no supply cannot report.

Fix Show it as unavailable, and say so by name.

Remember

  • One debug port reaches one hart at a time. Harts halted one by one stop far apart.
  • A halt group gets its request from one event on one edge, with no cable in the timing.
  • Each member still halts at its own instruction boundary: the spread is short, not zero.
  • The group is halted when every member has reported. A hart with no supply is shown as unavailable.

Practice

Report a problem with this page