Commit f9c695a2 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf lock: Add lock aggregation enum

Introduce the aggr_mode variable to prepare a later code change.

The default is LOCK_AGGR_ADDR which aggregates the result for the lock
instances.

When -t/--threads option is given, it'd be set to LOCK_AGGR_TASK.  The
LOCK_AGGR_CALLER is for the contention analysis and it'd aggregate the
stat by comparing the callstacks.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220725183124.368304-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent fb87158b
...@@ -126,6 +126,12 @@ static struct rb_root thread_stats; ...@@ -126,6 +126,12 @@ static struct rb_root thread_stats;
static bool combine_locks; static bool combine_locks;
static bool show_thread_stats; static bool show_thread_stats;
static enum {
LOCK_AGGR_ADDR,
LOCK_AGGR_TASK,
LOCK_AGGR_CALLER,
} aggr_mode = LOCK_AGGR_ADDR;
/* /*
* CONTENTION_STACK_DEPTH * CONTENTION_STACK_DEPTH
* Number of stack trace entries to find callers * Number of stack trace entries to find callers
...@@ -622,12 +628,22 @@ static int report_lock_acquire_event(struct evsel *evsel, ...@@ -622,12 +628,22 @@ static int report_lock_acquire_event(struct evsel *evsel,
const char *name = evsel__strval(evsel, sample, "name"); const char *name = evsel__strval(evsel, sample, "name");
u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
int flag = evsel__intval(evsel, sample, "flags"); int flag = evsel__intval(evsel, sample, "flags");
u64 key;
/* abuse ls->addr for tid */ switch (aggr_mode) {
if (show_thread_stats) case LOCK_AGGR_ADDR:
addr = sample->tid; key = addr;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_findnew(addr, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
return -ENOMEM; return -ENOMEM;
...@@ -695,11 +711,22 @@ static int report_lock_acquired_event(struct evsel *evsel, ...@@ -695,11 +711,22 @@ static int report_lock_acquired_event(struct evsel *evsel,
u64 contended_term; u64 contended_term;
const char *name = evsel__strval(evsel, sample, "name"); const char *name = evsel__strval(evsel, sample, "name");
u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
u64 key;
if (show_thread_stats) switch (aggr_mode) {
addr = sample->tid; case LOCK_AGGR_ADDR:
key = addr;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_findnew(addr, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
return -ENOMEM; return -ENOMEM;
...@@ -757,11 +784,22 @@ static int report_lock_contended_event(struct evsel *evsel, ...@@ -757,11 +784,22 @@ static int report_lock_contended_event(struct evsel *evsel,
struct lock_seq_stat *seq; struct lock_seq_stat *seq;
const char *name = evsel__strval(evsel, sample, "name"); const char *name = evsel__strval(evsel, sample, "name");
u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
u64 key;
if (show_thread_stats) switch (aggr_mode) {
addr = sample->tid; case LOCK_AGGR_ADDR:
key = addr;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_findnew(addr, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
return -ENOMEM; return -ENOMEM;
...@@ -812,11 +850,22 @@ static int report_lock_release_event(struct evsel *evsel, ...@@ -812,11 +850,22 @@ static int report_lock_release_event(struct evsel *evsel,
struct lock_seq_stat *seq; struct lock_seq_stat *seq;
const char *name = evsel__strval(evsel, sample, "name"); const char *name = evsel__strval(evsel, sample, "name");
u64 addr = evsel__intval(evsel, sample, "lockdep_addr"); u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
u64 key;
if (show_thread_stats) switch (aggr_mode) {
addr = sample->tid; case LOCK_AGGR_ADDR:
key = addr;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_findnew(addr, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
return -ENOMEM; return -ENOMEM;
...@@ -980,11 +1029,22 @@ static int report_lock_contention_begin_event(struct evsel *evsel, ...@@ -980,11 +1029,22 @@ static int report_lock_contention_begin_event(struct evsel *evsel,
struct thread_stat *ts; struct thread_stat *ts;
struct lock_seq_stat *seq; struct lock_seq_stat *seq;
u64 addr = evsel__intval(evsel, sample, "lock_addr"); u64 addr = evsel__intval(evsel, sample, "lock_addr");
u64 key;
if (show_thread_stats) switch (aggr_mode) {
addr = sample->tid; case LOCK_AGGR_ADDR:
key = addr;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_find(addr); ls = lock_stat_find(key);
if (!ls) { if (!ls) {
char buf[128]; char buf[128];
const char *caller = buf; const char *caller = buf;
...@@ -993,7 +1053,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, ...@@ -993,7 +1053,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel,
if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0)
caller = "Unknown"; caller = "Unknown";
ls = lock_stat_findnew(addr, caller, flags); ls = lock_stat_findnew(key, caller, flags);
if (!ls) if (!ls)
return -ENOMEM; return -ENOMEM;
} }
...@@ -1050,11 +1110,22 @@ static int report_lock_contention_end_event(struct evsel *evsel, ...@@ -1050,11 +1110,22 @@ static int report_lock_contention_end_event(struct evsel *evsel,
struct lock_seq_stat *seq; struct lock_seq_stat *seq;
u64 contended_term; u64 contended_term;
u64 addr = evsel__intval(evsel, sample, "lock_addr"); u64 addr = evsel__intval(evsel, sample, "lock_addr");
u64 key;
if (show_thread_stats) switch (aggr_mode) {
addr = sample->tid; case LOCK_AGGR_ADDR:
key = addr;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_find(addr); ls = lock_stat_find(key);
if (!ls) if (!ls)
return 0; return 0;
...@@ -1416,6 +1487,9 @@ static int __cmd_report(bool display_info) ...@@ -1416,6 +1487,9 @@ static int __cmd_report(bool display_info)
if (select_key()) if (select_key())
goto out_delete; goto out_delete;
if (show_thread_stats)
aggr_mode = LOCK_AGGR_TASK;
err = perf_session__process_events(session); err = perf_session__process_events(session);
if (err) if (err)
goto out_delete; goto out_delete;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment