oxnan
oxnan

Reputation: 45

How to properly install the perf command on WSL2

I am having trouble compiling perf on my machine in WSL2 ubuntu.

Ubuntu was downloaded from the microsoft store and the kernel version is 4.19.128-microsoft-standard

I have followed this answer on stackoverflow already and also https://blog.haoxp.xyz/posts/wsl2-perf/

When running make I get the following error:

mv: cannot stat 'util/.env.o.tmp': No such file or directory
make[4]: *** [/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/build/Makefile.build:97: util/env.o] Error 1
make[4]: *** Waiting for unfinished jobs....
  LD       bench/perf-in.o
make[3]: *** [/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/build/Makefile.build:139: util] Error 2
make[2]: *** [Makefile.perf:633: libperf-in.o] Error 2
make[2]: *** Waiting for unfinished jobs....
ld: bench/futex-lock-pi.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/bench/futex-lock-pi.c:38: multiple definition of `end'; bench/futex-hash.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/bench/futex-hash.c:38: first defined here
ld: bench/futex-lock-pi.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/bench/futex-lock-pi.c:38: multiple definition of `start'; bench/futex-hash.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/bench/futex-hash.c:38: first defined here
ld: bench/futex-lock-pi.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/bench/futex-lock-pi.c:38: multiple definition of `runtime'; bench/futex-hash.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/bench/futex-hash.c:38: first defined here
make[4]: *** [/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/build/Makefile.build:145: bench/perf-in.o] Error 1
make[3]: *** [/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/build/Makefile.build:139: bench] Error 2
make[3]: *** Waiting for unfinished jobs....
  LD       tests/perf-in.o
ld: tests/bp_account.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/tests/bp_account.c:25: multiple definition of `the_var'; tests/bp_signal.o:/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/perf/tests/bp_signal.c:37: first defined here
make[4]: *** [/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/build/Makefile.build:145: tests/perf-in.o] Error 1
make[3]: *** [/mnt/c/Users/micro/Documents/tools/WSL2-Linux-Kernel/tools/build/Makefile.build:139: tests] Error 2
make[2]: *** [Makefile.perf:507: perf-in.o] Error 2
make[1]: *** [Makefile.perf:206: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

Can anyone help me figure out what I am doing wrong?

Upvotes: 3

Views: 2207

Answers (1)

NotTheDr01ds
NotTheDr01ds

Reputation: 20795

Short answer - Try cloning the repo and building under your WSL home directory (under the ext4 filesystem) rather than your C: drive.

(Much) Longer answer -- You are probably running into two separate issues with the source being on your C: drive (and accessing it through /mnt/c):

First, permissions issues. Even the git clone fails for me on /mnt/c from within WSL2 using the automounted /mnt/c mount options. I'm guessing that you checked it out using Windows git instead of Linux git?

You could remount the drive with something like sudo mount -t drvfs C: /mnt/src -o uid=1000,gid=1000 (see this answer) to correct the permissions. I was able to do that, but then I noticed the following ...

Even after fixing permissions, I still faced the next issue - WSL case sensitivity support on NTFS drives. Linux git clone warned me about the duplicate directories. I believe this is why you are getting the "multiple definition of" warnings -- That source tree contains some duplicate directory names that only differ in case. Windows git is handling that correctly, but my guess is that the build is failing because it isn't parsing the right directories. I haven't tried it, but the command to set case-sensitivity on a directory is in that MS doc.

But even then, if you fix those issues (and you probably can), I still recommend avoiding /mnt/c (and any other NTFS drives) under WSL2. Any heavy file operations will completely grind to a halt due to the poor performance of NTFS under WSL2 (much, much worse than it was under WSL1). For instance, the git clone that of that repo took only a few seconds under /home/myusername/src but around 10 minutes (!!!) on /mnt/c. This is a known issue with WSL2.

I still keep WSL1 around for when I want to run Linux commands against the NTFS drive. For instance, s3cmd to sync/backup my photos to S3-compatible storage. And I use WSL2 for everything else, but I stick to the ext4 filesystem there, where performance is better than WSL1.

Upvotes: 4

Related Questions