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); |
Davidlohr Bueso | 0a98c7f | 2013-09-08 19:19:15 -0700 | [diff] [blame] | 324 | if (!new->name) { |
| 325 | free(new); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 326 | goto alloc_failed; |
Davidlohr Bueso | 0a98c7f | 2013-09-08 19:19:15 -0700 | [diff] [blame] | 327 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 328 | |
Davidlohr Bueso | 0a98c7f | 2013-09-08 19:19:15 -0700 | [diff] [blame] | 329 | strcpy(new->name, name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 330 | new->wait_time_min = ULLONG_MAX; |
| 331 | |
| 332 | list_add(&new->hash_entry, entry); |
| 333 | return new; |
| 334 | |
| 335 | alloc_failed: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 336 | pr_err("memory allocation failed\n"); |
| 337 | return NULL; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 338 | } |
| 339 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 340 | struct trace_lock_handler { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 341 | int (*acquire_event)(struct perf_evsel *evsel, |
| 342 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 343 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 344 | int (*acquired_event)(struct perf_evsel *evsel, |
| 345 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 346 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 347 | int (*contended_event)(struct perf_evsel *evsel, |
| 348 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 349 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 350 | int (*release_event)(struct perf_evsel *evsel, |
| 351 | struct perf_sample *sample); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 352 | }; |
| 353 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 354 | static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr) |
| 355 | { |
| 356 | struct lock_seq_stat *seq; |
| 357 | |
| 358 | list_for_each_entry(seq, &ts->seq_list, list) { |
| 359 | if (seq->addr == addr) |
| 360 | return seq; |
| 361 | } |
| 362 | |
| 363 | seq = zalloc(sizeof(struct lock_seq_stat)); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 364 | if (!seq) { |
| 365 | pr_err("memory allocation failed\n"); |
| 366 | return NULL; |
| 367 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 368 | seq->state = SEQ_STATE_UNINITIALIZED; |
| 369 | seq->addr = addr; |
| 370 | |
| 371 | list_add(&seq->list, &ts->seq_list); |
| 372 | return seq; |
| 373 | } |
| 374 | |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 375 | enum broken_state { |
| 376 | BROKEN_ACQUIRE, |
| 377 | BROKEN_ACQUIRED, |
| 378 | BROKEN_CONTENDED, |
| 379 | BROKEN_RELEASE, |
| 380 | BROKEN_MAX, |
| 381 | }; |
| 382 | |
| 383 | static int bad_hist[BROKEN_MAX]; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 384 | |
Frederic Weisbecker | 84c7a21 | 2010-05-05 23:57:25 +0200 | [diff] [blame] | 385 | enum acquire_flags { |
| 386 | TRY_LOCK = 1, |
| 387 | READ_LOCK = 2, |
| 388 | }; |
| 389 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 390 | static int report_lock_acquire_event(struct perf_evsel *evsel, |
| 391 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 392 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 393 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 394 | struct lock_stat *ls; |
| 395 | struct thread_stat *ts; |
| 396 | struct lock_seq_stat *seq; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 397 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 398 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
| 399 | int flag = perf_evsel__intval(evsel, sample, "flag"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 400 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 401 | memcpy(&addr, &tmp, sizeof(void *)); |
| 402 | |
| 403 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 404 | if (!ls) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 405 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 406 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 407 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 408 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 409 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 410 | if (!ts) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 411 | return -ENOMEM; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 412 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 413 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 414 | if (!seq) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 415 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 416 | |
| 417 | switch (seq->state) { |
| 418 | case SEQ_STATE_UNINITIALIZED: |
| 419 | case SEQ_STATE_RELEASED: |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 420 | if (!flag) { |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 421 | seq->state = SEQ_STATE_ACQUIRING; |
| 422 | } else { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 423 | if (flag & TRY_LOCK) |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 424 | ls->nr_trylock++; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 425 | if (flag & READ_LOCK) |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 426 | ls->nr_readlock++; |
| 427 | seq->state = SEQ_STATE_READ_ACQUIRED; |
| 428 | seq->read_count = 1; |
| 429 | ls->nr_acquired++; |
| 430 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 431 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 432 | case SEQ_STATE_READ_ACQUIRED: |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 433 | if (flag & READ_LOCK) { |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 434 | seq->read_count++; |
| 435 | ls->nr_acquired++; |
| 436 | goto end; |
| 437 | } else { |
| 438 | goto broken; |
| 439 | } |
| 440 | break; |
| 441 | case SEQ_STATE_ACQUIRED: |
| 442 | case SEQ_STATE_ACQUIRING: |
| 443 | case SEQ_STATE_CONTENDED: |
| 444 | broken: |
| 445 | /* broken lock sequence, discard it */ |
| 446 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 447 | bad_hist[BROKEN_ACQUIRE]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 448 | list_del(&seq->list); |
| 449 | free(seq); |
| 450 | goto end; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 451 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 452 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 453 | break; |
| 454 | } |
| 455 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 456 | ls->nr_acquire++; |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 457 | seq->prev_event_time = sample->time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 458 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 459 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 460 | } |
| 461 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 462 | static int report_lock_acquired_event(struct perf_evsel *evsel, |
| 463 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 464 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 465 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 466 | struct lock_stat *ls; |
| 467 | struct thread_stat *ts; |
| 468 | struct lock_seq_stat *seq; |
| 469 | u64 contended_term; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 470 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 471 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 472 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 473 | memcpy(&addr, &tmp, sizeof(void *)); |
| 474 | |
| 475 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 476 | if (!ls) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 477 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 478 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 479 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 480 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 481 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 482 | if (!ts) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 483 | return -ENOMEM; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 484 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 485 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 486 | if (!seq) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 487 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 488 | |
| 489 | switch (seq->state) { |
| 490 | case SEQ_STATE_UNINITIALIZED: |
| 491 | /* orphan event, do nothing */ |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 492 | return 0; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 493 | case SEQ_STATE_ACQUIRING: |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 494 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 495 | case SEQ_STATE_CONTENDED: |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 496 | contended_term = sample->time - seq->prev_event_time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 497 | ls->wait_time_total += contended_term; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 498 | if (contended_term < ls->wait_time_min) |
| 499 | ls->wait_time_min = contended_term; |
Frederic Weisbecker | 90c0e5f | 2010-05-07 02:33:42 +0200 | [diff] [blame] | 500 | if (ls->wait_time_max < contended_term) |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 501 | ls->wait_time_max = contended_term; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 502 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 503 | case SEQ_STATE_RELEASED: |
| 504 | case SEQ_STATE_ACQUIRED: |
| 505 | case SEQ_STATE_READ_ACQUIRED: |
| 506 | /* broken lock sequence, discard it */ |
| 507 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 508 | bad_hist[BROKEN_ACQUIRED]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 509 | list_del(&seq->list); |
| 510 | free(seq); |
| 511 | goto end; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 512 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 513 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 514 | break; |
| 515 | } |
| 516 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 517 | seq->state = SEQ_STATE_ACQUIRED; |
| 518 | ls->nr_acquired++; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 519 | seq->prev_event_time = sample->time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 520 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 521 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 522 | } |
| 523 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 524 | static int report_lock_contended_event(struct perf_evsel *evsel, |
| 525 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 526 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 527 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 528 | struct lock_stat *ls; |
| 529 | struct thread_stat *ts; |
| 530 | struct lock_seq_stat *seq; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 531 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 532 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 533 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 534 | memcpy(&addr, &tmp, sizeof(void *)); |
| 535 | |
| 536 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 537 | if (!ls) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 538 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 539 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 540 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 541 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 542 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 543 | if (!ts) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 544 | return -ENOMEM; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 545 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 546 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 547 | if (!seq) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 548 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 549 | |
| 550 | switch (seq->state) { |
| 551 | case SEQ_STATE_UNINITIALIZED: |
| 552 | /* orphan event, do nothing */ |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 553 | return 0; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 554 | case SEQ_STATE_ACQUIRING: |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 555 | break; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 556 | case SEQ_STATE_RELEASED: |
| 557 | case SEQ_STATE_ACQUIRED: |
| 558 | case SEQ_STATE_READ_ACQUIRED: |
| 559 | case SEQ_STATE_CONTENDED: |
| 560 | /* broken lock sequence, discard it */ |
| 561 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 562 | bad_hist[BROKEN_CONTENDED]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 563 | list_del(&seq->list); |
| 564 | free(seq); |
| 565 | goto end; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 566 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 567 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 568 | break; |
| 569 | } |
| 570 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 571 | seq->state = SEQ_STATE_CONTENDED; |
| 572 | ls->nr_contended++; |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 573 | seq->prev_event_time = sample->time; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 574 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 575 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 576 | } |
| 577 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 578 | static int report_lock_release_event(struct perf_evsel *evsel, |
| 579 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 580 | { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 581 | void *addr; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 582 | struct lock_stat *ls; |
| 583 | struct thread_stat *ts; |
| 584 | struct lock_seq_stat *seq; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 585 | const char *name = perf_evsel__strval(evsel, sample, "name"); |
| 586 | u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 587 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 588 | memcpy(&addr, &tmp, sizeof(void *)); |
| 589 | |
| 590 | ls = lock_stat_findnew(addr, name); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 591 | if (!ls) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 592 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 593 | if (ls->discard) |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 594 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 595 | |
Arnaldo Carvalho de Melo | 01d9552 | 2012-08-07 10:59:44 -0300 | [diff] [blame] | 596 | ts = thread_stat_findnew(sample->tid); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 597 | if (!ts) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 598 | return -ENOMEM; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 599 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 600 | seq = get_seq(ts, addr); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 601 | if (!seq) |
Davidlohr Bueso | b33492a | 2013-09-08 19:19:14 -0700 | [diff] [blame] | 602 | return -ENOMEM; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 603 | |
| 604 | switch (seq->state) { |
| 605 | case SEQ_STATE_UNINITIALIZED: |
| 606 | goto end; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 607 | case SEQ_STATE_ACQUIRED: |
| 608 | break; |
| 609 | case SEQ_STATE_READ_ACQUIRED: |
| 610 | seq->read_count--; |
| 611 | BUG_ON(seq->read_count < 0); |
| 612 | if (!seq->read_count) { |
| 613 | ls->nr_release++; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 614 | goto end; |
| 615 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 616 | break; |
| 617 | case SEQ_STATE_ACQUIRING: |
| 618 | case SEQ_STATE_CONTENDED: |
| 619 | case SEQ_STATE_RELEASED: |
| 620 | /* broken lock sequence, discard it */ |
| 621 | ls->discard = 1; |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 622 | bad_hist[BROKEN_RELEASE]++; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 623 | goto free_seq; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 624 | default: |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 625 | BUG_ON("Unknown state of lock sequence found!\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 626 | break; |
| 627 | } |
| 628 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 629 | ls->nr_release++; |
| 630 | free_seq: |
| 631 | list_del(&seq->list); |
| 632 | free(seq); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 633 | end: |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 634 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /* lock oriented handlers */ |
| 638 | /* TODO: handlers for CPU oriented, thread oriented */ |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 639 | static struct trace_lock_handler report_lock_ops = { |
| 640 | .acquire_event = report_lock_acquire_event, |
| 641 | .acquired_event = report_lock_acquired_event, |
| 642 | .contended_event = report_lock_contended_event, |
| 643 | .release_event = report_lock_release_event, |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 644 | }; |
| 645 | |
| 646 | static struct trace_lock_handler *trace_handler; |
| 647 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 648 | 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] | 649 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 650 | { |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 651 | if (trace_handler->acquire_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 652 | return trace_handler->acquire_event(evsel, sample); |
| 653 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 654 | } |
| 655 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 656 | 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] | 657 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 658 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 659 | if (trace_handler->acquired_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 660 | return trace_handler->acquired_event(evsel, sample); |
| 661 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 662 | } |
| 663 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 664 | 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] | 665 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 666 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 667 | if (trace_handler->contended_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 668 | return trace_handler->contended_event(evsel, sample); |
| 669 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 670 | } |
| 671 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 672 | 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] | 673 | struct perf_sample *sample) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 674 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 675 | if (trace_handler->release_event) |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 676 | return trace_handler->release_event(evsel, sample); |
| 677 | return 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 678 | } |
| 679 | |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 680 | static void print_bad_events(int bad, int total) |
| 681 | { |
| 682 | /* Output for debug, this have to be removed */ |
| 683 | int i; |
| 684 | const char *name[4] = |
| 685 | { "acquire", "acquired", "contended", "release" }; |
| 686 | |
| 687 | pr_info("\n=== output for debug===\n\n"); |
Frederic Weisbecker | 5efe08c | 2010-05-06 04:55:22 +0200 | [diff] [blame] | 688 | pr_info("bad: %d, total: %d\n", bad, total); |
Davidlohr Bueso | 60a25cb | 2013-09-08 19:19:18 -0700 | [diff] [blame^] | 689 | pr_info("bad rate: %.2f %%\n", (double)bad / (double)total * 100); |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 690 | pr_info("histogram of events caused bad sequence\n"); |
| 691 | for (i = 0; i < BROKEN_MAX; i++) |
| 692 | pr_info(" %10s: %d\n", name[i], bad_hist[i]); |
| 693 | } |
| 694 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 695 | /* TODO: various way to print, coloring, nano or milli sec */ |
| 696 | static void print_result(void) |
| 697 | { |
| 698 | struct lock_stat *st; |
| 699 | char cut_name[20]; |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 700 | int bad, total; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 701 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 702 | pr_info("%20s ", "Name"); |
| 703 | pr_info("%10s ", "acquired"); |
| 704 | pr_info("%10s ", "contended"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 705 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 706 | pr_info("%15s ", "total wait (ns)"); |
| 707 | pr_info("%15s ", "max wait (ns)"); |
| 708 | pr_info("%15s ", "min wait (ns)"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 709 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 710 | pr_info("\n\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 711 | |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 712 | bad = total = 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 713 | while ((st = pop_from_result())) { |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 714 | total++; |
| 715 | if (st->discard) { |
| 716 | bad++; |
| 717 | continue; |
| 718 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 719 | bzero(cut_name, 20); |
| 720 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 721 | if (strlen(st->name) < 16) { |
| 722 | /* output raw name */ |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 723 | pr_info("%20s ", st->name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 724 | } else { |
| 725 | strncpy(cut_name, st->name, 16); |
| 726 | cut_name[16] = '.'; |
| 727 | cut_name[17] = '.'; |
| 728 | cut_name[18] = '.'; |
| 729 | cut_name[19] = '\0'; |
| 730 | /* cut off name for saving output style */ |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 731 | pr_info("%20s ", cut_name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 732 | } |
| 733 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 734 | pr_info("%10u ", st->nr_acquired); |
| 735 | pr_info("%10u ", st->nr_contended); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 736 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 737 | pr_info("%15" PRIu64 " ", st->wait_time_total); |
| 738 | pr_info("%15" PRIu64 " ", st->wait_time_max); |
| 739 | pr_info("%15" PRIu64 " ", st->wait_time_min == ULLONG_MAX ? |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 740 | 0 : st->wait_time_min); |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 741 | pr_info("\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 742 | } |
Hitoshi Mitake | e4cef1f | 2010-04-21 21:23:54 +0900 | [diff] [blame] | 743 | |
Frederic Weisbecker | 10350ec | 2010-05-05 23:47:28 +0200 | [diff] [blame] | 744 | print_bad_events(bad, total); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 745 | } |
| 746 | |
Arnaldo Carvalho de Melo | 8035458 | 2010-05-17 15:51:10 -0300 | [diff] [blame] | 747 | static bool info_threads, info_map; |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 748 | |
| 749 | static void dump_threads(void) |
| 750 | { |
| 751 | struct thread_stat *st; |
| 752 | struct rb_node *node; |
| 753 | struct thread *t; |
| 754 | |
| 755 | pr_info("%10s: comm\n", "Thread ID"); |
| 756 | |
| 757 | node = rb_first(&thread_stats); |
| 758 | while (node) { |
| 759 | st = container_of(node, struct thread_stat, rb); |
| 760 | t = perf_session__findnew(session, st->tid); |
| 761 | pr_info("%10d: %s\n", st->tid, t->comm); |
| 762 | node = rb_next(node); |
| 763 | }; |
| 764 | } |
| 765 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 766 | static void dump_map(void) |
| 767 | { |
| 768 | unsigned int i; |
| 769 | struct lock_stat *st; |
| 770 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 771 | pr_info("Address of instance: name of class\n"); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 772 | for (i = 0; i < LOCKHASH_SIZE; i++) { |
| 773 | list_for_each_entry(st, &lockhash_table[i], hash_entry) { |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 774 | pr_info(" %p: %s\n", st->addr, st->name); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 779 | static int dump_info(void) |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 780 | { |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 781 | int rc = 0; |
| 782 | |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 783 | if (info_threads) |
| 784 | dump_threads(); |
| 785 | else if (info_map) |
| 786 | dump_map(); |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 787 | else { |
| 788 | rc = -1; |
| 789 | pr_err("Unknown type of information\n"); |
| 790 | } |
| 791 | |
| 792 | return rc; |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 793 | } |
| 794 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 795 | typedef int (*tracepoint_handler)(struct perf_evsel *evsel, |
| 796 | struct perf_sample *sample); |
| 797 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 798 | 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] | 799 | union perf_event *event, |
Arnaldo Carvalho de Melo | 9e69c21 | 2011-03-15 15:44:01 -0300 | [diff] [blame] | 800 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | fcf65bf | 2012-08-07 09:58:03 -0300 | [diff] [blame] | 801 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 802 | struct machine *machine) |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 803 | { |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 804 | struct thread *thread = machine__findnew_thread(machine, sample->pid, |
| 805 | sample->tid); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 806 | |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 807 | if (thread == NULL) { |
| 808 | pr_debug("problem processing %d event, skipping it.\n", |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 809 | event->header.type); |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 810 | return -1; |
| 811 | } |
| 812 | |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 813 | if (evsel->handler.func != NULL) { |
| 814 | tracepoint_handler f = evsel->handler.func; |
| 815 | return f(evsel, sample); |
| 816 | } |
| 817 | |
| 818 | return 0; |
Frederic Weisbecker | c61e52e | 2010-04-24 00:04:12 +0200 | [diff] [blame] | 819 | } |
| 820 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 821 | static void sort_result(void) |
| 822 | { |
| 823 | unsigned int i; |
| 824 | struct lock_stat *st; |
| 825 | |
| 826 | for (i = 0; i < LOCKHASH_SIZE; i++) { |
| 827 | list_for_each_entry(st, &lockhash_table[i], hash_entry) { |
| 828 | insert_to_result(st, compare); |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
Davidlohr Bueso | 375eb2b | 2013-09-08 19:19:16 -0700 | [diff] [blame] | 833 | static const struct perf_evsel_str_handler lock_tracepoints[] = { |
| 834 | { "lock:lock_acquire", perf_evsel__process_lock_acquire, }, /* CONFIG_LOCKDEP */ |
| 835 | { "lock:lock_acquired", perf_evsel__process_lock_acquired, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */ |
| 836 | { "lock:lock_contended", perf_evsel__process_lock_contended, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */ |
| 837 | { "lock:lock_release", perf_evsel__process_lock_release, }, /* CONFIG_LOCKDEP */ |
| 838 | }; |
| 839 | |
| 840 | static int __cmd_report(bool display_info) |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 841 | { |
Davidlohr Bueso | 375eb2b | 2013-09-08 19:19:16 -0700 | [diff] [blame] | 842 | int err = -EINVAL; |
| 843 | struct perf_tool eops = { |
| 844 | .sample = process_sample_event, |
| 845 | .comm = perf_event__process_comm, |
| 846 | .ordered_samples = true, |
| 847 | }; |
| 848 | |
| 849 | session = perf_session__new(input_name, O_RDONLY, 0, false, &eops); |
| 850 | if (!session) { |
| 851 | pr_err("Initializing perf session failed\n"); |
| 852 | return -ENOMEM; |
| 853 | } |
| 854 | |
| 855 | if (!perf_session__has_traces(session, "lock record")) |
| 856 | goto out_delete; |
| 857 | |
| 858 | if (perf_session__set_tracepoints_handlers(session, lock_tracepoints)) { |
| 859 | pr_err("Initializing perf session tracepoint handlers failed\n"); |
| 860 | goto out_delete; |
| 861 | } |
| 862 | |
| 863 | if (select_key()) |
| 864 | goto out_delete; |
| 865 | |
| 866 | err = perf_session__process_events(session, &eops); |
| 867 | if (err) |
| 868 | goto out_delete; |
| 869 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 870 | setup_pager(); |
Davidlohr Bueso | 375eb2b | 2013-09-08 19:19:16 -0700 | [diff] [blame] | 871 | if (display_info) /* used for info subcommand */ |
| 872 | err = dump_info(); |
| 873 | else { |
| 874 | sort_result(); |
| 875 | print_result(); |
| 876 | } |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 877 | |
Davidlohr Bueso | 375eb2b | 2013-09-08 19:19:16 -0700 | [diff] [blame] | 878 | out_delete: |
| 879 | perf_session__delete(session); |
| 880 | return err; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 881 | } |
| 882 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 883 | static int __cmd_record(int argc, const char **argv) |
| 884 | { |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 885 | const char *record_args[] = { |
Jiri Olsa | 4a4d371 | 2013-06-05 13:37:21 +0200 | [diff] [blame] | 886 | "record", "-R", "-m", "1024", "-c", "1", |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 887 | }; |
Davidlohr Bueso | 0a98c7f | 2013-09-08 19:19:15 -0700 | [diff] [blame] | 888 | unsigned int rec_argc, i, j, ret; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 889 | const char **rec_argv; |
| 890 | |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 891 | for (i = 0; i < ARRAY_SIZE(lock_tracepoints); i++) { |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 892 | if (!is_valid_tracepoint(lock_tracepoints[i].name)) { |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 893 | pr_err("tracepoint %s is not enabled. " |
| 894 | "Are CONFIG_LOCKDEP and CONFIG_LOCK_STAT enabled?\n", |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 895 | lock_tracepoints[i].name); |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 896 | return 1; |
| 897 | } |
| 898 | } |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 899 | |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 900 | rec_argc = ARRAY_SIZE(record_args) + argc - 1; |
| 901 | /* factor of 2 is for -e in front of each tracepoint */ |
| 902 | rec_argc += 2 * ARRAY_SIZE(lock_tracepoints); |
| 903 | |
| 904 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
Davidlohr Bueso | 0a98c7f | 2013-09-08 19:19:15 -0700 | [diff] [blame] | 905 | if (!rec_argv) |
Chris Samuel | ce47dc5 | 2010-11-13 13:35:06 +1100 | [diff] [blame] | 906 | return -ENOMEM; |
| 907 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 908 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
| 909 | rec_argv[i] = strdup(record_args[i]); |
| 910 | |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 911 | for (j = 0; j < ARRAY_SIZE(lock_tracepoints); j++) { |
| 912 | rec_argv[i++] = "-e"; |
Arnaldo Carvalho de Melo | 746f16e | 2012-09-24 10:52:12 -0300 | [diff] [blame] | 913 | rec_argv[i++] = strdup(lock_tracepoints[j].name); |
David Ahern | d25dcba | 2012-08-09 10:35:37 -0600 | [diff] [blame] | 914 | } |
| 915 | |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 916 | for (j = 1; j < (unsigned int)argc; j++, i++) |
| 917 | rec_argv[i] = argv[j]; |
| 918 | |
| 919 | BUG_ON(i != rec_argc); |
| 920 | |
Davidlohr Bueso | 0a98c7f | 2013-09-08 19:19:15 -0700 | [diff] [blame] | 921 | ret = cmd_record(i, rec_argv, NULL); |
| 922 | free(rec_argv); |
| 923 | return ret; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 924 | } |
| 925 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 926 | 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] | 927 | { |
Arnaldo Carvalho de Melo | c75d98a | 2012-10-01 15:20:58 -0300 | [diff] [blame] | 928 | const struct option info_options[] = { |
| 929 | OPT_BOOLEAN('t', "threads", &info_threads, |
| 930 | "dump thread list in perf.data"), |
| 931 | OPT_BOOLEAN('m', "map", &info_map, |
| 932 | "map of lock instances (address:name table)"), |
| 933 | OPT_END() |
| 934 | }; |
| 935 | const struct option lock_options[] = { |
| 936 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
| 937 | OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"), |
| 938 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"), |
| 939 | OPT_END() |
| 940 | }; |
| 941 | const struct option report_options[] = { |
| 942 | OPT_STRING('k', "key", &sort_key, "acquired", |
| 943 | "key for sorting (acquired / contended / wait_total / wait_max / wait_min)"), |
| 944 | /* TODO: type */ |
| 945 | OPT_END() |
| 946 | }; |
| 947 | const char * const info_usage[] = { |
| 948 | "perf lock info [<options>]", |
| 949 | NULL |
| 950 | }; |
| 951 | const char * const lock_usage[] = { |
| 952 | "perf lock [<options>] {record|report|script|info}", |
| 953 | NULL |
| 954 | }; |
| 955 | const char * const report_usage[] = { |
| 956 | "perf lock report [<options>]", |
| 957 | NULL |
| 958 | }; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 959 | unsigned int i; |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 960 | int rc = 0; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 961 | |
| 962 | symbol__init(); |
| 963 | for (i = 0; i < LOCKHASH_SIZE; i++) |
| 964 | INIT_LIST_HEAD(lockhash_table + i); |
| 965 | |
| 966 | argc = parse_options(argc, argv, lock_options, lock_usage, |
| 967 | PARSE_OPT_STOP_AT_NON_OPTION); |
| 968 | if (!argc) |
| 969 | usage_with_options(lock_usage, lock_options); |
| 970 | |
| 971 | if (!strncmp(argv[0], "rec", 3)) { |
| 972 | return __cmd_record(argc, argv); |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 973 | } else if (!strncmp(argv[0], "report", 6)) { |
| 974 | trace_handler = &report_lock_ops; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 975 | if (argc) { |
| 976 | argc = parse_options(argc, argv, |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 977 | report_options, report_usage, 0); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 978 | if (argc) |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 979 | usage_with_options(report_usage, report_options); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 980 | } |
Davidlohr Bueso | 375eb2b | 2013-09-08 19:19:16 -0700 | [diff] [blame] | 981 | rc = __cmd_report(false); |
Ingo Molnar | 133dc4c | 2010-11-16 18:45:39 +0100 | [diff] [blame] | 982 | } else if (!strcmp(argv[0], "script")) { |
| 983 | /* Aliased to 'perf script' */ |
| 984 | return cmd_script(argc, argv, prefix); |
Hitoshi Mitake | 26242d8 | 2010-05-03 14:12:00 +0900 | [diff] [blame] | 985 | } else if (!strcmp(argv[0], "info")) { |
| 986 | if (argc) { |
| 987 | argc = parse_options(argc, argv, |
| 988 | info_options, info_usage, 0); |
| 989 | if (argc) |
| 990 | usage_with_options(info_usage, info_options); |
| 991 | } |
Ingo Molnar | 59f411b | 2010-01-31 08:27:58 +0100 | [diff] [blame] | 992 | /* recycling report_lock_ops */ |
| 993 | trace_handler = &report_lock_ops; |
Davidlohr Bueso | 375eb2b | 2013-09-08 19:19:16 -0700 | [diff] [blame] | 994 | rc = __cmd_report(true); |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 995 | } else { |
| 996 | usage_with_options(lock_usage, lock_options); |
| 997 | } |
| 998 | |
David Ahern | 33d6aef | 2012-08-26 12:24:43 -0600 | [diff] [blame] | 999 | return rc; |
Hitoshi Mitake | 9b5e350 | 2010-01-30 20:43:33 +0900 | [diff] [blame] | 1000 | } |