Page MenuHomeFreeBSD

hwpmc: stop process PMCs on exit with PerfMonV2
Needs ReviewPublic

Authored by afscoelho_gmail.com on Tue, Sep 29, 7:20 PM.
Tags
None
Referenced Files
F174085101: D60141.diff
Wed, Sep 30, 12:40 PM
F174024699: D60141.id188087.diff
Wed, Sep 30, 1:35 AM
F174021521: D60141.diff
Wed, Sep 30, 1:03 AM
F174004299: D60141.id188087.diff
Tue, Sep 29, 10:10 PM
F174004210: D60141.diff
Tue, Sep 29, 10:09 PM
F174003711: D60141.diff
Tue, Sep 29, 10:04 PM
F174001208: D60141.id.diff
Tue, Sep 29, 9:37 PM
F173999295: D60141.diff
Tue, Sep 29, 9:15 PM
Subscribers

Details

Summary

Since 9d3064010590, pmc_process_exit() calls pmc_process_csw_stop_all()
first. That clears pps_cpustate for every virtual PMC on the CPU, so the
exit loop then skips the stop and the final read.

On AMD PerfMonV2 this has two effects:

  • The count from the last time slice is lost. A process that never switches out before exit reports 0 with pmcstat -p.
  • The EVSEL enable bit stays set. After kldunload, the next kldload sees it and says "PMCs maybe in use by firmware!".

When the class has pcd_stop_all, always stop and read the PMC, as
pmc_process_csw_out() already does.

Fixes: 9d3064010590 ("hwpmc_amd: add PerfMonV2 global-control path")
Sponsored by: AMD

Test Plan

On a Zen3 system (kern.hwpmc.amd_perfmon_v2=1):

pmcstat -p instructions sh -c 'i=0; while [ $i -lt 300000 ]; do i=$((i+1)); done'

Before: prints 0. After 25 runs, 25 PERF_CTL MSRs still have EN (bit 22)
set, and reloading hwpmc loads only the SOFT class.

After: prints about 4.65e9, the same as a system-mode PMC for the same
work. No PERF_CTL has EN set, and hwpmc reloads with all classes.

Diff Detail

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