perf sched replay: Fix -r/--repeat command line option for infinity
PATCH v2 1/1 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.
---
Changes in v2:
- Kept the existing 'for' loop and added a condition for infinite
looping. (James Clark)
- This change also ensures that integer overflow doesn't occur when 'replay_repeat' is zero.
- Add Reviewed-by tag from James Clark.
- Rebase against perf-tools-next commit 788c5160526a ("perf vendor
events: Add westmereex counter information")
- Link to v1: https://lore.kernel.org/all/[email protected]/
tools/perf/Documentation/perf-sched.txt | 7 +++++++ tools/perf/builtin-sched.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +7 -0
@@ -202,6 +202,13 @@ OPTIONS for 'perf sched timehist' --state:: Show task state when it switched out. +OPTIONS for 'perf sched replay' +------------------------------ + +-r:: +--repeat <n>:: + repeat the workload n times (0: infinite). Default is 10. + SEE ALSO -------- linkperf:perf-record[1]
tools/perf/builtin-sched.c +8 -3
@@ -3383,8 +3383,13 @@ static int perf_sched__replay(struct perf_sched *sched) sched->thread_funcs_exit = false;create_tasks (sched);printf ("------------------------------------------------------------\n" ); -for (i =0 ; i < sched->replay_repeat; i++) -run_one_test (sched); +if (sched->replay_repeat ==0 ) { +while (1 ) +run_one_test (sched); + }else { +for (i =0 ; i < sched->replay_repeat; i++) +run_one_test (sched); + } sched->thread_funcs_exit = true;destroy_tasks (sched);
@@ -3548,7 +3553,7 @@ int cmd_sched(int argc, const char **argv) };const struct option replay_options[] = {OPT_UINTEGER ('r' ,"repeat" , &sched.replay_repeat, -"repeat the workload replay N times (-1: infinite)" ), +"repeat the workload replay N times (0: infinite)" ),OPT_PARENT (sched_options) };const struct option map_options[] = {
Signature · 1 line
2.31.1
Quoted 17 lines · Madadi Vineeth Reddy
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_repeatis 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_testfunction is not called. (Note that mutex unlocking, which is essential for child threads spawned to emulate the workload, happens inrun_one_test.) However, mutex unlocking is still performed in thedestroy_tasksfunction. Thus, -r=0 results in the workload running once coincidentally.
Quoted 7 lines
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.
Signed-off-by Madadi Vineeth Reddy <[email protected]>Reviewed-by James Clark <[email protected]>
Hi all,
Any suggestions/comments on this patch?
Thanks and Regards
Madadi Vineeth Reddy
Quoted 62 lines
---
Changes in v2:
- Kept the existing 'for' loop and added a condition for infinite
looping. (James Clark)
- This change also ensures that integer overflow doesn't occur when 'replay_repeat' is zero.
- Add Reviewed-by tag from James Clark.
- Rebase against perf-tools-next commit788c5160526a("perf vendor
events: Add westmereex counter information")
- Link to v1: https://lore.kernel.org/all/[email protected]/tools/perf/Documentation/perf-sched.txt | 7 +++++++ tools/perf/builtin-sched.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)tools/perf/Documentation/perf-sched.txt +7
-0@@ -202,6 +202,13 @@ OPTIONS for 'perf sched timehist' --state:: Show task state when it switched out. +OPTIONS for 'perf sched replay' +------------------------------ + +-r:: +--repeat <n>:: + repeat the workload n times (0: infinite). Default is 10. + SEE ALSO -------- linkperf:perf-record[1]tools/perf/builtin-sched.c +8
-3@@ -3383,8 +3383,13 @@ static int perf_sched__replay(struct perf_sched *sched) sched->thread_funcs_exit = false;create_tasks (sched);printf ("------------------------------------------------------------\n" ); -for (i =0 ; i < sched->replay_repeat; i++) -run_one_test (sched); +if (sched->replay_repeat ==0 ) { +while (1 ) +run_one_test (sched); + }else { +for (i =0 ; i < sched->replay_repeat; i++) +run_one_test (sched); + } sched->thread_funcs_exit = true;destroy_tasks (sched);@@ -3548,7 +3553,7 @@ int cmd_sched(int argc, const char **argv) };const struct option replay_options[] = {OPT_UINTEGER ('r' ,"repeat" , &sched.replay_repeat, -"repeat the workload replay N times (-1: infinite)" ), +"repeat the workload replay N times (0: infinite)" ),OPT_PARENT (sched_options) };const struct option map_options[] = {
Namhyung Kim
maintainerQuoted 22 lines · Madadi Vineeth Reddy
Quoted 21 lines · Madadi Vineeth Reddy
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_repeatis 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_testfunction is not called. (Note that mutex unlocking, which is essential for child threads spawned to emulate the workload, happens inrun_one_test.) However, mutex unlocking is still performed in thedestroy_tasksfunction. 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.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Madadi Vineeth Reddy <[email protected]>Reviewed-by James Clark <[email protected]>Hi all,
Any suggestions/comments on this patch?
I think the original intention was to set replay_repeat to UINT_MAX using -1. But it seems to refuse the negative number now.
Maybe you can simply set it to UNIT_MAX for -r 0.
Thanks,
Namhyung
Quoted 63 lines
Quoted 62 lines
---
Changes in v2:
- Kept the existing 'for' loop and added a condition for infinite
looping. (James Clark)
- This change also ensures that integer overflow doesn't occur when 'replay_repeat' is zero.
- Add Reviewed-by tag from James Clark.
- Rebase against perf-tools-next commit788c5160526a("perf vendor
events: Add westmereex counter information")
- Link to v1: https://lore.kernel.org/all/[email protected]/tools/perf/Documentation/perf-sched.txt | 7 +++++++ tools/perf/builtin-sched.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)tools/perf/Documentation/perf-sched.txt +7
-0@@ -202,6 +202,13 @@ OPTIONS for 'perf sched timehist' --state:: Show task state when it switched out. +OPTIONS for 'perf sched replay' +------------------------------ + +-r:: +--repeat <n>:: + repeat the workload n times (0: infinite). Default is 10. + SEE ALSO -------- linkperf:perf-record[1]tools/perf/builtin-sched.c +8
-3@@ -3383,8 +3383,13 @@ static int perf_sched__replay(struct perf_sched *sched) sched->thread_funcs_exit = false;create_tasks (sched);printf ("------------------------------------------------------------\n" ); -for (i =0 ; i < sched->replay_repeat; i++) -run_one_test (sched); +if (sched->replay_repeat ==0 ) { +while (1 ) +run_one_test (sched); + }else { +for (i =0 ; i < sched->replay_repeat; i++) +run_one_test (sched); + } sched->thread_funcs_exit = true;destroy_tasks (sched);@@ -3548,7 +3553,7 @@ int cmd_sched(int argc, const char **argv) };const struct option replay_options[] = {OPT_UINTEGER ('r' ,"repeat" , &sched.replay_repeat, -"repeat the workload replay N times (-1: infinite)" ), +"repeat the workload replay N times (0: infinite)" ),OPT_PARENT (sched_options) };const struct option map_options[] = {
Hi Namhyung,
Quoted 30 lines · Namhyung Kim
Quoted 22 lines · Madadi Vineeth Reddy
Quoted 21 lines · Madadi Vineeth Reddy
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_repeatis 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_testfunction is not called. (Note that mutex unlocking, which is essential for child threads spawned to emulate the workload, happens inrun_one_test.) However, mutex unlocking is still performed in thedestroy_tasksfunction. 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.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Madadi Vineeth Reddy <[email protected]>Reviewed-by James Clark <[email protected]>Hi all,
Any suggestions/comments on this patch?
Quoted 4 lines
I think the original intention was to set
replay_repeattoUINT_MAXusing -1. But it seems to refuse the negative number now.Maybe you can simply set it to
UNIT_MAXfor -r 0.
Thanks for the feedback. I will make the change and send a v3.
Thanks and Regards
Madadi Vineeth Reddy
Quoted 68 lines
Thanks,
NamhyungQuoted 63 lines
Quoted 62 lines
---
Changes in v2:
- Kept the existing 'for' loop and added a condition for infinite
looping. (James Clark)
- This change also ensures that integer overflow doesn't occur when 'replay_repeat' is zero.
- Add Reviewed-by tag from James Clark.
- Rebase against perf-tools-next commit788c5160526a("perf vendor
events: Add westmereex counter information")
- Link to v1: https://lore.kernel.org/all/[email protected]/tools/perf/Documentation/perf-sched.txt | 7 +++++++ tools/perf/builtin-sched.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)tools/perf/Documentation/perf-sched.txt +7
-0@@ -202,6 +202,13 @@ OPTIONS for 'perf sched timehist' --state:: Show task state when it switched out. +OPTIONS for 'perf sched replay' +------------------------------ + +-r:: +--repeat <n>:: + repeat the workload n times (0: infinite). Default is 10. + SEE ALSO -------- linkperf:perf-record[1]tools/perf/builtin-sched.c +8
-3@@ -3383,8 +3383,13 @@ static int perf_sched__replay(struct perf_sched *sched) sched->thread_funcs_exit = false;create_tasks (sched);printf ("------------------------------------------------------------\n" ); -for (i =0 ; i < sched->replay_repeat; i++) -run_one_test (sched); +if (sched->replay_repeat ==0 ) { +while (1 ) +run_one_test (sched); + }else { +for (i =0 ; i < sched->replay_repeat; i++) +run_one_test (sched); + } sched->thread_funcs_exit = true;destroy_tasks (sched);@@ -3548,7 +3553,7 @@ int cmd_sched(int argc, const char **argv) };const struct option replay_options[] = {OPT_UINTEGER ('r' ,"repeat" , &sched.replay_repeat, -"repeat the workload replay N times (-1: infinite)" ), +"repeat the workload replay N times (0: infinite)" ),OPT_PARENT (sched_options) };const struct option map_options[] = {