Skip to content

Commit

Permalink
wip: Fix it?
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
  • Loading branch information
dave-tucker committed May 16, 2024
1 parent 53589c5 commit 7e4408b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
27 changes: 14 additions & 13 deletions pkg/bpf/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,22 @@ func (e *exporter) attach() error {
}

if config.ExposeIRQCounterMetrics {
// attach softirq_entry tracepoint to kepler_irq_trace function
irq_prog, err := e.module.GetProgram("kepler_irq_trace")
if err != nil {
klog.Warningf("could not get kepler_irq_trace: %v", err)
// disable IRQ metric
config.ExposeIRQCounterMetrics = false
} else {
if _, err := irq_prog.AttachGeneric(); err != nil {
klog.Warningf("could not attach irq/softirq_entry: %v", err)
// disable IRQ metric
config.ExposeIRQCounterMetrics = false
err := func() error {
// attach softirq_entry tracepoint to kepler_irq_trace function
irq_prog, err := e.module.GetProgram("kepler_irq_trace")
if err != nil {
return fmt.Errorf("could not get kepler_irq_trace: %v", err)
}
for _, event := range SoftIRQEvents {
e.enabledSoftwareCounters[event] = struct{}{}
if _, err := irq_prog.AttachGeneric(); err != nil {
return fmt.Errorf("could not attach irq/softirq_entry: %v", err)
}
e.enabledSoftwareCounters[config.IRQNetTXLabel] = struct{}{}
e.enabledSoftwareCounters[config.IRQNetRXLabel] = struct{}{}
e.enabledSoftwareCounters[config.IRQBlockLabel] = struct{}{}
return nil
}()
if err != nil {
klog.Warningf("IRQ tracing disabled: %v", err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/bpf/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func defaultHardwareCounters() map[string]struct{} {
func defaultSoftwareCounters() map[string]struct{} {
swCounters := map[string]struct{}{config.CPUTime: {}, config.PageCacheHit: {}}
if config.ExposeIRQCounterMetrics {
for _, event := range SoftIRQEvents {
swCounters[event] = struct{}{}
}
swCounters[config.IRQNetTXLabel] = struct{}{}
swCounters[config.IRQNetRXLabel] = struct{}{}
swCounters[config.IRQBlockLabel] = struct{}{}
}
return swCounters
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/bpf/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"github.com/sustainable-computing-io/kepler/pkg/config"
)

var SoftIRQEvents = []string{config.IRQNetTXLabel, config.IRQNetRXLabel, config.IRQBlockLabel}

type Exporter interface {
SupportedMetrics() SupportedMetrics
Detach()
Expand Down
27 changes: 19 additions & 8 deletions pkg/collector/resourceutilization/bpf/process_bpf_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,26 @@ import (
type ProcessBPFMetrics = bpf.ProcessBPFMetrics

// update software counter metrics
func updateSWCounters(key uint64, ct *ProcessBPFMetrics, processStats map[uint64]*stats.ProcessStats) {
func updateSWCounters(key uint64, ct *ProcessBPFMetrics, processStats map[uint64]*stats.ProcessStats, bpfSupportedMetrics bpf.SupportedMetrics) {
// update ebpf metrics
// first update CPU time and Page Cache Hit
processStats[key].ResourceUsage[config.CPUTime].AddDeltaStat(utils.GenericSocketID, ct.ProcessRunTime)
processStats[key].ResourceUsage[config.TaskClock].AddDeltaStat(utils.GenericSocketID, ct.TaskClockTime)
processStats[key].ResourceUsage[config.PageCacheHit].AddDeltaStat(utils.GenericSocketID, ct.PageCacheHit/(1000*1000))
// update IRQ vector. Soft IRQ events has the events ordered
for i, event := range bpf.SoftIRQEvents {
processStats[key].ResourceUsage[event].AddDeltaStat(utils.GenericSocketID, uint64(ct.VecNR[i]))
for counterKey := range bpfSupportedMetrics.SoftwareCounters {
switch counterKey {
case config.CPUTime:
processStats[key].ResourceUsage[config.CPUTime].AddDeltaStat(utils.GenericSocketID, ct.ProcessRunTime)
case config.TaskClock:
processStats[key].ResourceUsage[config.TaskClock].AddDeltaStat(utils.GenericSocketID, ct.TaskClockTime)
case config.PageCacheHit:
processStats[key].ResourceUsage[config.PageCacheHit].AddDeltaStat(utils.GenericSocketID, ct.PageCacheHit/(1000*1000))
case config.IRQNetTXLabel:
processStats[key].ResourceUsage[config.IRQNetTXLabel].AddDeltaStat(utils.GenericSocketID, uint64(ct.VecNR[bpf.IRQNetTX]))

Check failure on line 48 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / developer_local / unit_test_mac

undefined: bpf.IRQNetTX

Check failure on line 48 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / developer_local / unit_test_mac

undefined: bpf.IRQNetTX

Check failure on line 48 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / lint

undefined: bpf.IRQNetTX

Check failure on line 48 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / lint

undefined: bpf.IRQNetTX

Check failure on line 48 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / govet_test

undefined: bpf.IRQNetTX

Check failure on line 48 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / govet_test

undefined: bpf.IRQNetTX
case config.IRQNetRXLabel:
processStats[key].ResourceUsage[config.IRQNetRXLabel].AddDeltaStat(utils.GenericSocketID, uint64(ct.VecNR[bpf.IRQNetRX]))

Check failure on line 50 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / developer_local / unit_test_mac

undefined: bpf.IRQNetRX

Check failure on line 50 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / developer_local / unit_test_mac

undefined: bpf.IRQNetRX

Check failure on line 50 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / lint

undefined: bpf.IRQNetRX

Check failure on line 50 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / lint

undefined: bpf.IRQNetRX

Check failure on line 50 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / govet_test

undefined: bpf.IRQNetRX

Check failure on line 50 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / govet_test

undefined: bpf.IRQNetRX
case config.IRQBlockLabel:
processStats[key].ResourceUsage[config.IRQBlockLabel].AddDeltaStat(utils.GenericSocketID, uint64(ct.VecNR[bpf.IRQBlock]))

Check failure on line 52 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / developer_local / unit_test_mac

undefined: bpf.IRQBlock

Check failure on line 52 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / developer_local / unit_test_mac

undefined: bpf.IRQBlock

Check failure on line 52 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / lint

undefined: bpf.IRQBlock) (typecheck)

Check failure on line 52 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / lint

undefined: bpf.IRQBlock (typecheck)

Check failure on line 52 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / govet_test

undefined: bpf.IRQBlock

Check failure on line 52 in pkg/collector/resourceutilization/bpf/process_bpf_collector.go

View workflow job for this annotation

GitHub Actions / golang / govet_test

undefined: bpf.IRQBlock
default:
klog.Errorf("counter %s is not supported\n", counterKey)
}
}
}

Expand Down Expand Up @@ -126,7 +137,7 @@ func UpdateProcessBPFMetrics(bpfExporter bpf.Exporter, processStats map[uint64]*
// when the process metrics are updated, reset the idle counter
pStat.IdleCounter = 0

updateSWCounters(mapKey, &ct, processStats)
updateSWCounters(mapKey, &ct, processStats, bpfSupportedMetrics)
updateHWCounters(mapKey, &ct, processStats, bpfSupportedMetrics)
}
}
4 changes: 0 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ func IsCgroupMetricsEnabled() bool {
return ExposeCgroupMetrics
}

func IsIRQCounterMetricsEnabled() bool {
return ExposeIRQCounterMetrics
}

func SetGpuUsageMetric(metric string) {
GpuUsageMetric = metric
}

0 comments on commit 7e4408b

Please sign in to comment.