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