perf top: Use evsel's cpus to replace user_requested_cpus
PATCH 1/1 perf top: Use evsel's cpus to replace user_requested_cpus
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf top
Error:
The cycles:P event is not supported.
The user_requested_cpus may contain CPUs that are invalid for a hybrid PMU. It causes perf_event_open to fail.
The commit ef91871c960e ("perf evlist: Propagate user CPU maps intersecting core PMU maps") already intersect the requested CPU map with the CPU map of the PMU. Use the evsel's cpus to replace user_requested_cpus.
The evlist's threads is also propagated to evsel's threads in __perf_evlist__propagate_maps(). Replace it as well.
--- tools/perf/builtin-top.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +2 -2
@@ -1027,8 +1027,8 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again: -if (evsel__open (counter, top->evlist->core.user_requested_cpus, - top->evlist->core.threads) <0 ) { +if (evsel__open (counter, counter->core.cpus, + counter->core.threads) <0 ) {/* * Specially handle overwrite fall back.
Signature · 1 line
2.35.1
Arnaldo Carvalho de Melo
maintainerEm Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.
?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 7 lines
The commit
ef91871c960e("perf evlist: Propagate user CPU maps intersecting core PMU maps") already intersect the requested CPU map with the CPU map of the PMU. Use the evsel's cpus to replaceuser_requested_cpus.The evlist's threads is also propagated to evsel's threads in
__perf_evlist__propagate_maps(). Replace it as well.
Thanks, but please try to add more detail to the fix so as to help others to consider looking at the patch.
- Arnaldo
Quoted 25 lines
Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-top.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/builtin-top.c +2
-2@@ -1027,8 +1027,8 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again: -if (evsel__open (counter, top->evlist->core.user_requested_cpus, - top->evlist->core.threads) <0 ) { +if (evsel__open (counter, counter->core.cpus, + counter->core.threads) <0 ) {/* * Specially handle overwrite fall back. Signature · 1 line
2.35.1
Signature · 1 line
- Arnaldo
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 8 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.
Quoted 8 lines
Quoted 2 lines
The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs. Perf has to split it into two cycles events, cpu_core/cycles/ and cpu_atom/cycles/. Each event has its own CPU mask. If a event is opened on the unsupported CPU. The open fails. That's the reason perf top fails. So perf should only open the cycles event on the corresponding CPU.
Quoted 10 lines
Quoted 7 lines
The commit
ef91871c960e("perf evlist: Propagate user CPU maps intersecting core PMU maps") already intersect the requested CPU map with the CPU map of the PMU. Use the evsel's cpus to replaceuser_requested_cpus.The evlist's threads is also propagated to evsel's threads in
__perf_evlist__propagate_maps(). Replace it as well.Thanks, but please try to add more detail to the fix so as to help others to consider looking at the patch.
OK. For the threads, the same as other tools, e.g., perf record, perf appends a dummy for the system wide event. For a per-thread event, the evlist's thread_map is assigned to the evsel. So using the evsel's threads is appropriate and also be consistent with other tools.
I will update the description and send a V2.
Thanks,
Kan
Quoted 29 lines
- Arnaldo
Quoted 25 lines
Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-top.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/builtin-top.c +2
-2@@ -1027,8 +1027,8 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again: -if (evsel__open (counter, top->evlist->core.user_requested_cpus, - top->evlist->core.threads) <0 ) { +if (evsel__open (counter, counter->core.cpus, + counter->core.threads) <0 ) {/* * Specially handle overwrite fall back. Signature · 1 line
2.35.1
Arnaldo Carvalho de Melo
maintainerEm Tue, Dec 12, 2023 at 10:56:15AM -0500, Liang, Kan escreveu:
Quoted 20 lines · Arnaldo Carvalho de Melo
Quoted 9 lines
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 8 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.Quoted 7 lines
Quoted 2 lines
The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 6 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs. Perf has to split it into two cycles events, cpu_core/cycles/ and cpu_atom/cycles/. Each event has its own CPU mask. If a event is opened on the unsupported CPU. The open fails. That's the reason perf top fails. So perf should only open the cycles event on the corresponding CPU.
Great explanation, please make sure it is present in the fix, i.e. in the v2 you mentioned.
Quoted 46 lines
Quoted 10 lines
Quoted 7 lines
The commit
ef91871c960e("perf evlist: Propagate user CPU maps intersecting core PMU maps") already intersect the requested CPU map with the CPU map of the PMU. Use the evsel's cpus to replaceuser_requested_cpus.The evlist's threads is also propagated to evsel's threads in
__perf_evlist__propagate_maps(). Replace it as well.Thanks, but please try to add more detail to the fix so as to help others to consider looking at the patch.
OK. For the threads, the same as other tools, e.g., perf record, perf appends a dummy for the system wide event. For a per-thread event, the evlist's
thread_mapis assigned to the evsel. So using the evsel's threads is appropriate and also be consistent with other tools.I will update the description and send a V2.
Thanks,
KanQuoted 25 lines
- Arnaldo
Quoted 22 lines
Reported-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Kan Liang <[email protected]>--- tools/perf/builtin-top.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/builtin-top.c +2
-2@@ -1027,8 +1027,8 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again: -if (evsel__open (counter, top->evlist->core.user_requested_cpus, - top->evlist->core.threads) <0 ) { +if (evsel__open (counter, counter->core.cpus, + counter->core.threads) <0 ) {/* * Specially handle overwrite fall back.
Namhyung Kim
maintainerQuoted 16 lines · Kan
Quoted 12 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.
Quoted 8 lines
Quoted 5 lines
?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
Thanks,
Namhyung
Ian Rogers
reviewerQuoted 24 lines · Namhyung Kim
Quoted 22 lines · Kan
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 5 lines
Quoted 2 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
I believe not. When the extended type isn't set on legacy cycles we often have the CPU and from that can determine the PMU. The issue is with the -1 any CPU perf_event_open option. As I was told, the PMU the event is opened on in this case is the first one registered in the kernel, on Intel hybrid this could be cpu_core or cpu_atom.. but IIRC it'll probably be cpu_core. On ARM ¯\_(ツ)_/¯. In any case you only have an event that will be enabled on a fraction of the CPU cores the thread you are monitoring could be scheduled on. This is why 2 or more events are needed (depending on how many core types you have).
Thanks,
Ian
Quoted 2 lines
Thanks,
Namhyung
Mark Rutland
reviewerQuoted 31 lines · Ian Rogers
Quoted 24 lines · Namhyung Kim
Quoted 22 lines · Kan
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 5 lines
Quoted 2 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
Quoted 6 lines
I believe not. When the extended type isn't set on legacy cycles we often have the CPU and from that can determine the PMU. The issue is with the -1 any CPU
perf_event_openoption. As I was told, the PMU the event is opened on in this case is the first one registered in the kernel, on Intel hybrid this could becpu_coreorcpu_atom.. but IIRC it'll probably becpu_core. On ARM ¯\_(ツ)_/¯.
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by perf_init_event() when iterating over the 'pmus' list.
If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when perf_init_event() iterates over the 'pmus' list.
Mark.
Namhyung Kim
maintainerQuoted 40 lines · Mark Rutland
Quoted 31 lines · Ian Rogers
Quoted 24 lines · Namhyung Kim
Quoted 22 lines · Kan
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 5 lines
Quoted 2 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
Quoted 6 lines
I believe not. When the extended type isn't set on legacy cycles we often have the CPU and from that can determine the PMU. The issue is with the -1 any CPU
perf_event_openoption. As I was told, the PMU the event is opened on in this case is the first one registered in the kernel, on Intel hybrid this could becpu_coreorcpu_atom.. but IIRC it'll probably becpu_core. On ARM ¯\_(ツ)_/¯.
Quoted 8 lines
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.
Ok, that means "cycles" with cpu == -1 would not work well.
I'm curious if it's possible to do some basic work at the event_init() like to preserve (common) resource and to do some other work at sched to config PMU on the current CPU. So that users can simply use "cycles" or "instructions" for their processes.
Thanks,
Namhyung
Quoted 46 lines · Namhyung Kim
Quoted 45 lines · Mark Rutland
Quoted 31 lines · Ian Rogers
Quoted 24 lines · Namhyung Kim
Quoted 22 lines · Kan
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 5 lines
Quoted 2 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
Quoted 6 lines
I believe not. When the extended type isn't set on legacy cycles we often have the CPU and from that can determine the PMU. The issue is with the -1 any CPU
perf_event_openoption. As I was told, the PMU the event is opened on in this case is the first one registered in the kernel, on Intel hybrid this could becpu_coreorcpu_atom.. but IIRC it'll probably becpu_core. On ARM ¯\_(ツ)_/¯.On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.
Quoted 6 lines
Quoted 3 lines
If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.Ok, that means "cycles" with cpu == -1 would not work well.
Unless a PMU is specified.
Quoted 5 lines
I'm curious if it's possible to do some basic work at the
event_init()like to preserve (common) resource and to do some other work at sched to config PMU on the current CPU. So that users can simply use "cycles" or "instructions" for their processes.
The current code treats the hybrid as two standalone PMUs. To preserve the common resource in the other PMU, I think the only way is to create an event on the other PMU. It's what perf tool does now. I don't think we want to move the logic to the kernel.
I think a possible way is to abstract a common PMU (cpu) which only includes common PMU features. It should be doable, because without the enabling code of hybrid, the default PMU is the common PMU. But I don't know how does it coexist with the other hybrid PMUs if we have both common PMU and hybrid PMUs available? It may just bring more complexity.
Thanks,
Kan
Mark Rutland
reviewerQuoted 62 lines · Kan
Quoted 46 lines · Namhyung Kim
Quoted 45 lines · Mark Rutland
Quoted 31 lines · Ian Rogers
Quoted 24 lines · Namhyung Kim
Quoted 22 lines · Kan
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 5 lines
Quoted 2 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
Quoted 6 lines
I believe not. When the extended type isn't set on legacy cycles we often have the CPU and from that can determine the PMU. The issue is with the -1 any CPU
perf_event_openoption. As I was told, the PMU the event is opened on in this case is the first one registered in the kernel, on Intel hybrid this could becpu_coreorcpu_atom.. but IIRC it'll probably becpu_core. On ARM ¯\_(ツ)_/¯.On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.Quoted 5 lines
Quoted 3 lines
If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.Ok, that means "cycles" with cpu == -1 would not work well.
Unless a PMU is specified.
Quoted 4 lines
I'm curious if it's possible to do some basic work at the
event_init()like to preserve (common) resource and to do some other work at sched to config PMU on the current CPU. So that users can simply use "cycles" or "instructions" for their processes.
Quoted 4 lines
The current code treats the hybrid as two standalone PMUs. To preserve the common resource in the other PMU, I think the only way is to create an event on the other PMU. It's what perf tool does now. I don't think we want to move the logic to the kernel.
Agreed.
Quoted 5 lines
I think a possible way is to abstract a common PMU (cpu) which only includes common PMU features. It should be doable, because without the enabling code of hybrid, the default PMU is the common PMU. But I don't know how does it coexist with the other hybrid PMUs if we have both common PMU and hybrid PMUs available? It may just bring more complexity.
I think that brings a surprising amount of complexity, and I'm not entirely sure if that's practical (since you'd effectively end up with a logical PMU being dependent on multiple other logical PMUs).
I also think that it's practically necessary to expose the counts to the user separately, even for common events. For example, the 'instructions' event may count differently (speculative vs architectural execution), and 'cycles' can be wildly different across microarchitectures due to realizable IPC, and blindly adding those up across PMUs is liable to produce a misleading figure (and/or one with massive variation).
While it is ugly, I think that it's necessary for userspace to discover the set of CPU PMUs and open seperate events on them in order to produce useful data.
Specifically for perf top, if one is monitoring all CPUs, it'd be fine to open a PERF_TYPE_HARDWARE event for each CPU; so long as cpu!=-1 it would go to the relevant PMU and be counted as expected.
Thanks,
Mark.
Ian Rogers
reviewerQuoted 51 lines · Namhyung Kim
Quoted 40 lines · Mark Rutland
Quoted 31 lines · Ian Rogers
Quoted 24 lines · Namhyung Kim
Quoted 22 lines · Kan
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 08, 2023 at 01:08:55PM -0800, [email protected] escreveu:
Quoted 10 lines
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.?
All perf top expects is that the "cycles", the most basic one, be collected, on all CPUs in the system.
Quoted 5 lines
Quoted 2 lines
Yes, but for hybrid there is no single "cycles" event which can cover all CPUs.
Does that mean the kernel would reject the legacy "cycles" event on hybrid CPUs?
Quoted 6 lines
I believe not. When the extended type isn't set on legacy cycles we often have the CPU and from that can determine the PMU. The issue is with the -1 any CPU
perf_event_openoption. As I was told, the PMU the event is opened on in this case is the first one registered in the kernel, on Intel hybrid this could becpu_coreorcpu_atom.. but IIRC it'll probably becpu_core. On ARM ¯\_(ツ)_/¯.Quoted 8 lines
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.
Quoted 6 lines
Ok, that means "cycles" with cpu == -1 would not work well.
I'm curious if it's possible to do some basic work at the
event_init()like to preserve (common) resource and to do some other work at sched to config PMU on the current CPU. So that users can simply use "cycles" or "instructions" for their processes.
It should be possible to make things better, especially for standard events for cycles or instructions, for software that isn't aware of multiple core PMUs and the extended type field. There are legacy events like dTLB-speculative-read that may be supported by 1 PMU and not the other, so what should happen with thread scheduling there?
On RISC-V there was discussion of the legacy to pmu/config mapping that happens in the driver being something that is handled in the tool. A lot of the legacy events end up being "<not supported>" which is a pretty bad user experience, like this on AMD:
```
# perf stat -d -a sleep 1
Performance counter stats for 'system wide':
259,256.21 msec cpu-clock # 257.445
CPUs utilized
11,931 context-switches # 46.020
/sec
264 cpu-migrations # 1.018
/sec
419 page-faults # 1.616
/sec
5,892,812,250 cycles # 0.023
GHz (62.43%)
1,159,909,806 stalled-cycles-frontend # 19.68%
frontend cycles idle (62.48%)
831,668,644 stalled-cycles-backend # 14.11%
backend cycles idle (62.52%)
2,825,351,898 instructions # 0.48
insn per cycle
# 0.41 stalled
cycles per insn (62.54%)
520,403,374 branches # 2.007
M/sec (62.57%)
12,050,970 branch-misses # 2.32% of
all branches (62.55%)
1,117,382,209 L1-dcache-loads # 4.310
M/sec (62.48%)
61,060,457 L1-dcache-load-misses # 5.46% of
all L1-dcache accesses (62.43%)
<not supported> LLC-loads
<not supported> LLC-load-misses
1.007033432 seconds time elapsed
```So I think the move should be away from legacy events but that doesn't necessarily mean we can't make them better.
Thanks,
Ian
Quoted 2 lines
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerEm Tue, Dec 12, 2023 at 06:31:05PM +0000, Mark Rutland escreveu:
Quoted 8 lines
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.
The way that it is working non on my intel hybrid system, with Kan's patch, is equivalent to using this on the RK3399pc board I have:
root@roc-rk3399-pc:~# perf top -e armv8_cortex_a72/cycles/P,armv8_cortex_a53/cycles/P
Wouldn't be better to make 'perf top' on ARM work the way is being done in x86 now, i.e. default to opening the two events, one per PMU and allow the user to switch back and forth using the TUI/stdio?
Kan, I also noticed that the name of the event is:
1K cpu_atom/cycles:P/ ◆
11K cpu_core/cycles:P/
If I try to use that on the command line:
root@number:~# perf top -e cpu_atom/cycles:P/
event syntax error: 'cpu_atom/cycles:P/'
\___ Bad event or PMUUnable to find PMU or event on a PMU of 'cpu_atom'
Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu 'cpu_atom'
valid terms: event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware Run 'perf list' for a list of valid events
Usage: perf top [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
root@number:~#
It should be:
"cpu_atom/cycles/P"
- Arnaldo
Mark Rutland
reviewerQuoted 10 lines · Arnaldo Carvalho de Melo
Em Tue, Dec 12, 2023 at 06:31:05PM +0000, Mark Rutland escreveu:
Quoted 8 lines
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.
Quoted 8 lines
The way that it is working non on my intel hybrid system, with Kan's patch, is equivalent to using this on the RK3399pc board I have:
root@roc-rk3399-pc:~# perf top -e armv8_cortex_a72/cycles/P,armv8_cortex_a53/cycles/PWouldn't be better to make 'perf top' on ARM work the way is being done in x86 now, i.e. default to opening the two events, one per PMU and allow the user to switch back and forth using the TUI/stdio?
TBH, for perf top I don't know *which* behaviour is preferable, but I agree that it'd be good for x86 and arm to work in the same way.
For design-cleanliness and consistency with other commands I can see that opening those separately is probably for the best, but for typical usage of perf top it's really nice to have those presented together without having to tab back-and-forth between the distinct PMUs, and so the existing behaviour of using CPU-bound PERF_EVENT_TYPE_HARDWARE events is arguably nicer for the user.
I don't have a strong feeling either way; I'm personally happy so long as explicit pmu_name/event/ events don't get silently converted into PERF_EVENT_TYPE_HARDWARE events, and as long as we correctly set the extended HW type when we decide to use that.
Thanks,
Mark.
Quoted 30 lines
Kan, I also noticed that the name of the event is:
1K cpu_atom/cycles:P/ ◆
11K cpu_core/cycles:P/If I try to use that on the command line:
root@number:~# perf top -e cpu_atom/cycles:P/ event syntax error: 'cpu_atom/cycles:P/' \___ Bad event or PMUUnable to find PMU or event on a PMU of '
cpu_atom'Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu 'cpu_atom'valid terms: event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware Run 'perf list' for a list of valid events
Usage: perf top [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
root@number:~#It should be:
"cpu_atom/cycles/P"
- Arnaldo
Arnaldo Carvalho de Melo
maintainerEm Fri, Dec 15, 2023 at 04:51:49PM +0000, Mark Rutland escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 12 lines
Em Tue, Dec 12, 2023 at 06:31:05PM +0000, Mark Rutland escreveu:
Quoted 8 lines
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.The way that it is working non on my intel hybrid system, with Kan's patch, is equivalent to using this on the RK3399pc board I have:
Quoted 8 lines
Quoted 5 lines
root@roc-rk3399-pc:~# perf top -e armv8_cortex_a72/cycles/P,armv8_cortex_a53/cycles/PWouldn't be better to make 'perf top' on ARM work the way is being done in x86 now, i.e. default to opening the two events, one per PMU and allow the user to switch back and forth using the TUI/stdio?
TBH, for perf top I don't know *which* behaviour is preferable, but I agree that it'd be good for x86 and arm to work in the same way.
Right, reducing the difference in the user experience accross arches.
Quoted 4 lines
For design-cleanliness and consistency with other commands I can see that opening those separately is probably for the best, but for typical usage of perf top it's really nice to have those presented together without having to tab back-and-forth between the distinct PMUs, and so the existing behaviour of
Humm, so you would want two histogram viewers, one for each PMU, side by side?
Quoted 1 line
using CPU-bound
PERF_EVENT_TYPE_HARDWAREevents is arguably nicer for the user.
So, on ARM64, start the following 'perf trace' session, then run the stock 'perf top':
root@roc-rk3399-pc:~# perf trace -e perf_event_open
<SNIP calls doing capability queries and setting up sideband stuff>
535.764 ( 0.015 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 19
535.783 ( 0.067 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 28
535.854 ( 0.063 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 29
535.920 ( 0.015 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 30
535.939 ( 0.016 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 4, group_fd: -1, flags: FD_CLOEXEC) = 31
535.959 ( 0.011 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 5, group_fd: -1, flags: FD_CLOEXEC) = 32root@roc-rk3399-pc:~# grep "CPU part" /proc/cpuinfo | uniq -c
4 CPU part : 0xd03
2 CPU part : 0xd08
root@roc-rk3399-pc:~#It is already doing what you suggest, right? PERF_TYPE_HARDWARE, one counter per CPU, maps to armv8_cortex_a72/cycles/P and armv8_cortex_a53/cycles/P.
One thing I'm thinking is that we should split this per PMU at the hist_entry, so that we could show how many samples/events came from each of them...
- Arnaldo
Quoted 36 lines
I don't have a strong feeling either way; I'm personally happy so long as explicit pmu_name/event/ events don't get silently converted into
PERF_EVENT_TYPE_HARDWAREevents, and as long as we correctly set the extended HW type when we decide to use that.Thanks,
Mark.Quoted 28 lines
Kan, I also noticed that the name of the event is:
1K cpu_atom/cycles:P/ ◆
11K cpu_core/cycles:P/If I try to use that on the command line:
root@number:~# perf top -e cpu_atom/cycles:P/ event syntax error: 'cpu_atom/cycles:P/' \___ Bad event or PMUUnable to find PMU or event on a PMU of '
cpu_atom'Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu 'cpu_atom'valid terms: event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware Run 'perf list' for a list of valid events
Usage: perf top [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
root@number:~#It should be:
"cpu_atom/cycles/P"
Mark Rutland
reviewerQuoted 26 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 15, 2023 at 04:51:49PM +0000, Mark Rutland escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 12 lines
Em Tue, Dec 12, 2023 at 06:31:05PM +0000, Mark Rutland escreveu:
Quoted 8 lines
On ARM it'll be essentially the same as on x86: if you open an event with type==PERF_EVENT_TYPE_HARDWARE (without the extended HW type pointing to a specific PMU), and with cpu==-1, it'll go to an arbitrary CPU PMU, whichever happens to be found by
perf_init_event()when iterating over the 'pmus' list.If you open an event with type==PERF_EVENT_TYPE_HARDWARE and cpu!=-1, the event will opened on the appropriate CPU PMU, by virtue of being rejected by others when
perf_init_event()iterates over the 'pmus' list.The way that it is working non on my intel hybrid system, with Kan's patch, is equivalent to using this on the RK3399pc board I have:
Quoted 8 lines
Quoted 5 lines
root@roc-rk3399-pc:~# perf top -e armv8_cortex_a72/cycles/P,armv8_cortex_a53/cycles/PWouldn't be better to make 'perf top' on ARM work the way is being done in x86 now, i.e. default to opening the two events, one per PMU and allow the user to switch back and forth using the TUI/stdio?
TBH, for perf top I don't know *which* behaviour is preferable, but I agree that it'd be good for x86 and arm to work in the same way.
Right, reducing the difference in the user experience accross arches.
Quoted 7 lines
Quoted 4 lines
For design-cleanliness and consistency with other commands I can see that opening those separately is probably for the best, but for typical usage of perf top it's really nice to have those presented together without having to tab back-and-forth between the distinct PMUs, and so the existing behaviour of
Humm, so you would want two histogram viewers, one for each PMU, side by side?
I had meant as an aggregated view (the same as what you'd get if you opened one plain PERF_TYPE_HARDWARE event per cpu); I hadn't considered side-by-side views.
To be clear, I'm personally happy to tab between per-pmu views, and if that's how x86 works today for heterogeneous PMUs, I'm fine with the same for arm/arm64. I was trying to say that I didn't have a strong preference.
Quoted 14 lines
Quoted 1 line
using CPU-bound
PERF_EVENT_TYPE_HARDWAREevents is arguably nicer for the user.So, on ARM64, start the following 'perf trace' session, then run the stock 'perf top':
root@roc-rk3399-pc:~# perf trace -e perf_event_open <SNIP calls doing capability queries and setting up sideband stuff> 535.764 ( 0.015 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 19 535.783 ( 0.067 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 28 535.854 ( 0.063 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 29 535.920 ( 0.015 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 30 535.939 ( 0.016 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 4, group_fd: -1, flags: FD_CLOEXEC) = 31 535.959 ( 0.011 ms): perf/15627 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD, read_format: ID|LOST, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1 }, pid: -1, cpu: 5, group_fd: -1, flags: FD_CLOEXEC) = 32
Quoted 8 lines
root@roc-rk3399-pc:~# grep "CPU part" /proc/cpuinfo | uniq -c 4 CPU part : 0xd03 2 CPU part : 0xd08 root@roc-rk3399-pc:~#It is already doing what you suggest, right?
PERF_TYPE_HARDWARE, one counter per CPU, maps to armv8_cortex_a72/cycles/P and armv8_cortex_a53/cycles/P.
Sounds like it; as above I'm happy for that to change to per-PMU views.
Quoted 3 lines
One thing I'm thinking is that we should split this per PMU at the
hist_entry, so that we could show how manysamples/eventscame from each of them...
That sounds sensible to me.
Mark.
Quoted 39 lines
- Arnaldo
Quoted 36 lines
I don't have a strong feeling either way; I'm personally happy so long as explicit pmu_name/event/ events don't get silently converted into
PERF_EVENT_TYPE_HARDWAREevents, and as long as we correctly set the extended HW type when we decide to use that.Thanks,
Mark.Quoted 28 lines
Kan, I also noticed that the name of the event is:
1K cpu_atom/cycles:P/ ◆
11K cpu_core/cycles:P/If I try to use that on the command line:
root@number:~# perf top -e cpu_atom/cycles:P/ event syntax error: 'cpu_atom/cycles:P/' \___ Bad event or PMUUnable to find PMU or event on a PMU of '
cpu_atom'Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu 'cpu_atom'valid terms: event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware Run 'perf list' for a list of valid events
Usage: perf top [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
root@number:~#It should be:
"cpu_atom/cycles/P"
Quoted 27 lines · Arnaldo Carvalho de Melo
Kan, I also noticed that the name of the event is:
1K cpu_atom/cycles:P/
◆
11K cpu_core/cycles:P/If I try to use that on the command line:
root@number:~# perf top -e cpu_atom/cycles:P/ event syntax error: 'cpu_atom/cycles:P/' \___ Bad event or PMUUnable to find PMU or event on a PMU of '
cpu_atom'Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu
'cpu_atom'valid terms:
event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware Run
'perf list' for a list of valid eventsUsage: perf top [<options>]
Quoted 7 lines
-e, --event <event> event selector. use 'perf list' to list
available events
root@number:~#It should be:
"cpu_atom/cycles/P"
The issue also impacts the perf record and report as well.
#perf record true
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB perf.data (16 samples) ]
#perf report --header-only | grep event
# event : name = cpu_atom/cycles:P/, , id = { 7360, 7361, 7362, 7363,
7364, 7365, 7366, 7367, 7368, 7369 }, type = 0 (PERF_TYPE_HARDWARE),
size = 136, config = 0xa00000000, { sample_period, sample_freq } = 3000,
sample_type = IP|TID|TIME|PERIOD|IDENTIFIER, read_format = ID|LOST,
disabled = 1, inherit = 1, freq = 1, enable_on_exec = 1, precise_ip = 3,
sample_id_all = 1
# event : name = cpu_core/cycles:P/, , id = { 7370, 7371, 7372, 7373,
7374, 7375, 7376, 7377, 7378, 7379, 7380, 7381 }, type = 0
(PERF_TYPE_HARDWARE), size = 136, config = 0x400000000, { sample_period,
sample_freq } = 3000, sample_type = IP|TID|TIME|PERIOD|IDENTIFIER,
read_format = ID|LOST, disabled = 1, inherit = 1, freq = 1,
enable_on_exec = 1, precise_ip = 3, sample_id_all = 1I think we should move all the modifiers after the "/". The below patch can fix it.
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Kan
Arnaldo Carvalho de Melo
maintainerEm Fri, Dec 15, 2023 at 12:59:22PM -0500, Liang, Kan escreveu:
Quoted 16 lines · Arnaldo Carvalho de Melo
#perf report --header-only | grep event
# event : name = cpu_atom/cycles:P/, , id = { 7360, 7361, 7362, 7363, 7364, 7365, 7366, 7367, 7368, 7369 }, type = 0 (PERF_TYPE_HARDWARE), size = 136, config = 0xa00000000, { sample_period, sample_freq } = 3000, sample_type = IP|TID|TIME|PERIOD|IDENTIFIER, read_format = ID|LOST, disabled = 1, inherit = 1, freq = 1, enable_on_exec = 1, precise_ip = 3, sample_id_all = 1 # event : name = cpu_core/cycles:P/, , id = { 7370, 7371, 7372, 7373, 7374, 7375, 7376, 7377, 7378, 7379, 7380, 7381 }, type = 0 (PERF_TYPE_HARDWARE), size = 136, config = 0x400000000, { sample_period, sample_freq } = 3000, sample_type = IP|TID|TIME|PERIOD|IDENTIFIER, read_format = ID|LOST, disabled = 1, inherit = 1, freq = 1, enable_on_exec = 1, precise_ip = 3, sample_id_all = 1
Quoted 4 lines
I think we should move all the modifiers after the "/". The below patch can fix it.
Right, I implemented it in a slightly different way, but end result should be the same:
From 5dd1b7ab1ba69ebb8e070923dcc214b7b489ffc2 Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Fri, 15 Dec 2023 15:23:30 -0300
Subject: [PATCH 1/1] perf evlist: Move event attributes to after the / when
uniquefying using the PMU name
--- tools/perf/util/evlist.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +11 -3
@@ -2522,7 +2522,7 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lisvoid evlist__uniquify_name (struct evlist *evlist) {struct evsel *pos; -char *new_name; +char *new_name, *attributes;int ret;if (perf_pmus__num_core_pmus () ==1 )
@@ -2535,8 +2535,16 @@ void evlist__uniquify_name(struct evlist *evlist)if (strchr (pos->name,'/' ))continue ; - ret =asprintf (&new_name,"%s/%s/" , - pos->pmu_name, pos->name); + attributes =strchr (pos->name,':' ); +if (attributes) + *attributes ='\0' ; + + ret =asprintf (&new_name,"%s/%s/%s" , + pos->pmu_name, pos->name, attributes ? attributes +1 :"" ); + +if (attributes) + *attributes =':' ; +if (ret) {free (pos->name); pos->name = new_name;
Signature · 1 line
2.43.0
Liang, Kan
Tested-byQuoted 25 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 15, 2023 at 12:59:22PM -0500, Liang, Kan escreveu:
Quoted 16 lines · Arnaldo Carvalho de Melo
#perf report --header-only | grep event
# event : name = cpu_atom/cycles:P/, , id = { 7360, 7361, 7362, 7363, 7364, 7365, 7366, 7367, 7368, 7369 }, type = 0 (PERF_TYPE_HARDWARE), size = 136, config = 0xa00000000, { sample_period, sample_freq } = 3000, sample_type = IP|TID|TIME|PERIOD|IDENTIFIER, read_format = ID|LOST, disabled = 1, inherit = 1, freq = 1, enable_on_exec = 1, precise_ip = 3, sample_id_all = 1 # event : name = cpu_core/cycles:P/, , id = { 7370, 7371, 7372, 7373, 7374, 7375, 7376, 7377, 7378, 7379, 7380, 7381 }, type = 0 (PERF_TYPE_HARDWARE), size = 136, config = 0x400000000, { sample_period, sample_freq } = 3000, sample_type = IP|TID|TIME|PERIOD|IDENTIFIER, read_format = ID|LOST, disabled = 1, inherit = 1, freq = 1, enable_on_exec = 1, precise_ip = 3, sample_id_all = 1Quoted 4 lines
I think we should move all the modifiers after the "/". The below patch can fix it.
Right, I implemented it in a slightly different way, but end result should be the same:
Quoted 7 lines
From
5dd1b7ab1ba69ebb8e070923dcc214b7b489ffc2Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Fri, 15 Dec 2023 15:23:30 -0300
Subject: [PATCH 1/1] perf evlist: Move event attributes to after the / when
uniquefying using the PMU nameSigned-off-by Arnaldo Carvalho de Melo <[email protected]>
Looks good to me and verified.
Thanks,
Kan
Quoted 36 lines
--- tools/perf/util/evlist.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)tools/perf/util/evlist.c +11
-3@@ -2522,7 +2522,7 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lisvoid evlist__uniquify_name (struct evlist *evlist) {struct evsel *pos; -char *new_name; +char *new_name, *attributes;int ret;if (perf_pmus__num_core_pmus () ==1 )@@ -2535,8 +2535,16 @@ void evlist__uniquify_name(struct evlist *evlist)if (strchr (pos->name,'/' ))continue ; - ret =asprintf (&new_name,"%s/%s/" , - pos->pmu_name, pos->name); + attributes =strchr (pos->name,':' ); +if (attributes) + *attributes ='\0' ; + + ret =asprintf (&new_name,"%s/%s/%s" , + pos->pmu_name, pos->name, attributes ? attributes +1 :"" ); + +if (attributes) + *attributes =':' ; +if (ret) {free (pos->name); pos->name = new_name;
Arnaldo Carvalho de Melo
maintainerEm Fri, Dec 15, 2023 at 01:53:12PM -0500, Liang, Kan escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Right, I implemented it in a slightly different way, but end result should be the same:
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Fri, 15 Dec 2023 15:23:30 -0300
Subject: [PATCH 1/1] perf evlist: Move event attributes to after the / when uniquefying using the PMU nameLooks good to me and verified.
Tested-by Kan Liang <[email protected]>
I ended up with a bit more simplified version:
From 22ecc4601e28a12661f14ca877e39348dab6be8e Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Fri, 15 Dec 2023 15:23:30 -0300
Subject: [PATCH 1/1] perf evlist: Move event attributes to after the / when
uniquefying using the PMU name
When turning an event with attributes to the format including the PMU we need to move the "event:attributes" format to "event/attributes/" so that we can copy the event displayed and use it in the command line, i.e. in 'perf top' we had:
1K cpu_atom/cycles:P/
11K cpu_core/cycles:P/
If I try to use that on the command line:
# perf top -e cpu_atom/cycles:P/
event syntax error: 'cpu_atom/cycles:P/'
\___ Bad event or PMU Unable to find PMU or event on a PMU of 'cpu_atom'
Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu
'cpu_atom'
valid terms:
event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite ,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware
Run
'perf list' for a list of valid events
Usage: perf top [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
#
--- tools/perf/util/evlist.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/perf/util/evlist.c +10 -5
@@ -2521,9 +2521,8 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lisvoid evlist__uniquify_name (struct evlist *evlist) { +char *new_name, empty_attributes[2 ] =":" , *attributes;struct evsel *pos; -char *new_name; -int ret;if (perf_pmus__num_core_pmus () ==1 )return ;
@@ -2535,11 +2534,17 @@ void evlist__uniquify_name(struct evlist *evlist)if (strchr (pos->name,'/' ))continue ; - ret =asprintf (&new_name,"%s/%s/" , - pos->pmu_name, pos->name); -if (ret) { + attributes =strchr (pos->name,':' ); +if (attributes) + *attributes ='\0' ; +else + attributes = empty_attributes; + +if (asprintf (&new_name,"%s/%s/%s" , pos->pmu_name, pos->name, attributes +1 )) {free (pos->name); pos->name = new_name; + }else { + *attributes =':' ; } } }
Signature · 1 line
2.43.0
Liang, Kan
Tested-byQuoted 53 lines · Arnaldo Carvalho de Melo
Em Fri, Dec 15, 2023 at 01:53:12PM -0500, Liang, Kan escreveu:
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Right, I implemented it in a slightly different way, but end result should be the same:
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Fri, 15 Dec 2023 15:23:30 -0300
Subject: [PATCH 1/1] perf evlist: Move event attributes to after the / when uniquefying using the PMU nameLooks good to me and verified.
Tested-by Kan Liang <[email protected]>I ended up with a bit more simplified version:
From
22ecc4601e28a12661f14ca877e39348dab6be8eMon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <[email protected]>
Date: Fri, 15 Dec 2023 15:23:30 -0300
Subject: [PATCH 1/1] perf evlist: Move event attributes to after the / when
uniquefying using the PMU nameWhen turning an event with attributes to the format including the PMU we need to move the "event:attributes" format to "event/attributes/" so that we can copy the event displayed and use it in the command line, i.e. in 'perf top' we had:
1K cpu_atom/cycles:P/
11K cpu_core/cycles:P/If I try to use that on the command line:
# perf top -e cpu_atom/cycles:P/ event syntax error: 'cpu_atom/cycles:P/' \___ Bad event or PMUUnable to find PMU or event on a PMU of '
cpu_atom'Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu
'cpu_atom'valid terms:
event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite ,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware
Run
'perf list' for a list of valid eventsUsage: perf top [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
#
Quoted 8 lines
Cc Hector Martin <[email protected]>Cc Ian Rogers <[email protected]>Cc Kan Liang <[email protected]>Cc Marc Zyngier <[email protected]>Cc Mark Rutland <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Thanks,
Kan
Quoted 40 lines
--- tools/perf/util/evlist.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)tools/perf/util/evlist.c +10
-5@@ -2521,9 +2521,8 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lisvoid evlist__uniquify_name (struct evlist *evlist) { +char *new_name, empty_attributes[2 ] =":" , *attributes;struct evsel *pos; -char *new_name; -int ret;if (perf_pmus__num_core_pmus () ==1 )return ;@@ -2535,11 +2534,17 @@ void evlist__uniquify_name(struct evlist *evlist)if (strchr (pos->name,'/' ))continue ; - ret =asprintf (&new_name,"%s/%s/" , - pos->pmu_name, pos->name); -if (ret) { + attributes =strchr (pos->name,':' ); +if (attributes) + *attributes ='\0' ; +else + attributes = empty_attributes; + +if (asprintf (&new_name,"%s/%s/%s" , pos->pmu_name, pos->name, attributes +1 )) {free (pos->name); pos->name = new_name; + }else { + *attributes =':' ; } } }
Quoted 17 lines · On Fri, Dec 8, 2023 at 1:09 PM <[email protected]> wrote:
From: Kan Liang <[email protected]>
perf top errors out on a hybrid machine
$perf topError:
The cycles:P event is not supported.The
user_requested_cpusmay contain CPUs that are invalid for a hybrid PMU. It causesperf_event_opento fail.The commit
ef91871c960e("perf evlist: Propagate user CPU maps intersecting core PMU maps") already intersect the requested CPU map with the CPU map of the PMU. Use the evsel's cpus to replaceuser_requested_cpus.
Quoted 6 lines
The evlist's threads is also propagated to evsel's threads in
__perf_evlist__propagate_maps(). Replace it as well.
Sorry I missed top doing the evlist__create_maps calls:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-top.c?h=perf-tools-next#n1761
so it is right that the only divergence from record:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/builtin-record.c?h=perf-tools-next#n1362
and stat:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/stat.c?h=perf-tools-next#n797
So this is the right fix I believe.
Thanks,
Ian
Quoted 22 lines
--- tools/perf/builtin-top.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/builtin-top.c +2
-3@@ -1027,8 +1027,8 @@ static int perf_top__start_counters(struct perf_top *top)evlist__for_each_entry (evlist, counter) { try_again: -if (evsel__open (counter, top->evlist->core.user_requested_cpus, - top->evlist->core.threads) <0 ) { +if (evsel__open (counter, counter->core.cpus, + counter->core.threads) <0 ) {/* * Specially handle overwrite fall back. -- 2.35.1