public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf stat: Honour --timeout for forked workloads
@ 2020-04-15 15:38 Arnaldo Carvalho de Melo
  2020-04-15 16:25 ` Jiri Olsa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-04-15 15:38 UTC (permalink / raw)
  To: Jiri Olsa, Namhyung Kim
  Cc: Konstantin Kharlamov, Adrian Hunter, Linux Kernel Mailing List,
	linux-perf-users

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

  #

Reported-by: Konstantin Kharlamov <hi-angel@yandex.ru>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index ec053dc1e35c..9207b6c45475 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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));
-- 
2.25.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf stat: Honour --timeout for forked workloads
  2020-04-15 15:38 [PATCH] perf stat: Honour --timeout for forked workloads Arnaldo Carvalho de Melo
@ 2020-04-15 16:25 ` Jiri Olsa
  2020-04-15 16:46 ` Konstantin Kharlamov
  2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 4+ messages in thread
From: Jiri Olsa @ 2020-04-15 16:25 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Namhyung Kim, Konstantin Kharlamov, Adrian Hunter,
	Linux Kernel Mailing List, linux-perf-users, yuzhoujian

On Wed, Apr 15, 2020 at 12:38:03PM -0300, 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
> 
>   #
> 
> Reported-by: Konstantin Kharlamov <hi-angel@yandex.ru>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Acked/Tested-by: Jiri Olsa <jolsa@redhat.com>

cc-ing yuzhoujian, author of the --timeout

jirka

> ---
>  tools/perf/builtin-stat.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index ec053dc1e35c..9207b6c45475 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -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));
> -- 
> 2.25.2
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf stat: Honour --timeout for forked workloads
  2020-04-15 15:38 [PATCH] perf stat: Honour --timeout for forked workloads Arnaldo Carvalho de Melo
  2020-04-15 16:25 ` Jiri Olsa
@ 2020-04-15 16:46 ` Konstantin Kharlamov
  2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Kharlamov @ 2020-04-15 16:46 UTC (permalink / raw)
  To: Jiri Olsa, Namhyung Kim, Arnaldo Carvalho de Melo
  Cc: Adrian Hunter, Linux Kernel Mailing List, linux-perf-users

Tested-by: Konstantin Kharlamov <hi-angel@yandex.ru>

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
> 
>   #
> 
> Reported-by: Konstantin Kharlamov <hi-angel@yandex.ru>
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/builtin-stat.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index ec053dc1e35c..9207b6c45475 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -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));


-- 
Инженер-разработчик Константин Харламов



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: perf/core] perf stat: Honour --timeout for forked workloads
  2020-04-15 15:38 [PATCH] perf stat: Honour --timeout for forked workloads Arnaldo Carvalho de Melo
  2020-04-15 16:25 ` Jiri Olsa
  2020-04-15 16:46 ` Konstantin Kharlamov
@ 2020-04-22 12:17 ` tip-bot2 for Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Arnaldo Carvalho de Melo @ 2020-04-22 12:17 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Konstantin Kharlamov, Adrian Hunter, Jiri Olsa, Namhyung Kim,
	yuzhoujian, Arnaldo Carvalho de Melo, x86, LKML

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 <acme@redhat.com>
AuthorDate:    Wed, 15 Apr 2020 12:31:26 -03:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
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")
Reported-by: Konstantin Kharlamov <hi-angel@yandex.ru>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207243
Tested-by: Konstantin Kharlamov <hi-angel@yandex.ru>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: yuzhoujian <yuzhoujian@didichuxing.com>
Link: https://lore.kernel.org/lkml/20200415153803.GB20324@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index ec053dc..9207b6c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -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));

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-22 12:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-15 15:38 [PATCH] perf stat: Honour --timeout for forked workloads Arnaldo Carvalho de Melo
2020-04-15 16:25 ` Jiri Olsa
2020-04-15 16:46 ` Konstantin Kharlamov
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox