perf lock: Rename fields in lock_type_table

`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>
Cc: nick.forrington@arm.com
Link: https://lore.kernel.org/r/20250116235838.2769691-3-ctshao@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Chun-Tse Shao 2025-01-16 15:58:16 -08:00 committed by Namhyung Kim
parent e9188ae3cd
commit ac22d75377

View File

@ -1468,8 +1468,13 @@ static void sort_result(void)
static const struct { static const struct {
unsigned int flags; 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[] = { } lock_type_table[] = {
{ 0, "semaphore", "semaphore" }, { 0, "semaphore", "semaphore" },
{ LCB_F_SPIN, "spinlock", "spinlock" }, { LCB_F_SPIN, "spinlock", "spinlock" },
@ -1488,24 +1493,24 @@ static const struct {
{ LCB_F_MUTEX | LCB_F_SPIN, "mutex:spin", "mutex-spin" }, { 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; flags &= LCB_F_TYPE_MASK;
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
if (lock_type_table[i].flags == flags) if (lock_type_table[i].flags == flags)
return lock_type_table[i].str; return lock_type_table[i].flags_name;
} }
return "unknown"; 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; flags &= LCB_F_TYPE_MASK;
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
if (lock_type_table[i].flags == flags) if (lock_type_table[i].flags == flags)
return lock_type_table[i].name; return lock_type_table[i].lock_name;
} }
return "unknown"; return "unknown";
} }
@ -1618,7 +1623,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
switch (aggr_mode) { switch (aggr_mode) {
case LOCK_AGGR_CALLER: 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; break;
case LOCK_AGGR_TASK: case LOCK_AGGR_TASK:
pid = st->addr; pid = st->addr;
@ -1628,7 +1633,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
break; break;
case LOCK_AGGR_ADDR: case LOCK_AGGR_ADDR:
fprintf(lock_output, " %016llx %s (%s)\n", (unsigned long long)st->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; break;
case LOCK_AGGR_CGROUP: case LOCK_AGGR_CGROUP:
fprintf(lock_output, " %s\n", st->name); fprintf(lock_output, " %s\n", st->name);
@ -1669,7 +1674,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
switch (aggr_mode) { switch (aggr_mode) {
case LOCK_AGGR_CALLER: 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) if (verbose <= 0)
fprintf(lock_output, "\n"); fprintf(lock_output, "\n");
break; break;
@ -1681,7 +1686,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
break; break;
case LOCK_AGGR_ADDR: case LOCK_AGGR_ADDR:
fprintf(lock_output, "%llx%s %s%s %s\n", (unsigned long long)st->addr, sep, 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; break;
case LOCK_AGGR_CGROUP: case LOCK_AGGR_CGROUP:
fprintf(lock_output, "%s\n",st->name); fprintf(lock_output, "%s\n",st->name);
@ -2249,10 +2254,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)) { for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
bool found = false; bool found = false;
/* `tok` is `str` in `lock_type_table` if it contains ':'. */ /* `tok` is a flags name if it contains ':'. */
if (strchr(tok, ':')) { if (strchr(tok, ':')) {
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { 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)) { add_lock_type(lock_type_table[i].flags)) {
found = true; found = true;
break; break;
@ -2269,14 +2274,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. * Single lock name could contain multiple flags.
* Replace alias `pcpu-sem` with actual name `percpu-rwsem. * Replace alias `pcpu-sem` with actual name `percpu-rwsem.
*/ */
if (!strcmp(tok, "pcpu-sem")) if (!strcmp(tok, "pcpu-sem"))
tok = (char *)"percpu-rwsem"; tok = (char *)"percpu-rwsem";
for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { 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)) { if (add_lock_type(lock_type_table[i].flags)) {
found = true; found = true;
} else { } else {