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.
| Question | |
|---|---|
| 1 | Why is it not enough to halt eight harts one after another? |
| 2 | What does a halt group change, and what does it leave as it was? |
| 3 | Three of four members have reported. Is the group halted? |
| 4 | A member has no supply when the event comes. What should the debugger be told? |
| 5 | All 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
| Word | Meaning |
|---|---|
| Hart select | A field of the debug module. It holds the number of the hart that the debugger talks to. |
| Halt group | A set of harts that are to halt together. |
| Group mask | One bit for each hart. 1 means: this hart is a member of the halt group. |
| Group event | What starts the halt of a group: a member that halts, or a signal from another block. Event for short on this page. |
| Halt report | A signal from one hart to the debug module. 1 means: I have halted. |
| Halt spread | The time from the first halt of a member to the last. Spread for short. |
| Unavailable hart | A hart that cannot answer the debug module, because it has no supply or no clock. |
One Picture: From One Port to a Group
- Pads
- Debug
- Processor
- 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.
- One hart at a time
The hart select names one hart. A halt request from the debugger reaches that hart. The others run on.
- 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.
- 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.
- 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.
| Hart | Request arrives at | Instruction needs | Halted at |
|---|---|---|---|
| 0 | 4 | 1 | 5 |
| 1 | 8 | 3 | 11 |
| 3 | 12 | 2 | 14 |
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.
| Hart | Request arrives at | Instruction needs | Halted at |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 1 | 0 | 3 | 3 |
| 3 | 0 | 2 | 2 |
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
Rule 1: The debugger talks to one hart at a time.
It is the hart that the hart select names.
Rule 2: A halt request through the hart select reaches one hart.
Every other hart runs on while the debugger moves to the next.
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.
Rule 4: Each member still halts at its own instruction boundary.
So the spread of a group is short, and it is not zero.
Rule 5: A group is halted when every member has reported.
The first report proves nothing about the others.
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.
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=2Rules 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.
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=0111Rule 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
| Choice | The alternative | Its cost |
|---|---|---|
| The group request is made inside the chip | A faster cable | Any cable is slower than a clock edge. The spread would shrink and still be thousands of instructions. |
| Halted means all have reported | Halted at the first report | The debugger would read registers of harts that still run. A value could change between two reads. |
| An unavailable hart is named | The debugger just waits | A wait with no end looks like a broken tool. A limit with no reason looks like a broken chip. |
| A halted hart keeps its supply | The power controller may switch it off | Its 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
This section looks ahead, to what eight harts and several kinds of block ask of a debug system.
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.
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.
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.
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
| Name | Meaning |
|---|---|
| t | The time in ticks. In the group part, t=0 is the event. |
| select hart | The debugger names that hart in the hart select and writes a halt request. One such visit takes 4 ticks. |
| halted | One bit for each hart, hart 3 on the left and hart 0 on the right. 1 means: this hart has reported its halt. |
| group_halted | 1 when every member of the group has reported. |
| first, last, spread | The times of the first and of the last halt of a member, and the difference. |
| missing | The members that have not reported, as bits. |
| powered | One 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.
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=2Check Yourself
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.