{"id":2529,"date":"2024-07-30T12:59:27","date_gmt":"2024-07-30T12:59:27","guid":{"rendered":"https:\/\/mvermeulen.org\/perf\/?p=2529"},"modified":"2024-07-30T12:59:27","modified_gmt":"2024-07-30T12:59:27","slug":"wsl-and-performance-counters","status":"publish","type":"post","link":"https:\/\/mvermeulen.org\/perf\/2024\/07\/30\/wsl-and-performance-counters\/","title":{"rendered":"wsl and performance counters?"},"content":{"rendered":"\n<p>I have seen some references that it might be possible to have performance counters in WSL, like <a href=\"https:\/\/www.reddit.com\/r\/bashonubuntuonwindows\/comments\/qw6a0z\/can_anyone_confirm_that_you_can_use_cpu\/\">this page<\/a>.<\/p>\n\n\n\n<p>If I type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>perf stat ls<\/code><\/pre>\n\n\n\n<p>Then WSL tells me<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Command 'perf' not found, but can be installed with:\nsudo apt install linux-tools-common        # version 6.8.0-38.38, or\nsudo apt install linux-laptop-tools-common # version 6.5.0-1004.7<\/code><\/pre>\n\n\n\n<p>This seems both encouraging and discouraging.  Encouraging that it references a standard version of an ubuntu package. Discouraging because the kernel versions listed don&#8217;t match my WSL 5.15.131 kernel. The second is not available but the first does install. However, now WSL tells me<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WARNING: perf not found for kernel 5.15.153-1-microsoft\n\nYou may need to install the following packages for this specific kernel:\n   linux-tools-5.15.153.1-microsoft-standard-WSL2\n   linux-cloud-tools-5.15.153-1-microsoft-standard-WSL2\n\nYou may also want to install one of the following packages to keep up to date:\n   linux-tools-standard-WSL2\n   linux-cloud-tools-standard-WSL2<\/code><\/pre>\n\n\n\n<p>None of these packages exist.  What I am able to do is install the following package<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install linux-tools-generic<\/code><\/pre>\n\n\n\n<p>This gets me the following path<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/lib\/linux-tools-6.8-39\/perf<\/code><\/pre>\n\n\n\n<p>With these tools, I am able to get some basic counters.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Performance counter stats for 'ls':\n\n              0.66 msec task-clock:u                     #    0.397 CPUs utilized\n                 0      context-switches:u               #    0.000 \/sec\n                 0      cpu-migrations:u                 #    0.000 \/sec\n                97      page-faults:u                    #  147.148 K\/sec\n           1113650      cycles:u                         #    1.689 GHz\n             44775      stalled-cycles-frontend:u        #    4.02% frontend cycles idle\n             85883      stalled-cycles-backend:u         #    7.71% backend cycles idle\n            536486      instructions:u                   #    0.48  insn per cycle\n                                                  #    0.16  stalled cycles per insn\n            109474      branches:u                       #  166.071 M\/sec\n              6643      branch-misses:u                  #    6.07% of all branches\n\n       0.001661844 seconds time elapsed\n\n       0.000214000 seconds user\n       0.000000000 seconds sys<\/code><\/pre>\n\n\n\n<p>In particular, the output of perf list gives me the following generic events<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  branch-instructions OR branches                    &#91;Hardware event]\n  branch-misses                                      &#91;Hardware event]\n  cache-misses                                       &#91;Hardware event]\n  cache-references                                   &#91;Hardware event]\n  cpu-cycles OR cycles                               &#91;Hardware event]\n  instructions                                       &#91;Hardware event]\n  stalled-cycles-backend OR idle-cycles-backend      &#91;Hardware event]\n  stalled-cycles-frontend OR idle-cycles-frontend    &#91;Hardware event]\n  alignment-faults                                   &#91;Software event]\n  bpf-output                                         &#91;Software event]\n  cgroup-switches                                    &#91;Software event]\n  context-switches OR cs                             &#91;Software event]\n  cpu-clock                                          &#91;Software event]\n  cpu-migrations OR migrations                       &#91;Software event]\n  dummy                                              &#91;Software event]\n  emulation-faults                                   &#91;Software event]\n  major-faults                                       &#91;Software event]\n  minor-faults                                       &#91;Software event]\n  page-faults OR faults                              &#91;Software event]\n  task-clock                                         &#91;Software event]\n  duration_time                                      &#91;Tool event]\n  user_time                                          &#91;Tool event]\n  system_time                                        &#91;Tool event]\n\ncpu:\n  L1-dcache-loads OR cpu\/L1-dcache-loads\/\n  L1-dcache-load-misses OR cpu\/L1-dcache-load-misses\/\n  L1-dcache-prefetches OR cpu\/L1-dcache-prefetches\/\n  L1-icache-loads OR cpu\/L1-icache-loads\/\n  L1-icache-load-misses OR cpu\/L1-icache-load-misses\/\n  dTLB-loads OR cpu\/dTLB-loads\/\n  dTLB-load-misses OR cpu\/dTLB-load-misses\/\n  iTLB-loads OR cpu\/iTLB-loads\/\n  iTLB-load-misses OR cpu\/iTLB-load-misses\/\n  branch-loads OR cpu\/branch-loads\/\n  branch-load-misses OR cpu\/branch-load-misses\/\n  branch-instructions OR cpu\/branch-instructions\/    &#91;Kernel PMU event]\n  branch-misses OR cpu\/branch-misses\/                &#91;Kernel PMU event]\n  cache-misses OR cpu\/cache-misses\/                  &#91;Kernel PMU event]\n  cache-references OR cpu\/cache-references\/          &#91;Kernel PMU event]\n  cpu-cycles OR cpu\/cpu-cycles\/                      &#91;Kernel PMU event]\n  instructions OR cpu\/instructions\/                  &#91;Kernel PMU event]\n  stalled-cycles-backend OR cpu\/stalled-cycles-backend\/&#91;Kernel PMU event]\n  stalled-cycles-frontend OR cpu\/stalled-cycles-frontend\/&#91;Kernel PMU event]\n  msr\/tsc\/                                           &#91;Kernel PMU event]\n  rNNN                                               &#91;Raw hardware event descriptor]\n  cpu\/t1=v1&#91;,t2=v2,t3 ...]\/modifier                  &#91;Raw hardware event descriptor]\n       &#91;(see 'man perf-list' on how to encode it)]\n  mem:&lt;addr>&#91;\/len]&#91;:access]                          &#91;Hardware breakpoint]\n<\/code><\/pre>\n\n\n\n<p>This is encouraging since it at least shows the more generic hardware events like cycles, instructions and branches. What is missing from this list are counters specific to my Zen5 core such as the topdown performance counters used by wspy to look at microarchitecture differences.<\/p>\n\n\n\n<p>There is one possible way I might get closer to having these counters.  This would be to update my WSL kernel\/distribution with the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wsl --update --pre-release<\/code><\/pre>\n\n\n\n<p>I believe this updates WSL with the following repository: <a href=\"https:\/\/github.com\/microsoft\/WSL\/releases\">https:\/\/github.com\/microsoft\/WSL\/releases<\/a>  At present this is the 2.3.13 release which has a 6.6.36.3 kernel.  Unfortunately, according to this <a href=\"https:\/\/www.phoronix.com\/news\/AMD-Zen-5-Perf-Monitoring-Patch\">phoronix article <\/a>Zen5 performance events were posted in March 2024. At that time work was underway for a Linux 6.9 kernel.  Ubuntu 24.04 shipped with a Linux 6.8 kernel so it is unclear to me if stock Ubuntu 24.04 will support Zen5 topdown counters and the WSL pre-release is even older than that.  So at this point, I think I want to try Ubuntu 24.04 first to see what Zen5 counters are available before updating my WSL to a release that might not be new enough.<\/p>\n\n\n\n<p>A step at a time, but this might be sufficient to get some basic Zen5 IPC comparisons with Zen4 even if not the more complete topdown performance counters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have seen some references that it might be possible to have performance counters in WSL, like this page. If I type Then WSL tells me This seems both encouraging and discouraging. Encouraging that it references a standard version of <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/mvermeulen.org\/perf\/2024\/07\/30\/wsl-and-performance-counters\/\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[7,37,36],"class_list":["post-2529","post","type-post","status-publish","format-standard","hentry","category-experiment","tag-performance-counters","tag-wsl","tag-zen5"],"_links":{"self":[{"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/posts\/2529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/comments?post=2529"}],"version-history":[{"count":2,"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/posts\/2529\/revisions"}],"predecessor-version":[{"id":2531,"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/posts\/2529\/revisions\/2531"}],"wp:attachment":[{"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/media?parent=2529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/categories?post=2529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mvermeulen.org\/perf\/wp-json\/wp\/v2\/tags?post=2529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}