microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.05k stars 798 forks source link

State of hardware performance monitoring in WSL2 #8480

Open christian-vorhemus opened 2 years ago

christian-vorhemus commented 2 years ago

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

benhillis commented 2 years ago

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.

AndyAyersMS commented 1 year ago

@benhillis any update on this?

mingshi2333 commented 6 months ago

@benhillis any update on this? image the lastest kernel's condition works like this, but still not support llc, It need more work to finish it

oscarbg commented 2 months ago

+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
kh-abd-kh commented 1 month ago

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