sysfs

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	M = (int64(1) << 20)
	G = (int64(1) << 30)
	T = (int64(1) << 40)
)

unit multipliers

Variables

View Source
var (
	// NodeOfDRAMType filters nodes with DRAM memory.
	NodeOfDRAMType = NodeOfType(MemoryTypeDRAM)
	// NodeOfPMEMType filters nodes with PMEM memory.
	NodeOfPMEMType = NodeOfType(MemoryTypePMEM)
	// NodeOfHBMType filters nodes with HBM memory.
	NodeOfHBMType = NodeOfType(MemoryTypeHBM)
	// NodeHasMemory filters nodes with some attached memory.
	NodeHasMemory = func(n Node) bool {
		mi, _ := n.MemoryInfo()
		return mi == nil || mi.MemTotal > 0
	}
	// NodeHasNoMemory filters nodes with no any attached memory.
	NodeHasNoMemory = func(n Node) bool {
		mi, _ := n.MemoryInfo()
		return mi != nil && mi.MemTotal == 0
	}
	// NodeHasLocalCPUs filters nodes which has close CPUs.
	NodeHasLocalCPUs = func(n Node) bool {
		return !n.CPUSet().IsEmpty()
	}
	// NodeHasNoLocalCpus filters nodes which don't have close CPUs.
	NodeHasNoLocalCPUs = func(n Node) bool {
		return n.CPUSet().IsEmpty()
	}
)

Functions

func CPUSetFromIDSet

func CPUSetFromIDSet(s idset.IDSet) cpuset.CPUSet

CPUSetFromIDSet returns a cpuset.CPUSet corresponding to an id set.

func GetMemoryCapacity added in v0.9.0

func GetMemoryCapacity() int64

GetMemoryCapacity parses memory capacity from /proc/meminfo (mimicking cAdvisor).

func IDSetFromCPUSet

func IDSetFromCPUSet(cset cpuset.CPUSet) idset.IDSet

IDSetFromCPUSet returns an id set corresponding to a cpuset.CPUSet.

func ParseFileEntries

func ParseFileEntries(path string, values map[string]interface{}, pickFn PickEntryFn) error

ParseFileEntries parses a sysfs files for the given entries.

func SetSysRoot

func SetSysRoot(root string)

SetSysRoot sets the sys root directory.

Types

type CPU

type CPU interface {
	ID() idset.ID
	PackageID() idset.ID
	DieID() idset.ID
	ClusterID() idset.ID
	NodeID() idset.ID
	CoreID() idset.ID
	ThreadCPUSet() cpuset.CPUSet
	BaseFrequency() uint64
	FrequencyRange() CPUFreq
	EPP() EPP
	Online() bool
	Isolated() bool
	SetFrequencyLimits(min, max uint64) error
	SstClos() int
	CacheCount() int
	GetCaches() []*Cache
	GetCachesByLevel(int) []*Cache
	GetCacheByIndex(int) *Cache
	GetNthLevelCacheCPUSet(n int) cpuset.CPUSet
	GetLastLevelCaches() []*Cache
	GetLastLevelCacheCPUSet() cpuset.CPUSet
	CoreKind() CoreKind
}

CPU is a CPU core.

type CPUFreq

type CPUFreq struct {
	Base uint64 // base frequency
	Min  uint64 // minimum frequency (kHz)
	Max  uint64 // maximum frequency (kHz)
}

CPUFreq is a CPU frequency scaling range

type CPUPackage

type CPUPackage interface {
	ID() idset.ID
	CPUSet() cpuset.CPUSet
	DieIDs() []idset.ID
	NodeIDs() []idset.ID
	DieNodeIDs(idset.ID) []idset.ID
	DieCPUSet(idset.ID) cpuset.CPUSet
	DieClusterIDs(idset.ID) []idset.ID
	DieClusterCPUSet(idset.ID, idset.ID) cpuset.CPUSet
	LogicalDieClusterIDs(idset.ID) []idset.ID
	LogicalDieClusterCPUSet(idset.ID, idset.ID) cpuset.CPUSet
	SstInfo() *sst.SstPackageInfo
}

CPUPackage is a physical package (a collection of CPUs).

type Cache

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

Cache has details about a CPU cache.

func (*Cache) ID added in v0.5.0

func (c *Cache) ID() int

func (*Cache) Level added in v0.5.0

func (c *Cache) Level() int

func (*Cache) SharedCPUSet added in v0.5.0

func (c *Cache) SharedCPUSet() cpuset.CPUSet

func (*Cache) Size added in v0.5.0

func (c *Cache) Size() uint64

func (*Cache) Type added in v0.5.0

func (c *Cache) Type() CacheType

type CacheType

type CacheType int

CacheType specifies a cache type.

const (
	DataCache        CacheType = iota // DataCache is a data only cache
	InstructionCache                  // InstructionCache is an instruction only cache.
	UnifiedCache                      // UnifiedCache is a unified data and instruction cache.

	NumCacheTypes = int(numCacheTypes)
)

func (CacheType) String added in v0.5.0

func (t CacheType) String() string

type CoreKind added in v0.5.0

type CoreKind int

CoreKind represents high-level classification of CPU cores, currently P- and E-cores

const (
	PerformanceCore CoreKind = iota
	EfficientCore
)

func (CoreKind) String added in v0.5.0

func (k CoreKind) String() string

type DiscoveryFlag

type DiscoveryFlag uint

DiscoveryFlag controls what hardware details to discover.

const (
	// DiscoverCPUTopology requests discovering CPU topology details.
	DiscoverCPUTopology DiscoveryFlag = 1 << iota
	// DiscoverMemTopology requests discovering memory topology details.
	DiscoverMemTopology
	// DiscoverCache requests discovering CPU cache details.
	DiscoverCache
	// DiscoverSst requests discovering details of Intel Speed Select Technology
	DiscoverSst
	// DiscoverNone is the zero value for discovery flags.
	DiscoverNone DiscoveryFlag = 0
	// DiscoverAll requests full supported discovery.
	DiscoverAll DiscoveryFlag = 0xffffffff
	// DiscoverDefault is the default set of discovery flags.
	DiscoverDefault DiscoveryFlag = DiscoverAll
)

type EPP

type EPP int

EPP represents the value of a CPU energy performance profile

const (
	EPPPerformance EPP = iota
	EPPBalancePerformance
	EPPBalancePower
	EPPPower
	EPPUnknown
)

func EPPFromString

func EPPFromString(s string) EPP

EPPFromString converts string to EPP value

func (EPP) String

func (e EPP) String() string

String returns EPP value as string

type MemInfo

type MemInfo struct {
	MemTotal uint64
	MemFree  uint64
	MemUsed  uint64
}

MemInfo contains data read from a NUMA node meminfo file.

type MemoryType

type MemoryType int

MemoryType is an enum for the Node memory

const (
	// MemoryTypeDRAM means that the node has regular DRAM-type memory
	MemoryTypeDRAM MemoryType = iota
	// MemoryTypePMEM means that the node has persistent memory
	MemoryTypePMEM
	// MemoryTypeHBM means that the node has high bandwidth memory
	MemoryTypeHBM
)

func (MemoryType) String added in v0.7.0

func (t MemoryType) String() string

type Node

type Node interface {
	ID() idset.ID
	PackageID() idset.ID
	DieID() idset.ID
	CPUSet() cpuset.CPUSet
	Distance() []int
	DistanceFrom(id idset.ID) int
	ClosestNodes() ([]idset.IDSet, []int)
	MemoryInfo() (*MemInfo, error)
	GetMemoryType() MemoryType
	HasNormalMemory() bool
}

Node represents a NUMA node.

type NodeFilter added in v0.9.0

type NodeFilter func(n Node) bool

NodeFilter is a function for filtering nodes. A node passes a filter if the filter returns true for the node.

func NodeFilterAnd added in v0.9.0

func NodeFilterAnd(filters ...NodeFilter) NodeFilter

NodeFilterAnd returns a filter that is the logical AND of the given filters.

func NodeFilterNot added in v0.9.0

func NodeFilterNot(f NodeFilter) NodeFilter

NodeFilterNot returns a filter that is the logical NOT of the given filter.

func NodeFilterOr added in v0.9.0

func NodeFilterOr(filters ...NodeFilter) NodeFilter

NodeFilterOr returns a filter that is the logical OR of the given filters.

func NodeOfType added in v0.9.0

func NodeOfType(t MemoryType) NodeFilter

NodeOfType filters nodes with the given memory type.

type PickEntryFn

type PickEntryFn func(string) (string, string, error)

PickEntryFn picks a given input line apart into an entry of key and value.

type System

type System interface {
	Discover(flags DiscoveryFlag) error
	SetCpusOnline(online bool, cpus idset.IDSet) (idset.IDSet, error)
	SetCPUFrequencyLimits(min, max uint64, cpus idset.IDSet) error
	PackageIDs() []idset.ID
	NodeIDs() []idset.ID
	FilterNodes(ids []idset.ID, filters ...NodeFilter) idset.IDSet
	FilterNode(id idset.ID, filters ...NodeFilter) bool
	ClosestNodes(id idset.ID, filters ...NodeFilter) ([]idset.IDSet, []int)
	CPUIDs() []idset.ID
	PackageCount() int
	SocketCount() int
	CPUCount() int
	NUMANodeCount() int
	MinThreadCount() int
	MaxThreadCount() int
	CPUSet() cpuset.CPUSet
	Package(id idset.ID) CPUPackage
	Node(id idset.ID) Node
	NodeDistance(from, to idset.ID) int
	CPU(id idset.ID) CPU
	PossibleCPUs() cpuset.CPUSet
	PresentCPUs() cpuset.CPUSet
	OnlineCPUs() cpuset.CPUSet
	IsolatedCPUs() cpuset.CPUSet
	OfflineCPUs() cpuset.CPUSet
	CoreKindCPUs(CoreKind) cpuset.CPUSet
	CoreKinds() []CoreKind
	IDSetForCPUs(cpuset.CPUSet, func(CPU) idset.ID) idset.IDSet
	AllThreadsForCPUs(cpuset.CPUSet) cpuset.CPUSet
	SingleThreadForCPUs(cpuset.CPUSet) cpuset.CPUSet
	AllCPUsSharingNthLevelCacheWithCPUs(int, cpuset.CPUSet) cpuset.CPUSet

	Offlined() cpuset.CPUSet
	Isolated() cpuset.CPUSet

	NodeHintToCPUs(string) string
}

System devices

func DiscoverSystem

func DiscoverSystem(args ...DiscoveryFlag) (System, error)

DiscoverSystem performs discovery of the running systems details.

func DiscoverSystemAt

func DiscoverSystemAt(path string, args ...DiscoveryFlag) (System, error)

DiscoverSystemAt performs discovery of the running systems details from sysfs mounted at path.

Jump to

Keyboard shortcuts

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