Skip to content

feat(cpu): add AMD ESMI power meter support - #2566

Open
sivapt12 wants to merge 3 commits into
sustainable-computing-io:mainfrom
sivapt12:esmi-cpu-power-meter
Open

sivapt12 wants to merge 3 commits into
sustainable-computing-io:mainfrom
sivapt12:esmi-cpu-power-meter

Conversation

@sivapt12

Copy link
Copy Markdown

Summary

This PR adds support for AMD Energy System Management Interface (E-SMI) for CPU power monitoring on AMD EPYC platforms. It includes two commits:

  1. Refactor: CPUPowerMeter implementation into cpu package (prerequisite)
  2. Feature: Add AMD ESMI power meter with per-socket DIMM monitoring

Key Features

  • ESMI CPU power meter implementation with multiple backends:
    • goamdsmi: Uses E-SMI C library (libe_smi64.so) for socket/core energy + DIMM power
    • sysfs: Pure Go fallback using amd_energy kernel module
  • Per-socket DIMM power monitoring - aggregated power per socket
  • Individual zone naming (package-N, core-N, dimm-N) matching RAPL/sysfs behavior
  • Experimental config flag: experimental.esmi.enabled
  • Shared E-SMI initialization to prevent library re-init crashes

Zone Types

Zone Granularity Energy() Power() Notes
package-N Per-socket ✅ µJ ✅ Watts Socket-level power
core-N Per-thread ✅ µJ ❌ N/A Per-logical-thread energy
dimm-N Per-socket ❌ N/A ✅ Watts Aggregated DIMM power

Build Options

  • Default: make build - Uses sysfs backend only (no external deps)
  • With E-SMI: make build TAGS=goamdsmi - Enables all backends (requires libe_smi64.so)

Test Results

✅ All tests passing (18/18 packages, 84-100% coverage)
✅ Verified on AMD EPYC system with 2 sockets, 256 cores, 16 DIMMs

Sample Metrics

# Package zones (per-socket)
kepler_node_cpu_watts{path="esmi://cpu/socket/0",zone="package-0"} 150.7
kepler_node_cpu_watts{path="esmi://cpu/socket/1",zone="package-1"} 150.7

# DIMM zones (per-socket aggregated)
kepler_node_cpu_watts{path="esmi://cpu/socket/0/dimm",zone="dimm-0"} 7.025e-05
kepler_node_cpu_watts{path="esmi://cpu/socket/1/dimm",zone="dimm-1"} 7.55e-05

# Core zones (per-thread)
kepler_node_cpu_joules_total{path="esmi://cpu/core/0",zone="core-0"} ...

Configuration Example

experimental:
  esmi:
    enabled: true

Related Issues

Adds AMD platform support for CPU power monitoring to complement existing Intel RAPL support.

Checklist

  • Code follows conventional commit format
  • All tests pass with race detection
  • DCO sign-off included
  • SPDX headers on all new files
  • Matches existing RAPL patterns and conventions
  • Documentation in commit message

🤖 Generated with Claude Code

@github-actions github-actions Bot added the feat A new feature or enhancement label Sep 29, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Config changes detected in this PR
Please make sure that the config changes are updated in the following places as part of this PR:

  • docs/user/configuration.md
  • compose/dev/kepler-dev/etc/kepler/config.yaml
  • compose/default/kepler/etc/kepler/config.yaml
  • manifests/k8s/configmap.yaml
  • manifests/helm/kepler/values.yaml

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 21.64009% with 344 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (2677e75) to head (4f46308).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
internal/device/cpu/esmi/power_meter.go 0.00% 173 Missing ⚠️
internal/device/cpu/esmi/sysfs_reader.go 0.00% 139 Missing ⚠️
config/config.go 54.54% 8 Missing and 2 partials ⚠️
internal/device/cpu/mock_cpu_power_meter.go 16.66% 10 Missing ⚠️
internal/device/cpu/create_meter.go 0.00% 5 Missing ⚠️
internal/device/cpu/esmi/backends_default.go 0.00% 3 Missing ⚠️
internal/device/cpu/fake_cpu_power_meter.go 85.71% 2 Missing ⚠️
internal/device/energy_zone.go 50.00% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (21.64%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2566      +/-   ##
==========================================
- Coverage   92.41%   86.71%   -5.71%     
==========================================
  Files          58       61       +3     
  Lines        6121     6464     +343     
==========================================
- Hits         5657     5605      -52     
- Misses        329      724     +395     
  Partials      135      135              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📊 Profiling reports are ready to be viewed

⚠️ Variability in pprof CPU and Memory profiles
When comparing pprof profiles of Kepler versions, expect variability in CPU and memory. Focus only on significant, consistent differences.

💻 CPU Comparison with base Kepler
File: kepler
Build ID: 2ede9533b75d1187da34335059eb8e409cb7c782
Type: cpu
Time: 2026-10-04 15:54:25 UTC
Duration: 120s, Total samples = 3.87s ( 3.22%)
Active filters:
   show=github.com/sustainable-computing-io
Showing nodes accounting for -0.07s, 1.81% of 3.87s total
Dropped 1 node (cum <= 0.02s)
      flat  flat%   sum%        cum   cum%
         0     0%     0%      0.14s  3.62%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*gpuInfoCollector).Collect
         0     0%     0%     -0.12s  3.10%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).Collect
    -0.06s  1.55%  1.55%     -0.06s  1.55%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).CPUUsageRatio
         0     0%  1.55%     -0.06s  1.55%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh.func3
         0     0%  1.55%     -0.06s  1.55%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshNode
         0     0%  1.55%     -0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).scheduleNextCollection.func1
    -0.01s  0.26%  1.81%     -0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).updateProcessCache
     0.02s  0.52%  1.29%      0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).collectProcessMetrics
    -0.01s  0.26%  1.55%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*cpuInfoCollector).Collect
         0     0%  1.55%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculatePower
         0     0%  1.55%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).refreshSnapshot
         0     0%  1.55%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh
         0     0%  1.55%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh.func1
     0.02s  0.52%  1.03%      0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).StringID (inline)
     0.01s  0.26%  0.78%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshProcesses
         0     0%  0.78%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/resource.newProcess
         0     0%  0.78%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/resource.populateProcessFields
    -0.02s  0.52%  1.29%     -0.02s  0.52%  maps.Copy[go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.interface { Energy ; Index int; MaxEnergy github.com/sustainable-computing-io/kepler/internal/device.Energy; Name string; Path string; Power  },go.shape.struct { EnergyTotal github.com/sustainable-computing-io/kepler/internal/device.Energy; Power github.com/sustainable-computing-io/kepler/internal/device.Power }] (inline)
         0     0%  1.29%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/device.(*AggregatedZone).Energy
    -0.01s  0.26%  1.55%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/device.sysfsRaplZone.Energy
         0     0%  1.55%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PlatformCollector).Collect
    -0.01s  0.26%  1.81%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*realProcFS).CPUInfo
         0     0%  1.81%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateNodePower
         0     0%  1.81%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).ensureFreshData
     0.01s  0.26%  1.55%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).Clone (inline)
         0     0%  1.55%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Snapshot).Clone
         0     0%  1.55%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/platform/redfish.(*PowerReader).ReadAll
     0.01s  0.26%  1.29%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/platform/redfish.(*PowerReader).readPowerSubsystem
         0     0%  1.29%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/platform/redfish.(*Service).Power
    -0.01s  0.26%  1.55%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).CPUTime
    -0.01s  0.26%  1.81%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).CmdLine
    -0.01s  0.26%  2.07%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).Comm
     0.01s  0.26%  1.81%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh
         0     0%  1.81%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func2
         0     0%  1.81%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromProc
💾 Memory Comparison with base Kepler (Inuse)
File: kepler
Build ID: 2ede9533b75d1187da34335059eb8e409cb7c782
Type: inuse_space
Time: 2026-10-04 15:56:25 UTC
Duration: 120.02s, Total samples = 6517.38kB 
Active filters:
   show=github.com/sustainable-computing-io
Showing nodes accounting for -1042.97kB, 16.00% of 6517.38kB total
      flat  flat%   sum%        cum   cum%
         0     0%     0%  -528.17kB  8.10%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func1
         0     0%     0%  -528.17kB  8.10%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func2
 -528.17kB  8.10%  8.10%  -528.17kB  8.10%  github.com/sustainable-computing-io/kepler/internal/resource.containerInfoFromCgroupPaths
         0     0%  8.10%  -528.17kB  8.10%  github.com/sustainable-computing-io/kepler/internal/resource.containerInfoFromProc
 -528.17kB  8.10% 16.21%  -528.17kB  8.10%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromCmdLine
         0     0% 16.21%  -528.17kB  8.10%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromProc
         0     0% 16.21%   525.43kB  8.06%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculatePower
  525.43kB  8.06%  8.15%   525.43kB  8.06%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateProcessPower
         0     0%  8.15%   525.43kB  8.06%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).refreshSnapshot
         0     0%  8.15%   525.43kB  8.06%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).scheduleNextCollection.func1
         0     0%  8.15%   525.43kB  8.06%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh
         0     0%  8.15%   525.43kB  8.06%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh.func1
         0     0%  8.15%  -512.06kB  7.86%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*gpuInfoCollector).Collect
         0     0%  8.15%  -512.06kB  7.86%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).Snapshot
 -512.06kB  7.86% 16.00%  -512.06kB  7.86%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).Clone (inline)
         0     0% 16.00%  -512.06kB  7.86%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Snapshot).Clone
💾 Memory Comparison with base Kepler (Alloc)
File: kepler
Build ID: 2ede9533b75d1187da34335059eb8e409cb7c782
Type: alloc_space
Time: 2026-10-04 15:56:25 UTC
Duration: 120.02s, Total samples = 184.25MB 
Active filters:
   show=github.com/sustainable-computing-io
Showing nodes accounting for -3.44MB, 1.87% of 184.25MB total
Dropped 1 node (cum <= 0.92MB)
      flat  flat%   sum%        cum   cum%
         0     0%     0%    -7.54MB  4.09%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).Collect
   -3.02MB  1.64%  1.64%    -4.52MB  2.45%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).AllProcs
    4.50MB  2.44%   0.8%     4.50MB  2.44%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).CPUTime
       1MB  0.54%  1.35%     4.13MB  2.24%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*cpuInfoCollector).Collect
         0     0%  1.35%    -4.05MB  2.20%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculatePower
         0     0%  1.35%        4MB  2.17%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).updateProcessCache
         0     0%  1.35%        4MB  2.17%  github.com/sustainable-computing-io/kepler/internal/resource.populateProcessFields
         0     0%  1.35%    -3.55MB  1.93%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).refreshSnapshot
         0     0%  1.35%    -3.55MB  1.93%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh
         0     0%  1.35%    -3.55MB  1.93%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh.func1
   -3.50MB  1.90%  0.55%    -3.50MB  1.90%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).collectProcessMetrics
    3.13MB  1.70%  1.14%     3.13MB  1.70%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*realProcFS).CPUInfo
         0     0%  1.14%    -2.54MB  1.38%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).Snapshot
         0     0%  1.14%    -2.03MB  1.10%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).ensureFreshData
   -0.51MB  0.28%  0.86%    -2.01MB  1.09%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateProcessPower
   -0.50MB  0.27%  0.59%    -1.53MB  0.83%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh
         0     0%  0.59%    -1.52MB  0.82%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).scheduleNextCollection.func1
   -1.50MB  0.81%  0.22%    -1.50MB  0.81%  github.com/sustainable-computing-io/kepler/internal/resource.WrapProc (inline)
         0     0%  0.22%     1.49MB  0.81%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*gpuInfoCollector).Collect
         0     0%  0.22%     1.03MB  0.56%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func2
    1.03MB  0.56%  0.34%     1.03MB  0.56%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromCmdLine
         0     0%  0.34%     1.03MB  0.56%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromProc
   -0.51MB  0.28%  0.06%    -1.03MB  0.56%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshProcesses
         0     0%  0.06%    -1.02MB  0.55%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func1
         0     0%  0.06%    -1.02MB  0.55%  github.com/sustainable-computing-io/kepler/internal/resource.containerInfoFromProc
      -1MB  0.54%  0.48%       -1MB  0.54%  github.com/sustainable-computing-io/kepler/internal/monitor.newProcess (inline)
   -0.52MB  0.28%  0.76%    -0.52MB  0.28%  github.com/sustainable-computing-io/kepler/internal/resource.containerInfoFromCgroupPaths
   -0.51MB  0.28%  1.04%    -0.51MB  0.28%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Snapshot).Clone
   -0.50MB  0.27%  1.31%    -0.50MB  0.27%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).Cgroups
   -0.50MB  0.27%  1.59%    -0.50MB  0.27%  maps.Copy[go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.interface { Energy ; Index int; MaxEnergy github.com/sustainable-computing-io/kepler/internal/device.Energy; Name string; Path string; Power  },go.shape.struct { EnergyTotal github.com/sustainable-computing-io/kepler/internal/device.Energy; Power github.com/sustainable-computing-io/kepler/internal/device.Power }] (inline)
   -0.50MB  0.27%  1.86%    -0.50MB  0.27%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateContainerPower
    0.50MB  0.27%  1.59%     0.50MB  0.27%  github.com/sustainable-computing-io/kepler/internal/monitor.NewSnapshot (inline)
   -0.50MB  0.27%  1.86%    -0.50MB  0.27%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).Executable
   -0.50MB  0.27%  2.13%    -0.50MB  0.27%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).StringID (inline)
    0.48MB  0.26%  1.87%     0.48MB  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).CPUUsageRatio
         0     0%  1.87%     0.48MB  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh.func3
         0     0%  1.87%     0.48MB  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshNode

⬇️ Download the Profiling artifacts from the Actions Summary page

📦 Artifact name: profile-artifacts-2566

🔧 Or use GitHub CLI to download artifacts:

gh run download 36509427626 -n profile-artifacts-2566

Consolidate all CPU-specific power measurement implementations
(hwmon, RAPL, fake, mock) into cpu package.
This refactor decouples CPU power metering logic from the
generic device layer, improving code organization, modularity
and maintainability while preserving existing functionality.

Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
Add support for AMD Energy System Management Interface (E-SMI) for CPU
power monitoring on AMD platforms. This enables accurate power measurements
on AMD EPYC processors through E-SMI C library and sysfs fallback, including
per-socket DIMM power consumption monitoring.

Key changes:
- Add ESMI CPU power meter implementation (internal/device/cpu/esmi/)
- Support goamdsmi backend via E-SMI C library (libe_smi64.so)
- Support per-socket DIMM power consumption monitoring (dimm backend)
- Include sysfs fallback backend (pure Go, no dependencies)
- Add experimental.esmi.enabled config flag
- Integrate ESMI into CPU meter selection via cpu.preferredMeters
- Shared E-SMI library initialization to prevent re-init crashes
- Individual zone naming (package-N, core-N, dimm-N) matching sysfs behavior

The ESMI meter is automatically prepended to cpu.preferredMeters when
experimental.esmi.enabled is set to true, making it the first-tried
CPU power source on supported AMD hardware.

Zone types:
- package-N: Per-socket energy (µJ) + instantaneous power (W)
- core-N: Per-logical-thread energy (µJ)
- dimm-N: Per-socket aggregated DIMM instantaneous power (W)

Build options:
- Default build: Uses sysfs backend only (no external dependencies)
- With -tags goamdsmi: Adds E-SMI C library backends (requires libe_smi64.so)
  Installation: /opt/e-sms/e_smi/ or adjust CGO paths in source files

Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
- Update configuration documentation for experimental.esmi.enabled
- Add config examples in compose/dev, compose/default, k8s, and helm
- Add comprehensive unit tests for ESMI power meter (16.9% coverage)
- Tests cover PowerMeter interface, Init, Zones, and caching behavior

Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
@sivapt12
sivapt12 force-pushed the esmi-cpu-power-meter branch from 4f46308 to 2b8be94 Compare October 5, 2026 08:25
@github-actions github-actions Bot added the refactor Code refactoring without changing functionality label Oct 5, 2026
@bitflicker64
bitflicker64 requested a balanced review from Copilot October 5, 2026 08:37
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

📊 Profiling reports are ready to be viewed

⚠️ Variability in pprof CPU and Memory profiles
When comparing pprof profiles of Kepler versions, expect variability in CPU and memory. Focus only on significant, consistent differences.

💻 CPU Comparison with base Kepler
File: kepler
Build ID: 825fe8bbfff6a4406f29441c45069fec635603bf
Type: cpu
Time: 2026-10-05 08:40:24 UTC
Duration: 120s, Total samples = 3.84s ( 3.20%)
Active filters:
   show=github.com/sustainable-computing-io
Showing nodes accounting for 0, 0% of 3.84s total
      flat  flat%   sum%        cum   cum%
         0     0%     0%      0.05s  1.30%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*gpuInfoCollector).Collect
    -0.04s  1.04%  1.04%     -0.04s  1.04%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).AllProcs
         0     0%  1.04%     -0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).Collect
     0.03s  0.78%  0.26%      0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateProcessPower
         0     0%  0.26%     -0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).scheduleNextCollection.func1
         0     0%  0.26%     -0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh
     0.01s  0.26%     0%     -0.03s  0.78%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshProcesses
    -0.01s  0.26%  0.26%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*cpuInfoCollector).Collect
         0     0%  0.26%      0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).ensureFreshData
    -0.02s  0.52%  0.78%     -0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).CPUTime
         0     0%  0.78%      0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func1
         0     0%  0.78%      0.02s  0.52%  github.com/sustainable-computing-io/kepler/internal/resource.containerInfoFromProc
     0.01s  0.26%  0.52%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).collectProcessMetrics
    -0.01s  0.26%  0.78%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*realProcFS).CPUInfo
     0.01s  0.26%  0.52%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/logger.handlerForFormat.func1
         0     0%  0.52%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).Snapshot
    -0.01s  0.26%  0.78%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).refreshSnapshot
         0     0%  0.78%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh
         0     0%  0.78%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh.func1
    -0.02s  0.52%  1.30%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).Clone (inline)
     0.01s  0.26%  1.04%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).StringID (inline)
         0     0%  1.04%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Snapshot).Clone
    -0.01s  0.26%  1.30%     -0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/monitor.newProcess (inline)
     0.01s  0.26%  1.04%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).CPUUsageRatio
     0.01s  0.26%  0.78%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).Cgroups
     0.01s  0.26%  0.52%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).Comm
     0.01s  0.26%  0.26%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).Executable
         0     0%  0.26%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh.func3
         0     0%  0.26%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshNode
     0.01s  0.26%     0%      0.01s  0.26%  github.com/sustainable-computing-io/kepler/internal/resource.containerInfoFromCgroupPaths
     0.01s  0.26%  0.26%      0.01s  0.26%  maps.Copy[go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.interface { Energy ; Index int; MaxEnergy github.com/sustainable-computing-io/kepler/internal/device.Energy; Name string; Path string; Power  },go.shape.struct { EnergyTotal github.com/sustainable-computing-io/kepler/internal/device.Energy; Power github.com/sustainable-computing-io/kepler/internal/device.Power }] (inline)
    -0.01s  0.26%     0%          0     0%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculatePodPower
💾 Memory Comparison with base Kepler (Inuse)
File: kepler
Build ID: 825fe8bbfff6a4406f29441c45069fec635603bf
Type: inuse_space
Time: 2026-10-05 08:42:24 UTC
Duration: 120.02s, Total samples = 13824.29kB 
Active filters:
   show=github.com/sustainable-computing-io
Showing nodes accounting for -1542.90kB, 11.16% of 13824.29kB total
Dropped 2 nodes (cum <= 69.12kB)
      flat  flat%   sum%        cum   cum%
         0     0%     0% -2070.85kB 14.98%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculatePower
         0     0%     0% -2070.85kB 14.98%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).refreshSnapshot
         0     0%     0% -2070.85kB 14.98%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh
         0     0%     0% -2070.85kB 14.98%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh.func1
         0     0%     0% -2066.35kB 14.95%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).scheduleNextCollection.func1
-1042.07kB  7.54%  7.54% -1554.21kB 11.24%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateProcessPower
-1024.28kB  7.41% 14.95% -1024.28kB  7.41%  maps.Copy[go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.interface { Energy ; Index int; MaxEnergy github.com/sustainable-computing-io/kepler/internal/device.Energy; Name string; Path string; Power  },go.shape.struct { EnergyTotal github.com/sustainable-computing-io/kepler/internal/device.Energy; Power github.com/sustainable-computing-io/kepler/internal/device.Power }] (inline)
 1024.06kB  7.41%  7.54%  1024.06kB  7.41%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).collectProcessMetrics
         0     0%  7.54%  1023.91kB  7.41%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).Collect
         0     0%  7.54%   528.17kB  3.82%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func2
  528.17kB  3.82%  3.72%   528.17kB  3.82%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromCmdLine
         0     0%  3.72%   528.17kB  3.82%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromProc
 -516.64kB  3.74%  7.46%  -516.64kB  3.74%  github.com/sustainable-computing-io/kepler/internal/resource.(*procWrapper).CPUTime
         0     0%  7.46%  -516.64kB  3.74%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh
         0     0%  7.46%  -516.64kB  3.74%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshProcesses
         0     0%  7.46%  -516.64kB  3.74%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).updateProcessCache
         0     0%  7.46%  -516.64kB  3.74%  github.com/sustainable-computing-io/kepler/internal/resource.populateProcessFields
 -512.14kB  3.70% 11.16%  -512.14kB  3.70%  github.com/sustainable-computing-io/kepler/internal/monitor.newProcess (inline)
         0     0% 11.16%    -4.65kB 0.034%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).Snapshot
         0     0% 11.16%    -4.50kB 0.033%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*gpuInfoCollector).Collect
         0     0% 11.16%    -4.50kB 0.033%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).ensureFreshData
💾 Memory Comparison with base Kepler (Alloc)
File: kepler
Build ID: 825fe8bbfff6a4406f29441c45069fec635603bf
Type: alloc_space
Time: 2026-10-05 08:42:24 UTC
Duration: 120.02s, Total samples = 189972148B 
Active filters:
   show=github.com/sustainable-computing-io
Showing nodes accounting for 3345835B, 1.76% of 189972148B total
Dropped 6 nodes (cum <= 949860B)
      flat  flat%   sum%        cum   cum%
         0     0%     0% -11539936B  6.07%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).Snapshot
         0     0%     0%  -8962288B  4.72%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).Collect
         0     0%     0%  -6834174B  3.60%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).ensureFreshData
 -2097328B  1.10%  1.10%  -4719488B  2.48%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Process).Clone (inline)
   538038B  0.28%  0.82%  -4705762B  2.48%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Snapshot).Clone
  1048660B  0.55%  0.27%   3761669B  1.98%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*cpuInfoCollector).Collect
  3754609B  1.98%  1.71%   3754609B  1.98%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).CPUUsageRatio
         0     0%  1.71%   3754609B  1.98%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh.func3
         0     0%  1.71%   3754609B  1.98%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshNode
         0     0%  1.71%  -3725552B  1.96%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculatePower
         0     0%  1.71%  -3725552B  1.96%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).refreshSnapshot
         0     0%  1.71%  -3725552B  1.96%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh
         0     0%  1.71%  -3725552B  1.96%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).synchronizedPowerRefresh.func1
         0     0%  1.71%   3108622B  1.64%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).scheduleNextCollection.func1
  2713009B  1.43%  3.14%   2713009B  1.43%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*realProcFS).CPUInfo
 -2622160B  1.38%  1.76%  -2622160B  1.38%  maps.Copy[go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.map[github.com/sustainable-computing-io/kepler/internal/device.EnergyZone]github.com/sustainable-computing-io/kepler/internal/monitor.Usage,go.shape.interface { Energy ; Index int; MaxEnergy github.com/sustainable-computing-io/kepler/internal/device.Energy; Name string; Path string; Power  },go.shape.struct { EnergyTotal github.com/sustainable-computing-io/kepler/internal/device.Energy; Power github.com/sustainable-computing-io/kepler/internal/device.Power }] (inline)
         0     0%  1.76%   2163371B  1.14%  github.com/sustainable-computing-io/kepler/internal/resource.computeTypeInfoFromProc.func2
  2163371B  1.14%  2.89%   2163371B  1.14%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromCmdLine
         0     0%  2.89%   2163371B  1.14%  github.com/sustainable-computing-io/kepler/internal/resource.vmInfoFromProc
  -538038B  0.28%  2.61%  -1586782B  0.84%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateProcessPower
  1568314B  0.83%  3.44%   1568314B  0.83%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PowerCollector).collectProcessMetrics
         0     0%  3.44%  -1089930B  0.57%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).Refresh
        1B 5.3e-07%  3.44%  -1089930B  0.57%  github.com/sustainable-computing-io/kepler/internal/resource.(*resourceInformer).refreshProcesses
 -2133645B  1.12%  2.31%  -1085037B  0.57%  github.com/sustainable-computing-io/kepler/internal/resource.(*procFSReader).AllProcs
 -1048744B  0.55%  1.76%  -1048744B  0.55%  github.com/sustainable-computing-io/kepler/internal/monitor.newProcess (inline)
  1048608B  0.55%  2.31%   1048608B  0.55%  github.com/sustainable-computing-io/kepler/internal/resource.WrapProc (inline)
         0     0%  2.31%  -1009334B  0.53%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*gpuInfoCollector).Collect
         0     0%  2.31%   -524432B  0.28%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateContainerPower
  -524432B  0.28%  2.04%   -524432B  0.28%  github.com/sustainable-computing-io/kepler/internal/monitor.newContainer (inline)
  -524408B  0.28%  1.76%   -524408B  0.28%  github.com/sustainable-computing-io/kepler/internal/monitor.(*PowerMonitor).calculateNodePower
  -524312B  0.28%  1.49%   -524312B  0.28%  github.com/sustainable-computing-io/kepler/internal/monitor.(*Node).Clone (inline)
         0     0%  1.49%    524292B  0.28%  github.com/sustainable-computing-io/kepler/internal/exporter/prometheus/collector.(*PlatformCollector).Collect
   524292B  0.28%  1.76%    524292B  0.28%  github.com/sustainable-computing-io/kepler/internal/platform/redfish.(*PowerReader).ReadAll
         0     0%  1.76%    524292B  0.28%  github.com/sustainable-computing-io/kepler/internal/platform/redfish.(*Service).Power

⬇️ Download the Profiling artifacts from the Actions Summary page

📦 Artifact name: profile-artifacts-2566

🔧 Or use GitHub CLI to download artifacts:

gh run download 37283531943 -n profile-artifacts-2566

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Power units, sysfs zone normalization, primary-zone selection, and removed factory coverage must be corrected.

Review effort: Balanced
Findings: 2 High severity · 1 Medium severity · 1 Low severity

Open (4)
What changed in this PR

Adds AMD E-SMI CPU power monitoring while reorganizing CPU meter implementations into a dedicated package.

Changes:

  • Adds sysfs and optional CGo E-SMI backends, including DIMM monitoring.
  • Adds ESMI configuration, manifests, and documentation.
  • Refactors CPU meter interfaces, implementations, and tests.
File Description
manifests/​k8s/​configmap.yaml Adds ESMI configuration.
manifests/​helm/​kepler/​values.yaml Adds Helm ESMI setting.
Makefile Adds tagged CGo builds.
internal/​monitor/​node_test.go Updates CPU test imports.
internal/​monitor/​monitor.go Uses CPU package interface.
internal/​monitor/​monitor_test.go Updates CPU test helpers.
internal/​monitor/​monitor_concurrency_test.go Updates fake meter imports.
internal/​monitor/​mock_utils.go Adapts mocks to device zones.
internal/​exporter/​stdout/​stdout_test.go Updates zone mock imports.
internal/​exporter/​prometheus/​collector/​power_collector_test.go Updates collector test zones.
internal/​exporter/​prometheus/​collector/​power_collector_concurrency_test.go Updates concurrency fixtures.
internal/​device/​power_meter.go Moves shared zone interface.
internal/​device/​energy_zone.go Exports zone key and count.
internal/​device/​energy_zone_test.go Updates exported key tests.
internal/​device/​cpu/​rapl_zone_filtering_test.go Moves RAPL tests to CPU package.
internal/​device/​cpu/​rapl_sysfs_power_meter.go Moves RAPL implementation.
internal/​device/​cpu/​rapl_sysfs_power_meter_test.go Updates moved RAPL tests.
internal/​device/​cpu/​mock_cpu_power_meter.go Moves CPU meter mocks.
internal/​device/​cpu/​hwmon_power_meter.go Moves hwmon implementation.
internal/​device/​cpu/​hwmon_power_meter_test.go Updates moved hwmon tests.
internal/​device/​cpu/​hwmon_chip_rules.go Moves hwmon rules.
internal/​device/​cpu/​fake_cpu_power_meter.go Moves fake CPU meter.
internal/​device/​cpu/​fake_cpu_power_meter_test.go Updates fake meter tests.
internal/​device/​cpu/​esmi/​sysfs_reader.go Adds AMD sysfs reader.
internal/​device/​cpu/​esmi/​power_meter.go Adds ESMI meter selection.
internal/​device/​cpu/​esmi/​power_meter_test.go Tests common ESMI behavior.
internal/​device/​cpu/​esmi/​goamdsmi_reader.go Adds CGo E-SMI reader.
internal/​device/​cpu/​esmi/​esmi_init.go Shares E-SMI initialization.
internal/​device/​cpu/​esmi/​dimm_reader.go Adds DIMM power monitoring.
internal/​device/​cpu/​esmi/​backends_goamdsmi.go Registers tagged backends.
internal/​device/​cpu/​esmi/​backends_default.go Registers default sysfs backend.
internal/​device/​cpu/​create_meter.go Adds ESMI factory dispatch.
internal/​device/​cpu/​cpu_power_meter.go Defines CPU meter interface.
internal/​device/​cpu_power_meter_test.go Removes previous factory tests.
hack/​config.yaml Documents ESMI configuration.
docs/​user/​configuration.md Documents ESMI usage.
config/​config.go Adds ESMI flags and validation.
config/​config_cpu_test.go Tests ESMI preference injection.
compose/​dev/​kepler-dev/​etc/​kepler/​config.yaml Adds development ESMI setting.
compose/​default/​kepler/​etc/​kepler/​config.yaml Adds default ESMI setting.
cmd/​kepler/​main.go Uses refactored CPU factory.
.gitignore Adds generated-file exclusions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return 0, fmt.Errorf("esmi/dimm: all DIMM reads failed for socket %d", z.socketIdx)
}

return device.Power(float64(totalPowerMw) / 1000.0), nil
if C.esmi_socket_power_read(C.uint32_t(z.socketIdx), &power) != 0 {
return 0, fmt.Errorf("esmi: esmi_socket_power_get failed for socket %d", z.socketIdx)
}
return device.Power(float64(power) / 1000.0), nil
Comment on lines +208 to +211
// Normalize AMD zone names to match RAPL conventions
if baseName == "socket" {
return "package"
}
Comment on lines +132 to +133
"load the amd_energy kernel module or install libamd_smi.so " +
"and rebuild with -tags goamdsmi",

@bitflicker64 bitflicker64 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking up AMD support. DIMM power on AMD is something Kepler can't report today, and that part is worth having. Most of the rest of the diff either repeats what Kepler already does or exists only to support other parts of this PR. Here is what I'd cut, biggest first.

  1. Keep the meter in internal/device. The internal/device/cpu move is about 1,150 lines of churn across 25 files. ESMI doesn't need it. The only constraint is that esmi, as a subpackage, imports device, so the factory in device can't import it back. If the ESMI files sit next to rapl_sysfs_power_meter.go and hwmon_power_meter.go, that goes away and the whole refactor commit can be dropped. The test mocks in esmi/power_meter_test.go could then reuse the existing ones in mock_cpu_power_meter.go.

  2. Drop sysfs_reader.go and backends_goamdsmi.go, and cut backends_default.go down to a stub that returns an error without the tag. The hwmon meter's discoverZones() already reads energy*_input and power*_input from any hwmon chip, which covers both amd_energy and amd_hsmp_hwmon. amd_energy was also removed from mainline in 5.13. Users without the tag can set cpu.preferredMeters: ["hwmon"]. This saves about 320 lines.

  3. Replace the backend selection framework with a direct call. With only the E-SMI library left, backendCandidate, the additive flag, mergedReader, the Reader interface and the primary/additive probe loop in NewCPUPowerMeter are not needed. The constructor can call esmiInit() and build the zones. Init() already probes them again anyway. This saves about 110 lines.

  4. Drop experimental.esmi.enabled. It does the same thing as cpu.preferredMeters: ["esmi", "rapl", "hwmon"], and this PR already accepts esmi in Validate(). Removing it also removes the block in ApplyCpuMeterDeprecations, the CLI flag, the IsFeatureEnabled case, the docs section, and the edits to the compose, hack, Helm and k8s configs. This saves about 110 lines.

  5. Shrink PrimaryEnergyZone() and drop filterZones(). Nothing in production calls the esmi WithZoneFilter, because create_meter.go only passes WithLogger. If the socket and DIMM zones are named package and dimm with the socket as the index, the way RAPL names them, groupZonesByName() aggregates them like RAPL does and PrimaryEnergyZone() becomes a lookup of package. This saves about 80 lines.

  6. Drop the core zones in goamdsmi_reader.go. There is one core-N zone per logical CPU, and each zone is a zone label value on process, container, pod and VM metrics, so a 256-core host gets 256 or more series per workload per metric. Attribution splits every zone by node-wide CPU time anyway, so the per-thread counters don't make it more precise. Keep the package zones. CreateCPUMeter uses a single CPU meter, so an esmi meter with only DIMM zones would replace RAPL instead of adding to it. This saves about 65 lines.

  7. Use one cgo preamble. esmi_init.go, dimm_reader.go and goamdsmi_reader.go each repeat the /opt/e-sms flags, and esmi_num_sockets is defined twice. The energy and power wrappers only cast the return value, so Go can call C.esmi_socket_energy_get directly and compare against C.ESMI_SUCCESS. Only the DIMM helper needs to stay, because cgo can't read the bitfields in struct dimm_power. This saves about 50 lines.

  8. Drop the Makefile block. make build BUILD_ARGS="-tags goamdsmi" already works on main, CC ?= cc matches make's built-in default, and nothing here is C++, so -lstdc++ and -std=c++11 aren't needed. This saves about 20 lines.

  9. Delete dimmBackend() and zoneNames(). Nothing calls them. This saves about 15 lines.

All together, that's about 770 of the 1,460 lines the two feature commits add, plus the 1,150-line package move. What's left is a socket and DIMM meter of a few hundred lines that's easy to review.

Separately from the cuts, three things need fixing either way. Socket and DIMM power are divided by 1000, but device.Power is in microwatts, so both come out a million times too small, as Copilot already flagged. PrimaryEnergyZone() looks up package while the zones are named package-N, so it falls through to whichever energy zone comes first out of a map, usually a core zone. The test presets topZone, so it doesn't catch this. And the move deletes the 12 TestCreateCPUMeter_* and TestBuildCPUMeter_* tests instead of moving them.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat A new feature or enhancement refactor Code refactoring without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants