Skip to content

Commit

Permalink
perf test: Introduce workloads__for_each()
Browse files Browse the repository at this point in the history
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:~#

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Clark Williams <williams@redhat.com>
Link: https://lore.kernel.org/r/20241020021842.1752770-2-acme@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
  • Loading branch information
Arnaldo Carvalho de Melo authored and Namhyung Kim committed Oct 22, 2024
1 parent 46610ba commit 18b63d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tools/perf/tests/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 18b63d6

Please sign in to comment.