Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf sched replay: Fix -r/--repeat command line option for infinity

Currently, the -r/--repeat option accepts values from 0 and complains
for -1. The help section specifies:
-r, --repeat <n> repeat the workload replay N times (-1: infinite)

The -r -1 option raises an error because replay_repeat is defined as
an unsigned int.

In the current implementation, the workload is repeated n times when
-r <n> is used, except when n is 0.

When -r is set to 0, the workload is also repeated once. This happens
because when -r=0, the run_one_test function is not called. (Note that
mutex unlocking, which is essential for child threads spawned to emulate
the workload, happens in run_one_test.) However, mutex unlocking is
still performed in the destroy_tasks function. Thus, -r=0 results in the
workload running once coincidentally.

To clarify and maintain the existing logic for -r >= 1 (which runs the
workload the specified number of times) and to fix the issue with infinite
runs, make -r=0 perform an infinite run.

Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Link: https://lore.kernel.org/r/20240628071821.15264-1-vineethr@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Madadi Vineeth Reddy and committed by
Namhyung Kim
a7cacaa0 5484fd27

+11 -1
+7
tools/perf/Documentation/perf-sched.txt
··· 202 202 --state:: 203 203 Show task state when it switched out. 204 204 205 + OPTIONS for 'perf sched replay' 206 + ------------------------------ 207 + 208 + -r:: 209 + --repeat <n>:: 210 + repeat the workload n times (0: infinite). Default is 10. 211 + 205 212 SEE ALSO 206 213 -------- 207 214 linkperf:perf-record[1]
+4 -1
tools/perf/builtin-sched.c
··· 3386 3386 sched->thread_funcs_exit = false; 3387 3387 create_tasks(sched); 3388 3388 printf("------------------------------------------------------------\n"); 3389 + if (sched->replay_repeat == 0) 3390 + sched->replay_repeat = UINT_MAX; 3391 + 3389 3392 for (i = 0; i < sched->replay_repeat; i++) 3390 3393 run_one_test(sched); 3391 3394 ··· 3554 3551 }; 3555 3552 const struct option replay_options[] = { 3556 3553 OPT_UINTEGER('r', "repeat", &sched.replay_repeat, 3557 - "repeat the workload replay N times (-1: infinite)"), 3554 + "repeat the workload replay N times (0: infinite)"), 3558 3555 OPT_PARENT(sched_options) 3559 3556 }; 3560 3557 const struct option map_options[] = {