linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] perf lock: Rename fields in lock_type_table
@ 2024-11-26 21:22 Chun-Tse Shao
  2024-11-26 21:22 ` [PATCH v3 2/2] perf lock: Fix parse_lock_type which only retrieve one lock flag Chun-Tse Shao
  0 siblings, 1 reply; 4+ messages in thread
From: Chun-Tse Shao @ 2024-11-26 21:22 UTC (permalink / raw)
  To: linux-kernel
  Cc: Chun-Tse Shao, peterz, mingo, acme, namhyung, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
	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.

Signed-off-by: Chun-Tse Shao <ctshao@google.com>
---
 tools/perf/builtin-lock.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 062e2b56a2ab..c528aff1c9d5 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" },
@@ -1595,24 +1600,24 @@ static const struct {
 	{ LCB_F_MUTEX | LCB_F_SPIN,	"mutex-spin",	"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";
 }
@@ -1620,11 +1625,11 @@ static const char *get_type_name(unsigned int flags)
 static unsigned int get_type_flag(const char *str)
 {
 	for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
-		if (!strcmp(lock_type_table[i].name, str))
+		if (!strcmp(lock_type_table[i].flags_name, str))
 			return lock_type_table[i].flags;
 	}
 	for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
-		if (!strcmp(lock_type_table[i].str, str))
+		if (!strcmp(lock_type_table[i].lock_name, str))
 			return lock_type_table[i].flags;
 	}
 	return UINT_MAX;
@@ -1732,7 +1737,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;
@@ -1742,7 +1747,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);
@@ -1783,7 +1788,8 @@ 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;
@@ -1795,7 +1801,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);
-- 
2.47.0.338.g60cca15819-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] perf lock: Fix parse_lock_type which only retrieve one lock flag
  2024-11-26 21:22 [PATCH v3 1/2] perf lock: Rename fields in lock_type_table Chun-Tse Shao
@ 2024-11-26 21:22 ` Chun-Tse Shao
  2024-12-02 20:49   ` Namhyung Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Chun-Tse Shao @ 2024-11-26 21:22 UTC (permalink / raw)
  To: linux-kernel
  Cc: Chun-Tse Shao, peterz, mingo, acme, namhyung, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
	linux-perf-users

`parse_lock_type` can only add the first lock flag in `lock_type_table`
given input `str`. For example, for `Y rwlock`, it only adds `rwlock:R`
into this perf session. Another example is for `-Y mutex`, it only adds
the mutex without `LCB_F_SPIN` flag. The patch fixes this issue, makes
sure both `rwlock:R` and `rwlock:W` will be added with `-Y rwlock`, and
so on.

Testing:
  $ ./perf lock con -ab -Y mutex,rwlock -- perf bench sched pipe
  # Running 'sched/pipe' benchmark:
  # Executed 1000000 pipe operations between two processes

       Total time: 8.425 [sec]

         8.425402 usecs/op
           118688 ops/sec
   contended   total wait     max wait     avg wait         type   caller

         194      1.68 ms     44.16 us      8.66 us        mutex   pipe_read+0x57
          10    423.03 us     44.27 us     42.30 us     rwlock:W   do_exit+0x365
          54    254.67 us     58.87 us      4.72 us        mutex   pipe_write+0x50
          21    146.64 us     11.54 us      6.98 us        mutex   pipe_read+0x282
          10    141.27 us     20.62 us     14.13 us     rwlock:W   release_task+0x6f
           5     58.92 us     16.37 us     11.78 us        mutex   do_epoll_wait+0x24d
           3     29.81 us     17.66 us      9.94 us        mutex   do_epoll_ctl+0x6c1
           4     26.82 us     11.02 us      6.70 us        mutex   do_epoll_wait+0x24d
           2     18.32 us     12.49 us      9.16 us     rwlock:W   do_epoll_wait+0x255
           1     11.34 us     11.34 us     11.34 us     rwlock:W   ep_done_scan+0x2d
           1     11.02 us     11.02 us     11.02 us     rwlock:R   mm_update_next_owner+0x4e
           1     10.60 us     10.60 us     10.60 us     rwlock:W   do_epoll_ctl+0xb65
           1      9.90 us      9.90 us      9.90 us     rwlock:W   do_exit+0x365

Fixes: d783ea8f62c4 ("perf lock contention: Simplify parse_lock_type()")
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
---
 tools/perf/builtin-lock.c | 68 ++++++++++++++++++++++++++-------------
 1 file changed, 45 insertions(+), 23 deletions(-)

diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index c528aff1c9d5..c1870c287580 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1622,19 +1622,6 @@ static const char *get_type_lock_name(unsigned int flags)
 	return "unknown";
 }
 
-static unsigned int get_type_flag(const char *str)
-{
-	for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
-		if (!strcmp(lock_type_table[i].flags_name, str))
-			return lock_type_table[i].flags;
-	}
-	for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
-		if (!strcmp(lock_type_table[i].lock_name, str))
-			return lock_type_table[i].flags;
-	}
-	return UINT_MAX;
-}
-
 static void lock_filter_finish(void)
 {
 	zfree(&filters.types);
@@ -2356,29 +2343,64 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
 			   int unset __maybe_unused)
 {
 	char *s, *tmp, *tok;
-	int ret = 0;
 
 	s = strdup(str);
 	if (s == NULL)
 		return -1;
 
 	for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
-		unsigned int flags = get_type_flag(tok);
+		bool found = false;
 
-		if (flags == -1U) {
-			pr_err("Unknown lock flags: %s\n", tok);
-			ret = -1;
-			break;
+		/* `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].flags_name, tok) &&
+				    add_lock_type(lock_type_table[i].flags)) {
+					found = true;
+					break;
+				}
+			}
+
+			if (!found) {
+				pr_err("Unknown lock flags name: %s\n", tok);
+				free(s);
+				return -1;
+			}
+
+			continue;
 		}
 
-		if (!add_lock_type(flags)) {
-			ret = -1;
-			break;
+		/*
+		 * Otherwise `tok` is a lock name.
+		 * Single lock name could contain multiple flags.
+		 */
+		/*
+		 * By documentation, `percpu-rwmem` should be `pcpu-sem`.
+		 * For backward compatibility, we replace `pcpu-sem` with `percpu-rwmem`.
+		 */
+		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].lock_name, tok)) {
+				if (add_lock_type(lock_type_table[i].flags)) {
+					found = true;
+				} else {
+					free(s);
+					return -1;
+				}
+			}
+		}
+
+		if (!found) {
+			pr_err("Unknown lock name: %s\n", tok);
+			free(s);
+			return -1;
 		}
 	}
 
 	free(s);
-	return ret;
+	return 0;
 }
 
 static bool add_lock_addr(unsigned long addr)
-- 
2.47.0.338.g60cca15819-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/2] perf lock: Fix parse_lock_type which only retrieve one lock flag
  2024-11-26 21:22 ` [PATCH v3 2/2] perf lock: Fix parse_lock_type which only retrieve one lock flag Chun-Tse Shao
@ 2024-12-02 20:49   ` Namhyung Kim
  2024-12-09 20:03     ` Chun-Tse Shao
  0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2024-12-02 20:49 UTC (permalink / raw)
  To: Chun-Tse Shao
  Cc: linux-kernel, peterz, mingo, acme, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
	linux-perf-users

Hello,

On Tue, Nov 26, 2024 at 01:22:54PM -0800, Chun-Tse Shao wrote:
> `parse_lock_type` can only add the first lock flag in `lock_type_table`
> given input `str`. For example, for `Y rwlock`, it only adds `rwlock:R`
> into this perf session. Another example is for `-Y mutex`, it only adds
> the mutex without `LCB_F_SPIN` flag. The patch fixes this issue, makes
> sure both `rwlock:R` and `rwlock:W` will be added with `-Y rwlock`, and
> so on.
> 
> Testing:
>   $ ./perf lock con -ab -Y mutex,rwlock -- perf bench sched pipe
>   # Running 'sched/pipe' benchmark:
>   # Executed 1000000 pipe operations between two processes
> 
>        Total time: 8.425 [sec]
> 
>          8.425402 usecs/op
>            118688 ops/sec
>    contended   total wait     max wait     avg wait         type   caller
> 
>          194      1.68 ms     44.16 us      8.66 us        mutex   pipe_read+0x57
>           10    423.03 us     44.27 us     42.30 us     rwlock:W   do_exit+0x365
>           54    254.67 us     58.87 us      4.72 us        mutex   pipe_write+0x50
>           21    146.64 us     11.54 us      6.98 us        mutex   pipe_read+0x282
>           10    141.27 us     20.62 us     14.13 us     rwlock:W   release_task+0x6f
>            5     58.92 us     16.37 us     11.78 us        mutex   do_epoll_wait+0x24d
>            3     29.81 us     17.66 us      9.94 us        mutex   do_epoll_ctl+0x6c1
>            4     26.82 us     11.02 us      6.70 us        mutex   do_epoll_wait+0x24d
>            2     18.32 us     12.49 us      9.16 us     rwlock:W   do_epoll_wait+0x255
>            1     11.34 us     11.34 us     11.34 us     rwlock:W   ep_done_scan+0x2d
>            1     11.02 us     11.02 us     11.02 us     rwlock:R   mm_update_next_owner+0x4e
>            1     10.60 us     10.60 us     10.60 us     rwlock:W   do_epoll_ctl+0xb65
>            1      9.90 us      9.90 us      9.90 us     rwlock:W   do_exit+0x365
> 
> Fixes: d783ea8f62c4 ("perf lock contention: Simplify parse_lock_type()")

I think it won't apply to earlier kernels because you changed the field
names in the previous commit.  I think you can switch the order of the
commits so that we can have the fix first.


> Signed-off-by: Chun-Tse Shao <ctshao@google.com>
> ---
>  tools/perf/builtin-lock.c | 68 ++++++++++++++++++++++++++-------------
>  1 file changed, 45 insertions(+), 23 deletions(-)
> 
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index c528aff1c9d5..c1870c287580 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -1622,19 +1622,6 @@ static const char *get_type_lock_name(unsigned int flags)
>  	return "unknown";
>  }
>  
> -static unsigned int get_type_flag(const char *str)
> -{
> -	for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
> -		if (!strcmp(lock_type_table[i].flags_name, str))
> -			return lock_type_table[i].flags;
> -	}
> -	for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
> -		if (!strcmp(lock_type_table[i].lock_name, str))
> -			return lock_type_table[i].flags;
> -	}
> -	return UINT_MAX;
> -}
> -
>  static void lock_filter_finish(void)
>  {
>  	zfree(&filters.types);
> @@ -2356,29 +2343,64 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
>  			   int unset __maybe_unused)
>  {
>  	char *s, *tmp, *tok;
> -	int ret = 0;
>  
>  	s = strdup(str);
>  	if (s == NULL)
>  		return -1;
>  
>  	for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
> -		unsigned int flags = get_type_flag(tok);
> +		bool found = false;
>  
> -		if (flags == -1U) {
> -			pr_err("Unknown lock flags: %s\n", tok);
> -			ret = -1;
> -			break;
> +		/* `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].flags_name, tok) &&
> +				    add_lock_type(lock_type_table[i].flags)) {
> +					found = true;
> +					break;
> +				}
> +			}
> +
> +			if (!found) {
> +				pr_err("Unknown lock flags name: %s\n", tok);
> +				free(s);
> +				return -1;
> +			}
> +
> +			continue;
>  		}
>  
> -		if (!add_lock_type(flags)) {
> -			ret = -1;
> -			break;
> +		/*
> +		 * Otherwise `tok` is a lock name.
> +		 * Single lock name could contain multiple flags.
> +		 */
> +		/*
> +		 * By documentation, `percpu-rwmem` should be `pcpu-sem`.
> +		 * For backward compatibility, we replace `pcpu-sem` with `percpu-rwmem`.
> +		 */
> +		if (!strcmp(tok, "pcpu-sem"))
> +			tok = (char *)"percpu-rwsem";

I think it's better to split the pcpu-sem part into a separate commit as
it fixes a different issue.  Also you'd better merge the block commits.

Thanks,
Namhyung


> +
> +		for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
> +			if (!strcmp(lock_type_table[i].lock_name, tok)) {
> +				if (add_lock_type(lock_type_table[i].flags)) {
> +					found = true;
> +				} else {
> +					free(s);
> +					return -1;
> +				}
> +			}
> +		}
> +
> +		if (!found) {
> +			pr_err("Unknown lock name: %s\n", tok);
> +			free(s);
> +			return -1;
>  		}
>  	}
>  
>  	free(s);
> -	return ret;
> +	return 0;
>  }
>  
>  static bool add_lock_addr(unsigned long addr)
> -- 
> 2.47.0.338.g60cca15819-goog
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/2] perf lock: Fix parse_lock_type which only retrieve one lock flag
  2024-12-02 20:49   ` Namhyung Kim
@ 2024-12-09 20:03     ` Chun-Tse Shao
  0 siblings, 0 replies; 4+ messages in thread
From: Chun-Tse Shao @ 2024-12-09 20:03 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: linux-kernel, peterz, mingo, acme, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
	linux-perf-users

Thank you Namhyung, please check my v4 patches here:
https://lore.kernel.org/linux-perf-users/20241209200104.870531-1-ctshao@google.com/T/#t

On Mon, Dec 2, 2024 at 12:49 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hello,
>
> On Tue, Nov 26, 2024 at 01:22:54PM -0800, Chun-Tse Shao wrote:
> > `parse_lock_type` can only add the first lock flag in `lock_type_table`
> > given input `str`. For example, for `Y rwlock`, it only adds `rwlock:R`
> > into this perf session. Another example is for `-Y mutex`, it only adds
> > the mutex without `LCB_F_SPIN` flag. The patch fixes this issue, makes
> > sure both `rwlock:R` and `rwlock:W` will be added with `-Y rwlock`, and
> > so on.
> >
> > Testing:
> >   $ ./perf lock con -ab -Y mutex,rwlock -- perf bench sched pipe
> >   # Running 'sched/pipe' benchmark:
> >   # Executed 1000000 pipe operations between two processes
> >
> >        Total time: 8.425 [sec]
> >
> >          8.425402 usecs/op
> >            118688 ops/sec
> >    contended   total wait     max wait     avg wait         type   caller
> >
> >          194      1.68 ms     44.16 us      8.66 us        mutex   pipe_read+0x57
> >           10    423.03 us     44.27 us     42.30 us     rwlock:W   do_exit+0x365
> >           54    254.67 us     58.87 us      4.72 us        mutex   pipe_write+0x50
> >           21    146.64 us     11.54 us      6.98 us        mutex   pipe_read+0x282
> >           10    141.27 us     20.62 us     14.13 us     rwlock:W   release_task+0x6f
> >            5     58.92 us     16.37 us     11.78 us        mutex   do_epoll_wait+0x24d
> >            3     29.81 us     17.66 us      9.94 us        mutex   do_epoll_ctl+0x6c1
> >            4     26.82 us     11.02 us      6.70 us        mutex   do_epoll_wait+0x24d
> >            2     18.32 us     12.49 us      9.16 us     rwlock:W   do_epoll_wait+0x255
> >            1     11.34 us     11.34 us     11.34 us     rwlock:W   ep_done_scan+0x2d
> >            1     11.02 us     11.02 us     11.02 us     rwlock:R   mm_update_next_owner+0x4e
> >            1     10.60 us     10.60 us     10.60 us     rwlock:W   do_epoll_ctl+0xb65
> >            1      9.90 us      9.90 us      9.90 us     rwlock:W   do_exit+0x365
> >
> > Fixes: d783ea8f62c4 ("perf lock contention: Simplify parse_lock_type()")
>
> I think it won't apply to earlier kernels because you changed the field
> names in the previous commit.  I think you can switch the order of the
> commits so that we can have the fix first.
>
>
> > Signed-off-by: Chun-Tse Shao <ctshao@google.com>
> > ---
> >  tools/perf/builtin-lock.c | 68 ++++++++++++++++++++++++++-------------
> >  1 file changed, 45 insertions(+), 23 deletions(-)
> >
> > diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> > index c528aff1c9d5..c1870c287580 100644
> > --- a/tools/perf/builtin-lock.c
> > +++ b/tools/perf/builtin-lock.c
> > @@ -1622,19 +1622,6 @@ static const char *get_type_lock_name(unsigned int flags)
> >       return "unknown";
> >  }
> >
> > -static unsigned int get_type_flag(const char *str)
> > -{
> > -     for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
> > -             if (!strcmp(lock_type_table[i].flags_name, str))
> > -                     return lock_type_table[i].flags;
> > -     }
> > -     for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
> > -             if (!strcmp(lock_type_table[i].lock_name, str))
> > -                     return lock_type_table[i].flags;
> > -     }
> > -     return UINT_MAX;
> > -}
> > -
> >  static void lock_filter_finish(void)
> >  {
> >       zfree(&filters.types);
> > @@ -2356,29 +2343,64 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
> >                          int unset __maybe_unused)
> >  {
> >       char *s, *tmp, *tok;
> > -     int ret = 0;
> >
> >       s = strdup(str);
> >       if (s == NULL)
> >               return -1;
> >
> >       for (tok = strtok_r(s, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
> > -             unsigned int flags = get_type_flag(tok);
> > +             bool found = false;
> >
> > -             if (flags == -1U) {
> > -                     pr_err("Unknown lock flags: %s\n", tok);
> > -                     ret = -1;
> > -                     break;
> > +             /* `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].flags_name, tok) &&
> > +                                 add_lock_type(lock_type_table[i].flags)) {
> > +                                     found = true;
> > +                                     break;
> > +                             }
> > +                     }
> > +
> > +                     if (!found) {
> > +                             pr_err("Unknown lock flags name: %s\n", tok);
> > +                             free(s);
> > +                             return -1;
> > +                     }
> > +
> > +                     continue;
> >               }
> >
> > -             if (!add_lock_type(flags)) {
> > -                     ret = -1;
> > -                     break;
> > +             /*
> > +              * Otherwise `tok` is a lock name.
> > +              * Single lock name could contain multiple flags.
> > +              */
> > +             /*
> > +              * By documentation, `percpu-rwmem` should be `pcpu-sem`.
> > +              * For backward compatibility, we replace `pcpu-sem` with `percpu-rwmem`.
> > +              */
> > +             if (!strcmp(tok, "pcpu-sem"))
> > +                     tok = (char *)"percpu-rwsem";
>
> I think it's better to split the pcpu-sem part into a separate commit as
> it fixes a different issue.  Also you'd better merge the block commits.
>
> Thanks,
> Namhyung
>
>
> > +
> > +             for (unsigned int i = 0; i < ARRAY_SIZE(lock_type_table); i++) {
> > +                     if (!strcmp(lock_type_table[i].lock_name, tok)) {
> > +                             if (add_lock_type(lock_type_table[i].flags)) {
> > +                                     found = true;
> > +                             } else {
> > +                                     free(s);
> > +                                     return -1;
> > +                             }
> > +                     }
> > +             }
> > +
> > +             if (!found) {
> > +                     pr_err("Unknown lock name: %s\n", tok);
> > +                     free(s);
> > +                     return -1;
> >               }
> >       }
> >
> >       free(s);
> > -     return ret;
> > +     return 0;
> >  }
> >
> >  static bool add_lock_addr(unsigned long addr)
> > --
> > 2.47.0.338.g60cca15819-goog
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-09 20:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-26 21:22 [PATCH v3 1/2] perf lock: Rename fields in lock_type_table Chun-Tse Shao
2024-11-26 21:22 ` [PATCH v3 2/2] perf lock: Fix parse_lock_type which only retrieve one lock flag Chun-Tse Shao
2024-12-02 20:49   ` Namhyung Kim
2024-12-09 20:03     ` Chun-Tse Shao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).