cpufreq

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cpufreq owns the cpufreq-side CPU-class lifecycle: resolution of symbolic frequencies (min/base/turbo), turbo-priority winner selection per turbo domain, and the per-CPU sysfs writes that follow. The package is consumed by the cpuclass handler and exposes no behavior to user-facing code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

Allocator owns the per-turbo-domain class state for cpufreq.

func New

func New(sys sysfs.System, sink Sink) (*Allocator, error)

New returns an Allocator that publishes class definitions and per-CPU assignments to sink. The constructor does not push any class definitions; the caller follows up with Configure().

func (*Allocator) Configure

func (a *Allocator) Configure(classes []*policyapi.CPUClass, turboDomain string, allowed cpuset.CPUSet) error

Configure replaces the CPU class set, turbo domain mode and the set of allowed CPUs. Resets per-domain turbo winners and re-publishes class definitions to the sink.

func (*Allocator) IsKnownClass

func (a *Allocator) IsKnownClass(name string) bool

IsKnownClass reports whether the given class name is known to the allocator's CPUClasses configuration.

func (*Allocator) UseClass

func (a *Allocator) UseClass(className string, cpus cpuset.CPUSet) error

UseClass marks the given CPUs as active under className, recalculates the turbo winner of every affected turbo domain, then publishes per-CPU assignments to the sink. CPUs outside the configured Allowed set are silently dropped.

type Hooks

type Hooks struct {
	SetMin func(cpu, kHz int) error
	SetMax func(cpu, kHz int) error
	SetGov func(cpu int, governor string) error
}

Hooks lets tests intercept per-CPU writes without touching real sysfs. Production use leaves all hooks nil; the writer then talks to the platform via goresctrl.

type Sink

type Sink interface {
	SetClassDef(name string, def types.ClassDef)
	AssignCPUs(name string, cpus []int)
}

Sink is the back-channel through which the allocator publishes resolved class definitions and per-CPU class assignments to its owner (the cpuclass handler). The handler turns these into per-CPU dirty bits and sysfs writes performed by its Commit().

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is the direct per-CPU cpufreq sysfs writer. Properties are written only when the desired value differs from the last successfully written one. Failures on individual CPUs/properties are logged but do not stop processing of the remaining ones; the first error encountered is returned.

func NewWriter

func NewWriter(hooks Hooks) *Writer

NewWriter returns a Writer wired to the given hooks. Pass a zero-valued Hooks to use real sysfs via goresctrl.

func (*Writer) Enforce

func (w *Writer) Enforce(class string, def types.ClassDef, cpus []int) error

Enforce writes min/max/governor to sysfs for every CPU in cpus, skipping properties whose desired value matches the last written one. A zero min or max means "don't enforce". An empty governor means "don't enforce". The first error encountered is returned.

func (*Writer) Forget

func (w *Writer) Forget(cpus ...int)

Forget drops the lastWritten cache entries for the given CPUs.

func (*Writer) Reset

func (w *Writer) Reset()

Reset clears the per-CPU lastWritten cache so the next Enforce pass re-writes every desired value. Called by the handler when class definitions or the allowed set change.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL