cpumanager

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 27 Imported by: 51

Documentation

Index

Constants

View Source
const (
	FullPCPUsOnlyOption             string = "full-pcpus-only"
	DistributeCPUsAcrossNUMAOption  string = "distribute-cpus-across-numa"
	AlignBySocketOption             string = "align-by-socket"
	DistributeCPUsAcrossCoresOption string = "distribute-cpus-across-cores"
	StrictCPUReservationOption      string = "strict-cpu-reservation"
	PreferAlignByUnCoreCacheOption  string = "prefer-align-cpus-by-uncorecache"
)

Names of the options, as part of the user interface.

View Source
const (

	// PolicyStatic is the name of the static policy.
	// Should options be given, these will be ignored and backward (up to 1.21 included)
	// compatible behaviour will be enforced
	PolicyStatic policyName = "static"
	// ErrorSMTAlignment represents the type of an SMTAlignmentError
	ErrorSMTAlignment = "SMTAlignmentError"
)
View Source
const PolicyNone policyName = "none"

PolicyNone name of none policy

Variables

This section is empty.

Functions

func CheckPolicyOptionAvailable added in v1.23.0

func CheckPolicyOptionAvailable(option string) error

CheckPolicyOptionAvailable verifies if the given option can be used depending on the Feature Gate Settings. returns nil on success, or an error describing the failure on error.

func ValidateStaticPolicyOptions added in v1.25.0

func ValidateStaticPolicyOptions(opts StaticPolicyOptions, topology *topology.CPUTopology, topologyManager topologymanager.Store) error

ValidateStaticPolicyOptions ensures that the requested policy options are compatible with the machine on which the CPUManager is running.

Types

type ActivePodsFunc

type ActivePodsFunc func() []*v1.Pod

ActivePodsFunc is a function that returns a list of pods to reconcile.

type CPUSortingStrategy added in v1.31.0

type CPUSortingStrategy string

CPUSortingStrategy describes the CPU sorting solution within the socket scope. Using topoDualSocketHT (12 CPUs, 2 sockets, 6 cores) as an example:

CPUDetails: map[int]topology.CPUInfo{
	0:  {CoreID: 0, SocketID: 0, NUMANodeID: 0},
	1:  {CoreID: 1, SocketID: 1, NUMANodeID: 1},
	2:  {CoreID: 2, SocketID: 0, NUMANodeID: 0},
	3:  {CoreID: 3, SocketID: 1, NUMANodeID: 1},
	4:  {CoreID: 4, SocketID: 0, NUMANodeID: 0},
	5:  {CoreID: 5, SocketID: 1, NUMANodeID: 1},
	6:  {CoreID: 0, SocketID: 0, NUMANodeID: 0},
	7:  {CoreID: 1, SocketID: 1, NUMANodeID: 1},
	8:  {CoreID: 2, SocketID: 0, NUMANodeID: 0},
	9:  {CoreID: 3, SocketID: 1, NUMANodeID: 1},
	10: {CoreID: 4, SocketID: 0, NUMANodeID: 0},
	11: {CoreID: 5, SocketID: 1, NUMANodeID: 1},
},

- CPUSortingOptionPacked sorts CPUs in a packed manner, where CPUs are grouped by core before moving to the next core, resulting in packed cores, like: 0, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9, 11 - CPUSortingOptionSpread sorts CPUs in a spread manner, where CPUs are spread across cores before moving to the next CPU, resulting in spread-out cores, like: 0, 6, 2, 8, 4, 10, 1, 7, 3, 9, 5, 11

By default, CPUSortingOptionPacked will be used, and CPUSortingOptionSpread will only be activated when the user specifies the `DistributeCPUsAcrossCoresOption` static policy option.

const (
	CPUSortingStrategyPacked CPUSortingStrategy = "packed"
	CPUSortingStrategySpread CPUSortingStrategy = "spread"
)

type LoopControl added in v1.23.0

type LoopControl int

LoopControl controls the behavior of the cpu accumulator loop logic

const (
	Continue LoopControl = iota
	Break
)

Possible loop control outcomes

type Manager

type Manager interface {
	// Start is called during Kubelet initialization.
	Start(activePods ActivePodsFunc, sourcesReady config.SourcesReady, podStatusProvider status.PodStatusProvider, containerRuntime runtimeService, initialContainers containermap.ContainerMap) error

	// Called to trigger the allocation of CPUs to a container. This must be
	// called at some point prior to the AddContainer() call for a container,
	// e.g. at pod admission time.
	Allocate(pod *v1.Pod, container *v1.Container) error

	// AddContainer adds the mapping between container ID to pod UID and the container name
	// The mapping used to remove the CPU allocation during the container removal
	AddContainer(p *v1.Pod, c *v1.Container, containerID string)

	// RemoveContainer is called after Kubelet decides to kill or delete a
	// container. After this call, the CPU manager stops trying to reconcile
	// that container and any CPUs dedicated to the container are freed.
	RemoveContainer(containerID string) error

	// State returns a read-only interface to the internal CPU manager state.
	State() state.Reader

	// GetTopologyHints implements the topologymanager.HintProvider Interface
	// and is consulted to achieve NUMA aware resource alignment among this
	// and other resource controllers.
	GetTopologyHints(*v1.Pod, *v1.Container) map[string][]topologymanager.TopologyHint

	// GetExclusiveCPUs implements the podresources.CPUsProvider interface to provide
	// exclusively allocated cpus for the container
	GetExclusiveCPUs(podUID, containerName string) cpuset.CPUSet

	// GetPodTopologyHints implements the topologymanager.HintProvider Interface
	// and is consulted to achieve NUMA aware resource alignment per Pod
	// among this and other resource controllers.
	GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint

	// GetAllocatableCPUs returns the total set of CPUs available for allocation.
	GetAllocatableCPUs() cpuset.CPUSet

	// GetCPUAffinity returns cpuset which includes cpus from shared pools
	// as well as exclusively allocated cpus
	GetCPUAffinity(podUID, containerName string) cpuset.CPUSet

	// GetAllCPUs returns all the CPUs known by cpumanager, as reported by the
	// hardware discovery. Maps to the CPU capacity.
	GetAllCPUs() cpuset.CPUSet
}

Manager interface provides methods for Kubelet to manage pod cpus.

func NewFakeManager

func NewFakeManager() Manager

NewFakeManager creates empty/fake cpu manager

func NewManager

func NewManager(cpuPolicyName string, cpuPolicyOptions map[string]string, reconcilePeriod time.Duration, machineInfo *cadvisorapi.MachineInfo, specificCPUs cpuset.CPUSet, nodeAllocatableReservation v1.ResourceList, stateFileDirectory string, affinity topologymanager.Store) (Manager, error)

NewManager creates new cpu manager based on provided policy

type Policy

type Policy interface {
	Name() string
	Start(s state.State) error
	// Allocate call is idempotent
	Allocate(s state.State, pod *v1.Pod, container *v1.Container) error
	// RemoveContainer call is idempotent
	RemoveContainer(s state.State, podUID string, containerName string) error
	// GetTopologyHints implements the topologymanager.HintProvider Interface
	// and is consulted to achieve NUMA aware resource alignment among this
	// and other resource controllers.
	GetTopologyHints(s state.State, pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint
	// GetPodTopologyHints implements the topologymanager.HintProvider Interface
	// and is consulted to achieve NUMA aware resource alignment per Pod
	// among this and other resource controllers.
	GetPodTopologyHints(s state.State, pod *v1.Pod) map[string][]topologymanager.TopologyHint
	// GetAllocatableCPUs returns the total set of CPUs available for allocation.
	GetAllocatableCPUs(m state.State) cpuset.CPUSet
}

Policy implements logic for pod container to CPU assignment.

func NewNonePolicy

func NewNonePolicy(cpuPolicyOptions map[string]string) (Policy, error)

NewNonePolicy returns a cpuset manager policy that does nothing

func NewStaticPolicy

func NewStaticPolicy(topology *topology.CPUTopology, numReservedCPUs int, reservedCPUs cpuset.CPUSet, affinity topologymanager.Store, cpuPolicyOptions map[string]string) (Policy, error)

NewStaticPolicy returns a CPU manager policy that does not change CPU assignments for exclusively pinned guaranteed containers after the main container process starts.

type SMTAlignmentError added in v1.22.0

type SMTAlignmentError struct {
	RequestedCPUs         int
	CpusPerCore           int
	AvailablePhysicalCPUs int
	CausedByPhysicalCPUs  bool
}

SMTAlignmentError represents an error due to SMT alignment

func (SMTAlignmentError) Error added in v1.22.0

func (e SMTAlignmentError) Error() string

func (SMTAlignmentError) Type added in v1.22.0

func (e SMTAlignmentError) Type() string

Type returns human-readable type of this error. Used in the admission control to populate Admission Failure reason.

type StaticPolicyOptions added in v1.22.0

type StaticPolicyOptions struct {
	// flag to enable extra allocation restrictions to avoid
	// different containers to possibly end up on the same core.
	// we consider "core" and "physical CPU" synonim here, leaning
	// towards the terminoloy k8s hints. We acknowledge this is confusing.
	//
	// looking at https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/,
	// any possible naming scheme will lead to ambiguity to some extent.
	// We picked "pcpu" because it the established docs hints at vCPU already.
	FullPhysicalCPUsOnly bool
	// Flag to evenly distribute CPUs across NUMA nodes in cases where more
	// than one NUMA node is required to satisfy the allocation.
	DistributeCPUsAcrossNUMA bool
	// Flag to ensure CPUs are considered aligned at socket boundary rather than
	// NUMA boundary
	AlignBySocket bool
	// flag to enable extra allocation restrictions to spread
	// cpus (HT) on different physical core.
	// This is a preferred policy so do not throw error if they have to packed in one physical core.
	DistributeCPUsAcrossCores bool
	// Flag to remove reserved cores from the list of available cores
	StrictCPUReservation bool
	// Flag that makes best-effort to align CPUs to a uncorecache boundary
	// As long as there are CPUs available, pods will be admitted if the condition is not met.
	PreferAlignByUncoreCacheOption bool
}

StaticPolicyOptions holds the parsed value of the policy options, ready to be consumed internally.

func NewStaticPolicyOptions added in v1.22.0

func NewStaticPolicyOptions(policyOptions map[string]string) (StaticPolicyOptions, error)

NewStaticPolicyOptions creates a StaticPolicyOptions struct from the user configuration.

Directories

Path Synopsis
Package topology contains helpers for the CPU manager.
Package topology contains helpers for the CPU manager.

Jump to

Keyboard shortcuts

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