xref: /linux/tools/perf/arch/riscv/util/kvm-stat.c (revision 66e72a01b60ae6950ddbb3585fdc1424d303e14b)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Arch specific functions for perf kvm stat.
4  *
5  * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd.
6  *
7  */
8 #include <errno.h>
9 #include <memory.h>
10 #include "../../../util/evsel.h"
11 #include "../../../util/kvm-stat.h"
12 #include "riscv_exception_types.h"
13 #include "debug.h"
14 
15 define_exit_reasons_table(riscv_exit_reasons, kvm_riscv_exception_class);
16 
17 const char *vcpu_id_str = "id";
18 const char *kvm_exit_reason = "scause";
19 const char *kvm_entry_trace = "kvm:kvm_entry";
20 const char *kvm_exit_trace = "kvm:kvm_exit";
21 
22 const char *kvm_events_tp[] = {
23 	"kvm:kvm_entry",
24 	"kvm:kvm_exit",
25 	NULL,
26 };
27 
28 static void event_get_key(struct evsel *evsel,
29 			  struct perf_sample *sample,
30 			  struct event_key *key)
31 {
32 	key->info = 0;
33 	key->key = evsel__intval(evsel, sample, kvm_exit_reason);
34 	key->exit_reasons = riscv_exit_reasons;
35 }
36 
37 static bool event_begin(struct evsel *evsel,
38 			struct perf_sample *sample __maybe_unused,
39 			struct event_key *key __maybe_unused)
40 {
41 	return evsel__name_is(evsel, kvm_entry_trace);
42 }
43 
44 static bool event_end(struct evsel *evsel,
45 		      struct perf_sample *sample,
46 		      struct event_key *key)
47 {
48 	if (evsel__name_is(evsel, kvm_exit_trace)) {
49 		event_get_key(evsel, sample, key);
50 		return true;
51 	}
52 	return false;
53 }
54 
55 static struct kvm_events_ops exit_events = {
56 	.is_begin_event = event_begin,
57 	.is_end_event	= event_end,
58 	.decode_key	= exit_event_decode_key,
59 	.name		= "VM-EXIT"
60 };
61 
62 struct kvm_reg_events_ops kvm_reg_events_ops[] = {
63 	{
64 		.name	= "vmexit",
65 		.ops	= &exit_events,
66 	},
67 	{ NULL, NULL },
68 };
69 
70 const char * const kvm_skip_events[] = {
71 	NULL,
72 };
73 
74 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid __maybe_unused)
75 {
76 	kvm->exit_reasons_isa = "riscv64";
77 	return 0;
78 }
79