Skip to content

Commit

Permalink
fix(bpf): exclude swapper process bpf_cpu_time (#1830)
Browse files Browse the repository at this point in the history
Signed-off-by: Vimal Kumar <[email protected]>
  • Loading branch information
vimalk78 authored Nov 4, 2024
1 parent d23e90e commit 75b9533
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func UpdateProcessBPFMetrics(bpfExporter bpf.Exporter, processStats map[uint64]*
for _, ct := range processesData {
comm := C.GoString((*C.char)(unsafe.Pointer(&ct.Comm)))

if ct.Pid == 0 && config.ExcludeSwapperProcess() {
// exclude swapper process
continue
}

if ct.Pid != 0 {
klog.V(6).Infof("process %s (pid=%d, cgroup=%d) has %d process run time, %d CPU cycles, %d instructions, %d cache misses, %d page cache hits",
comm, ct.Pid, ct.CgroupId, ct.ProcessRunTime, ct.CpuCycles, ct.CpuInstr, ct.CacheMiss, ct.PageCacheHit)
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type KeplerConfig struct {
EstimatorSelectFilter string
CPUArchOverride string
MachineSpecFilePath string
ExcludeSwapperProcess bool
}
type MetricsConfig struct {
CoreUsageMetric string
Expand Down Expand Up @@ -158,6 +159,7 @@ func getKeplerConfig() KeplerConfig {
EstimatorModel: getConfig("ESTIMATOR_MODEL", defaultMetricValue),
EstimatorSelectFilter: getConfig("ESTIMATOR_SELECT_FILTER", defaultMetricValue), // no filter
CPUArchOverride: getConfig("CPU_ARCH_OVERRIDE", defaultCPUArchOverride),
ExcludeSwapperProcess: getBoolConfig("EXCLUDE_SWAPPER_PROCESS", defaultExcludeSwapperProcess),
}
}

Expand Down Expand Up @@ -262,6 +264,7 @@ func logBoolConfigs() {
klog.V(5).Infof("EXPOSE_COMPONENT_POWER: %t", instance.Kepler.ExposeComponentPower)
klog.V(5).Infof("EXPOSE_ESTIMATED_IDLE_POWER_METRICS: %t. This only impacts when the power is estimated using pre-prained models. Estimated idle power is meaningful only when Kepler is running on bare-metal or with a single virtual machine (VM) on the node.", instance.Kepler.ExposeIdlePowerMetrics)
klog.V(5).Infof("EXPERIMENTAL_BPF_SAMPLE_RATE: %d", instance.Kepler.BPFSampleRate)
klog.V(5).Infof("EXCLUDE_SWAPPER_PROCESS: %t", instance.Kepler.ExcludeSwapperProcess)
}
}

Expand Down Expand Up @@ -681,3 +684,8 @@ func DCGMHostEngineEndpoint() string {
ensureConfigInitialized()
return instance.DCGMHostEngineEndpoint
}

func ExcludeSwapperProcess() bool {
ensureConfigInitialized()
return instance.Kepler.ExcludeSwapperProcess
}
11 changes: 6 additions & 5 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ const (
// MaxIRQ is the maximum number of IRQs to be monitored
MaxIRQ = 10
// defaultSamplePeriodSec is the time in seconds that the reader will wait before reading the metrics again
defaultSamplePeriodSec = 3
configDir = "/etc/kepler/kepler.config"
defaultKubeConfig = ""
defaultBPFSampleRate = 0
defaultCPUArchOverride = ""
defaultSamplePeriodSec = 3
configDir = "/etc/kepler/kepler.config"
defaultKubeConfig = ""
defaultBPFSampleRate = 0
defaultCPUArchOverride = ""
defaultExcludeSwapperProcess = false
// model_parameter_prefix
defaultNodePlatformPowerKey = "NODE_TOTAL"
defaultNodeComponentsPowerKey = "NODE_COMPONENTS"
Expand Down

0 comments on commit 75b9533

Please sign in to comment.