perf kvm: Add pointer to 'perf_kvm_stat' in kvm event
authorLeo Yan <leo.yan@linaro.org>
Wed, 15 Mar 2023 14:50:58 +0000 (22:50 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 15 Mar 2023 19:14:04 +0000 (16:14 -0300)
Sometimes, handling kvm events needs to base on global variables, e.g.
when read event counts we need to know the target vcpu ID; the global
variables are stored in structure perf_kvm_stat.

This patch adds add a 'perf_kvm_stat' pointer in kvm event structure,
it is to be used by later refactoring.

Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230315145112.186603-2-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kvm.c
tools/perf/util/kvm-stat.h

index 0172e5b0d26eb558c3eba6d3e9a3bf5bee300f84..3d2560ec6b37df6c93a5327cdf1b26cef424f8ba 100644 (file)
@@ -209,7 +209,8 @@ static bool kvm_event_expand(struct kvm_event *event, int vcpu_id)
        return true;
 }
 
-static struct kvm_event *kvm_alloc_init_event(struct event_key *key)
+static struct kvm_event *kvm_alloc_init_event(struct perf_kvm_stat *kvm,
+                                             struct event_key *key)
 {
        struct kvm_event *event;
 
@@ -219,6 +220,7 @@ static struct kvm_event *kvm_alloc_init_event(struct event_key *key)
                return NULL;
        }
 
+       event->perf_kvm = kvm;
        event->key = *key;
        init_stats(&event->total.stats);
        return event;
@@ -238,7 +240,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm,
                        return event;
        }
 
-       event = kvm_alloc_init_event(key);
+       event = kvm_alloc_init_event(kvm, key);
        if (!event)
                return NULL;
 
index 6f0fa05b62b6e2196a3c75021dfe799eb34115a4..40a4b66cfee6e193f10127bdc8d6cdf4278d445d 100644 (file)
@@ -24,10 +24,13 @@ struct kvm_event_stats {
        struct stats stats;
 };
 
+struct perf_kvm_stat;
+
 struct kvm_event {
        struct list_head hash_entry;
        struct rb_node rb;
 
+       struct perf_kvm_stat *perf_kvm;
        struct event_key key;
 
        struct kvm_event_stats total;
@@ -44,8 +47,6 @@ struct kvm_event_key {
        key_cmp_fun key;
 };
 
-struct perf_kvm_stat;
-
 struct child_event_ops {
        void (*get_key)(struct evsel *evsel,
                        struct perf_sample *sample,