Skip to content

feat(agent): migrate RaplCollector from MSR to powercap sysfs - #50

Merged
patryk-przybysz merged 2 commits into
develfrom
feat/agent-rapl-powercap
Aug 8, 2026
Merged

feat(agent): migrate RaplCollector from MSR to powercap sysfs#50
patryk-przybysz merged 2 commits into
develfrom
feat/agent-rapl-powercap

Conversation

@patryk-przybysz

Copy link
Copy Markdown
Collaborator

Background

Previously, package energy came from MSR registers via /dev/cpu/*/msr, which typically requires root or elevated hardware access. Linux exposes the same counter through powercap sysfs (/sys/class/powercap/intel-rapl:*/energy_uj), which fits a daemon running as an unprivileged user with filesystem read access to those nodes.

Summary

  • Replace MSR-based RAPL reads with powercap sysfs energy_uj under intel-rapl package zones.
  • Discover package zones by sysfs name (package-N); emit socket 0 only; handle counter wrap via max_energy_range_uj.
  • Preserve existing metric semantics: METRIC_TYPE_CPU_POWER_PACKAGE reports energy delta in joules per sample.
  • Moves RAPL collection toward a non-root privilege model and further agent daemonization work.

@patryk-przybysz patryk-przybysz self-assigned this Aug 2, 2026

@FW-Nagorko FW-Nagorko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a good rewrite, some notes left to be addressed.

Comment thread sources/agent/src/collectors/rapl_collector.cc Outdated
Comment thread sources/agent/src/collectors/rapl_collector.cc Outdated
Comment thread sources/agent/src/collectors/rapl_collector.cc
Comment thread sources/agent/src/collectors/rapl_collector.h Outdated
Comment thread sources/agent/src/collectors/rapl_collector.cc Outdated
Comment thread sources/agent/src/collectors/rapl_collector.cc Outdated
Replace dirent/access with std::filesystem directory iteration, validate
energy_uj readability via ifstream in DiscoverPackages, store zone paths
as std::filesystem::path, and parse package-N names with std::regex.
@patryk-przybysz

Copy link
Copy Markdown
Collaborator Author

Good call, thanks for the thorough review.

Addressed the rest: switched discovery to std::filesystem, moved the energy_uj readability check into DiscoverPackages (via ifstream), path is now std::filesystem::path, and package names go through std::regex as you suggested.

Left multi-socket and CPU_POWER_CORES out for now - the MSR path only ever did socket-0 package energy, and cores were never wired up there either. This PR is just the read-path swap. I can open a follow-up issue/PR for the rest if that works.

@FW-Nagorko FW-Nagorko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after the changes, LGTM

@patryk-przybysz

Copy link
Copy Markdown
Collaborator Author

Tested on my machine ✅

Ran into a permission issue at first - the agent needs to be run with sudo (or otherwise granted read access to the powercap sysfs entries) for the metrics to show up. With sudo everything works as expected.

This will be properly resolved once we do proper packaging as a systemd daemon/service - no need to block this PR on that. 😄

@patryk-przybysz
patryk-przybysz merged commit d4d53fb into devel Aug 8, 2026
1 of 2 checks passed
@patryk-przybysz
patryk-przybysz deleted the feat/agent-rapl-powercap branch August 8, 2026 22:36
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

Successfully merging this pull request may close these issues.

2 participants