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
F168413778: D59230.id.diff
Fri, Aug 28, 3:54 AM
F168401486: D59230.diff
Fri, Aug 28, 1:39 AM
F168382028: D59230.diff
Thu, Aug 27, 9:45 PM
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