]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf kvm: Move functions used in util out of builtin
authorIan Rogers <irogers@google.com>
Tue, 19 Nov 2024 01:16:27 +0000 (17:16 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 18 Dec 2024 19:24:32 +0000 (16:24 -0300)
The util library code is used by the python module but doesn't have
access to the builtin files. Make a util/kvm-stat.c to match the
kvm-stat.h file that declares the functions and move the functions
there.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dapeng Mi <dapeng1.mi@linux.intel.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20241119011644.971342-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kvm.c
tools/perf/util/Build
tools/perf/util/kvm-stat.c [new file with mode: 0644]
tools/perf/util/kvm-stat.h
tools/perf/util/python.c

index 274568d712d12f9ada0ce141518b2eb526cb9537..67fd2b006b0b6f85c839014dcd3d0f98567feba6 100644 (file)
@@ -615,67 +615,6 @@ static const char *get_filename_for_perf_kvm(void)
 
 #if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
 
-void exit_event_get_key(struct evsel *evsel,
-                       struct perf_sample *sample,
-                       struct event_key *key)
-{
-       key->info = 0;
-       key->key  = evsel__intval(evsel, sample, kvm_exit_reason);
-}
-
-bool kvm_exit_event(struct evsel *evsel)
-{
-       return evsel__name_is(evsel, kvm_exit_trace);
-}
-
-bool exit_event_begin(struct evsel *evsel,
-                     struct perf_sample *sample, struct event_key *key)
-{
-       if (kvm_exit_event(evsel)) {
-               exit_event_get_key(evsel, sample, key);
-               return true;
-       }
-
-       return false;
-}
-
-bool kvm_entry_event(struct evsel *evsel)
-{
-       return evsel__name_is(evsel, kvm_entry_trace);
-}
-
-bool exit_event_end(struct evsel *evsel,
-                   struct perf_sample *sample __maybe_unused,
-                   struct event_key *key __maybe_unused)
-{
-       return kvm_entry_event(evsel);
-}
-
-static const char *get_exit_reason(struct perf_kvm_stat *kvm,
-                                  struct exit_reasons_table *tbl,
-                                  u64 exit_code)
-{
-       while (tbl->reason != NULL) {
-               if (tbl->exit_code == exit_code)
-                       return tbl->reason;
-               tbl++;
-       }
-
-       pr_err("unknown kvm exit code:%lld on %s\n",
-               (unsigned long long)exit_code, kvm->exit_reasons_isa);
-       return "UNKNOWN";
-}
-
-void exit_event_decode_key(struct perf_kvm_stat *kvm,
-                          struct event_key *key,
-                          char *decode)
-{
-       const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
-                                                 key->key);
-
-       scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason);
-}
-
 static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
 {
        struct kvm_reg_events_ops *events_ops = kvm_reg_events_ops;
index 93315bcba7bc61ccd912d1b98c8a5d1d7051defa..e1c8d191c510db7d66d2389684e5347fac97c1ec 100644 (file)
@@ -121,6 +121,7 @@ perf-util-y += spark.o
 perf-util-y += topdown.o
 perf-util-y += iostat.o
 perf-util-y += stream.o
+perf-util-y += kvm-stat.o
 perf-util-$(CONFIG_AUXTRACE) += auxtrace.o
 perf-util-$(CONFIG_AUXTRACE) += intel-pt-decoder/
 perf-util-$(CONFIG_AUXTRACE) += intel-pt.o
diff --git a/tools/perf/util/kvm-stat.c b/tools/perf/util/kvm-stat.c
new file mode 100644 (file)
index 0000000..38ace73
--- /dev/null
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "debug.h"
+#include "evsel.h"
+#include "kvm-stat.h"
+
+#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+
+bool kvm_exit_event(struct evsel *evsel)
+{
+       return evsel__name_is(evsel, kvm_exit_trace);
+}
+
+void exit_event_get_key(struct evsel *evsel,
+                       struct perf_sample *sample,
+                       struct event_key *key)
+{
+       key->info = 0;
+       key->key  = evsel__intval(evsel, sample, kvm_exit_reason);
+}
+
+
+bool exit_event_begin(struct evsel *evsel,
+                     struct perf_sample *sample, struct event_key *key)
+{
+       if (kvm_exit_event(evsel)) {
+               exit_event_get_key(evsel, sample, key);
+               return true;
+       }
+
+       return false;
+}
+
+bool kvm_entry_event(struct evsel *evsel)
+{
+       return evsel__name_is(evsel, kvm_entry_trace);
+}
+
+bool exit_event_end(struct evsel *evsel,
+                   struct perf_sample *sample __maybe_unused,
+                   struct event_key *key __maybe_unused)
+{
+       return kvm_entry_event(evsel);
+}
+
+static const char *get_exit_reason(struct perf_kvm_stat *kvm,
+                                  struct exit_reasons_table *tbl,
+                                  u64 exit_code)
+{
+       while (tbl->reason != NULL) {
+               if (tbl->exit_code == exit_code)
+                       return tbl->reason;
+               tbl++;
+       }
+
+       pr_err("unknown kvm exit code:%lld on %s\n",
+               (unsigned long long)exit_code, kvm->exit_reasons_isa);
+       return "UNKNOWN";
+}
+
+void exit_event_decode_key(struct perf_kvm_stat *kvm,
+                          struct event_key *key,
+                          char *decode)
+{
+       const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
+                                                 key->key);
+
+       scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason);
+}
+
+#endif
index 3e9ac754c3d1f0cfc0078a40f21a3bd1121df4c7..4249542544bbad312848d0e29351dd27036fea75 100644 (file)
@@ -115,6 +115,8 @@ struct kvm_reg_events_ops {
        struct kvm_events_ops *ops;
 };
 
+#if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+
 void exit_event_get_key(struct evsel *evsel,
                        struct perf_sample *sample,
                        struct event_key *key);
@@ -127,6 +129,7 @@ bool exit_event_end(struct evsel *evsel,
 void exit_event_decode_key(struct perf_kvm_stat *kvm,
                           struct event_key *key,
                           char *decode);
+#endif
 
 bool kvm_exit_event(struct evsel *evsel);
 bool kvm_entry_event(struct evsel *evsel);
index 029536c1fabcf18ee75644ad1f6461937c0d3b34..f8b291143884b63bda9e720dae62f1249ae64ede 100644 (file)
@@ -1307,38 +1307,6 @@ error:
 /* The following are stubs to avoid dragging in builtin-* objects. */
 /* TODO: move the code out of the builtin-* file into util. */
 
-#ifdef HAVE_KVM_STAT_SUPPORT
-bool kvm_entry_event(struct evsel *evsel __maybe_unused)
-{
-       return false;
-}
-
-bool kvm_exit_event(struct evsel *evsel __maybe_unused)
-{
-       return false;
-}
-
-bool exit_event_begin(struct evsel *evsel __maybe_unused,
-                     struct perf_sample *sample  __maybe_unused,
-                     struct event_key *key  __maybe_unused)
-{
-       return false;
-}
-
-bool exit_event_end(struct evsel *evsel __maybe_unused,
-                   struct perf_sample *sample __maybe_unused,
-                   struct event_key *key __maybe_unused)
-{
-       return false;
-}
-
-void exit_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
-                          struct event_key *key __maybe_unused,
-                          char *decode __maybe_unused)
-{
-}
-#endif // HAVE_KVM_STAT_SUPPORT
-
 int find_scripts(char **scripts_array  __maybe_unused, char **scripts_path_array  __maybe_unused,
                int num  __maybe_unused, int pathlen __maybe_unused)
 {