]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests: kvm/x86: Add the helper function create_pmu_event_filter
authorAaron Lewis <aaronlewis@google.com>
Tue, 17 May 2022 05:12:37 +0000 (05:12 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 20 May 2022 11:06:55 +0000 (07:06 -0400)
Add a helper function that creates a pmu event filter given an event
list.  Currently, a pmu event filter can only be created with the same
hard coded event list.  Add a way to create one given a different event
list.

Also, rename make_pmu_event_filter to alloc_pmu_event_filter to clarify
it's purpose given the introduction of create_pmu_event_filter.

No functional changes intended.

Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Message-Id: <20220517051238.2566934-2-aaronlewis@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c

index 0d06ffa95d9d4cdba158decf53bd17de479092f4..30c1a5804210c33a53c1909cb01a8c4c7996052b 100644 (file)
@@ -208,7 +208,7 @@ static bool sanity_check_pmu(struct kvm_vm *vm)
        return success;
 }
 
-static struct kvm_pmu_event_filter *make_pmu_event_filter(uint32_t nevents)
+static struct kvm_pmu_event_filter *alloc_pmu_event_filter(uint32_t nevents)
 {
        struct kvm_pmu_event_filter *f;
        int size = sizeof(*f) + nevents * sizeof(f->events[0]);
@@ -220,19 +220,29 @@ static struct kvm_pmu_event_filter *make_pmu_event_filter(uint32_t nevents)
        return f;
 }
 
-static struct kvm_pmu_event_filter *event_filter(uint32_t action)
+
+static struct kvm_pmu_event_filter *
+create_pmu_event_filter(const uint64_t event_list[],
+                       int nevents, uint32_t action)
 {
        struct kvm_pmu_event_filter *f;
        int i;
 
-       f = make_pmu_event_filter(ARRAY_SIZE(event_list));
+       f = alloc_pmu_event_filter(nevents);
        f->action = action;
-       for (i = 0; i < ARRAY_SIZE(event_list); i++)
+       for (i = 0; i < nevents; i++)
                f->events[i] = event_list[i];
 
        return f;
 }
 
+static struct kvm_pmu_event_filter *event_filter(uint32_t action)
+{
+       return create_pmu_event_filter(event_list,
+                                      ARRAY_SIZE(event_list),
+                                      action);
+}
+
 /*
  * Remove the first occurrence of 'event' (if any) from the filter's
  * event list.