perf list: Avoid a hardcoded cpu PMU name
Ian Rogers
reviewerPATCH 1/2 perf list: Avoid a hardcoded cpu PMU name
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 <[email protected]>
--- tools/perf/util/print-events.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
tools/perf/util/print-events.c +17 -11
@@ -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,
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Ian Rogers
reviewerPATCH 2/2 perf list pfm: Retry supported test with exclude_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 <[email protected]>
--- tools/perf/util/pfm.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
tools/perf/util/pfm.c +14 -1
@@ -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);
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Em Wed, Sep 06, 2023 at 04:44:15PM -0700, Ian Rogers escreveu:
Quoted 19 lines
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
Quoted 54 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/util/print-events.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)tools/perf/util/print-events.c +17
-11@@ -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,Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Signature · 1 line
- Arnaldo