RRZE-HPC / likwid

Performance monitoring and benchmarking suite
https://hpc.fau.de/research/tools/likwid/
GNU General Public License v3.0
1.66k stars 227 forks source link

[FeatureRequest] WSL2 support #465

Open kpamnany opened 2 years ago

kpamnany commented 2 years ago

Is your feature request related to a problem? Please describe. Running likwid under WSL2.

Describe the solution you'd like For it to work. :-)

Describe alternatives you've considered None.

Additional context Get a recent kernel (I got 5.10.102.1), turn on CONFIG_X86_MSR and CONFIG_X86_CPUID, build, make modules_install and copy the kernel where wsl.exe can see it with a .wslconfig file. Make sure you have hardware counters enabled -- you can build tools/perf/perf in the Microsoft kernel directory. I had to patch the following to make it build:

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index d3b5f5faf8c1..535f45b8fddf 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -669,8 +669,7 @@ static void create_tasks(struct perf_sched *sched)

        err = pthread_attr_init(&attr);
        BUG_ON(err);
-       err = pthread_attr_setstacksize(&attr,
-                       (size_t) max(16 * 1024, PTHREAD_STACK_MIN));
+       err = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);

Make sure you install a recent .msixbundle from here also.

Now we get to building likwid and the problem is that /proc/bus/pci/* is non-standard under WSL2 but CPUID says client memory is supported. So I commented out these lines and built likwid and it seems to work.

I'd offer a PR but there's no clear way I can find to detect if you're running under WSL2 (so that you can ignore cpuid_info.supportClientMem) so maybe a configuration option would be best? I'm posting this just for informational reasons -- feel free to close, move into the wiki or whatever.

TomTheBear commented 2 years ago

Hi, thanks for your instructions how to build and run LIKWID in WSL2.

Have you tried with ACCESSMODE=perf_event? It does not rely on the cpuid_info.supportClientMem flag and you don't need to change CONFIG_X86_MSR and CONFIG_X86_CPUID. As long as the perf_event interface and all corresponding sysfs entries exist (/sys/bus/event_source/devices), it should build and run directly. Using the two other access mode settings require your kernel update and probably cause more pain to support on the broad scale.

Of course, if LIKWID in WSL2 should be supported in general, there needs to be any method to determine the WSL2 environment. This could be used to skip client memory (and maybe other features). The other clean method for supportClientMem is probably to generate the topology file once with likwid-genTopoCfg, toggle the cpuid_info.supportClientMem there and run LIKWID with this topology file. It's not working at the moment because the the topology file reader does not read cpuid_info.supportClientMem. You would need to add this at src/topology.c in function readTopologyFile somewhere around line 500.

else if (strcmp(field, "supportClientMem") == 0)
{
    sscanf(line, "%s %s = %d", structure, field, &tmp);
    cpuid_info.supportClientMem = tmp;
}

(Reminder to myself: Rework the topology file reader to use strncmp everywhere)