2 #include "util/kvm-stat.h"
3 #include "util/parse-events.h"
4 #include "util/debug.h"
6 #include "book3s_hv_exits.h"
7 #include "book3s_hcalls.h"
11 const char *vcpu_id_str = "vcpu_id";
12 const int decode_str_len = 40;
13 const char *kvm_entry_trace = "kvm_hv:kvm_guest_enter";
14 const char *kvm_exit_trace = "kvm_hv:kvm_guest_exit";
16 define_exit_reasons_table(hv_exit_reasons, kvm_trace_symbol_exit);
17 define_exit_reasons_table(hcall_reasons, kvm_trace_symbol_hcall);
19 /* Tracepoints specific to ppc_book3s_hv */
20 const char *ppc_book3s_hv_kvm_tp[] = {
21 "kvm_hv:kvm_guest_enter",
22 "kvm_hv:kvm_guest_exit",
23 "kvm_hv:kvm_hcall_enter",
24 "kvm_hv:kvm_hcall_exit",
28 /* 1 extra placeholder for NULL */
29 const char *kvm_events_tp[NR_TPS + 1];
30 const char *kvm_exit_reason;
32 static void hcall_event_get_key(struct perf_evsel *evsel,
33 struct perf_sample *sample,
34 struct event_key *key)
37 key->key = perf_evsel__intval(evsel, sample, "req");
40 static const char *get_hcall_exit_reason(u64 exit_code)
42 struct exit_reasons_table *tbl = hcall_reasons;
44 while (tbl->reason != NULL) {
45 if (tbl->exit_code == exit_code)
50 pr_debug("Unknown hcall code: %lld\n",
51 (unsigned long long)exit_code);
55 static bool hcall_event_end(struct perf_evsel *evsel,
56 struct perf_sample *sample __maybe_unused,
57 struct event_key *key __maybe_unused)
59 return (!strcmp(evsel->name, kvm_events_tp[3]));
62 static bool hcall_event_begin(struct perf_evsel *evsel,
63 struct perf_sample *sample, struct event_key *key)
65 if (!strcmp(evsel->name, kvm_events_tp[2])) {
66 hcall_event_get_key(evsel, sample, key);
72 static void hcall_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
73 struct event_key *key,
76 const char *hcall_reason = get_hcall_exit_reason(key->key);
78 scnprintf(decode, decode_str_len, "%s", hcall_reason);
81 static struct kvm_events_ops hcall_events = {
82 .is_begin_event = hcall_event_begin,
83 .is_end_event = hcall_event_end,
84 .decode_key = hcall_event_decode_key,
85 .name = "HCALL-EVENT",
88 static struct kvm_events_ops exit_events = {
89 .is_begin_event = exit_event_begin,
90 .is_end_event = exit_event_end,
91 .decode_key = exit_event_decode_key,
95 struct kvm_reg_events_ops kvm_reg_events_ops[] = {
96 { .name = "vmexit", .ops = &exit_events },
97 { .name = "hcall", .ops = &hcall_events },
101 const char * const kvm_skip_events[] = {
106 static int is_tracepoint_available(const char *str, struct perf_evlist *evlist)
108 struct parse_events_error err;
112 ret = parse_events(evlist, str, &err);
114 pr_err("%s : %s\n", str, err.str);
118 static int ppc__setup_book3s_hv(struct perf_kvm_stat *kvm,
119 struct perf_evlist *evlist)
121 const char **events_ptr;
122 int i, nr_tp = 0, err = -1;
124 /* Check for book3s_hv tracepoints */
125 for (events_ptr = ppc_book3s_hv_kvm_tp; *events_ptr; events_ptr++) {
126 err = is_tracepoint_available(*events_ptr, evlist);
132 for (i = 0; i < nr_tp; i++)
133 kvm_events_tp[i] = ppc_book3s_hv_kvm_tp[i];
135 kvm_events_tp[i] = NULL;
136 kvm_exit_reason = "trap";
137 kvm->exit_reasons = hv_exit_reasons;
138 kvm->exit_reasons_isa = "HV";
143 /* Wrapper to setup kvm tracepoints */
144 static int ppc__setup_kvm_tp(struct perf_kvm_stat *kvm)
146 struct perf_evlist *evlist = perf_evlist__new();
151 /* Right now, only supported on book3s_hv */
152 return ppc__setup_book3s_hv(kvm, evlist);
155 int setup_kvm_events_tp(struct perf_kvm_stat *kvm)
157 return ppc__setup_kvm_tp(kvm);
160 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
164 ret = ppc__setup_kvm_tp(kvm);
166 kvm->exit_reasons = NULL;
167 kvm->exit_reasons_isa = NULL;