mirage / bechamel

Agnostic benchmark in OCaml (proof-of-concept)
MIT License
44 stars 15 forks source link

Bechamel_perf: fix running as non-root user #51

Closed edwintorok closed 1 month ago

edwintorok commented 1 month ago

By default my system (Fedora 40) has kernel.perf_event_paranoid set to 2, which doesn't allow non-root users to measure the kernel.

This causes Bechamel_perf to fail to load when linked into a program (even if I don't actually use any of its metrics), because the perf event is opened at module startup time, and not at Measure load time.

Catch the permission error and fall back to not measuring the kernel.

edwintorok commented 1 month ago

I've rebased this PR on top of https://github.com/mirage/bechamel/pull/52 to fix the CI failures. Although there is a 500 error from OCaml-CI now, reported here: https://github.com/ocurrent/ocaml-ci/issues/946

edwintorok commented 1 month ago

Note that there are other errors here that prevent loading the Bechamel_perf module (and as a result any application that links it), e.g. in a virtualized environment where you don't have access to perf counters, in which case you get ENOENT back.

I'll try to fix that in a separate PR though (will probably need some mechanism to detect which events are present, in a way that doesn't cause the entire module to fail to load, currently it is not possible to write a CLI to enable the perf features conditionally, because the failure is too early). E.g. on Xen without vPMU enabled you get very little (just cpu-clock,context-switches,cpu-migrations and page-faults).

dinosaure commented 1 month ago

Note that there are other errors here that prevent loading the Bechamel_perf module (and as a result any application that links it), e.g. in a virtualized environment where you don't have access to perf counters, in which case you get ENOENT back.

We should probably document that first I think 👍 .

edwintorok commented 1 month ago

Note that there are other errors here that prevent loading the Bechamel_perf module (and as a result any application that links it), e.g. in a virtualized environment where you don't have access to perf counters, in which case you get ENOENT back.

We should probably document that first I think 👍 .

Good point, I'll update this PR to document that later today.

dinosaure commented 1 month ago

I added a documentation about ENOENT and what is required if the user wants to measure kernel syscalls.

dinosaure commented 1 month ago

Thanks!

edwintorok commented 1 month ago

Thanks for fixing it up and merging, I got distracted by other things.