From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Sandipan Das <sandipan.das@amd.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Jim Mattson <jmattson@google.com>,
Mingwei Zhang <mizhang@google.com>,
Xiong Zhang <xiong.y.zhang@intel.com>,
Zhenyu Wang <zhenyuw@linux.intel.com>,
Like Xu <like.xu.linux@gmail.com>,
Jinrong Liang <cloudliang@tencent.com>,
Dapeng Mi <dapeng1.mi@intel.com>,
ravi.bangoria@amd.com, manali.shukla@amd.com,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Patch v5 12/18] x86: pmu: Improve instruction and branches events verification
Date: Thu, 4 Jul 2024 20:21:15 +0800 [thread overview]
Message-ID: <a00be0fa-1dbc-4873-85f9-958f5ea0ad7a@linux.intel.com> (raw)
In-Reply-To: <6d512a14-ace1-41a3-801e-0beb41425734@amd.com>
On 7/4/2024 4:02 PM, Sandipan Das wrote:
> On 7/3/2024 3:27 PM, Dapeng Mi wrote:
>> If HW supports GLOBAL_CTRL MSR, enabling and disabling PMCs are moved in
>> __precise_count_loop(). Thus, instructions and branches events can be
>> verified against a precise count instead of a rough range.
>>
>> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
>> ---
>> x86/pmu.c | 31 +++++++++++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
>>
>> diff --git a/x86/pmu.c b/x86/pmu.c
>> index d005e376..ffb7b4a4 100644
>> --- a/x86/pmu.c
>> +++ b/x86/pmu.c
>> @@ -19,6 +19,11 @@
>> #define EXPECTED_INSTR 17
>> #define EXPECTED_BRNCH 5
>>
>> +
>> +/* Enable GLOBAL_CTRL + disable GLOBAL_CTRL instructions */
>> +#define EXTRA_INSTRNS (3 + 3)
>> +#define LOOP_INSTRNS (N * 10 + EXTRA_INSTRNS)
>> +#define LOOP_BRANCHES (N)
>> #define LOOP_ASM(_wrmsr) \
>> _wrmsr "\n\t" \
>> "mov %%ecx, %%edi; mov %%ebx, %%ecx;\n\t" \
>> @@ -122,6 +127,24 @@ static inline void loop(u64 cntrs)
>> __precise_loop(cntrs);
>> }
>>
>> +static void adjust_events_range(struct pmu_event *gp_events,
>> + int instruction_idx, int branch_idx)
>> +{
>> + /*
>> + * If HW supports GLOBAL_CTRL MSR, enabling and disabling PMCs are
>> + * moved in __precise_loop(). Thus, instructions and branches events
>> + * can be verified against a precise count instead of a rough range.
>> + */
>> + if (this_cpu_has_perf_global_ctrl()) {
> This causes some intermittent failures on AMD processors using PerfMonV2
> due to variance in counts. This probably has to do with the way instructions
> leading to a VM-Entry or VM-Exit are accounted when counting retired
> instructions and branches. Adding the following change makes all the tests
> pass again.
Thanks to verify on AMD platforms. Would add it in next version.
>
> diff --git a/x86/pmu.c b/x86/pmu.c
> index 0658a1c1..09a34a3f 100644
> --- a/x86/pmu.c
> +++ b/x86/pmu.c
> @@ -222,7 +222,7 @@ static void adjust_events_range(struct pmu_event *gp_events,
> * moved in __precise_loop(). Thus, instructions and branches events
> * can be verified against a precise count instead of a rough range.
> */
> - if (this_cpu_has_perf_global_ctrl()) {
> + if (pmu.is_intel && this_cpu_has_perf_global_ctrl()) {
> /* instructions event */
> gp_events[instruction_idx].min = LOOP_INSTRNS;
> gp_events[instruction_idx].max = LOOP_INSTRNS;
>
>
>> + /* instructions event */
>> + gp_events[instruction_idx].min = LOOP_INSTRNS;
>> + gp_events[instruction_idx].max = LOOP_INSTRNS;
>> + /* branches event */
>> + gp_events[branch_idx].min = LOOP_BRANCHES;
>> + gp_events[branch_idx].max = LOOP_BRANCHES;
>> + }
>> +}
>> +
>> volatile uint64_t irq_received;
>>
>> static void cnt_overflow(isr_regs_t *regs)
>> @@ -823,6 +846,9 @@ static void check_invalid_rdpmc_gp(void)
>>
>> int main(int ac, char **av)
>> {
>> + int instruction_idx;
>> + int branch_idx;
>> +
>> setup_vm();
>> handle_irq(PMI_VECTOR, cnt_overflow);
>> buf = malloc(N*64);
>> @@ -836,13 +862,18 @@ int main(int ac, char **av)
>> }
>> gp_events = (struct pmu_event *)intel_gp_events;
>> gp_events_size = sizeof(intel_gp_events)/sizeof(intel_gp_events[0]);
>> + instruction_idx = INTEL_INSTRUCTIONS_IDX;
>> + branch_idx = INTEL_BRANCHES_IDX;
>> report_prefix_push("Intel");
>> set_ref_cycle_expectations();
>> } else {
>> gp_events_size = sizeof(amd_gp_events)/sizeof(amd_gp_events[0]);
>> gp_events = (struct pmu_event *)amd_gp_events;
>> + instruction_idx = AMD_INSTRUCTIONS_IDX;
>> + branch_idx = AMD_BRANCHES_IDX;
>> report_prefix_push("AMD");
>> }
>> + adjust_events_range(gp_events, instruction_idx, branch_idx);
>>
>> printf("PMU version: %d\n", pmu.version);
>> printf("GP counters: %d\n", pmu.nr_gp_counters);
>
next prev parent reply other threads:[~2024-07-04 12:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 9:56 [Patch v5 00/18] pmu test bugs fix and improvements Dapeng Mi
2024-07-03 9:56 ` [Patch v5 01/18] x86: pmu: Remove duplicate code in pmu_init() Dapeng Mi
2024-07-03 9:56 ` [Patch v5 02/18] x86: pmu: Remove blank line and redundant space Dapeng Mi
2024-07-03 9:56 ` [Patch v5 03/18] x86: pmu: Refine fixed_events[] names Dapeng Mi
2024-07-03 9:56 ` [Patch v5 04/18] x86: pmu: Fix the issue that pmu_counter_t.config crosses cache line Dapeng Mi
2024-07-03 9:56 ` [Patch v5 05/18] x86: pmu: Enlarge cnt[] length to 48 in check_counters_many() Dapeng Mi
2024-07-03 9:57 ` [Patch v5 06/18] x86: pmu: Add asserts to warn inconsistent fixed events and counters Dapeng Mi
2024-08-22 18:22 ` Jim Mattson
2024-08-26 6:56 ` Mi, Dapeng
2024-08-26 18:36 ` Jim Mattson
2024-08-27 0:41 ` Mi, Dapeng
2024-07-03 9:57 ` [Patch v5 07/18] x86: pmu: Fix cycles event validation failure Dapeng Mi
2024-07-03 9:57 ` [Patch v5 08/18] x86: pmu: Use macro to replace hard-coded branches event index Dapeng Mi
2024-07-03 9:57 ` [Patch v5 09/18] x86: pmu: Use macro to replace hard-coded ref-cycles " Dapeng Mi
2024-07-03 9:57 ` [Patch v5 10/18] x86: pmu: Use macro to replace hard-coded instructions " Dapeng Mi
2024-07-03 9:57 ` [Patch v5 11/18] x86: pmu: Enable and disable PMCs in loop() asm blob Dapeng Mi
2024-07-03 9:57 ` [Patch v5 12/18] x86: pmu: Improve instruction and branches events verification Dapeng Mi
2024-07-04 8:02 ` Sandipan Das
2024-07-04 12:21 ` Mi, Dapeng [this message]
2024-07-03 9:57 ` [Patch v5 13/18] x86: pmu: Improve LLC misses event verification Dapeng Mi
2024-07-03 9:57 ` [Patch v5 14/18] x86: pmu: Adjust lower boundary of llc-misses event to 0 for legacy CPUs Dapeng Mi
2024-07-03 9:57 ` [Patch v5 15/18] x86: pmu: Add IBPB indirect jump asm blob Dapeng Mi
2024-07-03 9:57 ` [Patch v5 16/18] x86: pmu: Adjust lower boundary of branch-misses event Dapeng Mi
2024-07-03 9:57 ` [Patch v5 17/18] x86: pmu: Optimize emulated instruction validation Dapeng Mi
2024-07-03 9:57 ` [Patch v5 18/18] x86: pmu: Print measured event count if test fails Dapeng Mi
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=a00be0fa-1dbc-4873-85f9-958f5ea0ad7a@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=cloudliang@tencent.com \
--cc=dapeng1.mi@intel.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manali.shukla@amd.com \
--cc=mizhang@google.com \
--cc=pbonzini@redhat.com \
--cc=ravi.bangoria@amd.com \
--cc=sandipan.das@amd.com \
--cc=seanjc@google.com \
--cc=xiong.y.zhang@intel.com \
--cc=zhenyuw@linux.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