Skip to contentSkip to conversation

Document the 'perf test -w' workloads functionality

PATCH Superseded Arnaldo Carvalho de Melo 3 participants 8 messages Oct 11, 2024 – Oct 18, 2024 perf events

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

v2 cover Document the 'perf test -w' workloads functionality

From: Arnaldo Carvalho de Melo <[email protected]>

Hi,

I noticed that the 'perf test -w' code wasn't well exposed, so
add a '-w --list' option to list the existing workloads and document it in the 'perf test' man page.

- Arnaldo

v2:

- Use --list-workloads, as suggesed by James Clark.

- Add info in the man page about the parameters the built-in workloads accept.

Arnaldo Carvalho de Melo (3):
perf test: Introduce workloads__for_each()
perf test: Introduce '-w --list' to list the available workloads perf test: Document the -w/--workload option

 tools/perf/Documentation/perf-test.txt | 14 +++++++++++++
 tools/perf/tests/builtin-test.c        | 27 ++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 4 deletions(-)
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH v2 1/3 perf test: Introduce workloads__for_each()

From: Arnaldo Carvalho de Melo <[email protected]>

And use it in run_workload().

Testing it:

  root@x1:~# perf trace -e *landlock* perf test -w landlock
       0.000 ( 0.015 ms): :1274331/1274331 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_PATH_BENEATH, rule_attr: 0x7ffd3fea55e0, flags: 45) = -1 EINVAL (Invalid argument)
       0.018 ( 0.003 ms): :1274331/1274331 landlock_add_rule(ruleset_fd: 11, rule_type: LANDLOCK_RULE_NET_PORT, rule_attr: 0x7ffd3fea55f0, flags: 45) = -1 EINVAL (Invalid argument)
  root@x1:~# perf test -w bla
  No workload found: bla
  root@x1:~#
Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/tests/builtin-test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/tests/builtin-test.c +4 -3
index 470a9709427ddaad..2201f7ed432ce9f2 100644
@@ -155,6 +155,9 @@ static struct test_workload *workloads[] = {
 	&workload__landlock,
 };
 
+#define workloads__for_each(workload) \
+	for (unsigned i = 0; i < ARRAY_SIZE(workloads) && ({ workload = workloads[i]; 1; }); i++)
+
 static int num_subtests(const struct test_suite *t)
 {
 	int num;
@@ -504,11 +507,9 @@ static int perf_test__list(int argc, const char **argv)
 
 static int run_workload(const char *work, int argc, const char **argv)
 {
-	unsigned int i = 0;
 	struct test_workload *twl;
 
-	for (i = 0; i < ARRAY_SIZE(workloads); i++) {
-		twl = workloads[i];
+	workloads__for_each(twl) {
 		if (!strcmp(twl->name, work))
 			return twl->func(argc, argv);
 	}
Signature · 1 line
2.47.0
author maintainer
#2 lore raw

PATCH v2 2/3 perf test: Introduce '-w --list' to list the available workloads

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Using it:

  $ perf test -w noplop
  No workload found: noplop
  $
  $ perf test -w
   Error: switch `w' requires a value
   Usage: perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]

-w, --workload <work>
workload to run for testing, use '--list-workloads' to list the available ones.
$

  $ perf test --list-workloads
  noploop
  thloop
  leafloop
  sqrtloop
  brstack
  datasym
  landlock
  $

Would be good at some point to have a description in 'struct test_workload'.

Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/tests/builtin-test.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
tools/perf/tests/builtin-test.c +19 -1
index 2201f7ed432ce9f2..cc43b9f366d09436 100644
@@ -505,6 +505,17 @@ static int perf_test__list(int argc, const char **argv)
 	return 0;
 }
 
+static int workloads__fprintf_list(FILE *fp)
+{
+	struct test_workload *twl;
+	int printed = 0;
+
+	workloads__for_each(twl)
+		printed += fprintf(fp, "%s\n", twl->name);
+
+	return printed;
+}
+
 static int run_workload(const char *work, int argc, const char **argv)
 {
 	struct test_workload *twl;
@@ -535,6 +546,7 @@ int cmd_test(int argc, const char **argv)
 	};
 	const char *skip = NULL;
 	const char *workload = NULL;
+	bool list_workloads = false;
 	const struct option test_options[] = {
 	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
 	OPT_INCR('v', "verbose", &verbose,
@@ -544,7 +556,8 @@ int cmd_test(int argc, const char **argv)
 	OPT_BOOLEAN('p', "parallel", &parallel, "Run the tests in parallel"),
 	OPT_BOOLEAN('S', "sequential", &sequential,
 		    "Run the tests one after another rather than in parallel"),
-	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
+	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing, use '--list-workloads' to list the available ones."),
+	OPT_BOOLEAN(0, "list-workloads", &list_workloads, "List the available builtin workloads to use with -w/--workload"),
 	OPT_STRING(0, "dso", &dso_to_test, "dso", "dso to test"),
 	OPT_STRING(0, "objdump", &test_objdump_path, "path",
 		   "objdump binary to use for disassembly and annotations"),
@@ -570,6 +583,11 @@ int cmd_test(int argc, const char **argv)
 	if (workload)
 		return run_workload(workload, argc, argv);
 
+	if (list_workloads) {
+		workloads__fprintf_list(stdout);
+		return 0;
+	}
+
 	if (dont_fork)
 		sequential = true;
 	else if (parallel)
Signature · 1 line
2.47.0
maintainer
#3 lore raw

Re: [PATCH 2/3] perf test: Introduce '-w --list' to list the available workloads

Hi Arnaldo,

The commit subject line should be changed to --list-workloads too.

Thanks,
Namhyung

Quoted 92 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Using it:

  $ perf test -w noplop
  No workload found: noplop
  $
  $ perf test -w
   Error: switch `w' requires a value
   Usage: perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]

-w, --workload <work>
workload to run for testing, use '--list-workloads' to list the available ones.
$

  $ perf test --list-workloads
  noploop
  thloop
  leafloop
  sqrtloop
  brstack
  datasym
  landlock
  $

Would be good at some point to have a description in 'struct test_workload'.

Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/tests/builtin-test.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
tools/perf/tests/builtin-test.c +19 -1
index 2201f7ed432ce9f2..cc43b9f366d09436 100644
@@ -505,6 +505,17 @@ static int perf_test__list(int argc, const char **argv)
 	return 0;
 }
 
+static int workloads__fprintf_list(FILE *fp)
+{
+	struct test_workload *twl;
+	int printed = 0;
+
+	workloads__for_each(twl)
+		printed += fprintf(fp, "%s\n", twl->name);
+
+	return printed;
+}
+
 static int run_workload(const char *work, int argc, const char **argv)
 {
 	struct test_workload *twl;
@@ -535,6 +546,7 @@ int cmd_test(int argc, const char **argv)
 	};
 	const char *skip = NULL;
 	const char *workload = NULL;
+	bool list_workloads = false;
 	const struct option test_options[] = {
 	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
 	OPT_INCR('v', "verbose", &verbose,
@@ -544,7 +556,8 @@ int cmd_test(int argc, const char **argv)
 	OPT_BOOLEAN('p', "parallel", &parallel, "Run the tests in parallel"),
 	OPT_BOOLEAN('S', "sequential", &sequential,
 		    "Run the tests one after another rather than in parallel"),
-	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"),
+	OPT_STRING('w', "workload", &workload, "work", "workload to run for testing, use '--list-workloads' to list the available ones."),
+	OPT_BOOLEAN(0, "list-workloads", &list_workloads, "List the available builtin workloads to use with -w/--workload"),
 	OPT_STRING(0, "dso", &dso_to_test, "dso", "dso to test"),
 	OPT_STRING(0, "objdump", &test_objdump_path, "path",
 		   "objdump binary to use for disassembly and annotations"),
@@ -570,6 +583,11 @@ int cmd_test(int argc, const char **argv)
 	if (workload)
 		return run_workload(workload, argc, argv);
 
+	if (list_workloads) {
+		workloads__fprintf_list(stdout);
+		return 0;
+	}
+
 	if (dont_fork)
 		sequential = true;
 	else if (parallel)
Signature · 1 line
2.47.0
author maintainer
#4 lore raw

PATCH v2 3/3 perf test: Document the -w/--workload option

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Wasn't documented so far, mention that it is mostly used in the shell regression tests.

Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/Documentation/perf-test.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tools/perf/Documentation/perf-test.txt +14 -0
index 9acb8d1f658890e9..62ce705d365f0442 100644
@@ -48,3 +48,17 @@ OPTIONS
 
 --dso::
 	Specify a DSO for the "Symbols" test.
+
+-w::
+--workload=::
+	Run a built-in workload, to list them use '-w --list', current ones include:
+	noploop, thloop, leafloop, sqrtloop, brstack, datasym and landlock.
+
+	Used with the shell script regression tests.
+
+	Some accept an extra parameter:
+
+		seconds: leafloop, noploop, sqrtloop, thloop
+		nrloops: brstack
+
+	The datasym and landlock workloads don't accept any.
Signature · 1 line
2.47.0
reviewer
#5 lore raw

Re: [PATCH 3/3] perf test: Document the -w/--workload option

Quoted 21 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Wasn't documented so far, mention that it is mostly used in the shell regression tests.

Cc Adrian Hunter <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Namhyung Kim <[email protected]>
---
  tools/perf/Documentation/perf-test.txt | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
tools/perf/Documentation/perf-test.txt +0 -0
index 9acb8d1f658890e9..62ce705d365f0442 100644

tools/perf/Documentation/perf-test.txt OPTIONS · line 54

Quoted 7 lines
tools/perf/Documentation/perf-test.txt +4 -0
@@ -48,3 +48,17 @@ OPTIONS
 
  --dso::
  	Specify a DSO for the "Symbols" test.
+
+-w::
+--workload=::
+	Run a built-in workload, to list them use '-w --list', current ones include:

Should be --list-workloads now

author maintainer
#6 lore raw

Re: [PATCH 3/3] perf test: Document the -w/--workload option

Quoted 11 lines · James Clark

tools/perf/Documentation/perf-test.txt OPTIONS · line 53

Quoted 8 lines · Arnaldo Carvalho de Melo

+++ b/tools/perf/Documentation/perf-test.txt

tools/perf/Documentation/perf-test.txt +4 -0
@@ -48,3 +48,17 @@ OPTIONS
  --dso::
  	Specify a DSO for the "Symbols" test.
+
+-w::
+--workload=::
+	Run a built-in workload, to list them use '-w --list', current ones include:

Should be --list-workloads now

Oops, fixed now.

Thanks,

- Arnaldo

reviewer Reviewed-by on the v2 series
#7 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 17 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Hi,

I noticed that the 'perf test -w' code wasn't well exposed, so
add a '-w --list' option to list the existing workloads and document it in the 'perf test' man page.

- Arnaldo

v2:

- Use --list-workloads, as suggesed by James Clark.

- Add info in the man page about the parameters the built-in workloads accept.

Quoted 9 lines

Arnaldo Carvalho de Melo (3):
perf test: Introduce workloads__for_each()
perf test: Introduce '-w --list' to list the available workloads perf test: Document the -w/--workload option

  tools/perf/Documentation/perf-test.txt | 14 +++++++++++++
  tools/perf/tests/builtin-test.c        | 27 ++++++++++++++++++++++----
  2 files changed, 37 insertions(+), 4 deletions(-)

With the fix for the comment on patch 3: