kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, seanjc@google.com
Subject: Re: [PATCH v4 3/7] kvm: x86/pmu: prepare the pmu event filter for masked events
Date: Wed, 14 Sep 2022 11:25:01 -0700	[thread overview]
Message-ID: <CALMp9eTjVEcay1hYLys=dR5pO+Huhmpr8JjpiEmdng3zp7_5tg@mail.gmail.com> (raw)
In-Reply-To: <20220831162124.947028-4-aaronlewis@google.com>

On Wed, Aug 31, 2022 at 9:21 AM Aaron Lewis <aaronlewis@google.com> wrote:
>
> Create an internal representation for filter events to abstract the
> events userspace uses from the events the kernel uses.  That will allow
> the kernel to use a common event and a common code path between the
> different types of filter events used in userspace once masked events
> are introduced.
>
> No functional changes intended
>
> Signed-off-by: Aaron Lewis <aaronlewis@google.com>
> ---
>  arch/x86/kvm/pmu.c | 118 ++++++++++++++++++++++++++++++++-------------
>  arch/x86/kvm/pmu.h |  16 ++++++
>  2 files changed, 100 insertions(+), 34 deletions(-)
>
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index e7d94e6b7f28..50a36cc5bfd0 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -239,6 +239,19 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
>         return true;
>  }
>
> +static inline u16 get_event_select(u64 eventsel)
> +{
> +       u64 e = eventsel &
> +               static_call(kvm_x86_pmu_get_eventsel_event_mask)();
> +
> +       return (e & ARCH_PERFMON_EVENTSEL_EVENT) | ((e >> 24) & 0xF00ULL);
> +}
> +
> +static inline u8 get_unit_mask(u64 eventsel)
> +{
> +       return (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
> +}
> +
>  static int cmp_u64(const void *pa, const void *pb)
>  {
>         u64 a = *(u64 *)pa;
> @@ -247,53 +260,63 @@ static int cmp_u64(const void *pa, const void *pb)
>         return (a > b) - (a < b);
>  }
>
> -static inline u64 get_event_select(u64 eventsel)
> +static u64 *find_filter_entry(struct kvm_pmu_event_filter *filter, u64 key)
> +{
> +       return bsearch(&key, filter->events, filter->nevents,
> +                         sizeof(filter->events[0]), cmp_u64);
> +}
> +
> +static bool filter_contains_match(struct kvm_pmu_event_filter *filter,
> +                                 u64 eventsel)
> +{
> +       u16 event_select = get_event_select(eventsel);
> +       u8 unit_mask = get_unit_mask(eventsel);
> +       u64 key;
> +
> +       key = KVM_PMU_ENCODE_FILTER_ENTRY(event_select, unit_mask);
> +       if (find_filter_entry(filter, key))
> +               return true;
> +       return false;

Perhaps just:
        return find_filter_entry(filter, key);

Reviewed-by: Jim Mattson <jmattson@google.com>

  reply	other threads:[~2022-09-14 18:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 16:21 [PATCH v4 0/7] Introduce and test masked events Aaron Lewis
2022-08-31 16:21 ` [PATCH v4 1/7] kvm: x86/pmu: Correct the mask used in a pmu event filter lookup Aaron Lewis
2022-09-14 18:15   ` Jim Mattson
2022-08-31 16:21 ` [PATCH v4 2/7] kvm: x86/pmu: Remove invalid raw events from the pmu event filter Aaron Lewis
2022-09-14 18:17   ` Jim Mattson
2022-08-31 16:21 ` [PATCH v4 3/7] kvm: x86/pmu: prepare the pmu event filter for masked events Aaron Lewis
2022-09-14 18:25   ` Jim Mattson [this message]
2022-08-31 16:21 ` [PATCH v4 4/7] kvm: x86/pmu: Introduce masked events to the pmu event filter Aaron Lewis
2022-09-14 18:45   ` Jim Mattson
2022-08-31 16:21 ` [PATCH v4 5/7] selftests: kvm/x86: Add flags when creating a " Aaron Lewis
2022-09-14 18:47   ` Jim Mattson
2022-08-31 16:21 ` [PATCH v4 6/7] selftests: kvm/x86: Add testing for KVM_SET_PMU_EVENT_FILTER Aaron Lewis
2022-09-14 19:00   ` Jim Mattson
2022-08-31 16:21 ` [PATCH v4 7/7] selftests: kvm/x86: Test masked events Aaron Lewis
2022-09-14 20:12   ` Jim Mattson
2022-09-20 15:24     ` Aaron Lewis

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='CALMp9eTjVEcay1hYLys=dR5pO+Huhmpr8JjpiEmdng3zp7_5tg@mail.gmail.com' \
    --to=jmattson@google.com \
    --cc=aaronlewis@google.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;
as well as URLs for NNTP newsgroup(s).