public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Like Xu <like.xu.linux@gmail.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] x86/pmu: Reset the expected count of the fixed counter 0 when i386
Date: Tue, 2 Aug 2022 15:05:05 +0800	[thread overview]
Message-ID: <9dce3dbb-ffa1-687a-d1c4-8234d1bf6cfb@gmail.com> (raw)
In-Reply-To: <Yuf0uJeN5n3AvXPg@google.com>

On 1/8/2022 11:43 pm, Sean Christopherson wrote:
> Not directly related to this patch...
> 
> Unless I've missed something, every invocation of start_event() and measure() first
> sets evt.count=0.  Rather than force every caller to ensure count is zeroed, why not
> zero the count during start_event() and then drop all of the manual zeroing?
> 

None object to this idea, after all, there is obvious redundancy here.

> diff --git a/x86/pmu.c b/x86/pmu.c
> index 01be1e90..ef804272 100644
> --- a/x86/pmu.c
> +++ b/x86/pmu.c
> @@ -141,7 +141,7 @@ static void global_disable(pmu_counter_t *cnt)
> 
>   static void start_event(pmu_counter_t *evt)
>   {
> -    wrmsr(evt->ctr, evt->count);
> +    wrmsr(evt->ctr, 0);

Now we have to fix the last call to measure() in check_counter_overflow(), since 
it will
also call start_event() after it has been modified and in that case, the 
requested high count
has to be passed in from another function parameter.

Also, the naming of start_event() does not imply that the counter will be set to 
zero implicitly,
it just lets a counter continue to run, not caring about the current value of 
the counter,
which is more flexible.

I may try to do that on the test-cases of AMD vPMU, to help verify the gain of 
your idea.

>       if (is_gp(evt))
>              wrmsr(MSR_P6_EVNTSEL0 + event_to_global_idx(evt),
>                              evt->config | EVNTSEL_EN);
> 
> 
> Accumulating counts can be handled by reading the current count before start_event(),
> and doing something like stuffing a high count to test an edge case could be handled
> by an inner helper, e.g. by adding __start_event().

  reply	other threads:[~2022-08-02  7:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-01 13:18 [kvm-unit-tests PATCH] x86/pmu: Reset the expected count of the fixed counter 0 when i386 Like Xu
2022-08-01 15:43 ` Sean Christopherson
2022-08-02  7:05   ` Like Xu [this message]
2022-08-02 14:09     ` Sean Christopherson

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=9dce3dbb-ffa1-687a-d1c4-8234d1bf6cfb@gmail.com \
    --to=like.xu.linux@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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