From: Sean Christopherson <seanjc@google.com>
To: Mingwei Zhang <mizhang@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org, Like Xu <likexu@tencent.com>,
Jim Mattson <jmattson@google.com>
Subject: Re: [PATCH] perf/x86: Don't enforce minimum period for KVM guest-only events
Date: Tue, 7 Nov 2023 15:02:43 -0800 [thread overview]
Message-ID: <ZUrCE9j1Gvw4zacY@google.com> (raw)
In-Reply-To: <ZUqSQKHwvKQs7_qA@google.com>
On Tue, Nov 07, 2023, Mingwei Zhang wrote:
> On Tue, Nov 07, 2023, Sean Christopherson wrote:
> > arch/x86/events/core.c | 21 +++++++++++++++------
> > 1 file changed, 15 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> > index 40ad1425ffa2..f8a8a4ea4d47 100644
> > --- a/arch/x86/events/core.c
> > +++ b/arch/x86/events/core.c
> > @@ -1388,16 +1388,25 @@ int x86_perf_event_set_period(struct perf_event *event)
> > hwc->last_period = period;
> > ret = 1;
> > }
> > - /*
> > - * Quirk: certain CPUs dont like it if just 1 hw_event is left:
> > - */
> > - if (unlikely(left < 2))
> > - left = 2;
> >
> > if (left > x86_pmu.max_period)
> > left = x86_pmu.max_period;
> >
> > - static_call_cond(x86_pmu_limit_period)(event, &left);
> > + /*
> > + * Exempt KVM guest events from the minimum period requirements. It's
> > + * the guest's responsibility to ensure it can make forward progress,
> > + * and it's KVM's responsibility to configure an appropriate "period"
> > + * to correctly virtualize overflow for the guest's PMCs.
> > + */
> > + if (!event->attr.exclude_host) {
> > + /*
> > + * Quirk: certain CPUs dont like it if just 1 event is left:
> > + */
> > + if (unlikely(left < 2))
> > + left = 2;
> > +
> > + static_call_cond(x86_pmu_limit_period)(event, &left);
> > + }
> >
> > this_cpu_write(pmc_prev_left[idx], left);
> >
>
> Nice one. I am curious how you tested this one? I would like to
> reproduce that one on my side.
The check_emulated_instr() sub-test in KVM-Unit-Tests's x86/pmu.c fails when run
with "my" (which is really yours) fix for the KVM's handling of emulated PMC
events[*]. If KVM synthesizes an "instructions retired" event that bumps the
PMC to all ones, i.e. -1 for all intents and purposes, the test fails because
KVM creates a sample_period of '1', but perf programs a period of '2'.
I suspect a very simple test of writing -1 to a PMC from the guest would exhibit
the same behavior.
[*] https://lkml.kernel.org/r/ZUWAg3WP2XESCAR4%40google.com
next prev parent reply other threads:[~2023-11-07 23:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 18:36 [PATCH] perf/x86: Don't enforce minimum period for KVM guest-only events Sean Christopherson
2023-11-07 19:38 ` Mingwei Zhang
2023-11-07 23:02 ` Sean Christopherson [this message]
2023-11-07 23:47 ` Mingwei Zhang
2023-11-17 10:32 ` Peter Zijlstra
2023-11-29 1:33 ` Sean Christopherson
2023-11-29 11:20 ` Peter Zijlstra
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=ZUrCE9j1Gvw4zacY@google.com \
--to=seanjc@google.com \
--cc=acme@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=jmattson@google.com \
--cc=likexu@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mizhang@google.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).