Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chun-Tse Shao and committed by
Namhyung Kim
ac22d753 e9188ae3

+19 -14
+19 -14
tools/perf/builtin-lock.c
··· 1468 1468 1469 1469 static const struct { 1470 1470 unsigned int flags; 1471 - const char *str; 1472 - const char *name; 1471 + /* 1472 + * Name of the lock flags (access), with delimeter ':'. 1473 + * For example, rwsem:R of rwsem:W. 1474 + */ 1475 + const char *flags_name; 1476 + /* Name of the lock (type), for example, rwlock or rwsem. */ 1477 + const char *lock_name; 1473 1478 } lock_type_table[] = { 1474 1479 { 0, "semaphore", "semaphore" }, 1475 1480 { LCB_F_SPIN, "spinlock", "spinlock" }, ··· 1493 1488 { LCB_F_MUTEX | LCB_F_SPIN, "mutex:spin", "mutex-spin" }, 1494 1489 }; 1495 1490 1496 - static const char *get_type_str(unsigned int flags) 1491 + static const char *get_type_flags_name(unsigned int flags) 1497 1492 { 1498 1493 flags &= LCB_F_TYPE_MASK; 1499 1494 1500 1495 for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { 1501 1496 if (lock_type_table[i].flags == flags) 1502 - return lock_type_table[i].str; 1497 + return lock_type_table[i].flags_name; 1503 1498 } 1504 1499 return "unknown"; 1505 1500 } 1506 1501 1507 - static const char *get_type_name(unsigned int flags) 1502 + static const char *get_type_lock_name(unsigned int flags) 1508 1503 { 1509 1504 flags &= LCB_F_TYPE_MASK; 1510 1505 1511 1506 for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { 1512 1507 if (lock_type_table[i].flags == flags) 1513 - return lock_type_table[i].name; 1508 + return lock_type_table[i].lock_name; 1514 1509 } 1515 1510 return "unknown"; 1516 1511 } ··· 1623 1618 1624 1619 switch (aggr_mode) { 1625 1620 case LOCK_AGGR_CALLER: 1626 - fprintf(lock_output, " %10s %s\n", get_type_str(st->flags), st->name); 1621 + fprintf(lock_output, " %10s %s\n", get_type_flags_name(st->flags), st->name); 1627 1622 break; 1628 1623 case LOCK_AGGR_TASK: 1629 1624 pid = st->addr; ··· 1633 1628 break; 1634 1629 case LOCK_AGGR_ADDR: 1635 1630 fprintf(lock_output, " %016llx %s (%s)\n", (unsigned long long)st->addr, 1636 - st->name, get_type_name(st->flags)); 1631 + st->name, get_type_lock_name(st->flags)); 1637 1632 break; 1638 1633 case LOCK_AGGR_CGROUP: 1639 1634 fprintf(lock_output, " %s\n", st->name); ··· 1674 1669 1675 1670 switch (aggr_mode) { 1676 1671 case LOCK_AGGR_CALLER: 1677 - fprintf(lock_output, "%s%s %s", get_type_str(st->flags), sep, st->name); 1672 + fprintf(lock_output, "%s%s %s", get_type_flags_name(st->flags), sep, st->name); 1678 1673 if (verbose <= 0) 1679 1674 fprintf(lock_output, "\n"); 1680 1675 break; ··· 1686 1681 break; 1687 1682 case LOCK_AGGR_ADDR: 1688 1683 fprintf(lock_output, "%llx%s %s%s %s\n", (unsigned long long)st->addr, sep, 1689 - st->name, sep, get_type_name(st->flags)); 1684 + st->name, sep, get_type_lock_name(st->flags)); 1690 1685 break; 1691 1686 case LOCK_AGGR_CGROUP: 1692 1687 fprintf(lock_output, "%s\n",st->name); ··· 2254 2249 for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) { 2255 2250 bool found = false; 2256 2251 2257 - /* `tok` is `str` in `lock_type_table` if it contains ':'. */ 2252 + /* `tok` is a flags name if it contains ':'. */ 2258 2253 if (strchr(tok, ':')) { 2259 2254 for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { 2260 - if (!strcmp(lock_type_table[i].str, tok) && 2255 + if (!strcmp(lock_type_table[i].flags_name, tok) && 2261 2256 add_lock_type(lock_type_table[i].flags)) { 2262 2257 found = true; 2263 2258 break; ··· 2274 2269 } 2275 2270 2276 2271 /* 2277 - * Otherwise `tok` is `name` in `lock_type_table`. 2272 + * Otherwise `tok` is a lock name. 2278 2273 * Single lock name could contain multiple flags. 2279 2274 * Replace alias `pcpu-sem` with actual name `percpu-rwsem. 2280 2275 */ 2281 2276 if (!strcmp(tok, "pcpu-sem")) 2282 2277 tok = (char *)"percpu-rwsem"; 2283 2278 for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) { 2284 - if (!strcmp(lock_type_table[i].name, tok)) { 2279 + if (!strcmp(lock_type_table[i].lock_name, tok)) { 2285 2280 if (add_lock_type(lock_type_table[i].flags)) { 2286 2281 found = true; 2287 2282 } else {