sysfs

package
v0.2.1-0...-d3ae3b1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

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

unit multipliers

View Source
const (
	// ProviderKubelet is a constant to distinguish that topology hint comes
	// from parameters passed to CRI create/update requests from Kubelet
	ProviderKubelet = "kubelet"
)
View Source
const (
	// SysfsRootPath is the mount path of sysfs.
	SysfsRootPath = "/sys"
)

Variables

This section is empty.

Functions

func FindSysFsDevice

func FindSysFsDevice(dev string) (string, error)

FindSysFsDevice for given argument returns physical device where it is linked to. For device nodes it will return path for device itself. For regular files or directories this function returns physical device where this inode resides (storage device). If result device is a virtual one (e.g. tmpfs), error will be returned. For non-existing path, no error returned and path is empty.

func ParseFileEntries

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

ParseFileEntries parses a sysfs files for the given entries.

Types

type CPU

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

CPU is a CPU core.

func (*CPU) CoreID

func (c *CPU) CoreID() ID

CoreID returns the core id of this CPU (lowest CPU id of all thread siblings).

func (*CPU) FrequencyRange

func (c *CPU) FrequencyRange() CPUFreq

FrequencyRange returns the frequency range for this CPU.

func (*CPU) ID

func (c *CPU) ID() ID

ID returns the id of this CPU.

func (*CPU) Isolated

func (c *CPU) Isolated() bool

Isolated returns if this CPU is isolated.

func (*CPU) NodeID

func (c *CPU) NodeID() ID

NodeID returns the node id of this CPU.

func (*CPU) Online

func (c *CPU) Online() bool

Online returns if this CPU is online.

func (*CPU) PackageID

func (c *CPU) PackageID() ID

PackageID returns package id of this CPU.

func (*CPU) SetFrequencyLimits

func (c *CPU) SetFrequencyLimits(min, max uint64) error

SetFrequencyLimits sets the frequency scaling limits for this CPU.

func (*CPU) ThreadCPUSet

func (c *CPU) ThreadCPUSet() cpuset.CPUSet

ThreadCPUSet returns the CPUSet for all threads in this core.

type CPUFreq

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

CPUFreq is a CPU frequency scaling range

type Cache

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

Cache has details about cache.

type CacheType

type CacheType string

CacheType specifies a cache type.

const (
	// DataCache marks data cache.
	DataCache CacheType = "Data"
	// InstructionCache marks instruction cache.
	InstructionCache CacheType = "Instruction"
	// UnifiedCache marks a unified data/instruction cache.
	UnifiedCache CacheType = "Unified"
)

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
	// 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 = (DiscoverCPUTopology | DiscoverMemTopology)
)

type ID

type ID int

ID is nn integer id, used to identify packages, CPUs, nodes, etc.

const (
	// Unknown represents an unknown id.
	Unknown ID = -1
)

type IDSet

type IDSet map[ID]struct{}

IDSet is an unordered set of integer ids.

func FromCPUSet

func FromCPUSet(cset cpuset.CPUSet) IDSet

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

func NewIDSet

func NewIDSet(ids ...ID) IDSet

NewIDSet creates a new unordered set of (integer) ids.

func NewIDSetFromIntSlice

func NewIDSetFromIntSlice(ids ...int) IDSet

NewIDSetFromIntSlice creates a new unordered set from an integer slice.

func (IDSet) Add

func (s IDSet) Add(ids ...ID)

Add adds the given ids into the set.

func (IDSet) CPUSet

func (s IDSet) CPUSet() cpuset.CPUSet

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

func (IDSet) Clone

func (s IDSet) Clone() IDSet

Clone returns a copy of this IdSet.

func (IDSet) Del

func (s IDSet) Del(ids ...ID)

Del deletes the given ids from the set.

func (IDSet) Has

func (s IDSet) Has(ids ...ID) bool

Has tests if all the ids are present in the set.

func (IDSet) Members

func (s IDSet) Members() []ID

Members returns all ids in the set as a randomly ordered slice.

func (IDSet) Size

func (s IDSet) Size() int

Size returns the number of ids in the set.

func (IDSet) SortedMembers

func (s IDSet) SortedMembers() []ID

SortedMembers returns all ids in the set as a sorted slice.

func (IDSet) String

func (s IDSet) String() string

String returns the set as a string.

func (IDSet) StringWithSeparator

func (s IDSet) StringWithSeparator(args ...string) string

StringWithSeparator returns the set as a string, separated with the given separator.

type MemInfo

type MemInfo struct {
	MemTotal uint64
	MemFree  uint64
	MemUsed  uint64
}

MemInfo contains data read from a NUMA node meminfo file.

type Node

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

Node is a NUMA node.

func (*Node) CPUSet

func (n *Node) CPUSet() cpuset.CPUSet

CPUSet returns the CPUSet for all cores/threads in this node.

func (*Node) Distance

func (n *Node) Distance() []int

Distance returns the distance vector for this node.

func (*Node) DistanceFrom

func (n *Node) DistanceFrom(id ID) int

DistanceFrom returns the distance of this and a given node.

func (*Node) ID

func (n *Node) ID() ID

ID returns id of this node.

func (*Node) MemoryInfo

func (n *Node) MemoryInfo() (*MemInfo, error)

MemoryInfo memory info for the node (partial content from the meminfo sysfs entry).

func (*Node) PackageID

func (n *Node) PackageID() ID

PackageID returns the id of this node.

type Package

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

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

func (*Package) CPUSet

func (p *Package) CPUSet() cpuset.CPUSet

CPUSet returns the CPUSet for all cores/threads in this package.

func (*Package) ID

func (p *Package) ID() ID

ID returns the id of this package.

func (*Package) NodeIDs

func (p *Package) NodeIDs() []ID

NodeIDs returns the NUMA node ids for this package.

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 struct {
	logger.Logger // our logger instance
	// contains filtered or unexported fields
}

System devices

func DiscoverSystem

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

DiscoverSystem performs discovery of the running systems details.

func (*System) CPU

func (sys *System) CPU(id ID) *CPU

CPU gets the CPU with a given CPU id.

func (*System) CPUCount

func (sys *System) CPUCount() int

CPUCount resturns the number of discovered CPUs/cores.

func (*System) CPUIDs

func (sys *System) CPUIDs() []ID

CPUIDs gets the ids of all CPUs present in the system.

func (*System) CPUSet

func (sys *System) CPUSet() cpuset.CPUSet

CPUSet gets the ids of all CPUs present in the system as a CPUSet.

func (*System) Discover

func (sys *System) Discover(flags DiscoveryFlag) error

Discover performs system/hardware discovery.

func (*System) Isolated

func (sys *System) Isolated() cpuset.CPUSet

Isolated gets the set of isolated CPUs."

func (*System) NUMANodeCount

func (sys *System) NUMANodeCount() int

NUMANodeCount returns the number of discovered NUMA nodes.

func (*System) Node

func (sys *System) Node(id ID) *Node

Node gets the node with a given node id.

func (*System) NodeIDs

func (sys *System) NodeIDs() []ID

NodeIDs gets the ids of all NUMA nodes present in the system.

func (*System) Offlined

func (sys *System) Offlined() cpuset.CPUSet

Offlined gets the set of offlined CPUs.

func (*System) Package

func (sys *System) Package(id ID) *Package

Package gets the package with a given package id.

func (*System) PackageCount

func (sys *System) PackageCount() int

PackageCount returns the number of discovered CPU packages (sockets).

func (*System) PackageIDs

func (sys *System) PackageIDs() []ID

PackageIDs gets the ids of all packages present in the system.

func (*System) SetCPUFrequencyLimits

func (sys *System) SetCPUFrequencyLimits(min, max uint64, cpus IDSet) error

SetCPUFrequencyLimits sets the CPU frequency scaling limits. Nil set implies all CPUs.

func (*System) SetCpusOnline

func (sys *System) SetCpusOnline(online bool, cpus IDSet) (IDSet, error)

SetCpusOnline puts a set of CPUs online. Return the toggled set. Nil set implies all CPUs.

func (*System) SocketCount

func (sys *System) SocketCount() int

SocketCount returns the number of discovered CPU packages (sockets).

func (*System) ThreadCount

func (sys *System) ThreadCount() int

ThreadCount returns the number of threads per core discovered.

type TopologyHint

type TopologyHint struct {
	Provider string
	CPUs     string
	NUMAs    string
	Sockets  string
}

TopologyHint represents various hints that can be detected from sysfs for the device

func (*TopologyHint) String

func (h *TopologyHint) String() string

String returns the hints as a string.

type TopologyHints

type TopologyHints map[string]TopologyHint

TopologyHints represents set of hints collected from multiple providers

func MergeTopologyHints

func MergeTopologyHints(org, hints TopologyHints) (res TopologyHints)

MergeTopologyHints combines org and hints.

func NewTopologyHints

func NewTopologyHints(devPath string) (hints TopologyHints, err error)

NewTopologyHints return array of hints for the device and its slaves (e.g. RAID).

Jump to

Keyboard shortcuts

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