Page MenuHomeFreeBSD

hwpmc: add pmc_sample(9), an in-kernel PMU-sampling KPI
Needs ReviewPublic

Authored by nickbanks_netflix.com on Thu, Aug 27, 7:51 PM.
Tags
None
Referenced Files
F170996432: D59230.id.diff
Tue, Sep 8, 2:16 AM
F170953732: D59230.diff
Mon, Sep 7, 8:17 PM
F170945749: D59230.id185239.diff
Mon, Sep 7, 7:03 PM
Unknown Object (File)
Mon, Sep 7, 6:45 AM
Unknown Object (File)
Sun, Sep 6, 8:43 PM
Unknown Object (File)
Sun, Sep 6, 6:33 PM
Unknown Object (File)
Sun, Sep 6, 12:19 PM
Unknown Object (File)
Sat, Sep 5, 5:51 AM
Subscribers

Details

Summary

Add <sys/pmc_sample.h>: an in-kernel KPI for consumers that want raw
PMU sampling callchains without going through pmclog/pmcstat(8). A
consumer registers a callback and requests a per-CPU sampling PMC at a
target frequency; callbacks run from the existing hwpmc sample-delivery
path (NMI context: no sleeping, no malloc(9), no sleepable locks). One
session at a time; no in-tree consumer yet.

Supports Intel (IAF CPU_CLK_UNHALTED.REF, frequency-invariant by
design) and AMD/Hygon (K8 BU_CPU_CLK_UNHALTED). AMD's counter tracks
real core clocks rather than a fixed reference rate, so its reload is
rescaled each interrupt by the live APERF/MPERF ratio to keep the
sampling period accurate across P-state transitions; the same
APERF/MPERF data is also surfaced as an optional effective-frequency
(MHz) field per sample. Both the rescale and the frequency report are
confined to this KPI's own sampler PMCs, so pmcstat(8) sessions are
unaffected.

Also fixes a PMC row leak: the standalone-row disposition counter
wasn't unmarked when pcd_write_pmc()/pcd_start_pmc() failed and left
the row in PMC_STATE_STOPPED rather than PMC_STATE_ALLOCATED.

Sponsored by: Netflix

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76229
Build 73112: arc lint + arc unit

Event Timeline

I'd rather you capture APERF/MPERF/TSC by enabling all the counters but we need below to land.

https://reviews.freebsd.org/D58647

sys/dev/hwpmc/hwpmc_amd.c
79

Even after we remove i386, we still shouldn't break AMD K8 which IIRC doesn't have APERF/MPERF.

sys/dev/hwpmc/hwpmc_mod.c
4857

If there's not a reason to include this with each sample I'd rather we just add the APERF/MPERF data from the new counters in the diff I listed in general comments.

5635

hwpmc_mod.c is already giant can we make a new file like hwpmc_kapi.c or something.

5659

Would be nice to move this into a per-platform function. There's a main file per architecture that's has function names that are the same across architectures and you can just move it in there. Same with the function below.