License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-18 21:46:11 +08:00
|
|
|
#include <errno.h>
|
2017-04-18 02:23:08 +08:00
|
|
|
#include <inttypes.h>
|
2010-01-30 19:43:33 +08:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "perf.h"
|
|
|
|
|
2019-08-30 23:29:03 +08:00
|
|
|
#include "util/evlist.h" // for struct evsel_str_handler
|
2012-08-07 20:58:03 +08:00
|
|
|
#include "util/evsel.h"
|
2010-01-30 19:43:33 +08:00
|
|
|
#include "util/symbol.h"
|
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/header.h"
|
2022-07-30 04:07:56 +08:00
|
|
|
#include "util/target.h"
|
2022-06-16 00:32:22 +08:00
|
|
|
#include "util/callchain.h"
|
2022-07-30 04:07:55 +08:00
|
|
|
#include "util/lock-contention.h"
|
2022-12-10 03:07:25 +08:00
|
|
|
#include "util/bpf_skel/lock_data.h"
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2019-08-30 23:52:25 +08:00
|
|
|
#include <subcmd/pager.h>
|
2015-12-15 23:39:39 +08:00
|
|
|
#include <subcmd/parse-options.h>
|
2010-01-30 19:43:33 +08:00
|
|
|
#include "util/trace-event.h"
|
2022-07-30 04:42:17 +08:00
|
|
|
#include "util/tracepoint.h"
|
2010-01-30 19:43:33 +08:00
|
|
|
|
|
|
|
#include "util/debug.h"
|
|
|
|
#include "util/session.h"
|
2011-11-28 18:30:20 +08:00
|
|
|
#include "util/tool.h"
|
2013-10-15 22:27:32 +08:00
|
|
|
#include "util/data.h"
|
2022-03-25 17:20:32 +08:00
|
|
|
#include "util/string2.h"
|
2022-06-16 00:32:22 +08:00
|
|
|
#include "util/map.h"
|
2022-10-29 02:01:26 +08:00
|
|
|
#include "util/util.h"
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
#include <stdio.h>
|
2010-01-30 19:43:33 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <limits.h>
|
2022-12-20 04:17:30 +08:00
|
|
|
#include <ctype.h>
|
2010-01-30 19:43:33 +08:00
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/hash.h>
|
2017-04-17 22:39:06 +08:00
|
|
|
#include <linux/kernel.h>
|
2019-07-04 22:32:27 +08:00
|
|
|
#include <linux/zalloc.h>
|
2019-08-22 15:20:49 +08:00
|
|
|
#include <linux/err.h>
|
2022-06-16 00:32:22 +08:00
|
|
|
#include <linux/stringify.h>
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
static struct perf_session *session;
|
2022-07-30 04:07:56 +08:00
|
|
|
static struct target target;
|
2010-04-21 20:23:54 +08:00
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
/* based on kernel/lockdep.c */
|
|
|
|
#define LOCKHASH_BITS 12
|
|
|
|
#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS)
|
|
|
|
|
2023-05-27 02:33:54 +08:00
|
|
|
static struct hlist_head *lockhash_table;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
|
|
|
#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS)
|
|
|
|
#define lockhashentry(key) (lockhash_table + __lockhashfn((key)))
|
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
static struct rb_root thread_stats;
|
|
|
|
|
2022-01-27 08:00:49 +08:00
|
|
|
static bool combine_locks;
|
2022-05-21 09:08:11 +08:00
|
|
|
static bool show_thread_stats;
|
2022-12-10 03:07:26 +08:00
|
|
|
static bool show_lock_addrs;
|
2023-02-07 08:24:02 +08:00
|
|
|
static bool show_lock_owner;
|
2022-07-30 04:07:55 +08:00
|
|
|
static bool use_bpf;
|
2023-04-07 05:06:07 +08:00
|
|
|
static unsigned long bpf_map_entries = MAX_ENTRIES;
|
2022-09-12 13:53:13 +08:00
|
|
|
static int max_stack_depth = CONTENTION_STACK_DEPTH;
|
|
|
|
static int stack_skip = CONTENTION_STACK_SKIP;
|
2022-09-24 08:42:19 +08:00
|
|
|
static int print_nr_entries = INT_MAX / 2;
|
2023-01-26 08:09:36 +08:00
|
|
|
static LIST_HEAD(callstack_filters);
|
2023-06-29 04:01:40 +08:00
|
|
|
static const char *output_name = NULL;
|
|
|
|
static FILE *lock_output;
|
2023-01-26 08:09:36 +08:00
|
|
|
|
|
|
|
struct callstack_filter {
|
|
|
|
struct list_head list;
|
|
|
|
char name[];
|
|
|
|
};
|
2022-01-27 08:00:49 +08:00
|
|
|
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
static struct lock_filter filters;
|
|
|
|
|
2022-12-10 03:07:25 +08:00
|
|
|
static enum lock_aggr_mode aggr_mode = LOCK_AGGR_ADDR;
|
2022-07-26 02:31:21 +08:00
|
|
|
|
2023-01-26 08:09:36 +08:00
|
|
|
static bool needs_callstack(void)
|
|
|
|
{
|
2023-04-07 05:06:10 +08:00
|
|
|
return !list_empty(&callstack_filters);
|
2023-01-26 08:09:36 +08:00
|
|
|
}
|
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
static struct thread_stat *thread_stat_find(u32 tid)
|
|
|
|
{
|
|
|
|
struct rb_node *node;
|
|
|
|
struct thread_stat *st;
|
|
|
|
|
|
|
|
node = thread_stats.rb_node;
|
|
|
|
while (node) {
|
|
|
|
st = container_of(node, struct thread_stat, rb);
|
|
|
|
if (st->tid == tid)
|
|
|
|
return st;
|
|
|
|
else if (tid < st->tid)
|
|
|
|
node = node->rb_left;
|
|
|
|
else
|
|
|
|
node = node->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void thread_stat_insert(struct thread_stat *new)
|
|
|
|
{
|
|
|
|
struct rb_node **rb = &thread_stats.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct thread_stat *p;
|
|
|
|
|
|
|
|
while (*rb) {
|
|
|
|
p = container_of(*rb, struct thread_stat, rb);
|
|
|
|
parent = *rb;
|
|
|
|
|
|
|
|
if (new->tid < p->tid)
|
|
|
|
rb = &(*rb)->rb_left;
|
|
|
|
else if (new->tid > p->tid)
|
|
|
|
rb = &(*rb)->rb_right;
|
|
|
|
else
|
|
|
|
BUG_ON("inserting invalid thread_stat\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&new->rb, parent, rb);
|
|
|
|
rb_insert_color(&new->rb, &thread_stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct thread_stat *thread_stat_findnew_after_first(u32 tid)
|
|
|
|
{
|
|
|
|
struct thread_stat *st;
|
|
|
|
|
|
|
|
st = thread_stat_find(tid);
|
|
|
|
if (st)
|
|
|
|
return st;
|
|
|
|
|
|
|
|
st = zalloc(sizeof(struct thread_stat));
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!st) {
|
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-21 20:23:54 +08:00
|
|
|
|
|
|
|
st->tid = tid;
|
|
|
|
INIT_LIST_HEAD(&st->seq_list);
|
|
|
|
|
|
|
|
thread_stat_insert(st);
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct thread_stat *thread_stat_findnew_first(u32 tid);
|
|
|
|
static struct thread_stat *(*thread_stat_findnew)(u32 tid) =
|
|
|
|
thread_stat_findnew_first;
|
|
|
|
|
|
|
|
static struct thread_stat *thread_stat_findnew_first(u32 tid)
|
|
|
|
{
|
|
|
|
struct thread_stat *st;
|
|
|
|
|
|
|
|
st = zalloc(sizeof(struct thread_stat));
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!st) {
|
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-21 20:23:54 +08:00
|
|
|
st->tid = tid;
|
|
|
|
INIT_LIST_HEAD(&st->seq_list);
|
|
|
|
|
|
|
|
rb_link_node(&st->rb, NULL, &thread_stats.rb_node);
|
|
|
|
rb_insert_color(&st->rb, &thread_stats);
|
|
|
|
|
|
|
|
thread_stat_findnew = thread_stat_findnew_after_first;
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
/* build simple key function one is bigger than two */
|
2010-01-31 15:27:58 +08:00
|
|
|
#define SINGLE_KEY(member) \
|
2010-01-30 19:43:33 +08:00
|
|
|
static int lock_stat_key_ ## member(struct lock_stat *one, \
|
|
|
|
struct lock_stat *two) \
|
|
|
|
{ \
|
|
|
|
return one->member > two->member; \
|
|
|
|
}
|
|
|
|
|
|
|
|
SINGLE_KEY(nr_acquired)
|
|
|
|
SINGLE_KEY(nr_contended)
|
2013-09-09 10:19:19 +08:00
|
|
|
SINGLE_KEY(avg_wait_time)
|
2010-01-30 19:43:33 +08:00
|
|
|
SINGLE_KEY(wait_time_total)
|
|
|
|
SINGLE_KEY(wait_time_max)
|
|
|
|
|
2011-02-23 01:47:15 +08:00
|
|
|
static int lock_stat_key_wait_time_min(struct lock_stat *one,
|
|
|
|
struct lock_stat *two)
|
|
|
|
{
|
|
|
|
u64 s1 = one->wait_time_min;
|
|
|
|
u64 s2 = two->wait_time_min;
|
|
|
|
if (s1 == ULLONG_MAX)
|
|
|
|
s1 = 0;
|
|
|
|
if (s2 == ULLONG_MAX)
|
|
|
|
s2 = 0;
|
|
|
|
return s1 > s2;
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
struct lock_key {
|
|
|
|
/*
|
|
|
|
* name: the value for specify by user
|
|
|
|
* this should be simpler than raw name of member
|
|
|
|
* e.g. nr_acquired -> acquired, wait_time_total -> wait_total
|
|
|
|
*/
|
2010-01-31 15:27:58 +08:00
|
|
|
const char *name;
|
2022-03-24 07:02:58 +08:00
|
|
|
/* header: the string printed on the header line */
|
|
|
|
const char *header;
|
|
|
|
/* len: the printing width of the field */
|
|
|
|
int len;
|
|
|
|
/* key: a pointer to function to compare two lock stats for sorting */
|
2010-01-31 15:27:58 +08:00
|
|
|
int (*key)(struct lock_stat*, struct lock_stat*);
|
2022-03-24 07:02:58 +08:00
|
|
|
/* print: a pointer to function to print a given lock stats */
|
|
|
|
void (*print)(struct lock_key*, struct lock_stat*);
|
|
|
|
/* list: list entry to link this */
|
|
|
|
struct list_head list;
|
2010-01-30 19:43:33 +08:00
|
|
|
};
|
|
|
|
|
2022-06-16 00:32:16 +08:00
|
|
|
static void lock_stat_key_print_time(unsigned long long nsec, int len)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
float base;
|
|
|
|
const char *unit;
|
|
|
|
} table[] = {
|
|
|
|
{ 1e9 * 3600, "h " },
|
|
|
|
{ 1e9 * 60, "m " },
|
|
|
|
{ 1e9, "s " },
|
|
|
|
{ 1e6, "ms" },
|
|
|
|
{ 1e3, "us" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
/* for CSV output */
|
|
|
|
if (len == 0) {
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%llu", nsec);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:16 +08:00
|
|
|
for (int i = 0; table[i].unit; i++) {
|
|
|
|
if (nsec < table[i].base)
|
|
|
|
continue;
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%*.2f %s", len - 3, nsec / table[i].base, table[i].unit);
|
2022-06-16 00:32:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%*llu %s", len - 3, nsec, "ns");
|
2022-06-16 00:32:16 +08:00
|
|
|
}
|
|
|
|
|
2022-03-24 07:02:58 +08:00
|
|
|
#define PRINT_KEY(member) \
|
|
|
|
static void lock_stat_key_print_ ## member(struct lock_key *key, \
|
|
|
|
struct lock_stat *ls) \
|
|
|
|
{ \
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%*llu", key->len, (unsigned long long)ls->member);\
|
2022-03-24 07:02:58 +08:00
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:16 +08:00
|
|
|
#define PRINT_TIME(member) \
|
|
|
|
static void lock_stat_key_print_ ## member(struct lock_key *key, \
|
|
|
|
struct lock_stat *ls) \
|
|
|
|
{ \
|
|
|
|
lock_stat_key_print_time((unsigned long long)ls->member, key->len); \
|
|
|
|
}
|
|
|
|
|
2022-03-24 07:02:58 +08:00
|
|
|
PRINT_KEY(nr_acquired)
|
|
|
|
PRINT_KEY(nr_contended)
|
2022-06-16 00:32:16 +08:00
|
|
|
PRINT_TIME(avg_wait_time)
|
|
|
|
PRINT_TIME(wait_time_total)
|
|
|
|
PRINT_TIME(wait_time_max)
|
2022-03-24 07:02:58 +08:00
|
|
|
|
|
|
|
static void lock_stat_key_print_wait_time_min(struct lock_key *key,
|
|
|
|
struct lock_stat *ls)
|
|
|
|
{
|
|
|
|
u64 wait_time = ls->wait_time_min;
|
|
|
|
|
|
|
|
if (wait_time == ULLONG_MAX)
|
|
|
|
wait_time = 0;
|
|
|
|
|
2022-06-16 00:32:16 +08:00
|
|
|
lock_stat_key_print_time(wait_time, key->len);
|
2022-03-24 07:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-31 15:27:58 +08:00
|
|
|
static const char *sort_key = "acquired";
|
|
|
|
|
|
|
|
static int (*compare)(struct lock_stat *, struct lock_stat *);
|
|
|
|
|
2022-01-27 08:00:49 +08:00
|
|
|
static struct rb_root sorted; /* place to store intermediate data */
|
2010-01-31 15:27:58 +08:00
|
|
|
static struct rb_root result; /* place to store sorted data */
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-03-24 07:02:58 +08:00
|
|
|
static LIST_HEAD(lock_keys);
|
2022-03-24 07:02:59 +08:00
|
|
|
static const char *output_fields;
|
2022-03-24 07:02:58 +08:00
|
|
|
|
|
|
|
#define DEF_KEY_LOCK(name, header, fn_suffix, len) \
|
|
|
|
{ #name, header, len, lock_stat_key_ ## fn_suffix, lock_stat_key_print_ ## fn_suffix, {} }
|
2022-07-26 02:31:23 +08:00
|
|
|
static struct lock_key report_keys[] = {
|
2022-03-24 07:02:58 +08:00
|
|
|
DEF_KEY_LOCK(acquired, "acquired", nr_acquired, 10),
|
|
|
|
DEF_KEY_LOCK(contended, "contended", nr_contended, 10),
|
2022-06-16 00:32:16 +08:00
|
|
|
DEF_KEY_LOCK(avg_wait, "avg wait", avg_wait_time, 12),
|
|
|
|
DEF_KEY_LOCK(wait_total, "total wait", wait_time_total, 12),
|
|
|
|
DEF_KEY_LOCK(wait_max, "max wait", wait_time_max, 12),
|
|
|
|
DEF_KEY_LOCK(wait_min, "min wait", wait_time_min, 12),
|
2010-01-30 19:43:33 +08:00
|
|
|
|
|
|
|
/* extra comparisons much complicated should be here */
|
2022-03-24 07:02:58 +08:00
|
|
|
{ }
|
2010-01-30 19:43:33 +08:00
|
|
|
};
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
static struct lock_key contention_keys[] = {
|
|
|
|
DEF_KEY_LOCK(contended, "contended", nr_contended, 10),
|
|
|
|
DEF_KEY_LOCK(wait_total, "total wait", wait_time_total, 12),
|
|
|
|
DEF_KEY_LOCK(wait_max, "max wait", wait_time_max, 12),
|
|
|
|
DEF_KEY_LOCK(wait_min, "min wait", wait_time_min, 12),
|
|
|
|
DEF_KEY_LOCK(avg_wait, "avg wait", avg_wait_time, 12),
|
|
|
|
|
|
|
|
/* extra comparisons much complicated should be here */
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int select_key(bool contention)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
|
|
|
int i;
|
2022-07-26 02:31:23 +08:00
|
|
|
struct lock_key *keys = report_keys;
|
|
|
|
|
|
|
|
if (contention)
|
|
|
|
keys = contention_keys;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
|
|
|
for (i = 0; keys[i].name; i++) {
|
|
|
|
if (!strcmp(keys[i].name, sort_key)) {
|
|
|
|
compare = keys[i].key;
|
2022-03-24 07:02:59 +08:00
|
|
|
|
|
|
|
/* selected key should be in the output fields */
|
|
|
|
if (list_empty(&keys[i].list))
|
|
|
|
list_add_tail(&keys[i].list, &lock_keys);
|
|
|
|
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 02:24:43 +08:00
|
|
|
pr_err("Unknown compare key: %s\n", sort_key);
|
|
|
|
return -1;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
static int add_output_field(bool contention, char *name)
|
2022-03-24 07:02:58 +08:00
|
|
|
{
|
|
|
|
int i;
|
2022-07-26 02:31:23 +08:00
|
|
|
struct lock_key *keys = report_keys;
|
|
|
|
|
|
|
|
if (contention)
|
|
|
|
keys = contention_keys;
|
2022-03-24 07:02:58 +08:00
|
|
|
|
2022-03-24 07:02:59 +08:00
|
|
|
for (i = 0; keys[i].name; i++) {
|
|
|
|
if (strcmp(keys[i].name, name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* prevent double link */
|
|
|
|
if (list_empty(&keys[i].list))
|
2022-07-26 02:31:23 +08:00
|
|
|
list_add_tail(&keys[i].list, &lock_keys);
|
2022-03-24 07:02:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_err("Unknown output field: %s\n", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
static int setup_output_field(bool contention, const char *str)
|
2022-03-24 07:02:59 +08:00
|
|
|
{
|
|
|
|
char *tok, *tmp, *orig;
|
|
|
|
int i, ret = 0;
|
2022-07-26 02:31:23 +08:00
|
|
|
struct lock_key *keys = report_keys;
|
|
|
|
|
|
|
|
if (contention)
|
|
|
|
keys = contention_keys;
|
2022-03-24 07:02:59 +08:00
|
|
|
|
|
|
|
/* no output field given: use all of them */
|
|
|
|
if (str == NULL) {
|
|
|
|
for (i = 0; keys[i].name; i++)
|
|
|
|
list_add_tail(&keys[i].list, &lock_keys);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-24 07:02:58 +08:00
|
|
|
for (i = 0; keys[i].name; i++)
|
2022-03-24 07:02:59 +08:00
|
|
|
INIT_LIST_HEAD(&keys[i].list);
|
2022-03-24 07:02:58 +08:00
|
|
|
|
2022-03-24 07:02:59 +08:00
|
|
|
orig = tmp = strdup(str);
|
|
|
|
if (orig == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
while ((tok = strsep(&tmp, ",")) != NULL){
|
2022-07-26 02:31:23 +08:00
|
|
|
ret = add_output_field(contention, tok);
|
2022-03-24 07:02:59 +08:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(orig);
|
|
|
|
|
|
|
|
return ret;
|
2022-03-24 07:02:58 +08:00
|
|
|
}
|
|
|
|
|
2022-01-27 08:00:49 +08:00
|
|
|
static void combine_lock_stats(struct lock_stat *st)
|
|
|
|
{
|
|
|
|
struct rb_node **rb = &sorted.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct lock_stat *p;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (*rb) {
|
|
|
|
p = container_of(*rb, struct lock_stat, rb);
|
|
|
|
parent = *rb;
|
|
|
|
|
|
|
|
if (st->name && p->name)
|
|
|
|
ret = strcmp(st->name, p->name);
|
|
|
|
else
|
|
|
|
ret = !!st->name - !!p->name;
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
p->nr_acquired += st->nr_acquired;
|
|
|
|
p->nr_contended += st->nr_contended;
|
|
|
|
p->wait_time_total += st->wait_time_total;
|
|
|
|
|
|
|
|
if (p->nr_contended)
|
|
|
|
p->avg_wait_time = p->wait_time_total / p->nr_contended;
|
|
|
|
|
|
|
|
if (p->wait_time_min > st->wait_time_min)
|
|
|
|
p->wait_time_min = st->wait_time_min;
|
|
|
|
if (p->wait_time_max < st->wait_time_max)
|
|
|
|
p->wait_time_max = st->wait_time_max;
|
|
|
|
|
2022-05-21 09:08:10 +08:00
|
|
|
p->broken |= st->broken;
|
2022-01-27 08:00:49 +08:00
|
|
|
st->combined = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
rb = &(*rb)->rb_left;
|
|
|
|
else
|
|
|
|
rb = &(*rb)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&st->rb, parent, rb);
|
|
|
|
rb_insert_color(&st->rb, &sorted);
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
static void insert_to_result(struct lock_stat *st,
|
2010-01-31 15:27:58 +08:00
|
|
|
int (*bigger)(struct lock_stat *, struct lock_stat *))
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
|
|
|
struct rb_node **rb = &result.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct lock_stat *p;
|
|
|
|
|
2022-01-27 08:00:49 +08:00
|
|
|
if (combine_locks && st->combined)
|
|
|
|
return;
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
while (*rb) {
|
|
|
|
p = container_of(*rb, struct lock_stat, rb);
|
|
|
|
parent = *rb;
|
|
|
|
|
|
|
|
if (bigger(st, p))
|
|
|
|
rb = &(*rb)->rb_left;
|
|
|
|
else
|
|
|
|
rb = &(*rb)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&st->rb, parent, rb);
|
|
|
|
rb_insert_color(&st->rb, &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns left most element of result, and erase it */
|
|
|
|
static struct lock_stat *pop_from_result(void)
|
|
|
|
{
|
|
|
|
struct rb_node *node = result.rb_node;
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (node->rb_left)
|
|
|
|
node = node->rb_left;
|
|
|
|
|
|
|
|
rb_erase(node, &result);
|
|
|
|
return container_of(node, struct lock_stat, rb);
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:13:23 +08:00
|
|
|
struct lock_stat *lock_stat_find(u64 addr)
|
2022-06-16 00:32:20 +08:00
|
|
|
{
|
|
|
|
struct hlist_head *entry = lockhashentry(addr);
|
|
|
|
struct lock_stat *ret;
|
|
|
|
|
|
|
|
hlist_for_each_entry(ret, entry, hash_entry) {
|
|
|
|
if (ret->addr == addr)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:13:23 +08:00
|
|
|
struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2022-01-27 08:00:45 +08:00
|
|
|
struct hlist_head *entry = lockhashentry(addr);
|
2010-01-30 19:43:33 +08:00
|
|
|
struct lock_stat *ret, *new;
|
|
|
|
|
2022-01-27 08:00:45 +08:00
|
|
|
hlist_for_each_entry(ret, entry, hash_entry) {
|
2010-01-30 19:43:33 +08:00
|
|
|
if (ret->addr == addr)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
new = zalloc(sizeof(struct lock_stat));
|
|
|
|
if (!new)
|
|
|
|
goto alloc_failed;
|
|
|
|
|
|
|
|
new->addr = addr;
|
2022-07-26 02:31:20 +08:00
|
|
|
new->name = strdup(name);
|
2013-09-09 10:19:15 +08:00
|
|
|
if (!new->name) {
|
|
|
|
free(new);
|
2010-01-30 19:43:33 +08:00
|
|
|
goto alloc_failed;
|
2013-09-09 10:19:15 +08:00
|
|
|
}
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-07-26 02:31:20 +08:00
|
|
|
new->flags = flags;
|
2010-01-30 19:43:33 +08:00
|
|
|
new->wait_time_min = ULLONG_MAX;
|
|
|
|
|
2022-01-27 08:00:45 +08:00
|
|
|
hlist_add_head(&new->hash_entry, entry);
|
2010-01-30 19:43:33 +08:00
|
|
|
return new;
|
|
|
|
|
|
|
|
alloc_failed:
|
2012-08-27 02:24:43 +08:00
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2023-02-03 10:13:24 +08:00
|
|
|
bool match_callstack_filter(struct machine *machine, u64 *callstack)
|
|
|
|
{
|
|
|
|
struct map *kmap;
|
|
|
|
struct symbol *sym;
|
|
|
|
u64 ip;
|
|
|
|
|
|
|
|
if (list_empty(&callstack_filters))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (int i = 0; i < max_stack_depth; i++) {
|
|
|
|
struct callstack_filter *filter;
|
|
|
|
|
|
|
|
if (!callstack || !callstack[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
ip = callstack[i];
|
|
|
|
sym = machine__find_kernel_symbol(machine, ip, &kmap);
|
|
|
|
if (sym == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
list_for_each_entry(filter, &callstack_filters, list) {
|
|
|
|
if (strstr(sym->name, filter->name))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
struct trace_lock_handler {
|
2022-06-16 00:32:19 +08:00
|
|
|
/* it's used on CONFIG_LOCKDEP */
|
2019-07-21 19:23:51 +08:00
|
|
|
int (*acquire_event)(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample);
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-06-16 00:32:19 +08:00
|
|
|
/* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */
|
2019-07-21 19:23:51 +08:00
|
|
|
int (*acquired_event)(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample);
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-06-16 00:32:19 +08:00
|
|
|
/* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */
|
2019-07-21 19:23:51 +08:00
|
|
|
int (*contended_event)(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample);
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-06-16 00:32:19 +08:00
|
|
|
/* it's used on CONFIG_LOCKDEP */
|
2019-07-21 19:23:51 +08:00
|
|
|
int (*release_event)(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample);
|
2022-06-16 00:32:19 +08:00
|
|
|
|
|
|
|
/* it's used when CONFIG_LOCKDEP is off */
|
|
|
|
int (*contention_begin_event)(struct evsel *evsel,
|
|
|
|
struct perf_sample *sample);
|
|
|
|
|
|
|
|
/* it's used when CONFIG_LOCKDEP is off */
|
|
|
|
int (*contention_end_event)(struct evsel *evsel,
|
|
|
|
struct perf_sample *sample);
|
2010-01-30 19:43:33 +08:00
|
|
|
};
|
|
|
|
|
2022-01-27 08:00:46 +08:00
|
|
|
static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr)
|
2010-04-21 20:23:54 +08:00
|
|
|
{
|
|
|
|
struct lock_seq_stat *seq;
|
|
|
|
|
|
|
|
list_for_each_entry(seq, &ts->seq_list, list) {
|
|
|
|
if (seq->addr == addr)
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
seq = zalloc(sizeof(struct lock_seq_stat));
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!seq) {
|
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-21 20:23:54 +08:00
|
|
|
seq->state = SEQ_STATE_UNINITIALIZED;
|
|
|
|
seq->addr = addr;
|
|
|
|
|
|
|
|
list_add(&seq->list, &ts->seq_list);
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
2010-05-06 05:47:28 +08:00
|
|
|
enum broken_state {
|
|
|
|
BROKEN_ACQUIRE,
|
|
|
|
BROKEN_ACQUIRED,
|
|
|
|
BROKEN_CONTENDED,
|
|
|
|
BROKEN_RELEASE,
|
|
|
|
BROKEN_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bad_hist[BROKEN_MAX];
|
2010-04-21 20:23:54 +08:00
|
|
|
|
2010-05-06 05:57:25 +08:00
|
|
|
enum acquire_flags {
|
|
|
|
TRY_LOCK = 1,
|
|
|
|
READ_LOCK = 2,
|
|
|
|
};
|
|
|
|
|
2022-09-08 10:11:39 +08:00
|
|
|
static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2022-07-26 02:31:21 +08:00
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_ADDR:
|
2022-09-08 10:11:39 +08:00
|
|
|
*key = addr;
|
2022-07-26 02:31:21 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
2022-09-08 10:11:39 +08:00
|
|
|
*key = tid;
|
2022-07-26 02:31:21 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
|
|
|
default:
|
|
|
|
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-09-08 10:11:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample);
|
|
|
|
|
|
|
|
static int get_key_by_aggr_mode(u64 *key, u64 addr, struct evsel *evsel,
|
|
|
|
struct perf_sample *sample)
|
|
|
|
{
|
|
|
|
if (aggr_mode == LOCK_AGGR_CALLER) {
|
|
|
|
*key = callchain_id(evsel, sample);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return get_key_by_aggr_mode_simple(key, addr, sample->tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_lock_acquire_event(struct evsel *evsel,
|
|
|
|
struct perf_sample *sample)
|
|
|
|
{
|
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
|
|
|
int flag = evsel__intval(evsel, sample, "flags");
|
|
|
|
u64 key;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 09:08:11 +08:00
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ls)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2012-08-07 21:59:44 +08:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ts)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2012-08-27 02:24:43 +08:00
|
|
|
|
2012-09-24 21:52:12 +08:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!seq)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
case SEQ_STATE_RELEASED:
|
2012-09-24 21:52:12 +08:00
|
|
|
if (!flag) {
|
2010-04-21 20:23:54 +08:00
|
|
|
seq->state = SEQ_STATE_ACQUIRING;
|
|
|
|
} else {
|
2012-09-24 21:52:12 +08:00
|
|
|
if (flag & TRY_LOCK)
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->nr_trylock++;
|
2012-09-24 21:52:12 +08:00
|
|
|
if (flag & READ_LOCK)
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->nr_readlock++;
|
|
|
|
seq->state = SEQ_STATE_READ_ACQUIRED;
|
|
|
|
seq->read_count = 1;
|
|
|
|
ls->nr_acquired++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
2012-09-24 21:52:12 +08:00
|
|
|
if (flag & READ_LOCK) {
|
2010-04-21 20:23:54 +08:00
|
|
|
seq->read_count++;
|
|
|
|
ls->nr_acquired++;
|
|
|
|
goto end;
|
|
|
|
} else {
|
|
|
|
goto broken;
|
|
|
|
}
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
2010-04-21 20:23:54 +08:00
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_ACQUIRING:
|
|
|
|
case SEQ_STATE_CONTENDED:
|
|
|
|
broken:
|
2022-05-21 09:08:10 +08:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_ACQUIRE]++;
|
|
|
|
}
|
2019-07-04 23:13:46 +08:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 20:23:54 +08:00
|
|
|
free(seq);
|
|
|
|
goto end;
|
2010-01-30 19:43:33 +08:00
|
|
|
default:
|
2010-04-21 20:23:54 +08:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->nr_acquire++;
|
2012-08-07 21:59:44 +08:00
|
|
|
seq->prev_event_time = sample->time;
|
2010-04-21 20:23:54 +08:00
|
|
|
end:
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2019-07-21 19:23:51 +08:00
|
|
|
static int report_lock_acquired_event(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2010-04-21 20:23:54 +08:00
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
|
|
|
u64 contended_term;
|
2020-04-30 03:26:57 +08:00
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
2022-01-27 08:00:46 +08:00
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
2022-07-26 02:31:21 +08:00
|
|
|
u64 key;
|
2022-09-08 10:11:39 +08:00
|
|
|
int ret;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-09-08 10:11:39 +08:00
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 09:08:11 +08:00
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ls)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-04-21 20:23:54 +08:00
|
|
|
|
2012-08-07 21:59:44 +08:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ts)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2012-08-27 02:24:43 +08:00
|
|
|
|
2012-09-24 21:52:12 +08:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!seq)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
/* orphan event, do nothing */
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-04-21 20:23:54 +08:00
|
|
|
case SEQ_STATE_ACQUIRING:
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
2010-04-21 20:23:54 +08:00
|
|
|
case SEQ_STATE_CONTENDED:
|
2012-09-24 21:52:12 +08:00
|
|
|
contended_term = sample->time - seq->prev_event_time;
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->wait_time_total += contended_term;
|
|
|
|
if (contended_term < ls->wait_time_min)
|
|
|
|
ls->wait_time_min = contended_term;
|
2010-05-07 08:33:42 +08:00
|
|
|
if (ls->wait_time_max < contended_term)
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->wait_time_max = contended_term;
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
2010-04-21 20:23:54 +08:00
|
|
|
case SEQ_STATE_RELEASED:
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
2022-05-21 09:08:10 +08:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_ACQUIRED]++;
|
|
|
|
}
|
2019-07-04 23:13:46 +08:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 20:23:54 +08:00
|
|
|
free(seq);
|
|
|
|
goto end;
|
2010-01-30 19:43:33 +08:00
|
|
|
default:
|
2010-04-21 20:23:54 +08:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
seq->state = SEQ_STATE_ACQUIRED;
|
|
|
|
ls->nr_acquired++;
|
2013-09-09 10:19:19 +08:00
|
|
|
ls->avg_wait_time = ls->nr_contended ? ls->wait_time_total/ls->nr_contended : 0;
|
2012-09-24 21:52:12 +08:00
|
|
|
seq->prev_event_time = sample->time;
|
2010-04-21 20:23:54 +08:00
|
|
|
end:
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2019-07-21 19:23:51 +08:00
|
|
|
static int report_lock_contended_event(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2010-04-21 20:23:54 +08:00
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
2020-04-30 03:26:57 +08:00
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
2022-01-27 08:00:46 +08:00
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
2022-07-26 02:31:21 +08:00
|
|
|
u64 key;
|
2022-09-08 10:11:39 +08:00
|
|
|
int ret;
|
2010-04-21 20:23:54 +08:00
|
|
|
|
2022-09-08 10:11:39 +08:00
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 09:08:11 +08:00
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ls)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2012-08-07 21:59:44 +08:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ts)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2012-08-27 02:24:43 +08:00
|
|
|
|
2012-09-24 21:52:12 +08:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!seq)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
/* orphan event, do nothing */
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-04-21 20:23:54 +08:00
|
|
|
case SEQ_STATE_ACQUIRING:
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
2010-04-21 20:23:54 +08:00
|
|
|
case SEQ_STATE_RELEASED:
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
|
|
|
case SEQ_STATE_CONTENDED:
|
2022-05-21 09:08:10 +08:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_CONTENDED]++;
|
|
|
|
}
|
2019-07-04 23:13:46 +08:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 20:23:54 +08:00
|
|
|
free(seq);
|
|
|
|
goto end;
|
2010-01-30 19:43:33 +08:00
|
|
|
default:
|
2010-04-21 20:23:54 +08:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
seq->state = SEQ_STATE_CONTENDED;
|
|
|
|
ls->nr_contended++;
|
2013-09-09 10:19:19 +08:00
|
|
|
ls->avg_wait_time = ls->wait_time_total/ls->nr_contended;
|
2012-08-07 21:59:44 +08:00
|
|
|
seq->prev_event_time = sample->time;
|
2010-04-21 20:23:54 +08:00
|
|
|
end:
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2019-07-21 19:23:51 +08:00
|
|
|
static int report_lock_release_event(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2010-04-21 20:23:54 +08:00
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
2020-04-30 03:26:57 +08:00
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
2022-01-27 08:00:46 +08:00
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
2022-07-26 02:31:21 +08:00
|
|
|
u64 key;
|
2022-09-08 10:11:39 +08:00
|
|
|
int ret;
|
2012-09-24 21:52:12 +08:00
|
|
|
|
2022-09-08 10:11:39 +08:00
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 09:08:11 +08:00
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ls)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2012-08-07 21:59:44 +08:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!ts)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2012-08-27 02:24:43 +08:00
|
|
|
|
2012-09-24 21:52:12 +08:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-27 02:24:43 +08:00
|
|
|
if (!seq)
|
2013-09-09 10:19:14 +08:00
|
|
|
return -ENOMEM;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
goto end;
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
break;
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
|
|
|
seq->read_count--;
|
|
|
|
BUG_ON(seq->read_count < 0);
|
2020-11-04 17:42:29 +08:00
|
|
|
if (seq->read_count) {
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->nr_release++;
|
2010-01-30 19:43:33 +08:00
|
|
|
goto end;
|
|
|
|
}
|
2010-04-21 20:23:54 +08:00
|
|
|
break;
|
|
|
|
case SEQ_STATE_ACQUIRING:
|
|
|
|
case SEQ_STATE_CONTENDED:
|
|
|
|
case SEQ_STATE_RELEASED:
|
2022-05-21 09:08:10 +08:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_RELEASE]++;
|
|
|
|
}
|
2010-04-21 20:23:54 +08:00
|
|
|
goto free_seq;
|
2010-01-30 19:43:33 +08:00
|
|
|
default:
|
2010-04-21 20:23:54 +08:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 19:43:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 20:23:54 +08:00
|
|
|
ls->nr_release++;
|
|
|
|
free_seq:
|
2019-07-04 23:13:46 +08:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 20:23:54 +08:00
|
|
|
free(seq);
|
2010-01-30 19:43:33 +08:00
|
|
|
end:
|
2012-08-27 02:24:43 +08:00
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2022-09-12 13:53:11 +08:00
|
|
|
static int get_symbol_name_offset(struct map *map, struct symbol *sym, u64 ip,
|
|
|
|
char *buf, int size)
|
|
|
|
{
|
|
|
|
u64 offset;
|
|
|
|
|
|
|
|
if (map == NULL || sym == NULL) {
|
|
|
|
buf[0] = '\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-05 04:59:44 +08:00
|
|
|
offset = map__map_ip(map, ip) - sym->start;
|
2022-09-12 13:53:11 +08:00
|
|
|
|
|
|
|
if (offset)
|
|
|
|
return scnprintf(buf, size, "%s+%#lx", sym->name, offset);
|
|
|
|
else
|
|
|
|
return strlcpy(buf, sym->name, size);
|
|
|
|
}
|
2022-06-16 00:32:22 +08:00
|
|
|
static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample,
|
|
|
|
char *buf, int size)
|
|
|
|
{
|
|
|
|
struct thread *thread;
|
2023-06-09 07:28:21 +08:00
|
|
|
struct callchain_cursor *cursor;
|
2022-07-30 04:07:54 +08:00
|
|
|
struct machine *machine = &session->machines.host;
|
2022-06-16 00:32:22 +08:00
|
|
|
struct symbol *sym;
|
|
|
|
int skip = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* lock names will be replaced to task name later */
|
|
|
|
if (show_thread_stats)
|
|
|
|
return -1;
|
|
|
|
|
2022-07-30 04:07:54 +08:00
|
|
|
thread = machine__findnew_thread(machine, -1, sample->pid);
|
2022-06-16 00:32:22 +08:00
|
|
|
if (thread == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-09 07:28:21 +08:00
|
|
|
cursor = get_tls_callchain_cursor();
|
|
|
|
|
2022-06-16 00:32:22 +08:00
|
|
|
/* use caller function name from the callchain */
|
|
|
|
ret = thread__resolve_callchain(thread, cursor, evsel, sample,
|
2022-09-12 13:53:13 +08:00
|
|
|
NULL, NULL, max_stack_depth);
|
2022-06-16 00:32:22 +08:00
|
|
|
if (ret != 0) {
|
|
|
|
thread__put(thread);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
callchain_cursor_commit(cursor);
|
|
|
|
thread__put(thread);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
struct callchain_cursor_node *node;
|
|
|
|
|
|
|
|
node = callchain_cursor_current(cursor);
|
|
|
|
if (node == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* skip first few entries - for lock functions */
|
2022-09-12 13:53:13 +08:00
|
|
|
if (++skip <= stack_skip)
|
2022-06-16 00:32:22 +08:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
sym = node->ms.sym;
|
2022-12-07 00:49:04 +08:00
|
|
|
if (sym && !machine__is_lock_function(machine, node->ip)) {
|
2022-09-12 13:53:11 +08:00
|
|
|
get_symbol_name_offset(node->ms.map, sym, node->ip,
|
|
|
|
buf, size);
|
2022-06-16 00:32:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
callchain_cursor_advance(cursor);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:22 +08:00
|
|
|
static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample)
|
|
|
|
{
|
2023-06-09 07:28:21 +08:00
|
|
|
struct callchain_cursor *cursor;
|
2022-07-30 04:07:54 +08:00
|
|
|
struct machine *machine = &session->machines.host;
|
2022-07-26 02:31:22 +08:00
|
|
|
struct thread *thread;
|
|
|
|
u64 hash = 0;
|
|
|
|
int skip = 0;
|
|
|
|
int ret;
|
|
|
|
|
2022-07-30 04:07:54 +08:00
|
|
|
thread = machine__findnew_thread(machine, -1, sample->pid);
|
2022-07-26 02:31:22 +08:00
|
|
|
if (thread == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-09 07:28:21 +08:00
|
|
|
cursor = get_tls_callchain_cursor();
|
2022-07-26 02:31:22 +08:00
|
|
|
/* use caller function name from the callchain */
|
|
|
|
ret = thread__resolve_callchain(thread, cursor, evsel, sample,
|
2022-09-12 13:53:13 +08:00
|
|
|
NULL, NULL, max_stack_depth);
|
2022-07-26 02:31:22 +08:00
|
|
|
thread__put(thread);
|
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
callchain_cursor_commit(cursor);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
struct callchain_cursor_node *node;
|
|
|
|
|
|
|
|
node = callchain_cursor_current(cursor);
|
|
|
|
if (node == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* skip first few entries - for lock functions */
|
2022-09-12 13:53:13 +08:00
|
|
|
if (++skip <= stack_skip)
|
2022-07-26 02:31:22 +08:00
|
|
|
goto next;
|
|
|
|
|
2022-12-07 00:49:04 +08:00
|
|
|
if (node->ms.sym && machine__is_lock_function(machine, node->ip))
|
2022-07-26 02:31:22 +08:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
hash ^= hash_long((unsigned long)node->ip, 64);
|
|
|
|
|
|
|
|
next:
|
|
|
|
callchain_cursor_advance(cursor);
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2022-09-12 13:53:12 +08:00
|
|
|
static u64 *get_callstack(struct perf_sample *sample, int max_stack)
|
|
|
|
{
|
|
|
|
u64 *callstack;
|
|
|
|
u64 i;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
callstack = calloc(max_stack, sizeof(*callstack));
|
|
|
|
if (callstack == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0, c = 0; i < sample->callchain->nr && c < max_stack; i++) {
|
|
|
|
u64 ip = sample->callchain->ips[i];
|
|
|
|
|
|
|
|
if (ip >= PERF_CONTEXT_MAX)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
callstack[c++] = ip;
|
|
|
|
}
|
|
|
|
return callstack;
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:20 +08:00
|
|
|
static int report_lock_contention_begin_event(struct evsel *evsel,
|
|
|
|
struct perf_sample *sample)
|
|
|
|
{
|
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
|
|
|
u64 addr = evsel__intval(evsel, sample, "lock_addr");
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
unsigned int flags = evsel__intval(evsel, sample, "flags");
|
2022-07-26 02:31:21 +08:00
|
|
|
u64 key;
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
int i, ret;
|
2022-12-20 04:17:30 +08:00
|
|
|
static bool kmap_loaded;
|
|
|
|
struct machine *machine = &session->machines.host;
|
|
|
|
struct map *kmap;
|
|
|
|
struct symbol *sym;
|
2022-06-16 00:32:20 +08:00
|
|
|
|
2022-09-08 10:11:39 +08:00
|
|
|
ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-06-16 00:32:20 +08:00
|
|
|
|
2022-12-20 04:17:30 +08:00
|
|
|
if (!kmap_loaded) {
|
|
|
|
unsigned long *addrs;
|
|
|
|
|
|
|
|
/* make sure it loads the kernel map to find lock symbols */
|
|
|
|
map__load(machine__kernel_map(machine));
|
|
|
|
kmap_loaded = true;
|
|
|
|
|
|
|
|
/* convert (kernel) symbols to addresses */
|
|
|
|
for (i = 0; i < filters.nr_syms; i++) {
|
|
|
|
sym = machine__find_kernel_symbol_by_name(machine,
|
|
|
|
filters.syms[i],
|
|
|
|
&kmap);
|
|
|
|
if (sym == NULL) {
|
|
|
|
pr_warning("ignore unknown symbol: %s\n",
|
|
|
|
filters.syms[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
addrs = realloc(filters.addrs,
|
|
|
|
(filters.nr_addrs + 1) * sizeof(*addrs));
|
|
|
|
if (addrs == NULL) {
|
|
|
|
pr_warning("memory allocation failure\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2023-04-05 04:59:44 +08:00
|
|
|
addrs[filters.nr_addrs++] = map__unmap_ip(kmap, sym->start);
|
2022-12-20 04:17:30 +08:00
|
|
|
filters.addrs = addrs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
ls = lock_stat_find(key);
|
2022-06-16 00:32:22 +08:00
|
|
|
if (!ls) {
|
|
|
|
char buf[128];
|
2022-12-10 03:07:26 +08:00
|
|
|
const char *name = "";
|
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_ADDR:
|
|
|
|
sym = machine__find_kernel_symbol(machine, key, &kmap);
|
|
|
|
if (sym)
|
|
|
|
name = sym->name;
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
|
|
|
name = buf;
|
|
|
|
if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0)
|
|
|
|
name = "Unknown";
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-06-16 00:32:22 +08:00
|
|
|
|
2022-12-10 03:07:26 +08:00
|
|
|
ls = lock_stat_findnew(key, name, flags);
|
2022-06-16 00:32:22 +08:00
|
|
|
if (!ls)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2022-06-16 00:32:20 +08:00
|
|
|
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
if (filters.nr_types) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (i = 0; i < filters.nr_types; i++) {
|
|
|
|
if (flags == filters.types[i]) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-12-20 04:17:30 +08:00
|
|
|
if (filters.nr_addrs) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (i = 0; i < filters.nr_addrs; i++) {
|
|
|
|
if (addr == filters.addrs[i]) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:13:24 +08:00
|
|
|
if (needs_callstack()) {
|
|
|
|
u64 *callstack = get_callstack(sample, max_stack_depth);
|
|
|
|
if (callstack == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!match_callstack_filter(machine, callstack)) {
|
|
|
|
free(callstack);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ls->callstack == NULL)
|
|
|
|
ls->callstack = callstack;
|
|
|
|
else
|
|
|
|
free(callstack);
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:20 +08:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
|
|
|
if (!ts)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
seq = get_seq(ts, addr);
|
|
|
|
if (!seq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
break;
|
|
|
|
case SEQ_STATE_CONTENDED:
|
|
|
|
/*
|
|
|
|
* It can have nested contention begin with mutex spinning,
|
|
|
|
* then we would use the original contention begin event and
|
|
|
|
* ignore the second one.
|
|
|
|
*/
|
|
|
|
goto end;
|
|
|
|
case SEQ_STATE_ACQUIRING:
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
|
|
|
case SEQ_STATE_RELEASED:
|
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_CONTENDED]++;
|
|
|
|
}
|
|
|
|
list_del_init(&seq->list);
|
|
|
|
free(seq);
|
|
|
|
goto end;
|
|
|
|
default:
|
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seq->state != SEQ_STATE_CONTENDED) {
|
|
|
|
seq->state = SEQ_STATE_CONTENDED;
|
|
|
|
seq->prev_event_time = sample->time;
|
|
|
|
ls->nr_contended++;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_lock_contention_end_event(struct evsel *evsel,
|
|
|
|
struct perf_sample *sample)
|
|
|
|
{
|
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
|
|
|
u64 contended_term;
|
|
|
|
u64 addr = evsel__intval(evsel, sample, "lock_addr");
|
2022-07-26 02:31:21 +08:00
|
|
|
u64 key;
|
2022-09-08 10:11:39 +08:00
|
|
|
int ret;
|
2022-06-16 00:32:20 +08:00
|
|
|
|
2022-09-08 10:11:39 +08:00
|
|
|
ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-06-16 00:32:20 +08:00
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
ls = lock_stat_find(key);
|
2022-06-16 00:32:20 +08:00
|
|
|
if (!ls)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ts = thread_stat_find(sample->tid);
|
|
|
|
if (!ts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
seq = get_seq(ts, addr);
|
|
|
|
if (!seq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
goto end;
|
|
|
|
case SEQ_STATE_CONTENDED:
|
|
|
|
contended_term = sample->time - seq->prev_event_time;
|
|
|
|
ls->wait_time_total += contended_term;
|
|
|
|
if (contended_term < ls->wait_time_min)
|
|
|
|
ls->wait_time_min = contended_term;
|
|
|
|
if (ls->wait_time_max < contended_term)
|
|
|
|
ls->wait_time_max = contended_term;
|
|
|
|
break;
|
|
|
|
case SEQ_STATE_ACQUIRING:
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
|
|
|
case SEQ_STATE_RELEASED:
|
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_ACQUIRED]++;
|
|
|
|
}
|
|
|
|
list_del_init(&seq->list);
|
|
|
|
free(seq);
|
|
|
|
goto end;
|
|
|
|
default:
|
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
seq->state = SEQ_STATE_ACQUIRED;
|
|
|
|
ls->nr_acquired++;
|
|
|
|
ls->avg_wait_time = ls->wait_time_total/ls->nr_acquired;
|
|
|
|
end:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
/* lock oriented handlers */
|
|
|
|
/* TODO: handlers for CPU oriented, thread oriented */
|
2010-01-31 15:27:58 +08:00
|
|
|
static struct trace_lock_handler report_lock_ops = {
|
|
|
|
.acquire_event = report_lock_acquire_event,
|
|
|
|
.acquired_event = report_lock_acquired_event,
|
|
|
|
.contended_event = report_lock_contended_event,
|
|
|
|
.release_event = report_lock_release_event,
|
2022-06-16 00:32:20 +08:00
|
|
|
.contention_begin_event = report_lock_contention_begin_event,
|
|
|
|
.contention_end_event = report_lock_contention_end_event,
|
2010-01-30 19:43:33 +08:00
|
|
|
};
|
|
|
|
|
2022-07-26 02:31:22 +08:00
|
|
|
static struct trace_lock_handler contention_lock_ops = {
|
|
|
|
.contention_begin_event = report_lock_contention_begin_event,
|
|
|
|
.contention_end_event = report_lock_contention_end_event,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
static struct trace_lock_handler *trace_handler;
|
|
|
|
|
2020-05-05 00:56:18 +08:00
|
|
|
static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2010-01-31 15:27:58 +08:00
|
|
|
if (trace_handler->acquire_event)
|
2012-09-24 21:52:12 +08:00
|
|
|
return trace_handler->acquire_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 00:56:18 +08:00
|
|
|
static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2012-08-27 02:24:43 +08:00
|
|
|
if (trace_handler->acquired_event)
|
2012-09-24 21:52:12 +08:00
|
|
|
return trace_handler->acquired_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 00:56:18 +08:00
|
|
|
static int evsel__process_lock_contended(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2012-08-27 02:24:43 +08:00
|
|
|
if (trace_handler->contended_event)
|
2012-09-24 21:52:12 +08:00
|
|
|
return trace_handler->contended_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 00:56:18 +08:00
|
|
|
static int evsel__process_lock_release(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2012-08-27 02:24:43 +08:00
|
|
|
if (trace_handler->release_event)
|
2012-09-24 21:52:12 +08:00
|
|
|
return trace_handler->release_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:19 +08:00
|
|
|
static int evsel__process_contention_begin(struct evsel *evsel, struct perf_sample *sample)
|
|
|
|
{
|
|
|
|
if (trace_handler->contention_begin_event)
|
|
|
|
return trace_handler->contention_begin_event(evsel, sample);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int evsel__process_contention_end(struct evsel *evsel, struct perf_sample *sample)
|
|
|
|
{
|
|
|
|
if (trace_handler->contention_end_event)
|
|
|
|
return trace_handler->contention_end_event(evsel, sample);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-06 05:47:28 +08:00
|
|
|
static void print_bad_events(int bad, int total)
|
|
|
|
{
|
|
|
|
/* Output for debug, this have to be removed */
|
|
|
|
int i;
|
2022-06-16 00:32:18 +08:00
|
|
|
int broken = 0;
|
2010-05-06 05:47:28 +08:00
|
|
|
const char *name[4] =
|
|
|
|
{ "acquire", "acquired", "contended", "release" };
|
|
|
|
|
2022-06-16 00:32:18 +08:00
|
|
|
for (i = 0; i < BROKEN_MAX; i++)
|
|
|
|
broken += bad_hist[i];
|
|
|
|
|
2023-03-28 06:57:10 +08:00
|
|
|
if (quiet || total == 0 || (broken == 0 && verbose <= 0))
|
2022-06-16 00:32:18 +08:00
|
|
|
return;
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\n=== output for debug ===\n\n");
|
|
|
|
fprintf(lock_output, "bad: %d, total: %d\n", bad, total);
|
|
|
|
fprintf(lock_output, "bad rate: %.2f %%\n", (double)bad / (double)total * 100);
|
|
|
|
fprintf(lock_output, "histogram of events caused bad sequence\n");
|
2010-05-06 05:47:28 +08:00
|
|
|
for (i = 0; i < BROKEN_MAX; i++)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %10s: %d\n", name[i], bad_hist[i]);
|
2010-05-06 05:47:28 +08:00
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
/* TODO: various way to print, coloring, nano or milli sec */
|
|
|
|
static void print_result(void)
|
|
|
|
{
|
|
|
|
struct lock_stat *st;
|
2022-03-24 07:02:58 +08:00
|
|
|
struct lock_key *key;
|
2010-01-30 19:43:33 +08:00
|
|
|
char cut_name[20];
|
2022-09-24 08:42:19 +08:00
|
|
|
int bad, total, printed;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-09-24 08:42:20 +08:00
|
|
|
if (!quiet) {
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%20s ", "Name");
|
2022-09-24 08:42:20 +08:00
|
|
|
list_for_each_entry(key, &lock_keys, list)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%*s ", key->len, key->header);
|
|
|
|
fprintf(lock_output, "\n\n");
|
2022-09-24 08:42:20 +08:00
|
|
|
}
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-09-24 08:42:19 +08:00
|
|
|
bad = total = printed = 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
while ((st = pop_from_result())) {
|
2010-04-21 20:23:54 +08:00
|
|
|
total++;
|
2022-05-21 09:08:10 +08:00
|
|
|
if (st->broken)
|
2010-04-21 20:23:54 +08:00
|
|
|
bad++;
|
2022-05-21 09:08:10 +08:00
|
|
|
if (!st->nr_acquired)
|
2010-04-21 20:23:54 +08:00
|
|
|
continue;
|
2022-05-21 09:08:10 +08:00
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
bzero(cut_name, 20);
|
|
|
|
|
2022-01-27 08:00:48 +08:00
|
|
|
if (strlen(st->name) < 20) {
|
2010-01-30 19:43:33 +08:00
|
|
|
/* output raw name */
|
2022-05-21 09:08:11 +08:00
|
|
|
const char *name = st->name;
|
|
|
|
|
|
|
|
if (show_thread_stats) {
|
|
|
|
struct thread *t;
|
|
|
|
|
|
|
|
/* st->addr contains tid of thread */
|
|
|
|
t = perf_session__findnew(session, st->addr);
|
|
|
|
name = thread__comm_str(t);
|
|
|
|
}
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%20s ", name);
|
2010-01-30 19:43:33 +08:00
|
|
|
} else {
|
|
|
|
strncpy(cut_name, st->name, 16);
|
|
|
|
cut_name[16] = '.';
|
|
|
|
cut_name[17] = '.';
|
|
|
|
cut_name[18] = '.';
|
|
|
|
cut_name[19] = '\0';
|
|
|
|
/* cut off name for saving output style */
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%20s ", cut_name);
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2022-03-24 07:02:58 +08:00
|
|
|
list_for_each_entry(key, &lock_keys, list) {
|
|
|
|
key->print(key, st);
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " ");
|
2022-03-24 07:02:58 +08:00
|
|
|
}
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\n");
|
2022-09-24 08:42:19 +08:00
|
|
|
|
|
|
|
if (++printed >= print_nr_entries)
|
|
|
|
break;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
2010-04-21 20:23:54 +08:00
|
|
|
|
2010-05-06 05:47:28 +08:00
|
|
|
print_bad_events(bad, total);
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2010-05-18 02:51:10 +08:00
|
|
|
static bool info_threads, info_map;
|
2010-05-03 13:12:00 +08:00
|
|
|
|
|
|
|
static void dump_threads(void)
|
|
|
|
{
|
|
|
|
struct thread_stat *st;
|
|
|
|
struct rb_node *node;
|
|
|
|
struct thread *t;
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%10s: comm\n", "Thread ID");
|
2010-05-03 13:12:00 +08:00
|
|
|
|
|
|
|
node = rb_first(&thread_stats);
|
|
|
|
while (node) {
|
|
|
|
st = container_of(node, struct thread_stat, rb);
|
|
|
|
t = perf_session__findnew(session, st->tid);
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%10d: %s\n", st->tid, thread__comm_str(t));
|
2010-05-03 13:12:00 +08:00
|
|
|
node = rb_next(node);
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
thread__put(t);
|
2020-04-28 17:18:43 +08:00
|
|
|
}
|
2010-05-03 13:12:00 +08:00
|
|
|
}
|
|
|
|
|
2022-01-27 08:00:47 +08:00
|
|
|
static int compare_maps(struct lock_stat *a, struct lock_stat *b)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (a->name && b->name)
|
|
|
|
ret = strcmp(a->name, b->name);
|
|
|
|
else
|
|
|
|
ret = !!a->name - !!b->name;
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return a->addr < b->addr;
|
|
|
|
else
|
|
|
|
return ret < 0;
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
static void dump_map(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct lock_stat *st;
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "Address of instance: name of class\n");
|
2010-01-30 19:43:33 +08:00
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++) {
|
2022-01-27 08:00:45 +08:00
|
|
|
hlist_for_each_entry(st, &lockhash_table[i], hash_entry) {
|
2022-01-27 08:00:47 +08:00
|
|
|
insert_to_result(st, compare_maps);
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-27 08:00:47 +08:00
|
|
|
|
|
|
|
while ((st = pop_from_result()))
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %#llx: %s\n", (unsigned long long)st->addr, st->name);
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2012-08-27 02:24:43 +08:00
|
|
|
static int dump_info(void)
|
2010-05-03 13:12:00 +08:00
|
|
|
{
|
2012-08-27 02:24:43 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
2010-05-03 13:12:00 +08:00
|
|
|
if (info_threads)
|
|
|
|
dump_threads();
|
|
|
|
else if (info_map)
|
|
|
|
dump_map();
|
2012-08-27 02:24:43 +08:00
|
|
|
else {
|
|
|
|
rc = -1;
|
|
|
|
pr_err("Unknown type of information\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2010-05-03 13:12:00 +08:00
|
|
|
}
|
|
|
|
|
2022-11-04 13:14:40 +08:00
|
|
|
static const struct evsel_str_handler lock_tracepoints[] = {
|
|
|
|
{ "lock:lock_acquire", evsel__process_lock_acquire, }, /* CONFIG_LOCKDEP */
|
|
|
|
{ "lock:lock_acquired", evsel__process_lock_acquired, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */
|
|
|
|
{ "lock:lock_contended", evsel__process_lock_contended, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */
|
|
|
|
{ "lock:lock_release", evsel__process_lock_release, }, /* CONFIG_LOCKDEP */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct evsel_str_handler contention_tracepoints[] = {
|
|
|
|
{ "lock:contention_begin", evsel__process_contention_begin, },
|
|
|
|
{ "lock:contention_end", evsel__process_contention_end, },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int process_event_update(struct perf_tool *tool,
|
|
|
|
union perf_event *event,
|
|
|
|
struct evlist **pevlist)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = perf_event__process_event_update(tool, event, pevlist);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* this can return -EEXIST since we call it for each evsel */
|
|
|
|
perf_session__set_tracepoints_handlers(session, lock_tracepoints);
|
|
|
|
perf_session__set_tracepoints_handlers(session, contention_tracepoints);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-21 19:23:51 +08:00
|
|
|
typedef int (*tracepoint_handler)(struct evsel *evsel,
|
2012-09-24 21:52:12 +08:00
|
|
|
struct perf_sample *sample);
|
|
|
|
|
2012-09-11 06:15:03 +08:00
|
|
|
static int process_sample_event(struct perf_tool *tool __maybe_unused,
|
2011-11-25 18:19:45 +08:00
|
|
|
union perf_event *event,
|
2011-03-16 02:44:01 +08:00
|
|
|
struct perf_sample *sample,
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel *evsel,
|
2011-11-28 17:56:39 +08:00
|
|
|
struct machine *machine)
|
2010-04-24 06:04:12 +08:00
|
|
|
{
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
int err = 0;
|
2013-08-27 16:23:03 +08:00
|
|
|
struct thread *thread = machine__findnew_thread(machine, sample->pid,
|
|
|
|
sample->tid);
|
2010-04-24 06:04:12 +08:00
|
|
|
|
|
|
|
if (thread == NULL) {
|
|
|
|
pr_debug("problem processing %d event, skipping it.\n",
|
2011-01-30 00:01:45 +08:00
|
|
|
event->header.type);
|
2010-04-24 06:04:12 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-06 21:17:38 +08:00
|
|
|
if (evsel->handler != NULL) {
|
|
|
|
tracepoint_handler f = evsel->handler;
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
err = f(evsel, sample);
|
2012-09-24 21:52:12 +08:00
|
|
|
}
|
|
|
|
|
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime
management, we need to protect access to machine->threads from
concurrent access.
That happens in 'perf top', where a thread processes events, inserting
and deleting entries from that rb_tree while another thread decays
hist_entries, that end up dropping references and ultimately deleting
threads from the rb_tree and releasing its resources when no further
hist_entry (or other data structures, like in 'perf sched') references
it.
So the rule is the same for refcounts + protected trees in the kernel,
get the tree lock, find object, bump the refcount, drop the tree lock,
return, use object, drop the refcount if no more use of it is needed,
keep it if storing it in some other data structure, drop when releasing
that data structure.
I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and
"perf_event__preprocess_sample(&al)" with "addr_location__put(&al)".
The addr_location__put() one is because as we return references to
several data structures, we may end up adding more reference counting
for the other data structures and then we'll drop it at
addr_location__put() time.
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 07:43:22 +08:00
|
|
|
thread__put(thread);
|
|
|
|
|
|
|
|
return err;
|
2010-04-24 06:04:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-27 08:00:49 +08:00
|
|
|
static void combine_result(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct lock_stat *st;
|
|
|
|
|
|
|
|
if (!combine_locks)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++) {
|
|
|
|
hlist_for_each_entry(st, &lockhash_table[i], hash_entry) {
|
|
|
|
combine_lock_stats(st);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-09 10:19:16 +08:00
|
|
|
static void sort_result(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct lock_stat *st;
|
|
|
|
|
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++) {
|
2022-01-27 08:00:45 +08:00
|
|
|
hlist_for_each_entry(st, &lockhash_table[i], hash_entry) {
|
2013-09-09 10:19:16 +08:00
|
|
|
insert_to_result(st, compare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 04:17:27 +08:00
|
|
|
static const struct {
|
|
|
|
unsigned int flags;
|
2023-03-14 04:48:25 +08:00
|
|
|
const char *str;
|
2022-12-20 04:17:27 +08:00
|
|
|
const char *name;
|
|
|
|
} lock_type_table[] = {
|
2023-03-14 04:48:25 +08:00
|
|
|
{ 0, "semaphore", "semaphore" },
|
|
|
|
{ LCB_F_SPIN, "spinlock", "spinlock" },
|
|
|
|
{ LCB_F_SPIN | LCB_F_READ, "rwlock:R", "rwlock" },
|
|
|
|
{ LCB_F_SPIN | LCB_F_WRITE, "rwlock:W", "rwlock" },
|
|
|
|
{ LCB_F_READ, "rwsem:R", "rwsem" },
|
|
|
|
{ LCB_F_WRITE, "rwsem:W", "rwsem" },
|
2023-04-07 05:06:05 +08:00
|
|
|
{ LCB_F_RT, "rt-mutex", "rt-mutex" },
|
2023-03-14 04:48:25 +08:00
|
|
|
{ LCB_F_RT | LCB_F_READ, "rwlock-rt:R", "rwlock-rt" },
|
|
|
|
{ LCB_F_RT | LCB_F_WRITE, "rwlock-rt:W", "rwlock-rt" },
|
|
|
|
{ LCB_F_PERCPU | LCB_F_READ, "pcpu-sem:R", "percpu-rwsem" },
|
|
|
|
{ LCB_F_PERCPU | LCB_F_WRITE, "pcpu-sem:W", "percpu-rwsem" },
|
|
|
|
{ LCB_F_MUTEX, "mutex", "mutex" },
|
|
|
|
{ LCB_F_MUTEX | LCB_F_SPIN, "mutex", "mutex" },
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
/* alias for get_type_flag() */
|
2023-03-14 04:48:25 +08:00
|
|
|
{ LCB_F_MUTEX | LCB_F_SPIN, "mutex-spin", "mutex" },
|
2022-12-20 04:17:27 +08:00
|
|
|
};
|
2022-07-26 02:31:22 +08:00
|
|
|
|
2022-12-20 04:17:27 +08:00
|
|
|
static const char *get_type_str(unsigned int flags)
|
|
|
|
{
|
2023-03-14 04:48:25 +08:00
|
|
|
flags &= LCB_F_MAX_FLAGS - 1;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
|
|
|
|
if (lock_type_table[i].flags == flags)
|
|
|
|
return lock_type_table[i].str;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *get_type_name(unsigned int flags)
|
|
|
|
{
|
|
|
|
flags &= LCB_F_MAX_FLAGS - 1;
|
|
|
|
|
2022-12-20 04:17:27 +08:00
|
|
|
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
|
|
|
|
if (lock_type_table[i].flags == flags)
|
|
|
|
return lock_type_table[i].name;
|
2022-07-26 02:31:22 +08:00
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
static unsigned int get_type_flag(const char *str)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
|
|
|
|
if (!strcmp(lock_type_table[i].name, str))
|
|
|
|
return lock_type_table[i].flags;
|
|
|
|
}
|
2023-04-07 05:06:05 +08:00
|
|
|
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
|
|
|
|
if (!strcmp(lock_type_table[i].str, str))
|
|
|
|
return lock_type_table[i].flags;
|
|
|
|
}
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lock_filter_finish(void)
|
|
|
|
{
|
|
|
|
zfree(&filters.types);
|
|
|
|
filters.nr_types = 0;
|
2022-12-20 04:17:30 +08:00
|
|
|
|
|
|
|
zfree(&filters.addrs);
|
|
|
|
filters.nr_addrs = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < filters.nr_syms; i++)
|
|
|
|
free(filters.syms[i]);
|
|
|
|
|
|
|
|
zfree(&filters.syms);
|
|
|
|
filters.nr_syms = 0;
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:22 +08:00
|
|
|
static void sort_contention_result(void)
|
|
|
|
{
|
|
|
|
sort_result();
|
|
|
|
}
|
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
static void print_header_stdio(void)
|
|
|
|
{
|
|
|
|
struct lock_key *key;
|
|
|
|
|
|
|
|
list_for_each_entry(key, &lock_keys, list)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%*s ", key->len, key->header);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_TASK:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %10s %s\n\n", "pid",
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
show_lock_owner ? "owner" : "comm");
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %10s %s\n\n", "type", "caller");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %16s %s\n\n", "address", "symbol");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_header_csv(const char *sep)
|
|
|
|
{
|
|
|
|
struct lock_key *key;
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "# output: ");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
list_for_each_entry(key, &lock_keys, list)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s%s ", key->header, sep);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_TASK:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s%s %s\n", "pid", sep,
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
show_lock_owner ? "owner" : "comm");
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s%s %s", "type", sep, "caller");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
if (verbose > 0)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s %s", sep, "stacktrace");
|
|
|
|
fprintf(lock_output, "\n");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s%s %s%s %s\n", "address", sep, "symbol", sep, "type");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_header(void)
|
|
|
|
{
|
|
|
|
if (!quiet) {
|
|
|
|
if (symbol_conf.field_sep)
|
|
|
|
print_header_csv(symbol_conf.field_sep);
|
|
|
|
else
|
|
|
|
print_header_stdio();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat *st)
|
|
|
|
{
|
|
|
|
struct lock_key *key;
|
|
|
|
struct thread *t;
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
list_for_each_entry(key, &lock_keys, list) {
|
|
|
|
key->print(key, st);
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " ");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %10s %s\n", get_type_str(st->flags), st->name);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
|
|
|
pid = st->addr;
|
|
|
|
t = perf_session__findnew(session, pid);
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %10d %s\n",
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
pid, pid == -1 ? "Unknown" : thread__comm_str(t));
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, " %016llx %s (%s)\n", (unsigned long long)st->addr,
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
st->name, get_type_name(st->flags));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aggr_mode == LOCK_AGGR_CALLER && verbose > 0) {
|
|
|
|
struct map *kmap;
|
|
|
|
struct symbol *sym;
|
|
|
|
char buf[128];
|
|
|
|
u64 ip;
|
|
|
|
|
|
|
|
for (int i = 0; i < max_stack_depth; i++) {
|
|
|
|
if (!st->callstack || !st->callstack[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
ip = st->callstack[i];
|
|
|
|
sym = machine__find_kernel_symbol(con->machine, ip, &kmap);
|
|
|
|
get_symbol_name_offset(kmap, sym, ip, buf, sizeof(buf));
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\t\t\t%#lx %s\n", (unsigned long)ip, buf);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *st,
|
|
|
|
const char *sep)
|
|
|
|
{
|
|
|
|
struct lock_key *key;
|
|
|
|
struct thread *t;
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
list_for_each_entry(key, &lock_keys, list) {
|
|
|
|
key->print(key, st);
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s ", sep);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s%s %s", get_type_str(st->flags), sep, st->name);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
if (verbose <= 0)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\n");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
|
|
|
pid = st->addr;
|
|
|
|
t = perf_session__findnew(session, pid);
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%d%s %s\n", pid, sep,
|
|
|
|
pid == -1 ? "Unknown" : thread__comm_str(t));
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%llx%s %s%s %s\n", (unsigned long long)st->addr, sep,
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
st->name, sep, get_type_name(st->flags));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aggr_mode == LOCK_AGGR_CALLER && verbose > 0) {
|
|
|
|
struct map *kmap;
|
|
|
|
struct symbol *sym;
|
|
|
|
char buf[128];
|
|
|
|
u64 ip;
|
|
|
|
|
|
|
|
for (int i = 0; i < max_stack_depth; i++) {
|
|
|
|
if (!st->callstack || !st->callstack[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
ip = st->callstack[i];
|
|
|
|
sym = machine__find_kernel_symbol(con->machine, ip, &kmap);
|
|
|
|
get_symbol_name_offset(kmap, sym, ip, buf, sizeof(buf));
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s %#lx %s", i ? ":" : sep, (unsigned long) ip, buf);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\n");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_lock_stat(struct lock_contention *con, struct lock_stat *st)
|
|
|
|
{
|
|
|
|
if (symbol_conf.field_sep)
|
|
|
|
print_lock_stat_csv(con, st, symbol_conf.field_sep);
|
|
|
|
else
|
|
|
|
print_lock_stat_stdio(con, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_footer_stdio(int total, int bad, struct lock_contention_fails *fails)
|
2023-03-28 06:57:11 +08:00
|
|
|
{
|
|
|
|
/* Output for debug, this have to be removed */
|
2023-04-07 05:06:08 +08:00
|
|
|
int broken = fails->task + fails->stack + fails->time + fails->data;
|
2023-03-28 06:57:11 +08:00
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
if (!use_bpf)
|
|
|
|
print_bad_events(bad, total);
|
|
|
|
|
2023-03-28 06:57:11 +08:00
|
|
|
if (quiet || total == 0 || (broken == 0 && verbose <= 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
total += broken;
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\n=== output for debug ===\n\n");
|
|
|
|
fprintf(lock_output, "bad: %d, total: %d\n", broken, total);
|
|
|
|
fprintf(lock_output, "bad rate: %.2f %%\n", 100.0 * broken / total);
|
2023-03-28 06:57:11 +08:00
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "histogram of failure reasons\n");
|
|
|
|
fprintf(lock_output, " %10s: %d\n", "task", fails->task);
|
|
|
|
fprintf(lock_output, " %10s: %d\n", "stack", fails->stack);
|
|
|
|
fprintf(lock_output, " %10s: %d\n", "time", fails->time);
|
|
|
|
fprintf(lock_output, " %10s: %d\n", "data", fails->data);
|
2023-03-28 06:57:11 +08:00
|
|
|
}
|
2023-04-07 05:06:08 +08:00
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
static void print_footer_csv(int total, int bad, struct lock_contention_fails *fails,
|
|
|
|
const char *sep)
|
|
|
|
{
|
|
|
|
/* Output for debug, this have to be removed */
|
|
|
|
if (use_bpf)
|
|
|
|
bad = fails->task + fails->stack + fails->time + fails->data;
|
|
|
|
|
|
|
|
if (quiet || total == 0 || (bad == 0 && verbose <= 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
total += bad;
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "# debug: total=%d%s bad=%d", total, sep, bad);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
|
|
|
|
if (use_bpf) {
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s bad_%s=%d", sep, "task", fails->task);
|
|
|
|
fprintf(lock_output, "%s bad_%s=%d", sep, "stack", fails->stack);
|
|
|
|
fprintf(lock_output, "%s bad_%s=%d", sep, "time", fails->time);
|
|
|
|
fprintf(lock_output, "%s bad_%s=%d", sep, "data", fails->data);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
const char *name[4] = { "acquire", "acquired", "contended", "release" };
|
|
|
|
|
|
|
|
for (i = 0; i < BROKEN_MAX; i++)
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "%s bad_%s=%d", sep, name[i], bad_hist[i]);
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
2023-06-29 04:01:40 +08:00
|
|
|
fprintf(lock_output, "\n");
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_footer(int total, int bad, struct lock_contention_fails *fails)
|
|
|
|
{
|
|
|
|
if (symbol_conf.field_sep)
|
|
|
|
print_footer_csv(total, bad, fails, symbol_conf.field_sep);
|
|
|
|
else
|
|
|
|
print_footer_stdio(total, bad, fails);
|
|
|
|
}
|
|
|
|
|
2022-09-12 13:53:12 +08:00
|
|
|
static void print_contention_result(struct lock_contention *con)
|
2022-07-26 02:31:22 +08:00
|
|
|
{
|
|
|
|
struct lock_stat *st;
|
2022-09-24 08:42:19 +08:00
|
|
|
int bad, total, printed;
|
2022-07-26 02:31:22 +08:00
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
if (!quiet)
|
|
|
|
print_header();
|
2022-07-26 02:31:22 +08:00
|
|
|
|
2022-09-24 08:42:19 +08:00
|
|
|
bad = total = printed = 0;
|
2022-08-03 03:10:04 +08:00
|
|
|
|
2022-07-26 02:31:22 +08:00
|
|
|
while ((st = pop_from_result())) {
|
2022-08-03 03:10:04 +08:00
|
|
|
total += use_bpf ? st->nr_contended : 1;
|
2022-07-26 02:31:22 +08:00
|
|
|
if (st->broken)
|
|
|
|
bad++;
|
|
|
|
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
if (!st->wait_time_total)
|
|
|
|
continue;
|
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
print_lock_stat(con, st);
|
2022-09-24 08:42:19 +08:00
|
|
|
|
|
|
|
if (++printed >= print_nr_entries)
|
|
|
|
break;
|
2022-07-26 02:31:22 +08:00
|
|
|
}
|
|
|
|
|
2023-04-07 05:06:09 +08:00
|
|
|
if (print_nr_entries) {
|
|
|
|
/* update the total/bad stats */
|
|
|
|
while ((st = pop_from_result())) {
|
|
|
|
total += use_bpf ? st->nr_contended : 1;
|
|
|
|
if (st->broken)
|
|
|
|
bad++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* some entries are collected but hidden by the callstack filter */
|
|
|
|
total += con->nr_filtered;
|
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
print_footer(total, bad, &con->fails);
|
2022-07-26 02:31:22 +08:00
|
|
|
}
|
|
|
|
|
2015-04-02 21:47:14 +08:00
|
|
|
static bool force;
|
|
|
|
|
2013-09-09 10:19:16 +08:00
|
|
|
static int __cmd_report(bool display_info)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2013-09-09 10:19:16 +08:00
|
|
|
int err = -EINVAL;
|
2012-10-02 02:20:58 +08:00
|
|
|
struct perf_tool eops = {
|
2022-11-04 13:14:40 +08:00
|
|
|
.attr = perf_event__process_attr,
|
|
|
|
.event_update = process_event_update,
|
2012-10-02 02:20:58 +08:00
|
|
|
.sample = process_sample_event,
|
|
|
|
.comm = perf_event__process_comm,
|
2022-06-16 00:32:22 +08:00
|
|
|
.mmap = perf_event__process_mmap,
|
perf tools: Add PERF_RECORD_NAMESPACES to include namespaces related info
Introduce a new option to record PERF_RECORD_NAMESPACES events emitted
by the kernel when fork, clone, setns or unshare are invoked. And update
perf-record documentation with the new option to record namespace
events.
Committer notes:
Combined it with a later patch to allow printing it via 'perf report -D'
and be able to test the feature introduced in this patch. Had to move
here also perf_ns__name(), that was introduced in another later patch.
Also used PRIu64 and PRIx64 to fix the build in some enfironments wrt:
util/event.c:1129:39: error: format '%lx' expects argument of type 'long unsigned int', but argument 6 has type 'long long unsigned int' [-Werror=format=]
ret += fprintf(fp, "%u/%s: %lu/0x%lx%s", idx
^
Testing it:
# perf record --namespaces -a
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.083 MB perf.data (423 samples) ]
#
# perf report -D
<SNIP>
3 2028902078892 0x115140 [0xa0]: PERF_RECORD_NAMESPACES 14783/14783 - nr_namespaces: 7
[0/net: 3/0xf0000081, 1/uts: 3/0xeffffffe, 2/ipc: 3/0xefffffff, 3/pid: 3/0xeffffffc,
4/user: 3/0xeffffffd, 5/mnt: 3/0xf0000000, 6/cgroup: 3/0xeffffffb]
0x1151e0 [0x30]: event: 9
.
. ... raw event: size 48 bytes
. 0000: 09 00 00 00 02 00 30 00 c4 71 82 68 0c 7f 00 00 ......0..q.h....
. 0010: a9 39 00 00 a9 39 00 00 94 28 fe 63 d8 01 00 00 .9...9...(.c....
. 0020: 03 00 00 00 00 00 00 00 ce c4 02 00 00 00 00 00 ................
<SNIP>
NAMESPACES events: 1
<SNIP>
#
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Aravinda Prasad <aravinda@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sargun Dhillon <sargun@sargun.me>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/148891930386.25309.18412039920746995488.stgit@hbathini.in.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-08 04:41:43 +08:00
|
|
|
.namespaces = perf_event__process_namespaces,
|
2022-11-04 13:14:40 +08:00
|
|
|
.tracing_data = perf_event__process_tracing_data,
|
2014-07-06 20:18:21 +08:00
|
|
|
.ordered_events = true,
|
2012-10-02 02:20:58 +08:00
|
|
|
};
|
2017-01-24 05:07:59 +08:00
|
|
|
struct perf_data data = {
|
2019-02-21 17:41:30 +08:00
|
|
|
.path = input_name,
|
|
|
|
.mode = PERF_DATA_MODE_READ,
|
|
|
|
.force = force,
|
2013-10-15 22:27:32 +08:00
|
|
|
};
|
2013-09-09 10:19:16 +08:00
|
|
|
|
2021-07-20 06:31:49 +08:00
|
|
|
session = perf_session__new(&data, &eops);
|
2019-08-22 15:20:49 +08:00
|
|
|
if (IS_ERR(session)) {
|
2012-08-27 02:24:43 +08:00
|
|
|
pr_err("Initializing perf session failed\n");
|
2019-08-22 15:20:49 +08:00
|
|
|
return PTR_ERR(session);
|
2012-08-27 02:24:43 +08:00
|
|
|
}
|
2010-01-30 19:43:33 +08:00
|
|
|
|
perf lock contention: Fix core dump related to not finding the "__sched_text_end" symbol on s/390
The test case perf lock contention dumps core on s390. Run the following
commands:
# ./perf lock record -- ./perf bench sched messaging
# Running 'sched/messaging' benchmark:
# 20 sender and receiver processes per group
# 10 groups == 400 processes run
Total time: 2.799 [sec]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.073 MB perf.data (100 samples) ]
#
# ./perf lock contention
Segmentation fault (core dumped)
#
The function call stack is lengthy, here are the top 5 functions:
# gdb ./perf core.24048
GNU gdb (GDB) Fedora Linux 12.1-6.fc37
Core was generated by `./perf lock contention'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000011dd25c in machine__is_lock_function (machine=0x3029e28, addr=1789230) at util/machine.c:3356
3356 machine->sched.text_end = kmap->unmap_ip(kmap, sym->start);
(gdb) where
#0 0x00000000011dd25c in machine__is_lock_function (machine=0x3029e28, addr=1789230) at util/machine.c:3356
#1 0x000000000109f244 in callchain_id (evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:957
#2 0x000000000109e094 in get_key_by_aggr_mode (key=0x3ffea4f7290, addr=27758136, evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:586
#3 0x000000000109f4d0 in report_lock_contention_begin_event (evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:1004
#4 0x00000000010a00ae in evsel__process_contention_begin (evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:1254
#5 0x00000000010a0e14 in process_sample_event (tool=0x3ffea4f8480, event=0x3ff85601ef8, sample=0x3ffea4f77d0, evsel=0x30313e0, machine=0x3029e28) at builtin-lock.c:1464
.....
The issue is in function machine__is_lock_function() in file
./util/machine.c lines 3355:
/* should not fail from here */
sym = machine__find_kernel_symbol_by_name(machine, "__sched_text_end", &kmap);
machine->sched.text_end = kmap->unmap_ip(kmap, sym->start)
On s390 the symbol __sched_text_end is *NOT* in the symbol list and the
resulting pointer sym is set to NULL. The sym->start is then a NULL pointer
access and generates the core dump.
The reason why __sched_text_end is not in the symbol list on s390 is
simple:
When the symbol list is created at perf start up with function calls
dso__load
+--> dso__load_vmlinux_path
+--> dso__load_vmlinux
+--> dso__load_sym
+--> dso__load_sym_internal (reads kernel symbols)
+--> symbols__fixup_end
+--> symbols__fixup_duplicate
The issue is in function symbols__fixup_duplicate(). It deletes all
symbols with have the same address. On s390:
# nm -g ~/linux/vmlinux| fgrep c68390
0000000000c68390 T __cpuidle_text_start
0000000000c68390 T __sched_text_end
#
two symbols have identical addresses and __sched_text_end is considered
duplicate (in ascending sort order) and removed from the symbol list.
Therefore it is missing and an invalid pointer reference occurs. The
code checks for symbol __sched_text_start and when it exists assumes
symbol __sched_text_end is also in the symbol table. However this is not
the case on s390.
Same situation exists for symbol __lock_text_start:
0000000000c68770 T __cpuidle_text_end
0000000000c68770 T __lock_text_start
This symbol is also removed from the symbol table but used in function
machine__is_lock_function().
To fix this and keep duplicate symbols in the symbol table, set
symbol_conf.allow_aliases to true. This prevents the removal of
duplicate symbols in function symbols__fixup_duplicate().
Output After:
# ./perf lock contention
contended total wait max wait avg wait type caller
48 124.39 ms 123.99 ms 2.59 ms rwsem:W unlink_anon_vmas+0x24a
47 83.68 ms 83.26 ms 1.78 ms rwsem:W free_pgtables+0x132
5 41.22 us 10.55 us 8.24 us rwsem:W free_pgtables+0x140
4 40.12 us 20.55 us 10.03 us rwsem:W copy_process+0x1ac8
#
Fixes: 0d2997f750d1de39 ("perf lock: Look up callchain for the contended locks")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: https://lore.kernel.org/r/20221230102627.2410847-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-30 18:26:27 +08:00
|
|
|
symbol_conf.allow_aliases = true;
|
2014-08-12 14:40:45 +08:00
|
|
|
symbol__init(&session->header.env);
|
2014-08-12 14:40:40 +08:00
|
|
|
|
2022-11-04 13:14:40 +08:00
|
|
|
if (!data.is_pipe) {
|
|
|
|
if (!perf_session__has_traces(session, "lock record"))
|
|
|
|
goto out_delete;
|
2013-09-09 10:19:16 +08:00
|
|
|
|
2022-11-04 13:14:40 +08:00
|
|
|
if (perf_session__set_tracepoints_handlers(session, lock_tracepoints)) {
|
|
|
|
pr_err("Initializing perf session tracepoint handlers failed\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2012-09-24 21:52:12 +08:00
|
|
|
|
2022-11-04 13:14:40 +08:00
|
|
|
if (perf_session__set_tracepoints_handlers(session, contention_tracepoints)) {
|
|
|
|
pr_err("Initializing perf session tracepoint handlers failed\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-06-16 00:32:20 +08:00
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
if (setup_output_field(false, output_fields))
|
2022-03-24 07:02:58 +08:00
|
|
|
goto out_delete;
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
if (select_key(false))
|
2013-09-09 10:19:16 +08:00
|
|
|
goto out_delete;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2022-07-26 02:31:21 +08:00
|
|
|
if (show_thread_stats)
|
|
|
|
aggr_mode = LOCK_AGGR_TASK;
|
|
|
|
|
2015-03-03 22:58:45 +08:00
|
|
|
err = perf_session__process_events(session);
|
2013-09-09 10:19:16 +08:00
|
|
|
if (err)
|
|
|
|
goto out_delete;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
|
|
|
setup_pager();
|
2013-09-09 10:19:16 +08:00
|
|
|
if (display_info) /* used for info subcommand */
|
|
|
|
err = dump_info();
|
|
|
|
else {
|
2022-01-27 08:00:49 +08:00
|
|
|
combine_result();
|
2013-09-09 10:19:16 +08:00
|
|
|
sort_result();
|
|
|
|
print_result();
|
|
|
|
}
|
2012-08-27 02:24:43 +08:00
|
|
|
|
2013-09-09 10:19:16 +08:00
|
|
|
out_delete:
|
|
|
|
perf_session__delete(session);
|
|
|
|
return err;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
static void sighandler(int sig __maybe_unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-07 08:24:02 +08:00
|
|
|
static int check_lock_contention_options(const struct option *options,
|
|
|
|
const char * const *usage)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (show_thread_stats && show_lock_addrs) {
|
|
|
|
pr_err("Cannot use thread and addr mode together\n");
|
|
|
|
parse_options_usage(usage, options, "threads", 0);
|
|
|
|
parse_options_usage(NULL, options, "lock-addr", 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_lock_owner && !use_bpf) {
|
|
|
|
pr_err("Lock owners are available only with BPF\n");
|
|
|
|
parse_options_usage(usage, options, "lock-owner", 0);
|
|
|
|
parse_options_usage(NULL, options, "use-bpf", 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_lock_owner && show_lock_addrs) {
|
|
|
|
pr_err("Cannot use owner and addr mode together\n");
|
|
|
|
parse_options_usage(usage, options, "lock-owner", 0);
|
|
|
|
parse_options_usage(NULL, options, "lock-addr", 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
if (symbol_conf.field_sep) {
|
|
|
|
if (strstr(symbol_conf.field_sep, ":") || /* part of type flags */
|
|
|
|
strstr(symbol_conf.field_sep, "+") || /* part of caller offset */
|
|
|
|
strstr(symbol_conf.field_sep, ".")) { /* can be in a symbol name */
|
|
|
|
pr_err("Cannot use the separator that is already used\n");
|
|
|
|
parse_options_usage(usage, options, "x", 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 08:24:02 +08:00
|
|
|
if (show_lock_owner)
|
|
|
|
show_thread_stats = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-30 04:07:56 +08:00
|
|
|
static int __cmd_contention(int argc, const char **argv)
|
2022-07-26 02:31:22 +08:00
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
|
|
|
struct perf_tool eops = {
|
2022-11-04 13:14:40 +08:00
|
|
|
.attr = perf_event__process_attr,
|
|
|
|
.event_update = process_event_update,
|
2022-07-26 02:31:22 +08:00
|
|
|
.sample = process_sample_event,
|
|
|
|
.comm = perf_event__process_comm,
|
|
|
|
.mmap = perf_event__process_mmap,
|
2022-11-04 13:14:40 +08:00
|
|
|
.tracing_data = perf_event__process_tracing_data,
|
2022-07-26 02:31:22 +08:00
|
|
|
.ordered_events = true,
|
|
|
|
};
|
|
|
|
struct perf_data data = {
|
|
|
|
.path = input_name,
|
|
|
|
.mode = PERF_DATA_MODE_READ,
|
|
|
|
.force = force,
|
|
|
|
};
|
2022-08-03 03:10:02 +08:00
|
|
|
struct lock_contention con = {
|
|
|
|
.target = &target,
|
2022-08-03 03:10:03 +08:00
|
|
|
.map_nr_entries = bpf_map_entries,
|
2022-09-12 13:53:13 +08:00
|
|
|
.max_stack = max_stack_depth,
|
|
|
|
.stack_skip = stack_skip,
|
2022-12-20 04:17:29 +08:00
|
|
|
.filters = &filters,
|
2023-01-26 08:09:36 +08:00
|
|
|
.save_callstack = needs_callstack(),
|
2023-02-07 08:24:02 +08:00
|
|
|
.owner = show_lock_owner,
|
2022-08-03 03:10:02 +08:00
|
|
|
};
|
2022-07-26 02:31:22 +08:00
|
|
|
|
2023-05-27 02:33:54 +08:00
|
|
|
lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table));
|
|
|
|
if (!lockhash_table)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
con.result = &lockhash_table[0];
|
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
session = perf_session__new(use_bpf ? NULL : &data, &eops);
|
2022-07-26 02:31:22 +08:00
|
|
|
if (IS_ERR(session)) {
|
|
|
|
pr_err("Initializing perf session failed\n");
|
2023-05-27 02:33:54 +08:00
|
|
|
err = PTR_ERR(session);
|
|
|
|
goto out_delete;
|
2022-07-26 02:31:22 +08:00
|
|
|
}
|
|
|
|
|
2022-09-12 13:53:12 +08:00
|
|
|
con.machine = &session->machines.host;
|
|
|
|
|
2022-12-10 03:07:26 +08:00
|
|
|
con.aggr_mode = aggr_mode = show_thread_stats ? LOCK_AGGR_TASK :
|
|
|
|
show_lock_addrs ? LOCK_AGGR_ADDR : LOCK_AGGR_CALLER;
|
|
|
|
|
2023-02-07 08:24:01 +08:00
|
|
|
if (con.aggr_mode == LOCK_AGGR_CALLER)
|
|
|
|
con.save_callstack = true;
|
|
|
|
|
perf lock contention: Fix core dump related to not finding the "__sched_text_end" symbol on s/390
The test case perf lock contention dumps core on s390. Run the following
commands:
# ./perf lock record -- ./perf bench sched messaging
# Running 'sched/messaging' benchmark:
# 20 sender and receiver processes per group
# 10 groups == 400 processes run
Total time: 2.799 [sec]
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.073 MB perf.data (100 samples) ]
#
# ./perf lock contention
Segmentation fault (core dumped)
#
The function call stack is lengthy, here are the top 5 functions:
# gdb ./perf core.24048
GNU gdb (GDB) Fedora Linux 12.1-6.fc37
Core was generated by `./perf lock contention'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000011dd25c in machine__is_lock_function (machine=0x3029e28, addr=1789230) at util/machine.c:3356
3356 machine->sched.text_end = kmap->unmap_ip(kmap, sym->start);
(gdb) where
#0 0x00000000011dd25c in machine__is_lock_function (machine=0x3029e28, addr=1789230) at util/machine.c:3356
#1 0x000000000109f244 in callchain_id (evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:957
#2 0x000000000109e094 in get_key_by_aggr_mode (key=0x3ffea4f7290, addr=27758136, evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:586
#3 0x000000000109f4d0 in report_lock_contention_begin_event (evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:1004
#4 0x00000000010a00ae in evsel__process_contention_begin (evsel=0x30313e0, sample=0x3ffea4f77d0) at builtin-lock.c:1254
#5 0x00000000010a0e14 in process_sample_event (tool=0x3ffea4f8480, event=0x3ff85601ef8, sample=0x3ffea4f77d0, evsel=0x30313e0, machine=0x3029e28) at builtin-lock.c:1464
.....
The issue is in function machine__is_lock_function() in file
./util/machine.c lines 3355:
/* should not fail from here */
sym = machine__find_kernel_symbol_by_name(machine, "__sched_text_end", &kmap);
machine->sched.text_end = kmap->unmap_ip(kmap, sym->start)
On s390 the symbol __sched_text_end is *NOT* in the symbol list and the
resulting pointer sym is set to NULL. The sym->start is then a NULL pointer
access and generates the core dump.
The reason why __sched_text_end is not in the symbol list on s390 is
simple:
When the symbol list is created at perf start up with function calls
dso__load
+--> dso__load_vmlinux_path
+--> dso__load_vmlinux
+--> dso__load_sym
+--> dso__load_sym_internal (reads kernel symbols)
+--> symbols__fixup_end
+--> symbols__fixup_duplicate
The issue is in function symbols__fixup_duplicate(). It deletes all
symbols with have the same address. On s390:
# nm -g ~/linux/vmlinux| fgrep c68390
0000000000c68390 T __cpuidle_text_start
0000000000c68390 T __sched_text_end
#
two symbols have identical addresses and __sched_text_end is considered
duplicate (in ascending sort order) and removed from the symbol list.
Therefore it is missing and an invalid pointer reference occurs. The
code checks for symbol __sched_text_start and when it exists assumes
symbol __sched_text_end is also in the symbol table. However this is not
the case on s390.
Same situation exists for symbol __lock_text_start:
0000000000c68770 T __cpuidle_text_end
0000000000c68770 T __lock_text_start
This symbol is also removed from the symbol table but used in function
machine__is_lock_function().
To fix this and keep duplicate symbols in the symbol table, set
symbol_conf.allow_aliases to true. This prevents the removal of
duplicate symbols in function symbols__fixup_duplicate().
Output After:
# ./perf lock contention
contended total wait max wait avg wait type caller
48 124.39 ms 123.99 ms 2.59 ms rwsem:W unlink_anon_vmas+0x24a
47 83.68 ms 83.26 ms 1.78 ms rwsem:W free_pgtables+0x132
5 41.22 us 10.55 us 8.24 us rwsem:W free_pgtables+0x140
4 40.12 us 20.55 us 10.03 us rwsem:W copy_process+0x1ac8
#
Fixes: 0d2997f750d1de39 ("perf lock: Look up callchain for the contended locks")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: https://lore.kernel.org/r/20221230102627.2410847-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-30 18:26:27 +08:00
|
|
|
symbol_conf.allow_aliases = true;
|
2022-07-26 02:31:22 +08:00
|
|
|
symbol__init(&session->header.env);
|
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
if (use_bpf) {
|
2022-07-30 04:07:56 +08:00
|
|
|
err = target__validate(&target);
|
|
|
|
if (err) {
|
|
|
|
char errbuf[512];
|
|
|
|
|
|
|
|
target__strerror(&target, err, errbuf, 512);
|
|
|
|
pr_err("%s\n", errbuf);
|
|
|
|
goto out_delete;
|
2022-07-30 04:07:55 +08:00
|
|
|
}
|
2022-07-26 02:31:22 +08:00
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
signal(SIGINT, sighandler);
|
|
|
|
signal(SIGCHLD, sighandler);
|
|
|
|
signal(SIGTERM, sighandler);
|
2022-07-30 04:07:56 +08:00
|
|
|
|
2022-08-03 03:10:02 +08:00
|
|
|
con.evlist = evlist__new();
|
|
|
|
if (con.evlist == NULL) {
|
2022-07-30 04:07:56 +08:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_delete;
|
|
|
|
}
|
|
|
|
|
2022-08-03 03:10:02 +08:00
|
|
|
err = evlist__create_maps(con.evlist, &target);
|
2022-07-30 04:07:56 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto out_delete;
|
|
|
|
|
|
|
|
if (argc) {
|
2022-08-03 03:10:02 +08:00
|
|
|
err = evlist__prepare_workload(con.evlist, &target,
|
2022-07-30 04:07:56 +08:00
|
|
|
argv, false, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto out_delete;
|
|
|
|
}
|
|
|
|
|
2022-08-03 03:10:02 +08:00
|
|
|
if (lock_contention_prepare(&con) < 0) {
|
2022-07-30 04:07:56 +08:00
|
|
|
pr_err("lock contention BPF setup failed\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-11-04 13:14:40 +08:00
|
|
|
} else if (!data.is_pipe) {
|
2022-07-30 04:07:55 +08:00
|
|
|
if (!perf_session__has_traces(session, "lock record"))
|
|
|
|
goto out_delete;
|
2022-07-26 02:31:22 +08:00
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
if (!evlist__find_evsel_by_str(session->evlist,
|
|
|
|
"lock:contention_begin")) {
|
|
|
|
pr_err("lock contention evsel not found\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (perf_session__set_tracepoints_handlers(session,
|
|
|
|
contention_tracepoints)) {
|
|
|
|
pr_err("Initializing perf session tracepoint handlers failed\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-07-26 02:31:22 +08:00
|
|
|
}
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
if (setup_output_field(true, output_fields))
|
2022-07-26 02:31:22 +08:00
|
|
|
goto out_delete;
|
|
|
|
|
2022-07-26 02:31:23 +08:00
|
|
|
if (select_key(true))
|
2022-07-26 02:31:22 +08:00
|
|
|
goto out_delete;
|
|
|
|
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
if (symbol_conf.field_sep) {
|
|
|
|
int i;
|
|
|
|
struct lock_key *keys = contention_keys;
|
|
|
|
|
|
|
|
/* do not align output in CSV format */
|
|
|
|
for (i = 0; keys[i].name; i++)
|
|
|
|
keys[i].len = 0;
|
|
|
|
}
|
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
if (use_bpf) {
|
|
|
|
lock_contention_start();
|
2022-07-30 04:07:56 +08:00
|
|
|
if (argc)
|
2022-08-03 03:10:02 +08:00
|
|
|
evlist__start_workload(con.evlist);
|
2022-07-30 04:07:55 +08:00
|
|
|
|
|
|
|
/* wait for signal */
|
|
|
|
pause();
|
|
|
|
|
|
|
|
lock_contention_stop();
|
2022-08-03 03:10:02 +08:00
|
|
|
lock_contention_read(&con);
|
2022-07-30 04:07:55 +08:00
|
|
|
} else {
|
|
|
|
err = perf_session__process_events(session);
|
|
|
|
if (err)
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-07-26 02:31:22 +08:00
|
|
|
|
|
|
|
setup_pager();
|
|
|
|
|
|
|
|
sort_contention_result();
|
2022-09-12 13:53:12 +08:00
|
|
|
print_contention_result(&con);
|
2022-07-26 02:31:22 +08:00
|
|
|
|
|
|
|
out_delete:
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
lock_filter_finish();
|
2022-08-03 03:10:02 +08:00
|
|
|
evlist__delete(con.evlist);
|
2022-07-30 04:07:55 +08:00
|
|
|
lock_contention_finish();
|
2022-07-26 02:31:22 +08:00
|
|
|
perf_session__delete(session);
|
2023-05-27 02:33:54 +08:00
|
|
|
zfree(&lockhash_table);
|
2022-07-26 02:31:22 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
static int __cmd_record(int argc, const char **argv)
|
|
|
|
{
|
2012-10-02 02:20:58 +08:00
|
|
|
const char *record_args[] = {
|
2022-06-01 14:58:42 +08:00
|
|
|
"record", "-R", "-m", "1024", "-c", "1", "--synth", "task",
|
2012-10-02 02:20:58 +08:00
|
|
|
};
|
2022-06-16 00:32:22 +08:00
|
|
|
const char *callgraph_args[] = {
|
|
|
|
"--call-graph", "fp," __stringify(CONTENTION_STACK_DEPTH),
|
|
|
|
};
|
2013-09-09 10:19:15 +08:00
|
|
|
unsigned int rec_argc, i, j, ret;
|
2022-06-16 00:32:19 +08:00
|
|
|
unsigned int nr_tracepoints;
|
2022-06-16 00:32:22 +08:00
|
|
|
unsigned int nr_callgraph_args = 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
const char **rec_argv;
|
2022-06-16 00:32:19 +08:00
|
|
|
bool has_lock_stat = true;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2012-08-10 00:35:37 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(lock_tracepoints); i++) {
|
2012-09-24 21:52:12 +08:00
|
|
|
if (!is_valid_tracepoint(lock_tracepoints[i].name)) {
|
2022-06-16 00:32:19 +08:00
|
|
|
pr_debug("tracepoint %s is not enabled. "
|
|
|
|
"Are CONFIG_LOCKDEP and CONFIG_LOCK_STAT enabled?\n",
|
|
|
|
lock_tracepoints[i].name);
|
|
|
|
has_lock_stat = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_lock_stat)
|
|
|
|
goto setup_args;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(contention_tracepoints); i++) {
|
|
|
|
if (!is_valid_tracepoint(contention_tracepoints[i].name)) {
|
|
|
|
pr_err("tracepoint %s is not enabled.\n",
|
|
|
|
contention_tracepoints[i].name);
|
|
|
|
return 1;
|
2012-08-10 00:35:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:22 +08:00
|
|
|
nr_callgraph_args = ARRAY_SIZE(callgraph_args);
|
|
|
|
|
2022-06-16 00:32:19 +08:00
|
|
|
setup_args:
|
2022-06-16 00:32:22 +08:00
|
|
|
rec_argc = ARRAY_SIZE(record_args) + nr_callgraph_args + argc - 1;
|
2022-06-16 00:32:19 +08:00
|
|
|
|
|
|
|
if (has_lock_stat)
|
|
|
|
nr_tracepoints = ARRAY_SIZE(lock_tracepoints);
|
|
|
|
else
|
|
|
|
nr_tracepoints = ARRAY_SIZE(contention_tracepoints);
|
|
|
|
|
2012-08-10 00:35:37 +08:00
|
|
|
/* factor of 2 is for -e in front of each tracepoint */
|
2022-06-16 00:32:19 +08:00
|
|
|
rec_argc += 2 * nr_tracepoints;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2012-08-10 00:35:37 +08:00
|
|
|
rec_argv = calloc(rec_argc + 1, sizeof(char *));
|
2013-09-09 10:19:15 +08:00
|
|
|
if (!rec_argv)
|
2010-11-13 10:35:06 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(record_args); i++)
|
|
|
|
rec_argv[i] = strdup(record_args[i]);
|
|
|
|
|
2022-06-16 00:32:19 +08:00
|
|
|
for (j = 0; j < nr_tracepoints; j++) {
|
|
|
|
const char *ev_name;
|
|
|
|
|
|
|
|
if (has_lock_stat)
|
|
|
|
ev_name = strdup(lock_tracepoints[j].name);
|
|
|
|
else
|
|
|
|
ev_name = strdup(contention_tracepoints[j].name);
|
|
|
|
|
|
|
|
if (!ev_name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-08-10 00:35:37 +08:00
|
|
|
rec_argv[i++] = "-e";
|
2022-06-16 00:32:19 +08:00
|
|
|
rec_argv[i++] = ev_name;
|
2012-08-10 00:35:37 +08:00
|
|
|
}
|
|
|
|
|
2022-06-16 00:32:22 +08:00
|
|
|
for (j = 0; j < nr_callgraph_args; j++, i++)
|
|
|
|
rec_argv[i] = callgraph_args[j];
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
for (j = 1; j < (unsigned int)argc; j++, i++)
|
|
|
|
rec_argv[i] = argv[j];
|
|
|
|
|
|
|
|
BUG_ON(i != rec_argc);
|
|
|
|
|
2017-03-27 22:47:20 +08:00
|
|
|
ret = cmd_record(i, rec_argv);
|
2013-09-09 10:19:15 +08:00
|
|
|
free(rec_argv);
|
|
|
|
return ret;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
|
|
|
|
2022-08-03 03:10:03 +08:00
|
|
|
static int parse_map_entry(const struct option *opt, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
unsigned long *len = (unsigned long *)opt->value;
|
|
|
|
unsigned long val;
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtoul(str, &endptr, 0);
|
|
|
|
if (*endptr != '\0' || errno != 0) {
|
|
|
|
pr_err("invalid BPF map length: %s\n", str);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-29 02:01:26 +08:00
|
|
|
static int parse_max_stack(const struct option *opt, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
unsigned long *len = (unsigned long *)opt->value;
|
|
|
|
long val;
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
val = strtol(str, &endptr, 0);
|
|
|
|
if (*endptr != '\0' || errno != 0) {
|
|
|
|
pr_err("invalid max stack depth: %s\n", str);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val < 0 || val > sysctl__max_stack()) {
|
|
|
|
pr_err("invalid max stack depth: %ld\n", val);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
static bool add_lock_type(unsigned int flags)
|
|
|
|
{
|
|
|
|
unsigned int *tmp;
|
|
|
|
|
|
|
|
tmp = realloc(filters.types, (filters.nr_types + 1) * sizeof(*filters.types));
|
|
|
|
if (tmp == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tmp[filters.nr_types++] = flags;
|
|
|
|
filters.types = tmp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_lock_type(const struct option *opt __maybe_unused, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
char *s, *tmp, *tok;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
s = strdup(str);
|
|
|
|
if (s == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
|
|
|
|
unsigned int flags = get_type_flag(tok);
|
|
|
|
|
|
|
|
if (flags == -1U) {
|
2023-04-07 05:06:05 +08:00
|
|
|
pr_err("Unknown lock flags: %s\n", tok);
|
|
|
|
ret = -1;
|
|
|
|
break;
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!add_lock_type(flags)) {
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-12-20 04:17:30 +08:00
|
|
|
static bool add_lock_addr(unsigned long addr)
|
|
|
|
{
|
|
|
|
unsigned long *tmp;
|
|
|
|
|
|
|
|
tmp = realloc(filters.addrs, (filters.nr_addrs + 1) * sizeof(*filters.addrs));
|
|
|
|
if (tmp == NULL) {
|
|
|
|
pr_err("Memory allocation failure\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp[filters.nr_addrs++] = addr;
|
|
|
|
filters.addrs = tmp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool add_lock_sym(char *name)
|
|
|
|
{
|
|
|
|
char **tmp;
|
|
|
|
char *sym = strdup(name);
|
|
|
|
|
|
|
|
if (sym == NULL) {
|
|
|
|
pr_err("Memory allocation failure\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = realloc(filters.syms, (filters.nr_syms + 1) * sizeof(*filters.syms));
|
|
|
|
if (tmp == NULL) {
|
|
|
|
pr_err("Memory allocation failure\n");
|
|
|
|
free(sym);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp[filters.nr_syms++] = sym;
|
|
|
|
filters.syms = tmp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_lock_addr(const struct option *opt __maybe_unused, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
char *s, *tmp, *tok;
|
|
|
|
int ret = 0;
|
|
|
|
u64 addr;
|
|
|
|
|
|
|
|
s = strdup(str);
|
|
|
|
if (s == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
addr = strtoul(tok, &end, 16);
|
|
|
|
if (*end == '\0') {
|
|
|
|
if (!add_lock_addr(addr)) {
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this moment, we don't have kernel symbols. Save the symbols
|
|
|
|
* in a separate list and resolve them to addresses later.
|
|
|
|
*/
|
|
|
|
if (!add_lock_sym(tok)) {
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-26 08:09:36 +08:00
|
|
|
static int parse_call_stack(const struct option *opt __maybe_unused, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
char *s, *tmp, *tok;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
s = strdup(str);
|
|
|
|
if (s == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
|
|
|
|
struct callstack_filter *entry;
|
|
|
|
|
|
|
|
entry = malloc(sizeof(*entry) + strlen(tok) + 1);
|
|
|
|
if (entry == NULL) {
|
|
|
|
pr_err("Memory allocation failure\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(entry->name, tok);
|
|
|
|
list_add_tail(&entry->list, &callstack_filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
static int parse_output(const struct option *opt __maybe_unused, const char *str,
|
|
|
|
int unset __maybe_unused)
|
|
|
|
{
|
|
|
|
const char **name = (const char **)opt->value;
|
|
|
|
|
|
|
|
if (str == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
lock_output = fopen(str, "w");
|
|
|
|
if (lock_output == NULL) {
|
|
|
|
pr_err("Cannot open %s\n", str);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*name = str;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-27 22:47:20 +08:00
|
|
|
int cmd_lock(int argc, const char **argv)
|
2010-01-30 19:43:33 +08:00
|
|
|
{
|
2017-03-17 13:53:42 +08:00
|
|
|
const struct option lock_options[] = {
|
|
|
|
OPT_STRING('i', "input", &input_name, "file", "input file name"),
|
2023-06-29 04:01:40 +08:00
|
|
|
OPT_CALLBACK(0, "output", &output_name, "file", "output file name", parse_output),
|
2017-03-17 13:53:42 +08:00
|
|
|
OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
|
|
|
|
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
|
2017-03-17 22:16:02 +08:00
|
|
|
OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
|
2022-06-16 00:32:17 +08:00
|
|
|
OPT_STRING(0, "vmlinux", &symbol_conf.vmlinux_name,
|
|
|
|
"file", "vmlinux pathname"),
|
|
|
|
OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
|
|
|
|
"file", "kallsyms pathname"),
|
2022-10-18 17:41:36 +08:00
|
|
|
OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"),
|
2017-03-17 13:53:42 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2012-10-02 02:20:58 +08:00
|
|
|
const struct option info_options[] = {
|
|
|
|
OPT_BOOLEAN('t', "threads", &info_threads,
|
|
|
|
"dump thread list in perf.data"),
|
|
|
|
OPT_BOOLEAN('m', "map", &info_map,
|
|
|
|
"map of lock instances (address:name table)"),
|
2017-03-17 13:53:42 +08:00
|
|
|
OPT_PARENT(lock_options)
|
2012-10-02 02:20:58 +08:00
|
|
|
};
|
2017-03-17 13:53:42 +08:00
|
|
|
|
2012-10-02 02:20:58 +08:00
|
|
|
const struct option report_options[] = {
|
|
|
|
OPT_STRING('k', "key", &sort_key, "acquired",
|
2013-09-09 10:19:19 +08:00
|
|
|
"key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
|
2022-03-24 07:02:59 +08:00
|
|
|
OPT_STRING('F', "field", &output_fields, NULL,
|
|
|
|
"output fields (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
|
2012-10-02 02:20:58 +08:00
|
|
|
/* TODO: type */
|
2022-01-27 08:00:49 +08:00
|
|
|
OPT_BOOLEAN('c', "combine-locks", &combine_locks,
|
|
|
|
"combine locks in the same class"),
|
2022-05-21 09:08:11 +08:00
|
|
|
OPT_BOOLEAN('t', "threads", &show_thread_stats,
|
|
|
|
"show per-thread lock stats"),
|
2022-09-24 08:42:19 +08:00
|
|
|
OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
|
2017-03-17 13:53:42 +08:00
|
|
|
OPT_PARENT(lock_options)
|
2012-10-02 02:20:58 +08:00
|
|
|
};
|
2017-03-17 13:53:42 +08:00
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
struct option contention_options[] = {
|
2022-07-26 02:31:23 +08:00
|
|
|
OPT_STRING('k', "key", &sort_key, "wait_total",
|
|
|
|
"key for sorting (contended / wait_total / wait_max / wait_min / avg_wait)"),
|
|
|
|
OPT_STRING('F', "field", &output_fields, "contended,wait_total,wait_max,avg_wait",
|
|
|
|
"output fields (contended / wait_total / wait_max / wait_min / avg_wait)"),
|
2022-07-26 02:31:24 +08:00
|
|
|
OPT_BOOLEAN('t', "threads", &show_thread_stats,
|
|
|
|
"show per-thread lock stats"),
|
2022-07-30 04:07:55 +08:00
|
|
|
OPT_BOOLEAN('b', "use-bpf", &use_bpf, "use BPF program to collect lock contention stats"),
|
2022-07-30 04:07:56 +08:00
|
|
|
OPT_BOOLEAN('a', "all-cpus", &target.system_wide,
|
|
|
|
"System-wide collection from all CPUs"),
|
|
|
|
OPT_STRING('C', "cpu", &target.cpu_list, "cpu",
|
|
|
|
"List of cpus to monitor"),
|
|
|
|
OPT_STRING('p', "pid", &target.pid, "pid",
|
|
|
|
"Trace on existing process id"),
|
|
|
|
OPT_STRING(0, "tid", &target.tid, "tid",
|
|
|
|
"Trace on existing thread id (exclusive to --pid)"),
|
2023-04-07 05:06:06 +08:00
|
|
|
OPT_CALLBACK('M', "map-nr-entries", &bpf_map_entries, "num",
|
2022-08-03 03:10:03 +08:00
|
|
|
"Max number of BPF map entries", parse_map_entry),
|
2022-10-29 02:01:26 +08:00
|
|
|
OPT_CALLBACK(0, "max-stack", &max_stack_depth, "num",
|
|
|
|
"Set the maximum stack depth when collecting lopck contention, "
|
|
|
|
"Default: " __stringify(CONTENTION_STACK_DEPTH), parse_max_stack),
|
2022-09-12 13:53:13 +08:00
|
|
|
OPT_INTEGER(0, "stack-skip", &stack_skip,
|
|
|
|
"Set the number of stack depth to skip when finding a lock caller, "
|
|
|
|
"Default: " __stringify(CONTENTION_STACK_SKIP)),
|
2022-09-24 08:42:19 +08:00
|
|
|
OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
|
2022-12-10 03:07:26 +08:00
|
|
|
OPT_BOOLEAN('l', "lock-addr", &show_lock_addrs, "show lock stats by address"),
|
perf lock contention: Add -Y/--type-filter option
The -Y/--type-filter option is to filter the result for specific lock
types only. It can accept comma-separated values. Note that it would
accept type names like one in the output. spinlock, mutex, rwsem:R and
so on.
For RW-variant lock types, it converts the name to the both variants.
In other words, "rwsem" is same as "rwsem:R,rwsem:W". Also note that
"mutex" has two different encoding - one for sleeping wait, another for
optimistic spinning. Add "mutex-spin" entry for the lock_type_table so
that we can add it for "mutex" under the table.
$ sudo ./perf lock record -a -- ./perf bench sched messaging
$ sudo ./perf lock con -E 5 -Y spinlock
contended total wait max wait avg wait type caller
802 1.26 ms 11.73 us 1.58 us spinlock __wake_up_common_lock+0x62
13 787.16 us 105.44 us 60.55 us spinlock remove_wait_queue+0x14
12 612.96 us 78.70 us 51.08 us spinlock prepare_to_wait+0x27
114 340.68 us 12.61 us 2.99 us spinlock try_to_wake_up+0x1f5
83 226.38 us 9.15 us 2.73 us spinlock folio_lruvec_lock_irqsave+0x5e
Committer notes:
Make get_type_flag() return UINT_MAX for error instad of -1UL, as that
function returns 'unsigned int' and we store the value on a 'unsigned
int' 'flags' variable which makes clang unhappy:
35 98.23 fedora:37 : FAIL clang version 15.0.6 (Fedora 15.0.6-1.fc37)
builtin-lock.c:2012:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2021:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
builtin-lock.c:2037:14: error: result of comparison of constant 18446744073709551615 with expression of type 'unsigned int' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
if (flags != -1UL) {
~~~~~ ^ ~~~~
3 errors generated.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
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: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221219201732.460111-3-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-12-20 04:17:28 +08:00
|
|
|
OPT_CALLBACK('Y', "type-filter", NULL, "FLAGS",
|
|
|
|
"Filter specific type of locks", parse_lock_type),
|
2022-12-20 04:17:30 +08:00
|
|
|
OPT_CALLBACK('L', "lock-filter", NULL, "ADDRS/NAMES",
|
|
|
|
"Filter specific address/symbol of locks", parse_lock_addr),
|
2023-01-26 08:09:36 +08:00
|
|
|
OPT_CALLBACK('S', "callstack-filter", NULL, "NAMES",
|
|
|
|
"Filter specific function in the callstack", parse_call_stack),
|
2023-02-07 08:24:02 +08:00
|
|
|
OPT_BOOLEAN('o', "lock-owner", &show_lock_owner, "show lock owners instead of waiters"),
|
perf lock contention: Add -x option for CSV style output
Sometimes we want to process the output by external programs. Let's add
the -x option to specify the field separator like perf stat.
$ sudo ./perf lock con -ab -x, sleep 1
# output: contended, total wait, max wait, avg wait, type, caller
19, 194232, 21415, 10222, spinlock, process_one_work+0x1f0
15, 162748, 23843, 10849, rwsem:R, do_user_addr_fault+0x40e
4, 86740, 23415, 21685, rwlock:R, ep_poll_callback+0x2d
1, 84281, 84281, 84281, mutex, iwl_mvm_async_handlers_wk+0x135
8, 67608, 27404, 8451, spinlock, __queue_work+0x174
3, 58616, 31125, 19538, rwsem:W, do_mprotect_pkey+0xff
3, 52953, 21172, 17651, rwlock:W, do_epoll_wait+0x248
2, 30324, 19704, 15162, rwsem:R, do_madvise+0x3ad
1, 24619, 24619, 24619, spinlock, rcu_core+0xd4
The first line is a comment that shows the output format. Each line is
separated by the given string ("," in this case). The time is printed
in nsec without the unit so that it can be parsed easily.
The characters can be used in the output like (":", "+" and ".") are not
allowed for the -x option.
$ ./perf lock con -x:
Cannot use the separator that is already used
Usage: perf lock contention [<options>]
-x, --field-separator <separator>
print result in CSV format with custom separator
The stacktraces are printed in the same line separated by ":". The
header is updated to show the stacktrace. Also the debug output is
added at the end as a comment.
$ sudo ./perf lock con -abv -x, -F wait_total sleep 1
Looking at the vmlinux_path (8 entries long)
symsrc__init: cannot get elf header.
Using /proc/kcore for kernel data
Using /proc/kallsyms for symbols
# output: total wait, type, caller, stacktrace
37134, spinlock, rcu_core+0xd4, 0xffffffff9d0401e4 _raw_spin_lock_irqsave+0x44: 0xffffffff9c738114 rcu_core+0xd4: ...
21213, spinlock, raw_spin_rq_lock_nested+0x1b, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9c6d9cfb raw_spin_rq_lock_nested+0x1b: ...
20506, rwlock:W, ep_done_scan+0x2d, 0xffffffff9c9bc4dd ep_done_scan+0x2d: 0xffffffff9c9bd5f1 do_epoll_wait+0x6d1: ...
18044, rwlock:R, ep_poll_callback+0x2d, 0xffffffff9d040555 _raw_read_lock_irqsave+0x45: 0xffffffff9c9bc81d ep_poll_callback+0x2d: ...
17890, rwlock:W, do_epoll_wait+0x47b, 0xffffffff9c9bd39b do_epoll_wait+0x47b: 0xffffffff9c9be9ef __x64_sys_epoll_wait+0x6d1: ...
12114, spinlock, futex_wait_queue+0x60, 0xffffffff9d0407c0 _raw_spin_lock+0x30: 0xffffffff9d037cae __schedule+0xbe: ...
# debug: total=7, bad=0, bad_task=0, bad_stack=0, bad_time=0, bad_data=0
Also note that some field (like lock symbols) can be empty.
$ sudo ./perf lock con -abl -x, -E 10 sleep 1
# output: contended, total wait, max wait, avg wait, address, symbol, type
6, 275025, 61764, 45837, ffff9dcc9f7d60d0, , spinlock
18, 87716, 11196, 4873, ffff9dc540059000, , spinlock
2, 6472, 5499, 3236, ffff9dcc7f730e00, rq_lock, spinlock
3, 4429, 2341, 1476, ffff9dcc7f7b0e00, rq_lock, spinlock
3, 3974, 1635, 1324, ffff9dcc7f7f0e00, rq_lock, spinlock
4, 3290, 1326, 822, ffff9dc5f4e2cde0, , rwlock
3, 2894, 1023, 964, ffffffff9e0d7700, rcu_state, spinlock
1, 2567, 2567, 2567, ffff9dcc7f6b0e00, rq_lock, spinlock
4, 1259, 596, 314, ffff9dc69c2adde0, , rwlock
1, 934, 934, 934, ffff9dcc7f670e00, rq_lock, spinlock
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-06-29 04:01:39 +08:00
|
|
|
OPT_STRING_NOEMPTY('x', "field-separator", &symbol_conf.field_sep, "separator",
|
|
|
|
"print result in CSV format with custom separator"),
|
2022-07-26 02:31:22 +08:00
|
|
|
OPT_PARENT(lock_options)
|
|
|
|
};
|
|
|
|
|
2012-10-02 02:20:58 +08:00
|
|
|
const char * const info_usage[] = {
|
|
|
|
"perf lock info [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
2014-03-15 11:17:53 +08:00
|
|
|
const char *const lock_subcommands[] = { "record", "report", "script",
|
perf lock: Remove redundant word 'contention' in help message
Before:
# perf lock -h
Usage: perf lock [<options>] {record|report|script|info|contention|contention}
-D, --dump-raw-trace dump raw trace in ASCII
-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)
--kallsyms <file>
kallsyms pathname
--vmlinux <file> vmlinux pathname
After:
# perf lock -h
Usage: perf lock [<options>] {record|report|script|info|contention}
-D, --dump-raw-trace dump raw trace in ASCII
-f, --force don't complain, do it
-i, --input <file> input file name
-v, --verbose be more verbose (show symbol address, etc)
--kallsyms <file>
kallsyms pathname
--vmlinux <file> vmlinux pathname
Fixes: 528b9cab3b813a3b ("perf lock: Add 'contention' subcommand")
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220908014854.151203-1-yangjihong1@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-09-08 09:48:54 +08:00
|
|
|
"info", "contention", NULL };
|
2014-03-15 11:17:53 +08:00
|
|
|
const char *lock_usage[] = {
|
|
|
|
NULL,
|
2012-10-02 02:20:58 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
const char * const report_usage[] = {
|
|
|
|
"perf lock report [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
2022-07-26 02:31:22 +08:00
|
|
|
const char * const contention_usage[] = {
|
|
|
|
"perf lock contention [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
2010-01-30 19:43:33 +08:00
|
|
|
unsigned int i;
|
2012-08-27 02:24:43 +08:00
|
|
|
int rc = 0;
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2023-05-27 02:33:54 +08:00
|
|
|
lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table));
|
|
|
|
if (!lockhash_table)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-01-30 19:43:33 +08:00
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++)
|
2022-01-27 08:00:45 +08:00
|
|
|
INIT_HLIST_HEAD(lockhash_table + i);
|
2010-01-30 19:43:33 +08:00
|
|
|
|
2023-06-29 04:01:40 +08:00
|
|
|
lock_output = stderr;
|
2014-03-15 11:17:53 +08:00
|
|
|
argc = parse_options_subcommand(argc, argv, lock_options, lock_subcommands,
|
|
|
|
lock_usage, PARSE_OPT_STOP_AT_NON_OPTION);
|
2010-01-30 19:43:33 +08:00
|
|
|
if (!argc)
|
|
|
|
usage_with_options(lock_usage, lock_options);
|
|
|
|
|
2022-03-25 17:20:32 +08:00
|
|
|
if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) {
|
2010-01-30 19:43:33 +08:00
|
|
|
return __cmd_record(argc, argv);
|
2022-03-25 17:20:32 +08:00
|
|
|
} else if (strlen(argv[0]) > 2 && strstarts("report", argv[0])) {
|
2010-01-31 15:27:58 +08:00
|
|
|
trace_handler = &report_lock_ops;
|
2010-01-30 19:43:33 +08:00
|
|
|
if (argc) {
|
|
|
|
argc = parse_options(argc, argv,
|
2010-01-31 15:27:58 +08:00
|
|
|
report_options, report_usage, 0);
|
2010-01-30 19:43:33 +08:00
|
|
|
if (argc)
|
2010-01-31 15:27:58 +08:00
|
|
|
usage_with_options(report_usage, report_options);
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|
2013-09-09 10:19:16 +08:00
|
|
|
rc = __cmd_report(false);
|
2010-11-17 01:45:39 +08:00
|
|
|
} else if (!strcmp(argv[0], "script")) {
|
|
|
|
/* Aliased to 'perf script' */
|
2023-05-27 02:33:54 +08:00
|
|
|
rc = cmd_script(argc, argv);
|
2010-05-03 13:12:00 +08:00
|
|
|
} else if (!strcmp(argv[0], "info")) {
|
|
|
|
if (argc) {
|
|
|
|
argc = parse_options(argc, argv,
|
|
|
|
info_options, info_usage, 0);
|
|
|
|
if (argc)
|
|
|
|
usage_with_options(info_usage, info_options);
|
|
|
|
}
|
2010-01-31 15:27:58 +08:00
|
|
|
/* recycling report_lock_ops */
|
|
|
|
trace_handler = &report_lock_ops;
|
2013-09-09 10:19:16 +08:00
|
|
|
rc = __cmd_report(true);
|
2022-07-26 02:31:22 +08:00
|
|
|
} else if (strlen(argv[0]) > 2 && strstarts("contention", argv[0])) {
|
|
|
|
trace_handler = &contention_lock_ops;
|
2022-07-26 02:31:23 +08:00
|
|
|
sort_key = "wait_total";
|
|
|
|
output_fields = "contended,wait_total,wait_max,avg_wait";
|
|
|
|
|
2022-07-30 04:07:55 +08:00
|
|
|
#ifndef HAVE_BPF_SKEL
|
|
|
|
set_option_nobuild(contention_options, 'b', "use-bpf",
|
2023-05-07 05:07:37 +08:00
|
|
|
"no BUILD_BPF_SKEL=1", false);
|
2022-07-30 04:07:55 +08:00
|
|
|
#endif
|
2022-07-26 02:31:22 +08:00
|
|
|
if (argc) {
|
|
|
|
argc = parse_options(argc, argv, contention_options,
|
|
|
|
contention_usage, 0);
|
|
|
|
}
|
2022-12-10 03:07:26 +08:00
|
|
|
|
2023-02-07 08:24:02 +08:00
|
|
|
if (check_lock_contention_options(contention_options,
|
|
|
|
contention_usage) < 0)
|
2022-12-10 03:07:26 +08:00
|
|
|
return -1;
|
|
|
|
|
2022-07-30 04:07:56 +08:00
|
|
|
rc = __cmd_contention(argc, argv);
|
2010-01-30 19:43:33 +08:00
|
|
|
} else {
|
|
|
|
usage_with_options(lock_usage, lock_options);
|
|
|
|
}
|
|
|
|
|
2023-05-27 02:33:54 +08:00
|
|
|
zfree(&lockhash_table);
|
2012-08-27 02:24:43 +08:00
|
|
|
return rc;
|
2010-01-30 19:43:33 +08:00
|
|
|
}
|