Skip to contentSkip to conversation

perf stat: Honour --timeout for forked workloads

PATCH Applied Arnaldo Carvalho de Melo 4 participants 4 messages Apr 15, 2020 – Apr 22, 2020 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf stat: Honour --timeout for forked workloads

Hi guys,

Please take a look and give this your acks, Tested-by, etc.

Thanks,

- Arnaldo

----

When --timeout is used and a workload is specified to be started by 'perf stat', i.e.

  $ perf stat --timeout 1000 sleep 1h

The --timeout wasn't being honoured, i.e. the workload, 'sleep 1h' in the above example, should be terminated after 1000ms, but it wasn't, 'perf stat' was waiting for it to finish.

Fix it by sending a SIGTERM when the timeout expires.

Now it works:

  # perf stat -e cycles --timeout 1234 sleep 1h
  sleep: Terminated

Performance counter stats for 'sleep 1h':

           1,066,692      cycles

         1.234314838 seconds time elapsed

         0.000750000 seconds user
         0.000000000 seconds sys

#

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243

Cc Adrian Hunter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
index ec053dc1e35c..9207b6c45475 100644
@@ -686,8 +686,11 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 					break;
 			}
 		}
-		if (child_pid != -1)
+		if (child_pid != -1) {
+			if (timeout)
+				kill(child_pid, SIGTERM);
 			wait4(child_pid, &status, 0, &stat_config.ru_data);
+		}
 
 		if (workload_exec_errno) {
 			const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
Signature · 1 line
2.25.2
#1 lore raw
Quoted 35 lines · Arnaldo Carvalho de Melo

Hi guys,

Please take a look and give this your acks, Tested-by, etc.

Thanks,

- Arnaldo

----

When --timeout is used and a workload is specified to be started by 'perf stat', i.e.

  $ perf stat --timeout 1000 sleep 1h

The --timeout wasn't being honoured, i.e. the workload, 'sleep 1h' in the above example, should be terminated after 1000ms, but it wasn't, 'perf stat' was waiting for it to finish.

Fix it by sending a SIGTERM when the timeout expires.

Now it works:

  # perf stat -e cycles --timeout 1234 sleep 1h
  sleep: Terminated
   Performance counter stats for 'sleep 1h':

           1,066,692      cycles

         1.234314838 seconds time elapsed

         0.000750000 seconds user
         0.000000000 seconds sys
Quoted 8 lines

#

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243

Cc Adrian Hunter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>

Acked/Tested-by: Jiri Olsa <[email protected]>

cc-ing yuzhoujian, author of the --timeout

jirka

Quoted 24 lines
---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
index ec053dc1e35c..9207b6c45475 100644
@@ -686,8 +686,11 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 					break;
 			}
 		}
-		if (child_pid != -1)
+		if (child_pid != -1) {
+			if (timeout)
+				kill(child_pid, SIGTERM);
 			wait4(child_pid, &status, 0, &stat_config.ru_data);
+		}
 
 		if (workload_exec_errno) {
 			const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
Signature · 1 line
2.25.2
Tested-by on v1 1/1
#2 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 52 lines · On среда, 15 апреля 2020 г. 18:38:03 MSK Arnaldo Carvalho de Melo wrote:

Hi guys,

Please take a look and give this your acks, Tested-by, etc.

Thanks,

- Arnaldo

----

When --timeout is used and a workload is specified to be started by 'perf stat', i.e.

  $ perf stat --timeout 1000 sleep 1h

The --timeout wasn't being honoured, i.e. the workload, 'sleep 1h' in the above example, should be terminated after 1000ms, but it wasn't, 'perf stat' was waiting for it to finish.

Fix it by sending a SIGTERM when the timeout expires.

Now it works:

  # perf stat -e cycles --timeout 1234 sleep 1h
  sleep: Terminated
   Performance counter stats for 'sleep 1h':

           1,066,692      cycles

         1.234314838 seconds time elapsed

         0.000750000 seconds user
         0.000000000 seconds sys

#

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243

Cc Adrian Hunter <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +0 -0
index ec053dc1e35c..9207b6c45475 100644

tools/perf/builtin-stat.c static int __run_perf_stat(int argc, const char **argv, · line 692

Quoted 8 lines
tools/perf/builtin-stat.c +3 -1
@@ -686,8 +686,11 @@ static int __run_perf_stat(int argc, const char **argv,
 int run_idx) break;
 			}
 		}
-		if (child_pid != -1)
+		if (child_pid != -1) {
+			if (timeout)
+				kill(child_pid, SIGTERM);
 			wait4(child_pid, &status, 0, 

&stat_config.ru_data);

tools/perf/builtin-stat.c static int __run_perf_stat(int argc, const char **argv, int run_idx)

Quoted 4 lines
tools/perf/builtin-stat.c +1 -0
+		}
 
 		if (workload_exec_errno) {
 			const char *emsg = 

str_error_r(workload_exec_errno, msg, sizeof(msg));

Signature · 1 line
Инженер-разработчик Константин Харламов
#3 lore raw
In reply to Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     cfbd41b786519d4a15e1c15181556689bcf6635a
Gitweb:        https://git.kernel.org/tip/cfbd41b786519d4a15e1c15181556689bcf6635a
Author:        Arnaldo Carvalho de Melo <[email protected]>
AuthorDate:    Wed, 15 Apr 2020 12:31:26 -03:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Thu, 16 Apr 2020 12:17:41 -03:00

perf stat: Honour --timeout for forked workloads

When --timeout is used and a workload is specified to be started by 'perf stat', i.e.

  $ perf stat --timeout 1000 sleep 1h

The --timeout wasn't being honoured, i.e. the workload, 'sleep 1h' in the above example, should be terminated after 1000ms, but it wasn't, 'perf stat' was waiting for it to finish.

Fix it by sending a SIGTERM when the timeout expires.

Now it works:

  # perf stat -e cycles --timeout 1234 sleep 1h
  sleep: Terminated

Performance counter stats for 'sleep 1h':

           1,066,692      cycles

         1.234314838 seconds time elapsed

         0.000750000 seconds user
         0.000000000 seconds sys

#

Fixes f1f8ad52f8bf ("perf stat: Add support to print counts after a period of time")

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243

---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/builtin-stat.c +4 -1
index ec053dc..9207b6c 100644
@@ -686,8 +686,11 @@ try_again_reset:
 					break;
 			}
 		}
-		if (child_pid != -1)
+		if (child_pid != -1) {
+			if (timeout)
+				kill(child_pid, SIGTERM);
 			wait4(child_pid, &status, 0, &stat_config.ru_data);
+		}
 
 		if (workload_exec_errno) {
 			const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));