Skip to content

Commit

Permalink
ACPI: Update to only read cpu freq files when BPF is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Amaral <[email protected]>
  • Loading branch information
marceloamaral committed Nov 29, 2022
1 parent 855e7fc commit 13c9ddb
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/power/acpi/acpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ func NewACPIPowerMeter() *ACPI {
return acpi
}

func (a *ACPI) Run() {
func (a *ACPI) Run(isEBPFEnabled bool) {
go func() {
for {
select {
case <-a.stopChannel:
return
default:
cpuCoreFrequency := getCPUCoreFrequency()
a.mu.Lock()
for cpu, freq := range cpuCoreFrequency {
// average cpu frequency
a.cpuCoreFrequency[cpu] = (cpuCoreFrequency[cpu] + freq) / 2
// in the case we cannot collect the cpu frequency using EBPF
if !isEBPFEnabled {
cpuCoreFrequency := getCPUCoreFrequency()
a.mu.Lock()
for cpu, freq := range cpuCoreFrequency {
// average cpu frequency
a.cpuCoreFrequency[cpu] = (cpuCoreFrequency[cpu] + freq) / 2
}
a.mu.Unlock()
}
a.mu.Unlock()

if a.collectEnergy {
if sensorPower, err := getPowerFromSensor(); err == nil {
Expand All @@ -92,6 +95,11 @@ func (a *ACPI) Run() {
}
}

// stop the gorotime if there is nothing to do
if (isEBPFEnabled) && (!a.collectEnergy) {
return
}

time.Sleep(poolingInterval)
}
}
Expand Down

0 comments on commit 13c9ddb

Please sign in to comment.