Page MenuHomeFreeBSD

hwpmc: Add support for AMD-only IRPERF in hwpmc PERF class
Needs RevisionPublic

Authored by anascime_amd.com on Thu, Sep 10, 2:36 AM.
Tags
None
Referenced Files
F171955503: D59554.diff
Mon, Sep 14, 9:57 PM
Unknown Object (File)
Sun, Sep 13, 4:46 AM
Unknown Object (File)
Sat, Sep 12, 5:05 PM
Unknown Object (File)
Fri, Sep 11, 2:01 PM
Unknown Object (File)
Thu, Sep 10, 11:55 PM
Unknown Object (File)
Thu, Sep 10, 5:08 PM
Unknown Object (File)
Thu, Sep 10, 4:59 PM
Unknown Object (File)
Thu, Sep 10, 4:35 PM
Subscribers

Details

Summary

The IRPERF MSR counter (0xc00000e9) exposes an instructions-retired count
when read. Its support is advertised through CPUID leaf 0x80000008 EBX bit 1.
If this bit is set, the CPU supports the IRPERF MSR. For it to be used
by the system, bit 30 of the HWCR MSR (0xC0010015) needs to be enabled.

This patch checks for availability of the feature and enables the bit. If
the feature is available, the hwpmc PERF class detects its presence and
registers a third PERF MSR counter that allows hwpmc users to measure
instructions retired using IRPERF. This is AMD-only, as Intel does not
support IRPERF.

Due to erratum #1054 affecting AMD Zen 1 before model 30h, IRPERF is only
enabled for AMD Zen 1 model 30h onwards and later microarchitectures. This
commit also implements a validation step to make sure the IRPERF counter
is actually incrementing; otherwise, the feature is not enabled. This
guarantees it is working as expected before being made available to the
system and users.

To support this, the perf_pmcdesc[] structure changed from being
statically initialized with 2 entries (MPERF/APERF) to being populated
dynamically. If both MPERF/APERF and IRPERF are supported, the structure
will contain three entries: MPERF, APERF, and IRPERF. Each entry now also
carries its own MSR address and PMC event, so perf_read_pmc() reads the
MSR to use from the matching perf_pmcdesc[] entry at runtime instead of
switching over a fixed set of row indices.

Definitions for the features available on the HWCR MSR did not previously
exist. This commit adds macros for those features, including
HWCR_IRPERFEN. The MSR definition for MSR_IRPERF was also missing and has
now been added.

This commit also updates the manual page accordingly.

Signed-off-by: Anderson Nascimento <anascime@amd.com>
Sponsored by: AMD

Diff Detail

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

Event Timeline

anascime_amd.com retitled this revision from Add support for IRPERF in hwpmc PERF class to hwpmc: Add support for IRPERF in hwpmc PERF class.Thu, Sep 10, 2:42 AM
anascime_amd.com retitled this revision from hwpmc: Add support for IRPERF in hwpmc PERF class to hwpmc: Add support for AMD-only IRPERF in hwpmc PERF class.
anascime_amd.com edited the summary of this revision. (Show Details)
sys/x86/include/specialreg.h
131

Here "HWCR_EFFRFREQCNTMWAIT" should be "HWCR_EFFFREQCNTMWAIT". There's an extra "R". I'll fix this during the reviewing process.

ziaee requested changes to this revision.Thu, Sep 10, 2:33 PM

Hey! Thanks for tagging me. Doc changes looks pretty good, few ideas:

lib/libpmc/pmc.perf.3
11–12

Nd is the "document description". It should be one line. If possible it's better to have it as one rendered line less than 80 columns. It doesn't need to tell them everything, it just needs to tell them if this is the manual they're looking for, and have the correct search keywords. It should definitely not be two lines, I suggest this, which will render like so:

pmc.perf(3) - measurements using the MPERF/APERF/IRPERF frequency counters

105

Nit: project uses serial commas per FreeBSD Documentation Primer

188–191

I wouldnt add these lines

This revision now requires changes to proceed.Thu, Sep 10, 2:33 PM