Skip to content

KVM: x86/pmu: Add hardware Topdown metrics support

Zide Chen kvm lkml sashiko-reviews 9 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest12 patches 24 repliesIn review
  2. v88 patches 11 repliesSuperseded
  3. v79 patches 13 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v68 patches44 repliesSuperseded
v57 patches5 repliesSuperseded
v44 patches5 repliesSuperseded
v34 patches3 repliesSuperseded
v24 patches9 repliesSuperseded
v13 patches5 repliesSuperseded

Patches in v9 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12KVM: x86/pmu: Do not map fixed counters >= 3 to generic perf eventsarch/x86/kvm/vmx/pmu_intel.c+8 -60 replies
2/12KVM: x86/pmu: Support Intel fixed counter 3 on mediated vPMUarch/x86/include/asm/kvm_host.h arch/x86/kvm/msrs.c arch/x86/kvm/pmu.c+21 -40 replies
3/12KVM: x86/pmu: Rename and move vcpu_get_perf_capabilities() to pmu.harch/x86/kvm/pmu.h arch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/vmx/pmu_intel.h+12 -140 replies
4/12KVM: x86/pmu: Snapshot host IA32_PERF_CAPABILITIES in kvm_hostarch/x86/include/asm/kvm_host.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+7 -60 replies
5/12KVM: x86/pmu: Support PERF_METRICS MSR in mediated vPMUarch/x86/include/asm/kvm_host.h arch/x86/include/asm/msr-index.h arch/x86/kvm/msrs.c +5 more+57 -110 replies
6/12KVM: x86/pmu: Move RDPMC emulation into per-vendor callbacksarch/x86/include/asm/kvm-x86-pmu-ops.h arch/x86/kvm/pmu.c arch/x86/kvm/pmu.h +2 more+25 -280 replies
7/12KVM: x86/pmu: Emulate RDPMC on performance metricsarch/x86/kvm/pmu.c arch/x86/kvm/vmx/pmu_intel.c+15 -01 reply
8/12KVM: selftests: Add PERF_METRICS and fixed counter 3 teststools/arch/x86/include/asm/msr-index.h tools/testing/selftests/kvm/include/x86/pmu.h tools/testing/selftests/kvm/x86/pmu_counters_test.c+96 -51 reply
9/12perf/x86: Add INTEL_TD_METRIC_FIELD_{BITS,MASK} constantsarch/x86/events/intel/core.c arch/x86/include/asm/perf_event.h+9 -33 replies
10/12perf/x86: Expose number of Topdown metric events to KVMarch/x86/events/core.c arch/x86/include/asm/perf_event.h+2 -01 reply
11/12KVM: x86/pmu: Reject writes to reserved MSR_PERF_METRICS bitsarch/x86/include/asm/kvm_host.h arch/x86/kvm/pmu.c arch/x86/kvm/vmx/pmu_intel.c+19 -13 replies
12/12KVM: x86/pmu: Support RDPMC Metrics Clear Modearch/x86/include/asm/msr-index.h arch/x86/kvm/vmx/pmu_intel.c arch/x86/kvm/vmx/vmx.c+34 -15 replies

Reviews trailers per patch

9 of 12 patches have a Reviewed-by or Acked-by.

PatchDapeng MiJim MattsonSandipan Das
1/12R-b R-b
2/12R-b
3/12R-b R-b
4/12R-b R-b
5/12
6/12R-b R-b R-b
7/12R-b R-b
8/12R-b
9/12
10/12R-b
11/12R-b
12/12

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v9 thread

Cover letter [PATCH v9 00/12] KVM: x86/pmu: Add hardware Topdown metrics support

Previous revisions were missing two things that are now addressed:

- A previous comment incorrectly claimed that MSR_PERF_METRICS bits [63:32] are ignored on hardware that only implements level-1 metrics; patch 10/12 fixes this by rejecting such writes.

- Patch 11/12 adds support for RDPMC Metrics Clear Mode. Without this feature, for user programs using RDPMC directly, the counter has to be reset explicitly using ioctl:

  ioctl(perf_fd, PERF_EVENT_IOC_RESET, 0);

Tests: besides the tests mentioned on v8 cover letter, tested RDPMC Metrics Clear on a DMR machine, and tested Topdown metrics on nested setup on top of the vPMU support series [1].

perf tool misidentifies "cpu/slots,metrics_clear=1/" as not being the slots event, so it inserts an additional slots event into the group; event scheduling then fails because the group needs fixed counter 3 (SLOTS) twice:

  $ perf stat -e "{cpu/slots,metrics_clear=1/,cpu/topdown-retiring/}" -- sleep 1
    WARNING: events were regrouped to match PMUs
           <not counted>      slots
         <not supported>      cpu/slots,metrics_clear=1/
           <not counted>      cpu/topdown-retiring/

A fix for this perf tool bug is posted at [2].

New patches:
patch 8/12: Add INTEL_TD_METRIC_FIELD_BITS for code cleanup. patch 9/12: perf/x86: Expose number of Topdown metric events to KVM. patch 10/12: Reject writes to reserved MSR_PERF_METRICS bits. patch 11/12: Support RDPMC Metrics Clear Mode.

Minor non-logical changes to existing patches:
patch 5/12: Remove the incorrect comment about writing to PERF_METRICS. patch 7/12: Remove references to Metrics Clear from the changelog.

Patch 11/12 could be folded into patch 5/12, but I kept them separate because patches 1-8 were already well reviewed, and keeping them unchanged should make reviewing v9 easier.

Rebased to kvm-x86/next: 70c944caf570fda2d79baa71435589a8db39f048

v8: https://lore.kernel.org/kvm/[email protected]/
QEMU: https://lore.kernel.org/qemu-devel/[email protected]/

[1] https://lore.kernel.org/kvm/[email protected]/
[2] https://lore.kernel.org/linux-perf-users/[email protected]/T/#t

Dapeng Mi (2):
KVM: x86/pmu: Support Intel fixed counter 3 on mediated vPMU
KVM: x86/pmu: Support PERF_METRICS MSR in mediated vPMU

Mingwei Zhang (1):
KVM: x86/pmu: Snapshot host IA32_PERF_CAPABILITIES in kvm_host

Zide Chen (9):
KVM: x86/pmu: Do not map fixed counters >= 3 to generic perf events
KVM: x86/pmu: Rename and move vcpu_get_perf_capabilities() to pmu.h
KVM: x86/pmu: Move RDPMC emulation into per-vendor callbacks
KVM: x86/pmu: Emulate RDPMC on performance metrics
KVM: selftests: Add PERF_METRICS and fixed counter 3 tests perf/x86: Add INTEL_TD_METRIC_FIELD_{BITS,MASK} constants perf/x86: Expose number of Topdown metric events to KVM
KVM: x86/pmu: Reject writes to reserved MSR_PERF_METRICS bits
KVM: x86/pmu: Support RDPMC Metrics Clear Mode

 arch/x86/events/core.c                        |   1 +
 arch/x86/events/intel/core.c                  |   8 +-
 arch/x86/include/asm/kvm-x86-pmu-ops.h        |   2 +-
 arch/x86/include/asm/kvm_host.h               |   5 +-
 arch/x86/include/asm/msr-index.h              |   2 +
 arch/x86/include/asm/perf_event.h             |   5 +
 arch/x86/kvm/msrs.c                           |  10 +-
 arch/x86/kvm/pmu.c                            |  37 +++--
 arch/x86/kvm/pmu.h                            |  17 ++-
 arch/x86/kvm/svm/pmu.c                        |  13 +-
 arch/x86/kvm/vmx/nested.c                     |   2 +
 arch/x86/kvm/vmx/pmu_intel.c                  | 132 +++++++++++++++---
 arch/x86/kvm/vmx/pmu_intel.h                  |  12 +-
 arch/x86/kvm/vmx/vmx.c                        |  19 ++-
 arch/x86/kvm/x86.c                            |   4 +
 tools/arch/x86/include/asm/msr-index.h        |   1 +
 tools/testing/selftests/kvm/include/x86/pmu.h |   3 +
 .../selftests/kvm/x86/pmu_counters_test.c     |  97 ++++++++++++-
 18 files changed, 303 insertions(+), 67 deletions(-)
Signature · 1 line
2.55.0