linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified
@ 2021-09-27  8:11 Like Xu
  2021-09-27  8:11 ` [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *' Like Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Like Xu @ 2021-09-27  8:11 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers
  Cc: Alexander Antonov, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Mark Rutland, Stephane Eranian, Peter Zijlstra, Ingo Molnar,
	linux-perf-users, linux-kernel

From: Like Xu <likexu@tencent.com>

An iostate use case like "perf iostat 0000:16,0000:97 -- ls" should be
implemented to work in system-wide mode to ensure that the output from
print_header() is consistent with the user documentation perf-iostat.txt,
rather than incorrectly assuming that the kernel does not support it:

 Error:
 The sys_perf_event_open() syscall returned with 22 (Invalid argument) \
 for event (uncore_iio_0/event=0x83,umask=0x04,ch_mask=0xF,fc_mask=0x07/).
 /bin/dmesg | grep -i perf may provide additional information.

This error is easily fixed by assigning system-wide mode by default
for IOSTAT_RUN only when the target cpu_list is unspecified.

Signed-off-by: Like Xu <likexu@tencent.com>
---
 tools/perf/builtin-stat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index f6e87b7be5fa..f0ecfda34ece 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2408,6 +2408,8 @@ int cmd_stat(int argc, const char **argv)
 			goto out;
 		} else if (verbose)
 			iostat_list(evsel_list, &stat_config);
+		if (iostat_mode == IOSTAT_RUN && !target__has_cpu(&target))
+			target.system_wide = true;
 	}
 
 	if (add_default_attributes())
-- 
2.32.0


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

* [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *'
  2021-09-27  8:11 [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Like Xu
@ 2021-09-27  8:11 ` Like Xu
  2021-09-27 12:42   ` Arnaldo Carvalho de Melo
  2021-09-27 12:40 ` [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Arnaldo Carvalho de Melo
  2021-09-28  9:06 ` Alexander Antonov
  2 siblings, 1 reply; 5+ messages in thread
From: Like Xu @ 2021-09-27  8:11 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Ian Rogers
  Cc: Alexander Antonov, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Mark Rutland, Stephane Eranian, Peter Zijlstra, Ingo Molnar,
	linux-perf-users, linux-kernel

From: Like Xu <likexu@tencent.com>

If the perf-iostat user specifies two or more iio_root_ports and
also specifies the cpu(s) by -C which is not *connected to all*
the above iio ports, the iostat_print_metric() will run into trouble:

For example:

 $ perf iostat list
 S0-uncore_iio_0<0000:16>
 S1-uncore_iio_0<0000:97> # <--- CPU 1 is located in the socket S0

 $ perf iostat 0000:16,0000:97 -C 1 -- ls
 port 	Inbound Read(MB)	Inbound Write(MB)	Outbound Read(MB)	Outbound
 Write(MB) ../perf-iostat: line 12: 104418 Segmentation fault
 (core dumped) perf stat --iostat$DELIMITER$*

The core-dump stack says, in the above corner case, the returned
(struct perf_counts_values *) count will be NULL, and the caller
iostat_print_metric() apparently doesn't not handle this case.

 433	struct perf_counts_values *count = perf_counts(evsel->counts, die, 0);
 434
 435	if (count->run && count->ena) {
 (gdb) p count
 $1 = (struct perf_counts_values *) 0x0

The deeper reason is that there are actually no statistics from the user
specified pair "iostat 0000:X, -C (disconnected) Y ", but let's fix it with
minimum cost by adding a NULL check in the user space.

Signed-off-by: Like Xu <likexu@tencent.com>
---
 tools/perf/arch/x86/util/iostat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
index eeafe97b8105..792cd75ade33 100644
--- a/tools/perf/arch/x86/util/iostat.c
+++ b/tools/perf/arch/x86/util/iostat.c
@@ -432,7 +432,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
 	u8 die = ((struct iio_root_port *)evsel->priv)->die;
 	struct perf_counts_values *count = perf_counts(evsel->counts, die, 0);
 
-	if (count->run && count->ena) {
+	if (count && count->run && count->ena) {
 		if (evsel->prev_raw_counts && !out->force_header) {
 			struct perf_counts_values *prev_count =
 				perf_counts(evsel->prev_raw_counts, die, 0);
-- 
2.32.0


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

* Re: [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified
  2021-09-27  8:11 [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Like Xu
  2021-09-27  8:11 ` [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *' Like Xu
@ 2021-09-27 12:40 ` Arnaldo Carvalho de Melo
  2021-09-28  9:06 ` Alexander Antonov
  2 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-27 12:40 UTC (permalink / raw)
  To: Like Xu
  Cc: Ian Rogers, Alexander Antonov, Jiri Olsa, Alexander Shishkin,
	Namhyung Kim, Mark Rutland, Stephane Eranian, Peter Zijlstra,
	Ingo Molnar, linux-perf-users, linux-kernel

Em Mon, Sep 27, 2021 at 04:11:14PM +0800, Like Xu escreveu:
> From: Like Xu <likexu@tencent.com>
> 
> An iostate use case like "perf iostat 0000:16,0000:97 -- ls" should be
> implemented to work in system-wide mode to ensure that the output from
> print_header() is consistent with the user documentation perf-iostat.txt,
> rather than incorrectly assuming that the kernel does not support it:
> 
>  Error:
>  The sys_perf_event_open() syscall returned with 22 (Invalid argument) \
>  for event (uncore_iio_0/event=0x83,umask=0x04,ch_mask=0xF,fc_mask=0x07/).
>  /bin/dmesg | grep -i perf may provide additional information.
> 
> This error is easily fixed by assigning system-wide mode by default
> for IOSTAT_RUN only when the target cpu_list is unspecified.

Looks ok, added:

Fixes: f07952b179697771 ("perf stat: Basic support for iostat in perf")

For stable@vger.kernel.org sake.

- Arnaldo
 
> Signed-off-by: Like Xu <likexu@tencent.com>
> ---
>  tools/perf/builtin-stat.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index f6e87b7be5fa..f0ecfda34ece 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -2408,6 +2408,8 @@ int cmd_stat(int argc, const char **argv)
>  			goto out;
>  		} else if (verbose)
>  			iostat_list(evsel_list, &stat_config);
> +		if (iostat_mode == IOSTAT_RUN && !target__has_cpu(&target))
> +			target.system_wide = true;
>  	}
>  
>  	if (add_default_attributes())
> -- 
> 2.32.0

-- 

- Arnaldo

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

* Re: [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *'
  2021-09-27  8:11 ` [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *' Like Xu
@ 2021-09-27 12:42   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-27 12:42 UTC (permalink / raw)
  To: Like Xu
  Cc: Ian Rogers, Alexander Antonov, Jiri Olsa, Alexander Shishkin,
	Namhyung Kim, Mark Rutland, Stephane Eranian, Peter Zijlstra,
	Ingo Molnar, linux-perf-users, linux-kernel

Em Mon, Sep 27, 2021 at 04:11:15PM +0800, Like Xu escreveu:
> From: Like Xu <likexu@tencent.com>
> 
> If the perf-iostat user specifies two or more iio_root_ports and
> also specifies the cpu(s) by -C which is not *connected to all*
> the above iio ports, the iostat_print_metric() will run into trouble:
> 
> For example:
> 
>  $ perf iostat list
>  S0-uncore_iio_0<0000:16>
>  S1-uncore_iio_0<0000:97> # <--- CPU 1 is located in the socket S0
> 
>  $ perf iostat 0000:16,0000:97 -C 1 -- ls
>  port 	Inbound Read(MB)	Inbound Write(MB)	Outbound Read(MB)	Outbound
>  Write(MB) ../perf-iostat: line 12: 104418 Segmentation fault
>  (core dumped) perf stat --iostat$DELIMITER$*
> 
> The core-dump stack says, in the above corner case, the returned
> (struct perf_counts_values *) count will be NULL, and the caller
> iostat_print_metric() apparently doesn't not handle this case.
> 
>  433	struct perf_counts_values *count = perf_counts(evsel->counts, die, 0);
>  434
>  435	if (count->run && count->ena) {
>  (gdb) p count
>  $1 = (struct perf_counts_values *) 0x0
> 
> The deeper reason is that there are actually no statistics from the user
> specified pair "iostat 0000:X, -C (disconnected) Y ", but let's fix it with
> minimum cost by adding a NULL check in the user space.

Added:

Fixes: f9ed693e8bc0e7de ("perf stat: Enable iostat mode for x86 platforms")

Please do that next time,

- Arnaldo
 
> Signed-off-by: Like Xu <likexu@tencent.com>
> ---
>  tools/perf/arch/x86/util/iostat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/iostat.c
> index eeafe97b8105..792cd75ade33 100644
> --- a/tools/perf/arch/x86/util/iostat.c
> +++ b/tools/perf/arch/x86/util/iostat.c
> @@ -432,7 +432,7 @@ void iostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
>  	u8 die = ((struct iio_root_port *)evsel->priv)->die;
>  	struct perf_counts_values *count = perf_counts(evsel->counts, die, 0);
>  
> -	if (count->run && count->ena) {
> +	if (count && count->run && count->ena) {
>  		if (evsel->prev_raw_counts && !out->force_header) {
>  			struct perf_counts_values *prev_count =
>  				perf_counts(evsel->prev_raw_counts, die, 0);
> -- 
> 2.32.0

-- 

- Arnaldo

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

* Re: [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified
  2021-09-27  8:11 [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Like Xu
  2021-09-27  8:11 ` [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *' Like Xu
  2021-09-27 12:40 ` [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Arnaldo Carvalho de Melo
@ 2021-09-28  9:06 ` Alexander Antonov
  2 siblings, 0 replies; 5+ messages in thread
From: Alexander Antonov @ 2021-09-28  9:06 UTC (permalink / raw)
  To: Like Xu, Arnaldo Carvalho de Melo, Ian Rogers
  Cc: Jiri Olsa, Alexander Shishkin, Namhyung Kim, Mark Rutland,
	Stephane Eranian, Peter Zijlstra, Ingo Molnar, linux-perf-users,
	linux-kernel

On 9/27/2021 11:11 AM, Like Xu wrote:
> From: Like Xu <likexu@tencent.com>
>
> An iostate use case like "perf iostat 0000:16,0000:97 -- ls" should be
> implemented to work in system-wide mode to ensure that the output from
> print_header() is consistent with the user documentation perf-iostat.txt,
> rather than incorrectly assuming that the kernel does not support it:
>
>   Error:
>   The sys_perf_event_open() syscall returned with 22 (Invalid argument) \
>   for event (uncore_iio_0/event=0x83,umask=0x04,ch_mask=0xF,fc_mask=0x07/).
>   /bin/dmesg | grep -i perf may provide additional information.
>
> This error is easily fixed by assigning system-wide mode by default
> for IOSTAT_RUN only when the target cpu_list is unspecified.
Hello,
Thank you for your fixes.

Tested-by: Alexander Antonov <alexander.antonov@linux.intel.com>
> Signed-off-by: Like Xu <likexu@tencent.com>
> ---
>   tools/perf/builtin-stat.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index f6e87b7be5fa..f0ecfda34ece 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -2408,6 +2408,8 @@ int cmd_stat(int argc, const char **argv)
>   			goto out;
>   		} else if (verbose)
>   			iostat_list(evsel_list, &stat_config);
> +		if (iostat_mode == IOSTAT_RUN && !target__has_cpu(&target))
> +			target.system_wide = true;
>   	}
>   
>   	if (add_default_attributes())

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

end of thread, other threads:[~2021-09-28  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27  8:11 [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Like Xu
2021-09-27  8:11 ` [PATCH 2/2] perf iostat: Fix Segmentation fault from NULL 'struct perf_counts_values *' Like Xu
2021-09-27 12:42   ` Arnaldo Carvalho de Melo
2021-09-27 12:40 ` [PATCH 1/2] perf iostat: Use system-wide mode if the target cpu_list is unspecified Arnaldo Carvalho de Melo
2021-09-28  9:06 ` Alexander Antonov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).