Covering Chip Events, from the Bench and from C
Count chip events where they happen. A sampler bound into the bench counts events on wires. Firmware reports a scenario in software, only after checking it.
You Will Be Able To
- Write the coverage point of a chip event as a bench sampler and as a covergroup with a cross.
- Say which events the bench can sample and which only firmware can report.
- Pair a firmware scenario point with a bench point, and say why.
- Explain why the chip's own model counts with integers, and what it gives up.
- Lesson
- V12.2
- Time
- 28 min
- Runs on
- Coverage build
- Check
- 5 questions
A wake-up test prints "wake ok" and reports its scenario to the coverage model. The scenario bin fills. Did the wake really happen, or did the test only say so?
- Peripheral
- Processor
- Monitor
- Test
- Bus
- Result
- Interrupt
- Control
- Data
- Analysis
- An event on a wire
The timer's request rises. The bench sees the edge without any help from software.
- The state at that moment
The sampler asks what the core is doing right then, and counts the pair: one cross bin.
- An event only software knows
Firmware checks a scenario, then writes a planned number to TB_EVENT. The bench counts the write.
- One ledger
Both kinds of point carry dotted names, so the merge treats them alike.
Read the diagram as text
- Timer: request, source 3
- Core: running, in wfi, in a handler
- Bench sampler: counts at the rising edge
- Firmware: checks, then tb_cover
- TB_EVENT: a planned number
- Ledger: one bin per point
- Timer → Bench sampler: request rises
- Core → Bench sampler: state now
- Firmware → TB_EVENT: scenario held
- TB_EVENT → Bench sampler: full-word write
- Bench sampler → Ledger: hits
The structure of the chip's coverage model: tools/soc/ap_soc/bench/soc_tb/coverage/chip_cov.sv and the firmware kit's tb_cover.h.
Before You Start
Read What Coverage Means at Chip Level first. The mailbox is taught in The Mailbox: Telling the Bench What Happened. Covergroups and crosses: Covergroups and Coverpoints and Cross Coverage.
| Question | |
|---|---|
| 1 | Where in the bench is a chip event best counted? |
| 2 | How is the core's state attached to an interrupt arrival? |
| 3 | Which events can only firmware report, and how? |
| 4 | Why must a firmware point follow a check, and pair with a bench point? |
| 5 | Why does the chip's own model count with integers instead of covergroups? |
The Idea: Sample the Wire When There Is One
A chip event usually shows on some wire: a request rising, a gate closing, an address phase accepted. A sampler bound into the bench can watch that wire and count. It needs nothing from the test, so the test cannot fool it.
Some events have no wire. "The byte that arrived was the one expected" lives only in the firmware's comparison. So firmware reports it, by writing a planned number to the mailbox. That report is only as true as the code in front of it.
The two kinds work together. The bench says the hardware event happened; firmware says the scenario around it held. A scenario point paired with a bench point catches a test that reports without doing the work.
New Words
| Word | Meaning |
|---|---|
| Sampling event | The moment a point is counted, such as the rising edge of a request. |
| Bench-side point | A bin the bench's sampler counts by watching wires. |
| Firmware scenario point | A bin firmware fills by writing a planned number to TB_EVENT. |
| tb_cover | The firmware kit's call that writes such a number: 0xC07E_0000 plus the scenario's ID. |
| Core context | What the core is doing when a request rises: running, asleep in wfi, inside a handler, or replaced by the seat. |
The Smallest Example: One Request, One State
The chip's sampler counts irq.context.<id>.<state>: which request rose and what the core was doing. The core's state comes from three facts. Is the seat in place of the core? Is the core asleep? How many traps has it taken that it has not yet left with mret?
| Seat in place | Asleep | Traps minus returns | Context counted |
|---|---|---|---|
| yes | any | any | seat |
| no | yes | any | wfi |
| no | no | 1 or more | handler |
| no | no | 0 | other_cpu |
From core_context() in chip_cov.sv. The checks run in this order.
Work one through. The timer handler is running, so one trap is taken and not returned. It writes 1 to CLINT MSIP, and the software line rises. Not the seat, not asleep, one trap open: the sampler counts irq.context.msip.handler.
The Rules
Rule 1: Count a point at its own event, in the bench.
A rising edge, an accepted address phase, a gate closing. Count once per event, not once per cycle.
Rule 2: Attach the state the point is about.
An interrupt arrival is worth little alone. Crossed with the core's state it is an integration point.
Rule 3: Report a scenario from firmware only after checking it.
The call comes last, inside the branch where the check passed.
Rule 4: Pair each firmware point with a bench point.
The bench confirms that the hardware event behind the scenario happened.
Rule 5: Count only when it means something.
Not during reset, not before the system clock runs. The chip's sampler counts routes, interrupts, gates and pads only while resetn_sys is high.
Rule 6: Use one naming scheme everywhere.
Dotted bin names from bench and firmware merge into one ledger.
Sources for These Rules
Sampling edges, the core context and the firmware channel: tools/soc/ap_soc/bench/soc_tb/README.md, "Chip coverage (E11)"; facts §27.15. The marker range 0xC07E_0000 to 0xC07E_000F: tools/soc/fwkit/tb_cover.h.
Enable a point only when it is meaningful, so not during reset. Do not cover the same thing twice: MEHTA-DV 7.10.2 (PDF p168).
Covergroups, bins, ignore_bins and crosses: IEEE 1800 clauses 19.3, 19.5 and 19.6; a sample method with arguments: clause 19.8.1. The Coverage track teaches them in lessons C2 and C5.
The Lab: The Same Points, Two Ways
Here is the chip's sampler as it is, from chip_cov.sv. It keeps plain integer arrays. At each rising edge of a device request it adds one to irq_state[id][state]:
function automatic int core_context();
if (soc_tb.use_bfm) return 3;
if (dut.u_core.core_sleep) return 2;
return (handler_depth != 0) ? 1 : 0;
endfunction
...
if (dut.irq_irq[id] && !last_irq[id]) begin
raised[id]++;
irq_state[id][core_context()]++;
endNow the same points written as a covergroup, with a cross of source and state. This one is the runnable example below, on the Coverage track's engine:
id 3 in OTHER_CPU group 25.93%
id 3 in WFI group 40.74%
id 1 in OTHER_CPU group 55.56%
id 2 in HANDLER group 81.48%Rule 2 at work: the group percentage moves when a new pair arrives, not when a request repeats. After four arrivals the source and state points are full, but the cross has only four of its nine pairs. Read the last line as (100 + 100 + 44.44) / 3.
Then a firmware point on the chip. The E11 suite's wake test claims source 9, checks it and calls tb_cover. The ledger shows firmware.wake_claim with 2 hits, paired with irq.claimed.9 (2) and irq.completed.9 (2). Rule 4 is met: the bench saw the claim the firmware reported. Note irq.context.9.wfi at 0: the wake never arrived while the core slept.
The sampler is cheap. On the §6.2 loop it made the coverage build 3% slower than the same build without it. The medians of three runs were 5.475 s and 5.645 s, on a laptop busy with other jobs. The plan measured the same sampler on a quiet laptop at 4.6%, and in the build the problems run on at 1.8%. A few percent, then, and the spread between runs is of the same size.
Why It Is Built This Way
Why integers and not a covergroup in the chip's sampler? The coverage-capable simulator build can report a group's percentage, but it cannot answer how many times one bin was hit. A ledger needs the count of every bin, and the test that hit it first. So the sampler counts with integers and prints one line per bin, in the Coverage track's dotted names. Its one covergroup, on the power states, marks the two unused state codes as illegal bins; integers beside it give the counts.
You lose the language's conveniences: automatic bins, crosses written in one line, ignore_bins. You gain a per-bin count you can merge exactly. On a simulator with full covergroup reporting, the same plan would be a covergroup. The example above shows what it would look like.
Traps
The first trap is the report before the check. A test calls tb_cover, then compares the byte, and fails the comparison quietly on some seeds. The scenario bin fills on every run. Only the paired bench point, or a run where the check is planted to fail, shows the lie.
The second trap is counting during reset. A sampler counts edges while the chip comes out of reset, when requests can glitch to their reset values. The ledger fills with arrivals no test made. Gate every sampler on the system reset.
The third trap is two names for one point. The bench calls it irq.claimed.9 and firmware reports "pwr_claim". The merge sees two points, one always empty, and the review chases a hole that is not there.
At Scale
This section looks ahead. ap_soc has one core and one firmware channel.
Commercial coverage databases
Large flows keep covergroups, assertions' covers and code coverage in one database per run, with per-bin counts and merges.
Software coverage beside hardware
Teams also measure which firmware functions ran, with the compiler's own coverage tools, and set it beside the hardware plan.
Many cores
The core context becomes a vector: which core, in which state, received which interrupt.
Try It
Run it: four arrivals, and the group percentage after each.
Repeat one pair three times, then add another source (the predict question below). Which lines stay the same?
Add an arrival in the SEAT state. Why does the percentage not move?
id 3 in OTHER_CPU group 25.93% id 3 in WFI group 40.74% id 1 in OTHER_CPU group 55.56% id 2 in HANDLER group 81.48%Check Yourself
Common Mistakes
Wrong Call tb_cover at the top of the scenario.
The bin fills even when the scenario fails later.
Fix Call it last, inside the branch where the check passed.
Wrong Count an interrupt point at every cycle the request is high.
One arrival fills the bin many times, and the state is sampled at random moments.
Fix Count at the rising edge, with the state at that edge.
Wrong Trust a firmware point alone.
Firmware can report without the hardware event behind it.
Fix Pair it with a bench point on the same event.
Remember
- Count chip events in the bench, at their own edge, with the state they are about.
- Firmware reports what only software knows, after checking it, through TB_EVENT.
- Pair firmware points with bench points.
- The chip's sampler counts with integers because its simulator build cannot report per-bin counts of a covergroup.