Skip to contentSkip to conversation

Perf lock improvements

PATCH Superseded Nick Forrington 2 participants 5 messages May 8, 2024 – May 13, 2024 perf events

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Perf lock improvements

Improvement to command line handling for perf lock info.
---
v1: https://lore.kernel.org/all/[email protected]/

v2:
* Drop previous "perf lock report: Restore aggregation by caller by default" patch. Not required for newly collected data with LOCKDEP tracepoints.
* Display map and thread info (rather than an error) when neither or both of --map and --thread are specified.

v3:
* Update --help output

Nick Forrington (1):
perf lock info: Display both map and thread by default

 tools/perf/Documentation/perf-lock.txt |  4 ++--
 tools/perf/builtin-lock.c              | 22 +++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH v3 1/1 perf lock info: Display both map and thread by default

Change "perf lock info" argument handling to:

Display both map and thread info (rather than an error) when neither are specified.

Display both map and thread info (rather than just thread info) when both are requested.

---
 tools/perf/Documentation/perf-lock.txt |  4 ++--
 tools/perf/builtin-lock.c              | 22 +++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-lock.txt +2 -2
index f5938d616d75..57a940399de0 100644
@@ -111,11 +111,11 @@ INFO OPTIONS
 
 -t::
 --threads::
-	dump thread list in perf.data
+	dump only the thread list in perf.data
 
 -m::
 --map::
-	dump map of lock instances (address:name table)
+	dump only the map of lock instances (address:name table)
 
 
 CONTENTION OPTIONS
tools/perf/builtin-lock.c +17 -5
index 230461280e45..d0b8645487ad 100644
@@ -1483,11 +1483,16 @@ static int dump_info(void)
 
 	if (info_threads)
 		dump_threads();
-	else if (info_map)
+
+	if (info_map) {
+		if (info_threads)
+			fputc('\n', lock_output);
 		dump_map();
-	else {
+	}
+
+	if (!info_threads && !info_map) {
 		rc = -1;
-		pr_err("Unknown type of information\n");
+		pr_err("No lock info specified\n");
 	}
 
 	return rc;
@@ -2578,9 +2583,9 @@ int cmd_lock(int argc, const char **argv)
 
 	const struct option info_options[] = {
 	OPT_BOOLEAN('t', "threads", &info_threads,
-		    "dump thread list in perf.data"),
+		    "dump the thread list in perf.data"),
 	OPT_BOOLEAN('m', "map", &info_map,
-		    "map of lock instances (address:name table)"),
+		    "dump the map of lock instances (address:name table)"),
 	OPT_PARENT(lock_options)
 	};
 
@@ -2694,6 +2699,13 @@ int cmd_lock(int argc, const char **argv)
 			if (argc)
 				usage_with_options(info_usage, info_options);
 		}
+
+		/* If neither threads nor map requested, display both */
+		if (!info_threads && !info_map) {
+			info_threads = true;
+			info_map = true;
+		}
+
 		/* recycling report_lock_ops */
 		trace_handler = &report_lock_ops;
 		rc = __cmd_report(true);
Signature · 1 line
2.44.0
maintainer
#2 lore raw

Re: [PATCH 1/1] perf lock info: Display both map and thread by default

Hello,

Quoted 38 lines · Nick Forrington

Change "perf lock info" argument handling to:

Display both map and thread info (rather than an error) when neither are specified.

Display both map and thread info (rather than just thread info) when both are requested.

---
 tools/perf/Documentation/perf-lock.txt |  4 ++--
 tools/perf/builtin-lock.c              | 22 +++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-lock.txt +2 -2
index f5938d616d75..57a940399de0 100644
@@ -111,11 +111,11 @@ INFO OPTIONS
 
 -t::
 --threads::
-       dump thread list in perf.data
+       dump only the thread list in perf.data
 
 -m::
 --map::
-       dump map of lock instances (address:name table)
+       dump only the map of lock instances (address:name table)
 
 
 CONTENTION OPTIONS
tools/perf/builtin-lock.c +0 -0
index 230461280e45..d0b8645487ad 100644

tools/perf/builtin-lock.c static int dump_info(void) · line 1489

Quoted 8 lines
tools/perf/builtin-lock.c +4 -1
@@ -1483,11 +1483,16 @@ static int dump_info(void)
 
        if (info_threads)
                dump_threads();
-       else if (info_map)
+
+       if (info_map) {
+               if (info_threads)
+                       fputc('\n', lock_output);

it seems you need pr_info("\n"). Where does lock_output come from?

tools/perf/builtin-lock.c static int dump_info(void) · line 1496

Quoted 9 lines
tools/perf/builtin-lock.c +4 -2
                dump_map();
-       else {
+       }
+
+       if (!info_threads && !info_map) {
                rc = -1;
-               pr_err("Unknown type of information\n");
+               pr_err("No lock info specified\n");
        }

I think we can remove this block now.

Thanks,
Namhyung

Quoted 32 lines
tools/perf/builtin-lock.c +9 -3
        return rc;
@@ -2578,9 +2583,9 @@ int cmd_lock(int argc, const char **argv)
 
        const struct option info_options[] = {
        OPT_BOOLEAN('t', "threads", &info_threads,
-                   "dump thread list in perf.data"),
+                   "dump the thread list in perf.data"),
        OPT_BOOLEAN('m', "map", &info_map,
-                   "map of lock instances (address:name table)"),
+                   "dump the map of lock instances (address:name table)"),
        OPT_PARENT(lock_options)
        };
 
@@ -2694,6 +2699,13 @@ int cmd_lock(int argc, const char **argv)
                        if (argc)
                                usage_with_options(info_usage, info_options);
                }
+
+               /* If neither threads nor map requested, display both */
+               if (!info_threads && !info_map) {
+                       info_threads = true;
+                       info_map = true;
+               }
+
                /* recycling report_lock_ops */
                trace_handler = &report_lock_ops;
                rc = __cmd_report(true);
--

2.44.0

#3 lore raw

Re: [PATCH 1/1] perf lock info: Display both map and thread by default

Hello,

Quoted 41 lines · Namhyung Kim

Hello,

Quoted 38 lines · Nick Forrington

Change "perf lock info" argument handling to:

Display both map and thread info (rather than an error) when neither are specified.

Display both map and thread info (rather than just thread info) when both are requested.

---
  tools/perf/Documentation/perf-lock.txt |  4 ++--
  tools/perf/builtin-lock.c              | 22 +++++++++++++++++-----
  2 files changed, 19 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-lock.txt +2 -2
index f5938d616d75..57a940399de0 100644
@@ -111,11 +111,11 @@ INFO OPTIONS
 
  -t::
  --threads::
-       dump thread list in perf.data
+       dump only the thread list in perf.data
 
  -m::
  --map::
-       dump map of lock instances (address:name table)
+       dump only the map of lock instances (address:name table)
 
 
  CONTENTION OPTIONS
tools/perf/builtin-lock.c +0 -0
index 230461280e45..d0b8645487ad 100644
@@ -1483,11 +1483,16 @@ static int dump_info(void)
 
Quoted 8 lines

tools/perf/builtin-lock.c static int dump_info(void) · line 1489

Quoted 7 lines
tools/perf/builtin-lock.c +4 -1
         if (info_threads)
                 dump_threads();
-       else if (info_map)
+
+       if (info_map) {
+               if (info_threads)
+                       fputc('\n', lock_output);

it seems you need pr_info("\n"). Where does lock_output come from?

It's a static FILE* that defaults to stderr.

It's used by dump_threads and dump_map (via fprintf), so I think it makes sense to use it for the output spacing between them?

Quoted 11 lines

tools/perf/builtin-lock.c static int dump_info(void) · line 1496

Quoted 11 lines
tools/perf/builtin-lock.c +4 -2
                 dump_map();
-       else {
+       }
+
+       if (!info_threads && !info_map) {
                 rc = -1;
-               pr_err("Unknown type of information\n");
+               pr_err("No lock info specified\n");
         }
Quoted 1 line

I think we can remove this block now.

The original error looked like a function input sanity check (rather than for handling user input), so I kept it (even if it should no longer be possible for a user to trigger it).

Although I can remove it (or move it to the start of the function) if you prefer.

Thanks,
Nick

Quoted 36 lines

Thanks,
Namhyung

Quoted 31 lines
tools/perf/builtin-lock.c +9 -3
         return rc;
@@ -2578,9 +2583,9 @@ int cmd_lock(int argc, const char **argv)
 
         const struct option info_options[] = {
         OPT_BOOLEAN('t', "threads", &info_threads,
-                   "dump thread list in perf.data"),
+                   "dump the thread list in perf.data"),
         OPT_BOOLEAN('m', "map", &info_map,
-                   "map of lock instances (address:name table)"),
+                   "dump the map of lock instances (address:name table)"),
         OPT_PARENT(lock_options)
         };
 
@@ -2694,6 +2699,13 @@ int cmd_lock(int argc, const char **argv)
                         if (argc)
                                 usage_with_options(info_usage, info_options);
                 }
+
+               /* If neither threads nor map requested, display both */
+               if (!info_threads && !info_map) {
+                       info_threads = true;
+                       info_map = true;
+               }
+
                 /* recycling report_lock_ops */
                 trace_handler = &report_lock_ops;
                 rc = __cmd_report(true);
--

2.44.0

maintainer
#4 lore raw

Re: [PATCH 1/1] perf lock info: Display both map and thread by default

Quoted 55 lines · Nick Forrington

Hello,

Quoted 41 lines · Namhyung Kim

Hello,

Quoted 38 lines · Nick Forrington

Change "perf lock info" argument handling to:

Display both map and thread info (rather than an error) when neither are specified.

Display both map and thread info (rather than just thread info) when both are requested.

---
  tools/perf/Documentation/perf-lock.txt |  4 ++--
  tools/perf/builtin-lock.c              | 22 +++++++++++++++++-----
  2 files changed, 19 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-lock.txt +2 -2
index f5938d616d75..57a940399de0 100644
@@ -111,11 +111,11 @@ INFO OPTIONS
 
  -t::
  --threads::
-       dump thread list in perf.data
+       dump only the thread list in perf.data
 
  -m::
  --map::
-       dump map of lock instances (address:name table)
+       dump only the map of lock instances (address:name table)
 
 
  CONTENTION OPTIONS
tools/perf/builtin-lock.c +0 -0
index 230461280e45..d0b8645487ad 100644
@@ -1483,11 +1483,16 @@ static int dump_info(void)
 
Quoted 8 lines

tools/perf/builtin-lock.c static int dump_info(void) · line 1489

Quoted 7 lines
tools/perf/builtin-lock.c +4 -1
         if (info_threads)
                 dump_threads();
-       else if (info_map)
+
+       if (info_map) {
+               if (info_threads)
+                       fputc('\n', lock_output);

it seems you need pr_info("\n"). Where does lock_output come from?

Quoted 1 line

It's a static FILE* that defaults to stderr.

Oh, right. I somehow confused this with perf sched. ;-p

Quoted 19 lines

It's used by dump_threads and dump_map (via fprintf), so I think it makes sense to use it for the output spacing between them?

Quoted 11 lines

tools/perf/builtin-lock.c static int dump_info(void) · line 1496

Quoted 11 lines
tools/perf/builtin-lock.c +4 -2
                 dump_map();
-       else {
+       }
+
+       if (!info_threads && !info_map) {
                 rc = -1;
-               pr_err("Unknown type of information\n");
+               pr_err("No lock info specified\n");
         }
Quoted 1 line

I think we can remove this block now.

Quoted 7 lines

The original error looked like a function input sanity check (rather than for handling user input), so I kept it (even if it should no longer be possible for a user to trigger it).

Although I can remove it (or move it to the start of the function) if you prefer.

Yep, I think we can just remove it.

Thanks,
Namhyung