powerapi-ng / hwpc-sensor

Hardware Performance Counters monitoring agent for containers.
BSD 3-Clause "New" or "Revised" License
14 stars 16 forks source link

Sensor does not work when built from source despite working with .deb installation #25

Closed jack-leyland closed 10 months ago

jack-leyland commented 2 years ago

Thanks for the work on this project. I am trying to add some functionality to the sensor for a project of mine, however, I am unable to sucessfully run the sensor when compiling from source even before making any changes. This is puzzling as the sensor works perfectly when install the .deb package on Ubuntu LTS 20.04 and run it that way. I am not using docker.

The sensor outputs the following: E: 22-06-27 10:33:14 config: event 'TSC' is invalid or unsupported by this machine E: 22-06-27 10:33:14 config: failed to parse the provided config file

I have identified the issue as being the pfm_get_os_event_encoding() function from libpfm in events.c. It consistently returns a PFM_ERR_NOTFOUND for both msr and rapl events in the config file that I know exist in my architecture (Haswell). All events appear as expected using "perf list."

I have attempted building directly from the source of the latest release to no avail. Might you have any ideas as to why this may be happening, given that the sensor runs successfully and is able to find these events when the sensor installed from the .deb package?

jack-leyland commented 2 years ago

A little more digging around has yeiled a solution. As this issue appears to have come up before for others I will detail the steps taken to fix (note this applies only to local builds, I have not attempted to run the sensor in a container):

As mentioned in #1, the sensor only seems to function with a patched version of libpfm4 that support certain events, including "TSC", "APERF" and "MPERF." The working patch is available on the smartwatts branch of https://github.com/gfieni/libpfm4.git and must be installed locally from there.

I echo PierreRust's comment in #1 that it would be be helpful to include the correct libpfm patch in the repo and the build pipeline to allow a more seamless local build process.

gfieni commented 2 years ago

Hello, You can find the procedure to build the sensor along the patched libpfm4 inside the Dockerfile. As you can see in the branch name, this is a patch made specifically for the SmartWatts formula. The main build pipeline of this project is the Dockerfile, and building the patched libpfm4 is already done there. I agree that this issue is confusing, and it will be addressed in the future with a better documentation for the build process.