linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] perf lock: Add -E/--entries option
@ 2022-09-24  0:42 Namhyung Kim
  2022-09-24  0:42 ` [PATCH 2/3] perf lock: Add -q/--quiet option Namhyung Kim
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Namhyung Kim @ 2022-09-24  0:42 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users

Like perf top, the -E option can limit number of entries to print.
It can be useful when users want to see top N contended locks only.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/Documentation/perf-lock.txt | 10 ++++++++++
 tools/perf/builtin-lock.c              | 20 +++++++++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
index 5f2dc634258e..b23e76200ac2 100644
--- a/tools/perf/Documentation/perf-lock.txt
+++ b/tools/perf/Documentation/perf-lock.txt
@@ -94,6 +94,11 @@ REPORT OPTIONS
          EventManager_De       1845          1             636
          futex-default-S       1609          0               0
 
+-E::
+--entries=<value>::
+	Display this many entries.
+
+
 INFO OPTIONS
 ------------
 
@@ -105,6 +110,7 @@ INFO OPTIONS
 --map::
 	dump map of lock instances (address:name table)
 
+
 CONTENTION OPTIONS
 --------------
 
@@ -154,6 +160,10 @@ CONTENTION OPTIONS
 --stack-skip
 	Number of stack depth to skip when finding a lock caller (default: 3).
 
+-E::
+--entries=<value>::
+	Display this many entries.
+
 
 SEE ALSO
 --------
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 25d75fa09b90..1c0d52384d9e 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -58,6 +58,7 @@ static bool use_bpf;
 static unsigned long bpf_map_entries = 10240;
 static int max_stack_depth = CONTENTION_STACK_DEPTH;
 static int stack_skip = CONTENTION_STACK_SKIP;
+static int print_nr_entries = INT_MAX / 2;
 
 static enum {
 	LOCK_AGGR_ADDR,
@@ -1266,14 +1267,14 @@ static void print_result(void)
 	struct lock_stat *st;
 	struct lock_key *key;
 	char cut_name[20];
-	int bad, total;
+	int bad, total, printed;
 
 	pr_info("%20s ", "Name");
 	list_for_each_entry(key, &lock_keys, list)
 		pr_info("%*s ", key->len, key->header);
 	pr_info("\n\n");
 
-	bad = total = 0;
+	bad = total = printed = 0;
 	while ((st = pop_from_result())) {
 		total++;
 		if (st->broken)
@@ -1311,6 +1312,9 @@ static void print_result(void)
 			pr_info(" ");
 		}
 		pr_info("\n");
+
+		if (++printed >= print_nr_entries)
+			break;
 	}
 
 	print_bad_events(bad, total);
@@ -1476,7 +1480,7 @@ static void print_contention_result(struct lock_contention *con)
 {
 	struct lock_stat *st;
 	struct lock_key *key;
-	int bad, total;
+	int bad, total, printed;
 
 	list_for_each_entry(key, &lock_keys, list)
 		pr_info("%*s ", key->len, key->header);
@@ -1486,7 +1490,7 @@ static void print_contention_result(struct lock_contention *con)
 	else
 		pr_info("  %10s   %s\n\n", "type", "caller");
 
-	bad = total = 0;
+	bad = total = printed = 0;
 	if (use_bpf)
 		bad = bad_hist[BROKEN_CONTENDED];
 
@@ -1507,7 +1511,7 @@ static void print_contention_result(struct lock_contention *con)
 			/* st->addr contains tid of thread */
 			t = perf_session__findnew(session, pid);
 			pr_info("  %10d   %s\n", pid, thread__comm_str(t));
-			continue;
+			goto next;
 		}
 
 		pr_info("  %10s   %s\n", get_type_str(st), st->name);
@@ -1527,6 +1531,10 @@ static void print_contention_result(struct lock_contention *con)
 				pr_info("\t\t\t%#lx  %s\n", (unsigned long)ip, buf);
 			}
 		}
+
+next:
+		if (++printed >= print_nr_entries)
+			break;
 	}
 
 	print_bad_events(bad, total);
@@ -1878,6 +1886,7 @@ int cmd_lock(int argc, const char **argv)
 		    "combine locks in the same class"),
 	OPT_BOOLEAN('t', "threads", &show_thread_stats,
 		    "show per-thread lock stats"),
+	OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
 	OPT_PARENT(lock_options)
 	};
 
@@ -1905,6 +1914,7 @@ int cmd_lock(int argc, const char **argv)
 	OPT_INTEGER(0, "stack-skip", &stack_skip,
 		    "Set the number of stack depth to skip when finding a lock caller, "
 		    "Default: " __stringify(CONTENTION_STACK_SKIP)),
+	OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
 	OPT_PARENT(lock_options)
 	};
 
-- 
2.37.3.998.g577e59143f-goog


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

* [PATCH 2/3] perf lock: Add -q/--quiet option
  2022-09-24  0:42 [PATCH 1/3] perf lock: Add -E/--entries option Namhyung Kim
@ 2022-09-24  0:42 ` Namhyung Kim
  2022-09-24  2:49   ` Ian Rogers
  2022-09-24  0:42 ` [PATCH 3/3] perf test: Add kernel lock contention test Namhyung Kim
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Namhyung Kim @ 2022-09-24  0:42 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users

Like perf report, this option is to suppress header and debug messages.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/Documentation/perf-lock.txt |  4 ++++
 tools/perf/builtin-lock.c              | 27 +++++++++++++++-----------
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
index b23e76200ac2..3b1e16563b79 100644
--- a/tools/perf/Documentation/perf-lock.txt
+++ b/tools/perf/Documentation/perf-lock.txt
@@ -40,6 +40,10 @@ COMMON OPTIONS
 --verbose::
         Be more verbose (show symbol address, etc).
 
+-q::
+--quiet::
+	Do not show any message. (Suppress -v)
+
 -D::
 --dump-raw-trace::
         Dump raw trace in ASCII.
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index 1c0d52384d9e..9722d4ab2e55 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1250,7 +1250,7 @@ static void print_bad_events(int bad, int total)
 	for (i = 0; i < BROKEN_MAX; i++)
 		broken += bad_hist[i];
 
-	if (broken == 0 && !verbose)
+	if (quiet || (broken == 0 && !verbose))
 		return;
 
 	pr_info("\n=== output for debug===\n\n");
@@ -1269,10 +1269,12 @@ static void print_result(void)
 	char cut_name[20];
 	int bad, total, printed;
 
-	pr_info("%20s ", "Name");
-	list_for_each_entry(key, &lock_keys, list)
-		pr_info("%*s ", key->len, key->header);
-	pr_info("\n\n");
+	if (!quiet) {
+		pr_info("%20s ", "Name");
+		list_for_each_entry(key, &lock_keys, list)
+			pr_info("%*s ", key->len, key->header);
+		pr_info("\n\n");
+	}
 
 	bad = total = printed = 0;
 	while ((st = pop_from_result())) {
@@ -1482,13 +1484,15 @@ static void print_contention_result(struct lock_contention *con)
 	struct lock_key *key;
 	int bad, total, printed;
 
-	list_for_each_entry(key, &lock_keys, list)
-		pr_info("%*s ", key->len, key->header);
+	if (!quiet) {
+		list_for_each_entry(key, &lock_keys, list)
+			pr_info("%*s ", key->len, key->header);
 
-	if (show_thread_stats)
-		pr_info("  %10s   %s\n\n", "pid", "comm");
-	else
-		pr_info("  %10s   %s\n\n", "type", "caller");
+		if (show_thread_stats)
+			pr_info("  %10s   %s\n\n", "pid", "comm");
+		else
+			pr_info("  %10s   %s\n\n", "type", "caller");
+	}
 
 	bad = total = printed = 0;
 	if (use_bpf)
@@ -1865,6 +1869,7 @@ int cmd_lock(int argc, const char **argv)
 		   "file", "vmlinux pathname"),
 	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
 		   "file", "kallsyms pathname"),
+	OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
 	OPT_END()
 	};
 
-- 
2.37.3.998.g577e59143f-goog


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

* [PATCH 3/3] perf test: Add kernel lock contention test
  2022-09-24  0:42 [PATCH 1/3] perf lock: Add -E/--entries option Namhyung Kim
  2022-09-24  0:42 ` [PATCH 2/3] perf lock: Add -q/--quiet option Namhyung Kim
@ 2022-09-24  0:42 ` Namhyung Kim
  2022-09-24  2:50   ` Ian Rogers
  2022-09-24  8:09   ` Adrian Hunter
  2022-09-24  2:49 ` [PATCH 1/3] perf lock: Add -E/--entries option Ian Rogers
  2022-09-26 19:45 ` Arnaldo Carvalho de Melo
  3 siblings, 2 replies; 9+ messages in thread
From: Namhyung Kim @ 2022-09-24  0:42 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, Adrian Hunter,
	linux-perf-users

Add a new shell test to check if both normal perf lock record +
contention and BPF (with -b) option are working.  Use perf bench
sched messaging as a workload since it'd create some contention for
sending and receiving messages.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/lock_contention.sh | 73 +++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100755 tools/perf/tests/shell/lock_contention.sh

diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
new file mode 100755
index 000000000000..04bf604e3c6f
--- /dev/null
+++ b/tools/perf/tests/shell/lock_contention.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+# kernel lock contention analysis test
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+result=$(mktemp /tmp/__perf_test.result.XXXXX)
+
+cleanup() {
+	rm -f ${perfdata}
+	rm -f ${result}
+	trap - exit term int
+}
+
+trap_cleanup() {
+	cleanup
+	exit ${err}
+}
+trap trap_cleanup exit term int
+
+check() {
+	if [ `id -u` != 0 ]; then
+		echo "[Skip] No root permission"
+		err=2
+		exit
+	fi
+
+	if ! perf list | grep -q lock:contention_begin; then
+		echo "[Skip] No lock contention tracepoints"
+		err=2
+		exit
+	fi
+}
+
+test_record()
+{
+	echo "Testing perf lock record and perf lock contention"
+	perf lock record -o ${perfdata} -- perf bench sched messaging > /dev/null 2>&1
+	# the output goes to the stderr and we expect only 1 output (-E 1)
+	perf lock contention -i ${perfdata} -E 1 -q 2> ${result}
+	if [ $(cat "${result}" | wc -l) != "1" ]; then
+		echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
+		err=1
+		exit
+	fi
+}
+
+test_bpf()
+{
+	echo "Testing perf lock contention --use-bpf"
+
+	if ! perf lock con -b true > /dev/null 2>&1 ; then
+		echo "[Skip] No BPF support"
+		exit
+	fi
+
+	# the perf lock contention output goes to the stderr
+	perf lock con -a -b -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
+	if [ $(cat "${result}" | wc -l) != "1" ]; then
+		echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
+		err=1
+		exit
+	fi
+}
+
+check
+
+test_record
+test_bpf
+
+exit ${err}
-- 
2.37.3.998.g577e59143f-goog


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

* Re: [PATCH 1/3] perf lock: Add -E/--entries option
  2022-09-24  0:42 [PATCH 1/3] perf lock: Add -E/--entries option Namhyung Kim
  2022-09-24  0:42 ` [PATCH 2/3] perf lock: Add -q/--quiet option Namhyung Kim
  2022-09-24  0:42 ` [PATCH 3/3] perf test: Add kernel lock contention test Namhyung Kim
@ 2022-09-24  2:49 ` Ian Rogers
  2022-09-26 19:45 ` Arnaldo Carvalho de Melo
  3 siblings, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2022-09-24  2:49 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Adrian Hunter, linux-perf-users

On Fri, Sep 23, 2022 at 5:42 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Like perf top, the -E option can limit number of entries to print.
> It can be useful when users want to see top N contended locks only.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/Documentation/perf-lock.txt | 10 ++++++++++
>  tools/perf/builtin-lock.c              | 20 +++++++++++++++-----
>  2 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
> index 5f2dc634258e..b23e76200ac2 100644
> --- a/tools/perf/Documentation/perf-lock.txt
> +++ b/tools/perf/Documentation/perf-lock.txt
> @@ -94,6 +94,11 @@ REPORT OPTIONS
>           EventManager_De       1845          1             636
>           futex-default-S       1609          0               0
>
> +-E::
> +--entries=<value>::
> +       Display this many entries.
> +
> +
>  INFO OPTIONS
>  ------------
>
> @@ -105,6 +110,7 @@ INFO OPTIONS
>  --map::
>         dump map of lock instances (address:name table)
>
> +
>  CONTENTION OPTIONS
>  --------------
>
> @@ -154,6 +160,10 @@ CONTENTION OPTIONS
>  --stack-skip
>         Number of stack depth to skip when finding a lock caller (default: 3).
>
> +-E::
> +--entries=<value>::
> +       Display this many entries.
> +
>
>  SEE ALSO
>  --------
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index 25d75fa09b90..1c0d52384d9e 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -58,6 +58,7 @@ static bool use_bpf;
>  static unsigned long bpf_map_entries = 10240;
>  static int max_stack_depth = CONTENTION_STACK_DEPTH;
>  static int stack_skip = CONTENTION_STACK_SKIP;
> +static int print_nr_entries = INT_MAX / 2;
>
>  static enum {
>         LOCK_AGGR_ADDR,
> @@ -1266,14 +1267,14 @@ static void print_result(void)
>         struct lock_stat *st;
>         struct lock_key *key;
>         char cut_name[20];
> -       int bad, total;
> +       int bad, total, printed;
>
>         pr_info("%20s ", "Name");
>         list_for_each_entry(key, &lock_keys, list)
>                 pr_info("%*s ", key->len, key->header);
>         pr_info("\n\n");
>
> -       bad = total = 0;
> +       bad = total = printed = 0;
>         while ((st = pop_from_result())) {
>                 total++;
>                 if (st->broken)
> @@ -1311,6 +1312,9 @@ static void print_result(void)
>                         pr_info(" ");
>                 }
>                 pr_info("\n");
> +
> +               if (++printed >= print_nr_entries)
> +                       break;
>         }
>
>         print_bad_events(bad, total);
> @@ -1476,7 +1480,7 @@ static void print_contention_result(struct lock_contention *con)
>  {
>         struct lock_stat *st;
>         struct lock_key *key;
> -       int bad, total;
> +       int bad, total, printed;
>
>         list_for_each_entry(key, &lock_keys, list)
>                 pr_info("%*s ", key->len, key->header);
> @@ -1486,7 +1490,7 @@ static void print_contention_result(struct lock_contention *con)
>         else
>                 pr_info("  %10s   %s\n\n", "type", "caller");
>
> -       bad = total = 0;
> +       bad = total = printed = 0;
>         if (use_bpf)
>                 bad = bad_hist[BROKEN_CONTENDED];
>
> @@ -1507,7 +1511,7 @@ static void print_contention_result(struct lock_contention *con)
>                         /* st->addr contains tid of thread */
>                         t = perf_session__findnew(session, pid);
>                         pr_info("  %10d   %s\n", pid, thread__comm_str(t));
> -                       continue;
> +                       goto next;
>                 }
>
>                 pr_info("  %10s   %s\n", get_type_str(st), st->name);
> @@ -1527,6 +1531,10 @@ static void print_contention_result(struct lock_contention *con)
>                                 pr_info("\t\t\t%#lx  %s\n", (unsigned long)ip, buf);
>                         }
>                 }
> +
> +next:
> +               if (++printed >= print_nr_entries)
> +                       break;
>         }
>
>         print_bad_events(bad, total);
> @@ -1878,6 +1886,7 @@ int cmd_lock(int argc, const char **argv)
>                     "combine locks in the same class"),
>         OPT_BOOLEAN('t', "threads", &show_thread_stats,
>                     "show per-thread lock stats"),
> +       OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
>         OPT_PARENT(lock_options)
>         };
>
> @@ -1905,6 +1914,7 @@ int cmd_lock(int argc, const char **argv)
>         OPT_INTEGER(0, "stack-skip", &stack_skip,
>                     "Set the number of stack depth to skip when finding a lock caller, "
>                     "Default: " __stringify(CONTENTION_STACK_SKIP)),
> +       OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
>         OPT_PARENT(lock_options)
>         };
>
> --
> 2.37.3.998.g577e59143f-goog
>

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

* Re: [PATCH 2/3] perf lock: Add -q/--quiet option
  2022-09-24  0:42 ` [PATCH 2/3] perf lock: Add -q/--quiet option Namhyung Kim
@ 2022-09-24  2:49   ` Ian Rogers
  0 siblings, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2022-09-24  2:49 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Adrian Hunter, linux-perf-users

On Fri, Sep 23, 2022 at 5:42 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Like perf report, this option is to suppress header and debug messages.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/Documentation/perf-lock.txt |  4 ++++
>  tools/perf/builtin-lock.c              | 27 +++++++++++++++-----------
>  2 files changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
> index b23e76200ac2..3b1e16563b79 100644
> --- a/tools/perf/Documentation/perf-lock.txt
> +++ b/tools/perf/Documentation/perf-lock.txt
> @@ -40,6 +40,10 @@ COMMON OPTIONS
>  --verbose::
>          Be more verbose (show symbol address, etc).
>
> +-q::
> +--quiet::
> +       Do not show any message. (Suppress -v)
> +
>  -D::
>  --dump-raw-trace::
>          Dump raw trace in ASCII.
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index 1c0d52384d9e..9722d4ab2e55 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -1250,7 +1250,7 @@ static void print_bad_events(int bad, int total)
>         for (i = 0; i < BROKEN_MAX; i++)
>                 broken += bad_hist[i];
>
> -       if (broken == 0 && !verbose)
> +       if (quiet || (broken == 0 && !verbose))
>                 return;
>
>         pr_info("\n=== output for debug===\n\n");
> @@ -1269,10 +1269,12 @@ static void print_result(void)
>         char cut_name[20];
>         int bad, total, printed;
>
> -       pr_info("%20s ", "Name");
> -       list_for_each_entry(key, &lock_keys, list)
> -               pr_info("%*s ", key->len, key->header);
> -       pr_info("\n\n");
> +       if (!quiet) {
> +               pr_info("%20s ", "Name");
> +               list_for_each_entry(key, &lock_keys, list)
> +                       pr_info("%*s ", key->len, key->header);
> +               pr_info("\n\n");
> +       }
>
>         bad = total = printed = 0;
>         while ((st = pop_from_result())) {
> @@ -1482,13 +1484,15 @@ static void print_contention_result(struct lock_contention *con)
>         struct lock_key *key;
>         int bad, total, printed;
>
> -       list_for_each_entry(key, &lock_keys, list)
> -               pr_info("%*s ", key->len, key->header);
> +       if (!quiet) {
> +               list_for_each_entry(key, &lock_keys, list)
> +                       pr_info("%*s ", key->len, key->header);
>
> -       if (show_thread_stats)
> -               pr_info("  %10s   %s\n\n", "pid", "comm");
> -       else
> -               pr_info("  %10s   %s\n\n", "type", "caller");
> +               if (show_thread_stats)
> +                       pr_info("  %10s   %s\n\n", "pid", "comm");
> +               else
> +                       pr_info("  %10s   %s\n\n", "type", "caller");
> +       }
>
>         bad = total = printed = 0;
>         if (use_bpf)
> @@ -1865,6 +1869,7 @@ int cmd_lock(int argc, const char **argv)
>                    "file", "vmlinux pathname"),
>         OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
>                    "file", "kallsyms pathname"),
> +       OPT_BOOLEAN('q', "quiet", &quiet, "Do not show any message"),
>         OPT_END()
>         };
>
> --
> 2.37.3.998.g577e59143f-goog
>

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

* Re: [PATCH 3/3] perf test: Add kernel lock contention test
  2022-09-24  0:42 ` [PATCH 3/3] perf test: Add kernel lock contention test Namhyung Kim
@ 2022-09-24  2:50   ` Ian Rogers
  2022-09-24  8:09   ` Adrian Hunter
  1 sibling, 0 replies; 9+ messages in thread
From: Ian Rogers @ 2022-09-24  2:50 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Adrian Hunter, linux-perf-users

On Fri, Sep 23, 2022 at 5:42 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Add a new shell test to check if both normal perf lock record +
> contention and BPF (with -b) option are working.  Use perf bench
> sched messaging as a workload since it'd create some contention for
> sending and receiving messages.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Great!

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian


> ---
>  tools/perf/tests/shell/lock_contention.sh | 73 +++++++++++++++++++++++
>  1 file changed, 73 insertions(+)
>  create mode 100755 tools/perf/tests/shell/lock_contention.sh
>
> diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
> new file mode 100755
> index 000000000000..04bf604e3c6f
> --- /dev/null
> +++ b/tools/perf/tests/shell/lock_contention.sh
> @@ -0,0 +1,73 @@
> +#!/bin/sh
> +# kernel lock contention analysis test
> +# SPDX-License-Identifier: GPL-2.0
> +
> +set -e
> +
> +err=0
> +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +result=$(mktemp /tmp/__perf_test.result.XXXXX)
> +
> +cleanup() {
> +       rm -f ${perfdata}
> +       rm -f ${result}
> +       trap - exit term int
> +}
> +
> +trap_cleanup() {
> +       cleanup
> +       exit ${err}
> +}
> +trap trap_cleanup exit term int
> +
> +check() {
> +       if [ `id -u` != 0 ]; then
> +               echo "[Skip] No root permission"
> +               err=2
> +               exit
> +       fi
> +
> +       if ! perf list | grep -q lock:contention_begin; then
> +               echo "[Skip] No lock contention tracepoints"
> +               err=2
> +               exit
> +       fi
> +}
> +
> +test_record()
> +{
> +       echo "Testing perf lock record and perf lock contention"
> +       perf lock record -o ${perfdata} -- perf bench sched messaging > /dev/null 2>&1
> +       # the output goes to the stderr and we expect only 1 output (-E 1)
> +       perf lock contention -i ${perfdata} -E 1 -q 2> ${result}
> +       if [ $(cat "${result}" | wc -l) != "1" ]; then
> +               echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
> +               err=1
> +               exit
> +       fi
> +}
> +
> +test_bpf()
> +{
> +       echo "Testing perf lock contention --use-bpf"
> +
> +       if ! perf lock con -b true > /dev/null 2>&1 ; then
> +               echo "[Skip] No BPF support"
> +               exit
> +       fi
> +
> +       # the perf lock contention output goes to the stderr
> +       perf lock con -a -b -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
> +       if [ $(cat "${result}" | wc -l) != "1" ]; then
> +               echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
> +               err=1
> +               exit
> +       fi
> +}
> +
> +check
> +
> +test_record
> +test_bpf
> +
> +exit ${err}
> --
> 2.37.3.998.g577e59143f-goog
>

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

* Re: [PATCH 3/3] perf test: Add kernel lock contention test
  2022-09-24  0:42 ` [PATCH 3/3] perf test: Add kernel lock contention test Namhyung Kim
  2022-09-24  2:50   ` Ian Rogers
@ 2022-09-24  8:09   ` Adrian Hunter
  2022-09-24 16:50     ` Namhyung Kim
  1 sibling, 1 reply; 9+ messages in thread
From: Adrian Hunter @ 2022-09-24  8:09 UTC (permalink / raw)
  To: Namhyung Kim, Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers, linux-perf-users

On 24/09/22 03:42, Namhyung Kim wrote:
> Add a new shell test to check if both normal perf lock record +
> contention and BPF (with -b) option are working.  Use perf bench
> sched messaging as a workload since it'd create some contention for
> sending and receiving messages.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

There are a few things below that don't need to be fixed but
are perhaps things to be aware of.

Nevertheless:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>


> ---
>  tools/perf/tests/shell/lock_contention.sh | 73 +++++++++++++++++++++++
>  1 file changed, 73 insertions(+)
>  create mode 100755 tools/perf/tests/shell/lock_contention.sh
> 
> diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
> new file mode 100755
> index 000000000000..04bf604e3c6f
> --- /dev/null
> +++ b/tools/perf/tests/shell/lock_contention.sh
> @@ -0,0 +1,73 @@
> +#!/bin/sh
> +# kernel lock contention analysis test
> +# SPDX-License-Identifier: GPL-2.0

All the shell tests are like this, but checkpatch says:

WARNING: Missing or malformed SPDX-License-Identifier tag in line 2
#24: FILE: tools/perf/tests/shell/lock_contention.sh:2:
+# kernel lock contention analysis test

WARNING: Misplaced SPDX-License-Identifier tag - use line 2 instead
#25: FILE: tools/perf/tests/shell/lock_contention.sh:3:
+# SPDX-License-Identifier: GPL-2.0

> +
> +set -e
> +
> +err=0
> +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
> +result=$(mktemp /tmp/__perf_test.result.XXXXX)
> +
> +cleanup() {
> +	rm -f ${perfdata}
> +	rm -f ${result}
> +	trap - exit term int
> +}
> +
> +trap_cleanup() {
> +	cleanup

With "set -e", a command failure will end up here with err=0

> +	exit ${err}
> +}
> +trap trap_cleanup exit term int

shellcheck -S warning tools/perf/tests/shell/lock_contention.sh

In tools/perf/tests/shell/lock_contention.sh line 14:
        trap - exit term int
               ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                    ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                         ^-^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.


In tools/perf/tests/shell/lock_contention.sh line 21:
trap trap_cleanup exit term int
                  ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                       ^--^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.
                            ^-^ SC2039: In POSIX sh, using lower/mixed case for signal names is undefined.


> +
> +check() {
> +	if [ `id -u` != 0 ]; then
> +		echo "[Skip] No root permission"
> +		err=2
> +		exit
> +	fi
> +
> +	if ! perf list | grep -q lock:contention_begin; then
> +		echo "[Skip] No lock contention tracepoints"
> +		err=2
> +		exit
> +	fi
> +}
> +
> +test_record()
> +{
> +	echo "Testing perf lock record and perf lock contention"
> +	perf lock record -o ${perfdata} -- perf bench sched messaging > /dev/null 2>&1
> +	# the output goes to the stderr and we expect only 1 output (-E 1)
> +	perf lock contention -i ${perfdata} -E 1 -q 2> ${result}
> +	if [ $(cat "${result}" | wc -l) != "1" ]; then
> +		echo "[Fail] Recorded result count is not 1:" $(cat "${result}" | wc -l)
> +		err=1
> +		exit
> +	fi
> +}
> +
> +test_bpf()
> +{
> +	echo "Testing perf lock contention --use-bpf"
> +
> +	if ! perf lock con -b true > /dev/null 2>&1 ; then
> +		echo "[Skip] No BPF support"
> +		exit
> +	fi
> +
> +	# the perf lock contention output goes to the stderr
> +	perf lock con -a -b -E 1 -q -- perf bench sched messaging > /dev/null 2> ${result}
> +	if [ $(cat "${result}" | wc -l) != "1" ]; then
> +		echo "[Fail] BPF result count is not 1:" $(cat "${result}" | wc -l)
> +		err=1
> +		exit
> +	fi
> +}
> +
> +check
> +
> +test_record
> +test_bpf
> +
> +exit ${err}


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

* Re: [PATCH 3/3] perf test: Add kernel lock contention test
  2022-09-24  8:09   ` Adrian Hunter
@ 2022-09-24 16:50     ` Namhyung Kim
  0 siblings, 0 replies; 9+ messages in thread
From: Namhyung Kim @ 2022-09-24 16:50 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
	LKML, Ian Rogers, linux-perf-users

On Sat, Sep 24, 2022 at 1:10 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> On 24/09/22 03:42, Namhyung Kim wrote:
> > Add a new shell test to check if both normal perf lock record +
> > contention and BPF (with -b) option are working.  Use perf bench
> > sched messaging as a workload since it'd create some contention for
> > sending and receiving messages.
> >
> > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>
> There are a few things below that don't need to be fixed but
> are perhaps things to be aware of.
>
> Nevertheless:
>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>

Thanks Adrian, I'll install and run shellcheck next time.

Arnaldo, please let me know if you want me to resend it
with the suggested changes.

Thanks,
Namhyung

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

* Re: [PATCH 1/3] perf lock: Add -E/--entries option
  2022-09-24  0:42 [PATCH 1/3] perf lock: Add -E/--entries option Namhyung Kim
                   ` (2 preceding siblings ...)
  2022-09-24  2:49 ` [PATCH 1/3] perf lock: Add -E/--entries option Ian Rogers
@ 2022-09-26 19:45 ` Arnaldo Carvalho de Melo
  3 siblings, 0 replies; 9+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-26 19:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Ingo Molnar, Peter Zijlstra, LKML, Ian Rogers,
	Adrian Hunter, linux-perf-users

Em Fri, Sep 23, 2022 at 05:42:19PM -0700, Namhyung Kim escreveu:
> Like perf top, the -E option can limit number of entries to print.
> It can be useful when users want to see top N contended locks only.

Thanks, applied.

- Arnaldo

 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/perf/Documentation/perf-lock.txt | 10 ++++++++++
>  tools/perf/builtin-lock.c              | 20 +++++++++++++++-----
>  2 files changed, 25 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
> index 5f2dc634258e..b23e76200ac2 100644
> --- a/tools/perf/Documentation/perf-lock.txt
> +++ b/tools/perf/Documentation/perf-lock.txt
> @@ -94,6 +94,11 @@ REPORT OPTIONS
>           EventManager_De       1845          1             636
>           futex-default-S       1609          0               0
>  
> +-E::
> +--entries=<value>::
> +	Display this many entries.
> +
> +
>  INFO OPTIONS
>  ------------
>  
> @@ -105,6 +110,7 @@ INFO OPTIONS
>  --map::
>  	dump map of lock instances (address:name table)
>  
> +
>  CONTENTION OPTIONS
>  --------------
>  
> @@ -154,6 +160,10 @@ CONTENTION OPTIONS
>  --stack-skip
>  	Number of stack depth to skip when finding a lock caller (default: 3).
>  
> +-E::
> +--entries=<value>::
> +	Display this many entries.
> +
>  
>  SEE ALSO
>  --------
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index 25d75fa09b90..1c0d52384d9e 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -58,6 +58,7 @@ static bool use_bpf;
>  static unsigned long bpf_map_entries = 10240;
>  static int max_stack_depth = CONTENTION_STACK_DEPTH;
>  static int stack_skip = CONTENTION_STACK_SKIP;
> +static int print_nr_entries = INT_MAX / 2;
>  
>  static enum {
>  	LOCK_AGGR_ADDR,
> @@ -1266,14 +1267,14 @@ static void print_result(void)
>  	struct lock_stat *st;
>  	struct lock_key *key;
>  	char cut_name[20];
> -	int bad, total;
> +	int bad, total, printed;
>  
>  	pr_info("%20s ", "Name");
>  	list_for_each_entry(key, &lock_keys, list)
>  		pr_info("%*s ", key->len, key->header);
>  	pr_info("\n\n");
>  
> -	bad = total = 0;
> +	bad = total = printed = 0;
>  	while ((st = pop_from_result())) {
>  		total++;
>  		if (st->broken)
> @@ -1311,6 +1312,9 @@ static void print_result(void)
>  			pr_info(" ");
>  		}
>  		pr_info("\n");
> +
> +		if (++printed >= print_nr_entries)
> +			break;
>  	}
>  
>  	print_bad_events(bad, total);
> @@ -1476,7 +1480,7 @@ static void print_contention_result(struct lock_contention *con)
>  {
>  	struct lock_stat *st;
>  	struct lock_key *key;
> -	int bad, total;
> +	int bad, total, printed;
>  
>  	list_for_each_entry(key, &lock_keys, list)
>  		pr_info("%*s ", key->len, key->header);
> @@ -1486,7 +1490,7 @@ static void print_contention_result(struct lock_contention *con)
>  	else
>  		pr_info("  %10s   %s\n\n", "type", "caller");
>  
> -	bad = total = 0;
> +	bad = total = printed = 0;
>  	if (use_bpf)
>  		bad = bad_hist[BROKEN_CONTENDED];
>  
> @@ -1507,7 +1511,7 @@ static void print_contention_result(struct lock_contention *con)
>  			/* st->addr contains tid of thread */
>  			t = perf_session__findnew(session, pid);
>  			pr_info("  %10d   %s\n", pid, thread__comm_str(t));
> -			continue;
> +			goto next;
>  		}
>  
>  		pr_info("  %10s   %s\n", get_type_str(st), st->name);
> @@ -1527,6 +1531,10 @@ static void print_contention_result(struct lock_contention *con)
>  				pr_info("\t\t\t%#lx  %s\n", (unsigned long)ip, buf);
>  			}
>  		}
> +
> +next:
> +		if (++printed >= print_nr_entries)
> +			break;
>  	}
>  
>  	print_bad_events(bad, total);
> @@ -1878,6 +1886,7 @@ int cmd_lock(int argc, const char **argv)
>  		    "combine locks in the same class"),
>  	OPT_BOOLEAN('t', "threads", &show_thread_stats,
>  		    "show per-thread lock stats"),
> +	OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
>  	OPT_PARENT(lock_options)
>  	};
>  
> @@ -1905,6 +1914,7 @@ int cmd_lock(int argc, const char **argv)
>  	OPT_INTEGER(0, "stack-skip", &stack_skip,
>  		    "Set the number of stack depth to skip when finding a lock caller, "
>  		    "Default: " __stringify(CONTENTION_STACK_SKIP)),
> +	OPT_INTEGER('E', "entries", &print_nr_entries, "display this many functions"),
>  	OPT_PARENT(lock_options)
>  	};
>  
> -- 
> 2.37.3.998.g577e59143f-goog

-- 

- Arnaldo

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

end of thread, other threads:[~2022-09-26 19:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-24  0:42 [PATCH 1/3] perf lock: Add -E/--entries option Namhyung Kim
2022-09-24  0:42 ` [PATCH 2/3] perf lock: Add -q/--quiet option Namhyung Kim
2022-09-24  2:49   ` Ian Rogers
2022-09-24  0:42 ` [PATCH 3/3] perf test: Add kernel lock contention test Namhyung Kim
2022-09-24  2:50   ` Ian Rogers
2022-09-24  8:09   ` Adrian Hunter
2022-09-24 16:50     ` Namhyung Kim
2022-09-24  2:49 ` [PATCH 1/3] perf lock: Add -E/--entries option Ian Rogers
2022-09-26 19:45 ` Arnaldo Carvalho de Melo

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).