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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-18 13:46:11 +00:00
|
|
|
#include <errno.h>
|
2017-04-17 18:23:08 +00:00
|
|
|
#include <inttypes.h>
|
2010-01-30 11:43:33 +00:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "perf.h"
|
|
|
|
|
2019-08-30 15:29:03 +00:00
|
|
|
#include "util/evlist.h" // for struct evsel_str_handler
|
2012-08-07 12:58:03 +00:00
|
|
|
#include "util/evsel.h"
|
2010-01-30 11:43:33 +00:00
|
|
|
#include "util/symbol.h"
|
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/header.h"
|
2022-07-29 20:07:56 +00:00
|
|
|
#include "util/target.h"
|
2023-09-06 17:49:02 +00:00
|
|
|
#include "util/cgroup.h"
|
2022-06-15 16:32:22 +00:00
|
|
|
#include "util/callchain.h"
|
2022-07-29 20:07:55 +00:00
|
|
|
#include "util/lock-contention.h"
|
2022-12-09 19:07:25 +00:00
|
|
|
#include "util/bpf_skel/lock_data.h"
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2019-08-30 15:52:25 +00:00
|
|
|
#include <subcmd/pager.h>
|
2015-12-15 15:39:39 +00:00
|
|
|
#include <subcmd/parse-options.h>
|
2010-01-30 11:43:33 +00:00
|
|
|
#include "util/trace-event.h"
|
2022-07-29 20:42:17 +00:00
|
|
|
#include "util/tracepoint.h"
|
2010-01-30 11:43:33 +00:00
|
|
|
|
|
|
|
#include "util/debug.h"
|
|
|
|
#include "util/session.h"
|
2011-11-28 10:30:20 +00:00
|
|
|
#include "util/tool.h"
|
2013-10-15 14:27:32 +00:00
|
|
|
#include "util/data.h"
|
2022-03-25 09:20:32 +00:00
|
|
|
#include "util/string2.h"
|
2022-06-15 16:32:22 +00:00
|
|
|
#include "util/map.h"
|
2022-10-28 18:01:26 +00:00
|
|
|
#include "util/util.h"
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2023-06-28 20:01:40 +00:00
|
|
|
#include <stdio.h>
|
2010-01-30 11:43:33 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <limits.h>
|
2022-12-19 20:17:30 +00:00
|
|
|
#include <ctype.h>
|
2010-01-30 11:43:33 +00:00
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/hash.h>
|
2017-04-17 14:39:06 +00:00
|
|
|
#include <linux/kernel.h>
|
2019-07-04 14:32:27 +00:00
|
|
|
#include <linux/zalloc.h>
|
2019-08-22 07:20:49 +00:00
|
|
|
#include <linux/err.h>
|
2022-06-15 16:32:22 +00:00
|
|
|
#include <linux/stringify.h>
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
static struct perf_session *session;
|
2022-07-29 20:07:56 +00:00
|
|
|
static struct target target;
|
2010-04-21 12:23:54 +00:00
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
/* based on kernel/lockdep.c */
|
|
|
|
#define LOCKHASH_BITS 12
|
|
|
|
#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS)
|
|
|
|
|
2023-05-26 18:33:54 +00:00
|
|
|
static struct hlist_head *lockhash_table;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
|
|
|
#define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS)
|
|
|
|
#define lockhashentry(key) (lockhash_table + __lockhashfn((key)))
|
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
static struct rb_root thread_stats;
|
|
|
|
|
2022-01-27 00:00:49 +00:00
|
|
|
static bool combine_locks;
|
2022-05-21 01:08:11 +00:00
|
|
|
static bool show_thread_stats;
|
2022-12-09 19:07:26 +00:00
|
|
|
static bool show_lock_addrs;
|
2023-02-07 00:24:02 +00:00
|
|
|
static bool show_lock_owner;
|
2023-09-06 17:49:01 +00:00
|
|
|
static bool show_lock_cgroups;
|
2022-07-29 20:07:55 +00:00
|
|
|
static bool use_bpf;
|
2023-04-06 21:06:07 +00:00
|
|
|
static unsigned long bpf_map_entries = MAX_ENTRIES;
|
2022-09-12 05:53:13 +00:00
|
|
|
static int max_stack_depth = CONTENTION_STACK_DEPTH;
|
|
|
|
static int stack_skip = CONTENTION_STACK_SKIP;
|
2022-09-24 00:42:19 +00:00
|
|
|
static int print_nr_entries = INT_MAX / 2;
|
2023-01-26 00:09:36 +00:00
|
|
|
static LIST_HEAD(callstack_filters);
|
2023-06-28 20:01:40 +00:00
|
|
|
static const char *output_name = NULL;
|
|
|
|
static FILE *lock_output;
|
2023-01-26 00:09:36 +00:00
|
|
|
|
|
|
|
struct callstack_filter {
|
|
|
|
struct list_head list;
|
|
|
|
char name[];
|
|
|
|
};
|
2022-01-27 00:00:49 +00: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-19 20:17:28 +00:00
|
|
|
static struct lock_filter filters;
|
|
|
|
|
2022-12-09 19:07:25 +00:00
|
|
|
static enum lock_aggr_mode aggr_mode = LOCK_AGGR_ADDR;
|
2022-07-25 18:31:21 +00:00
|
|
|
|
2023-01-26 00:09:36 +00:00
|
|
|
static bool needs_callstack(void)
|
|
|
|
{
|
2023-04-06 21:06:10 +00:00
|
|
|
return !list_empty(&callstack_filters);
|
2023-01-26 00:09:36 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 12:23:54 +00: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-26 18:24:43 +00:00
|
|
|
if (!st) {
|
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-21 12:23:54 +00: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-26 18:24:43 +00:00
|
|
|
if (!st) {
|
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-21 12:23:54 +00: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 11:43:33 +00:00
|
|
|
/* build simple key function one is bigger than two */
|
2010-01-31 07:27:58 +00:00
|
|
|
#define SINGLE_KEY(member) \
|
2010-01-30 11:43:33 +00: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 02:19:19 +00:00
|
|
|
SINGLE_KEY(avg_wait_time)
|
2010-01-30 11:43:33 +00:00
|
|
|
SINGLE_KEY(wait_time_total)
|
|
|
|
SINGLE_KEY(wait_time_max)
|
|
|
|
|
2011-02-22 17:47:15 +00: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 11:43:33 +00: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 07:27:58 +00:00
|
|
|
const char *name;
|
2022-03-23 23:02:58 +00: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 07:27:58 +00:00
|
|
|
int (*key)(struct lock_stat*, struct lock_stat*);
|
2022-03-23 23:02:58 +00: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 11:43:33 +00:00
|
|
|
};
|
|
|
|
|
2022-06-15 16:32:16 +00: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-28 20:01:39 +00:00
|
|
|
/* for CSV output */
|
|
|
|
if (len == 0) {
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-15 16:32:16 +00:00
|
|
|
for (int i = 0; table[i].unit; i++) {
|
|
|
|
if (nsec < table[i].base)
|
|
|
|
continue;
|
|
|
|
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%*.2f %s", len - 3, nsec / table[i].base, table[i].unit);
|
2022-06-15 16:32:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%*llu %s", len - 3, nsec, "ns");
|
2022-06-15 16:32:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 23:02:58 +00:00
|
|
|
#define PRINT_KEY(member) \
|
|
|
|
static void lock_stat_key_print_ ## member(struct lock_key *key, \
|
|
|
|
struct lock_stat *ls) \
|
|
|
|
{ \
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%*llu", key->len, (unsigned long long)ls->member);\
|
2022-03-23 23:02:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 16:32:16 +00: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-23 23:02:58 +00:00
|
|
|
PRINT_KEY(nr_acquired)
|
|
|
|
PRINT_KEY(nr_contended)
|
2022-06-15 16:32:16 +00:00
|
|
|
PRINT_TIME(avg_wait_time)
|
|
|
|
PRINT_TIME(wait_time_total)
|
|
|
|
PRINT_TIME(wait_time_max)
|
2022-03-23 23:02:58 +00: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-15 16:32:16 +00:00
|
|
|
lock_stat_key_print_time(wait_time, key->len);
|
2022-03-23 23:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-31 07:27:58 +00:00
|
|
|
static const char *sort_key = "acquired";
|
|
|
|
|
|
|
|
static int (*compare)(struct lock_stat *, struct lock_stat *);
|
|
|
|
|
2022-01-27 00:00:49 +00:00
|
|
|
static struct rb_root sorted; /* place to store intermediate data */
|
2010-01-31 07:27:58 +00:00
|
|
|
static struct rb_root result; /* place to store sorted data */
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-03-23 23:02:58 +00:00
|
|
|
static LIST_HEAD(lock_keys);
|
2022-03-23 23:02:59 +00:00
|
|
|
static const char *output_fields;
|
2022-03-23 23:02:58 +00: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-25 18:31:23 +00:00
|
|
|
static struct lock_key report_keys[] = {
|
2022-03-23 23:02:58 +00:00
|
|
|
DEF_KEY_LOCK(acquired, "acquired", nr_acquired, 10),
|
|
|
|
DEF_KEY_LOCK(contended, "contended", nr_contended, 10),
|
2022-06-15 16:32:16 +00: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 11:43:33 +00:00
|
|
|
|
|
|
|
/* extra comparisons much complicated should be here */
|
2022-03-23 23:02:58 +00:00
|
|
|
{ }
|
2010-01-30 11:43:33 +00:00
|
|
|
};
|
|
|
|
|
2022-07-25 18:31:23 +00: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 11:43:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
2022-07-25 18:31:23 +00:00
|
|
|
struct lock_key *keys = report_keys;
|
|
|
|
|
|
|
|
if (contention)
|
|
|
|
keys = contention_keys;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
|
|
|
for (i = 0; keys[i].name; i++) {
|
|
|
|
if (!strcmp(keys[i].name, sort_key)) {
|
|
|
|
compare = keys[i].key;
|
2022-03-23 23:02:59 +00: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-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-26 18:24:43 +00:00
|
|
|
pr_err("Unknown compare key: %s\n", sort_key);
|
|
|
|
return -1;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:23 +00:00
|
|
|
static int add_output_field(bool contention, char *name)
|
2022-03-23 23:02:58 +00:00
|
|
|
{
|
|
|
|
int i;
|
2022-07-25 18:31:23 +00:00
|
|
|
struct lock_key *keys = report_keys;
|
|
|
|
|
|
|
|
if (contention)
|
|
|
|
keys = contention_keys;
|
2022-03-23 23:02:58 +00:00
|
|
|
|
2022-03-23 23:02:59 +00: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-25 18:31:23 +00:00
|
|
|
list_add_tail(&keys[i].list, &lock_keys);
|
2022-03-23 23:02:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_err("Unknown output field: %s\n", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:23 +00:00
|
|
|
static int setup_output_field(bool contention, const char *str)
|
2022-03-23 23:02:59 +00:00
|
|
|
{
|
|
|
|
char *tok, *tmp, *orig;
|
|
|
|
int i, ret = 0;
|
2022-07-25 18:31:23 +00:00
|
|
|
struct lock_key *keys = report_keys;
|
|
|
|
|
|
|
|
if (contention)
|
|
|
|
keys = contention_keys;
|
2022-03-23 23:02:59 +00: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-23 23:02:58 +00:00
|
|
|
for (i = 0; keys[i].name; i++)
|
2022-03-23 23:02:59 +00:00
|
|
|
INIT_LIST_HEAD(&keys[i].list);
|
2022-03-23 23:02:58 +00:00
|
|
|
|
2022-03-23 23:02:59 +00:00
|
|
|
orig = tmp = strdup(str);
|
|
|
|
if (orig == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
while ((tok = strsep(&tmp, ",")) != NULL){
|
2022-07-25 18:31:23 +00:00
|
|
|
ret = add_output_field(contention, tok);
|
2022-03-23 23:02:59 +00:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(orig);
|
|
|
|
|
|
|
|
return ret;
|
2022-03-23 23:02:58 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 00:00:49 +00: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 01:08:10 +00:00
|
|
|
p->broken |= st->broken;
|
2022-01-27 00:00:49 +00: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 11:43:33 +00:00
|
|
|
static void insert_to_result(struct lock_stat *st,
|
2010-01-31 07:27:58 +00:00
|
|
|
int (*bigger)(struct lock_stat *, struct lock_stat *))
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
|
|
|
struct rb_node **rb = &result.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct lock_stat *p;
|
|
|
|
|
2022-01-27 00:00:49 +00:00
|
|
|
if (combine_locks && st->combined)
|
|
|
|
return;
|
|
|
|
|
2010-01-30 11:43:33 +00: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 02:13:23 +00:00
|
|
|
struct lock_stat *lock_stat_find(u64 addr)
|
2022-06-15 16:32:20 +00: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 02:13:23 +00:00
|
|
|
struct lock_stat *lock_stat_findnew(u64 addr, const char *name, int flags)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2022-01-27 00:00:45 +00:00
|
|
|
struct hlist_head *entry = lockhashentry(addr);
|
2010-01-30 11:43:33 +00:00
|
|
|
struct lock_stat *ret, *new;
|
|
|
|
|
2022-01-27 00:00:45 +00:00
|
|
|
hlist_for_each_entry(ret, entry, hash_entry) {
|
2010-01-30 11:43:33 +00:00
|
|
|
if (ret->addr == addr)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
new = zalloc(sizeof(struct lock_stat));
|
|
|
|
if (!new)
|
|
|
|
goto alloc_failed;
|
|
|
|
|
|
|
|
new->addr = addr;
|
2022-07-25 18:31:20 +00:00
|
|
|
new->name = strdup(name);
|
2013-09-09 02:19:15 +00:00
|
|
|
if (!new->name) {
|
|
|
|
free(new);
|
2010-01-30 11:43:33 +00:00
|
|
|
goto alloc_failed;
|
2013-09-09 02:19:15 +00:00
|
|
|
}
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-07-25 18:31:20 +00:00
|
|
|
new->flags = flags;
|
2010-01-30 11:43:33 +00:00
|
|
|
new->wait_time_min = ULLONG_MAX;
|
|
|
|
|
2022-01-27 00:00:45 +00:00
|
|
|
hlist_add_head(&new->hash_entry, entry);
|
2010-01-30 11:43:33 +00:00
|
|
|
return new;
|
|
|
|
|
|
|
|
alloc_failed:
|
2012-08-26 18:24:43 +00:00
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 02:13:24 +00:00
|
|
|
bool match_callstack_filter(struct machine *machine, u64 *callstack)
|
|
|
|
{
|
|
|
|
struct map *kmap;
|
|
|
|
struct symbol *sym;
|
|
|
|
u64 ip;
|
tools/perf: Update call stack check in builtin-lock.c
The perf test named "kernel lock contention analysis test"
fails in powerpc system with below error:
[command]# ./perf test 81 -vv
81: kernel lock contention analysis test :
--- start ---
test child forked, pid 2140
Testing perf lock record and perf lock contention
Testing perf lock contention --use-bpf
[Skip] No BPF support
Testing perf lock record and perf lock contention at the same time
Testing perf lock contention --threads
Testing perf lock contention --lock-addr
Testing perf lock contention --type-filter (w/ spinlock)
Testing perf lock contention --lock-filter (w/ tasklist_lock)
Testing perf lock contention --callstack-filter (w/ unix_stream)
[Fail] Recorded result should have a lock from unix_stream:
test child finished with -1
---- end ----
kernel lock contention analysis test: FAILED!
The test is failing because we get an address entry with 0 in
perf lock samples for powerpc, and code for lock contention
option "--callstack-filter" will not check further entries after
address 0.
Below are some of the samples from test generated perf.data file, which
have 0 address in the 2nd entry of callstack:
--------
sched-messaging 3409 [001] 7152.904029: lock:contention_begin: 0xc00000c80904ef00 (flags=SPIN)
c0000000001e926c __traceiter_contention_begin+0x6c ([kernel.kallsyms])
0 [unknown] ([unknown])
c000000000f8a178 native_queued_spin_lock_slowpath+0x1f8 ([kernel.kallsyms])
c000000000f89f44 _raw_spin_lock_irqsave+0x84 ([kernel.kallsyms])
c0000000001d9fd0 prepare_to_wait+0x50 ([kernel.kallsyms])
c000000000c80f50 sock_alloc_send_pskb+0x1b0 ([kernel.kallsyms])
c000000000e82298 unix_stream_sendmsg+0x2b8 ([kernel.kallsyms])
c000000000c78980 sock_sendmsg+0x80 ([kernel.kallsyms])
sched-messaging 3408 [005] 7152.904036: lock:contention_begin: 0xc00000c80904ef00 (flags=SPIN)
c0000000001e926c __traceiter_contention_begin+0x6c ([kernel.kallsyms])
0 [unknown] ([unknown])
c000000000f8a178 native_queued_spin_lock_slowpath+0x1f8 ([kernel.kallsyms])
c000000000f89f44 _raw_spin_lock_irqsave+0x84 ([kernel.kallsyms])
c0000000001d9fd0 prepare_to_wait+0x50 ([kernel.kallsyms])
c000000000c80f50 sock_alloc_send_pskb+0x1b0 ([kernel.kallsyms])
c000000000e82298 unix_stream_sendmsg+0x2b8 ([kernel.kallsyms])
c000000000c78980 sock_sendmsg+0x80 ([kernel.kallsyms])
--------
Based on commit 20002ded4d93 ("perf_counter: powerpc: Add callchain support"),
incase of powerpc, the callchain saved by kernel always includes first
three entries as the NIP (next instruction pointer), LR (link register), and
the contents of LR save area in the second stack frame. In certain scenarios
its possible to have invalid kernel instruction addresses in either of LR or the
second stack frame's LR. In that case, kernel will store the address as zer0.
Hence, its possible to have 2nd or 3rd callstack entry as 0.
As per the current code in match_callstack_filter function, we skip the callstack
check incase we get 0 address. And hence the test case is failing in powerpc.
Fix this issue by updating the check in match_callstack_filter function,
to not skip callstack check if the 2nd or 3rd entry have 0 address
for powerpc.
Result in powerpc after patch changes:
[command]# ./perf test 81 -vv
81: kernel lock contention analysis test :
--- start ---
test child forked, pid 4570
Testing perf lock record and perf lock contention
Testing perf lock contention --use-bpf
[Skip] No BPF support
Testing perf lock record and perf lock contention at the same time
Testing perf lock contention --threads
Testing perf lock contention --lock-addr
Testing perf lock contention --type-filter (w/ spinlock)
Testing perf lock contention --lock-filter (w/ tasklist_lock)
[Skip] Could not find 'tasklist_lock'
Testing perf lock contention --callstack-filter (w/ unix_stream)
Testing perf lock contention --callstack-filter with task aggregation
Testing perf lock contention CSV output
[Skip] No BPF support
test child finished with 0
---- end ----
kernel lock contention analysis test: Ok
Fixes: ebab291641be ("perf lock contention: Support filters for different aggregation")
Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
Tested-by: Disha Goel <disgoel@linux.ibm.com>
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Cc: maddy@linux.ibm.com
Cc: atrajeev@linux.vnet.ibm.com
Link: https://lore.kernel.org/r/20231003092113.252380-1-kjain@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-10-03 09:21:13 +00:00
|
|
|
const char *arch = perf_env__arch(machine->env);
|
2023-02-03 02:13:24 +00:00
|
|
|
|
|
|
|
if (list_empty(&callstack_filters))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (int i = 0; i < max_stack_depth; i++) {
|
|
|
|
struct callstack_filter *filter;
|
|
|
|
|
tools/perf: Update call stack check in builtin-lock.c
The perf test named "kernel lock contention analysis test"
fails in powerpc system with below error:
[command]# ./perf test 81 -vv
81: kernel lock contention analysis test :
--- start ---
test child forked, pid 2140
Testing perf lock record and perf lock contention
Testing perf lock contention --use-bpf
[Skip] No BPF support
Testing perf lock record and perf lock contention at the same time
Testing perf lock contention --threads
Testing perf lock contention --lock-addr
Testing perf lock contention --type-filter (w/ spinlock)
Testing perf lock contention --lock-filter (w/ tasklist_lock)
Testing perf lock contention --callstack-filter (w/ unix_stream)
[Fail] Recorded result should have a lock from unix_stream:
test child finished with -1
---- end ----
kernel lock contention analysis test: FAILED!
The test is failing because we get an address entry with 0 in
perf lock samples for powerpc, and code for lock contention
option "--callstack-filter" will not check further entries after
address 0.
Below are some of the samples from test generated perf.data file, which
have 0 address in the 2nd entry of callstack:
--------
sched-messaging 3409 [001] 7152.904029: lock:contention_begin: 0xc00000c80904ef00 (flags=SPIN)
c0000000001e926c __traceiter_contention_begin+0x6c ([kernel.kallsyms])
0 [unknown] ([unknown])
c000000000f8a178 native_queued_spin_lock_slowpath+0x1f8 ([kernel.kallsyms])
c000000000f89f44 _raw_spin_lock_irqsave+0x84 ([kernel.kallsyms])
c0000000001d9fd0 prepare_to_wait+0x50 ([kernel.kallsyms])
c000000000c80f50 sock_alloc_send_pskb+0x1b0 ([kernel.kallsyms])
c000000000e82298 unix_stream_sendmsg+0x2b8 ([kernel.kallsyms])
c000000000c78980 sock_sendmsg+0x80 ([kernel.kallsyms])
sched-messaging 3408 [005] 7152.904036: lock:contention_begin: 0xc00000c80904ef00 (flags=SPIN)
c0000000001e926c __traceiter_contention_begin+0x6c ([kernel.kallsyms])
0 [unknown] ([unknown])
c000000000f8a178 native_queued_spin_lock_slowpath+0x1f8 ([kernel.kallsyms])
c000000000f89f44 _raw_spin_lock_irqsave+0x84 ([kernel.kallsyms])
c0000000001d9fd0 prepare_to_wait+0x50 ([kernel.kallsyms])
c000000000c80f50 sock_alloc_send_pskb+0x1b0 ([kernel.kallsyms])
c000000000e82298 unix_stream_sendmsg+0x2b8 ([kernel.kallsyms])
c000000000c78980 sock_sendmsg+0x80 ([kernel.kallsyms])
--------
Based on commit 20002ded4d93 ("perf_counter: powerpc: Add callchain support"),
incase of powerpc, the callchain saved by kernel always includes first
three entries as the NIP (next instruction pointer), LR (link register), and
the contents of LR save area in the second stack frame. In certain scenarios
its possible to have invalid kernel instruction addresses in either of LR or the
second stack frame's LR. In that case, kernel will store the address as zer0.
Hence, its possible to have 2nd or 3rd callstack entry as 0.
As per the current code in match_callstack_filter function, we skip the callstack
check incase we get 0 address. And hence the test case is failing in powerpc.
Fix this issue by updating the check in match_callstack_filter function,
to not skip callstack check if the 2nd or 3rd entry have 0 address
for powerpc.
Result in powerpc after patch changes:
[command]# ./perf test 81 -vv
81: kernel lock contention analysis test :
--- start ---
test child forked, pid 4570
Testing perf lock record and perf lock contention
Testing perf lock contention --use-bpf
[Skip] No BPF support
Testing perf lock record and perf lock contention at the same time
Testing perf lock contention --threads
Testing perf lock contention --lock-addr
Testing perf lock contention --type-filter (w/ spinlock)
Testing perf lock contention --lock-filter (w/ tasklist_lock)
[Skip] Could not find 'tasklist_lock'
Testing perf lock contention --callstack-filter (w/ unix_stream)
Testing perf lock contention --callstack-filter with task aggregation
Testing perf lock contention CSV output
[Skip] No BPF support
test child finished with 0
---- end ----
kernel lock contention analysis test: Ok
Fixes: ebab291641be ("perf lock contention: Support filters for different aggregation")
Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com>
Tested-by: Disha Goel <disgoel@linux.ibm.com>
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Cc: maddy@linux.ibm.com
Cc: atrajeev@linux.vnet.ibm.com
Link: https://lore.kernel.org/r/20231003092113.252380-1-kjain@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2023-10-03 09:21:13 +00:00
|
|
|
/*
|
|
|
|
* In powerpc, the callchain saved by kernel always includes
|
|
|
|
* first three entries as the NIP (next instruction pointer),
|
|
|
|
* LR (link register), and the contents of LR save area in the
|
|
|
|
* second stack frame. In certain scenarios its possible to have
|
|
|
|
* invalid kernel instruction addresses in either LR or the second
|
|
|
|
* stack frame's LR. In that case, kernel will store that address as
|
|
|
|
* zero.
|
|
|
|
*
|
|
|
|
* The below check will continue to look into callstack,
|
|
|
|
* incase first or second callstack index entry has 0
|
|
|
|
* address for powerpc.
|
|
|
|
*/
|
|
|
|
if (!callstack || (!callstack[i] && (strcmp(arch, "powerpc") ||
|
|
|
|
(i != 1 && i != 2))))
|
2023-02-03 02:13:24 +00:00
|
|
|
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 11:43:33 +00:00
|
|
|
struct trace_lock_handler {
|
2022-06-15 16:32:19 +00:00
|
|
|
/* it's used on CONFIG_LOCKDEP */
|
2019-07-21 11:23:51 +00:00
|
|
|
int (*acquire_event)(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample);
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-06-15 16:32:19 +00:00
|
|
|
/* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */
|
2019-07-21 11:23:51 +00:00
|
|
|
int (*acquired_event)(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample);
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-06-15 16:32:19 +00:00
|
|
|
/* it's used on CONFIG_LOCKDEP && CONFIG_LOCK_STAT */
|
2019-07-21 11:23:51 +00:00
|
|
|
int (*contended_event)(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample);
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-06-15 16:32:19 +00:00
|
|
|
/* it's used on CONFIG_LOCKDEP */
|
2019-07-21 11:23:51 +00:00
|
|
|
int (*release_event)(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample);
|
2022-06-15 16:32:19 +00: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 11:43:33 +00:00
|
|
|
};
|
|
|
|
|
2022-01-27 00:00:46 +00:00
|
|
|
static struct lock_seq_stat *get_seq(struct thread_stat *ts, u64 addr)
|
2010-04-21 12:23:54 +00: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-26 18:24:43 +00:00
|
|
|
if (!seq) {
|
|
|
|
pr_err("memory allocation failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-21 12:23:54 +00:00
|
|
|
seq->state = SEQ_STATE_UNINITIALIZED;
|
|
|
|
seq->addr = addr;
|
|
|
|
|
|
|
|
list_add(&seq->list, &ts->seq_list);
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
2010-05-05 21:47:28 +00:00
|
|
|
enum broken_state {
|
|
|
|
BROKEN_ACQUIRE,
|
|
|
|
BROKEN_ACQUIRED,
|
|
|
|
BROKEN_CONTENDED,
|
|
|
|
BROKEN_RELEASE,
|
|
|
|
BROKEN_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bad_hist[BROKEN_MAX];
|
2010-04-21 12:23:54 +00:00
|
|
|
|
2010-05-05 21:57:25 +00:00
|
|
|
enum acquire_flags {
|
|
|
|
TRY_LOCK = 1,
|
|
|
|
READ_LOCK = 2,
|
|
|
|
};
|
|
|
|
|
2022-09-08 02:11:39 +00:00
|
|
|
static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2022-07-25 18:31:21 +00:00
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_ADDR:
|
2022-09-08 02:11:39 +00:00
|
|
|
*key = addr;
|
2022-07-25 18:31:21 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
2022-09-08 02:11:39 +00:00
|
|
|
*key = tid;
|
2022-07-25 18:31:21 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-09-06 17:49:01 +00:00
|
|
|
case LOCK_AGGR_CGROUP:
|
2022-07-25 18:31:21 +00:00
|
|
|
default:
|
|
|
|
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-09-08 02:11:39 +00: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 01:08:11 +00:00
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ls)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2012-08-07 13:59:44 +00:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ts)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2012-08-26 18:24:43 +00:00
|
|
|
|
2012-09-24 13:52:12 +00:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!seq)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
case SEQ_STATE_RELEASED:
|
2012-09-24 13:52:12 +00:00
|
|
|
if (!flag) {
|
2010-04-21 12:23:54 +00:00
|
|
|
seq->state = SEQ_STATE_ACQUIRING;
|
|
|
|
} else {
|
2012-09-24 13:52:12 +00:00
|
|
|
if (flag & TRY_LOCK)
|
2010-04-21 12:23:54 +00:00
|
|
|
ls->nr_trylock++;
|
2012-09-24 13:52:12 +00:00
|
|
|
if (flag & READ_LOCK)
|
2010-04-21 12:23:54 +00: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 13:52:12 +00:00
|
|
|
if (flag & READ_LOCK) {
|
2010-04-21 12:23:54 +00:00
|
|
|
seq->read_count++;
|
|
|
|
ls->nr_acquired++;
|
|
|
|
goto end;
|
|
|
|
} else {
|
|
|
|
goto broken;
|
|
|
|
}
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
2010-04-21 12:23:54 +00:00
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_ACQUIRING:
|
|
|
|
case SEQ_STATE_CONTENDED:
|
|
|
|
broken:
|
2022-05-21 01:08:10 +00:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_ACQUIRE]++;
|
|
|
|
}
|
2019-07-04 15:13:46 +00:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 12:23:54 +00:00
|
|
|
free(seq);
|
|
|
|
goto end;
|
2010-01-30 11:43:33 +00:00
|
|
|
default:
|
2010-04-21 12:23:54 +00:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
ls->nr_acquire++;
|
2012-08-07 13:59:44 +00:00
|
|
|
seq->prev_event_time = sample->time;
|
2010-04-21 12:23:54 +00:00
|
|
|
end:
|
2012-08-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:23:51 +00:00
|
|
|
static int report_lock_acquired_event(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2010-04-21 12:23:54 +00:00
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
|
|
|
u64 contended_term;
|
2020-04-29 19:26:57 +00:00
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
2022-01-27 00:00:46 +00:00
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
2022-07-25 18:31:21 +00:00
|
|
|
u64 key;
|
2022-09-08 02:11:39 +00:00
|
|
|
int ret;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-09-08 02:11:39 +00:00
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 01:08:11 +00:00
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ls)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-04-21 12:23:54 +00:00
|
|
|
|
2012-08-07 13:59:44 +00:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ts)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2012-08-26 18:24:43 +00:00
|
|
|
|
2012-09-24 13:52:12 +00:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!seq)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
/* orphan event, do nothing */
|
2012-08-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-04-21 12:23:54 +00:00
|
|
|
case SEQ_STATE_ACQUIRING:
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
2010-04-21 12:23:54 +00:00
|
|
|
case SEQ_STATE_CONTENDED:
|
2012-09-24 13:52:12 +00:00
|
|
|
contended_term = sample->time - seq->prev_event_time;
|
2010-04-21 12:23:54 +00:00
|
|
|
ls->wait_time_total += contended_term;
|
|
|
|
if (contended_term < ls->wait_time_min)
|
|
|
|
ls->wait_time_min = contended_term;
|
2010-05-07 00:33:42 +00:00
|
|
|
if (ls->wait_time_max < contended_term)
|
2010-04-21 12:23:54 +00:00
|
|
|
ls->wait_time_max = contended_term;
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
2010-04-21 12:23:54 +00:00
|
|
|
case SEQ_STATE_RELEASED:
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
2022-05-21 01:08:10 +00:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_ACQUIRED]++;
|
|
|
|
}
|
2019-07-04 15:13:46 +00:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 12:23:54 +00:00
|
|
|
free(seq);
|
|
|
|
goto end;
|
2010-01-30 11:43:33 +00:00
|
|
|
default:
|
2010-04-21 12:23:54 +00:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
seq->state = SEQ_STATE_ACQUIRED;
|
|
|
|
ls->nr_acquired++;
|
2013-09-09 02:19:19 +00:00
|
|
|
ls->avg_wait_time = ls->nr_contended ? ls->wait_time_total/ls->nr_contended : 0;
|
2012-09-24 13:52:12 +00:00
|
|
|
seq->prev_event_time = sample->time;
|
2010-04-21 12:23:54 +00:00
|
|
|
end:
|
2012-08-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:23:51 +00:00
|
|
|
static int report_lock_contended_event(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2010-04-21 12:23:54 +00:00
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
2020-04-29 19:26:57 +00:00
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
2022-01-27 00:00:46 +00:00
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
2022-07-25 18:31:21 +00:00
|
|
|
u64 key;
|
2022-09-08 02:11:39 +00:00
|
|
|
int ret;
|
2010-04-21 12:23:54 +00:00
|
|
|
|
2022-09-08 02:11:39 +00:00
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 01:08:11 +00:00
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ls)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2012-08-07 13:59:44 +00:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ts)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2012-08-26 18:24:43 +00:00
|
|
|
|
2012-09-24 13:52:12 +00:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!seq)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
switch (seq->state) {
|
|
|
|
case SEQ_STATE_UNINITIALIZED:
|
|
|
|
/* orphan event, do nothing */
|
2012-08-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-04-21 12:23:54 +00:00
|
|
|
case SEQ_STATE_ACQUIRING:
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
2010-04-21 12:23:54 +00:00
|
|
|
case SEQ_STATE_RELEASED:
|
|
|
|
case SEQ_STATE_ACQUIRED:
|
|
|
|
case SEQ_STATE_READ_ACQUIRED:
|
|
|
|
case SEQ_STATE_CONTENDED:
|
2022-05-21 01:08:10 +00:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_CONTENDED]++;
|
|
|
|
}
|
2019-07-04 15:13:46 +00:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 12:23:54 +00:00
|
|
|
free(seq);
|
|
|
|
goto end;
|
2010-01-30 11:43:33 +00:00
|
|
|
default:
|
2010-04-21 12:23:54 +00:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
seq->state = SEQ_STATE_CONTENDED;
|
|
|
|
ls->nr_contended++;
|
2013-09-09 02:19:19 +00:00
|
|
|
ls->avg_wait_time = ls->wait_time_total/ls->nr_contended;
|
2012-08-07 13:59:44 +00:00
|
|
|
seq->prev_event_time = sample->time;
|
2010-04-21 12:23:54 +00:00
|
|
|
end:
|
2012-08-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:23:51 +00:00
|
|
|
static int report_lock_release_event(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2010-04-21 12:23:54 +00:00
|
|
|
struct lock_stat *ls;
|
|
|
|
struct thread_stat *ts;
|
|
|
|
struct lock_seq_stat *seq;
|
2020-04-29 19:26:57 +00:00
|
|
|
const char *name = evsel__strval(evsel, sample, "name");
|
2022-01-27 00:00:46 +00:00
|
|
|
u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
|
2022-07-25 18:31:21 +00:00
|
|
|
u64 key;
|
2022-09-08 02:11:39 +00:00
|
|
|
int ret;
|
2012-09-24 13:52:12 +00:00
|
|
|
|
2022-09-08 02:11:39 +00:00
|
|
|
ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-05-21 01:08:11 +00:00
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
ls = lock_stat_findnew(key, name, 0);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ls)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2012-08-07 13:59:44 +00:00
|
|
|
ts = thread_stat_findnew(sample->tid);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!ts)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2012-08-26 18:24:43 +00:00
|
|
|
|
2012-09-24 13:52:12 +00:00
|
|
|
seq = get_seq(ts, addr);
|
2012-08-26 18:24:43 +00:00
|
|
|
if (!seq)
|
2013-09-09 02:19:14 +00:00
|
|
|
return -ENOMEM;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2010-04-21 12:23:54 +00: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 09:42:29 +00:00
|
|
|
if (seq->read_count) {
|
2010-04-21 12:23:54 +00:00
|
|
|
ls->nr_release++;
|
2010-01-30 11:43:33 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2010-04-21 12:23:54 +00:00
|
|
|
break;
|
|
|
|
case SEQ_STATE_ACQUIRING:
|
|
|
|
case SEQ_STATE_CONTENDED:
|
|
|
|
case SEQ_STATE_RELEASED:
|
2022-05-21 01:08:10 +00:00
|
|
|
/* broken lock sequence */
|
|
|
|
if (!ls->broken) {
|
|
|
|
ls->broken = 1;
|
|
|
|
bad_hist[BROKEN_RELEASE]++;
|
|
|
|
}
|
2010-04-21 12:23:54 +00:00
|
|
|
goto free_seq;
|
2010-01-30 11:43:33 +00:00
|
|
|
default:
|
2010-04-21 12:23:54 +00:00
|
|
|
BUG_ON("Unknown state of lock sequence found!\n");
|
2010-01-30 11:43:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-21 12:23:54 +00:00
|
|
|
ls->nr_release++;
|
|
|
|
free_seq:
|
2019-07-04 15:13:46 +00:00
|
|
|
list_del_init(&seq->list);
|
2010-04-21 12:23:54 +00:00
|
|
|
free(seq);
|
2010-01-30 11:43:33 +00:00
|
|
|
end:
|
2012-08-26 18:24:43 +00:00
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 05:53:11 +00: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-04 20:59:44 +00:00
|
|
|
offset = map__map_ip(map, ip) - sym->start;
|
2022-09-12 05:53:11 +00:00
|
|
|
|
|
|
|
if (offset)
|
|
|
|
return scnprintf(buf, size, "%s+%#lx", sym->name, offset);
|
|
|
|
else
|
|
|
|
return strlcpy(buf, sym->name, size);
|
|
|
|
}
|
2022-06-15 16:32:22 +00:00
|
|
|
static int lock_contention_caller(struct evsel *evsel, struct perf_sample *sample,
|
|
|
|
char *buf, int size)
|
|
|
|
{
|
|
|
|
struct thread *thread;
|
2023-06-08 23:28:21 +00:00
|
|
|
struct callchain_cursor *cursor;
|
2022-07-29 20:07:54 +00:00
|
|
|
struct machine *machine = &session->machines.host;
|
2022-06-15 16:32:22 +00: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-29 20:07:54 +00:00
|
|
|
thread = machine__findnew_thread(machine, -1, sample->pid);
|
2022-06-15 16:32:22 +00:00
|
|
|
if (thread == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-08 23:28:21 +00:00
|
|
|
cursor = get_tls_callchain_cursor();
|
|
|
|
|
2022-06-15 16:32:22 +00:00
|
|
|
/* use caller function name from the callchain */
|
|
|
|
ret = thread__resolve_callchain(thread, cursor, evsel, sample,
|
2022-09-12 05:53:13 +00:00
|
|
|
NULL, NULL, max_stack_depth);
|
2022-06-15 16:32:22 +00: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 05:53:13 +00:00
|
|
|
if (++skip <= stack_skip)
|
2022-06-15 16:32:22 +00:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
sym = node->ms.sym;
|
2022-12-06 16:49:04 +00:00
|
|
|
if (sym && !machine__is_lock_function(machine, node->ip)) {
|
2022-09-12 05:53:11 +00:00
|
|
|
get_symbol_name_offset(node->ms.map, sym, node->ip,
|
|
|
|
buf, size);
|
2022-06-15 16:32:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
callchain_cursor_advance(cursor);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:22 +00:00
|
|
|
static u64 callchain_id(struct evsel *evsel, struct perf_sample *sample)
|
|
|
|
{
|
2023-06-08 23:28:21 +00:00
|
|
|
struct callchain_cursor *cursor;
|
2022-07-29 20:07:54 +00:00
|
|
|
struct machine *machine = &session->machines.host;
|
2022-07-25 18:31:22 +00:00
|
|
|
struct thread *thread;
|
|
|
|
u64 hash = 0;
|
|
|
|
int skip = 0;
|
|
|
|
int ret;
|
|
|
|
|
2022-07-29 20:07:54 +00:00
|
|
|
thread = machine__findnew_thread(machine, -1, sample->pid);
|
2022-07-25 18:31:22 +00:00
|
|
|
if (thread == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2023-06-08 23:28:21 +00:00
|
|
|
cursor = get_tls_callchain_cursor();
|
2022-07-25 18:31:22 +00:00
|
|
|
/* use caller function name from the callchain */
|
|
|
|
ret = thread__resolve_callchain(thread, cursor, evsel, sample,
|
2022-09-12 05:53:13 +00:00
|
|
|
NULL, NULL, max_stack_depth);
|
2022-07-25 18:31:22 +00: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 05:53:13 +00:00
|
|
|
if (++skip <= stack_skip)
|
2022-07-25 18:31:22 +00:00
|
|
|
goto next;
|
|
|
|
|
2022-12-06 16:49:04 +00:00
|
|
|
if (node->ms.sym && machine__is_lock_function(machine, node->ip))
|
2022-07-25 18:31:22 +00:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
hash ^= hash_long((unsigned long)node->ip, 64);
|
|
|
|
|
|
|
|
next:
|
|
|
|
callchain_cursor_advance(cursor);
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2022-09-12 05:53:12 +00: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-15 16:32:20 +00: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-19 20:17:28 +00:00
|
|
|
unsigned int flags = evsel__intval(evsel, sample, "flags");
|
2022-07-25 18:31:21 +00: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-19 20:17:28 +00:00
|
|
|
int i, ret;
|
2022-12-19 20:17:30 +00:00
|
|
|
static bool kmap_loaded;
|
|
|
|
struct machine *machine = &session->machines.host;
|
|
|
|
struct map *kmap;
|
|
|
|
struct symbol *sym;
|
2022-06-15 16:32:20 +00:00
|
|
|
|
2022-09-08 02:11:39 +00:00
|
|
|
ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-06-15 16:32:20 +00:00
|
|
|
|
2022-12-19 20:17:30 +00: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-04 20:59:44 +00:00
|
|
|
addrs[filters.nr_addrs++] = map__unmap_ip(kmap, sym->start);
|
2022-12-19 20:17:30 +00:00
|
|
|
filters.addrs = addrs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
ls = lock_stat_find(key);
|
2022-06-15 16:32:22 +00:00
|
|
|
if (!ls) {
|
|
|
|
char buf[128];
|
2022-12-09 19:07:26 +00: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;
|
2023-09-06 17:49:01 +00:00
|
|
|
case LOCK_AGGR_CGROUP:
|
2022-12-09 19:07:26 +00:00
|
|
|
case LOCK_AGGR_TASK:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-06-15 16:32:22 +00:00
|
|
|
|
2022-12-09 19:07:26 +00:00
|
|
|
ls = lock_stat_findnew(key, name, flags);
|
2022-06-15 16:32:22 +00:00
|
|
|
if (!ls)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2022-06-15 16:32:20 +00: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-19 20:17:28 +00: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-19 20:17:30 +00: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 02:13:24 +00: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-15 16:32:20 +00: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-25 18:31:21 +00:00
|
|
|
u64 key;
|
2022-09-08 02:11:39 +00:00
|
|
|
int ret;
|
2022-06-15 16:32:20 +00:00
|
|
|
|
2022-09-08 02:11:39 +00:00
|
|
|
ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-06-15 16:32:20 +00:00
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
ls = lock_stat_find(key);
|
2022-06-15 16:32:20 +00: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 11:43:33 +00:00
|
|
|
/* lock oriented handlers */
|
|
|
|
/* TODO: handlers for CPU oriented, thread oriented */
|
2010-01-31 07:27:58 +00: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-15 16:32:20 +00:00
|
|
|
.contention_begin_event = report_lock_contention_begin_event,
|
|
|
|
.contention_end_event = report_lock_contention_end_event,
|
2010-01-30 11:43:33 +00:00
|
|
|
};
|
|
|
|
|
2022-07-25 18:31:22 +00: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 11:43:33 +00:00
|
|
|
static struct trace_lock_handler *trace_handler;
|
|
|
|
|
2020-05-04 16:56:18 +00:00
|
|
|
static int evsel__process_lock_acquire(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2010-01-31 07:27:58 +00:00
|
|
|
if (trace_handler->acquire_event)
|
2012-09-24 13:52:12 +00:00
|
|
|
return trace_handler->acquire_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 16:56:18 +00:00
|
|
|
static int evsel__process_lock_acquired(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2012-08-26 18:24:43 +00:00
|
|
|
if (trace_handler->acquired_event)
|
2012-09-24 13:52:12 +00:00
|
|
|
return trace_handler->acquired_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 16:56:18 +00:00
|
|
|
static int evsel__process_lock_contended(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2012-08-26 18:24:43 +00:00
|
|
|
if (trace_handler->contended_event)
|
2012-09-24 13:52:12 +00:00
|
|
|
return trace_handler->contended_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 16:56:18 +00:00
|
|
|
static int evsel__process_lock_release(struct evsel *evsel, struct perf_sample *sample)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2012-08-26 18:24:43 +00:00
|
|
|
if (trace_handler->release_event)
|
2012-09-24 13:52:12 +00:00
|
|
|
return trace_handler->release_event(evsel, sample);
|
|
|
|
return 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 16:32:19 +00: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-05 21:47:28 +00:00
|
|
|
static void print_bad_events(int bad, int total)
|
|
|
|
{
|
|
|
|
/* Output for debug, this have to be removed */
|
|
|
|
int i;
|
2022-06-15 16:32:18 +00:00
|
|
|
int broken = 0;
|
2010-05-05 21:47:28 +00:00
|
|
|
const char *name[4] =
|
|
|
|
{ "acquire", "acquired", "contended", "release" };
|
|
|
|
|
2022-06-15 16:32:18 +00:00
|
|
|
for (i = 0; i < BROKEN_MAX; i++)
|
|
|
|
broken += bad_hist[i];
|
|
|
|
|
2023-03-27 22:57:10 +00:00
|
|
|
if (quiet || total == 0 || (broken == 0 && verbose <= 0))
|
2022-06-15 16:32:18 +00:00
|
|
|
return;
|
|
|
|
|
2023-06-28 20:01:40 +00: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-05 21:47:28 +00:00
|
|
|
for (i = 0; i < BROKEN_MAX; i++)
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, " %10s: %d\n", name[i], bad_hist[i]);
|
2010-05-05 21:47:28 +00:00
|
|
|
}
|
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
/* TODO: various way to print, coloring, nano or milli sec */
|
|
|
|
static void print_result(void)
|
|
|
|
{
|
|
|
|
struct lock_stat *st;
|
2022-03-23 23:02:58 +00:00
|
|
|
struct lock_key *key;
|
2010-01-30 11:43:33 +00:00
|
|
|
char cut_name[20];
|
2022-09-24 00:42:19 +00:00
|
|
|
int bad, total, printed;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-09-24 00:42:20 +00:00
|
|
|
if (!quiet) {
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%20s ", "Name");
|
2022-09-24 00:42:20 +00:00
|
|
|
list_for_each_entry(key, &lock_keys, list)
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%*s ", key->len, key->header);
|
|
|
|
fprintf(lock_output, "\n\n");
|
2022-09-24 00:42:20 +00:00
|
|
|
}
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-09-24 00:42:19 +00:00
|
|
|
bad = total = printed = 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
while ((st = pop_from_result())) {
|
2010-04-21 12:23:54 +00:00
|
|
|
total++;
|
2022-05-21 01:08:10 +00:00
|
|
|
if (st->broken)
|
2010-04-21 12:23:54 +00:00
|
|
|
bad++;
|
2022-05-21 01:08:10 +00:00
|
|
|
if (!st->nr_acquired)
|
2010-04-21 12:23:54 +00:00
|
|
|
continue;
|
2022-05-21 01:08:10 +00:00
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
bzero(cut_name, 20);
|
|
|
|
|
2022-01-27 00:00:48 +00:00
|
|
|
if (strlen(st->name) < 20) {
|
2010-01-30 11:43:33 +00:00
|
|
|
/* output raw name */
|
2022-05-21 01:08:11 +00: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-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%20s ", name);
|
2010-01-30 11:43:33 +00: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-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%20s ", cut_name);
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 23:02:58 +00:00
|
|
|
list_for_each_entry(key, &lock_keys, list) {
|
|
|
|
key->print(key, st);
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, " ");
|
2022-03-23 23:02:58 +00:00
|
|
|
}
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "\n");
|
2022-09-24 00:42:19 +00:00
|
|
|
|
|
|
|
if (++printed >= print_nr_entries)
|
|
|
|
break;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
2010-04-21 12:23:54 +00:00
|
|
|
|
2010-05-05 21:47:28 +00:00
|
|
|
print_bad_events(bad, total);
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-17 18:51:10 +00:00
|
|
|
static bool info_threads, info_map;
|
2010-05-03 05:12:00 +00:00
|
|
|
|
|
|
|
static void dump_threads(void)
|
|
|
|
{
|
|
|
|
struct thread_stat *st;
|
|
|
|
struct rb_node *node;
|
|
|
|
struct thread *t;
|
|
|
|
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%10s: comm\n", "Thread ID");
|
2010-05-03 05:12:00 +00: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-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "%10d: %s\n", st->tid, thread__comm_str(t));
|
2010-05-03 05:12:00 +00: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-06 23:43:22 +00:00
|
|
|
thread__put(t);
|
2020-04-28 09:18:43 +00:00
|
|
|
}
|
2010-05-03 05:12:00 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 00:00:47 +00: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 11:43:33 +00:00
|
|
|
static void dump_map(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct lock_stat *st;
|
|
|
|
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, "Address of instance: name of class\n");
|
2010-01-30 11:43:33 +00:00
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++) {
|
2022-01-27 00:00:45 +00:00
|
|
|
hlist_for_each_entry(st, &lockhash_table[i], hash_entry) {
|
2022-01-27 00:00:47 +00:00
|
|
|
insert_to_result(st, compare_maps);
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-27 00:00:47 +00:00
|
|
|
|
|
|
|
while ((st = pop_from_result()))
|
2023-06-28 20:01:40 +00:00
|
|
|
fprintf(lock_output, " %#llx: %s\n", (unsigned long long)st->addr, st->name);
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 09:14:12 +00:00
|
|
|
static void dump_info(void)
|
2010-05-03 05:12:00 +00:00
|
|
|
{
|
|
|
|
if (info_threads)
|
|
|
|
dump_threads();
|
2024-05-13 09:14:12 +00:00
|
|
|
|
|
|
|
if (info_map) {
|
|
|
|
if (info_threads)
|
|
|
|
fputc('\n', lock_output);
|
2010-05-03 05:12:00 +00:00
|
|
|
dump_map();
|
2012-08-26 18:24:43 +00:00
|
|
|
}
|
2010-05-03 05:12:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 05:14:40 +00: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, },
|
|
|
|
};
|
|
|
|
|
2024-08-12 20:46:55 +00:00
|
|
|
static int process_event_update(const struct perf_tool *tool,
|
2022-11-04 05:14:40 +00:00
|
|
|
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 11:23:51 +00:00
|
|
|
typedef int (*tracepoint_handler)(struct evsel *evsel,
|
2012-09-24 13:52:12 +00:00
|
|
|
struct perf_sample *sample);
|
|
|
|
|
2024-08-12 20:46:55 +00:00
|
|
|
static int process_sample_event(const struct perf_tool *tool __maybe_unused,
|
2011-11-25 10:19:45 +00:00
|
|
|
union perf_event *event,
|
2011-03-15 18:44:01 +00:00
|
|
|
struct perf_sample *sample,
|
2019-07-21 11:23:51 +00:00
|
|
|
struct evsel *evsel,
|
2011-11-28 09:56:39 +00:00
|
|
|
struct machine *machine)
|
2010-04-23 22:04:12 +00: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-06 23:43:22 +00:00
|
|
|
int err = 0;
|
2013-08-27 08:23:03 +00:00
|
|
|
struct thread *thread = machine__findnew_thread(machine, sample->pid,
|
|
|
|
sample->tid);
|
2010-04-23 22:04:12 +00:00
|
|
|
|
|
|
|
if (thread == NULL) {
|
|
|
|
pr_debug("problem processing %d event, skipping it.\n",
|
2011-01-29 16:01:45 +00:00
|
|
|
event->header.type);
|
2010-04-23 22:04:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-06 13:17:38 +00: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-06 23:43:22 +00:00
|
|
|
err = f(evsel, sample);
|
2012-09-24 13:52:12 +00: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-06 23:43:22 +00:00
|
|
|
thread__put(thread);
|
|
|
|
|
|
|
|
return err;
|
2010-04-23 22:04:12 +00:00
|
|
|
}
|
|
|
|
|
2022-01-27 00:00:49 +00: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 02:19:16 +00:00
|
|
|
static void sort_result(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct lock_stat *st;
|
|
|
|
|
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++) {
|
2022-01-27 00:00:45 +00:00
|
|
|
hlist_for_each_entry(st, &lockhash_table[i], hash_entry) {
|
2013-09-09 02:19:16 +00:00
|
|
|
insert_to_result(st, compare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 20:17:27 +00:00
|
|
|
static const struct {
|
|
|
|
unsigned int flags;
|
2023-03-13 20:48:25 +00:00
|
|
|
const char *str;
|
2022-12-19 20:17:27 +00:00
|
|
|
const char *name;
|
|
|
|
} lock_type_table[] = {
|
2023-03-13 20:48:25 +00: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-06 21:06:05 +00:00
|
|
|
{ LCB_F_RT, "rt-mutex", "rt-mutex" },
|
2023-03-13 20:48:25 +00: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-19 20:17:28 +00:00
|
|
|
/* alias for get_type_flag() */
|
2023-03-13 20:48:25 +00:00
|
|
|
{ LCB_F_MUTEX | LCB_F_SPIN, "mutex-spin", "mutex" },
|
2022-12-19 20:17:27 +00:00
|
|
|
};
|
2022-07-25 18:31:22 +00:00
|
|
|
|
2022-12-19 20:17:27 +00:00
|
|
|
static const char *get_type_str(unsigned int flags)
|
|
|
|
{
|
2023-03-13 20:48:25 +00: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-19 20:17:27 +00: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-25 18:31:22 +00: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-19 20:17:28 +00: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-06 21:06:05 +00: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-19 20:17:28 +00:00
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lock_filter_finish(void)
|
|
|
|
{
|
|
|
|
zfree(&filters.types);
|
|
|
|
filters.nr_types = 0;
|
2022-12-19 20:17:30 +00: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;
|
2023-09-06 17:49:02 +00:00
|
|
|
|
|
|
|
zfree(&filters.cgrps);
|
|
|
|
filters.nr_cgrps = 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-19 20:17:28 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:22 +00: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-28 20:01:39 +00:00
|
|
|
static void print_header_stdio(void)
|
|
|
|
{
|
|
|
|
struct lock_key *key;
|
|
|
|
|
|
|
|
list_for_each_entry(key, &lock_keys, list)
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_TASK:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
show_lock_owner ? "owner" : "comm");
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
2023-09-06 17:49:01 +00:00
|
|
|
case LOCK_AGGR_CGROUP:
|
|
|
|
fprintf(lock_output, " %s\n\n", "cgroup");
|
|
|
|
break;
|
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-28 20:01:39 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_header_csv(const char *sep)
|
|
|
|
{
|
|
|
|
struct lock_key *key;
|
|
|
|
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
list_for_each_entry(key, &lock_keys, list)
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_TASK:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
show_lock_owner ? "owner" : "comm");
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
if (verbose > 0)
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
2023-09-06 17:49:01 +00:00
|
|
|
case LOCK_AGGR_CGROUP:
|
|
|
|
fprintf(lock_output, "%s\n", "cgroup");
|
|
|
|
break;
|
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-28 20:01:39 +00:00
|
|
|
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-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
|
|
|
pid = st->addr;
|
|
|
|
t = perf_session__findnew(session, pid);
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
pid, pid == -1 ? "Unknown" : thread__comm_str(t));
|
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
st->name, get_type_name(st->flags));
|
|
|
|
break;
|
2023-09-06 17:49:01 +00:00
|
|
|
case LOCK_AGGR_CGROUP:
|
|
|
|
fprintf(lock_output, " %s\n", st->name);
|
|
|
|
break;
|
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-28 20:01:39 +00:00
|
|
|
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-28 20:01:40 +00: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-28 20:01:39 +00: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-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aggr_mode) {
|
|
|
|
case LOCK_AGGR_CALLER:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
if (verbose <= 0)
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_TASK:
|
|
|
|
pid = st->addr;
|
|
|
|
t = perf_session__findnew(session, pid);
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
break;
|
|
|
|
case LOCK_AGGR_ADDR:
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
st->name, sep, get_type_name(st->flags));
|
|
|
|
break;
|
2023-09-06 17:49:01 +00:00
|
|
|
case LOCK_AGGR_CGROUP:
|
|
|
|
fprintf(lock_output, "%s\n",st->name);
|
|
|
|
break;
|
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-28 20:01:39 +00:00
|
|
|
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-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
}
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00: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-27 22:57:11 +00:00
|
|
|
{
|
|
|
|
/* Output for debug, this have to be removed */
|
2023-04-06 21:06:08 +00:00
|
|
|
int broken = fails->task + fails->stack + fails->time + fails->data;
|
2023-03-27 22:57:11 +00: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-28 20:01:39 +00:00
|
|
|
if (!use_bpf)
|
|
|
|
print_bad_events(bad, total);
|
|
|
|
|
2023-03-27 22:57:11 +00:00
|
|
|
if (quiet || total == 0 || (broken == 0 && verbose <= 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
total += broken;
|
2023-06-28 20:01:40 +00: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-27 22:57:11 +00:00
|
|
|
|
2023-06-28 20:01:40 +00: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-27 22:57:11 +00:00
|
|
|
}
|
2023-04-06 21:06:08 +00: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-28 20:01:39 +00: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-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
|
|
|
|
if (use_bpf) {
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
const char *name[4] = { "acquire", "acquired", "contended", "release" };
|
|
|
|
|
|
|
|
for (i = 0; i < BROKEN_MAX; i++)
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00:00
|
|
|
}
|
2023-06-28 20:01:40 +00: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-28 20:01:39 +00: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 05:53:12 +00:00
|
|
|
static void print_contention_result(struct lock_contention *con)
|
2022-07-25 18:31:22 +00:00
|
|
|
{
|
|
|
|
struct lock_stat *st;
|
2022-09-24 00:42:19 +00:00
|
|
|
int bad, total, printed;
|
2022-07-25 18:31:22 +00: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-28 20:01:39 +00:00
|
|
|
if (!quiet)
|
|
|
|
print_header();
|
2022-07-25 18:31:22 +00:00
|
|
|
|
2022-09-24 00:42:19 +00:00
|
|
|
bad = total = printed = 0;
|
2022-08-02 19:10:04 +00:00
|
|
|
|
2022-07-25 18:31:22 +00:00
|
|
|
while ((st = pop_from_result())) {
|
2022-08-02 19:10:04 +00:00
|
|
|
total += use_bpf ? st->nr_contended : 1;
|
2022-07-25 18:31:22 +00: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-19 20:17:28 +00: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-28 20:01:39 +00:00
|
|
|
print_lock_stat(con, st);
|
2022-09-24 00:42:19 +00:00
|
|
|
|
|
|
|
if (++printed >= print_nr_entries)
|
|
|
|
break;
|
2022-07-25 18:31:22 +00:00
|
|
|
}
|
|
|
|
|
2023-04-06 21:06:09 +00: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-28 20:01:39 +00:00
|
|
|
print_footer(total, bad, &con->fails);
|
2022-07-25 18:31:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 13:47:14 +00:00
|
|
|
static bool force;
|
|
|
|
|
2013-09-09 02:19:16 +00:00
|
|
|
static int __cmd_report(bool display_info)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2013-09-09 02:19:16 +00:00
|
|
|
int err = -EINVAL;
|
2024-08-12 20:47:01 +00:00
|
|
|
struct perf_tool eops;
|
2017-01-23 21:07:59 +00:00
|
|
|
struct perf_data data = {
|
2019-02-21 09:41:30 +00:00
|
|
|
.path = input_name,
|
|
|
|
.mode = PERF_DATA_MODE_READ,
|
|
|
|
.force = force,
|
2013-10-15 14:27:32 +00:00
|
|
|
};
|
2013-09-09 02:19:16 +00:00
|
|
|
|
2024-08-12 20:47:01 +00:00
|
|
|
perf_tool__init(&eops, /*ordered_events=*/true);
|
|
|
|
eops.attr = perf_event__process_attr;
|
|
|
|
eops.event_update = process_event_update;
|
|
|
|
eops.sample = process_sample_event;
|
|
|
|
eops.comm = perf_event__process_comm;
|
|
|
|
eops.mmap = perf_event__process_mmap;
|
|
|
|
eops.namespaces = perf_event__process_namespaces;
|
|
|
|
eops.tracing_data = perf_event__process_tracing_data;
|
2021-07-19 22:31:49 +00:00
|
|
|
session = perf_session__new(&data, &eops);
|
2019-08-22 07:20:49 +00:00
|
|
|
if (IS_ERR(session)) {
|
2012-08-26 18:24:43 +00:00
|
|
|
pr_err("Initializing perf session failed\n");
|
2019-08-22 07:20:49 +00:00
|
|
|
return PTR_ERR(session);
|
2012-08-26 18:24:43 +00:00
|
|
|
}
|
2010-01-30 11:43:33 +00: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 10:26:27 +00:00
|
|
|
symbol_conf.allow_aliases = true;
|
2014-08-12 06:40:45 +00:00
|
|
|
symbol__init(&session->header.env);
|
2014-08-12 06:40:40 +00:00
|
|
|
|
2022-11-04 05:14:40 +00:00
|
|
|
if (!data.is_pipe) {
|
|
|
|
if (!perf_session__has_traces(session, "lock record"))
|
|
|
|
goto out_delete;
|
2013-09-09 02:19:16 +00:00
|
|
|
|
2022-11-04 05:14:40 +00: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 13:52:12 +00:00
|
|
|
|
2022-11-04 05:14:40 +00:00
|
|
|
if (perf_session__set_tracepoints_handlers(session, contention_tracepoints)) {
|
|
|
|
pr_err("Initializing perf session tracepoint handlers failed\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-06-15 16:32:20 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:23 +00:00
|
|
|
if (setup_output_field(false, output_fields))
|
2022-03-23 23:02:58 +00:00
|
|
|
goto out_delete;
|
|
|
|
|
2022-07-25 18:31:23 +00:00
|
|
|
if (select_key(false))
|
2013-09-09 02:19:16 +00:00
|
|
|
goto out_delete;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-07-25 18:31:21 +00:00
|
|
|
if (show_thread_stats)
|
|
|
|
aggr_mode = LOCK_AGGR_TASK;
|
|
|
|
|
2015-03-03 14:58:45 +00:00
|
|
|
err = perf_session__process_events(session);
|
2013-09-09 02:19:16 +00:00
|
|
|
if (err)
|
|
|
|
goto out_delete;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
|
|
|
setup_pager();
|
2013-09-09 02:19:16 +00:00
|
|
|
if (display_info) /* used for info subcommand */
|
2024-05-13 09:14:12 +00:00
|
|
|
dump_info();
|
2013-09-09 02:19:16 +00:00
|
|
|
else {
|
2022-01-27 00:00:49 +00:00
|
|
|
combine_result();
|
2013-09-09 02:19:16 +00:00
|
|
|
sort_result();
|
|
|
|
print_result();
|
|
|
|
}
|
2012-08-26 18:24:43 +00:00
|
|
|
|
2013-09-09 02:19:16 +00:00
|
|
|
out_delete:
|
|
|
|
perf_session__delete(session);
|
|
|
|
return err;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 20:07:55 +00:00
|
|
|
static void sighandler(int sig __maybe_unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-07 00:24:02 +00: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;
|
|
|
|
}
|
|
|
|
|
2023-09-06 17:49:01 +00:00
|
|
|
if (show_lock_cgroups && !use_bpf) {
|
|
|
|
pr_err("Cgroups are available only with BPF\n");
|
|
|
|
parse_options_usage(usage, options, "lock-cgroup", 0);
|
|
|
|
parse_options_usage(NULL, options, "use-bpf", 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_lock_cgroups && show_lock_addrs) {
|
|
|
|
pr_err("Cannot use cgroup and addr mode together\n");
|
|
|
|
parse_options_usage(usage, options, "lock-cgroup", 0);
|
|
|
|
parse_options_usage(NULL, options, "lock-addr", 0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_lock_cgroups && show_thread_stats) {
|
|
|
|
pr_err("Cannot use cgroup and thread mode together\n");
|
|
|
|
parse_options_usage(usage, options, "lock-cgroup", 0);
|
|
|
|
parse_options_usage(NULL, options, "threads", 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-28 20:01:39 +00: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 00:24:02 +00:00
|
|
|
if (show_lock_owner)
|
|
|
|
show_thread_stats = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-29 20:07:56 +00:00
|
|
|
static int __cmd_contention(int argc, const char **argv)
|
2022-07-25 18:31:22 +00:00
|
|
|
{
|
|
|
|
int err = -EINVAL;
|
2024-08-12 20:47:01 +00:00
|
|
|
struct perf_tool eops;
|
2022-07-25 18:31:22 +00:00
|
|
|
struct perf_data data = {
|
|
|
|
.path = input_name,
|
|
|
|
.mode = PERF_DATA_MODE_READ,
|
|
|
|
.force = force,
|
|
|
|
};
|
2022-08-02 19:10:02 +00:00
|
|
|
struct lock_contention con = {
|
|
|
|
.target = &target,
|
2022-08-02 19:10:03 +00:00
|
|
|
.map_nr_entries = bpf_map_entries,
|
2022-09-12 05:53:13 +00:00
|
|
|
.max_stack = max_stack_depth,
|
|
|
|
.stack_skip = stack_skip,
|
2022-12-19 20:17:29 +00:00
|
|
|
.filters = &filters,
|
2023-01-26 00:09:36 +00:00
|
|
|
.save_callstack = needs_callstack(),
|
2023-02-07 00:24:02 +00:00
|
|
|
.owner = show_lock_owner,
|
2023-09-06 17:49:00 +00:00
|
|
|
.cgroups = RB_ROOT,
|
2022-08-02 19:10:02 +00:00
|
|
|
};
|
2022-07-25 18:31:22 +00:00
|
|
|
|
2023-05-26 18:33:54 +00:00
|
|
|
lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table));
|
|
|
|
if (!lockhash_table)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
con.result = &lockhash_table[0];
|
|
|
|
|
2024-08-12 20:47:01 +00:00
|
|
|
perf_tool__init(&eops, /*ordered_events=*/true);
|
|
|
|
eops.attr = perf_event__process_attr;
|
|
|
|
eops.event_update = process_event_update;
|
|
|
|
eops.sample = process_sample_event;
|
|
|
|
eops.comm = perf_event__process_comm;
|
|
|
|
eops.mmap = perf_event__process_mmap;
|
|
|
|
eops.tracing_data = perf_event__process_tracing_data;
|
|
|
|
|
2022-07-29 20:07:55 +00:00
|
|
|
session = perf_session__new(use_bpf ? NULL : &data, &eops);
|
2022-07-25 18:31:22 +00:00
|
|
|
if (IS_ERR(session)) {
|
|
|
|
pr_err("Initializing perf session failed\n");
|
2023-05-26 18:33:54 +00:00
|
|
|
err = PTR_ERR(session);
|
2023-08-17 12:11:21 +00:00
|
|
|
session = NULL;
|
2023-05-26 18:33:54 +00:00
|
|
|
goto out_delete;
|
2022-07-25 18:31:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 05:53:12 +00:00
|
|
|
con.machine = &session->machines.host;
|
|
|
|
|
2022-12-09 19:07:26 +00:00
|
|
|
con.aggr_mode = aggr_mode = show_thread_stats ? LOCK_AGGR_TASK :
|
2023-09-06 17:49:01 +00:00
|
|
|
show_lock_addrs ? LOCK_AGGR_ADDR :
|
|
|
|
show_lock_cgroups ? LOCK_AGGR_CGROUP : LOCK_AGGR_CALLER;
|
2022-12-09 19:07:26 +00:00
|
|
|
|
2023-02-07 00:24:01 +00: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 10:26:27 +00:00
|
|
|
symbol_conf.allow_aliases = true;
|
2022-07-25 18:31:22 +00:00
|
|
|
symbol__init(&session->header.env);
|
|
|
|
|
2022-07-29 20:07:55 +00:00
|
|
|
if (use_bpf) {
|
2022-07-29 20:07:56 +00: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-29 20:07:55 +00:00
|
|
|
}
|
2022-07-25 18:31:22 +00:00
|
|
|
|
2022-07-29 20:07:55 +00:00
|
|
|
signal(SIGINT, sighandler);
|
|
|
|
signal(SIGCHLD, sighandler);
|
|
|
|
signal(SIGTERM, sighandler);
|
2022-07-29 20:07:56 +00:00
|
|
|
|
2022-08-02 19:10:02 +00:00
|
|
|
con.evlist = evlist__new();
|
|
|
|
if (con.evlist == NULL) {
|
2022-07-29 20:07:56 +00:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_delete;
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:10:02 +00:00
|
|
|
err = evlist__create_maps(con.evlist, &target);
|
2022-07-29 20:07:56 +00:00
|
|
|
if (err < 0)
|
|
|
|
goto out_delete;
|
|
|
|
|
|
|
|
if (argc) {
|
2022-08-02 19:10:02 +00:00
|
|
|
err = evlist__prepare_workload(con.evlist, &target,
|
2022-07-29 20:07:56 +00:00
|
|
|
argv, false, NULL);
|
|
|
|
if (err < 0)
|
|
|
|
goto out_delete;
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:10:02 +00:00
|
|
|
if (lock_contention_prepare(&con) < 0) {
|
2022-07-29 20:07:56 +00:00
|
|
|
pr_err("lock contention BPF setup failed\n");
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-11-04 05:14:40 +00:00
|
|
|
} else if (!data.is_pipe) {
|
2022-07-29 20:07:55 +00:00
|
|
|
if (!perf_session__has_traces(session, "lock record"))
|
|
|
|
goto out_delete;
|
2022-07-25 18:31:22 +00:00
|
|
|
|
2022-07-29 20:07:55 +00: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-25 18:31:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 18:31:23 +00:00
|
|
|
if (setup_output_field(true, output_fields))
|
2022-07-25 18:31:22 +00:00
|
|
|
goto out_delete;
|
|
|
|
|
2022-07-25 18:31:23 +00:00
|
|
|
if (select_key(true))
|
2022-07-25 18:31:22 +00: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-28 20:01:39 +00: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-29 20:07:55 +00:00
|
|
|
if (use_bpf) {
|
|
|
|
lock_contention_start();
|
2022-07-29 20:07:56 +00:00
|
|
|
if (argc)
|
2022-08-02 19:10:02 +00:00
|
|
|
evlist__start_workload(con.evlist);
|
2022-07-29 20:07:55 +00:00
|
|
|
|
|
|
|
/* wait for signal */
|
|
|
|
pause();
|
|
|
|
|
|
|
|
lock_contention_stop();
|
2022-08-02 19:10:02 +00:00
|
|
|
lock_contention_read(&con);
|
2022-07-29 20:07:55 +00:00
|
|
|
} else {
|
|
|
|
err = perf_session__process_events(session);
|
|
|
|
if (err)
|
|
|
|
goto out_delete;
|
|
|
|
}
|
2022-07-25 18:31:22 +00:00
|
|
|
|
|
|
|
setup_pager();
|
|
|
|
|
|
|
|
sort_contention_result();
|
2022-09-12 05:53:12 +00:00
|
|
|
print_contention_result(&con);
|
2022-07-25 18:31:22 +00: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-19 20:17:28 +00:00
|
|
|
lock_filter_finish();
|
2022-08-02 19:10:02 +00:00
|
|
|
evlist__delete(con.evlist);
|
2023-09-06 17:49:00 +00:00
|
|
|
lock_contention_finish(&con);
|
2022-07-25 18:31:22 +00:00
|
|
|
perf_session__delete(session);
|
2023-05-26 18:33:54 +00:00
|
|
|
zfree(&lockhash_table);
|
2022-07-25 18:31:22 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
static int __cmd_record(int argc, const char **argv)
|
|
|
|
{
|
2012-10-01 18:20:58 +00:00
|
|
|
const char *record_args[] = {
|
2022-06-01 06:58:42 +00:00
|
|
|
"record", "-R", "-m", "1024", "-c", "1", "--synth", "task",
|
2012-10-01 18:20:58 +00:00
|
|
|
};
|
2022-06-15 16:32:22 +00:00
|
|
|
const char *callgraph_args[] = {
|
|
|
|
"--call-graph", "fp," __stringify(CONTENTION_STACK_DEPTH),
|
|
|
|
};
|
2013-09-09 02:19:15 +00:00
|
|
|
unsigned int rec_argc, i, j, ret;
|
2022-06-15 16:32:19 +00:00
|
|
|
unsigned int nr_tracepoints;
|
2022-06-15 16:32:22 +00:00
|
|
|
unsigned int nr_callgraph_args = 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
const char **rec_argv;
|
2022-06-15 16:32:19 +00:00
|
|
|
bool has_lock_stat = true;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2012-08-09 16:35:37 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(lock_tracepoints); i++) {
|
2012-09-24 13:52:12 +00:00
|
|
|
if (!is_valid_tracepoint(lock_tracepoints[i].name)) {
|
2022-06-15 16:32:19 +00: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-09 16:35:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 16:32:22 +00:00
|
|
|
nr_callgraph_args = ARRAY_SIZE(callgraph_args);
|
|
|
|
|
2022-06-15 16:32:19 +00:00
|
|
|
setup_args:
|
2022-06-15 16:32:22 +00:00
|
|
|
rec_argc = ARRAY_SIZE(record_args) + nr_callgraph_args + argc - 1;
|
2022-06-15 16:32:19 +00:00
|
|
|
|
|
|
|
if (has_lock_stat)
|
|
|
|
nr_tracepoints = ARRAY_SIZE(lock_tracepoints);
|
|
|
|
else
|
|
|
|
nr_tracepoints = ARRAY_SIZE(contention_tracepoints);
|
|
|
|
|
2012-08-09 16:35:37 +00:00
|
|
|
/* factor of 2 is for -e in front of each tracepoint */
|
2022-06-15 16:32:19 +00:00
|
|
|
rec_argc += 2 * nr_tracepoints;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2012-08-09 16:35:37 +00:00
|
|
|
rec_argv = calloc(rec_argc + 1, sizeof(char *));
|
2013-09-09 02:19:15 +00:00
|
|
|
if (!rec_argv)
|
2010-11-13 02:35:06 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(record_args); i++)
|
2024-05-09 05:31:23 +00:00
|
|
|
rec_argv[i] = record_args[i];
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2022-06-15 16:32:19 +00:00
|
|
|
for (j = 0; j < nr_tracepoints; j++) {
|
2012-08-09 16:35:37 +00:00
|
|
|
rec_argv[i++] = "-e";
|
2024-05-09 05:31:23 +00:00
|
|
|
rec_argv[i++] = has_lock_stat
|
|
|
|
? lock_tracepoints[j].name
|
|
|
|
: contention_tracepoints[j].name;
|
2012-08-09 16:35:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 16:32:22 +00:00
|
|
|
for (j = 0; j < nr_callgraph_args; j++, i++)
|
|
|
|
rec_argv[i] = callgraph_args[j];
|
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
for (j = 1; j < (unsigned int)argc; j++, i++)
|
|
|
|
rec_argv[i] = argv[j];
|
|
|
|
|
|
|
|
BUG_ON(i != rec_argc);
|
|
|
|
|
2017-03-27 14:47:20 +00:00
|
|
|
ret = cmd_record(i, rec_argv);
|
2013-09-09 02:19:15 +00:00
|
|
|
free(rec_argv);
|
|
|
|
return ret;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-02 19:10:03 +00: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-28 18:01:26 +00: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-19 20:17:28 +00: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-06 21:06:05 +00: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-19 20:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!add_lock_type(flags)) {
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-12-19 20:17:30 +00: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 00:09:36 +00: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");
|
2023-10-09 18:39:15 +00:00
|
|
|
free(s);
|
2023-01-26 00:09:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(entry->name, tok);
|
|
|
|
list_add_tail(&entry->list, &callstack_filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-28 20:01:40 +00: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;
|
|
|
|
}
|
|
|
|
|
2023-09-06 17:49:02 +00:00
|
|
|
static bool add_lock_cgroup(char *name)
|
|
|
|
{
|
|
|
|
u64 *tmp;
|
|
|
|
struct cgroup *cgrp;
|
|
|
|
|
|
|
|
cgrp = cgroup__new(name, /*do_open=*/false);
|
|
|
|
if (cgrp == NULL) {
|
|
|
|
pr_err("Failed to create cgroup: %s\n", name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read_cgroup_id(cgrp) < 0) {
|
|
|
|
pr_err("Failed to read cgroup id for %s\n", name);
|
|
|
|
cgroup__put(cgrp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = realloc(filters.cgrps, (filters.nr_cgrps + 1) * sizeof(*filters.cgrps));
|
|
|
|
if (tmp == NULL) {
|
|
|
|
pr_err("Memory allocation failure\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp[filters.nr_cgrps++] = cgrp->id;
|
|
|
|
filters.cgrps = tmp;
|
|
|
|
cgroup__put(cgrp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_cgroup_filter(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)) {
|
|
|
|
if (!add_lock_cgroup(tok)) {
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-27 14:47:20 +00:00
|
|
|
int cmd_lock(int argc, const char **argv)
|
2010-01-30 11:43:33 +00:00
|
|
|
{
|
2017-03-17 05:53:42 +00:00
|
|
|
const struct option lock_options[] = {
|
|
|
|
OPT_STRING('i', "input", &input_name, "file", "input file name"),
|
2023-06-28 20:01:40 +00:00
|
|
|
OPT_CALLBACK(0, "output", &output_name, "file", "output file name", parse_output),
|
2017-03-17 05:53:42 +00: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 14:16:02 +00:00
|
|
|
OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
|
2022-06-15 16:32:17 +00: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 09:41:36 +00:00
|
|
|
OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any warnings or messages"),
|
2017-03-17 05:53:42 +00:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2012-10-01 18:20:58 +00:00
|
|
|
const struct option info_options[] = {
|
|
|
|
OPT_BOOLEAN('t', "threads", &info_threads,
|
2024-05-13 09:14:12 +00:00
|
|
|
"dump the thread list in perf.data"),
|
2012-10-01 18:20:58 +00:00
|
|
|
OPT_BOOLEAN('m', "map", &info_map,
|
2024-05-13 09:14:12 +00:00
|
|
|
"dump the map of lock instances (address:name table)"),
|
2017-03-17 05:53:42 +00:00
|
|
|
OPT_PARENT(lock_options)
|
2012-10-01 18:20:58 +00:00
|
|
|
};
|
2017-03-17 05:53:42 +00:00
|
|
|
|
2012-10-01 18:20:58 +00:00
|
|
|
const struct option report_options[] = {
|
|
|
|
OPT_STRING('k', "key", &sort_key, "acquired",
|
2013-09-09 02:19:19 +00:00
|
|
|
"key for sorting (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
|
2022-03-23 23:02:59 +00:00
|
|
|
OPT_STRING('F', "field", &output_fields, NULL,
|
|
|
|
"output fields (acquired / contended / avg_wait / wait_total / wait_max / wait_min)"),
|
2012-10-01 18:20:58 +00:00
|
|
|
/* TODO: type */
|
2022-01-27 00:00:49 +00:00
|
|
|
OPT_BOOLEAN('c', "combine-locks", &combine_locks,
|
|
|
|
"combine locks in the same class"),
|
2022-05-21 01:08:11 +00:00
|
|
|
OPT_BOOLEAN('t', "threads", &show_thread_stats,
|
|
|
|
"show per-thread lock stats"),
|
2022-09-24 00:42:19 +00:00
|
|
|
OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
|
2017-03-17 05:53:42 +00:00
|
|
|
OPT_PARENT(lock_options)
|
2012-10-01 18:20:58 +00:00
|
|
|
};
|
2017-03-17 05:53:42 +00:00
|
|
|
|
2022-07-29 20:07:55 +00:00
|
|
|
struct option contention_options[] = {
|
2022-07-25 18:31:23 +00: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-25 18:31:24 +00:00
|
|
|
OPT_BOOLEAN('t', "threads", &show_thread_stats,
|
|
|
|
"show per-thread lock stats"),
|
2022-07-29 20:07:55 +00:00
|
|
|
OPT_BOOLEAN('b', "use-bpf", &use_bpf, "use BPF program to collect lock contention stats"),
|
2022-07-29 20:07:56 +00: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-06 21:06:06 +00:00
|
|
|
OPT_CALLBACK('M', "map-nr-entries", &bpf_map_entries, "num",
|
2022-08-02 19:10:03 +00:00
|
|
|
"Max number of BPF map entries", parse_map_entry),
|
2022-10-28 18:01:26 +00:00
|
|
|
OPT_CALLBACK(0, "max-stack", &max_stack_depth, "num",
|
2023-08-25 10:47:00 +00:00
|
|
|
"Set the maximum stack depth when collecting lock contention, "
|
2022-10-28 18:01:26 +00:00
|
|
|
"Default: " __stringify(CONTENTION_STACK_DEPTH), parse_max_stack),
|
2022-09-12 05:53:13 +00: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 00:42:19 +00:00
|
|
|
OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
|
2022-12-09 19:07:26 +00: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-19 20:17:28 +00:00
|
|
|
OPT_CALLBACK('Y', "type-filter", NULL, "FLAGS",
|
|
|
|
"Filter specific type of locks", parse_lock_type),
|
2022-12-19 20:17:30 +00:00
|
|
|
OPT_CALLBACK('L', "lock-filter", NULL, "ADDRS/NAMES",
|
|
|
|
"Filter specific address/symbol of locks", parse_lock_addr),
|
2023-01-26 00:09:36 +00:00
|
|
|
OPT_CALLBACK('S', "callstack-filter", NULL, "NAMES",
|
|
|
|
"Filter specific function in the callstack", parse_call_stack),
|
2023-02-07 00:24:02 +00: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-28 20:01:39 +00:00
|
|
|
OPT_STRING_NOEMPTY('x', "field-separator", &symbol_conf.field_sep, "separator",
|
|
|
|
"print result in CSV format with custom separator"),
|
2023-09-06 17:49:01 +00:00
|
|
|
OPT_BOOLEAN(0, "lock-cgroup", &show_lock_cgroups, "show lock stats by cgroup"),
|
2023-09-06 17:49:02 +00:00
|
|
|
OPT_CALLBACK('G', "cgroup-filter", NULL, "CGROUPS",
|
|
|
|
"Filter specific cgroups", parse_cgroup_filter),
|
2022-07-25 18:31:22 +00:00
|
|
|
OPT_PARENT(lock_options)
|
|
|
|
};
|
|
|
|
|
2012-10-01 18:20:58 +00:00
|
|
|
const char * const info_usage[] = {
|
|
|
|
"perf lock info [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
2014-03-15 03:17:53 +00: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 01:48:54 +00:00
|
|
|
"info", "contention", NULL };
|
2014-03-15 03:17:53 +00:00
|
|
|
const char *lock_usage[] = {
|
|
|
|
NULL,
|
2012-10-01 18:20:58 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
const char * const report_usage[] = {
|
|
|
|
"perf lock report [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
2022-07-25 18:31:22 +00:00
|
|
|
const char * const contention_usage[] = {
|
|
|
|
"perf lock contention [<options>]",
|
|
|
|
NULL
|
|
|
|
};
|
2010-01-30 11:43:33 +00:00
|
|
|
unsigned int i;
|
2012-08-26 18:24:43 +00:00
|
|
|
int rc = 0;
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2023-05-26 18:33:54 +00:00
|
|
|
lockhash_table = calloc(LOCKHASH_SIZE, sizeof(*lockhash_table));
|
|
|
|
if (!lockhash_table)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-01-30 11:43:33 +00:00
|
|
|
for (i = 0; i < LOCKHASH_SIZE; i++)
|
2022-01-27 00:00:45 +00:00
|
|
|
INIT_HLIST_HEAD(lockhash_table + i);
|
2010-01-30 11:43:33 +00:00
|
|
|
|
2023-06-28 20:01:40 +00:00
|
|
|
lock_output = stderr;
|
2014-03-15 03:17:53 +00:00
|
|
|
argc = parse_options_subcommand(argc, argv, lock_options, lock_subcommands,
|
|
|
|
lock_usage, PARSE_OPT_STOP_AT_NON_OPTION);
|
2010-01-30 11:43:33 +00:00
|
|
|
if (!argc)
|
|
|
|
usage_with_options(lock_usage, lock_options);
|
|
|
|
|
2022-03-25 09:20:32 +00:00
|
|
|
if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) {
|
2010-01-30 11:43:33 +00:00
|
|
|
return __cmd_record(argc, argv);
|
2022-03-25 09:20:32 +00:00
|
|
|
} else if (strlen(argv[0]) > 2 && strstarts("report", argv[0])) {
|
2010-01-31 07:27:58 +00:00
|
|
|
trace_handler = &report_lock_ops;
|
2010-01-30 11:43:33 +00:00
|
|
|
if (argc) {
|
|
|
|
argc = parse_options(argc, argv,
|
2010-01-31 07:27:58 +00:00
|
|
|
report_options, report_usage, 0);
|
2010-01-30 11:43:33 +00:00
|
|
|
if (argc)
|
2010-01-31 07:27:58 +00:00
|
|
|
usage_with_options(report_usage, report_options);
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|
2013-09-09 02:19:16 +00:00
|
|
|
rc = __cmd_report(false);
|
2010-11-16 17:45:39 +00:00
|
|
|
} else if (!strcmp(argv[0], "script")) {
|
|
|
|
/* Aliased to 'perf script' */
|
2023-05-26 18:33:54 +00:00
|
|
|
rc = cmd_script(argc, argv);
|
2010-05-03 05:12:00 +00: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);
|
|
|
|
}
|
2024-05-13 09:14:12 +00:00
|
|
|
|
|
|
|
/* If neither threads nor map requested, display both */
|
|
|
|
if (!info_threads && !info_map) {
|
|
|
|
info_threads = true;
|
|
|
|
info_map = true;
|
|
|
|
}
|
|
|
|
|
2010-01-31 07:27:58 +00:00
|
|
|
/* recycling report_lock_ops */
|
|
|
|
trace_handler = &report_lock_ops;
|
2013-09-09 02:19:16 +00:00
|
|
|
rc = __cmd_report(true);
|
2022-07-25 18:31:22 +00:00
|
|
|
} else if (strlen(argv[0]) > 2 && strstarts("contention", argv[0])) {
|
|
|
|
trace_handler = &contention_lock_ops;
|
2022-07-25 18:31:23 +00:00
|
|
|
sort_key = "wait_total";
|
|
|
|
output_fields = "contended,wait_total,wait_max,avg_wait";
|
|
|
|
|
2022-07-29 20:07:55 +00:00
|
|
|
#ifndef HAVE_BPF_SKEL
|
|
|
|
set_option_nobuild(contention_options, 'b', "use-bpf",
|
2023-05-06 21:07:37 +00:00
|
|
|
"no BUILD_BPF_SKEL=1", false);
|
2022-07-29 20:07:55 +00:00
|
|
|
#endif
|
2022-07-25 18:31:22 +00:00
|
|
|
if (argc) {
|
|
|
|
argc = parse_options(argc, argv, contention_options,
|
|
|
|
contention_usage, 0);
|
|
|
|
}
|
2022-12-09 19:07:26 +00:00
|
|
|
|
2023-02-07 00:24:02 +00:00
|
|
|
if (check_lock_contention_options(contention_options,
|
|
|
|
contention_usage) < 0)
|
2022-12-09 19:07:26 +00:00
|
|
|
return -1;
|
|
|
|
|
2022-07-29 20:07:56 +00:00
|
|
|
rc = __cmd_contention(argc, argv);
|
2010-01-30 11:43:33 +00:00
|
|
|
} else {
|
|
|
|
usage_with_options(lock_usage, lock_options);
|
|
|
|
}
|
|
|
|
|
libsubcmd: Don't free the usage string
Currently, commands which depend on 'parse_options_subcommand()' don't
show the usage string, and instead show '(null)'
$ ./perf sched
Usage: (null)
-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)
'parse_options_subcommand()' is generally expected to initialise the usage
string, with information in the passed 'subcommands[]' array
This behaviour was changed in:
230a7a71f92212e7 ("libsubcmd: Fix parse-options memory leak")
Where the generated usage string is deallocated, and usage[0] string is
reassigned as NULL.
As discussed in [1], free the allocated usage string in the main
function itself, and don't reset usage string to NULL in
parse_options_subcommand
With this change, the behaviour is restored.
$ ./perf sched
Usage: perf sched [<options>] {record|latency|map|replay|script|timehist}
-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)
[1]: https://lore.kernel.org/linux-perf-users/htq5vhx6piet4nuq2mmhk7fs2bhfykv52dbppwxmo3s7du2odf@styd27tioc6e/
Fixes: 230a7a71f92212e7 ("libsubcmd: Fix parse-options memory leak")
Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Aditya Gupta <adityag@linux.ibm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240904061836.55873-2-adityag@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-09-04 06:18:30 +00:00
|
|
|
/* free usage string allocated by parse_options_subcommand */
|
|
|
|
free((void *)lock_usage[0]);
|
|
|
|
|
2023-05-26 18:33:54 +00:00
|
|
|
zfree(&lockhash_table);
|
2012-08-26 18:24:43 +00:00
|
|
|
return rc;
|
2010-01-30 11:43:33 +00:00
|
|
|
}
|