The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Jim Mattson <jmattson@google.com>
Cc: Zide Chen <zide.chen@intel.com>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mingwei Zhang <mizhang@google.com>,
	Das Sandipan <Sandipan.Das@amd.com>,
	Shukla Manali <Manali.Shukla@amd.com>,
	Falcon Thomas <thomas.falcon@intel.com>,
	Xudong Hao <xudong.hao@intel.com>
Subject: Re: [PATCH v6 8/8] KVM: selftests: Add PERF_METRICS and fixed counter 3 tests
Date: Mon, 13 Jul 2026 15:11:51 +0800	[thread overview]
Message-ID: <212b058b-5804-4a00-a95a-67f58546fd9a@linux.intel.com> (raw)
In-Reply-To: <CALMp9eTs1A73DUDQwO_mHDQF8UfJQG2B_GgJczdu2uxdazG+KQ@mail.gmail.com>


On 7/10/2026 11:22 PM, Jim Mattson wrote:
> On Fri, Jul 10, 2026 at 1:08 AM Mi, Dapeng <dapeng1.mi@linux.intel.com> wrote:
>>
>> On 7/9/2026 8:35 PM, Jim Mattson wrote:
>>> On Mon, Jun 29, 2026 at 7:36 PM Mi, Dapeng <dapeng1.mi@linux.intel.com> wrote:
>>>> On 6/30/2026 7:19 AM, Zide Chen wrote:
>>>>> Add a test case to exercise IA32_PERF_METRICS, i.e. architectural
>>>>> support for Topdown (TMA) Level 1 metrics, enumerated by
>>>>> IA32_PERF_CAPABILITIES[15].
>>>>>
>>>>> Only check for non-zero metrics, as they are derived and depend on
>>>>> the workload, CPU model, and host scheduling, making precise
>>>>> expectations fragile.
>>>>>
>>>>> Extend the PMU selftest to cover Intel fixed counter 3 by bumping
>>>>> MAX_NR_FIXED_COUNTERS to 4 and validating basic functionality.
>>>>>
>>>>> Signed-off-by: Zide Chen <zide.chen@intel.com>
>>>>> ---
>>>>> ...
>>>>> +static void __guest_test_perf_metrics(void)
>>>>> +{
>>>>> +     int retiring, bad_spec, fe_bound, be_bound, sum;
>>>>> +     u64 global_ctrl, metrics;
>>>>> +
>>>>> +     if ((guest_get_pmu_version() < 2) ||    /* Does guest have GLOBAL_CTRL? */
>>>>> +         !this_cpu_has(X86_FEATURE_PDCM) ||
>>>>> +         !(rdmsr(MSR_IA32_PERF_CAPABILITIES) & PERF_CAP_PERF_METRICS))
>>>>> +             return;
>>>>> +
>>>>> +     wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, 0);
>>>>> +     wrmsr(MSR_CORE_PERF_FIXED_CTR3, 0);
>>>>> +     wrmsr(MSR_PERF_METRICS, 0);
>>>>> +
>>>>> +     /* Enable fixed ctr3 (TOPDOWN.SLOTS) and PERF_METRICS. */
>>>>> +     wrmsr(MSR_CORE_PERF_FIXED_CTR_CTRL, FIXED_PMC_CTRL(3, FIXED_PMC_KERNEL));
>>>>> +     global_ctrl = FIXED_PMC_GLOBAL_CTRL_ENABLE(3) |
>>>>> +                   PERF_METRICS_GLOBAL_CTRL_ENABLE;
>>>>> +
>>>>> +     GUEST_RUN_PAYLOAD(MSR_CORE_PERF_GLOBAL_CTRL, global_ctrl, "");
>>>>> +
>>>>> +     /* Check test results. */
>>>>> +     metrics = rdmsr(MSR_PERF_METRICS);
>>>> Could we use rdpmc instead of rdmsr here? rdpmc is a preferred way to read
>>>> counter value.
>>> This is in-guest code, so the unintercepted RDMSR will be much faster
>>> than the emulated RDPMC.
>>>
>>> Should we rethink that preference, or add hardware support for
>>> selective RDPMC intercepts?
>> Hmm, in current most cases, rdpmc and rdmsr should share consistent
>> interception configuration for PERF_METRICS except host and guest have
>> different counters bitmap.
> I'm assuming that Intel wants to reserve the right to cover other
> resources with RDPMC in the future. Unless we have some way of
> determining, through a hardware enumeration, that all readable
> resources contain guest state, then we will akways have to intercept
> RDPMC.

rdpmc is the preferable way to read PMU counters since the better
performance than rdmsr, and most of current code regardless of kernel or
user-space already use rdpmc to read PMC counters. If we set the rdpmc to
interception by default, then it may cause extra performance hit.

Currently I didn't hear there is any plan to extend the rdpmc to support
more types for Intel platforms ...


>
> If I'm wrong, and Intel is willing to guarantee that no new resources
> will ever be added, then we can let the guest execute RDPMC natively,
> when the guest owns all of the counters and  PERF_METRICS.
>

      reply	other threads:[~2026-07-13  7:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 23:19 [PATCH V6 0/8] KVM: x86/pmu: Add hardware Topdown metrics support Zide Chen
2026-06-29 23:19 ` [PATCH v6 1/8] KVM: x86/pmu: Do not map fixed counters >= 3 to generic perf events Zide Chen
2026-06-30  2:13   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 2/8] KVM: x86/pmu: Support Intel fixed counter 3 on mediated vPMU Zide Chen
2026-06-30  2:16   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 3/8] KVM: x86/pmu: Rename and move vcpu_get_perf_capabilities() to pmu.h Zide Chen
2026-06-30  2:18   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 4/8] KVM: x86/pmu: Snapshot host IA32_PERF_CAPABILITIES in kvm_host Zide Chen
2026-06-30  2:19   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 5/8] KVM: x86/pmu: Support PERF_METRICS MSR in mediated vPMU Zide Chen
2026-06-30  2:20   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 6/8] KVM: x86/pmu: Move RDPMC emulation into per-vendor callbacks Zide Chen
2026-06-30  2:23   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 7/8] KVM: x86/pmu: Emulate RDPMC on performance metrics Zide Chen
2026-06-30  2:23   ` Mi, Dapeng
2026-06-29 23:19 ` [PATCH v6 8/8] KVM: selftests: Add PERF_METRICS and fixed counter 3 tests Zide Chen
2026-06-30  2:36   ` Mi, Dapeng
2026-07-09 12:35     ` Jim Mattson
2026-07-10  8:08       ` Mi, Dapeng
2026-07-10 14:52         ` Chen, Zide
2026-07-13  6:57           ` Mi, Dapeng
2026-07-10 15:22         ` Jim Mattson
2026-07-13  7:11           ` Mi, Dapeng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=212b058b-5804-4a00-a95a-67f58546fd9a@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=Manali.Shukla@amd.com \
    --cc=Sandipan.Das@amd.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mizhang@google.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=thomas.falcon@intel.com \
    --cc=xudong.hao@intel.com \
    --cc=zide.chen@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox