Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use perf even compile from source in WSL2 #10829

Closed
1 of 2 tasks
discord9 opened this issue Nov 27, 2023 · 5 comments
Closed
1 of 2 tasks

Can't use perf even compile from source in WSL2 #10829

discord9 opened this issue Nov 27, 2023 · 5 comments

Comments

@discord9
Copy link

discord9 commented Nov 27, 2023

Windows Version

Microsoft Windows [Version 10.0.19045.3693]

WSL Version

2.0.9.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.133.1-1

Distro Version

ubuntu20.04

Other Software

No response

Repro Steps

I'm using Linux version 5.15.133.1-microsoft-standard-WSL2 (root@1c602f52c2e4) (gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP Thu Oct 5 21:02:42 UTC 2023 and have
hardwarePerformanceCounters=true in my .wslconfig file

  1. git clone --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git
  2. install all essential depend: build-essential flex bison libssl-dev libelf-dev libbabeltrace-dev libunwind-dev libdw-dev binutils-dev libiberty-dev
  3. run make under WSL2-Linux-Kernel/tools/perf and make say:
Auto-detecting system features:
...                         dwarf: [ on  ]
...            dwarf_getlocations: [ on  ]
...                         glibc: [ on  ]
...                        libbfd: [ on  ]
...                libbfd-buildid: [ on  ]
...                        libcap: [ on  ]
...                        libelf: [ on  ]
...                       libnuma: [ on  ]
...        numa_num_possible_cpus: [ on  ]
...                       libperl: [ on  ]
...                     libpython: [ on  ]
...                     libcrypto: [ on  ]
...                     libunwind: [ on  ]
...            libdw-dwarf-unwind: [ on  ]
...                          zlib: [ on  ]
...                          lzma: [ on  ]
...                     get_cpuid: [ on  ]
...                           bpf: [ on  ]
...                        libaio: [ on  ]
...                       libzstd: [ on  ]
...        disassembler-four-args: [ on  ]
  1. run sudo ./perf stat -d ls, unexpectedly got:
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (slots).
/bin/dmesg | grep -i perf may provide additional information.

run /bin/dmesg | grep -i perf
got

[    0.079396] Performance Events: Icelake events, 32-deep LBR, full-width counters, Intel PMU driver.
[    0.281393]     Performance counters on

Expected Behavior

Can use perf with all rich features

Actual Behavior

Can't even start it

Diagnostic Logs

No response

Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@pmartincic
Copy link
Collaborator

Is there a reason you don't want to use the perf included with the linux-tools-generic package?

See: #10734

@discord9
Copy link
Author

discord9 commented Nov 29, 2023

Is there a reason you don't want to use the perf included with the linux-tools-generic package?

See: #10734

Thank you!
I read from a stackoverflow problem(https://stackoverflow.com/questions/60237123/is-there-any-method-to-run-perf-under-wsl) saying that should fix my problem, must be outdated, never mind, I fixed my problem with install linux-tools-generic
However I'm still curious what I did wrong that I can't compile from source XD

@sergio-eld
Copy link

Have the exact same issue. Both linux-tools-generic and manually compiled version fail with the same error.

  Virtualization: wsl
Operating System: Ubuntu 22.04.3 LTS
          Kernel: Linux 5.15.133.1-microsoft-standard-WSL2
    Architecture: x86-64

@sergio-eld
Copy link

From here:

Add kvm@vger.kernel.org as this issue is in virtualization env.

The topdown metrics events became default since
commit 42641d6f4d15 ("perf stat: Add Topdown metrics events as default
events"). The perf will use 'slots' if the
/sys/bus/event_source/devices/cpu/events/slots is available.

Unfortunately, the 'slots' may not be supported in the virualization
environment. The hypervisor may not expose the 'slots' counter to the VM
in cpuid. As a result, the kernel may disable topdown slots and metrics
events in intel_pmu_init() if slots event is not in CPUID. E.g., both
c->weight and c->idxmsk64 are set to 0.

There will be below error on Icelake VM since 'slots' is the leader:

$ perf stat
Error:
The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (slots).
/bin/dmesg | grep -i perf may provide additional information.

This is because the stat_handle_error() returns COUNTER_FATAL when the
'slots' is used as leader of events.

There are three options to fix the issue.

  1. Do not expose /sys/bus/event_source/devices/cpu/events/slots to
    userspace so that pmu_have_event(pmu->name, "slots") returns false.

  2. Run cpuid at perf userspace and avoid using 'slots' if it is not
    supported in cpuid.

  3. Do not fatal perf if the leader is failed. Do not create events for an
    evsel if its leader is already failed.

This RFC patch is with the 3rd option. Would you mind suggesting which
option is better?

The workaround is to run perf stat -e and explicitly NOT specify slots.
For example, the command ./perf stat -e cache-misses -d ls will be successful:

 Performance counter stats for 'ls':

              5268      cache-misses:u
            221626      L1-dcache-loads:u
              8179      L1-dcache-load-misses:u   #    3.69% of all L1-dcache accesses
   <not supported>      LLC-loads:u
   <not supported>      LLC-load-misses:u

       0.000868303 seconds time elapsed

       0.000943000 seconds user
       0.000000000 seconds sys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants