State of hardware performance monitoring in WSL2
I read mixed signals [1] [2] to which extent we can access the Performance Monitoring Unit by using the perf command. I cloned and compiled the perf tool present in https://github.com/microsoft/WSL2-Linux-Kernel and when I run sudo ./perf stat -d ls I get the following output:
Performance counter stats for 'ls':
1.76 msec task-clock # 0.730 CPUs utilized
0 context-switches # 0.000 K/sec
0 cpu-migrations # 0.000 K/sec
108 page-faults # 0.061 M/sec
<not supported> cycles
<not supported> instructions
<not supported> branches
<not supported> branch-misses
<not supported> L1-dcache-loads
<not supported> L1-dcache-load-misses
<not supported> LLC-loads
<not supported> LLC-load-misses
0.002411486 seconds time elapsed
0.002558000 seconds user
0.000000000 seconds sys
Especially getting the cache misses would be interesting for my use case. Is it expected that measures like cycles, LLC-loads are "not supported" in WSL2 or did I do something wrong? If the former, is support for it planned?
[1] https://stackoverflow.com/questions/60237123/is-there-any-method-to-run-perf-under-wsl#comment125398632_60276918 [2] https://github.com/microsoft/WSL/issues/329#issuecomment-564461721
Yeah we have a backlog item to add additional perf counters, but unfortunately there isn't a great API to query if the host supports them. It's something we're looking into.
@benhillis any update on this?
@benhillis any update on this?
the lastest kernel's condition works like this, but still not support llc, It need more work to finish it
+1 on LLC metrics..
getting on Zen4:
7209 branch-misses:u # 6.49% of all branches
<not counted> L1-dcache-loads:u (0.00%)
<not counted> L1-dcache-load-misses:u (0.00%)
<not supported> LLC-loads:u
<not supported> LLC-load-misses:u
I used this sudo apt install linux-tools-generic
/usr/lib/linux-tools/5.15.0-112-generic/perf stat ls ............ .......... .............
Performance counter stats for 'ls':
2.11 msec task-clock:u # 0.762 CPUs utilized
0 context-switches:u # 0.000 /sec
0 cpu-migrations:u # 0.000 /sec
117 page-faults:u # 55.508 K/sec
1660148 cycles:u # 0.788 GHz
123771 stalled-cycles-frontend:u # 7.46% frontend cycles idle
389595 stalled-cycles-backend:u # 23.47% backend cycles idle
1856800 instructions:u # 1.12 insn per cycle
# 0.21 stalled cycles per insn
400912 branches:u # 190.204 M/sec
15016 branch-misses:u # 3.75% of all branches
0.002766014 seconds time elapsed
0.000285000 seconds user
0.000000000 seconds sys
I hope this might help
$ /usr/lib/linux-tools/6.8.0-45-generic/perf stat ls
event syntax error: 'cpu_core/TOPDOWN.SLOTS,metric-id=cpu_core!3TOPDOWN.SLOTS!3/,cpu_core/topdown-retiring,metric-id=cpu_core!3topdo..'
\___ Bad event or PMU
Unable to find PMU or event on a PMU of 'cpu_core'
Initial error:
event syntax error: 'cpu_core/TOPDOWN.SLOTS,metric-id=cpu_core!3TOPDOWN.SLOTS!3/,cpu_core/topdown-retiring,metric-id=cpu_core!3topdo..'
\___ Cannot find PMU `cpu_core'. Missing kernel support?
...
Performance counter stats for 'ls':
1.69 msec task-clock:u # 0.235 CPUs utilized
0 context-switches:u # 0.000 /sec
0 cpu-migrations:u # 0.000 /sec
99 page-faults:u # 58.708 K/sec
<not supported> cycles:u
<not supported> instructions:u
<not supported> branches:u
<not supported> branch-misses:u
0.007168466 seconds time elapsed
0.002439000 seconds user
0.000000000 seconds sys
@benhillis any update on this?
the lastest kernel's condition works like this, but still not support llc, It need more work to finish it
Did you use a user customized kernel or microsoft-standard-WSL2? my kernel version is 5.15.167.4-microsoft-standard-WSL2
Any update? I also got the same result as @elazarg with the latest WSL2 and 6.8.0-60-generic/perf