linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name
@ 2023-09-06 23:44 Ian Rogers
  2023-09-06 23:44 ` [PATCH v1 2/2] perf list pfm: Retry supported test with exclude_kernel Ian Rogers
  2023-09-12 19:18 ` [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2023-09-06 23:44 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Thomas Richter, Kan Liang,
	Zhengjun Xing, Kang Minchul, linux-perf-users, linux-kernel

Use the first core PMU instead.

On a Raspberry Pi, before:
```
$ perf list
...
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]
       [(see 'man perf-list' on how to encode it)]
...
```
After:
```

$ perf list
...
  armv8_cortex_a72/t1=v1[,t2=v2,t3 ...]/modifier     [Raw hardware event descriptor]
       [(see 'man perf-list' on how to encode it)]
...
```

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/print-events.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index a7566edc86a3..b0fc48be623f 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -395,6 +395,8 @@ void print_symbol_events(const struct print_callbacks *print_cb, void *print_sta
  */
 void print_events(const struct print_callbacks *print_cb, void *print_state)
 {
+	char *tmp;
+
 	print_symbol_events(print_cb, print_state, PERF_TYPE_HARDWARE,
 			event_symbols_hw, PERF_COUNT_HW_MAX);
 	print_symbol_events(print_cb, print_state, PERF_TYPE_SOFTWARE,
@@ -418,17 +420,21 @@ void print_events(const struct print_callbacks *print_cb, void *print_state)
 			/*long_desc=*/NULL,
 			/*encoding_desc=*/NULL);
 
-	print_cb->print_event(print_state,
-			/*topic=*/NULL,
-			/*pmu_name=*/NULL,
-			"cpu/t1=v1[,t2=v2,t3 ...]/modifier",
-			/*event_alias=*/NULL,
-			/*scale_unit=*/NULL,
-			/*deprecated=*/false,
-			event_type_descriptors[PERF_TYPE_RAW],
-			"(see 'man perf-list' on how to encode it)",
-			/*long_desc=*/NULL,
-			/*encoding_desc=*/NULL);
+	if (asprintf(&tmp, "%s/t1=v1[,t2=v2,t3 ...]/modifier",
+		     perf_pmus__scan_core(/*pmu=*/NULL)->name) > 0) {
+		print_cb->print_event(print_state,
+				/*topic=*/NULL,
+				/*pmu_name=*/NULL,
+				tmp,
+				/*event_alias=*/NULL,
+				/*scale_unit=*/NULL,
+				/*deprecated=*/false,
+				event_type_descriptors[PERF_TYPE_RAW],
+				"(see 'man perf-list' on how to encode it)",
+				/*long_desc=*/NULL,
+				/*encoding_desc=*/NULL);
+		free(tmp);
+	}
 
 	print_cb->print_event(print_state,
 			/*topic=*/NULL,
-- 
2.42.0.283.g2d96d420d3-goog


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

* [PATCH v1 2/2] perf list pfm: Retry supported test with exclude_kernel
  2023-09-06 23:44 [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name Ian Rogers
@ 2023-09-06 23:44 ` Ian Rogers
  2023-09-12 19:18 ` [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2023-09-06 23:44 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Thomas Richter, Kan Liang,
	Zhengjun Xing, Kang Minchul, linux-perf-users, linux-kernel

With paranoia set at 2 evsel__open will fail with EACCES for non-root
users. To avoid this stopping libpfm4 events from being printed, retry
with exclude_kernel enabled - copying the regular is_event_supported
test.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/pfm.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c
index 862e4a689868..5ccfe4b64cdf 100644
--- a/tools/perf/util/pfm.c
+++ b/tools/perf/util/pfm.c
@@ -145,7 +145,20 @@ static bool is_libpfm_event_supported(const char *name, struct perf_cpu_map *cpu
 
 	evsel->is_libpfm_event = true;
 
-	if (evsel__open(evsel, cpus, threads) < 0)
+	ret = evsel__open(evsel, cpus, threads);
+	if (ret == -EACCES) {
+		/*
+		 * This happens if the paranoid value
+		 * /proc/sys/kernel/perf_event_paranoid is set to 2
+		 * Re-run with exclude_kernel set; we don't do that
+		 * by default as some ARM machines do not support it.
+		 *
+		 */
+		evsel->core.attr.exclude_kernel = 1;
+		ret = evsel__open(evsel, cpus, threads);
+
+	}
+	if (ret < 0)
 		result = false;
 
 	evsel__close(evsel);
-- 
2.42.0.283.g2d96d420d3-goog


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

* Re: [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name
  2023-09-06 23:44 [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name Ian Rogers
  2023-09-06 23:44 ` [PATCH v1 2/2] perf list pfm: Retry supported test with exclude_kernel Ian Rogers
@ 2023-09-12 19:18 ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-09-12 19:18 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Adrian Hunter, Thomas Richter, Kan Liang,
	Zhengjun Xing, Kang Minchul, linux-perf-users, linux-kernel

Em Wed, Sep 06, 2023 at 04:44:15PM -0700, Ian Rogers escreveu:
> Use the first core PMU instead.
> 
> On a Raspberry Pi, before:
> ```
> $ perf list
> ...
>   cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]
>        [(see 'man perf-list' on how to encode it)]
> ...
> ```
> After:
> ```
> 
> $ perf list
> ...
>   armv8_cortex_a72/t1=v1[,t2=v2,t3 ...]/modifier     [Raw hardware event descriptor]
>        [(see 'man perf-list' on how to encode it)]
> ...
> ```

Thanks, applied the two patches.

- Arnaldo

 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/print-events.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index a7566edc86a3..b0fc48be623f 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -395,6 +395,8 @@ void print_symbol_events(const struct print_callbacks *print_cb, void *print_sta
>   */
>  void print_events(const struct print_callbacks *print_cb, void *print_state)
>  {
> +	char *tmp;
> +
>  	print_symbol_events(print_cb, print_state, PERF_TYPE_HARDWARE,
>  			event_symbols_hw, PERF_COUNT_HW_MAX);
>  	print_symbol_events(print_cb, print_state, PERF_TYPE_SOFTWARE,
> @@ -418,17 +420,21 @@ void print_events(const struct print_callbacks *print_cb, void *print_state)
>  			/*long_desc=*/NULL,
>  			/*encoding_desc=*/NULL);
>  
> -	print_cb->print_event(print_state,
> -			/*topic=*/NULL,
> -			/*pmu_name=*/NULL,
> -			"cpu/t1=v1[,t2=v2,t3 ...]/modifier",
> -			/*event_alias=*/NULL,
> -			/*scale_unit=*/NULL,
> -			/*deprecated=*/false,
> -			event_type_descriptors[PERF_TYPE_RAW],
> -			"(see 'man perf-list' on how to encode it)",
> -			/*long_desc=*/NULL,
> -			/*encoding_desc=*/NULL);
> +	if (asprintf(&tmp, "%s/t1=v1[,t2=v2,t3 ...]/modifier",
> +		     perf_pmus__scan_core(/*pmu=*/NULL)->name) > 0) {
> +		print_cb->print_event(print_state,
> +				/*topic=*/NULL,
> +				/*pmu_name=*/NULL,
> +				tmp,
> +				/*event_alias=*/NULL,
> +				/*scale_unit=*/NULL,
> +				/*deprecated=*/false,
> +				event_type_descriptors[PERF_TYPE_RAW],
> +				"(see 'man perf-list' on how to encode it)",
> +				/*long_desc=*/NULL,
> +				/*encoding_desc=*/NULL);
> +		free(tmp);
> +	}
>  
>  	print_cb->print_event(print_state,
>  			/*topic=*/NULL,
> -- 
> 2.42.0.283.g2d96d420d3-goog
> 

-- 

- Arnaldo

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

end of thread, other threads:[~2023-09-12 19:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-06 23:44 [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name Ian Rogers
2023-09-06 23:44 ` [PATCH v1 2/2] perf list pfm: Retry supported test with exclude_kernel Ian Rogers
2023-09-12 19:18 ` [PATCH v1 1/2] perf list: Avoid a hardcoded cpu PMU name 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;
as well as URLs for NNTP newsgroup(s).