Documentation
¶
Index ¶
- Constants
- func CleanupOrphanedCPUFreqState(ctx context.Context, log logrus.FieldLogger, stateFiles []StateFile, ...) error
- func FormatFrequency(kHz uint64) string
- func HasWriteAccess(basePath string) error
- func IsCPUFreqSupported(basePath string) bool
- func ParseFrequency(freq string) (uint64, error)
- func RemoveStateFile(statePath string) error
- func RestoreFromStateFile(ctx context.Context, log logrus.FieldLogger, statePath, sysfsBasePath string) error
- func SaveState(cacheDir string, settings *OriginalSettings) (string, error)
- func ValidateFrequency(basePath string, freqKHz uint64) error
- func ValidateGovernor(basePath string, governor string) error
- type CPUInfo
- type CPUSettings
- type Config
- type Manager
- type OriginalSettings
- type StateFile
- type TurboBoostSettings
- type TurboBoostType
Constants ¶
const (
// DefaultSysfsCPUPath is the default sysfs path for CPU frequency control.
DefaultSysfsCPUPath = "/sys/devices/system/cpu"
)
Variables ¶
This section is empty.
Functions ¶
func CleanupOrphanedCPUFreqState ¶
func CleanupOrphanedCPUFreqState( ctx context.Context, log logrus.FieldLogger, stateFiles []StateFile, sysfsBasePath string, ) error
CleanupOrphanedCPUFreqState restores settings from all orphaned state files. sysfsBasePath is the base path for CPU sysfs files (e.g. "/sys/devices/system/cpu").
func FormatFrequency ¶
FormatFrequency formats a frequency in kHz to a human-readable string.
func HasWriteAccess ¶
HasWriteAccess checks if we have write access to CPU frequency sysfs files.
func IsCPUFreqSupported ¶
IsCPUFreqSupported checks if CPU frequency control is supported on this system.
func ParseFrequency ¶
ParseFrequency parses a frequency string and returns the value in kHz. Supported formats: "2000MHz", "2.4GHz", "2400000KHz", "2400000", "MAX".
func RemoveStateFile ¶
RemoveStateFile removes a state file.
func RestoreFromStateFile ¶
func RestoreFromStateFile( ctx context.Context, log logrus.FieldLogger, statePath, sysfsBasePath string, ) error
RestoreFromStateFile restores CPU frequency settings from a state file and removes it. sysfsBasePath is the base path for CPU sysfs files (e.g. "/sys/devices/system/cpu").
func SaveState ¶
func SaveState(cacheDir string, settings *OriginalSettings) (string, error)
SaveState saves the original CPU frequency settings to a state file.
func ValidateFrequency ¶
ValidateFrequency validates that the specified frequency is within system bounds.
func ValidateGovernor ¶
ValidateGovernor checks if the specified governor is available on the system.
Types ¶
type CPUInfo ¶
type CPUInfo struct {
ID int
MinFreqKHz uint64
MaxFreqKHz uint64
CurrentFreqKHz uint64
Governor string
AvailGovernors []string
ScalingMinKHz uint64
ScalingMaxKHz uint64
}
CPUInfo contains frequency information for a single CPU.
type CPUSettings ¶
type CPUSettings struct {
ScalingMaxKHz uint64 `json:"scaling_max_khz"`
ScalingMinKHz uint64 `json:"scaling_min_khz"`
Governor string `json:"governor"`
}
CPUSettings stores settings for a single CPU.
type Config ¶
type Config struct {
Frequency string // "2000MHz", "2.4GHz", "MAX", or empty (unchanged)
TurboBoost *bool // nil=unchanged, true=enable, false=disable
Governor string // Governor name, defaults to "performance" if Frequency is set
}
Config holds CPU frequency configuration.
type Manager ¶
type Manager interface {
Start(ctx context.Context) error
Stop() error
// Apply applies CPU frequency settings to the specified CPUs.
// If cpus is empty, settings are applied to all online CPUs.
Apply(ctx context.Context, cfg *Config, cpus []int) error
// Restore restores original CPU frequency settings.
Restore(ctx context.Context) error
// GetCPUInfo returns CPU frequency info for all online CPUs.
GetCPUInfo() ([]CPUInfo, error)
}
Manager controls CPU frequency settings for benchmark CPUs.
func NewManager ¶
func NewManager(log logrus.FieldLogger, cacheDir, sysfsBasePath string) Manager
NewManager creates a new CPU frequency manager. sysfsBasePath is the base path for CPU sysfs files (e.g. "/sys/devices/system/cpu").
type OriginalSettings ¶
type OriginalSettings struct {
CPUs map[int]*CPUSettings `json:"cpus"`
TurboBoost *TurboBoostSettings `json:"turbo_boost,omitempty"`
}
OriginalSettings stores the original CPU frequency settings before modification.
func LoadState ¶
func LoadState(statePath string) (*OriginalSettings, error)
LoadState loads CPU frequency settings from a state file.
type StateFile ¶
StateFile represents a CPU frequency state file for orphan detection.
func ListOrphanedStateFiles ¶
ListOrphanedStateFiles finds state files left behind by interrupted runs.
type TurboBoostSettings ¶
type TurboBoostSettings struct {
Type string `json:"type"` // "intel" or "amd"
Value int `json:"value"` // Original sysfs value
}
TurboBoostSettings stores turbo boost settings.
type TurboBoostType ¶
type TurboBoostType string
TurboBoostType represents the type of turbo boost control available.
const ( TurboBoostIntel TurboBoostType = "intel" TurboBoostAMD TurboBoostType = "amd" TurboBoostNone TurboBoostType = "none" )
func GetTurboBoostEnabled ¶
func GetTurboBoostEnabled(basePath string) (bool, TurboBoostType, error)
GetTurboBoostEnabled returns whether turbo boost is currently enabled.