System-wide collection from all CPUs.
-C::
---cpu::
+--cpu=<value>::
Collect samples only on the list of CPUs provided. Multiple CPUs can be
provided as a comma-separated list with no space: 0,1. Ranges of CPUs
are specified with -: 0-2. Default is to monitor all CPUs.
-p::
---pid=::
+--pid=<value>::
Record events on existing process ID (comma separated list).
---tid=::
+--tid=<value>::
Record events on existing thread ID (comma separated list).
---map-nr-entries::
+--map-nr-entries=<value>::
Maximum number of BPF map entries (default: 10240).
---max-stack::
+--max-stack=<value>::
Maximum stack depth when collecting lock contention (default: 8).
---stack-skip
+--stack-skip=<value>::
Number of stack depth to skip when finding a lock caller (default: 3).
-E::
--lock-addr::
Show lock contention stat by address
+-Y::
+--type-filter=<value>::
+ Show lock contention only for given lock types (comma separated list).
+ Available values are:
+ semaphore, spinlock, rwlock, rwlock:R, rwlock:W, rwsem, rwsem:R, rwsem:W,
+ rtmutex, rwlock-rt, rwlock-rt:R, rwlock-rt:W, pcpu-sem, pcpu-sem:R, pcpu-sem:W,
+ mutex
+
+ Note that RW-variant of locks have :R and :W suffix. Names without the
+ suffix are shortcuts for the both variants. Ex) rwsem = rwsem:R + rwsem:W.
+
SEE ALSO
--------
static int stack_skip = CONTENTION_STACK_SKIP;
static int print_nr_entries = INT_MAX / 2;
+static struct lock_filter filters;
+
static enum lock_aggr_mode aggr_mode = LOCK_AGGR_ADDR;
static struct thread_stat *thread_stat_find(u32 tid)
struct thread_stat *ts;
struct lock_seq_stat *seq;
u64 addr = evsel__intval(evsel, sample, "lock_addr");
+ unsigned int flags = evsel__intval(evsel, sample, "flags");
u64 key;
- int ret;
+ int i, ret;
ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
if (ret < 0)
if (!ls) {
char buf[128];
const char *name = "";
- unsigned int flags = evsel__intval(evsel, sample, "flags");
struct machine *machine = &session->machines.host;
struct map *kmap;
struct symbol *sym;
}
}
+ 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;
+ }
+
ts = thread_stat_findnew(sample->tid);
if (!ts)
return -ENOMEM;
{ LCB_F_PERCPU | LCB_F_WRITE, "pcpu-sem:W" },
{ LCB_F_MUTEX, "mutex" },
{ LCB_F_MUTEX | LCB_F_SPIN, "mutex" },
+ /* alias for get_type_flag() */
+ { LCB_F_MUTEX | LCB_F_SPIN, "mutex-spin" },
};
static const char *get_type_str(unsigned int flags)
return "unknown";
}
+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;
+ }
+ return UINT_MAX;
+}
+
+static void lock_filter_finish(void)
+{
+ zfree(&filters.types);
+ filters.nr_types = 0;
+}
+
static void sort_contention_result(void)
{
sort_result();
if (st->broken)
bad++;
+ if (!st->wait_time_total)
+ continue;
+
list_for_each_entry(key, &lock_keys, list) {
key->print(key, st);
pr_info(" ");
print_contention_result(&con);
out_delete:
+ lock_filter_finish();
evlist__delete(con.evlist);
lock_contention_finish();
perf_session__delete(session);
return 0;
}
+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) {
+ char buf[32];
+
+ if (strchr(tok, ':'))
+ continue;
+
+ /* try :R and :W suffixes for rwlock, rwsem, ... */
+ scnprintf(buf, sizeof(buf), "%s:R", tok);
+ flags = get_type_flag(buf);
+ if (flags != UINT_MAX) {
+ if (!add_lock_type(flags)) {
+ ret = -1;
+ break;
+ }
+ }
+
+ scnprintf(buf, sizeof(buf), "%s:W", tok);
+ flags = get_type_flag(buf);
+ if (flags != UINT_MAX) {
+ if (!add_lock_type(flags)) {
+ ret = -1;
+ break;
+ }
+ }
+ continue;
+ }
+
+ if (!add_lock_type(flags)) {
+ ret = -1;
+ break;
+ }
+
+ if (!strcmp(tok, "mutex")) {
+ flags = get_type_flag("mutex-spin");
+ if (flags != UINT_MAX) {
+ if (!add_lock_type(flags)) {
+ ret = -1;
+ break;
+ }
+ }
+ }
+ }
+
+ free(s);
+ return ret;
+}
+
int cmd_lock(int argc, const char **argv)
{
const struct option lock_options[] = {
"Default: " __stringify(CONTENTION_STACK_SKIP)),
OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
OPT_BOOLEAN('l', "lock-addr", &show_lock_addrs, "show lock stats by address"),
+ OPT_CALLBACK('Y', "type-filter", NULL, "FLAGS",
+ "Filter specific type of locks", parse_lock_type),
OPT_PARENT(lock_options)
};