* [PATCH v6 2/3] perf lock: Add percpu-rwsem for type filter
2025-01-16 23:58 [PATCH v6 1/3] perf lock: Fix parse_lock_type which only retrieve one lock flag Chun-Tse Shao
@ 2025-01-16 23:58 ` Chun-Tse Shao
2025-01-16 23:58 ` [PATCH v6 3/3] perf lock: Rename fields in lock_type_table Chun-Tse Shao
2025-01-18 17:59 ` [PATCH v6 1/3] perf lock: Fix parse_lock_type which only retrieve one lock flag Namhyung Kim
2 siblings, 0 replies; 4+ messages in thread
From: Chun-Tse Shao @ 2025-01-16 23:58 UTC (permalink / raw)
To: linux-kernel
Cc: Chun-Tse Shao, Namhyung Kim, peterz, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
nick.forrington, linux-perf-users
percpu-rwsem was missing in man page. And for backward compatibility,
replace `pcpu-sem` with `percpu-rwsem` before parsing lock name.
Tested `./perf lock con -ab -Y pcpu-sem` and `./perf lock con -ab -Y
percpu-rwsem`
Fixes: 4f701063bfa2 ("perf lock contention: Show lock type with address")
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
---
Note:
Rebased on tmp.perf-tools-next
tools/perf/Documentation/perf-lock.txt | 4 ++--
tools/perf/builtin-lock.c | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
index 57a940399de0..d3793054f7d3 100644
--- a/tools/perf/Documentation/perf-lock.txt
+++ b/tools/perf/Documentation/perf-lock.txt
@@ -187,8 +187,8 @@ CONTENTION OPTIONS
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
+ rtmutex, rwlock-rt, rwlock-rt:R, rwlock-rt:W, percpu-rwmem, 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.
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index a6203c622967..258c4ccb96af 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -2265,7 +2265,10 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
/*
* Otherwise `tok` is `name` in `lock_type_table`.
* Single lock name could contain multiple flags.
+ * Replace alias `pcpu-sem` with actual name `percpu-rwsem.
*/
+ if (!strcmp(tok, "pcpu-sem"))
+ tok = (char *)"percpu-rwsem";
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
if (!strcmp(lock_type_table[i].name, tok)) {
if (add_lock_type(lock_type_table[i].flags)) {
--
2.48.0.rc2.279.g1de40edade-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v6 3/3] perf lock: Rename fields in lock_type_table
2025-01-16 23:58 [PATCH v6 1/3] perf lock: Fix parse_lock_type which only retrieve one lock flag Chun-Tse Shao
2025-01-16 23:58 ` [PATCH v6 2/3] perf lock: Add percpu-rwsem for type filter Chun-Tse Shao
@ 2025-01-16 23:58 ` Chun-Tse Shao
2025-01-18 17:59 ` [PATCH v6 1/3] perf lock: Fix parse_lock_type which only retrieve one lock flag Namhyung Kim
2 siblings, 0 replies; 4+ messages in thread
From: Chun-Tse Shao @ 2025-01-16 23:58 UTC (permalink / raw)
To: linux-kernel
Cc: Chun-Tse Shao, Namhyung Kim, peterz, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
nick.forrington, linux-perf-users
`lock_type_table` contains `name` and `str` which can be confusing.
Rename them to `flags_name` and `lock_name` and add descriptions to
enhance understanding.
Tested by building perf for x86.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
---
Note:
Rebased on tmp.perf-tools-next
tools/perf/builtin-lock.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 258c4ccb96af..ea3a62ba95d4 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1468,8 +1468,13 @@ static void sort_result(void)
static const struct {
unsigned int flags;
- const char *str;
- const char *name;
+ /*
+ * Name of the lock flags (access), with delimeter ':'.
+ * For example, rwsem:R of rwsem:W.
+ */
+ const char *flags_name;
+ /* Name of the lock (type), for example, rwlock or rwsem. */
+ const char *lock_name;
} lock_type_table[] = {
{ 0, "semaphore", "semaphore" },
{ LCB_F_SPIN, "spinlock", "spinlock" },
@@ -1487,24 +1492,24 @@ static const struct {
{ LCB_F_MUTEX | LCB_F_SPIN, "mutex-spin", "mutex-spin" },
};
-static const char *get_type_str(unsigned int flags)
+static const char *get_type_flags_name(unsigned int flags)
{
flags &= LCB_F_TYPE_MASK;
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 lock_type_table[i].flags_name;
}
return "unknown";
}
-static const char *get_type_name(unsigned int flags)
+static const char *get_type_lock_name(unsigned int flags)
{
flags &= LCB_F_TYPE_MASK;
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;
+ return lock_type_table[i].lock_name;
}
return "unknown";
}
@@ -1617,7 +1622,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
switch (aggr_mode) {
case LOCK_AGGR_CALLER:
- fprintf(lock_output, " %10s %s\n", get_type_str(st->flags), st->name);
+ fprintf(lock_output, " %10s %s\n", get_type_flags_name(st->flags), st->name);
break;
case LOCK_AGGR_TASK:
pid = st->addr;
@@ -1627,7 +1632,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
break;
case LOCK_AGGR_ADDR:
fprintf(lock_output, " %016llx %s (%s)\n", (unsigned long long)st->addr,
- st->name, get_type_name(st->flags));
+ st->name, get_type_lock_name(st->flags));
break;
case LOCK_AGGR_CGROUP:
fprintf(lock_output, " %s\n", st->name);
@@ -1668,7 +1673,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
switch (aggr_mode) {
case LOCK_AGGR_CALLER:
- fprintf(lock_output, "%s%s %s", get_type_str(st->flags), sep, st->name);
+ fprintf(lock_output, "%s%s %s", get_type_flags_name(st->flags), sep, st->name);
if (verbose <= 0)
fprintf(lock_output, "\n");
break;
@@ -1680,7 +1685,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
break;
case LOCK_AGGR_ADDR:
fprintf(lock_output, "%llx%s %s%s %s\n", (unsigned long long)st->addr, sep,
- st->name, sep, get_type_name(st->flags));
+ st->name, sep, get_type_lock_name(st->flags));
break;
case LOCK_AGGR_CGROUP:
fprintf(lock_output, "%s\n",st->name);
@@ -2243,10 +2248,10 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
bool found = false;
- /* `tok` is `str` in `lock_type_table` if it contains ':'. */
+ /* `tok` is a flags name if it contains ':'. */
if (strchr(tok, ':')) {
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
- if (!strcmp(lock_type_table[i].str, tok) &&
+ if (!strcmp(lock_type_table[i].flags_name, tok) &&
add_lock_type(lock_type_table[i].flags)) {
found = true;
break;
@@ -2263,14 +2268,14 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
}
/*
- * Otherwise `tok` is `name` in `lock_type_table`.
+ * Otherwise `tok` is a lock name.
* Single lock name could contain multiple flags.
* Replace alias `pcpu-sem` with actual name `percpu-rwsem.
*/
if (!strcmp(tok, "pcpu-sem"))
tok = (char *)"percpu-rwsem";
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
- if (!strcmp(lock_type_table[i].name, tok)) {
+ if (!strcmp(lock_type_table[i].lock_name, tok)) {
if (add_lock_type(lock_type_table[i].flags)) {
found = true;
} else {
--
2.48.0.rc2.279.g1de40edade-goog
^ permalink raw reply [flat|nested] 4+ messages in thread