Most firmware regressions break something you can see: a test fails, a value is wrong, the board doesn't boot. Timing regressions don't. A logging call lands in an interrupt handler, a priority gets shuffled, a driver starts holding a lock a little longer, and every functional test still passes. The response that took 2 µs now takes 9 µs, and you find out when a motor controller misses a commutation in the field.
The fix is boring: measure the time, on the real board, on every commit, and fail when it moves. Here's how we do that with a BenchPod.
The setup
The board under test has an input that matters (an interrupt pin, a trigger, a sensor's "data ready") and does something visible in response: it toggles an output, starts a PWM, raises a "busy" line. If there's no natural output, a debug GPIO that the handler toggles is enough. Two of the pod's channels cover it:
| Signal | Board | BenchPod |
|---|---|---|
| Stimulus | the input pin | an LA channel as a GPIO output |
| Response | the output pin | an LA channel, captured |
The trick is that the pod captures both lines. We don't trust the host to know when the stimulus happened: the edge is in the capture, at the same resolution as the response. Network latency, Python and the operating system drop out of the measurement completely.
How fine is fine enough
The logic analyzer's timing resolution is one sample. Since firmware 3.9.6 the pod samples all 14 channels at up to 48 MS/s:
| Sample rate | One sample | Good for |
|---|---|---|
| 1 MS/s | 1 µs | millisecond-scale deadlines, control loops |
| 12 MS/s | 83 ns | most interrupt handlers |
| 48 MS/s | 20.8 ns | interrupt entry, short handlers, jitter |
At 48 MS/s the pod records only the moments a line changes, so a quiet capture costs almost nothing and a few milliseconds of two toggling lines fits easily. For reference, a Cortex-M4 needs a dozen clock cycles to enter an interrupt, well under 100 ns at typical clock speeds, so 20.8 ns is enough to see the handler's own work and its jitter, not just the order of magnitude.
One measurement
The cleanest single measurement uses capture_la(send=...): the pod arms the capture, then sets the stimulus pin itself, in the same command. Trigger on the stimulus edge, and t = 0 is the exact moment the pin went high.
from embeddedci.benchpod import BenchPod, GpioSend, Trigger
STIM, RESP = 9, 10 # LA channels: the board's input and its answer
with BenchPod("192.168.1.150", la_voltage=3.3) as bp:
stim = bp.gpio(STIM, "output", level=0)
cap = bp.capture_la(100_000, sample_rate_hz=48e6,
trigger=Trigger(STIM, "rising"),
send=GpioSend(STIM, 1))
stim.low()
latency = cap.delay(STIM, RESP, from_edge="rising", to_edge="both")
print(f"stimulus to response: {latency * 1e9:.0f} ns")cap.delay() finds the first rising edge on the stimulus and the next edge on the response, and returns the seconds between them, or None if the board never answered inside the capture. 100,000 samples at 48 MS/s is about 2 ms of window; size it to your slowest acceptable response.
Many measurements, at a steady rate
One number isn't a latency. Interrupt response has jitter: a higher-priority handler, a flash wait state, a cache miss. To see it you want hundreds of events, ideally at the rate the board sees in the field.
The pod's FPGA can produce that rate by itself. pin.pulse(width, count=n) sends n high pulses of width seconds with the same gap between them, timed by the FPGA rather than the host. Width runs from 4 µs to 65.535 ms and the count up to 65,535. The call returns as soon as the train starts, so we start a long train and arm a capture on one of its rising edges:
import statistics, time
def response_times(bp, stim_la, resp_la, *, width=50e-6, count=2000, samples=400_000):
"""Stimulus-to-response times (s) for every stimulus pulse in one 48 MS/s capture."""
stim = bp.gpio(stim_la, "output", level=0)
stim.pulse(width, count=count) # 2000 pulses, 100 µs apart: 200 ms of train
cap = bp.capture_la(samples, sample_rate_hz=48e6, trigger=Trigger(stim_la, "rising"))
rises = cap.edge_times(stim_la, "rising")
answers = cap.edge_times(resp_la, "both")
times = []
for t in rises:
later = [a for a in answers if a >= t]
if later and later[0] - t < width * 2: # an answer before the next stimulus
times.append(later[0] - t)
time.sleep(count * 2 * width) # let the train finish before the next one
return times
times = response_times(bp, STIM, RESP)
times.sort()
p99 = times[int(len(times) * 0.99) - 1]
print(f"n={len(times)} median={statistics.median(times) * 1e9:.0f} ns "
f"p99={p99 * 1e9:.0f} ns max={times[-1] * 1e9:.0f} ns")The train has to outlast the round trip of the capture command (a few milliseconds on the LAN), which is why it's 200 ms long. The 400,000-sample capture covers about 8 ms of it, roughly 80 stimulus edges per capture; run a handful of captures to get a few hundred events.
Two things to check before trusting the numbers. The response pin must not be driven by the pod: mark it as a board output in the wiring profile and the pod refuses to drive it. And if the handler toggles the pin, use to_edge="both" or pair rising edges with both edges, as above, since every other answer is a falling edge.
Make it a test
The measurement turns into a pytest test that writes its numbers next to the commit and compares them to a baseline you keep in the repository:
import json, os, pathlib
BASELINE = pathlib.Path(__file__).parent / "timing_baseline.json"
def test_irq_response_time(benchpod):
times = []
for _ in range(5):
times += response_times(benchpod, STIM, RESP)
times.sort()
result = {
"commit": os.environ.get("GITHUB_SHA", "local"),
"n": len(times),
"median_ns": round(statistics.median(times) * 1e9),
"p99_ns": round(times[int(len(times) * 0.99) - 1] * 1e9),
"max_ns": round(times[-1] * 1e9),
}
pathlib.Path("timing.json").write_text(json.dumps(result, indent=2))
assert result["n"] >= 300, "the board missed stimulus pulses"
base = json.loads(BASELINE.read_text())
assert result["median_ns"] <= base["median_ns"] * 1.20, result
assert result["p99_ns"] <= base["p99_ns"] * 1.30, result
assert result["max_ns"] <= base["deadline_ns"], resultThree limits, for three different failures:
- Median catches the handler that does more work than it used to.
- p99 catches new jitter: a priority change, a longer critical section somewhere else.
- A hard deadline on the maximum is the number the product actually needs. Drift inside the margins is allowed; crossing the deadline never is.
Upload timing.json as a build artifact in GitHub Actions and every commit carries its own latency figures. When a number moves, you know which commit moved it, and updating timing_baseline.json becomes a reviewed change instead of something nobody noticed. The workflow side (the pod lease, OIDC, no stored secrets) is in Running Hardware CI with GitHub Actions.
Beyond interrupt latency
The same pattern measures anything with a cause and an effect on two pins:
- Boot time: from releasing reset to the "ready" GPIO, with the reset line captured too.
- Watchdog timeout: stop the heartbeat input and time how long until the board resets.
- Control loop period and jitter:
cap.pulse_widths()andcap.frequency()on a PWM output. - Bus turnaround: from the end of an I2C or SPI command the pod sent to the board's interrupt line.
The capture helpers are documented in the pytest docs, and the MCP server exposes gpio_pulse, capture_la and la_timing, so an agent can run the same measurement when you ask it why the board feels slow.