Commit 0f405f87 authored by Shang XiaoJing's avatar Shang XiaoJing Committed by Arnaldo Carvalho de Melo

perf lock: Add get_key_by_aggr_mode helper

Wrap repeated code in helper functions get_key_by_aggr_mode and
get_key_by_aggr_mode_simple, which assign the value to key based on
aggregation mode. Note that for the conditions not support
LOCK_AGGR_CALLER, should call get_key_by_aggr_mode_simple directly.
Signed-off-by: default avatarShang XiaoJing <shangxiaojing@huawei.com>
Acked-by: default avatarNamhyung 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: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220908021141.27134-3-shangxiaojing@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e3e7572f
...@@ -560,29 +560,50 @@ enum acquire_flags { ...@@ -560,29 +560,50 @@ enum acquire_flags {
READ_LOCK = 2, READ_LOCK = 2,
}; };
static int report_lock_acquire_event(struct evsel *evsel, static int get_key_by_aggr_mode_simple(u64 *key, u64 addr, u32 tid)
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;
switch (aggr_mode) { switch (aggr_mode) {
case LOCK_AGGR_ADDR: case LOCK_AGGR_ADDR:
key = addr; *key = addr;
break; break;
case LOCK_AGGR_TASK: case LOCK_AGGR_TASK:
key = sample->tid; *key = tid;
break; break;
case LOCK_AGGR_CALLER: case LOCK_AGGR_CALLER:
default: default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode); pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL; return -EINVAL;
} }
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;
ls = lock_stat_findnew(key, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
...@@ -653,19 +674,11 @@ static int report_lock_acquired_event(struct evsel *evsel, ...@@ -653,19 +674,11 @@ static int report_lock_acquired_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");
u64 key; u64 key;
int ret;
switch (aggr_mode) { ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
case LOCK_AGGR_ADDR: if (ret < 0)
key = addr; return ret;
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(key, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
...@@ -726,19 +739,11 @@ static int report_lock_contended_event(struct evsel *evsel, ...@@ -726,19 +739,11 @@ static int report_lock_contended_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");
u64 key; u64 key;
int ret;
switch (aggr_mode) { ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
case LOCK_AGGR_ADDR: if (ret < 0)
key = addr; return ret;
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(key, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
...@@ -792,19 +797,11 @@ static int report_lock_release_event(struct evsel *evsel, ...@@ -792,19 +797,11 @@ static int report_lock_release_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");
u64 key; u64 key;
int ret;
switch (aggr_mode) { ret = get_key_by_aggr_mode_simple(&key, addr, sample->tid);
case LOCK_AGGR_ADDR: if (ret < 0)
key = addr; return ret;
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(key, name, 0); ls = lock_stat_findnew(key, name, 0);
if (!ls) if (!ls)
...@@ -1015,21 +1012,11 @@ static int report_lock_contention_begin_event(struct evsel *evsel, ...@@ -1015,21 +1012,11 @@ static int report_lock_contention_begin_event(struct evsel *evsel,
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; u64 key;
int ret;
switch (aggr_mode) { ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
case LOCK_AGGR_ADDR: if (ret < 0)
key = addr; return ret;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
key = callchain_id(evsel, sample);
break;
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_find(key); ls = lock_stat_find(key);
if (!ls) { if (!ls) {
...@@ -1098,21 +1085,11 @@ static int report_lock_contention_end_event(struct evsel *evsel, ...@@ -1098,21 +1085,11 @@ static int report_lock_contention_end_event(struct evsel *evsel,
u64 contended_term; u64 contended_term;
u64 addr = evsel__intval(evsel, sample, "lock_addr"); u64 addr = evsel__intval(evsel, sample, "lock_addr");
u64 key; u64 key;
int ret;
switch (aggr_mode) { ret = get_key_by_aggr_mode(&key, addr, evsel, sample);
case LOCK_AGGR_ADDR: if (ret < 0)
key = addr; return ret;
break;
case LOCK_AGGR_TASK:
key = sample->tid;
break;
case LOCK_AGGR_CALLER:
key = callchain_id(evsel, sample);
break;
default:
pr_err("Invalid aggregation mode: %d\n", aggr_mode);
return -EINVAL;
}
ls = lock_stat_find(key); ls = lock_stat_find(key);
if (!ls) if (!ls)
......
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