1 #include "util/kvm-stat.h"
2 #include "util/parse-events.h"
3 #include "util/debug.h"
5 #include "book3s_hv_exits.h"
6 #include "book3s_hcalls.h"
10 const char *vcpu_id_str
= "vcpu_id";
11 const int decode_str_len
= 40;
12 const char *kvm_entry_trace
= "kvm_hv:kvm_guest_enter";
13 const char *kvm_exit_trace
= "kvm_hv:kvm_guest_exit";
15 define_exit_reasons_table(hv_exit_reasons
, kvm_trace_symbol_exit
);
16 define_exit_reasons_table(hcall_reasons
, kvm_trace_symbol_hcall
);
18 /* Tracepoints specific to ppc_book3s_hv */
19 const char *ppc_book3s_hv_kvm_tp
[] = {
20 "kvm_hv:kvm_guest_enter",
21 "kvm_hv:kvm_guest_exit",
22 "kvm_hv:kvm_hcall_enter",
23 "kvm_hv:kvm_hcall_exit",
27 /* 1 extra placeholder for NULL */
28 const char *kvm_events_tp
[NR_TPS
+ 1];
29 const char *kvm_exit_reason
;
31 static void hcall_event_get_key(struct perf_evsel
*evsel
,
32 struct perf_sample
*sample
,
33 struct event_key
*key
)
36 key
->key
= perf_evsel__intval(evsel
, sample
, "req");
39 static const char *get_hcall_exit_reason(u64 exit_code
)
41 struct exit_reasons_table
*tbl
= hcall_reasons
;
43 while (tbl
->reason
!= NULL
) {
44 if (tbl
->exit_code
== exit_code
)
49 pr_debug("Unknown hcall code: %lld\n",
50 (unsigned long long)exit_code
);
54 static bool hcall_event_end(struct perf_evsel
*evsel
,
55 struct perf_sample
*sample __maybe_unused
,
56 struct event_key
*key __maybe_unused
)
58 return (!strcmp(evsel
->name
, kvm_events_tp
[3]));
61 static bool hcall_event_begin(struct perf_evsel
*evsel
,
62 struct perf_sample
*sample
, struct event_key
*key
)
64 if (!strcmp(evsel
->name
, kvm_events_tp
[2])) {
65 hcall_event_get_key(evsel
, sample
, key
);
71 static void hcall_event_decode_key(struct perf_kvm_stat
*kvm __maybe_unused
,
72 struct event_key
*key
,
75 const char *hcall_reason
= get_hcall_exit_reason(key
->key
);
77 scnprintf(decode
, decode_str_len
, "%s", hcall_reason
);
80 static struct kvm_events_ops hcall_events
= {
81 .is_begin_event
= hcall_event_begin
,
82 .is_end_event
= hcall_event_end
,
83 .decode_key
= hcall_event_decode_key
,
84 .name
= "HCALL-EVENT",
87 static struct kvm_events_ops exit_events
= {
88 .is_begin_event
= exit_event_begin
,
89 .is_end_event
= exit_event_end
,
90 .decode_key
= exit_event_decode_key
,
94 struct kvm_reg_events_ops kvm_reg_events_ops
[] = {
95 { .name
= "vmexit", .ops
= &exit_events
},
96 { .name
= "hcall", .ops
= &hcall_events
},
100 const char * const kvm_skip_events
[] = {
105 static int is_tracepoint_available(const char *str
, struct perf_evlist
*evlist
)
107 struct parse_events_error err
;
111 ret
= parse_events(evlist
, str
, &err
);
113 pr_err("%s : %s\n", str
, err
.str
);
117 static int ppc__setup_book3s_hv(struct perf_kvm_stat
*kvm
,
118 struct perf_evlist
*evlist
)
120 const char **events_ptr
;
121 int i
, nr_tp
= 0, err
= -1;
123 /* Check for book3s_hv tracepoints */
124 for (events_ptr
= ppc_book3s_hv_kvm_tp
; *events_ptr
; events_ptr
++) {
125 err
= is_tracepoint_available(*events_ptr
, evlist
);
131 for (i
= 0; i
< nr_tp
; i
++)
132 kvm_events_tp
[i
] = ppc_book3s_hv_kvm_tp
[i
];
134 kvm_events_tp
[i
] = NULL
;
135 kvm_exit_reason
= "trap";
136 kvm
->exit_reasons
= hv_exit_reasons
;
137 kvm
->exit_reasons_isa
= "HV";
142 /* Wrapper to setup kvm tracepoints */
143 static int ppc__setup_kvm_tp(struct perf_kvm_stat
*kvm
)
145 struct perf_evlist
*evlist
= perf_evlist__new();
150 /* Right now, only supported on book3s_hv */
151 return ppc__setup_book3s_hv(kvm
, evlist
);
154 int setup_kvm_events_tp(struct perf_kvm_stat
*kvm
)
156 return ppc__setup_kvm_tp(kvm
);
159 int cpu_isa_init(struct perf_kvm_stat
*kvm
, const char *cpuid __maybe_unused
)
163 ret
= ppc__setup_kvm_tp(kvm
);
165 kvm
->exit_reasons
= NULL
;
166 kvm
->exit_reasons_isa
= NULL
;