cstates

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSysfs

func NewSysfs() sysfsIface

Types

type AttrID

type AttrID int
const (
	// C-state attributes IDs
	AttrAbove AttrID = iota
	AttrBelow
	AttrDisable
	AttrLatency
	AttrResidency
	AttrTime
	AttrIDCount
)

func (AttrID) String

func (attr AttrID) String() string

type BasicFilter

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

BasicFilter implements a simple filter based on CPU IDs, cstate names and attributes.

func NewBasicFilter

func NewBasicFilter() *BasicFilter

func (*BasicFilter) Match

func (f *BasicFilter) Match(args *FilterInput) bool

Match evaluates the filter against the provided input arguments. Implements a logical AND of all filter criteria.

func (*BasicFilter) SetAttributeValues

func (f *BasicFilter) SetAttributeValues(attr AttrID, values ...string) *BasicFilter

SetAttributeValues sets the values of a given attribute accepted by the filter. This does not imply that the attribute itself is accepted or other attributes would be rejected; use SetAttributes for filtering attribute IDs.

func (*BasicFilter) SetAttributes

func (f *BasicFilter) SetAttributes(attrs ...AttrID) *BasicFilter

SetAttributes sets the attribute IDs accepted by the filter.

func (*BasicFilter) SetCPUs

func (f *BasicFilter) SetCPUs(cpus ...utils.ID) *BasicFilter

SetCPUs sets the CPU IDs accepted by the filter.

func (*BasicFilter) SetCstateNames

func (f *BasicFilter) SetCstateNames(names ...string) *BasicFilter

SetCstateNames sets the cstate names accepted by the filter.

type Cstate

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

Cstate represents single C-state, e.g. "C6" of a single CPU, e.g. cpu2.

Attribute values correspond to files located in sysfs. For example, Cstate{cpu: 2, state: 3}.attrVal[AttrResidency] corresponds to the file /sys/devices/system/cpu/cpu2/cpuidle/state3/residency.

If an attribute value is nil, file has not been read value has been cleared to skip writing it to sysfs.

func NewCstate

func NewCstate(name string, cpu utils.ID, state int) *Cstate

NewCstate creates a new Cstate instance with the given name.

func (*Cstate) AttrCount

func (c *Cstate) AttrCount() int

AttrCount returns the number of attributes that have a value set.

func (*Cstate) Attrs

func (c *Cstate) Attrs() []AttrID

Attrs returns a list of attribute IDs that have a value set.

func (*Cstate) CPU

func (c *Cstate) CPU() utils.ID

CPU returns the CPU ID, e.g. 2.

func (*Cstate) Copy

func (c *Cstate) Copy(filter Filter) *Cstate

Copy returns a new Cstate instance containing a copy attribute values. If filters are given, only matching attributes will be copied and while others will be nil.

func (*Cstate) GetAttr

func (c *Cstate) GetAttr(id AttrID) *string

GetAttr returns the attribute value, or nil if the attribute has not been read from sysfs or it has been cleared.

func (*Cstate) Name

func (c *Cstate) Name() string

Name returns the C-state name, e.g. "C6".

func (*Cstate) SetAttr

func (c *Cstate) SetAttr(id AttrID, value *string)

SetAttr sets the attribute value. If value is nil, the attribute is cleared and will not be written to sysfs.

func (*Cstate) State

func (c *Cstate) State() int

State returns the C-state number, e.g. 3 for state3.

func (*Cstate) String

func (c *Cstate) String() string

String returns a string representation of the Cstate instance.

type CstateAttribute

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

CstateAttribute represents a single C-state attribute, e.g. "residency".

type Cstates

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

Cstates represents a collection of Cstate instances.

func NewCstates

func NewCstates() *Cstates

NewCstates creates a new empty Cstates instance.

func NewCstatesFromSysfs

func NewCstatesFromSysfs(filter Filter) (*Cstates, error)

NewCstatesFromSysfs creates a new Cstates instance by reading the C-state information from sysfs.

If filters are given, only matching C-states and attributes are read.

func (*Cstates) Add

func (cs *Cstates) Add(cstate *Cstate)

Add adds a Cstate instance to the collection.

func (*Cstates) Apply

func (cs *Cstates) Apply() error

Apply writes attributes back to sysfs.

func (*Cstates) Attrs

func (cs *Cstates) Attrs() []AttrID

Attrs returns a list of attribute IDs that have a value set.

func (*Cstates) CPUs

func (cs *Cstates) CPUs() utils.IDSet

CPUs returns a set of CPU IDs present in the collection

func (*Cstates) ClearAttrs

func (cs *Cstates) ClearAttrs(attrs ...AttrID)

ClearAttrs clears the given attribute for all C-states in the collection.

func (*Cstates) Copy

func (cs *Cstates) Copy(filter Filter) *Cstates

Copy returns a new Cstates instance containing copies of the C-states. If filters are given, result includes only matching C-states with matching attributes and values, and C-states without attributes are omitted.

func (*Cstates) Cstate

func (cs *Cstates) Cstate(cpu utils.ID, name string) *Cstate

Cstate returns the Cstate instance for the given CPU ID and C-state name, or nil if not found.

func (*Cstates) GetAttr

func (cs *Cstates) GetAttr(cpu utils.ID, name string, attr AttrID) *string

GetAttr returns the attribute value for the given CPU ID and C-state name,

func (*Cstates) Names

func (cs *Cstates) Names() []string

Names returns a sorted list of unique C-state names in the collection. The order of names corresponds to the order of state numbers, e.g. ["POLL", "C1E", "C6", "C8", "C10"], where "POLL" is state0, "C1E" is state1, etc. Lists C-state names present in the collection, not all possible names.

func (*Cstates) Read

func (cs *Cstates) Read(filter Filter) error

Read populates the Cstates instance from filesystem that implements the sysfsIface interface.

func (*Cstates) SetAttrs

func (cs *Cstates) SetAttrs(attr AttrID, val string)

SetAttrs sets the given attribute to the given value for all C-states in the collection.

func (*Cstates) SetFs

func (c *Cstates) SetFs(fs sysfsIface)

SetFs sets the filesystem interface to be used by the Cstates instance.

func (*Cstates) String

func (cs *Cstates) String() string

String returns a string representation of the Cstates instance.

type Filter

type Filter interface {
	// Match returns true if the given arguments match the filter criteria.
	Match(*FilterInput) bool
}

Filter defines the interface for filtering cstate data.

type FilterInput

type FilterInput struct {
	CPU            *utils.ID
	CstateName     *string
	Attribute      *AttrID
	AttributeValue *string
}

FilterInput holds the input values for evaluating the filter. All fields are optional. Nil values indicate "not defined" and should be ignored in filter evaluation.

func NewFilterInput

func NewFilterInput(opts ...FilterInputOpt) *FilterInput

NewFilterInput creates a new FilterInput instance.

func (*FilterInput) SetAttribute

func (f *FilterInput) SetAttribute(attr AttrID) *FilterInput

SetAttribute sets the attribute ID in the FilterInput. It clears any existing AttributeValue causing the filter to match any value for the attribute.

func (*FilterInput) SetAttributeValue

func (f *FilterInput) SetAttributeValue(attr AttrID, value string) *FilterInput

SetAttributeValue sets the attribute ID and value in the FilterInput.

func (*FilterInput) SetCPU

func (f *FilterInput) SetCPU(cpu utils.ID) *FilterInput

SetCPU sets the CPU ID in the FilterInput.

func (*FilterInput) SetCstateName

func (f *FilterInput) SetCstateName(name string) *FilterInput

SetCstateName sets the cstate name in the FilterInput.

type FilterInputOpt

type FilterInputOpt func(*FilterInput)

Jump to

Keyboard shortcuts

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