From: Namhyung Kim <namhyung@kernel.org>
To: Chun-Tse Shao <ctshao@google.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, nick.forrington@arm.com,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v5 3/3] perf lock: Rename fields in lock_type_table
Date: Wed, 11 Dec 2024 11:16:06 -0800 [thread overview]
Message-ID: <Z1nk9owKE_xHVh1i@google.com> (raw)
In-Reply-To: <20241210200847.1023139-3-ctshao@google.com>
On Tue, Dec 10, 2024 at 12:08:22PM -0800, Chun-Tse Shao wrote:
> `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.
>
> Signed-off-by: Chun-Tse Shao <ctshao@google.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
> ---
> 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 50630551adad..74085c8e32d3 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -1575,8 +1575,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" },
> @@ -1593,24 +1598,24 @@ static const struct {
> { LCB_F_MUTEX | LCB_F_SPIN, "mutex", "mutex" },
> };
>
> -static const char *get_type_str(unsigned int flags)
> +static const char *get_type_flags_name(unsigned int flags)
> {
> flags &= LCB_F_MAX_FLAGS - 1;
>
> 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_MAX_FLAGS - 1;
>
> 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";
> }
> @@ -1717,7 +1722,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;
> @@ -1727,7 +1732,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);
> @@ -1768,7 +1773,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;
> @@ -1780,7 +1785,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);
> @@ -2343,10 +2348,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;
> @@ -2363,14 +2368,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.47.1.545.g3c1d2e2a6a-goog
>
next prev parent reply other threads:[~2024-12-11 19:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 20:08 [PATCH v5 1/3] perf lock: Fix parse_lock_type which only retrieve one lock flag Chun-Tse Shao
2024-12-10 20:08 ` [PATCH v5 2/3] perf lock: Add percpu-rwsem for type filter Chun-Tse Shao
2024-12-11 19:15 ` Namhyung Kim
2024-12-12 19:00 ` Arnaldo Carvalho de Melo
2024-12-12 20:58 ` Namhyung Kim
2024-12-10 20:08 ` [PATCH v5 3/3] perf lock: Rename fields in lock_type_table Chun-Tse Shao
2024-12-11 19:16 ` Namhyung Kim [this message]
2025-01-16 19:08 ` Namhyung Kim
2024-12-11 19:15 ` [PATCH v5 1/3] perf lock: Fix parse_lock_type which only retrieve one lock flag Namhyung Kim
2025-01-16 23:41 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z1nk9owKE_xHVh1i@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ctshao@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=nick.forrington@arm.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox