1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __PERF_KVM_STAT_H 3 #define __PERF_KVM_STAT_H 4 5 #include "tool.h" 6 #include "stat.h" 7 #include "record.h" 8 9 struct evsel; 10 struct evlist; 11 struct perf_session; 12 13 struct event_key { 14 #define INVALID_KEY (~0ULL) 15 u64 key; 16 int info; 17 struct exit_reasons_table *exit_reasons; 18 }; 19 20 struct kvm_event_stats { 21 u64 time; 22 struct stats stats; 23 }; 24 25 struct kvm_event { 26 struct list_head hash_entry; 27 struct rb_node rb; 28 29 struct event_key key; 30 31 struct kvm_event_stats total; 32 33 #define DEFAULT_VCPU_NUM 8 34 int max_vcpu; 35 struct kvm_event_stats *vcpu; 36 }; 37 38 typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); 39 40 struct kvm_event_key { 41 const char *name; 42 key_cmp_fun key; 43 }; 44 45 struct perf_kvm_stat; 46 47 struct child_event_ops { 48 void (*get_key)(struct evsel *evsel, 49 struct perf_sample *sample, 50 struct event_key *key); 51 const char *name; 52 }; 53 54 struct kvm_events_ops { 55 bool (*is_begin_event)(struct evsel *evsel, 56 struct perf_sample *sample, 57 struct event_key *key); 58 bool (*is_end_event)(struct evsel *evsel, 59 struct perf_sample *sample, struct event_key *key); 60 struct child_event_ops *child_ops; 61 void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, 62 char *decode); 63 const char *name; 64 }; 65 66 struct exit_reasons_table { 67 unsigned long exit_code; 68 const char *reason; 69 }; 70 71 #define EVENTS_BITS 12 72 #define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS) 73 74 struct perf_kvm_stat { 75 struct perf_tool tool; 76 struct record_opts opts; 77 struct evlist *evlist; 78 struct perf_session *session; 79 80 const char *file_name; 81 const char *report_event; 82 const char *sort_key; 83 int trace_vcpu; 84 85 struct exit_reasons_table *exit_reasons; 86 const char *exit_reasons_isa; 87 88 struct kvm_events_ops *events_ops; 89 key_cmp_fun compare; 90 struct list_head kvm_events_cache[EVENTS_CACHE_SIZE]; 91 92 u64 total_time; 93 u64 total_count; 94 u64 lost_events; 95 u64 duration; 96 97 struct intlist *pid_list; 98 99 struct rb_root result; 100 101 int timerfd; 102 unsigned int display_time; 103 bool live; 104 bool force; 105 }; 106 107 struct kvm_reg_events_ops { 108 const char *name; 109 struct kvm_events_ops *ops; 110 }; 111 112 void exit_event_get_key(struct evsel *evsel, 113 struct perf_sample *sample, 114 struct event_key *key); 115 bool exit_event_begin(struct evsel *evsel, 116 struct perf_sample *sample, 117 struct event_key *key); 118 bool exit_event_end(struct evsel *evsel, 119 struct perf_sample *sample, 120 struct event_key *key); 121 void exit_event_decode_key(struct perf_kvm_stat *kvm, 122 struct event_key *key, 123 char *decode); 124 125 bool kvm_exit_event(struct evsel *evsel); 126 bool kvm_entry_event(struct evsel *evsel); 127 int setup_kvm_events_tp(struct perf_kvm_stat *kvm); 128 129 #define define_exit_reasons_table(name, symbols) \ 130 static struct exit_reasons_table name[] = { \ 131 symbols, { -1, NULL } \ 132 } 133 134 /* 135 * arch specific callbacks and data structures 136 */ 137 int cpu_isa_init(struct perf_kvm_stat *kvm, const char *cpuid); 138 139 extern const char *kvm_events_tp[]; 140 extern struct kvm_reg_events_ops kvm_reg_events_ops[]; 141 extern const char * const kvm_skip_events[]; 142 extern const char *vcpu_id_str; 143 extern const int decode_str_len; 144 extern const char *kvm_exit_reason; 145 extern const char *kvm_entry_trace; 146 extern const char *kvm_exit_trace; 147 148 #endif /* __PERF_KVM_STAT_H */ 149