Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf lock: Account for lock average wait time

While perf-lock currently reports both the total wait time and the
number of contentions, it doesn't explicitly show the average wait time.
Having this value immediately in the report can be quite useful when
looking into performance issues.

Furthermore, allowing report to sort by averages is another handy
feature to have - and thus do not only print the value, but add it to
the lock_stat structure.

Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Cc: Aswin Chandramouleeswaran <aswin@hp.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1378693159-8747-8-git-send-email-davidlohr@hp.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Davidlohr Bueso and committed by
Arnaldo Carvalho de Melo
f37376cd 60a25cbc

+10 -2
+1 -1
tools/perf/Documentation/perf-lock.txt
··· 48 48 -k:: 49 49 --key=<value>:: 50 50 Sorting key. Possible values: acquired (default), contended, 51 - wait_total, wait_max, wait_min. 51 + avg_wait, wait_total, wait_max, wait_min. 52 52 53 53 INFO OPTIONS 54 54 ------------
+9 -1
tools/perf/builtin-lock.c
··· 56 56 57 57 unsigned int nr_readlock; 58 58 unsigned int nr_trylock; 59 + 59 60 /* these times are in nano sec. */ 61 + u64 avg_wait_time; 60 62 u64 wait_time_total; 61 63 u64 wait_time_min; 62 64 u64 wait_time_max; ··· 210 208 211 209 SINGLE_KEY(nr_acquired) 212 210 SINGLE_KEY(nr_contended) 211 + SINGLE_KEY(avg_wait_time) 213 212 SINGLE_KEY(wait_time_total) 214 213 SINGLE_KEY(wait_time_max) 215 214 ··· 247 244 struct lock_key keys[] = { 248 245 DEF_KEY_LOCK(acquired, nr_acquired), 249 246 DEF_KEY_LOCK(contended, nr_contended), 247 + DEF_KEY_LOCK(avg_wait, avg_wait_time), 250 248 DEF_KEY_LOCK(wait_total, wait_time_total), 251 249 DEF_KEY_LOCK(wait_min, wait_time_min), 252 250 DEF_KEY_LOCK(wait_max, wait_time_max), ··· 520 516 521 517 seq->state = SEQ_STATE_ACQUIRED; 522 518 ls->nr_acquired++; 519 + ls->avg_wait_time = ls->nr_contended ? ls->wait_time_total/ls->nr_contended : 0; 523 520 seq->prev_event_time = sample->time; 524 521 end: 525 522 return 0; ··· 575 570 576 571 seq->state = SEQ_STATE_CONTENDED; 577 572 ls->nr_contended++; 573 + ls->avg_wait_time = ls->wait_time_total/ls->nr_contended; 578 574 seq->prev_event_time = sample->time; 579 575 end: 580 576 return 0; ··· 709 703 pr_info("%10s ", "acquired"); 710 704 pr_info("%10s ", "contended"); 711 705 706 + pr_info("%15s ", "avg wait (ns)"); 712 707 pr_info("%15s ", "total wait (ns)"); 713 708 pr_info("%15s ", "max wait (ns)"); 714 709 pr_info("%15s ", "min wait (ns)"); ··· 741 734 pr_info("%10u ", st->nr_acquired); 742 735 pr_info("%10u ", st->nr_contended); 743 736 737 + pr_info("%15" PRIu64 " ", st->avg_wait_time); 744 738 pr_info("%15" PRIu64 " ", st->wait_time_total); 745 739 pr_info("%15" PRIu64 " ", st->wait_time_max); 746 740 pr_info("%15" PRIu64 " ", st->wait_time_min == ULLONG_MAX ? ··· 948 940 }; 949 941 const struct option report_options[] = { 950 942 OPT_STRING('k', "key", &sort_key, "acquired", 951 - "key for sorting (acquired / contended / wait_total / wait_max / wait_min)"), 943 + "key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"), 952 944 /* TODO: type */ 953 945 OPT_END() 954 946 };