1 #include "../../util/kvm-stat.h"
2 #include <asm/kvm_perf.h>
4 define_exit_reasons_table(vmx_exit_reasons
, VMX_EXIT_REASONS
);
5 define_exit_reasons_table(svm_exit_reasons
, SVM_EXIT_REASONS
);
7 static struct kvm_events_ops exit_events
= {
8 .is_begin_event
= exit_event_begin
,
9 .is_end_event
= exit_event_end
,
10 .decode_key
= exit_event_decode_key
,
15 * For the mmio events, we treat:
16 * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
17 * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
19 static void mmio_event_get_key(struct perf_evsel
*evsel
, struct perf_sample
*sample
,
20 struct event_key
*key
)
22 key
->key
= perf_evsel__intval(evsel
, sample
, "gpa");
23 key
->info
= perf_evsel__intval(evsel
, sample
, "type");
26 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0
27 #define KVM_TRACE_MMIO_READ 1
28 #define KVM_TRACE_MMIO_WRITE 2
30 static bool mmio_event_begin(struct perf_evsel
*evsel
,
31 struct perf_sample
*sample
, struct event_key
*key
)
33 /* MMIO read begin event in kernel. */
34 if (kvm_exit_event(evsel
))
37 /* MMIO write begin event in kernel. */
38 if (!strcmp(evsel
->name
, "kvm:kvm_mmio") &&
39 perf_evsel__intval(evsel
, sample
, "type") == KVM_TRACE_MMIO_WRITE
) {
40 mmio_event_get_key(evsel
, sample
, key
);
47 static bool mmio_event_end(struct perf_evsel
*evsel
, struct perf_sample
*sample
,
48 struct event_key
*key
)
50 /* MMIO write end event in kernel. */
51 if (kvm_entry_event(evsel
))
54 /* MMIO read end event in kernel.*/
55 if (!strcmp(evsel
->name
, "kvm:kvm_mmio") &&
56 perf_evsel__intval(evsel
, sample
, "type") == KVM_TRACE_MMIO_READ
) {
57 mmio_event_get_key(evsel
, sample
, key
);
64 static void mmio_event_decode_key(struct perf_kvm_stat
*kvm __maybe_unused
,
65 struct event_key
*key
,
68 scnprintf(decode
, DECODE_STR_LEN
, "%#lx:%s",
69 (unsigned long)key
->key
,
70 key
->info
== KVM_TRACE_MMIO_WRITE
? "W" : "R");
73 static struct kvm_events_ops mmio_events
= {
74 .is_begin_event
= mmio_event_begin
,
75 .is_end_event
= mmio_event_end
,
76 .decode_key
= mmio_event_decode_key
,
80 /* The time of emulation pio access is from kvm_pio to kvm_entry. */
81 static void ioport_event_get_key(struct perf_evsel
*evsel
,
82 struct perf_sample
*sample
,
83 struct event_key
*key
)
85 key
->key
= perf_evsel__intval(evsel
, sample
, "port");
86 key
->info
= perf_evsel__intval(evsel
, sample
, "rw");
89 static bool ioport_event_begin(struct perf_evsel
*evsel
,
90 struct perf_sample
*sample
,
91 struct event_key
*key
)
93 if (!strcmp(evsel
->name
, "kvm:kvm_pio")) {
94 ioport_event_get_key(evsel
, sample
, key
);
101 static bool ioport_event_end(struct perf_evsel
*evsel
,
102 struct perf_sample
*sample __maybe_unused
,
103 struct event_key
*key __maybe_unused
)
105 return kvm_entry_event(evsel
);
108 static void ioport_event_decode_key(struct perf_kvm_stat
*kvm __maybe_unused
,
109 struct event_key
*key
,
112 scnprintf(decode
, DECODE_STR_LEN
, "%#llx:%s",
113 (unsigned long long)key
->key
,
114 key
->info
? "POUT" : "PIN");
117 static struct kvm_events_ops ioport_events
= {
118 .is_begin_event
= ioport_event_begin
,
119 .is_end_event
= ioport_event_end
,
120 .decode_key
= ioport_event_decode_key
,
121 .name
= "IO Port Access"
124 const char * const kvm_events_tp
[] = {
132 struct kvm_reg_events_ops kvm_reg_events_ops
[] = {
133 { .name
= "vmexit", .ops
= &exit_events
},
134 { .name
= "mmio", .ops
= &mmio_events
},
135 { .name
= "ioport", .ops
= &ioport_events
},
139 const char * const kvm_skip_events
[] = {
144 int cpu_isa_init(struct perf_kvm_stat
*kvm
, const char *cpuid
)
146 if (strstr(cpuid
, "Intel")) {
147 kvm
->exit_reasons
= vmx_exit_reasons
;
148 kvm
->exit_reasons_isa
= "VMX";
149 } else if (strstr(cpuid
, "AMD")) {
150 kvm
->exit_reasons
= svm_exit_reasons
;
151 kvm
->exit_reasons_isa
= "SVM";