]> Git Repo - linux.git/blob - tools/perf/util/kvm-stat.c
Linux 6.14-rc3
[linux.git] / tools / perf / util / kvm-stat.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include "debug.h"
3 #include "evsel.h"
4 #include "kvm-stat.h"
5
6 #if defined(HAVE_KVM_STAT_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
7
8 bool kvm_exit_event(struct evsel *evsel)
9 {
10         return evsel__name_is(evsel, kvm_exit_trace);
11 }
12
13 void exit_event_get_key(struct evsel *evsel,
14                         struct perf_sample *sample,
15                         struct event_key *key)
16 {
17         key->info = 0;
18         key->key  = evsel__intval(evsel, sample, kvm_exit_reason);
19 }
20
21
22 bool exit_event_begin(struct evsel *evsel,
23                       struct perf_sample *sample, struct event_key *key)
24 {
25         if (kvm_exit_event(evsel)) {
26                 exit_event_get_key(evsel, sample, key);
27                 return true;
28         }
29
30         return false;
31 }
32
33 bool kvm_entry_event(struct evsel *evsel)
34 {
35         return evsel__name_is(evsel, kvm_entry_trace);
36 }
37
38 bool exit_event_end(struct evsel *evsel,
39                     struct perf_sample *sample __maybe_unused,
40                     struct event_key *key __maybe_unused)
41 {
42         return kvm_entry_event(evsel);
43 }
44
45 static const char *get_exit_reason(struct perf_kvm_stat *kvm,
46                                    struct exit_reasons_table *tbl,
47                                    u64 exit_code)
48 {
49         while (tbl->reason != NULL) {
50                 if (tbl->exit_code == exit_code)
51                         return tbl->reason;
52                 tbl++;
53         }
54
55         pr_err("unknown kvm exit code:%lld on %s\n",
56                 (unsigned long long)exit_code, kvm->exit_reasons_isa);
57         return "UNKNOWN";
58 }
59
60 void exit_event_decode_key(struct perf_kvm_stat *kvm,
61                            struct event_key *key,
62                            char *decode)
63 {
64         const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
65                                                   key->key);
66
67         scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason);
68 }
69
70 #endif
This page took 0.033532 seconds and 4 git commands to generate.