xref: /openbmc/linux/tools/perf/arch/arm64/util/kvm-stat.c (revision ce1d3bc2)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <errno.h>
3 #include <memory.h>
4 #include "../../../util/evsel.h"
5 #include "../../../util/kvm-stat.h"
6 #include "arm64_exception_types.h"
7 #include "debug.h"
8 
9 define_exit_reasons_table(arm64_exit_reasons, kvm_arm_exception_type);
10 define_exit_reasons_table(arm64_trap_exit_reasons, kvm_arm_exception_class);
11 
12 const char *kvm_trap_exit_reason = "esr_ec";
13 const char *vcpu_id_str = "id";
14 const char *kvm_exit_reason = "ret";
15 const char *kvm_entry_trace = "kvm:kvm_entry";
16 const char *kvm_exit_trace = "kvm:kvm_exit";
17 
18 const char *kvm_events_tp[] = {
19 	"kvm:kvm_entry",
20 	"kvm:kvm_exit",
21 	NULL,
22 };
23 
event_get_key(struct evsel * evsel,struct perf_sample * sample,struct event_key * key)24 static void event_get_key(struct evsel *evsel,
25 			  struct perf_sample *sample,
26 			  struct event_key *key)
27 {
28 	key->info = 0;
29 	key->key = evsel__intval(evsel, sample, kvm_exit_reason);
30 	key->exit_reasons = arm64_exit_reasons;
31 
32 	/*
33 	 * TRAP exceptions carry exception class info in esr_ec field
34 	 * and, hence, we need to use a different exit_reasons table to
35 	 * properly decode event's est_ec.
36 	 */
37 	if (key->key == ARM_EXCEPTION_TRAP) {
38 		key->key = evsel__intval(evsel, sample, kvm_trap_exit_reason);
39 		key->exit_reasons = arm64_trap_exit_reasons;
40 	}
41 }
42 
event_begin(struct evsel * evsel,struct perf_sample * sample __maybe_unused,struct event_key * key __maybe_unused)43 static bool event_begin(struct evsel *evsel,
44 			struct perf_sample *sample __maybe_unused,
45 			struct event_key *key __maybe_unused)
46 {
47 	return evsel__name_is(evsel, kvm_entry_trace);
48 }
49 
event_end(struct evsel * evsel,struct perf_sample * sample,struct event_key * key)50 static bool event_end(struct evsel *evsel,
51 		      struct perf_sample *sample,
52 		      struct event_key *key)
53 {
54 	if (evsel__name_is(evsel, kvm_exit_trace)) {
55 		event_get_key(evsel, sample, key);
56 		return true;
57 	}
58 	return false;
59 }
60 
61 static struct kvm_events_ops exit_events = {
62 	.is_begin_event = event_begin,
63 	.is_end_event	= event_end,
64 	.decode_key	= exit_event_decode_key,
65 	.name		= "VM-EXIT"
66 };
67 
68 struct kvm_reg_events_ops kvm_reg_events_ops[] = {
69 	{
70 		.name	= "vmexit",
71 		.ops	= &exit_events,
72 	},
73 	{ NULL, NULL },
74 };
75 
76 const char * const kvm_skip_events[] = {
77 	NULL,
78 };
79 
cpu_isa_init(struct perf_kvm_stat * kvm,const char * cpuid __maybe_unused)80 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
81 {
82 	kvm->exit_reasons_isa = "arm64";
83 	return 0;
84 }
85