cpuset

package
v0.0.0-...-c9cfaf6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package cpuset is a library for manipulation of Linux cpusets.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUSet

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

CPUSet represents a cpuset in the sysfs filesystem.

func Create

func Create(name string) (*CPUSet, error)

Create the named cpuset under the standard sysfs hierarchy.

func CreatePath

func CreatePath(path string) (*CPUSet, error)

CreatePath creates a cpuset at a custom path.

func NewCPUSet

func NewCPUSet(name string) *CPUSet

NewCPUSet returns a reference to the named cpuset under the standard sysfs hierarchy.

func NewCPUSetPath

func NewCPUSetPath(path string) *CPUSet

NewCPUSetPath returns a reference to a cpuset directory at a custom path.

func Root

func Root() *CPUSet

Root returns the root cpuset.

func (*CPUSet) AddTask

func (c *CPUSet) AddTask(task int) error

AddTask adds a single task to the cpuset.

func (*CPUSet) AddTasks

func (c *CPUSet) AddTasks(tasks []int) error

AddTasks writes to the "tasks" file of the cpuset.

See Tasks() for the meaning of this field.

func (*CPUSet) CPUExclusive

func (c *CPUSet) CPUExclusive() (bool, error)

CPUExclusive reports whether the cpuset has exclusive use of its CPUs (no sibling or cousin cpuset may overlap CPUs). By default, this is off. Newly created cpusets also initially default this to off.

Two cpusets are sibling cpusets if they share the same parent cpuset in the hierarchy. Two cpusets are cousin cpusets if neither is the ancestor of the other. Regardless of the cpu_exclusive setting, if one cpuset is the ancestor of another, and if both of these cpusets have nonempty cpus, then their cpus must overlap, because the cpus of any cpuset are always a subset of the cpus of its parent cpuset.

Corresponds to the "cpuset.cpu_exclusive" file in the cpuset directory.

func (*CPUSet) CPUs

func (c *CPUSet) CPUs() (Set, error)

CPUs returns the set of physical numbers of the CPUs on which processes in the cpuset are allowed to execute.

Corresponds to the "cpuset.cpus" file in the cpuset directory.

func (*CPUSet) DisableCPUExclusive

func (c *CPUSet) DisableCPUExclusive() error

DisableCPUExclusive sets the "cpuset.cpu_exclusive" file to false.

See CPUExclusive() for the meaning of this field.

func (*CPUSet) DisableMemExclusive

func (c *CPUSet) DisableMemExclusive() error

DisableMemExclusive sets the "cpuset.mem_exclusive" file to false.

See MemExclusive() for the meaning of this field.

func (*CPUSet) DisableMemHardwall

func (c *CPUSet) DisableMemHardwall() error

DisableMemHardwall sets the "cpuset.mem_hardwall" file to false.

See MemHardwall() for the meaning of this field.

func (*CPUSet) DisableMemoryMigrate

func (c *CPUSet) DisableMemoryMigrate() error

DisableMemoryMigrate sets the "cpuset.memory_migrate" file to false.

See MemoryMigrate() for the meaning of this field.

func (*CPUSet) DisableMemoryPressureEnabled

func (c *CPUSet) DisableMemoryPressureEnabled() error

DisableMemoryPressureEnabled sets the "cpuset.memory_pressure_enabled" file to false.

See MemoryPressureEnabled() for the meaning of this field.

func (*CPUSet) DisableMemorySpreadPage

func (c *CPUSet) DisableMemorySpreadPage() error

DisableMemorySpreadPage sets the "cpuset.memory_spread_page" file to false.

See MemorySpreadPage() for the meaning of this field.

func (*CPUSet) DisableMemorySpreadSlab

func (c *CPUSet) DisableMemorySpreadSlab() error

DisableMemorySpreadSlab sets the "cpuset.memory_spread_slab" file to false.

See MemorySpreadSlab() for the meaning of this field.

func (*CPUSet) DisableNotifyOnRelease

func (c *CPUSet) DisableNotifyOnRelease() error

DisableNotifyOnRelease sets the "notify_on_release" file to false.

See NotifyOnRelease() for the meaning of this field.

func (*CPUSet) DisableSchedLoadBalance

func (c *CPUSet) DisableSchedLoadBalance() error

DisableSchedLoadBalance sets the "cpuset.sched_load_balance" file to false.

See SchedLoadBalance() for the meaning of this field.

func (*CPUSet) EnableCPUExclusive

func (c *CPUSet) EnableCPUExclusive() error

EnableCPUExclusive sets the "cpuset.cpu_exclusive" file to true.

See CPUExclusive() for the meaning of this field.

func (*CPUSet) EnableMemExclusive

func (c *CPUSet) EnableMemExclusive() error

EnableMemExclusive sets the "cpuset.mem_exclusive" file to true.

See MemExclusive() for the meaning of this field.

func (*CPUSet) EnableMemHardwall

func (c *CPUSet) EnableMemHardwall() error

EnableMemHardwall sets the "cpuset.mem_hardwall" file to true.

See MemHardwall() for the meaning of this field.

func (*CPUSet) EnableMemoryMigrate

func (c *CPUSet) EnableMemoryMigrate() error

EnableMemoryMigrate sets the "cpuset.memory_migrate" file to true.

See MemoryMigrate() for the meaning of this field.

func (*CPUSet) EnableMemoryPressureEnabled

func (c *CPUSet) EnableMemoryPressureEnabled() error

EnableMemoryPressureEnabled sets the "cpuset.memory_pressure_enabled" file to true.

See MemoryPressureEnabled() for the meaning of this field.

func (*CPUSet) EnableMemorySpreadPage

func (c *CPUSet) EnableMemorySpreadPage() error

EnableMemorySpreadPage sets the "cpuset.memory_spread_page" file to true.

See MemorySpreadPage() for the meaning of this field.

func (*CPUSet) EnableMemorySpreadSlab

func (c *CPUSet) EnableMemorySpreadSlab() error

EnableMemorySpreadSlab sets the "cpuset.memory_spread_slab" file to true.

See MemorySpreadSlab() for the meaning of this field.

func (*CPUSet) EnableNotifyOnRelease

func (c *CPUSet) EnableNotifyOnRelease() error

EnableNotifyOnRelease sets the "notify_on_release" file to true.

See NotifyOnRelease() for the meaning of this field.

func (*CPUSet) EnableSchedLoadBalance

func (c *CPUSet) EnableSchedLoadBalance() error

EnableSchedLoadBalance sets the "cpuset.sched_load_balance" file to true.

See SchedLoadBalance() for the meaning of this field.

func (*CPUSet) MemExclusive

func (c *CPUSet) MemExclusive() (bool, error)

MemExclusive reports whether the cpuset has exclusive use of its memory nodes (no sibling or cousin may overlap). Also if set, the cpuset is a Hardwall cpuset. By default, this is off. Newly created cpusets also initially default this to off.

Regardless of the mem_exclusive setting, if one cpuset is the ancestor of another, then their memory nodes must overlap, because the memory nodes of any cpuset are always a subset of the memory nodes of that cpuset's parent cpuset.

Corresponds to the "cpuset.mem_exclusive" file in the cpuset directory.

func (*CPUSet) MemHardwall

func (c *CPUSet) MemHardwall() (bool, error)

MemHardwall reports whether the cpuset is a Hardwall cpuset (see below). Unlike mem_exclusive, there is no constraint on whether cpusets marked mem_hardwall may have overlapping memory nodes with sibling or cousin cpusets. By default, this is off. Newly created cpusets also initially default this to off.

Corresponds to the "cpuset.mem_hardwall" file in the cpuset directory.

func (*CPUSet) MemoryMigrate

func (c *CPUSet) MemoryMigrate() (bool, error)

MemoryMigrate reports whether memory migration is enabled.

Corresponds to the "cpuset.memory_migrate" file in the cpuset directory.

func (*CPUSet) MemoryPressure

func (c *CPUSet) MemoryPressure() (int, error)

MemoryPressure reports a measure of how much memory pressure the processes in this cpuset are causing. If MemoryPressureEnabled() is false this will always be 0.

Corresponds to the "cpuset.memory_pressure" file in the cpuset directory.

func (*CPUSet) MemoryPressureEnabled

func (c *CPUSet) MemoryPressureEnabled() (bool, error)

MemoryPressureEnabled reports whether memory pressure calculations are enabled for all cpusets in the system. This method only works for the root cpuset. By default, this is off.

Corresponds to the "cpuset.memory_pressure_enabled" file in the cpuset directory.

func (*CPUSet) MemorySpreadPage

func (c *CPUSet) MemorySpreadPage() (bool, error)

MemorySpreadPage reports whether pages in the kernel page cache (filesystem buffers) are uniformly spread across the cpuset. By default, this is off (0) in the top cpuset, and inherited from the parent cpuset in newly created cpusets.

Corresponds to the "cpuset.memory_spread_page" file in the cpuset directory.

func (*CPUSet) MemorySpreadSlab

func (c *CPUSet) MemorySpreadSlab() (bool, error)

MemorySpreadSlab reports whether the kernel slab caches for file I/O (directory and inode structures) are uniformly spread across the cpuset. By default, this is off (0) in the top cpuset, and inherited from the parent cpuset in newly created cpusets.

Corresponds to the "cpuset.memory_spread_slab" file in the cpuset directory.

func (*CPUSet) Mems

func (c *CPUSet) Mems() (Set, error)

Mems returns the list of memory nodes on which processes in this cpuset are allowed to allocate memory.

Corresponds to the "cpuset.mems" file in the cpuset directory.

func (*CPUSet) NotifyOnRelease

func (c *CPUSet) NotifyOnRelease() (bool, error)

NotifyOnRelease reports whether the notify_on_release flag is set for this cpuset. If true, that cpuset will receive special handling after it is released, that is, after all processes cease using it (i.e., terminate or are moved to a different cpuset) and all child cpuset directories have been removed.

Corresponds to the "notify_on_release" file in the cpuset directory.

func (*CPUSet) Path

func (c *CPUSet) Path() string

Path returns the path to the cpuset directory.

func (*CPUSet) Remove

func (c *CPUSet) Remove() error

Remove the cpuset. Note the cpuset must have no children or attached processes.

func (*CPUSet) SchedLoadBalance

func (c *CPUSet) SchedLoadBalance() (bool, error)

SchedLoadBalance reports wether the kernel will automatically load balance processes in that cpuset over the allowed CPUs in that cpuset. If false the kernel will avoid load balancing processes in this cpuset, unless some other cpuset with overlapping CPUs has its sched_load_balance flag set.

Corresponds to the "cpuset.sched_load_balance" file in the cpuset directory.

func (*CPUSet) SchedRelaxDomainLevel

func (c *CPUSet) SchedRelaxDomainLevel() (int, error)

SchedRelaxDomainLevel controls the width of the range of CPUs over which the kernel scheduler performs immediate rebalancing of runnable tasks across CPUs. If sched_load_balance is disabled, then the setting of sched_relax_domain_level does not matter, as no such load balancing is done. If sched_load_balance is enabled, then the higher the value of the sched_relax_domain_level, the wider the range of CPUs over which immediate load balancing is attempted.

Corresponds to the "cpuset.sched_relax_domain_level" file in the cpuset directory.

func (*CPUSet) SetCPUExclusive

func (c *CPUSet) SetCPUExclusive(enabled bool) error

SetCPUExclusive writes to the "cpuset.cpu_exclusive" file of the cpuset.

See CPUExclusive() for the meaning of this field.

func (*CPUSet) SetCPUs

func (c *CPUSet) SetCPUs(s Set) error

SetCPUs writes to the "cpuset.cpus" file of the cpuset.

See CPUs() for the meaning of this field.

func (*CPUSet) SetMemExclusive

func (c *CPUSet) SetMemExclusive(enabled bool) error

SetMemExclusive writes to the "cpuset.mem_exclusive" file of the cpuset.

See MemExclusive() for the meaning of this field.

func (*CPUSet) SetMemHardwall

func (c *CPUSet) SetMemHardwall(enabled bool) error

SetMemHardwall writes to the "cpuset.mem_hardwall" file of the cpuset.

See MemHardwall() for the meaning of this field.

func (*CPUSet) SetMemoryMigrate

func (c *CPUSet) SetMemoryMigrate(enabled bool) error

SetMemoryMigrate writes to the "cpuset.memory_migrate" file of the cpuset.

See MemoryMigrate() for the meaning of this field.

func (*CPUSet) SetMemoryPressureEnabled

func (c *CPUSet) SetMemoryPressureEnabled(enabled bool) error

SetMemoryPressureEnabled writes to the "cpuset.memory_pressure_enabled" file of the cpuset.

See MemoryPressureEnabled() for the meaning of this field.

func (*CPUSet) SetMemorySpreadPage

func (c *CPUSet) SetMemorySpreadPage(enabled bool) error

SetMemorySpreadPage writes to the "cpuset.memory_spread_page" file of the cpuset.

See MemorySpreadPage() for the meaning of this field.

func (*CPUSet) SetMemorySpreadSlab

func (c *CPUSet) SetMemorySpreadSlab(enabled bool) error

SetMemorySpreadSlab writes to the "cpuset.memory_spread_slab" file of the cpuset.

See MemorySpreadSlab() for the meaning of this field.

func (*CPUSet) SetMems

func (c *CPUSet) SetMems(s Set) error

SetMems writes to the "cpuset.mems" file of the cpuset.

See Mems() for the meaning of this field.

func (*CPUSet) SetNotifyOnRelease

func (c *CPUSet) SetNotifyOnRelease(enabled bool) error

SetNotifyOnRelease writes to the "notify_on_release" file of the cpuset.

See NotifyOnRelease() for the meaning of this field.

func (*CPUSet) SetSchedLoadBalance

func (c *CPUSet) SetSchedLoadBalance(enabled bool) error

SetSchedLoadBalance writes to the "cpuset.sched_load_balance" file of the cpuset.

See SchedLoadBalance() for the meaning of this field.

func (*CPUSet) SetSchedRelaxDomainLevel

func (c *CPUSet) SetSchedRelaxDomainLevel(level int) error

SetSchedRelaxDomainLevel writes to the "cpuset.sched_relax_domain_level" file of the cpuset.

See SchedRelaxDomainLevel() for the meaning of this field.

func (*CPUSet) Tasks

func (c *CPUSet) Tasks() ([]int, error)

Tasks returns the list of process IDs (PIDs) of the processes in the cpuset.

Corresponds to the "tasks" file in the cpuset directory.

type MoveResult

type MoveResult struct {
	// Tasks successfully moved.
	Moved []int
	// Tasks which could not be found.
	Nonexistent []int
	// Invalid tasks were unmovable for some reason. For example, "bound" tasks
	// that are already pinned to CPUs cannot be moved, nor can the "kthreadd"
	// task.
	Invalid []int
}

MoveResult records the outcome of a batch task migration from one cpuset to another.

func MoveTasks

func MoveTasks(src, dst *CPUSet) (*MoveResult, error)

MoveTasks attempts to move all tasks from src to dst cpusets, returning the result in a MoveResult struct. Certain error cases are common, for example tasks bound to CPUs cannot be moved, and it's also possible for tasks to terminate while the move is taking place. These cases will not cause the entire operation to error, rather they will be recorded in the MoveResult return value for inspection by the caller. Other error cases will be bubbled up as errors from MoveTasks.

type Set

type Set map[uint]bool

Set of unsigned integers.

func NewSet

func NewSet(members ...uint) Set

NewSet builds a new set and inserts the given members into it.

func ParseList

func ParseList(s string) (Set, error)

ParseList parses a set represented in "List Format", specifically a comma-separated list of ranges.

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/goperf/pkg/cpuset"
)

func main() {
	s, _ := cpuset.ParseList("0-2,7,12-14")
	for n := range s {
		fmt.Println(n)
	}
}
Output:

0
1
2
7
12
13
14

func ParseMask

func ParseMask(s string) (Set, error)

ParseMask parses a set represented in linux "Mask Format", specifically a comma-separated list of 32-bit hex words in big-endian order.

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/goperf/pkg/cpuset"
)

func main() {
	s, _ := cpuset.ParseMask("40000000,00000001,00000000")
	for n := range s {
		fmt.Println(n)
	}
}
Output:

32
94

func (Set) Clone

func (s Set) Clone() Set

Clone returns a copy of s.

func (Set) Contains

func (s Set) Contains(t Set) bool

Contains reports whether s contains t.

func (Set) Difference

func (s Set) Difference(t Set) Set

Difference returns a new set with elements in s but not in t.

func (Set) Equals

func (s Set) Equals(t Set) bool

Equals returns whether s and t are equal.

func (Set) FormatList

func (s Set) FormatList() string

FormatList represents s in "List Format".

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/goperf/pkg/cpuset"
)

func main() {
	s := cpuset.NewSet(13, 2, 0, 7, 1, 14, 12)
	fmt.Println(s.FormatList())
}
Output:

0-2,7,12-14

func (Set) FormatMask

func (s Set) FormatMask() string

FormatMask represents s in linux "Mask Format".

Example
package main

import (
	"fmt"

	"github.com/mmcloughlin/goperf/pkg/cpuset"
)

func main() {
	s := cpuset.NewSet(32, 64, 0, 1, 4, 2, 8, 16)
	fmt.Println(s.FormatMask())
}
Output:

00000001,00000001,00010117

func (Set) Members

func (s Set) Members() []uint

Members returns the members of s as a slice. No guarantees are made about order.

func (Set) SortedMembers

func (s Set) SortedMembers() []uint

SortedMembers returns the members of s as a slice in sorted order.

func (Set) String

func (s Set) String() string

Jump to

Keyboard shortcuts

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