Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 1 | #include "builtin.h" |
| 2 | #include "perf.h" |
| 3 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 4 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 5 | #include "util/evsel.h" |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 6 | #include "util/util.h" |
| 7 | #include "util/cache.h" |
| 8 | #include "util/symbol.h" |
| 9 | #include "util/thread.h" |
| 10 | #include "util/header.h" |
| 11 | |
| 12 | #include "util/parse-options.h" |
| 13 | #include "util/trace-event.h" |
| 14 | |
| 15 | #include "util/debug.h" |
| 16 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 17 | #include "util/tool.h" |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 18 | |
| 19 | #include <sys/types.h> |
| 20 | #include <sys/prctl.h> |
| 21 | #include <semaphore.h> |
| 22 | #include <pthread.h> |
| 23 | #include <math.h> |
| 24 | #include <limits.h> |
| 25 | |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/hash.h> |
| 28 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 29 | static struct perf_session *session; |
| 30 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 31 | /* based on kernel/lockdep.c */ |
| 32 | #define LOCKHASH_BITS 12 |
| 33 | #define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) |
| 34 | |
| 35 | static struct list_head lockhash_table[LOCKHASH_SIZE]; |
| 36 | |
| 37 | #define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) |
| 38 | #define lockhashentry(key) (lockhash_table + __lockhashfn((key))) |
| 39 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 40 | struct lock_stat { |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 41 | struct list_head hash_entry; |
| 42 | struct rb_node rb; /* used for sorting */ |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 43 | |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 44 | /* |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 45 | * FIXME: perf_evsel__intval() returns u64, |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 46 | * so address of lockdep_map should be dealed as 64bit. |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 47 | * Is there more better solution? |
| 48 | */ |
| 49 | void *addr; /* address of lockdep_map, used as ID */ |
| 50 | char *name; /* for strcpy(), we cannot use const */ |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 51 | |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 52 | unsigned int nr_acquire; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 53 | unsigned int nr_acquired; |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 54 | unsigned int nr_contended; |
| 55 | unsigned int nr_release; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 56 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 57 | unsigned int nr_readlock; |
| 58 | unsigned int nr_trylock; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 59 | /* these times are in nano sec. */ |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 60 | u64 wait_time_total; |
| 61 | u64 wait_time_min; |
| 62 | u64 wait_time_max; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 63 | |
| 64 | int discard; /* flag of blacklist */ |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 65 | }; |
| 66 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 67 | /* |
| 68 | * States of lock_seq_stat |
| 69 | * |
| 70 | * UNINITIALIZED is required for detecting first event of acquire. |
| 71 | * As the nature of lock events, there is no guarantee |
| 72 | * that the first event for the locks are acquire, |
| 73 | * it can be acquired, contended or release. |
| 74 | */ |
| 75 | #define SEQ_STATE_UNINITIALIZED 0 /* initial state */ |
| 76 | #define SEQ_STATE_RELEASED 1 |
| 77 | #define SEQ_STATE_ACQUIRING 2 |
| 78 | #define SEQ_STATE_ACQUIRED 3 |
| 79 | #define SEQ_STATE_READ_ACQUIRED 4 |
| 80 | #define SEQ_STATE_CONTENDED 5 |
| 81 | |
| 82 | /* |
| 83 | * MAX_LOCK_DEPTH |
| 84 | * Imported from include/linux/sched.h. |
| 85 | * Should this be synchronized? |
| 86 | */ |
| 87 | #define MAX_LOCK_DEPTH 48 |
| 88 | |
| 89 | /* |
| 90 | * struct lock_seq_stat: |
| 91 | * Place to put on state of one lock sequence |
| 92 | * 1) acquire -> acquired -> release |
| 93 | * 2) acquire -> contended -> acquired -> release |
| 94 | * 3) acquire (with read or try) -> release |
| 95 | * 4) Are there other patterns? |
| 96 | */ |
| 97 | struct lock_seq_stat { |
| 98 | struct list_head list; |
| 99 | int state; |
| 100 | u64 prev_event_time; |
| 101 | void *addr; |
| 102 | |
| 103 | int read_count; |
| 104 | }; |
| 105 | |
| 106 | struct thread_stat { |
| 107 | struct rb_node rb; |
| 108 | |
| 109 | u32 tid; |
| 110 | struct list_head seq_list; |
| 111 | }; |
| 112 | |
| 113 | static struct rb_root thread_stats; |
| 114 | |
| 115 | static struct thread_stat *thread_stat_find(u32 tid) |
| 116 | { |
| 117 | struct rb_node *node; |
| 118 | struct thread_stat *st; |
| 119 | |
| 120 | node = thread_stats.rb_node; |
| 121 | while (node) { |
| 122 | st = container_of(node, struct thread_stat, rb); |
| 123 | if (st->tid == tid) |
| 124 | return st; |
| 125 | else if (tid < st->tid) |
| 126 | node = node->rb_left; |
| 127 | else |
| 128 | node = node->rb_right; |
| 129 | } |
| 130 | |
| 131 | return NULL; |
| 132 | } |
| 133 | |
| 134 | static void thread_stat_insert(struct thread_stat *new) |
| 135 | { |
| 136 | struct rb_node **rb = &thread_stats.rb_node; |
| 137 | struct rb_node *parent = NULL; |
| 138 | struct thread_stat *p; |
| 139 | |
| 140 | while (*rb) { |
| 141 | p = container_of(*rb, struct thread_stat, rb); |
| 142 | parent = *rb; |
| 143 | |
| 144 | if (new->tid < p->tid) |
| 145 | rb = &(*rb)->rb_left; |
| 146 | else if (new->tid > p->tid) |
| 147 | rb = &(*rb)->rb_right; |
| 148 | else |
| 149 | BUG_ON("inserting invalid thread_stat\n"); |
| 150 | } |
| 151 | |
| 152 | rb_link_node(&new->rb, parent, rb); |
| 153 | rb_insert_color(&new->rb, &thread_stats); |
| 154 | } |
| 155 | |
| 156 | static struct thread_stat *thread_stat_findnew_after_first(u32 tid) |
| 157 | { |
| 158 | struct thread_stat *st; |
| 159 | |
| 160 | st = thread_stat_find(tid); |
| 161 | if (st) |
| 162 | return st; |
| 163 | |
| 164 | st = zalloc(sizeof(struct thread_stat)); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 165 | if (!st) { |
| 166 | pr_err("memory allocation failed\n"); |
| 167 | return NULL; |
| 168 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 169 | |
| 170 | st->tid = tid; |
| 171 | INIT_LIST_HEAD(&st->seq_list); |
| 172 | |
| 173 | thread_stat_insert(st); |
| 174 | |
| 175 | return st; |
| 176 | } |
| 177 | |
| 178 | static struct thread_stat *thread_stat_findnew_first(u32 tid); |
| 179 | static struct thread_stat *(*thread_stat_findnew)(u32 tid) = |
| 180 | thread_stat_findnew_first; |
| 181 | |
| 182 | static struct thread_stat *thread_stat_findnew_first(u32 tid) |
| 183 | { |
| 184 | struct thread_stat *st; |
| 185 | |
| 186 | st = zalloc(sizeof(struct thread_stat)); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 187 | if (!st) { |
| 188 | pr_err("memory allocation failed\n"); |
| 189 | return NULL; |
| 190 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 191 | st->tid = tid; |
| 192 | INIT_LIST_HEAD(&st->seq_list); |
| 193 | |
| 194 | rb_link_node(&st->rb, NULL, &thread_stats.rb_node); |
| 195 | rb_insert_color(&st->rb, &thread_stats); |
| 196 | |
| 197 | thread_stat_findnew = thread_stat_findnew_after_first; |
| 198 | return st; |
| 199 | } |
| 200 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 201 | /* build simple key function one is bigger than two */ |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 202 | #define SINGLE_KEY(member) \ |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 203 | static int lock_stat_key_ ## member(struct lock_stat *one, \ |
| 204 | struct lock_stat *two) \ |
| 205 | { \ |
| 206 | return one->member > two->member; \ |
| 207 | } |
| 208 | |
| 209 | SINGLE_KEY(nr_acquired) |
| 210 | SINGLE_KEY(nr_contended) |
| 211 | SINGLE_KEY(wait_time_total) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 212 | SINGLE_KEY(wait_time_max) |
| 213 | |
Marcin Slusarz | 9df03ab | 2011-02-22 18:47:15 +0100 | [diff] [blame] | 214 | static int lock_stat_key_wait_time_min(struct lock_stat *one, |
| 215 | struct lock_stat *two) |
| 216 | { |
| 217 | u64 s1 = one->wait_time_min; |
| 218 | u64 s2 = two->wait_time_min; |
| 219 | if (s1 == ULLONG_MAX) |
| 220 | s1 = 0; |
| 221 | if (s2 == ULLONG_MAX) |
| 222 | s2 = 0; |
| 223 | return s1 > s2; |
| 224 | } |
| 225 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 226 | struct lock_key { |
| 227 | /* |
| 228 | * name: the value for specify by user |
| 229 | * this should be simpler than raw name of member |
| 230 | * e.g. nr_acquired -> acquired, wait_time_total -> wait_total |
| 231 | */ |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 232 | const char *name; |
| 233 | int (*key)(struct lock_stat*, struct lock_stat*); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 234 | }; |
| 235 | |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 236 | static const char *sort_key = "acquired"; |
| 237 | |
| 238 | static int (*compare)(struct lock_stat *, struct lock_stat *); |
| 239 | |
| 240 | static struct rb_root result; /* place to store sorted data */ |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 241 | |
| 242 | #define DEF_KEY_LOCK(name, fn_suffix) \ |
| 243 | { #name, lock_stat_key_ ## fn_suffix } |
| 244 | struct lock_key keys[] = { |
| 245 | DEF_KEY_LOCK(acquired, nr_acquired), |
| 246 | DEF_KEY_LOCK(contended, nr_contended), |
| 247 | DEF_KEY_LOCK(wait_total, wait_time_total), |
| 248 | DEF_KEY_LOCK(wait_min, wait_time_min), |
| 249 | DEF_KEY_LOCK(wait_max, wait_time_max), |
| 250 | |
| 251 | /* extra comparisons much complicated should be here */ |
| 252 | |
| 253 | { NULL, NULL } |
| 254 | }; |
| 255 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 256 | static int select_key(void) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 257 | { |
| 258 | int i; |
| 259 | |
| 260 | for (i = 0; keys[i].name; i++) { |
| 261 | if (!strcmp(keys[i].name, sort_key)) { |
| 262 | compare = keys[i].key; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 263 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 267 | pr_err("Unknown compare key: %s\n", sort_key); |
| 268 | |
| 269 | return -1; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 270 | } |
| 271 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 272 | static void insert_to_result(struct lock_stat *st, |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 273 | int (*bigger)(struct lock_stat *, struct lock_stat *)) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 274 | { |
| 275 | struct rb_node **rb = &result.rb_node; |
| 276 | struct rb_node *parent = NULL; |
| 277 | struct lock_stat *p; |
| 278 | |
| 279 | while (*rb) { |
| 280 | p = container_of(*rb, struct lock_stat, rb); |
| 281 | parent = *rb; |
| 282 | |
| 283 | if (bigger(st, p)) |
| 284 | rb = &(*rb)->rb_left; |
| 285 | else |
| 286 | rb = &(*rb)->rb_right; |
| 287 | } |
| 288 | |
| 289 | rb_link_node(&st->rb, parent, rb); |
| 290 | rb_insert_color(&st->rb, &result); |
| 291 | } |
| 292 | |
| 293 | /* returns left most element of result, and erase it */ |
| 294 | static struct lock_stat *pop_from_result(void) |
| 295 | { |
| 296 | struct rb_node *node = result.rb_node; |
| 297 | |
| 298 | if (!node) |
| 299 | return NULL; |
| 300 | |
| 301 | while (node->rb_left) |
| 302 | node = node->rb_left; |
| 303 | |
| 304 | rb_erase(node, &result); |
| 305 | return container_of(node, struct lock_stat, rb); |
| 306 | } |
| 307 | |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 308 | static struct lock_stat *lock_stat_findnew(void *addr, const char *name) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 309 | { |
| 310 | struct list_head *entry = lockhashentry(addr); |
| 311 | struct lock_stat *ret, *new; |
| 312 | |
| 313 | list_for_each_entry(ret, entry, hash_entry) { |
| 314 | if (ret->addr == addr) |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | new = zalloc(sizeof(struct lock_stat)); |
| 319 | if (!new) |
| 320 | goto alloc_failed; |
| 321 | |
| 322 | new->addr = addr; |
| 323 | new->name = zalloc(sizeof(char) * strlen(name) + 1); |
| 324 | if (!new->name) |
| 325 | goto alloc_failed; |
| 326 | strcpy(new->name, name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 327 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 328 | new->wait_time_min = ULLONG_MAX; |
| 329 | |
| 330 | list_add(&new->hash_entry, entry); |
| 331 | return new; |
| 332 | |
| 333 | alloc_failed: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 334 | pr_err("memory allocation failed\n"); |
| 335 | return NULL; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 336 | } |
| 337 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 338 | struct trace_lock_handler { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 339 | int (*acquire_event)(struct perf_evsel *evsel, |
| 340 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 341 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 342 | int (*acquired_event)(struct perf_evsel *evsel, |
| 343 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 344 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 345 | int (*contended_event)(struct perf_evsel *evsel, |
| 346 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 347 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 348 | int (*release_event)(struct perf_evsel *evsel, |
| 349 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 350 | }; |
| 351 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 352 | static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr) |
| 353 | { |
| 354 | struct lock_seq_stat *seq; |
| 355 | |
| 356 | list_for_each_entry(seq, &ts->seq_list, list) { |
| 357 | if (seq->addr == addr) |
| 358 | return seq; |
| 359 | } |
| 360 | |
| 361 | seq = zalloc(sizeof(struct lock_seq_stat)); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 362 | if (!seq) { |
| 363 | pr_err("memory allocation failed\n"); |
| 364 | return NULL; |
| 365 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 366 | seq->state = SEQ_STATE_UNINITIALIZED; |
| 367 | seq->addr = addr; |
| 368 | |
| 369 | list_add(&seq->list, &ts->seq_list); |
| 370 | return seq; |
| 371 | } |
| 372 | |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 373 | enum broken_state { |
| 374 | BROKEN_ACQUIRE, |
| 375 | BROKEN_ACQUIRED, |
| 376 | BROKEN_CONTENDED, |
| 377 | BROKEN_RELEASE, |
| 378 | BROKEN_MAX, |
| 379 | }; |
| 380 | |
| 381 | static int bad_hist[BROKEN_MAX]; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 382 | |
Frederic Weisbecker | 84c7a21 | 2010-05-05 23:57:25 +0200 | [diff] [blame] | 383 | enum acquire_flags { |
| 384 | TRY_LOCK = 1, |
| 385 | READ_LOCK = 2, |
| 386 | }; |
| 387 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 388 | static int report_lock_acquire_event(struct perf_evsel *evsel, |
| 389 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 390 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 391 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 392 | struct lock_stat *ls; |
| 393 | struct thread_stat *ts; |
| 394 | struct lock_seq_stat *seq; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 395 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 396 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
| 397 | int flag = perf_evsel__intval(evsel, sample, "flag"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 398 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 399 | memcpy(&addr, &tmp, sizeof(void *)); |
| 400 | |
| 401 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 402 | if (!ls) |
| 403 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 404 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 405 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 406 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 407 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 408 | if (!ts) |
| 409 | return -1; |
| 410 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 411 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 412 | if (!seq) |
| 413 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 414 | |
| 415 | switch (seq->state) { |
| 416 | case SEQ_STATE_UNINITIALIZED: |
| 417 | case SEQ_STATE_RELEASED: |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 418 | if (!flag) { |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 419 | seq->state = SEQ_STATE_ACQUIRING; |
| 420 | } else { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 421 | if (flag & TRY_LOCK) |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 422 | ls->nr_trylock++; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 423 | if (flag & READ_LOCK) |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 424 | ls->nr_readlock++; |
| 425 | seq->state = SEQ_STATE_READ_ACQUIRED; |
| 426 | seq->read_count = 1; |
| 427 | ls->nr_acquired++; |
| 428 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 429 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 430 | case SEQ_STATE_READ_ACQUIRED: |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 431 | if (flag & READ_LOCK) { |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 432 | seq->read_count++; |
| 433 | ls->nr_acquired++; |
| 434 | goto end; |
| 435 | } else { |
| 436 | goto broken; |
| 437 | } |
| 438 | break; |
| 439 | case SEQ_STATE_ACQUIRED: |
| 440 | case SEQ_STATE_ACQUIRING: |
| 441 | case SEQ_STATE_CONTENDED: |
| 442 | broken: |
| 443 | /* broken lock sequence, discard it */ |
| 444 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 445 | bad_hist[BROKEN_ACQUIRE]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 446 | list_del(&seq->list); |
| 447 | free(seq); |
| 448 | goto end; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 449 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 450 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 451 | break; |
| 452 | } |
| 453 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 454 | ls->nr_acquire++; |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 455 | seq->prev_event_time = sample->time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 456 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 457 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 458 | } |
| 459 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 460 | static int report_lock_acquired_event(struct perf_evsel *evsel, |
| 461 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 462 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 463 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 464 | struct lock_stat *ls; |
| 465 | struct thread_stat *ts; |
| 466 | struct lock_seq_stat *seq; |
| 467 | u64 contended_term; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 468 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 469 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 470 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 471 | memcpy(&addr, &tmp, sizeof(void *)); |
| 472 | |
| 473 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 474 | if (!ls) |
| 475 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 476 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 477 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 478 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 479 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 480 | if (!ts) |
| 481 | return -1; |
| 482 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 483 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 484 | if (!seq) |
| 485 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 486 | |
| 487 | switch (seq->state) { |
| 488 | case SEQ_STATE_UNINITIALIZED: |
| 489 | /* orphan event, do nothing */ |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 490 | return 0; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 491 | case SEQ_STATE_ACQUIRING: |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 492 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 493 | case SEQ_STATE_CONTENDED: |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 494 | contended_term = sample->time - seq->prev_event_time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 495 | ls->wait_time_total += contended_term; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 496 | if (contended_term < ls->wait_time_min) |
| 497 | ls->wait_time_min = contended_term; |
Frederic Weisbecker | 90c0e5f | 2010-05-07 02:33:42 +0200 | [diff] [blame] | 498 | if (ls->wait_time_max < contended_term) |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 499 | ls->wait_time_max = contended_term; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 500 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 501 | case SEQ_STATE_RELEASED: |
| 502 | case SEQ_STATE_ACQUIRED: |
| 503 | case SEQ_STATE_READ_ACQUIRED: |
| 504 | /* broken lock sequence, discard it */ |
| 505 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 506 | bad_hist[BROKEN_ACQUIRED]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 507 | list_del(&seq->list); |
| 508 | free(seq); |
| 509 | goto end; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 510 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 511 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 512 | break; |
| 513 | } |
| 514 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 515 | seq->state = SEQ_STATE_ACQUIRED; |
| 516 | ls->nr_acquired++; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 517 | seq->prev_event_time = sample->time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 518 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 519 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 520 | } |
| 521 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 522 | static int report_lock_contended_event(struct perf_evsel *evsel, |
| 523 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 524 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 525 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 526 | struct lock_stat *ls; |
| 527 | struct thread_stat *ts; |
| 528 | struct lock_seq_stat *seq; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 529 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 530 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 531 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 532 | memcpy(&addr, &tmp, sizeof(void *)); |
| 533 | |
| 534 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 535 | if (!ls) |
| 536 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 537 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 538 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 539 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 540 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 541 | if (!ts) |
| 542 | return -1; |
| 543 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 544 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 545 | if (!seq) |
| 546 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 547 | |
| 548 | switch (seq->state) { |
| 549 | case SEQ_STATE_UNINITIALIZED: |
| 550 | /* orphan event, do nothing */ |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 551 | return 0; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 552 | case SEQ_STATE_ACQUIRING: |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 553 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 554 | case SEQ_STATE_RELEASED: |
| 555 | case SEQ_STATE_ACQUIRED: |
| 556 | case SEQ_STATE_READ_ACQUIRED: |
| 557 | case SEQ_STATE_CONTENDED: |
| 558 | /* broken lock sequence, discard it */ |
| 559 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 560 | bad_hist[BROKEN_CONTENDED]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 561 | list_del(&seq->list); |
| 562 | free(seq); |
| 563 | goto end; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 564 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 565 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 566 | break; |
| 567 | } |
| 568 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 569 | seq->state = SEQ_STATE_CONTENDED; |
| 570 | ls->nr_contended++; |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 571 | seq->prev_event_time = sample->time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 572 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 573 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 574 | } |
| 575 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 576 | static int report_lock_release_event(struct perf_evsel *evsel, |
| 577 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 578 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 579 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 580 | struct lock_stat *ls; |
| 581 | struct thread_stat *ts; |
| 582 | struct lock_seq_stat *seq; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 583 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 584 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 585 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 586 | memcpy(&addr, &tmp, sizeof(void *)); |
| 587 | |
| 588 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 589 | if (!ls) |
| 590 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 591 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 592 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 593 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 594 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 595 | if (!ts) |
| 596 | return -1; |
| 597 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 598 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 599 | if (!seq) |
| 600 | return -1; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 601 | |
| 602 | switch (seq->state) { |
| 603 | case SEQ_STATE_UNINITIALIZED: |
| 604 | goto end; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 605 | case SEQ_STATE_ACQUIRED: |
| 606 | break; |
| 607 | case SEQ_STATE_READ_ACQUIRED: |
| 608 | seq->read_count--; |
| 609 | BUG_ON(seq->read_count < 0); |
| 610 | if (!seq->read_count) { |
| 611 | ls->nr_release++; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 612 | goto end; |
| 613 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 614 | break; |
| 615 | case SEQ_STATE_ACQUIRING: |
| 616 | case SEQ_STATE_CONTENDED: |
| 617 | case SEQ_STATE_RELEASED: |
| 618 | /* broken lock sequence, discard it */ |
| 619 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 620 | bad_hist[BROKEN_RELEASE]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 621 | goto free_seq; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 622 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 623 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 624 | break; |
| 625 | } |
| 626 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 627 | ls->nr_release++; |
| 628 | free_seq: |
| 629 | list_del(&seq->list); |
| 630 | free(seq); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 631 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 632 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* lock oriented handlers */ |
| 636 | /* TODO: handlers for CPU oriented, thread oriented */ |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 637 | static struct trace_lock_handler report_lock_ops = { |
| 638 | .acquire_event = report_lock_acquire_event, |
| 639 | .acquired_event = report_lock_acquired_event, |
| 640 | .contended_event = report_lock_contended_event, |
| 641 | .release_event = report_lock_release_event, |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | static struct trace_lock_handler *trace_handler; |
| 645 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 646 | static int perf_evsel__process_lock_acquire(struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 647 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 648 | { |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 649 | if (trace_handler->acquire_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 650 | return trace_handler->acquire_event(evsel, sample); |
| 651 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 652 | } |
| 653 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 654 | static int perf_evsel__process_lock_acquired(struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 655 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 656 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 657 | if (trace_handler->acquired_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 658 | return trace_handler->acquired_event(evsel, sample); |
| 659 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 660 | } |
| 661 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 662 | static int perf_evsel__process_lock_contended(struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 663 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 664 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 665 | if (trace_handler->contended_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 666 | return trace_handler->contended_event(evsel, sample); |
| 667 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 668 | } |
| 669 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 670 | static int perf_evsel__process_lock_release(struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 671 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 672 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 673 | if (trace_handler->release_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 674 | return trace_handler->release_event(evsel, sample); |
| 675 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 676 | } |
| 677 | |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 678 | static void print_bad_events(int bad, int total) |
| 679 | { |
| 680 | /* Output for debug, this have to be removed */ |
| 681 | int i; |
| 682 | const char *name[4] = |
| 683 | { "acquire", "acquired", "contended", "release" }; |
| 684 | |
| 685 | pr_info("\n=== output for debug===\n\n"); |
Frederic Weisbecker | 5efe08c | 2010-05-06 04:55:22 +0200 | [diff] [blame] | 686 | pr_info("bad: %d, total: %d\n", bad, total); |
| 687 | pr_info("bad rate: %f %%\n", (double)bad / (double)total * 100); |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 688 | pr_info("histogram of events caused bad sequence\n"); |
| 689 | for (i = 0; i < BROKEN_MAX; i++) |
| 690 | pr_info(" %10s: %d\n", name[i], bad_hist[i]); |
| 691 | } |
| 692 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 693 | /* TODO: various way to print, coloring, nano or milli sec */ |
| 694 | static void print_result(void) |
| 695 | { |
| 696 | struct lock_stat *st; |
| 697 | char cut_name[20]; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 698 | int bad, total; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 699 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 700 | pr_info("%20s ", "Name"); |
| 701 | pr_info("%10s ", "acquired"); |
| 702 | pr_info("%10s ", "contended"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 703 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 704 | pr_info("%15s ", "total wait (ns)"); |
| 705 | pr_info("%15s ", "max wait (ns)"); |
| 706 | pr_info("%15s ", "min wait (ns)"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 707 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 708 | pr_info("\n\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 709 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 710 | bad = total = 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 711 | while ((st = pop_from_result())) { |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 712 | total++; |
| 713 | if (st->discard) { |
| 714 | bad++; |
| 715 | continue; |
| 716 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 717 | bzero(cut_name, 20); |
| 718 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 719 | if (strlen(st->name) < 16) { |
| 720 | /* output raw name */ |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 721 | pr_info("%20s ", st->name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 722 | } else { |
| 723 | strncpy(cut_name, st->name, 16); |
| 724 | cut_name[16] = '.'; |
| 725 | cut_name[17] = '.'; |
| 726 | cut_name[18] = '.'; |
| 727 | cut_name[19] = '\0'; |
| 728 | /* cut off name for saving output style */ |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 729 | pr_info("%20s ", cut_name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 730 | } |
| 731 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 732 | pr_info("%10u ", st->nr_acquired); |
| 733 | pr_info("%10u ", st->nr_contended); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 734 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 735 | pr_info("%15" PRIu64 " ", st->wait_time_total); |
| 736 | pr_info("%15" PRIu64 " ", st->wait_time_max); |
| 737 | pr_info("%15" PRIu64 " ", st->wait_time_min == ULLONG_MAX ? |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 738 | 0 : st->wait_time_min); |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 739 | pr_info("\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 740 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 741 | |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 742 | print_bad_events(bad, total); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 743 | } |
| 744 | |
Arnaldo Carvalho de Melo | 8035458 | 2010-05-17 15:51:10 -0300 | [diff] [blame] | 745 | static bool info_threads, info_map; |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 746 | |
| 747 | static void dump_threads(void) |
| 748 | { |
| 749 | struct thread_stat *st; |
| 750 | struct rb_node *node; |
| 751 | struct thread *t; |
| 752 | |
| 753 | pr_info("%10s: comm\n", "Thread ID"); |
| 754 | |
| 755 | node = rb_first(&thread_stats); |
| 756 | while (node) { |
| 757 | st = container_of(node, struct thread_stat, rb); |
| 758 | t = perf_session__findnew(session, st->tid); |
| 759 | pr_info("%10d: %s\n", st->tid, t->comm); |
| 760 | node = rb_next(node); |
| 761 | }; |
| 762 | } |
| 763 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 764 | static void dump_map(void) |
| 765 | { |
| 766 | unsigned int i; |
| 767 | struct lock_stat *st; |
| 768 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 769 | pr_info("Address of instance: name of class\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 770 | for (i = 0; i < LOCKHASH_SIZE; i++) { |
| 771 | list_for_each_entry(st, &lockhash_table[i], hash_entry) { |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 772 | pr_info(" %p: %s\n", st->addr, st->name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 777 | static int dump_info(void) |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 778 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 779 | int rc = 0; |
| 780 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 781 | if (info_threads) |
| 782 | dump_threads(); |
| 783 | else if (info_map) |
| 784 | dump_map(); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 785 | else { |
| 786 | rc = -1; |
| 787 | pr_err("Unknown type of information\n"); |
| 788 | } |
| 789 | |
| 790 | return rc; |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 791 | } |
| 792 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 793 | typedef int (*tracepoint_handler)(struct perf_evsel *evsel, |
| 794 | struct perf_sample *sample); |
| 795 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 796 | static int process_sample_event(struct perf_tool *tool __maybe_unused, |
Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 797 | union perf_event *event, |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 798 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 799 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 800 | struct machine *machine) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 801 | { |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 802 | struct thread *thread = machine__findnew_thread(machine, sample->pid, |
| 803 | sample->tid); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 804 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 805 | if (thread == NULL) { |
| 806 | pr_debug("problem processing %d event, skipping it.\n", |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 807 | event->header.type); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 808 | return -1; |
| 809 | } |
| 810 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 811 | if (evsel->handler.func != NULL) { |
| 812 | tracepoint_handler f = evsel->handler.func; |
| 813 | return f(evsel, sample); |
| 814 | } |
| 815 | |
| 816 | return 0; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 817 | } |
| 818 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 819 | static const struct perf_evsel_str_handler lock_tracepoints[] = { |
| 820 | { "lock:lock_acquire", perf_evsel__process_lock_acquire, }, /* CONFIG_LOCKDEP */ |
| 821 | { "lock:lock_acquired", perf_evsel__process_lock_acquired, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */ |
| 822 | { "lock:lock_contended", perf_evsel__process_lock_contended, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */ |
| 823 | { "lock:lock_release", perf_evsel__process_lock_release, }, /* CONFIG_LOCKDEP */ |
| 824 | }; |
| 825 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 826 | static int read_events(void) |
| 827 | { |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 828 | struct perf_tool eops = { |
| 829 | .sample = process_sample_event, |
| 830 | .comm = perf_event__process_comm, |
| 831 | .ordered_samples = true, |
| 832 | }; |
Ian Munsie | 21ef97f | 2010-12-10 14:09:16 +1100 | [diff] [blame] | 833 | session = perf_session__new(input_name, O_RDONLY, 0, false, &eops); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 834 | if (!session) { |
| 835 | pr_err("Initializing perf session failed\n"); |
| 836 | return -1; |
| 837 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 838 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 839 | if (perf_session__set_tracepoints_handlers(session, lock_tracepoints)) { |
| 840 | pr_err("Initializing perf session tracepoint handlers failed\n"); |
| 841 | return -1; |
| 842 | } |
| 843 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 844 | return perf_session__process_events(session, &eops); |
| 845 | } |
| 846 | |
| 847 | static void sort_result(void) |
| 848 | { |
| 849 | unsigned int i; |
| 850 | struct lock_stat *st; |
| 851 | |
| 852 | for (i = 0; i < LOCKHASH_SIZE; i++) { |
| 853 | list_for_each_entry(st, &lockhash_table[i], hash_entry) { |
| 854 | insert_to_result(st, compare); |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 859 | static int __cmd_report(void) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 860 | { |
| 861 | setup_pager(); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 862 | |
| 863 | if ((select_key() != 0) || |
| 864 | (read_events() != 0)) |
| 865 | return -1; |
| 866 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 867 | sort_result(); |
| 868 | print_result(); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 869 | |
| 870 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 871 | } |
| 872 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 873 | static int __cmd_record(int argc, const char **argv) |
| 874 | { |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 875 | const char *record_args[] = { |
Jiri Olsa | 4a4d371 | 2013-06-05 13:37:21 +0200 | [diff] [blame] | 876 | "record", "-R", "-m", "1024", "-c", "1", |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 877 | }; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 878 | unsigned int rec_argc, i, j; |
| 879 | const char **rec_argv; |
| 880 | |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 881 | for (i = 0; i < ARRAY_SIZE(lock_tracepoints); i++) { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 882 | if (!is_valid_tracepoint(lock_tracepoints[i].name)) { |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 883 | pr_err("tracepoint %s is not enabled. " |
| 884 | "Are CONFIG_LOCKDEP and CONFIG_LOCK_STAT enabled?\n", |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 885 | lock_tracepoints[i].name); |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 886 | return 1; |
| 887 | } |
| 888 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 889 | |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 890 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; |
| 891 | /* factor of 2 is for -e in front of each tracepoint */ |
| 892 | rec_argc += 2 * ARRAY_SIZE(lock_tracepoints); |
| 893 | |
| 894 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
Chris Samuel | ce47dc5 | 2010-11-13 13:35:06 +1100 | [diff] [blame] | 895 | if (rec_argv == NULL) |
| 896 | return -ENOMEM; |
| 897 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 898 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 899 | rec_argv[i] = strdup(record_args[i]); |
| 900 | |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 901 | for (j = 0; j < ARRAY_SIZE(lock_tracepoints); j++) { |
| 902 | rec_argv[i++] = "-e"; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 903 | rec_argv[i++] = strdup(lock_tracepoints[j].name); |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 904 | } |
| 905 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 906 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 907 | rec_argv[i] = argv[j]; |
| 908 | |
| 909 | BUG_ON(i != rec_argc); |
| 910 | |
| 911 | return cmd_record(i, rec_argv, NULL); |
| 912 | } |
| 913 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 914 | int cmd_lock(int argc, const char **argv, const char *prefix __maybe_unused) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 915 | { |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 916 | const struct option info_options[] = { |
| 917 | OPT_BOOLEAN('t', "threads", &info_threads, |
| 918 | "dump thread list in perf.data"), |
| 919 | OPT_BOOLEAN('m', "map", &info_map, |
| 920 | "map of lock instances (address:name table)"), |
| 921 | OPT_END() |
| 922 | }; |
| 923 | const struct option lock_options[] = { |
| 924 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
| 925 | OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"), |
| 926 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"), |
| 927 | OPT_END() |
| 928 | }; |
| 929 | const struct option report_options[] = { |
| 930 | OPT_STRING('k', "key", &sort_key, "acquired", |
| 931 | "key for sorting (acquired / contended / wait_total / wait_max / wait_min)"), |
| 932 | /* TODO: type */ |
| 933 | OPT_END() |
| 934 | }; |
| 935 | const char * const info_usage[] = { |
| 936 | "perf lock info [<options>]", |
| 937 | NULL |
| 938 | }; |
| 939 | const char * const lock_usage[] = { |
| 940 | "perf lock [<options>] {record|report|script|info}", |
| 941 | NULL |
| 942 | }; |
| 943 | const char * const report_usage[] = { |
| 944 | "perf lock report [<options>]", |
| 945 | NULL |
| 946 | }; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 947 | unsigned int i; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 948 | int rc = 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 949 | |
| 950 | symbol__init(); |
| 951 | for (i = 0; i < LOCKHASH_SIZE; i++) |
| 952 | INIT_LIST_HEAD(lockhash_table + i); |
| 953 | |
| 954 | argc = parse_options(argc, argv, lock_options, lock_usage, |
| 955 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 956 | if (!argc) |
| 957 | usage_with_options(lock_usage, lock_options); |
| 958 | |
| 959 | if (!strncmp(argv[0], "rec", 3)) { |
| 960 | return __cmd_record(argc, argv); |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 961 | } else if (!strncmp(argv[0], "report", 6)) { |
| 962 | trace_handler = &report_lock_ops; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 963 | if (argc) { |
| 964 | argc = parse_options(argc, argv, |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 965 | report_options, report_usage, 0); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 966 | if (argc) |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 967 | usage_with_options(report_usage, report_options); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 968 | } |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 969 | __cmd_report(); |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 970 | } else if (!strcmp(argv[0], "script")) { |
| 971 | /* Aliased to 'perf script' */ |
| 972 | return cmd_script(argc, argv, prefix); |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 973 | } else if (!strcmp(argv[0], "info")) { |
| 974 | if (argc) { |
| 975 | argc = parse_options(argc, argv, |
| 976 | info_options, info_usage, 0); |
| 977 | if (argc) |
| 978 | usage_with_options(info_usage, info_options); |
| 979 | } |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 980 | /* recycling report_lock_ops */ |
| 981 | trace_handler = &report_lock_ops; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 982 | setup_pager(); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 983 | if (read_events() != 0) |
| 984 | rc = -1; |
| 985 | else |
| 986 | rc = dump_info(); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 987 | } else { |
| 988 | usage_with_options(lock_usage, lock_options); |
| 989 | } |
| 990 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 991 | return rc; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 992 | } |