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

perf lock: Support -t option for 'contention' subcommand

Like perf lock report, it can report lock contention stat of each task.

$ perf lock contention -t
contended total wait max wait avg wait pid comm

5 945.20 us 902.08 us 189.04 us 316167 EventManager_De
33 98.17 us 6.78 us 2.97 us 766063 kworker/0:1-get
7 92.47 us 61.26 us 13.21 us 316170 EventManager_De
14 76.31 us 12.87 us 5.45 us 12949 timedcall
24 76.15 us 12.27 us 3.17 us 767992 sched-pipe
15 75.62 us 11.93 us 5.04 us 15127 switchto-defaul
24 71.84 us 5.59 us 2.99 us 629168 kworker/u513:2-
17 67.41 us 7.94 us 3.96 us 13504 coroner-
1 59.56 us 59.56 us 59.56 us 316165 EventManager_De
14 56.21 us 6.89 us 4.01 us 0 swapper

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220725183124.368304-6-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
1ab55323 79079f21

+24 -2
+4
tools/perf/Documentation/perf-lock.txt
··· 119 119 and users can customize that using this. Possible values: 120 120 contended, wait_total, wait_max, wait_min, avg_wait. 121 121 122 + -t:: 123 + --threads:: 124 + Show per-thread lock contention stat 125 + 122 126 123 127 SEE ALSO 124 128 --------
+20 -2
tools/perf/builtin-lock.c
··· 1560 1560 list_for_each_entry(key, &lock_keys, list) 1561 1561 pr_info("%*s ", key->len, key->header); 1562 1562 1563 - pr_info(" %10s %s\n\n", "type", "caller"); 1563 + if (show_thread_stats) 1564 + pr_info(" %10s %s\n\n", "pid", "comm"); 1565 + else 1566 + pr_info(" %10s %s\n\n", "type", "caller"); 1564 1567 1565 1568 bad = total = 0; 1566 1569 while ((st = pop_from_result())) { ··· 1574 1571 list_for_each_entry(key, &lock_keys, list) { 1575 1572 key->print(key, st); 1576 1573 pr_info(" "); 1574 + } 1575 + 1576 + if (show_thread_stats) { 1577 + struct thread *t; 1578 + int pid = st->addr; 1579 + 1580 + /* st->addr contains tid of thread */ 1581 + t = perf_session__findnew(session, pid); 1582 + pr_info(" %10d %s\n", pid, thread__comm_str(t)); 1583 + continue; 1577 1584 } 1578 1585 1579 1586 pr_info(" %10s %s\n", get_type_str(st), st->name); ··· 1716 1703 if (select_key(true)) 1717 1704 goto out_delete; 1718 1705 1719 - aggr_mode = LOCK_AGGR_CALLER; 1706 + if (show_thread_stats) 1707 + aggr_mode = LOCK_AGGR_TASK; 1708 + else 1709 + aggr_mode = LOCK_AGGR_CALLER; 1720 1710 1721 1711 err = perf_session__process_events(session); 1722 1712 if (err) ··· 1859 1843 "key for sorting (contended / wait_total / wait_max / wait_min / avg_wait)"), 1860 1844 OPT_STRING('F', "field", &output_fields, "contended,wait_total,wait_max,avg_wait", 1861 1845 "output fields (contended / wait_total / wait_max / wait_min / avg_wait)"), 1846 + OPT_BOOLEAN('t', "threads", &show_thread_stats, 1847 + "show per-thread lock stats"), 1862 1848 OPT_PARENT(lock_options) 1863 1849 }; 1864 1850