Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | #include "perf.h" |
| 3 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 4 | #include "util/evsel.h" |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 5 | #include "util/util.h" |
| 6 | #include "util/cache.h" |
| 7 | #include "util/symbol.h" |
| 8 | #include "util/thread.h" |
| 9 | #include "util/header.h" |
| 10 | #include "util/session.h" |
| 11 | |
| 12 | #include "util/parse-options.h" |
| 13 | #include "util/trace-event.h" |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 14 | #include "util/debug.h" |
Borislav Petkov | 85c66be | 2013-02-20 16:32:30 +0100 | [diff] [blame] | 15 | #include <lk/debugfs.h> |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 16 | #include "util/tool.h" |
| 17 | #include "util/stat.h" |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 18 | |
| 19 | #include <sys/prctl.h> |
| 20 | |
| 21 | #include <semaphore.h> |
| 22 | #include <pthread.h> |
| 23 | #include <math.h> |
| 24 | |
Xiao Guangrong | 7321090 | 2012-11-19 16:19:21 +0800 | [diff] [blame] | 25 | #if defined(__i386__) || defined(__x86_64__) |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 26 | #include <asm/svm.h> |
| 27 | #include <asm/vmx.h> |
| 28 | #include <asm/kvm.h> |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 29 | |
| 30 | struct event_key { |
| 31 | #define INVALID_KEY (~0ULL) |
| 32 | u64 key; |
| 33 | int info; |
| 34 | }; |
| 35 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 36 | struct kvm_event_stats { |
| 37 | u64 time; |
| 38 | struct stats stats; |
| 39 | }; |
| 40 | |
| 41 | struct kvm_event { |
| 42 | struct list_head hash_entry; |
| 43 | struct rb_node rb; |
| 44 | |
| 45 | struct event_key key; |
| 46 | |
| 47 | struct kvm_event_stats total; |
| 48 | |
| 49 | #define DEFAULT_VCPU_NUM 8 |
| 50 | int max_vcpu; |
| 51 | struct kvm_event_stats *vcpu; |
| 52 | }; |
| 53 | |
| 54 | typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int); |
| 55 | |
| 56 | struct kvm_event_key { |
| 57 | const char *name; |
| 58 | key_cmp_fun key; |
| 59 | }; |
| 60 | |
| 61 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 62 | struct perf_kvm_stat; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 63 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 64 | struct kvm_events_ops { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 65 | bool (*is_begin_event)(struct perf_evsel *evsel, |
| 66 | struct perf_sample *sample, |
| 67 | struct event_key *key); |
| 68 | bool (*is_end_event)(struct perf_evsel *evsel, |
| 69 | struct perf_sample *sample, struct event_key *key); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 70 | void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 71 | char decode[20]); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 72 | const char *name; |
| 73 | }; |
| 74 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 75 | struct exit_reasons_table { |
| 76 | unsigned long exit_code; |
| 77 | const char *reason; |
| 78 | }; |
| 79 | |
| 80 | #define EVENTS_BITS 12 |
| 81 | #define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS) |
| 82 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 83 | struct perf_kvm_stat { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 84 | struct perf_tool tool; |
| 85 | struct perf_session *session; |
| 86 | |
| 87 | const char *file_name; |
| 88 | const char *report_event; |
| 89 | const char *sort_key; |
| 90 | int trace_vcpu; |
| 91 | |
| 92 | struct exit_reasons_table *exit_reasons; |
| 93 | int exit_reasons_size; |
| 94 | const char *exit_reasons_isa; |
| 95 | |
| 96 | struct kvm_events_ops *events_ops; |
| 97 | key_cmp_fun compare; |
| 98 | struct list_head kvm_events_cache[EVENTS_CACHE_SIZE]; |
| 99 | u64 total_time; |
| 100 | u64 total_count; |
| 101 | |
| 102 | struct rb_root result; |
| 103 | }; |
| 104 | |
| 105 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 106 | static void exit_event_get_key(struct perf_evsel *evsel, |
| 107 | struct perf_sample *sample, |
| 108 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 109 | { |
| 110 | key->info = 0; |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 111 | key->key = perf_evsel__intval(evsel, sample, "exit_reason"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 112 | } |
| 113 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 114 | static bool kvm_exit_event(struct perf_evsel *evsel) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 115 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 116 | return !strcmp(evsel->name, "kvm:kvm_exit"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 117 | } |
| 118 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 119 | static bool exit_event_begin(struct perf_evsel *evsel, |
| 120 | struct perf_sample *sample, struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 121 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 122 | if (kvm_exit_event(evsel)) { |
| 123 | exit_event_get_key(evsel, sample, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 124 | return true; |
| 125 | } |
| 126 | |
| 127 | return false; |
| 128 | } |
| 129 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 130 | static bool kvm_entry_event(struct perf_evsel *evsel) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 131 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 132 | return !strcmp(evsel->name, "kvm:kvm_entry"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 133 | } |
| 134 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 135 | static bool exit_event_end(struct perf_evsel *evsel, |
| 136 | struct perf_sample *sample __maybe_unused, |
| 137 | struct event_key *key __maybe_unused) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 138 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 139 | return kvm_entry_event(evsel); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 140 | } |
| 141 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 142 | static struct exit_reasons_table vmx_exit_reasons[] = { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 143 | VMX_EXIT_REASONS |
| 144 | }; |
| 145 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 146 | static struct exit_reasons_table svm_exit_reasons[] = { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 147 | SVM_EXIT_REASONS |
| 148 | }; |
| 149 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 150 | static const char *get_exit_reason(struct perf_kvm_stat *kvm, u64 exit_code) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 151 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 152 | int i = kvm->exit_reasons_size; |
| 153 | struct exit_reasons_table *tbl = kvm->exit_reasons; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 154 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 155 | while (i--) { |
| 156 | if (tbl->exit_code == exit_code) |
| 157 | return tbl->reason; |
| 158 | tbl++; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | pr_err("unknown kvm exit code:%lld on %s\n", |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 162 | (unsigned long long)exit_code, kvm->exit_reasons_isa); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 163 | return "UNKNOWN"; |
| 164 | } |
| 165 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 166 | static void exit_event_decode_key(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 167 | struct event_key *key, |
| 168 | char decode[20]) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 169 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 170 | const char *exit_reason = get_exit_reason(kvm, key->key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 171 | |
| 172 | scnprintf(decode, 20, "%s", exit_reason); |
| 173 | } |
| 174 | |
| 175 | static struct kvm_events_ops exit_events = { |
| 176 | .is_begin_event = exit_event_begin, |
| 177 | .is_end_event = exit_event_end, |
| 178 | .decode_key = exit_event_decode_key, |
| 179 | .name = "VM-EXIT" |
| 180 | }; |
| 181 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 182 | /* |
| 183 | * For the mmio events, we treat: |
| 184 | * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry |
| 185 | * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...). |
| 186 | */ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 187 | static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample, |
| 188 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 189 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 190 | key->key = perf_evsel__intval(evsel, sample, "gpa"); |
| 191 | key->info = perf_evsel__intval(evsel, sample, "type"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | #define KVM_TRACE_MMIO_READ_UNSATISFIED 0 |
| 195 | #define KVM_TRACE_MMIO_READ 1 |
| 196 | #define KVM_TRACE_MMIO_WRITE 2 |
| 197 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 198 | static bool mmio_event_begin(struct perf_evsel *evsel, |
| 199 | struct perf_sample *sample, struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 200 | { |
| 201 | /* MMIO read begin event in kernel. */ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 202 | if (kvm_exit_event(evsel)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 203 | return true; |
| 204 | |
| 205 | /* MMIO write begin event in kernel. */ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 206 | if (!strcmp(evsel->name, "kvm:kvm_mmio") && |
| 207 | perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) { |
| 208 | mmio_event_get_key(evsel, sample, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 209 | return true; |
| 210 | } |
| 211 | |
| 212 | return false; |
| 213 | } |
| 214 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 215 | static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample, |
| 216 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 217 | { |
| 218 | /* MMIO write end event in kernel. */ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 219 | if (kvm_entry_event(evsel)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 220 | return true; |
| 221 | |
| 222 | /* MMIO read end event in kernel.*/ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 223 | if (!strcmp(evsel->name, "kvm:kvm_mmio") && |
| 224 | perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) { |
| 225 | mmio_event_get_key(evsel, sample, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 226 | return true; |
| 227 | } |
| 228 | |
| 229 | return false; |
| 230 | } |
| 231 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 232 | static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 233 | struct event_key *key, |
| 234 | char decode[20]) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 235 | { |
| 236 | scnprintf(decode, 20, "%#lx:%s", (unsigned long)key->key, |
| 237 | key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R"); |
| 238 | } |
| 239 | |
| 240 | static struct kvm_events_ops mmio_events = { |
| 241 | .is_begin_event = mmio_event_begin, |
| 242 | .is_end_event = mmio_event_end, |
| 243 | .decode_key = mmio_event_decode_key, |
| 244 | .name = "MMIO Access" |
| 245 | }; |
| 246 | |
| 247 | /* The time of emulation pio access is from kvm_pio to kvm_entry. */ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 248 | static void ioport_event_get_key(struct perf_evsel *evsel, |
| 249 | struct perf_sample *sample, |
| 250 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 251 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 252 | key->key = perf_evsel__intval(evsel, sample, "port"); |
| 253 | key->info = perf_evsel__intval(evsel, sample, "rw"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 254 | } |
| 255 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 256 | static bool ioport_event_begin(struct perf_evsel *evsel, |
| 257 | struct perf_sample *sample, |
| 258 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 259 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 260 | if (!strcmp(evsel->name, "kvm:kvm_pio")) { |
| 261 | ioport_event_get_key(evsel, sample, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 262 | return true; |
| 263 | } |
| 264 | |
| 265 | return false; |
| 266 | } |
| 267 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 268 | static bool ioport_event_end(struct perf_evsel *evsel, |
| 269 | struct perf_sample *sample __maybe_unused, |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 270 | struct event_key *key __maybe_unused) |
| 271 | { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 272 | return kvm_entry_event(evsel); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 273 | } |
| 274 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 275 | static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 276 | struct event_key *key, |
| 277 | char decode[20]) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 278 | { |
| 279 | scnprintf(decode, 20, "%#llx:%s", (unsigned long long)key->key, |
| 280 | key->info ? "POUT" : "PIN"); |
| 281 | } |
| 282 | |
| 283 | static struct kvm_events_ops ioport_events = { |
| 284 | .is_begin_event = ioport_event_begin, |
| 285 | .is_end_event = ioport_event_end, |
| 286 | .decode_key = ioport_event_decode_key, |
| 287 | .name = "IO Port Access" |
| 288 | }; |
| 289 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 290 | static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 291 | { |
| 292 | bool ret = true; |
| 293 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 294 | if (!strcmp(kvm->report_event, "vmexit")) |
| 295 | kvm->events_ops = &exit_events; |
| 296 | else if (!strcmp(kvm->report_event, "mmio")) |
| 297 | kvm->events_ops = &mmio_events; |
| 298 | else if (!strcmp(kvm->report_event, "ioport")) |
| 299 | kvm->events_ops = &ioport_events; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 300 | else { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 301 | pr_err("Unknown report event:%s\n", kvm->report_event); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 302 | ret = false; |
| 303 | } |
| 304 | |
| 305 | return ret; |
| 306 | } |
| 307 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 308 | struct vcpu_event_record { |
| 309 | int vcpu_id; |
| 310 | u64 start_time; |
| 311 | struct kvm_event *last_event; |
| 312 | }; |
| 313 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 314 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 315 | static void init_kvm_event_record(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 316 | { |
David Ahern | b880dee | 2012-10-08 11:17:30 -0600 | [diff] [blame] | 317 | unsigned int i; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 318 | |
David Ahern | b880dee | 2012-10-08 11:17:30 -0600 | [diff] [blame] | 319 | for (i = 0; i < EVENTS_CACHE_SIZE; i++) |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 320 | INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static int kvm_events_hash_fn(u64 key) |
| 324 | { |
| 325 | return key & (EVENTS_CACHE_SIZE - 1); |
| 326 | } |
| 327 | |
| 328 | static bool kvm_event_expand(struct kvm_event *event, int vcpu_id) |
| 329 | { |
| 330 | int old_max_vcpu = event->max_vcpu; |
David Ahern | 6ca5f30 | 2013-05-25 18:24:46 -0600 | [diff] [blame] | 331 | void *prev; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 332 | |
| 333 | if (vcpu_id < event->max_vcpu) |
| 334 | return true; |
| 335 | |
| 336 | while (event->max_vcpu <= vcpu_id) |
| 337 | event->max_vcpu += DEFAULT_VCPU_NUM; |
| 338 | |
David Ahern | 6ca5f30 | 2013-05-25 18:24:46 -0600 | [diff] [blame] | 339 | prev = event->vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 340 | event->vcpu = realloc(event->vcpu, |
| 341 | event->max_vcpu * sizeof(*event->vcpu)); |
| 342 | if (!event->vcpu) { |
David Ahern | 6ca5f30 | 2013-05-25 18:24:46 -0600 | [diff] [blame] | 343 | free(prev); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 344 | pr_err("Not enough memory\n"); |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | memset(event->vcpu + old_max_vcpu, 0, |
| 349 | (event->max_vcpu - old_max_vcpu) * sizeof(*event->vcpu)); |
| 350 | return true; |
| 351 | } |
| 352 | |
| 353 | static struct kvm_event *kvm_alloc_init_event(struct event_key *key) |
| 354 | { |
| 355 | struct kvm_event *event; |
| 356 | |
| 357 | event = zalloc(sizeof(*event)); |
| 358 | if (!event) { |
| 359 | pr_err("Not enough memory\n"); |
| 360 | return NULL; |
| 361 | } |
| 362 | |
| 363 | event->key = *key; |
| 364 | return event; |
| 365 | } |
| 366 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 367 | static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 368 | struct event_key *key) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 369 | { |
| 370 | struct kvm_event *event; |
| 371 | struct list_head *head; |
| 372 | |
| 373 | BUG_ON(key->key == INVALID_KEY); |
| 374 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 375 | head = &kvm->kvm_events_cache[kvm_events_hash_fn(key->key)]; |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 376 | list_for_each_entry(event, head, hash_entry) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 377 | if (event->key.key == key->key && event->key.info == key->info) |
| 378 | return event; |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 379 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 380 | |
| 381 | event = kvm_alloc_init_event(key); |
| 382 | if (!event) |
| 383 | return NULL; |
| 384 | |
| 385 | list_add(&event->hash_entry, head); |
| 386 | return event; |
| 387 | } |
| 388 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 389 | static bool handle_begin_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 390 | struct vcpu_event_record *vcpu_record, |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 391 | struct event_key *key, u64 timestamp) |
| 392 | { |
| 393 | struct kvm_event *event = NULL; |
| 394 | |
| 395 | if (key->key != INVALID_KEY) |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 396 | event = find_create_kvm_event(kvm, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 397 | |
| 398 | vcpu_record->last_event = event; |
| 399 | vcpu_record->start_time = timestamp; |
| 400 | return true; |
| 401 | } |
| 402 | |
| 403 | static void |
| 404 | kvm_update_event_stats(struct kvm_event_stats *kvm_stats, u64 time_diff) |
| 405 | { |
| 406 | kvm_stats->time += time_diff; |
| 407 | update_stats(&kvm_stats->stats, time_diff); |
| 408 | } |
| 409 | |
| 410 | static double kvm_event_rel_stddev(int vcpu_id, struct kvm_event *event) |
| 411 | { |
| 412 | struct kvm_event_stats *kvm_stats = &event->total; |
| 413 | |
| 414 | if (vcpu_id != -1) |
| 415 | kvm_stats = &event->vcpu[vcpu_id]; |
| 416 | |
| 417 | return rel_stddev_stats(stddev_stats(&kvm_stats->stats), |
| 418 | avg_stats(&kvm_stats->stats)); |
| 419 | } |
| 420 | |
| 421 | static bool update_kvm_event(struct kvm_event *event, int vcpu_id, |
| 422 | u64 time_diff) |
| 423 | { |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 424 | if (vcpu_id == -1) { |
| 425 | kvm_update_event_stats(&event->total, time_diff); |
| 426 | return true; |
| 427 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 428 | |
| 429 | if (!kvm_event_expand(event, vcpu_id)) |
| 430 | return false; |
| 431 | |
| 432 | kvm_update_event_stats(&event->vcpu[vcpu_id], time_diff); |
| 433 | return true; |
| 434 | } |
| 435 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 436 | static bool handle_end_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 437 | struct vcpu_event_record *vcpu_record, |
| 438 | struct event_key *key, |
| 439 | u64 timestamp) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 440 | { |
| 441 | struct kvm_event *event; |
| 442 | u64 time_begin, time_diff; |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 443 | int vcpu; |
| 444 | |
| 445 | if (kvm->trace_vcpu == -1) |
| 446 | vcpu = -1; |
| 447 | else |
| 448 | vcpu = vcpu_record->vcpu_id; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 449 | |
| 450 | event = vcpu_record->last_event; |
| 451 | time_begin = vcpu_record->start_time; |
| 452 | |
| 453 | /* The begin event is not caught. */ |
| 454 | if (!time_begin) |
| 455 | return true; |
| 456 | |
| 457 | /* |
| 458 | * In some case, the 'begin event' only records the start timestamp, |
| 459 | * the actual event is recognized in the 'end event' (e.g. mmio-event). |
| 460 | */ |
| 461 | |
| 462 | /* Both begin and end events did not get the key. */ |
| 463 | if (!event && key->key == INVALID_KEY) |
| 464 | return true; |
| 465 | |
| 466 | if (!event) |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 467 | event = find_create_kvm_event(kvm, key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 468 | |
| 469 | if (!event) |
| 470 | return false; |
| 471 | |
| 472 | vcpu_record->last_event = NULL; |
| 473 | vcpu_record->start_time = 0; |
| 474 | |
| 475 | BUG_ON(timestamp < time_begin); |
| 476 | |
| 477 | time_diff = timestamp - time_begin; |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 478 | return update_kvm_event(event, vcpu, time_diff); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 479 | } |
| 480 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 481 | static |
| 482 | struct vcpu_event_record *per_vcpu_record(struct thread *thread, |
| 483 | struct perf_evsel *evsel, |
| 484 | struct perf_sample *sample) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 485 | { |
| 486 | /* Only kvm_entry records vcpu id. */ |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 487 | if (!thread->priv && kvm_entry_event(evsel)) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 488 | struct vcpu_event_record *vcpu_record; |
| 489 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 490 | vcpu_record = zalloc(sizeof(*vcpu_record)); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 491 | if (!vcpu_record) { |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 492 | pr_err("%s: Not enough memory\n", __func__); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 493 | return NULL; |
| 494 | } |
| 495 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 496 | vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, "vcpu_id"); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 497 | thread->priv = vcpu_record; |
| 498 | } |
| 499 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 500 | return thread->priv; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 501 | } |
| 502 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 503 | static bool handle_kvm_event(struct perf_kvm_stat *kvm, |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 504 | struct thread *thread, |
| 505 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 506 | struct perf_sample *sample) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 507 | { |
| 508 | struct vcpu_event_record *vcpu_record; |
| 509 | struct event_key key = {.key = INVALID_KEY}; |
| 510 | |
Arnaldo Carvalho de Melo | 14907e7 | 2012-09-21 16:10:26 -0300 | [diff] [blame] | 511 | vcpu_record = per_vcpu_record(thread, evsel, sample); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 512 | if (!vcpu_record) |
| 513 | return true; |
| 514 | |
David Ahern | 2aa8eab | 2012-10-08 11:17:35 -0600 | [diff] [blame] | 515 | /* only process events for vcpus user cares about */ |
| 516 | if ((kvm->trace_vcpu != -1) && |
| 517 | (kvm->trace_vcpu != vcpu_record->vcpu_id)) |
| 518 | return true; |
| 519 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 520 | if (kvm->events_ops->is_begin_event(evsel, sample, &key)) |
| 521 | return handle_begin_event(kvm, vcpu_record, &key, sample->time); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 522 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 523 | if (kvm->events_ops->is_end_event(evsel, sample, &key)) |
| 524 | return handle_end_event(kvm, vcpu_record, &key, sample->time); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 525 | |
| 526 | return true; |
| 527 | } |
| 528 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 529 | #define GET_EVENT_KEY(func, field) \ |
| 530 | static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \ |
| 531 | { \ |
| 532 | if (vcpu == -1) \ |
| 533 | return event->total.field; \ |
| 534 | \ |
| 535 | if (vcpu >= event->max_vcpu) \ |
| 536 | return 0; \ |
| 537 | \ |
| 538 | return event->vcpu[vcpu].field; \ |
| 539 | } |
| 540 | |
| 541 | #define COMPARE_EVENT_KEY(func, field) \ |
| 542 | GET_EVENT_KEY(func, field) \ |
| 543 | static int compare_kvm_event_ ## func(struct kvm_event *one, \ |
| 544 | struct kvm_event *two, int vcpu)\ |
| 545 | { \ |
| 546 | return get_event_ ##func(one, vcpu) > \ |
| 547 | get_event_ ##func(two, vcpu); \ |
| 548 | } |
| 549 | |
| 550 | GET_EVENT_KEY(time, time); |
| 551 | COMPARE_EVENT_KEY(count, stats.n); |
| 552 | COMPARE_EVENT_KEY(mean, stats.mean); |
| 553 | |
| 554 | #define DEF_SORT_NAME_KEY(name, compare_key) \ |
| 555 | { #name, compare_kvm_event_ ## compare_key } |
| 556 | |
| 557 | static struct kvm_event_key keys[] = { |
| 558 | DEF_SORT_NAME_KEY(sample, count), |
| 559 | DEF_SORT_NAME_KEY(time, mean), |
| 560 | { NULL, NULL } |
| 561 | }; |
| 562 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 563 | static bool select_key(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 564 | { |
| 565 | int i; |
| 566 | |
| 567 | for (i = 0; keys[i].name; i++) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 568 | if (!strcmp(keys[i].name, kvm->sort_key)) { |
| 569 | kvm->compare = keys[i].key; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 570 | return true; |
| 571 | } |
| 572 | } |
| 573 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 574 | pr_err("Unknown compare key:%s\n", kvm->sort_key); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 575 | return false; |
| 576 | } |
| 577 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 578 | static void insert_to_result(struct rb_root *result, struct kvm_event *event, |
| 579 | key_cmp_fun bigger, int vcpu) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 580 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 581 | struct rb_node **rb = &result->rb_node; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 582 | struct rb_node *parent = NULL; |
| 583 | struct kvm_event *p; |
| 584 | |
| 585 | while (*rb) { |
| 586 | p = container_of(*rb, struct kvm_event, rb); |
| 587 | parent = *rb; |
| 588 | |
| 589 | if (bigger(event, p, vcpu)) |
| 590 | rb = &(*rb)->rb_left; |
| 591 | else |
| 592 | rb = &(*rb)->rb_right; |
| 593 | } |
| 594 | |
| 595 | rb_link_node(&event->rb, parent, rb); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 596 | rb_insert_color(&event->rb, result); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 597 | } |
| 598 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 599 | static void |
| 600 | update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 601 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 602 | int vcpu = kvm->trace_vcpu; |
| 603 | |
| 604 | kvm->total_count += get_event_count(event, vcpu); |
| 605 | kvm->total_time += get_event_time(event, vcpu); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static bool event_is_valid(struct kvm_event *event, int vcpu) |
| 609 | { |
| 610 | return !!get_event_count(event, vcpu); |
| 611 | } |
| 612 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 613 | static void sort_result(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 614 | { |
| 615 | unsigned int i; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 616 | int vcpu = kvm->trace_vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 617 | struct kvm_event *event; |
| 618 | |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 619 | for (i = 0; i < EVENTS_CACHE_SIZE; i++) { |
| 620 | list_for_each_entry(event, &kvm->kvm_events_cache[i], hash_entry) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 621 | if (event_is_valid(event, vcpu)) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 622 | update_total_count(kvm, event); |
| 623 | insert_to_result(&kvm->result, event, |
| 624 | kvm->compare, vcpu); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 625 | } |
David Ahern | 355afe8 | 2012-10-08 11:17:32 -0600 | [diff] [blame] | 626 | } |
| 627 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* returns left most element of result, and erase it */ |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 631 | static struct kvm_event *pop_from_result(struct rb_root *result) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 632 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 633 | struct rb_node *node = rb_first(result); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 634 | |
| 635 | if (!node) |
| 636 | return NULL; |
| 637 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 638 | rb_erase(node, result); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 639 | return container_of(node, struct kvm_event, rb); |
| 640 | } |
| 641 | |
| 642 | static void print_vcpu_info(int vcpu) |
| 643 | { |
| 644 | pr_info("Analyze events for "); |
| 645 | |
| 646 | if (vcpu == -1) |
| 647 | pr_info("all VCPUs:\n\n"); |
| 648 | else |
| 649 | pr_info("VCPU %d:\n\n", vcpu); |
| 650 | } |
| 651 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 652 | static void print_result(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 653 | { |
| 654 | char decode[20]; |
| 655 | struct kvm_event *event; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 656 | int vcpu = kvm->trace_vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 657 | |
| 658 | pr_info("\n\n"); |
| 659 | print_vcpu_info(vcpu); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 660 | pr_info("%20s ", kvm->events_ops->name); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 661 | pr_info("%10s ", "Samples"); |
| 662 | pr_info("%9s ", "Samples%"); |
| 663 | |
| 664 | pr_info("%9s ", "Time%"); |
| 665 | pr_info("%16s ", "Avg time"); |
| 666 | pr_info("\n\n"); |
| 667 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 668 | while ((event = pop_from_result(&kvm->result))) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 669 | u64 ecount, etime; |
| 670 | |
| 671 | ecount = get_event_count(event, vcpu); |
| 672 | etime = get_event_time(event, vcpu); |
| 673 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 674 | kvm->events_ops->decode_key(kvm, &event->key, decode); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 675 | pr_info("%20s ", decode); |
| 676 | pr_info("%10llu ", (unsigned long long)ecount); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 677 | pr_info("%8.2f%% ", (double)ecount / kvm->total_count * 100); |
| 678 | pr_info("%8.2f%% ", (double)etime / kvm->total_time * 100); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 679 | pr_info("%9.2fus ( +-%7.2f%% )", (double)etime / ecount/1e3, |
| 680 | kvm_event_rel_stddev(vcpu, event)); |
| 681 | pr_info("\n"); |
| 682 | } |
| 683 | |
David Ahern | e4f7637 | 2012-10-08 11:17:34 -0600 | [diff] [blame] | 684 | pr_info("\nTotal Samples:%" PRIu64 ", Total events handled time:%.2fus.\n\n", |
| 685 | kvm->total_count, kvm->total_time / 1e3); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 686 | } |
| 687 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 688 | static int process_sample_event(struct perf_tool *tool, |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 689 | union perf_event *event, |
| 690 | struct perf_sample *sample, |
| 691 | struct perf_evsel *evsel, |
| 692 | struct machine *machine) |
| 693 | { |
| 694 | struct thread *thread = machine__findnew_thread(machine, sample->tid); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 695 | struct perf_kvm_stat *kvm = container_of(tool, struct perf_kvm_stat, |
| 696 | tool); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 697 | |
| 698 | if (thread == NULL) { |
| 699 | pr_debug("problem processing %d event, skipping it.\n", |
| 700 | event->header.type); |
| 701 | return -1; |
| 702 | } |
| 703 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 704 | if (!handle_kvm_event(kvm, thread, evsel, sample)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 705 | return -1; |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 710 | static int get_cpu_isa(struct perf_session *session) |
| 711 | { |
Namhyung Kim | 2f9e97a | 2012-09-24 17:15:02 +0900 | [diff] [blame] | 712 | char *cpuid = session->header.env.cpuid; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 713 | int isa; |
| 714 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 715 | if (strstr(cpuid, "Intel")) |
| 716 | isa = 1; |
| 717 | else if (strstr(cpuid, "AMD")) |
| 718 | isa = 0; |
| 719 | else { |
| 720 | pr_err("CPU %s is not supported.\n", cpuid); |
| 721 | isa = -ENOTSUP; |
| 722 | } |
| 723 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 724 | return isa; |
| 725 | } |
| 726 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 727 | static int read_events(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 728 | { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 729 | int ret; |
| 730 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 731 | struct perf_tool eops = { |
| 732 | .sample = process_sample_event, |
| 733 | .comm = perf_event__process_comm, |
| 734 | .ordered_samples = true, |
| 735 | }; |
| 736 | |
| 737 | kvm->tool = eops; |
| 738 | kvm->session = perf_session__new(kvm->file_name, O_RDONLY, 0, false, |
| 739 | &kvm->tool); |
| 740 | if (!kvm->session) { |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 741 | pr_err("Initializing perf session failed\n"); |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 745 | if (!perf_session__has_traces(kvm->session, "kvm record")) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 746 | return -EINVAL; |
| 747 | |
| 748 | /* |
| 749 | * Do not use 'isa' recorded in kvm_exit tracepoint since it is not |
| 750 | * traced in the old kernel. |
| 751 | */ |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 752 | ret = get_cpu_isa(kvm->session); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 753 | |
| 754 | if (ret < 0) |
| 755 | return ret; |
| 756 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 757 | if (ret == 1) { |
| 758 | kvm->exit_reasons = vmx_exit_reasons; |
| 759 | kvm->exit_reasons_size = ARRAY_SIZE(vmx_exit_reasons); |
| 760 | kvm->exit_reasons_isa = "VMX"; |
| 761 | } |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 762 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 763 | return perf_session__process_events(kvm->session, &kvm->tool); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static bool verify_vcpu(int vcpu) |
| 767 | { |
| 768 | if (vcpu != -1 && vcpu < 0) { |
| 769 | pr_err("Invalid vcpu:%d.\n", vcpu); |
| 770 | return false; |
| 771 | } |
| 772 | |
| 773 | return true; |
| 774 | } |
| 775 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 776 | static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 777 | { |
| 778 | int ret = -EINVAL; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 779 | int vcpu = kvm->trace_vcpu; |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 780 | |
| 781 | if (!verify_vcpu(vcpu)) |
| 782 | goto exit; |
| 783 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 784 | if (!select_key(kvm)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 785 | goto exit; |
| 786 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 787 | if (!register_kvm_events_ops(kvm)) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 788 | goto exit; |
| 789 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 790 | init_kvm_event_record(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 791 | setup_pager(); |
| 792 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 793 | ret = read_events(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 794 | if (ret) |
| 795 | goto exit; |
| 796 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 797 | sort_result(kvm); |
| 798 | print_result(kvm); |
| 799 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 800 | exit: |
| 801 | return ret; |
| 802 | } |
| 803 | |
| 804 | static const char * const record_args[] = { |
| 805 | "record", |
| 806 | "-R", |
| 807 | "-f", |
| 808 | "-m", "1024", |
| 809 | "-c", "1", |
| 810 | "-e", "kvm:kvm_entry", |
| 811 | "-e", "kvm:kvm_exit", |
| 812 | "-e", "kvm:kvm_mmio", |
| 813 | "-e", "kvm:kvm_pio", |
| 814 | }; |
| 815 | |
| 816 | #define STRDUP_FAIL_EXIT(s) \ |
| 817 | ({ char *_p; \ |
| 818 | _p = strdup(s); \ |
| 819 | if (!_p) \ |
| 820 | return -ENOMEM; \ |
| 821 | _p; \ |
| 822 | }) |
| 823 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 824 | static int |
| 825 | kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 826 | { |
| 827 | unsigned int rec_argc, i, j; |
| 828 | const char **rec_argv; |
| 829 | |
| 830 | rec_argc = ARRAY_SIZE(record_args) + argc + 2; |
| 831 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 832 | |
| 833 | if (rec_argv == NULL) |
| 834 | return -ENOMEM; |
| 835 | |
| 836 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 837 | rec_argv[i] = STRDUP_FAIL_EXIT(record_args[i]); |
| 838 | |
| 839 | rec_argv[i++] = STRDUP_FAIL_EXIT("-o"); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 840 | rec_argv[i++] = STRDUP_FAIL_EXIT(kvm->file_name); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 841 | |
| 842 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 843 | rec_argv[i] = argv[j]; |
| 844 | |
| 845 | return cmd_record(i, rec_argv, NULL); |
| 846 | } |
| 847 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 848 | static int |
| 849 | kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 850 | { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 851 | const struct option kvm_events_report_options[] = { |
| 852 | OPT_STRING(0, "event", &kvm->report_event, "report event", |
| 853 | "event for reporting: vmexit, mmio, ioport"), |
| 854 | OPT_INTEGER(0, "vcpu", &kvm->trace_vcpu, |
| 855 | "vcpu id to report"), |
| 856 | OPT_STRING('k', "key", &kvm->sort_key, "sort-key", |
| 857 | "key for sorting: sample(sort by samples number)" |
| 858 | " time (sort by avg time)"), |
| 859 | OPT_END() |
| 860 | }; |
| 861 | |
| 862 | const char * const kvm_events_report_usage[] = { |
| 863 | "perf kvm stat report [<options>]", |
| 864 | NULL |
| 865 | }; |
| 866 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 867 | symbol__init(); |
| 868 | |
| 869 | if (argc) { |
| 870 | argc = parse_options(argc, argv, |
| 871 | kvm_events_report_options, |
| 872 | kvm_events_report_usage, 0); |
| 873 | if (argc) |
| 874 | usage_with_options(kvm_events_report_usage, |
| 875 | kvm_events_report_options); |
| 876 | } |
| 877 | |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 878 | return kvm_events_report_vcpu(kvm); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static void print_kvm_stat_usage(void) |
| 882 | { |
| 883 | printf("Usage: perf kvm stat <command>\n\n"); |
| 884 | |
| 885 | printf("# Available commands:\n"); |
| 886 | printf("\trecord: record kvm events\n"); |
| 887 | printf("\treport: report statistical data of kvm events\n"); |
| 888 | |
| 889 | printf("\nOtherwise, it is the alias of 'perf stat':\n"); |
| 890 | } |
| 891 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 892 | static int kvm_cmd_stat(const char *file_name, int argc, const char **argv) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 893 | { |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 894 | struct perf_kvm_stat kvm = { |
| 895 | .file_name = file_name, |
| 896 | |
| 897 | .trace_vcpu = -1, |
| 898 | .report_event = "vmexit", |
| 899 | .sort_key = "sample", |
| 900 | |
| 901 | .exit_reasons = svm_exit_reasons, |
| 902 | .exit_reasons_size = ARRAY_SIZE(svm_exit_reasons), |
| 903 | .exit_reasons_isa = "SVM", |
| 904 | }; |
| 905 | |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 906 | if (argc == 1) { |
| 907 | print_kvm_stat_usage(); |
| 908 | goto perf_stat; |
| 909 | } |
| 910 | |
| 911 | if (!strncmp(argv[1], "rec", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 912 | return kvm_events_record(&kvm, argc - 1, argv + 1); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 913 | |
| 914 | if (!strncmp(argv[1], "rep", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 915 | return kvm_events_report(&kvm, argc - 1 , argv + 1); |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 916 | |
| 917 | perf_stat: |
| 918 | return cmd_stat(argc, argv, NULL); |
| 919 | } |
Xiao Guangrong | 7321090 | 2012-11-19 16:19:21 +0800 | [diff] [blame] | 920 | #endif |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 921 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 922 | static int __cmd_record(const char *file_name, int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 923 | { |
| 924 | int rec_argc, i = 0, j; |
| 925 | const char **rec_argv; |
| 926 | |
| 927 | rec_argc = argc + 2; |
| 928 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 929 | rec_argv[i++] = strdup("record"); |
| 930 | rec_argv[i++] = strdup("-o"); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 931 | rec_argv[i++] = strdup(file_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 932 | for (j = 1; j < argc; j++, i++) |
| 933 | rec_argv[i] = argv[j]; |
| 934 | |
| 935 | BUG_ON(i != rec_argc); |
| 936 | |
| 937 | return cmd_record(i, rec_argv, NULL); |
| 938 | } |
| 939 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 940 | static int __cmd_report(const char *file_name, int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 941 | { |
| 942 | int rec_argc, i = 0, j; |
| 943 | const char **rec_argv; |
| 944 | |
| 945 | rec_argc = argc + 2; |
| 946 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 947 | rec_argv[i++] = strdup("report"); |
| 948 | rec_argv[i++] = strdup("-i"); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 949 | rec_argv[i++] = strdup(file_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 950 | for (j = 1; j < argc; j++, i++) |
| 951 | rec_argv[i] = argv[j]; |
| 952 | |
| 953 | BUG_ON(i != rec_argc); |
| 954 | |
| 955 | return cmd_report(i, rec_argv, NULL); |
| 956 | } |
| 957 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 958 | static int |
| 959 | __cmd_buildid_list(const char *file_name, int argc, const char **argv) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 960 | { |
| 961 | int rec_argc, i = 0, j; |
| 962 | const char **rec_argv; |
| 963 | |
| 964 | rec_argc = argc + 2; |
| 965 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 966 | rec_argv[i++] = strdup("buildid-list"); |
| 967 | rec_argv[i++] = strdup("-i"); |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 968 | rec_argv[i++] = strdup(file_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 969 | for (j = 1; j < argc; j++, i++) |
| 970 | rec_argv[i] = argv[j]; |
| 971 | |
| 972 | BUG_ON(i != rec_argc); |
| 973 | |
| 974 | return cmd_buildid_list(i, rec_argv, NULL); |
| 975 | } |
| 976 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 977 | int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 978 | { |
Arnaldo Carvalho de Melo | 20914ce5 | 2012-12-19 10:59:29 -0300 | [diff] [blame] | 979 | const char *file_name = NULL; |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 980 | const struct option kvm_options[] = { |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 981 | OPT_STRING('i', "input", &file_name, "file", |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 982 | "Input file name"), |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 983 | OPT_STRING('o', "output", &file_name, "file", |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 984 | "Output file name"), |
| 985 | OPT_BOOLEAN(0, "guest", &perf_guest, |
| 986 | "Collect guest os data"), |
| 987 | OPT_BOOLEAN(0, "host", &perf_host, |
| 988 | "Collect host os data"), |
| 989 | OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", |
| 990 | "guest mount directory under which every guest os" |
| 991 | " instance has a subdir"), |
| 992 | OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name, |
| 993 | "file", "file saving guest os vmlinux"), |
| 994 | OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms, |
| 995 | "file", "file saving guest os /proc/kallsyms"), |
| 996 | OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, |
| 997 | "file", "file saving guest os /proc/modules"), |
| 998 | OPT_END() |
| 999 | }; |
| 1000 | |
| 1001 | |
| 1002 | const char * const kvm_usage[] = { |
| 1003 | "perf kvm [<options>] {top|record|report|diff|buildid-list|stat}", |
| 1004 | NULL |
| 1005 | }; |
| 1006 | |
Joerg Roedel | 1aed267 | 2012-01-04 17:54:20 +0100 | [diff] [blame] | 1007 | perf_host = 0; |
| 1008 | perf_guest = 1; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1009 | |
| 1010 | argc = parse_options(argc, argv, kvm_options, kvm_usage, |
| 1011 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 1012 | if (!argc) |
| 1013 | usage_with_options(kvm_usage, kvm_options); |
| 1014 | |
| 1015 | if (!perf_host) |
| 1016 | perf_guest = 1; |
| 1017 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1018 | if (!file_name) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1019 | if (perf_host && !perf_guest) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1020 | file_name = strdup("perf.data.host"); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1021 | else if (!perf_host && perf_guest) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1022 | file_name = strdup("perf.data.guest"); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1023 | else |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1024 | file_name = strdup("perf.data.kvm"); |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1025 | |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1026 | if (!file_name) { |
David Ahern | de332ac | 2012-10-02 22:09:53 -0600 | [diff] [blame] | 1027 | pr_err("Failed to allocate memory for filename\n"); |
| 1028 | return -ENOMEM; |
| 1029 | } |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | if (!strncmp(argv[0], "rec", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1033 | return __cmd_record(file_name, argc, argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1034 | else if (!strncmp(argv[0], "rep", 3)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1035 | return __cmd_report(file_name, argc, argv); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1036 | else if (!strncmp(argv[0], "diff", 4)) |
| 1037 | return cmd_diff(argc, argv, NULL); |
| 1038 | else if (!strncmp(argv[0], "top", 3)) |
| 1039 | return cmd_top(argc, argv, NULL); |
| 1040 | else if (!strncmp(argv[0], "buildid-list", 12)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1041 | return __cmd_buildid_list(file_name, argc, argv); |
Xiao Guangrong | 7321090 | 2012-11-19 16:19:21 +0800 | [diff] [blame] | 1042 | #if defined(__i386__) || defined(__x86_64__) |
Xiao Guangrong | bcf6edc | 2012-09-17 16:31:15 +0800 | [diff] [blame] | 1043 | else if (!strncmp(argv[0], "stat", 4)) |
Xiao Guangrong | 3786063 | 2012-11-15 14:17:01 +0800 | [diff] [blame] | 1044 | return kvm_cmd_stat(file_name, argc, argv); |
Xiao Guangrong | 7321090 | 2012-11-19 16:19:21 +0800 | [diff] [blame] | 1045 | #endif |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1046 | else |
| 1047 | usage_with_options(kvm_usage, kvm_options); |
| 1048 | |
| 1049 | return 0; |
| 1050 | } |