Merge pull request #113744 from iancoolidge/devel-cpuset-set

Prepare cpuset for import into kubernets/utils
This commit is contained in:
Kubernetes Prow Robot 2023-01-06 21:01:27 -08:00 committed by GitHub
commit 8ce77a53b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 606 additions and 717 deletions

View file

@ -465,7 +465,7 @@ func makeEventRecorder(kubeDeps *kubelet.Dependencies, nodeName types.NodeName)
}
func getReservedCPUs(machineInfo *cadvisorapi.MachineInfo, cpus string) (cpuset.CPUSet, error) {
emptyCPUSet := cpuset.NewCPUSet()
emptyCPUSet := cpuset.New()
if cpus == "" {
return emptyCPUSet, nil

View file

@ -972,16 +972,24 @@ func (cm *containerManagerImpl) GetAllocatableDevices() []*podresourcesapi.Conta
return containerDevicesFromResourceDeviceInstances(cm.deviceManager.GetAllocatableDevices())
}
func int64Slice(in []int) []int64 {
out := make([]int64, len(in))
for i := range in {
out[i] = int64(in[i])
}
return out
}
func (cm *containerManagerImpl) GetCPUs(podUID, containerName string) []int64 {
if cm.cpuManager != nil {
return cm.cpuManager.GetExclusiveCPUs(podUID, containerName).ToSliceNoSortInt64()
return int64Slice(cm.cpuManager.GetExclusiveCPUs(podUID, containerName).UnsortedList())
}
return []int64{}
}
func (cm *containerManagerImpl) GetAllocatableCPUs() []int64 {
if cm.cpuManager != nil {
return cm.cpuManager.GetAllocatableCPUs().ToSliceNoSortInt64()
return int64Slice(cm.cpuManager.GetAllocatableCPUs().UnsortedList())
}
return []int64{}
}

View file

@ -128,7 +128,7 @@ func (n *numaFirst) takeFullSecondLevel() {
// If NUMA nodes are higher in the memory hierarchy than sockets, then just
// sort the NUMA nodes directly, and return them.
func (n *numaFirst) sortAvailableNUMANodes() []int {
numas := n.acc.details.NUMANodes().ToSliceNoSort()
numas := n.acc.details.NUMANodes().UnsortedList()
n.acc.sort(numas, n.acc.details.CPUsInNUMANodes)
return numas
}
@ -139,7 +139,7 @@ func (n *numaFirst) sortAvailableNUMANodes() []int {
func (n *numaFirst) sortAvailableSockets() []int {
var result []int
for _, numa := range n.sortAvailableNUMANodes() {
sockets := n.acc.details.SocketsInNUMANodes(numa).ToSliceNoSort()
sockets := n.acc.details.SocketsInNUMANodes(numa).UnsortedList()
n.acc.sort(sockets, n.acc.details.CPUsInSockets)
result = append(result, sockets...)
}
@ -151,7 +151,7 @@ func (n *numaFirst) sortAvailableSockets() []int {
func (n *numaFirst) sortAvailableCores() []int {
var result []int
for _, socket := range n.acc.sortAvailableSockets() {
cores := n.acc.details.CoresInSockets(socket).ToSliceNoSort()
cores := n.acc.details.CoresInSockets(socket).UnsortedList()
n.acc.sort(cores, n.acc.details.CPUsInCores)
result = append(result, cores...)
}
@ -176,7 +176,7 @@ func (s *socketsFirst) takeFullSecondLevel() {
func (s *socketsFirst) sortAvailableNUMANodes() []int {
var result []int
for _, socket := range s.sortAvailableSockets() {
numas := s.acc.details.NUMANodesInSockets(socket).ToSliceNoSort()
numas := s.acc.details.NUMANodesInSockets(socket).UnsortedList()
s.acc.sort(numas, s.acc.details.CPUsInNUMANodes)
result = append(result, numas...)
}
@ -186,7 +186,7 @@ func (s *socketsFirst) sortAvailableNUMANodes() []int {
// If sockets are higher in the memory hierarchy than NUMA nodes, then just
// sort the sockets directly, and return them.
func (s *socketsFirst) sortAvailableSockets() []int {
sockets := s.acc.details.Sockets().ToSliceNoSort()
sockets := s.acc.details.Sockets().UnsortedList()
s.acc.sort(sockets, s.acc.details.CPUsInSockets)
return sockets
}
@ -196,7 +196,7 @@ func (s *socketsFirst) sortAvailableSockets() []int {
func (s *socketsFirst) sortAvailableCores() []int {
var result []int
for _, numa := range s.acc.sortAvailableNUMANodes() {
cores := s.acc.details.CoresInNUMANodes(numa).ToSliceNoSort()
cores := s.acc.details.CoresInNUMANodes(numa).UnsortedList()
s.acc.sort(cores, s.acc.details.CPUsInCores)
result = append(result, cores...)
}
@ -216,7 +216,7 @@ func newCPUAccumulator(topo *topology.CPUTopology, availableCPUs cpuset.CPUSet,
topo: topo,
details: topo.CPUDetails.KeepOnly(availableCPUs),
numCPUsNeeded: numCPUs,
result: cpuset.NewCPUSet(),
result: cpuset.New(),
}
if topo.NumSockets >= topo.NumNUMANodes {
@ -323,7 +323,7 @@ func (a *cpuAccumulator) sortAvailableCores() []int {
func (a *cpuAccumulator) sortAvailableCPUs() []int {
var result []int
for _, core := range a.sortAvailableCores() {
cpus := a.details.CPUsInCores(core).ToSliceNoSort()
cpus := a.details.CPUsInCores(core).UnsortedList()
sort.Ints(cpus)
result = append(result, cpus...)
}
@ -372,7 +372,7 @@ func (a *cpuAccumulator) takeFullCores() {
func (a *cpuAccumulator) takeRemainingCPUs() {
for _, cpu := range a.sortAvailableCPUs() {
klog.V(4).InfoS("takeRemainingCPUs: claiming CPU", "cpu", cpu)
a.take(cpuset.NewCPUSet(cpu))
a.take(cpuset.New(cpu))
if a.isSatisfied() {
return
}
@ -453,7 +453,7 @@ func takeByTopologyNUMAPacked(topo *topology.CPUTopology, availableCPUs cpuset.C
return acc.result, nil
}
if acc.isFailed() {
return cpuset.NewCPUSet(), fmt.Errorf("not enough cpus available to satisfy request")
return cpuset.New(), fmt.Errorf("not enough cpus available to satisfy request")
}
// Algorithm: topology-aware best-fit
@ -485,7 +485,7 @@ func takeByTopologyNUMAPacked(topo *topology.CPUTopology, availableCPUs cpuset.C
return acc.result, nil
}
return cpuset.NewCPUSet(), fmt.Errorf("failed to allocate cpus")
return cpuset.New(), fmt.Errorf("failed to allocate cpus")
}
// takeByTopologyNUMADistributed returns a CPUSet of size 'numCPUs'.
@ -565,7 +565,7 @@ func takeByTopologyNUMADistributed(topo *topology.CPUTopology, availableCPUs cpu
return acc.result, nil
}
if acc.isFailed() {
return cpuset.NewCPUSet(), fmt.Errorf("not enough cpus available to satisfy request")
return cpuset.New(), fmt.Errorf("not enough cpus available to satisfy request")
}
// Get the list of NUMA nodes represented by the set of CPUs in 'availableCPUs'.
@ -763,13 +763,13 @@ func takeByTopologyNUMADistributed(topo *topology.CPUTopology, availableCPUs cpu
// If we haven't allocated all of our CPUs at this point, then something
// went wrong in our accounting and we should error out.
if acc.numCPUsNeeded > 0 {
return cpuset.NewCPUSet(), fmt.Errorf("accounting error, not enough CPUs allocated, remaining: %v", acc.numCPUsNeeded)
return cpuset.New(), fmt.Errorf("accounting error, not enough CPUs allocated, remaining: %v", acc.numCPUsNeeded)
}
// Likewise, if we have allocated too many CPUs at this point, then something
// went wrong in our accounting and we should error out.
if acc.numCPUsNeeded < 0 {
return cpuset.NewCPUSet(), fmt.Errorf("accounting error, too many CPUs allocated, remaining: %v", acc.numCPUsNeeded)
return cpuset.New(), fmt.Errorf("accounting error, too many CPUs allocated, remaining: %v", acc.numCPUsNeeded)
}
// Otherwise, return the result

View file

@ -35,31 +35,31 @@ func TestCPUAccumulatorFreeSockets(t *testing.T) {
{
"single socket HT, 1 socket free",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]int{0},
},
{
"single socket HT, 0 sockets free",
topoSingleSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
cpuset.New(1, 2, 3, 4, 5, 6, 7),
[]int{},
},
{
"dual socket HT, 2 sockets free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
[]int{0, 1},
},
{
"dual socket HT, 1 socket free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11),
[]int{1},
},
{
"dual socket HT, 0 sockets free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 2, 3, 4, 5, 6, 7, 8, 9, 11),
cpuset.New(0, 2, 3, 4, 5, 6, 7, 8, 9, 11),
[]int{},
},
{
@ -135,31 +135,31 @@ func TestCPUAccumulatorFreeNUMANodes(t *testing.T) {
{
"single socket HT, 1 NUMA node free",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]int{0},
},
{
"single socket HT, 0 NUMA Node free",
topoSingleSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
cpuset.New(1, 2, 3, 4, 5, 6, 7),
[]int{},
},
{
"dual socket HT, 2 NUMA Node free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
[]int{0, 1},
},
{
"dual socket HT, 1 NUMA Node free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11),
[]int{1},
},
{
"dual socket HT, 0 NUMA node free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 2, 3, 4, 5, 6, 7, 8, 9, 11),
cpuset.New(0, 2, 3, 4, 5, 6, 7, 8, 9, 11),
[]int{},
},
{
@ -286,49 +286,49 @@ func TestCPUAccumulatorFreeCores(t *testing.T) {
{
"single socket HT, 4 cores free",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]int{0, 1, 2, 3},
},
{
"single socket HT, 3 cores free",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 4, 5, 6),
cpuset.New(0, 1, 2, 4, 5, 6),
[]int{0, 1, 2},
},
{
"single socket HT, 3 cores free (1 partially consumed)",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6),
cpuset.New(0, 1, 2, 3, 4, 5, 6),
[]int{0, 1, 2},
},
{
"single socket HT, 0 cores free",
topoSingleSocketHT,
cpuset.NewCPUSet(),
cpuset.New(),
[]int{},
},
{
"single socket HT, 0 cores free (4 partially consumed)",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3),
cpuset.New(0, 1, 2, 3),
[]int{},
},
{
"dual socket HT, 6 cores free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
[]int{0, 2, 4, 1, 3, 5},
},
{
"dual socket HT, 5 cores free (1 consumed from socket 0)",
topoDualSocketHT,
cpuset.NewCPUSet(2, 1, 3, 4, 5, 7, 8, 9, 10, 11),
cpuset.New(2, 1, 3, 4, 5, 7, 8, 9, 10, 11),
[]int{2, 4, 1, 3, 5},
},
{
"dual socket HT, 4 cores free (1 consumed from each socket)",
topoDualSocketHT,
cpuset.NewCPUSet(2, 3, 4, 5, 8, 9, 10, 11),
cpuset.New(2, 3, 4, 5, 8, 9, 10, 11),
[]int{2, 4, 3, 5},
},
}
@ -354,37 +354,37 @@ func TestCPUAccumulatorFreeCPUs(t *testing.T) {
{
"single socket HT, 8 cpus free",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]int{0, 4, 1, 5, 2, 6, 3, 7},
},
{
"single socket HT, 5 cpus free",
topoSingleSocketHT,
cpuset.NewCPUSet(3, 4, 5, 6, 7),
cpuset.New(3, 4, 5, 6, 7),
[]int{4, 5, 6, 3, 7},
},
{
"dual socket HT, 12 cpus free",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
[]int{0, 6, 2, 8, 4, 10, 1, 7, 3, 9, 5, 11},
},
{
"dual socket HT, 11 cpus free",
topoDualSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
cpuset.New(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
[]int{6, 2, 8, 4, 10, 1, 7, 3, 9, 5, 11},
},
{
"dual socket HT, 10 cpus free",
topoDualSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
cpuset.New(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
[]int{2, 8, 4, 10, 1, 7, 3, 9, 5, 11},
},
{
"triple socket HT, 12 cpus free",
topoTripleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13),
cpuset.New(0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13),
[]int{12, 13, 0, 1, 2, 3, 6, 7, 8, 9, 10, 11},
},
}
@ -413,8 +413,8 @@ func TestCPUAccumulatorTake(t *testing.T) {
{
"take 0 cpus from a single socket HT, require 1",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{cpuset.NewCPUSet()},
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{cpuset.New()},
1,
false,
false,
@ -422,8 +422,8 @@ func TestCPUAccumulatorTake(t *testing.T) {
{
"take 0 cpus from a single socket HT, require 1, none available",
topoSingleSocketHT,
cpuset.NewCPUSet(),
[]cpuset.CPUSet{cpuset.NewCPUSet()},
cpuset.New(),
[]cpuset.CPUSet{cpuset.New()},
1,
false,
true,
@ -431,8 +431,8 @@ func TestCPUAccumulatorTake(t *testing.T) {
{
"take 1 cpu from a single socket HT, require 1",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{cpuset.NewCPUSet(0)},
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{cpuset.New(0)},
1,
true,
false,
@ -440,8 +440,8 @@ func TestCPUAccumulatorTake(t *testing.T) {
{
"take 1 cpu from a single socket HT, require 2",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{cpuset.NewCPUSet(0)},
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{cpuset.New(0)},
2,
false,
false,
@ -449,8 +449,8 @@ func TestCPUAccumulatorTake(t *testing.T) {
{
"take 2 cpu from a single socket HT, require 4, expect failed",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2),
[]cpuset.CPUSet{cpuset.NewCPUSet(0), cpuset.NewCPUSet(1)},
cpuset.New(0, 1, 2),
[]cpuset.CPUSet{cpuset.New(0), cpuset.New(1)},
4,
false,
true,
@ -458,16 +458,16 @@ func TestCPUAccumulatorTake(t *testing.T) {
{
"take all cpus one at a time from a single socket HT, require 8",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
[]cpuset.CPUSet{
cpuset.NewCPUSet(0),
cpuset.NewCPUSet(1),
cpuset.NewCPUSet(2),
cpuset.NewCPUSet(3),
cpuset.NewCPUSet(4),
cpuset.NewCPUSet(5),
cpuset.NewCPUSet(6),
cpuset.NewCPUSet(7),
cpuset.New(0),
cpuset.New(1),
cpuset.New(2),
cpuset.New(3),
cpuset.New(4),
cpuset.New(5),
cpuset.New(6),
cpuset.New(7),
},
8,
true,
@ -520,66 +520,66 @@ func commonTakeByTopologyTestCases(t *testing.T) []takeByTopologyTestCase {
{
"take more cpus than are available from single socket with HT",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 2, 4, 6),
cpuset.New(0, 2, 4, 6),
5,
"not enough cpus available to satisfy request",
cpuset.NewCPUSet(),
cpuset.New(),
},
{
"take zero cpus from single socket with HT",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
0,
"",
cpuset.NewCPUSet(),
cpuset.New(),
},
{
"take one cpu from single socket with HT",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
1,
"",
cpuset.NewCPUSet(0),
cpuset.New(0),
},
{
"take one cpu from single socket with HT, some cpus are taken",
topoSingleSocketHT,
cpuset.NewCPUSet(1, 3, 5, 6, 7),
cpuset.New(1, 3, 5, 6, 7),
1,
"",
cpuset.NewCPUSet(6),
cpuset.New(6),
},
{
"take two cpus from single socket with HT",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
2,
"",
cpuset.NewCPUSet(0, 4),
cpuset.New(0, 4),
},
{
"take all cpus from single socket with HT",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
8,
"",
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
},
{
"take two cpus from single socket with HT, only one core totally free",
topoSingleSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 6),
cpuset.New(0, 1, 2, 3, 6),
2,
"",
cpuset.NewCPUSet(2, 6),
cpuset.New(2, 6),
},
{
"take a socket of cpus from dual socket with HT",
topoDualSocketHT,
cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
6,
"",
cpuset.NewCPUSet(0, 2, 4, 6, 8, 10),
cpuset.New(0, 2, 4, 6, 8, 10),
},
{
"take a socket of cpus from dual socket with multi-numa-per-socket with HT",
@ -630,10 +630,10 @@ func TestTakeByTopologyNUMAPacked(t *testing.T) {
{
"take one cpu from dual socket with HT - core from Socket 0",
topoDualSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
cpuset.New(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
1,
"",
cpuset.NewCPUSet(2),
cpuset.New(2),
},
{
"allocate 4 full cores with 3 coming from the first NUMA node (filling it up) and 1 coming from the second NUMA node",
@ -767,20 +767,20 @@ func TestTakeByTopologyNUMADistributed(t *testing.T) {
{
"take one cpu from dual socket with HT - core from Socket 0",
topoDualSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
cpuset.New(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
1,
1,
"",
cpuset.NewCPUSet(1),
cpuset.New(1),
},
{
"take one cpu from dual socket with HT - core from Socket 0 - cpuGroupSize 2",
topoDualSocketHT,
cpuset.NewCPUSet(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
cpuset.New(1, 2, 3, 4, 5, 7, 8, 9, 10, 11),
1,
2,
"",
cpuset.NewCPUSet(2),
cpuset.New(2),
},
{
"allocate 13 full cores distributed across the first 2 NUMA nodes",

View file

@ -121,7 +121,7 @@ func (p *mockPolicy) GetPodTopologyHints(s state.State, pod *v1.Pod) map[string]
}
func (p *mockPolicy) GetAllocatableCPUs(m state.State) cpuset.CPUSet {
return cpuset.NewCPUSet()
return cpuset.New()
}
type mockRuntimeService struct {
@ -228,7 +228,7 @@ func TestCPUManagerAdd(t *testing.T) {
},
},
0,
cpuset.NewCPUSet(),
cpuset.New(),
topologymanager.NewFakeManager(),
nil)
testCases := []struct {
@ -243,7 +243,7 @@ func TestCPUManagerAdd(t *testing.T) {
description: "cpu manager add - no error",
updateErr: nil,
policy: testPolicy,
expCPUSet: cpuset.NewCPUSet(3, 4),
expCPUSet: cpuset.New(3, 4),
expAllocateErr: nil,
expAddContainerErr: nil,
},
@ -253,7 +253,7 @@ func TestCPUManagerAdd(t *testing.T) {
policy: &mockPolicy{
err: fmt.Errorf("fake reg error"),
},
expCPUSet: cpuset.NewCPUSet(1, 2, 3, 4),
expCPUSet: cpuset.New(1, 2, 3, 4),
expAllocateErr: fmt.Errorf("fake reg error"),
expAddContainerErr: nil,
},
@ -264,7 +264,7 @@ func TestCPUManagerAdd(t *testing.T) {
policy: testCase.policy,
state: &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3, 4),
defaultCPUSet: cpuset.New(1, 2, 3, 4),
},
lastUpdateState: state.NewMemoryState(),
containerRuntime: mockRuntimeService{
@ -316,71 +316,71 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
[]struct{ request, limit string }{{"100m", "100m"}},
[]struct{ request, limit string }{{"4000m", "4000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet()},
cpuset.New()},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5)},
},
{
description: "Equal Number of Guaranteed CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
[]struct{ request, limit string }{{"4000m", "4000m"}},
[]struct{ request, limit string }{{"4000m", "4000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5)},
},
{
description: "More Init Container Guaranteed CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
[]struct{ request, limit string }{{"6000m", "6000m"}},
[]struct{ request, limit string }{{"4000m", "4000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5, 2, 6)},
cpuset.New(0, 4, 1, 5, 2, 6)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5)},
},
{
description: "Less Init Container Guaranteed CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
[]struct{ request, limit string }{{"2000m", "2000m"}},
[]struct{ request, limit string }{{"4000m", "4000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4)},
cpuset.New(0, 4)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5)},
},
{
description: "Multi Init Container Equal CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID-1", "initFakeID-2"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
@ -390,17 +390,17 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
[]struct{ request, limit string }{
{"2000m", "2000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4),
cpuset.NewCPUSet(0, 4)},
cpuset.New(0, 4),
cpuset.New(0, 4)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4)},
cpuset.New(0, 4)},
},
{
description: "Multi Init Container Less CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID-1", "initFakeID-2"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
@ -410,17 +410,17 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
[]struct{ request, limit string }{
{"2000m", "2000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5),
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5),
cpuset.New(0, 4, 1, 5)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4)},
cpuset.New(0, 4)},
},
{
description: "Multi Init Container More CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID-1", "initFakeID-2"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
@ -430,17 +430,17 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
[]struct{ request, limit string }{
{"4000m", "4000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4),
cpuset.NewCPUSet(0, 4)},
cpuset.New(0, 4),
cpuset.New(0, 4)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4, 1, 5)},
},
{
description: "Multi Init Container Increasing CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID-1", "initFakeID-2"},
containerIDs: []string{"appFakeID"},
pod: makeMultiContainerPod(
@ -450,17 +450,17 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
[]struct{ request, limit string }{
{"6000m", "6000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4),
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4),
cpuset.New(0, 4, 1, 5)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4, 1, 5, 2, 6)},
cpuset.New(0, 4, 1, 5, 2, 6)},
},
{
description: "Multi Init, Multi App Container Split CPUs",
topo: topoSingleSocketHT,
numReservedCPUs: 0,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
initContainerIDs: []string{"initFakeID-1", "initFakeID-2"},
containerIDs: []string{"appFakeID-1", "appFakeID-2"},
pod: makeMultiContainerPod(
@ -471,16 +471,16 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
{"2000m", "2000m"},
{"2000m", "2000m"}}),
expInitCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4),
cpuset.NewCPUSet(0, 4, 1, 5)},
cpuset.New(0, 4),
cpuset.New(0, 4, 1, 5)},
expCSets: []cpuset.CPUSet{
cpuset.NewCPUSet(0, 4),
cpuset.NewCPUSet(1, 5)},
cpuset.New(0, 4),
cpuset.New(1, 5)},
},
}
for _, testCase := range testCases {
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil)
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.New(), topologymanager.NewFakeManager(), nil)
mockState := &mockState{
assignments: testCase.stAssignments,
@ -512,7 +512,7 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
testCase.expInitCSets,
testCase.expCSets...)
cumCSet := cpuset.NewCPUSet()
cumCSet := cpuset.New()
for i := range containers {
err := mgr.Allocate(testCase.pod, &containers[i])
@ -635,7 +635,7 @@ func TestCPUManagerGenerate(t *testing.T) {
}
defer os.RemoveAll(sDir)
mgr, err := NewManager(testCase.cpuPolicyName, nil, 5*time.Second, machineInfo, cpuset.NewCPUSet(), testCase.nodeAllocatableReservation, sDir, topologymanager.NewFakeManager())
mgr, err := NewManager(testCase.cpuPolicyName, nil, 5*time.Second, machineInfo, cpuset.New(), testCase.nodeAllocatableReservation, sDir, topologymanager.NewFakeManager())
if testCase.expectedError != nil {
if !strings.Contains(err.Error(), testCase.expectedError.Error()) {
t.Errorf("Unexpected error message. Have: %s wants %s", err.Error(), testCase.expectedError.Error())
@ -671,7 +671,7 @@ func TestCPUManagerRemove(t *testing.T) {
},
state: &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
},
lastUpdateState: state.NewMemoryState(),
containerRuntime: mockRuntimeService{},
@ -722,7 +722,7 @@ func TestReconcileState(t *testing.T) {
},
},
0,
cpuset.NewCPUSet(),
cpuset.New(),
topologymanager.NewFakeManager(),
nil)
@ -775,18 +775,18 @@ func TestReconcileState(t *testing.T) {
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
expectStDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
expectSucceededContainerName: "fakeContainerName",
expectFailedContainerName: "",
},
@ -823,18 +823,18 @@ func TestReconcileState(t *testing.T) {
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
expectStDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
expectSucceededContainerName: "fakeContainerName",
expectFailedContainerName: "",
},
@ -860,11 +860,11 @@ func TestReconcileState(t *testing.T) {
pspFound: false,
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(),
stDefaultCPUSet: cpuset.New(),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{},
expectStDefaultCPUSet: cpuset.NewCPUSet(),
expectStDefaultCPUSet: cpuset.New(),
expectSucceededContainerName: "",
expectFailedContainerName: "",
},
@ -897,11 +897,11 @@ func TestReconcileState(t *testing.T) {
pspFound: true,
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(),
stDefaultCPUSet: cpuset.New(),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{},
expectStDefaultCPUSet: cpuset.NewCPUSet(),
expectStDefaultCPUSet: cpuset.New(),
expectSucceededContainerName: "",
expectFailedContainerName: "fakeContainerName",
},
@ -938,18 +938,18 @@ func TestReconcileState(t *testing.T) {
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(),
"fakeContainerName": cpuset.New(),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(),
"fakeContainerName": cpuset.New(),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
expectStDefaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
expectSucceededContainerName: "",
expectFailedContainerName: "fakeContainerName",
},
@ -986,18 +986,18 @@ func TestReconcileState(t *testing.T) {
updateErr: fmt.Errorf("fake container update error"),
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
expectStDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
expectSucceededContainerName: "",
expectFailedContainerName: "fakeContainerName",
},
@ -1034,21 +1034,21 @@ func TestReconcileState(t *testing.T) {
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
"secondfakePodUID": map[string]cpuset.CPUSet{
"secondfakeContainerName": cpuset.NewCPUSet(3, 4),
"secondfakeContainerName": cpuset.New(3, 4),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(5, 6, 7),
stDefaultCPUSet: cpuset.New(5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(),
lastUpdateStDefaultCPUSet: cpuset.New(),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
expectStDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
expectSucceededContainerName: "fakeContainerName",
expectFailedContainerName: "",
},
@ -1085,22 +1085,22 @@ func TestReconcileState(t *testing.T) {
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(5, 6, 7),
stDefaultCPUSet: cpuset.New(5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(5, 6, 7),
lastUpdateStDefaultCPUSet: cpuset.New(5, 6, 7),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(5, 6, 7),
expectStDefaultCPUSet: cpuset.New(5, 6, 7),
expectSucceededContainerName: "fakeContainerName",
expectFailedContainerName: "",
},
@ -1137,22 +1137,22 @@ func TestReconcileState(t *testing.T) {
updateErr: nil,
stAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
lastUpdateStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(3, 4),
"fakeContainerName": cpuset.New(3, 4),
},
},
lastUpdateStDefaultCPUSet: cpuset.NewCPUSet(1, 2, 5, 6, 7),
lastUpdateStDefaultCPUSet: cpuset.New(1, 2, 5, 6, 7),
expectStAssignments: state.ContainerCPUAssignments{
"fakePodUID": map[string]cpuset.CPUSet{
"fakeContainerName": cpuset.NewCPUSet(1, 2),
"fakeContainerName": cpuset.New(1, 2),
},
},
expectStDefaultCPUSet: cpuset.NewCPUSet(3, 4, 5, 6, 7),
expectStDefaultCPUSet: cpuset.New(3, 4, 5, 6, 7),
expectSucceededContainerName: "fakeContainerName",
expectFailedContainerName: "",
},
@ -1241,7 +1241,7 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
},
},
1,
cpuset.NewCPUSet(0),
cpuset.New(0),
topologymanager.NewFakeManager(),
nil)
testCases := []struct {
@ -1256,7 +1256,7 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
description: "cpu manager add - no error",
updateErr: nil,
policy: testPolicy,
expCPUSet: cpuset.NewCPUSet(0, 3),
expCPUSet: cpuset.New(0, 3),
expAllocateErr: nil,
expAddContainerErr: nil,
},
@ -1267,7 +1267,7 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
policy: testCase.policy,
state: &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3),
defaultCPUSet: cpuset.New(0, 1, 2, 3),
},
lastUpdateState: state.NewMemoryState(),
containerRuntime: mockRuntimeService{
@ -1355,7 +1355,7 @@ func TestCPUManagerHandlePolicyOptions(t *testing.T) {
}
defer os.RemoveAll(sDir)
_, err = NewManager(testCase.cpuPolicyName, testCase.cpuPolicyOptions, 5*time.Second, machineInfo, cpuset.NewCPUSet(), nodeAllocatableReservation, sDir, topologymanager.NewFakeManager())
_, err = NewManager(testCase.cpuPolicyName, testCase.cpuPolicyOptions, 5*time.Second, machineInfo, cpuset.New(), nodeAllocatableReservation, sDir, topologymanager.NewFakeManager())
if err == nil {
t.Errorf("Expected error, but NewManager succeeded")
}
@ -1382,7 +1382,7 @@ func TestCPUManagerGetAllocatableCPUs(t *testing.T) {
},
},
1,
cpuset.NewCPUSet(0),
cpuset.New(0),
topologymanager.NewFakeManager(),
nil)
@ -1394,12 +1394,12 @@ func TestCPUManagerGetAllocatableCPUs(t *testing.T) {
{
description: "None Policy",
policy: nonePolicy,
expAllocatableCPUs: cpuset.NewCPUSet(),
expAllocatableCPUs: cpuset.New(),
},
{
description: "Static Policy",
policy: staticPolicy,
expAllocatableCPUs: cpuset.NewCPUSet(1, 2, 3),
expAllocatableCPUs: cpuset.New(1, 2, 3),
},
}
for _, testCase := range testCases {
@ -1408,7 +1408,7 @@ func TestCPUManagerGetAllocatableCPUs(t *testing.T) {
activePods: func() []*v1.Pod { return nil },
state: &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3),
defaultCPUSet: cpuset.New(0, 1, 2, 3),
},
lastUpdateState: state.NewMemoryState(),
containerMap: containermap.NewContainerMap(),

View file

@ -72,5 +72,5 @@ func (p *nonePolicy) GetPodTopologyHints(s state.State, pod *v1.Pod) map[string]
// CAN get exclusive access to core(s).
// Hence, we return empty set here: no cpus are assignable according to above definition with this policy.
func (p *nonePolicy) GetAllocatableCPUs(m state.State) cpuset.CPUSet {
return cpuset.NewCPUSet()
return cpuset.New()
}

View file

@ -37,7 +37,7 @@ func TestNonePolicyAllocate(t *testing.T) {
st := &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
defaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
}
testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m")
@ -54,7 +54,7 @@ func TestNonePolicyRemove(t *testing.T) {
st := &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
defaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
}
testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m")
@ -78,7 +78,7 @@ func TestNonePolicyGetAllocatableCPUs(t *testing.T) {
st := &mockState{
assignments: state.ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(cpuIDs...),
defaultCPUSet: cpuset.New(cpuIDs...),
}
cpus := policy.GetAllocatableCPUs(st)

View file

@ -217,7 +217,7 @@ func (p *staticPolicy) validateState(s state.State) error {
tmpCPUSets = append(tmpCPUSets, cset)
}
}
totalKnownCPUs = totalKnownCPUs.UnionAll(tmpCPUSets)
totalKnownCPUs = totalKnownCPUs.Union(tmpCPUSets...)
if !totalKnownCPUs.Equals(p.topology.CPUDetails.CPUs()) {
return fmt.Errorf("current set of available CPUs \"%s\" doesn't match with CPUs in state \"%s\"",
p.topology.CPUDetails.CPUs().String(), totalKnownCPUs.String())
@ -245,7 +245,7 @@ func (p *staticPolicy) updateCPUsToReuse(pod *v1.Pod, container *v1.Container, c
}
// If no cpuset exists for cpusToReuse by this pod yet, create one.
if _, ok := p.cpusToReuse[string(pod.UID)]; !ok {
p.cpusToReuse[string(pod.UID)] = cpuset.NewCPUSet()
p.cpusToReuse[string(pod.UID)] = cpuset.New()
}
// Check if the container is an init container.
// If so, add its cpuset to the cpuset of reusable CPUs for any new allocations.
@ -316,7 +316,7 @@ func (p *staticPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Contai
// getAssignedCPUsOfSiblings returns assigned cpus of given container's siblings(all containers other than the given container) in the given pod `podUID`.
func getAssignedCPUsOfSiblings(s state.State, podUID string, containerName string) cpuset.CPUSet {
assignments := s.GetCPUAssignments()
cset := cpuset.NewCPUSet()
cset := cpuset.New()
for name, cpus := range assignments[podUID] {
if containerName == name {
continue
@ -344,7 +344,7 @@ func (p *staticPolicy) allocateCPUs(s state.State, numCPUs int, numaAffinity bit
allocatableCPUs := p.GetAvailableCPUs(s).Union(reusableCPUs)
// If there are aligned CPUs in numaAffinity, attempt to take those first.
result := cpuset.NewCPUSet()
result := cpuset.New()
if numaAffinity != nil {
alignedCPUs := p.getAlignedCPUs(numaAffinity, allocatableCPUs)
@ -355,7 +355,7 @@ func (p *staticPolicy) allocateCPUs(s state.State, numCPUs int, numaAffinity bit
alignedCPUs, err := p.takeByTopology(alignedCPUs, numAlignedToAlloc)
if err != nil {
return cpuset.NewCPUSet(), err
return cpuset.New(), err
}
result = result.Union(alignedCPUs)
@ -364,7 +364,7 @@ func (p *staticPolicy) allocateCPUs(s state.State, numCPUs int, numaAffinity bit
// Get any remaining CPUs from what's leftover after attempting to grab aligned ones.
remainingCPUs, err := p.takeByTopology(allocatableCPUs.Difference(result), numCPUs-result.Size())
if err != nil {
return cpuset.NewCPUSet(), err
return cpuset.New(), err
}
result = result.Union(remainingCPUs)
@ -486,7 +486,7 @@ func (p *staticPolicy) GetPodTopologyHints(s state.State, pod *v1.Pod) map[strin
return nil
}
assignedCPUs := cpuset.NewCPUSet()
assignedCPUs := cpuset.New()
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
requestedByContainer := p.guaranteedCPUs(pod, &container)
// Short circuit to regenerate the same hints if there are already
@ -544,7 +544,7 @@ func (p *staticPolicy) generateCPUTopologyHints(availableCPUs cpuset.CPUSet, reu
// Iterate through all combinations of numa nodes bitmask and build hints from them.
hints := []topologymanager.TopologyHint{}
bitmask.IterateBitMasks(p.topology.CPUDetails.NUMANodes().ToSlice(), func(mask bitmask.BitMask) {
bitmask.IterateBitMasks(p.topology.CPUDetails.NUMANodes().List(), func(mask bitmask.BitMask) {
// First, update minAffinitySize for the current request size.
cpusInMask := p.topology.CPUDetails.CPUsInNUMANodes(mask.GetBits()...).Size()
if cpusInMask >= request && mask.Count() < minAffinitySize {
@ -554,7 +554,7 @@ func (p *staticPolicy) generateCPUTopologyHints(availableCPUs cpuset.CPUSet, reu
// Then check to see if we have enough CPUs available on the current
// numa node bitmask to satisfy the CPU request.
numMatching := 0
for _, c := range reusableCPUs.ToSlice() {
for _, c := range reusableCPUs.List() {
// Disregard this mask if its NUMANode isn't part of it.
if !mask.IsSet(p.topology.CPUDetails[c].NUMANodeID) {
return
@ -564,7 +564,7 @@ func (p *staticPolicy) generateCPUTopologyHints(availableCPUs cpuset.CPUSet, reu
// Finally, check to see if enough available CPUs remain on the current
// NUMA node combination to satisfy the CPU request.
for _, c := range availableCPUs.ToSlice() {
for _, c := range availableCPUs.List() {
if mask.IsSet(p.topology.CPUDetails[c].NUMANodeID) {
numMatching++
}
@ -616,14 +616,14 @@ func (p *staticPolicy) isHintSocketAligned(hint topologymanager.TopologyHint, mi
// getAlignedCPUs return set of aligned CPUs based on numa affinity mask and configured policy options.
func (p *staticPolicy) getAlignedCPUs(numaAffinity bitmask.BitMask, allocatableCPUs cpuset.CPUSet) cpuset.CPUSet {
alignedCPUs := cpuset.NewCPUSet()
alignedCPUs := cpuset.New()
numaBits := numaAffinity.GetBits()
// If align-by-socket policy option is enabled, NUMA based hint is expanded to
// socket aligned hint. It will ensure that first socket aligned available CPUs are
// allocated before we try to find CPUs across socket to satisfy allocation request.
if p.options.AlignBySocket {
socketBits := p.topology.CPUDetails.SocketsInNUMANodes(numaBits...).ToSliceNoSort()
socketBits := p.topology.CPUDetails.SocketsInNUMANodes(numaBits...).UnsortedList()
for _, socketID := range socketBits {
alignedCPUs = alignedCPUs.Union(allocatableCPUs.Intersection(p.topology.CPUDetails.CPUsInSockets(socketID)))
}

View file

@ -68,7 +68,7 @@ func (spt staticPolicyTest) PseudoClone() staticPolicyTest {
}
func TestStaticPolicyName(t *testing.T) {
policy, _ := NewStaticPolicy(topoSingleSocketHT, 1, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil)
policy, _ := NewStaticPolicy(topoSingleSocketHT, 1, cpuset.New(), topologymanager.NewFakeManager(), nil)
policyName := policy.Name()
if policyName != "static" {
@ -84,26 +84,26 @@ func TestStaticPolicyStart(t *testing.T) {
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"0": cpuset.NewCPUSet(0),
"0": cpuset.New(0),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expCSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expCSet: cpuset.New(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
},
{
description: "empty cpuset",
topo: topoDualSocketHT,
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(),
expCSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(),
expCSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
},
{
description: "reserved cores 0 & 6 are not present in available cpuset",
topo: topoDualSocketHT,
numReservedCPUs: 2,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1),
stDefaultCPUSet: cpuset.New(0, 1),
expErr: fmt.Errorf("not all reserved cpus: \"0,6\" are present in defaultCpuSet: \"0-1\""),
},
{
@ -111,10 +111,10 @@ func TestStaticPolicyStart(t *testing.T) {
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"0": cpuset.NewCPUSet(0, 1, 2),
"0": cpuset.New(0, 1, 2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expErr: fmt.Errorf("pod: fakePod, container: 0 cpuset: \"0-2\" overlaps with default cpuset \"2-11\""),
},
{
@ -122,11 +122,11 @@ func TestStaticPolicyStart(t *testing.T) {
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"0": cpuset.NewCPUSet(0, 1, 2),
"1": cpuset.NewCPUSet(3, 4),
"0": cpuset.New(0, 1, 2),
"1": cpuset.New(3, 4),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(5, 6, 7, 8, 9, 10, 11, 12),
stDefaultCPUSet: cpuset.New(5, 6, 7, 8, 9, 10, 11, 12),
expErr: fmt.Errorf("current set of available CPUs \"0-11\" doesn't match with CPUs in state \"0-12\""),
},
{
@ -134,17 +134,17 @@ func TestStaticPolicyStart(t *testing.T) {
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"0": cpuset.NewCPUSet(0, 1, 2),
"1": cpuset.NewCPUSet(3, 4),
"0": cpuset.New(0, 1, 2),
"1": cpuset.New(3, 4),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(5, 6, 7, 8, 9, 10),
stDefaultCPUSet: cpuset.New(5, 6, 7, 8, 9, 10),
expErr: fmt.Errorf("current set of available CPUs \"0-11\" doesn't match with CPUs in state \"0-10\""),
},
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
p, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil)
p, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.New(), topologymanager.NewFakeManager(), nil)
policy := p.(*staticPolicy)
st := &mockState{
assignments: testCase.stAssignments,
@ -176,21 +176,21 @@ func TestStaticPolicyStart(t *testing.T) {
}
func TestStaticPolicyAdd(t *testing.T) {
largeTopoBuilder := cpuset.NewBuilder()
largeTopoSock0Builder := cpuset.NewBuilder()
largeTopoSock1Builder := cpuset.NewBuilder()
var largeTopoCPUids []int
var largeTopoSock0CPUids []int
var largeTopoSock1CPUids []int
largeTopo := *topoQuadSocketFourWayHT
for cpuid, val := range largeTopo.CPUDetails {
largeTopoBuilder.Add(cpuid)
largeTopoCPUids = append(largeTopoCPUids, cpuid)
if val.SocketID == 0 {
largeTopoSock0Builder.Add(cpuid)
largeTopoSock0CPUids = append(largeTopoSock0CPUids, cpuid)
} else if val.SocketID == 1 {
largeTopoSock1Builder.Add(cpuid)
largeTopoSock1CPUids = append(largeTopoSock1CPUids, cpuid)
}
}
largeTopoCPUSet := largeTopoBuilder.Result()
largeTopoSock0CPUSet := largeTopoSock0Builder.Result()
largeTopoSock1CPUSet := largeTopoSock1Builder.Result()
largeTopoCPUSet := cpuset.New(largeTopoCPUids...)
largeTopoSock0CPUSet := cpuset.New(largeTopoSock0CPUids...)
largeTopoSock1CPUSet := cpuset.New(largeTopoSock1CPUids...)
// these are the cases which must behave the same regardless the policy options.
// So we will permutate the options to ensure this holds true.
@ -201,11 +201,11 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoSingleSocketHT,
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer2", "8000m", "8000m"),
expErr: fmt.Errorf("not enough cpus available to satisfy request"),
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
{
description: "GuPodMultipleCores, SingleSocketHT, ExpectAllocOneCore",
@ -213,14 +213,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(2, 3, 6, 7),
"fakeContainer100": cpuset.New(2, 3, 6, 7),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 4, 5),
stDefaultCPUSet: cpuset.New(0, 1, 4, 5),
pod: makePod("fakePod", "fakeContainer3", "2000m", "2000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(1, 5),
expCSet: cpuset.New(1, 5),
},
{
description: "GuPodMultipleCores, SingleSocketHT, ExpectSameAllocation",
@ -228,14 +228,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer3": cpuset.NewCPUSet(2, 3, 6, 7),
"fakeContainer3": cpuset.New(2, 3, 6, 7),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 4, 5),
stDefaultCPUSet: cpuset.New(0, 1, 4, 5),
pod: makePod("fakePod", "fakeContainer3", "4000m", "4000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(2, 3, 6, 7),
expCSet: cpuset.New(2, 3, 6, 7),
},
{
description: "GuPodMultipleCores, DualSocketHT, ExpectAllocOneSocket",
@ -243,14 +243,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(2),
"fakeContainer100": cpuset.New(2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11),
pod: makePod("fakePod", "fakeContainer3", "6000m", "6000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(1, 3, 5, 7, 9, 11),
expCSet: cpuset.New(1, 3, 5, 7, 9, 11),
},
{
description: "GuPodMultipleCores, DualSocketHT, ExpectAllocThreeCores",
@ -258,14 +258,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(1, 5),
"fakeContainer100": cpuset.New(1, 5),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 2, 3, 4, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 2, 3, 4, 6, 7, 8, 9, 10, 11),
pod: makePod("fakePod", "fakeContainer3", "6000m", "6000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(2, 3, 4, 8, 9, 10),
expCSet: cpuset.New(2, 3, 4, 8, 9, 10),
},
{
description: "GuPodMultipleCores, DualSocketNoHT, ExpectAllocOneSocket",
@ -273,14 +273,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(),
"fakeContainer100": cpuset.New(),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer1", "4000m", "4000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(4, 5, 6, 7),
expCSet: cpuset.New(4, 5, 6, 7),
},
{
description: "GuPodMultipleCores, DualSocketNoHT, ExpectAllocFourCores",
@ -288,14 +288,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(4, 5),
"fakeContainer100": cpuset.New(4, 5),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 3, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 3, 6, 7),
pod: makePod("fakePod", "fakeContainer1", "4000m", "4000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(1, 3, 6, 7),
expCSet: cpuset.New(1, 3, 6, 7),
},
{
description: "GuPodMultipleCores, DualSocketHT, ExpectAllocOneSocketOneCore",
@ -303,36 +303,36 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(2),
"fakeContainer100": cpuset.New(2),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11),
pod: makePod("fakePod", "fakeContainer3", "8000m", "8000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(1, 3, 4, 5, 7, 9, 10, 11),
expCSet: cpuset.New(1, 3, 4, 5, 7, 9, 10, 11),
},
{
description: "NonGuPod, SingleSocketHT, NoAlloc",
topo: topoSingleSocketHT,
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer1", "1000m", "2000m"),
expErr: nil,
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
{
description: "GuPodNonIntegerCore, SingleSocketHT, NoAlloc",
topo: topoSingleSocketHT,
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer4", "977m", "977m"),
expErr: nil,
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
{
description: "GuPodMultipleCores, SingleSocketHT, NoAllocExpectError",
@ -340,14 +340,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(1, 2, 3, 4, 5, 6),
"fakeContainer100": cpuset.New(1, 2, 3, 4, 5, 6),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 7),
stDefaultCPUSet: cpuset.New(0, 7),
pod: makePod("fakePod", "fakeContainer5", "2000m", "2000m"),
expErr: fmt.Errorf("not enough cpus available to satisfy request"),
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
{
description: "GuPodMultipleCores, DualSocketHT, NoAllocExpectError",
@ -355,14 +355,14 @@ func TestStaticPolicyAdd(t *testing.T) {
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(1, 2, 3),
"fakeContainer100": cpuset.New(1, 2, 3),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 4, 5, 6, 7, 8, 9, 10, 11),
pod: makePod("fakePod", "fakeContainer5", "10000m", "10000m"),
expErr: fmt.Errorf("not enough cpus available to satisfy request"),
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
{
// All the CPUs from Socket 0 are available. Some CPUs from each
@ -372,10 +372,10 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoQuadSocketFourWayHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(3, 11, 4, 5, 6, 7),
"fakeContainer100": cpuset.New(3, 11, 4, 5, 6, 7),
},
},
stDefaultCPUSet: largeTopoCPUSet.Difference(cpuset.NewCPUSet(3, 11, 4, 5, 6, 7)),
stDefaultCPUSet: largeTopoCPUSet.Difference(cpuset.New(3, 11, 4, 5, 6, 7)),
pod: makePod("fakePod", "fakeContainer5", "72000m", "72000m"),
expErr: nil,
expCPUAlloc: true,
@ -388,15 +388,15 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoQuadSocketFourWayHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": largeTopoCPUSet.Difference(cpuset.NewCPUSet(1, 25, 13, 38, 2, 9, 11, 35, 23, 48, 12, 51,
"fakeContainer100": largeTopoCPUSet.Difference(cpuset.New(1, 25, 13, 38, 2, 9, 11, 35, 23, 48, 12, 51,
53, 173, 113, 233, 54, 61)),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(1, 25, 13, 38, 2, 9, 11, 35, 23, 48, 12, 51, 53, 173, 113, 233, 54, 61),
stDefaultCPUSet: cpuset.New(1, 25, 13, 38, 2, 9, 11, 35, 23, 48, 12, 51, 53, 173, 113, 233, 54, 61),
pod: makePod("fakePod", "fakeCcontainer5", "12000m", "12000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(1, 25, 13, 38, 11, 35, 23, 48, 53, 173, 113, 233),
expCSet: cpuset.New(1, 25, 13, 38, 11, 35, 23, 48, 53, 173, 113, 233),
},
{
// All CPUs from Socket 1, 1 full core and some partial cores are available.
@ -405,16 +405,16 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoQuadSocketFourWayHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": largeTopoCPUSet.Difference(largeTopoSock1CPUSet.Union(cpuset.NewCPUSet(10, 34, 22, 47, 53,
"fakeContainer100": largeTopoCPUSet.Difference(largeTopoSock1CPUSet.Union(cpuset.New(10, 34, 22, 47, 53,
173, 61, 181, 108, 228, 115, 235))),
},
},
stDefaultCPUSet: largeTopoSock1CPUSet.Union(cpuset.NewCPUSet(10, 34, 22, 47, 53, 173, 61, 181, 108, 228,
stDefaultCPUSet: largeTopoSock1CPUSet.Union(cpuset.New(10, 34, 22, 47, 53, 173, 61, 181, 108, 228,
115, 235)),
pod: makePod("fakePod", "fakeContainer5", "76000m", "76000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: largeTopoSock1CPUSet.Union(cpuset.NewCPUSet(10, 34, 22, 47)),
expCSet: largeTopoSock1CPUSet.Union(cpuset.New(10, 34, 22, 47)),
},
{
// Only 7 CPUs are available.
@ -424,14 +424,14 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoQuadSocketFourWayHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": largeTopoCPUSet.Difference(cpuset.NewCPUSet(10, 11, 53, 37, 55, 67, 52)),
"fakeContainer100": largeTopoCPUSet.Difference(cpuset.New(10, 11, 53, 37, 55, 67, 52)),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(10, 11, 53, 37, 55, 67, 52),
stDefaultCPUSet: cpuset.New(10, 11, 53, 37, 55, 67, 52),
pod: makePod("fakePod", "fakeContainer5", "76000m", "76000m"),
expErr: fmt.Errorf("not enough cpus available to satisfy request"),
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
}
@ -442,11 +442,11 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoSingleSocketHT,
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer2", "1000m", "1000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(4), // expect sibling of partial core
expCSet: cpuset.New(4), // expect sibling of partial core
},
{
// Only partial cores are available in the entire system.
@ -455,14 +455,14 @@ func TestStaticPolicyAdd(t *testing.T) {
topo: topoQuadSocketFourWayHT,
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": largeTopoCPUSet.Difference(cpuset.NewCPUSet(10, 11, 53, 37, 55, 67, 52)),
"fakeContainer100": largeTopoCPUSet.Difference(cpuset.New(10, 11, 53, 37, 55, 67, 52)),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(10, 11, 53, 67, 52),
stDefaultCPUSet: cpuset.New(10, 11, 53, 67, 52),
pod: makePod("fakePod", "fakeContainer5", "5000m", "5000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(10, 11, 53, 67, 52),
expCSet: cpuset.New(10, 11, 53, 67, 52),
},
}
@ -476,11 +476,11 @@ func TestStaticPolicyAdd(t *testing.T) {
},
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer2", "1000m", "1000m"),
expErr: SMTAlignmentError{RequestedCPUs: 1, CpusPerCore: 2},
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(), // reject allocation of sibling of partial core
expCSet: cpuset.New(), // reject allocation of sibling of partial core
},
{
// test SMT-level != 2 - which is the default on x86_64
@ -495,7 +495,7 @@ func TestStaticPolicyAdd(t *testing.T) {
pod: makePod("fakePod", "fakeContainer15", "15000m", "15000m"),
expErr: SMTAlignmentError{RequestedCPUs: 15, CpusPerCore: 4},
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
}
newNUMAAffinity := func(bits ...int) bitmask.BitMask {
@ -511,12 +511,12 @@ func TestStaticPolicyAdd(t *testing.T) {
},
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(2, 11, 21, 22),
stDefaultCPUSet: cpuset.New(2, 11, 21, 22),
pod: makePod("fakePod", "fakeContainer2", "2000m", "2000m"),
topologyHint: &topologymanager.TopologyHint{NUMANodeAffinity: newNUMAAffinity(0, 2), Preferred: true},
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(2, 11),
expCSet: cpuset.New(2, 11),
},
{
description: "Align by socket: false, cpu's are taken strictly from NUMA nodes in hint",
@ -526,12 +526,12 @@ func TestStaticPolicyAdd(t *testing.T) {
},
numReservedCPUs: 1,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(2, 11, 21, 22),
stDefaultCPUSet: cpuset.New(2, 11, 21, 22),
pod: makePod("fakePod", "fakeContainer2", "2000m", "2000m"),
topologyHint: &topologymanager.TopologyHint{NUMANodeAffinity: newNUMAAffinity(0, 2), Preferred: true},
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(2, 21),
expCSet: cpuset.New(2, 21),
},
}
@ -565,7 +565,7 @@ func runStaticPolicyTestCase(t *testing.T, testCase staticPolicyTest) {
if testCase.topologyHint != nil {
tm = topologymanager.NewFakeManagerWithHint(testCase.topologyHint)
}
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), tm, testCase.options)
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.New(), tm, testCase.options)
st := &mockState{
assignments: testCase.stAssignments,
@ -628,15 +628,15 @@ func TestStaticPolicyReuseCPUs(t *testing.T) {
{"2000m", "2000m"}}), // 0, 4
containerName: "initContainer-0",
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
},
expCSetAfterAlloc: cpuset.NewCPUSet(2, 3, 6, 7),
expCSetAfterRemove: cpuset.NewCPUSet(1, 2, 3, 5, 6, 7),
expCSetAfterAlloc: cpuset.New(2, 3, 6, 7),
expCSetAfterRemove: cpuset.New(1, 2, 3, 5, 6, 7),
},
}
for _, testCase := range testCases {
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil)
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.New(), topologymanager.NewFakeManager(), nil)
st := &mockState{
assignments: testCase.stAssignments,
@ -676,11 +676,11 @@ func TestStaticPolicyRemove(t *testing.T) {
containerName: "fakeContainer1",
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer1": cpuset.NewCPUSet(1, 2, 3),
"fakeContainer1": cpuset.New(1, 2, 3),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(4, 5, 6, 7),
expCSet: cpuset.NewCPUSet(1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(4, 5, 6, 7),
expCSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
},
{
description: "SingleSocketHT, DeAllocOneContainer, BeginEmpty",
@ -689,12 +689,12 @@ func TestStaticPolicyRemove(t *testing.T) {
containerName: "fakeContainer1",
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer1": cpuset.NewCPUSet(1, 2, 3),
"fakeContainer2": cpuset.NewCPUSet(4, 5, 6, 7),
"fakeContainer1": cpuset.New(1, 2, 3),
"fakeContainer2": cpuset.New(4, 5, 6, 7),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(),
expCSet: cpuset.NewCPUSet(1, 2, 3),
stDefaultCPUSet: cpuset.New(),
expCSet: cpuset.New(1, 2, 3),
},
{
description: "SingleSocketHT, DeAllocTwoContainer",
@ -703,12 +703,12 @@ func TestStaticPolicyRemove(t *testing.T) {
containerName: "fakeContainer1",
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer1": cpuset.NewCPUSet(1, 3, 5),
"fakeContainer2": cpuset.NewCPUSet(2, 4),
"fakeContainer1": cpuset.New(1, 3, 5),
"fakeContainer2": cpuset.New(2, 4),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(6, 7),
expCSet: cpuset.NewCPUSet(1, 3, 5, 6, 7),
stDefaultCPUSet: cpuset.New(6, 7),
expCSet: cpuset.New(1, 3, 5, 6, 7),
},
{
description: "SingleSocketHT, NoDeAlloc",
@ -717,16 +717,16 @@ func TestStaticPolicyRemove(t *testing.T) {
containerName: "fakeContainer2",
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer1": cpuset.NewCPUSet(1, 3, 5),
"fakeContainer1": cpuset.New(1, 3, 5),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(2, 4, 6, 7),
expCSet: cpuset.NewCPUSet(2, 4, 6, 7),
stDefaultCPUSet: cpuset.New(2, 4, 6, 7),
expCSet: cpuset.New(2, 4, 6, 7),
},
}
for _, testCase := range testCases {
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil)
policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.New(), topologymanager.NewFakeManager(), nil)
st := &mockState{
assignments: testCase.stAssignments,
@ -761,62 +761,62 @@ func TestTopologyAwareAllocateCPUs(t *testing.T) {
description: "Request 2 CPUs, No BitMask",
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
numRequested: 2,
socketMask: nil,
expCSet: cpuset.NewCPUSet(0, 6),
expCSet: cpuset.New(0, 6),
},
{
description: "Request 2 CPUs, BitMask on Socket 0",
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
numRequested: 2,
socketMask: func() bitmask.BitMask {
mask, _ := bitmask.NewBitMask(0)
return mask
}(),
expCSet: cpuset.NewCPUSet(0, 6),
expCSet: cpuset.New(0, 6),
},
{
description: "Request 2 CPUs, BitMask on Socket 1",
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
numRequested: 2,
socketMask: func() bitmask.BitMask {
mask, _ := bitmask.NewBitMask(1)
return mask
}(),
expCSet: cpuset.NewCPUSet(1, 7),
expCSet: cpuset.New(1, 7),
},
{
description: "Request 8 CPUs, BitMask on Socket 0",
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
numRequested: 8,
socketMask: func() bitmask.BitMask {
mask, _ := bitmask.NewBitMask(0)
return mask
}(),
expCSet: cpuset.NewCPUSet(0, 6, 2, 8, 4, 10, 1, 7),
expCSet: cpuset.New(0, 6, 2, 8, 4, 10, 1, 7),
},
{
description: "Request 8 CPUs, BitMask on Socket 1",
topo: topoDualSocketHT,
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
numRequested: 8,
socketMask: func() bitmask.BitMask {
mask, _ := bitmask.NewBitMask(1)
return mask
}(),
expCSet: cpuset.NewCPUSet(1, 7, 3, 9, 5, 11, 0, 6),
expCSet: cpuset.New(1, 7, 3, 9, 5, 11, 0, 6),
},
}
for _, tc := range testCases {
p, _ := NewStaticPolicy(tc.topo, 0, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil)
p, _ := NewStaticPolicy(tc.topo, 0, cpuset.New(), topologymanager.NewFakeManager(), nil)
policy := p.(*staticPolicy)
st := &mockState{
assignments: tc.stAssignments,
@ -828,7 +828,7 @@ func TestTopologyAwareAllocateCPUs(t *testing.T) {
continue
}
cset, err := policy.allocateCPUs(st, tc.numRequested, tc.socketMask, cpuset.NewCPUSet())
cset, err := policy.allocateCPUs(st, tc.numRequested, tc.socketMask, cpuset.New())
if err != nil {
t.Errorf("StaticPolicy allocateCPUs() error (%v). expected CPUSet %v not error %v",
tc.description, tc.expCSet, err)
@ -864,27 +864,27 @@ func TestStaticPolicyStartWithResvList(t *testing.T) {
description: "empty cpuset",
topo: topoDualSocketHT,
numReservedCPUs: 2,
reserved: cpuset.NewCPUSet(0, 1),
reserved: cpuset.New(0, 1),
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(),
expCSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(),
expCSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
},
{
description: "reserved cores 0 & 1 are not present in available cpuset",
topo: topoDualSocketHT,
numReservedCPUs: 2,
reserved: cpuset.NewCPUSet(0, 1),
reserved: cpuset.New(0, 1),
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(2, 3, 4, 5),
stDefaultCPUSet: cpuset.New(2, 3, 4, 5),
expErr: fmt.Errorf("not all reserved cpus: \"0-1\" are present in defaultCpuSet: \"2-5\""),
},
{
description: "inconsistency between numReservedCPUs and reserved",
topo: topoDualSocketHT,
numReservedCPUs: 1,
reserved: cpuset.NewCPUSet(0, 1),
reserved: cpuset.New(0, 1),
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expNewErr: fmt.Errorf("[cpumanager] unable to reserve the required amount of CPUs (size of 0-1 did not equal 1)"),
},
}
@ -928,41 +928,41 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
description: "GuPodSingleCore, SingleSocketHT, ExpectError",
topo: topoSingleSocketHT,
numReservedCPUs: 1,
reserved: cpuset.NewCPUSet(0),
reserved: cpuset.New(0),
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer2", "8000m", "8000m"),
expErr: fmt.Errorf("not enough cpus available to satisfy request"),
expCPUAlloc: false,
expCSet: cpuset.NewCPUSet(),
expCSet: cpuset.New(),
},
{
description: "GuPodSingleCore, SingleSocketHT, ExpectAllocOneCPU",
topo: topoSingleSocketHT,
numReservedCPUs: 2,
reserved: cpuset.NewCPUSet(0, 1),
reserved: cpuset.New(0, 1),
stAssignments: state.ContainerCPUAssignments{},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7),
stDefaultCPUSet: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7),
pod: makePod("fakePod", "fakeContainer2", "1000m", "1000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(4), // expect sibling of partial core
expCSet: cpuset.New(4), // expect sibling of partial core
},
{
description: "GuPodMultipleCores, SingleSocketHT, ExpectAllocOneCore",
topo: topoSingleSocketHT,
numReservedCPUs: 2,
reserved: cpuset.NewCPUSet(0, 1),
reserved: cpuset.New(0, 1),
stAssignments: state.ContainerCPUAssignments{
"fakePod": map[string]cpuset.CPUSet{
"fakeContainer100": cpuset.NewCPUSet(2, 3, 6, 7),
"fakeContainer100": cpuset.New(2, 3, 6, 7),
},
},
stDefaultCPUSet: cpuset.NewCPUSet(0, 1, 4, 5),
stDefaultCPUSet: cpuset.New(0, 1, 4, 5),
pod: makePod("fakePod", "fakeContainer3", "2000m", "2000m"),
expErr: nil,
expCPUAlloc: true,
expCSet: cpuset.NewCPUSet(4, 5),
expCSet: cpuset.New(4, 5),
},
}

View file

@ -60,7 +60,7 @@ func TestCheckpointStateRestore(t *testing.T) {
containermap.ContainerMap{},
"",
&stateMemory{
defaultCPUSet: cpuset.NewCPUSet(4, 5, 6),
defaultCPUSet: cpuset.New(4, 5, 6),
},
},
{
@ -82,11 +82,11 @@ func TestCheckpointStateRestore(t *testing.T) {
&stateMemory{
assignments: ContainerCPUAssignments{
"pod": map[string]cpuset.CPUSet{
"container1": cpuset.NewCPUSet(4, 5, 6),
"container2": cpuset.NewCPUSet(1, 2, 3),
"container1": cpuset.New(4, 5, 6),
"container2": cpuset.New(1, 2, 3),
},
},
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3),
defaultCPUSet: cpuset.New(1, 2, 3),
},
},
{
@ -165,7 +165,7 @@ func TestCheckpointStateRestore(t *testing.T) {
containermap.ContainerMap{},
"",
&stateMemory{
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3),
defaultCPUSet: cpuset.New(1, 2, 3),
},
},
{
@ -190,11 +190,11 @@ func TestCheckpointStateRestore(t *testing.T) {
&stateMemory{
assignments: ContainerCPUAssignments{
"pod": map[string]cpuset.CPUSet{
"container1": cpuset.NewCPUSet(4, 5, 6),
"container2": cpuset.NewCPUSet(1, 2, 3),
"container1": cpuset.New(4, 5, 6),
"container2": cpuset.New(1, 2, 3),
},
},
defaultCPUSet: cpuset.NewCPUSet(1, 2, 3),
defaultCPUSet: cpuset.New(1, 2, 3),
},
},
}
@ -242,14 +242,14 @@ func TestCheckpointStateStore(t *testing.T) {
}{
{
"Store default cpu set",
&stateMemory{defaultCPUSet: cpuset.NewCPUSet(1, 2, 3)},
&stateMemory{defaultCPUSet: cpuset.New(1, 2, 3)},
},
{
"Store assignments",
&stateMemory{
assignments: map[string]map[string]cpuset.CPUSet{
"pod": {
"container1": cpuset.NewCPUSet(1, 5, 8),
"container1": cpuset.New(1, 5, 8),
},
},
},
@ -301,29 +301,29 @@ func TestCheckpointStateHelpers(t *testing.T) {
}{
{
description: "One container",
defaultCPUset: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8),
defaultCPUset: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8),
assignments: map[string]map[string]cpuset.CPUSet{
"pod": {
"c1": cpuset.NewCPUSet(0, 1),
"c1": cpuset.New(0, 1),
},
},
},
{
description: "Two containers",
defaultCPUset: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8),
defaultCPUset: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8),
assignments: map[string]map[string]cpuset.CPUSet{
"pod": {
"c1": cpuset.NewCPUSet(0, 1),
"c2": cpuset.NewCPUSet(2, 3, 4, 5),
"c1": cpuset.New(0, 1),
"c2": cpuset.New(2, 3, 4, 5),
},
},
},
{
description: "Container without assigned cpus",
defaultCPUset: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8),
defaultCPUset: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8),
assignments: map[string]map[string]cpuset.CPUSet{
"pod": {
"c1": cpuset.NewCPUSet(),
"c1": cpuset.New(),
},
},
},
@ -377,10 +377,10 @@ func TestCheckpointStateClear(t *testing.T) {
}{
{
"Valid state",
cpuset.NewCPUSet(1, 5, 10),
cpuset.New(1, 5, 10),
map[string]map[string]cpuset.CPUSet{
"pod": {
"container1": cpuset.NewCPUSet(1, 4),
"container1": cpuset.New(1, 4),
},
},
},
@ -404,7 +404,7 @@ func TestCheckpointStateClear(t *testing.T) {
state.SetCPUAssignments(tc.assignments)
state.ClearState()
if !cpuset.NewCPUSet().Equals(state.GetDefaultCPUSet()) {
if !cpuset.New().Equals(state.GetDefaultCPUSet()) {
t.Fatal("cleared state with non-empty default cpu set")
}
for pod := range tc.assignments {

View file

@ -36,7 +36,7 @@ func NewMemoryState() State {
klog.InfoS("Initialized new in-memory state store")
return &stateMemory{
assignments: ContainerCPUAssignments{},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
}
}

View file

@ -26,8 +26,8 @@ import (
func TestClone(t *testing.T) {
expect := ContainerCPUAssignments{
"pod": map[string]cpuset.CPUSet{
"container1": cpuset.NewCPUSet(4, 5, 6),
"container2": cpuset.NewCPUSet(1, 2, 3),
"container1": cpuset.New(4, 5, 6),
"container2": cpuset.New(1, 2, 3),
},
}
actual := expect.Clone()

View file

@ -83,138 +83,138 @@ func (d CPUDetails) KeepOnly(cpus cpuset.CPUSet) CPUDetails {
// NUMANodes returns all of the NUMANode IDs associated with the CPUs in this
// CPUDetails.
func (d CPUDetails) NUMANodes() cpuset.CPUSet {
b := cpuset.NewBuilder()
var numaNodeIDs []int
for _, info := range d {
b.Add(info.NUMANodeID)
numaNodeIDs = append(numaNodeIDs, info.NUMANodeID)
}
return b.Result()
return cpuset.New(numaNodeIDs...)
}
// NUMANodesInSockets returns all of the logical NUMANode IDs associated with
// the given socket IDs in this CPUDetails.
func (d CPUDetails) NUMANodesInSockets(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var numaNodeIDs []int
for _, id := range ids {
for _, info := range d {
if info.SocketID == id {
b.Add(info.NUMANodeID)
numaNodeIDs = append(numaNodeIDs, info.NUMANodeID)
}
}
}
return b.Result()
return cpuset.New(numaNodeIDs...)
}
// Sockets returns all of the socket IDs associated with the CPUs in this
// CPUDetails.
func (d CPUDetails) Sockets() cpuset.CPUSet {
b := cpuset.NewBuilder()
var socketIDs []int
for _, info := range d {
b.Add(info.SocketID)
socketIDs = append(socketIDs, info.SocketID)
}
return b.Result()
return cpuset.New(socketIDs...)
}
// CPUsInSockets returns all of the logical CPU IDs associated with the given
// socket IDs in this CPUDetails.
func (d CPUDetails) CPUsInSockets(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var cpuIDs []int
for _, id := range ids {
for cpu, info := range d {
if info.SocketID == id {
b.Add(cpu)
cpuIDs = append(cpuIDs, cpu)
}
}
}
return b.Result()
return cpuset.New(cpuIDs...)
}
// SocketsInNUMANodes returns all of the logical Socket IDs associated with the
// given NUMANode IDs in this CPUDetails.
func (d CPUDetails) SocketsInNUMANodes(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var socketIDs []int
for _, id := range ids {
for _, info := range d {
if info.NUMANodeID == id {
b.Add(info.SocketID)
socketIDs = append(socketIDs, info.SocketID)
}
}
}
return b.Result()
return cpuset.New(socketIDs...)
}
// Cores returns all of the core IDs associated with the CPUs in this
// CPUDetails.
func (d CPUDetails) Cores() cpuset.CPUSet {
b := cpuset.NewBuilder()
var coreIDs []int
for _, info := range d {
b.Add(info.CoreID)
coreIDs = append(coreIDs, info.CoreID)
}
return b.Result()
return cpuset.New(coreIDs...)
}
// CoresInNUMANodes returns all of the core IDs associated with the given
// NUMANode IDs in this CPUDetails.
func (d CPUDetails) CoresInNUMANodes(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var coreIDs []int
for _, id := range ids {
for _, info := range d {
if info.NUMANodeID == id {
b.Add(info.CoreID)
coreIDs = append(coreIDs, info.CoreID)
}
}
}
return b.Result()
return cpuset.New(coreIDs...)
}
// CoresInSockets returns all of the core IDs associated with the given socket
// IDs in this CPUDetails.
func (d CPUDetails) CoresInSockets(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var coreIDs []int
for _, id := range ids {
for _, info := range d {
if info.SocketID == id {
b.Add(info.CoreID)
coreIDs = append(coreIDs, info.CoreID)
}
}
}
return b.Result()
return cpuset.New(coreIDs...)
}
// CPUs returns all of the logical CPU IDs in this CPUDetails.
func (d CPUDetails) CPUs() cpuset.CPUSet {
b := cpuset.NewBuilder()
var cpuIDs []int
for cpuID := range d {
b.Add(cpuID)
cpuIDs = append(cpuIDs, cpuID)
}
return b.Result()
return cpuset.New(cpuIDs...)
}
// CPUsInNUMANodes returns all of the logical CPU IDs associated with the given
// NUMANode IDs in this CPUDetails.
func (d CPUDetails) CPUsInNUMANodes(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var cpuIDs []int
for _, id := range ids {
for cpu, info := range d {
if info.NUMANodeID == id {
b.Add(cpu)
cpuIDs = append(cpuIDs, cpu)
}
}
}
return b.Result()
return cpuset.New(cpuIDs...)
}
// CPUsInCores returns all of the logical CPU IDs associated with the given
// core IDs in this CPUDetails.
func (d CPUDetails) CPUsInCores(ids ...int) cpuset.CPUSet {
b := cpuset.NewBuilder()
var cpuIDs []int
for _, id := range ids {
for cpu, info := range d {
if info.CoreID == id {
b.Add(cpu)
cpuIDs = append(cpuIDs, cpu)
}
}
}
return b.Result()
return cpuset.New(cpuIDs...)
}
// Discover returns CPUTopology based on cadvisor node info
@ -261,7 +261,7 @@ func getUniqueCoreID(threads []int) (coreID int, err error) {
return 0, fmt.Errorf("no cpus provided")
}
if len(threads) != cpuset.NewCPUSet(threads...).Size() {
if len(threads) != cpuset.New(threads...).Size() {
return 0, fmt.Errorf("cpus provided are not unique")
}

View file

@ -537,14 +537,14 @@ func TestCPUDetailsKeepOnly(t *testing.T) {
want CPUDetails
}{{
name: "cpus is in CPUDetails.",
cpus: cpuset.NewCPUSet(0, 1),
cpus: cpuset.New(0, 1),
want: map[int]CPUInfo{
0: {},
1: {},
},
}, {
name: "cpus is not in CPUDetails.",
cpus: cpuset.NewCPUSet(3),
cpus: cpuset.New(3),
want: CPUDetails{},
}}
@ -572,7 +572,7 @@ func TestCPUDetailsNUMANodes(t *testing.T) {
2: {NUMANodeID: 1},
3: {NUMANodeID: 1},
},
want: cpuset.NewCPUSet(0, 1),
want: cpuset.New(0, 1),
}}
for _, tt := range tests {
@ -613,22 +613,22 @@ func TestCPUDetailsNUMANodesInSockets(t *testing.T) {
name: "Socket IDs is in CPUDetails.",
details: details1,
ids: []int{0, 1, 2},
want: cpuset.NewCPUSet(0, 1),
want: cpuset.New(0, 1),
}, {
name: "Socket IDs is not in CPUDetails.",
details: details1,
ids: []int{4},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}, {
name: "Socket IDs is in CPUDetails. (poorly designed mainboards)",
details: details2,
ids: []int{0},
want: cpuset.NewCPUSet(0, 1),
want: cpuset.New(0, 1),
}, {
name: "Socket IDs is not in CPUDetails. (poorly designed mainboards)",
details: details2,
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {
@ -655,7 +655,7 @@ func TestCPUDetailsSockets(t *testing.T) {
2: {SocketID: 1},
3: {SocketID: 1},
},
want: cpuset.NewCPUSet(0, 1),
want: cpuset.New(0, 1),
}}
for _, tt := range tests {
@ -685,11 +685,11 @@ func TestCPUDetailsCPUsInSockets(t *testing.T) {
}{{
name: "Socket IDs is in CPUDetails.",
ids: []int{0, 1},
want: cpuset.NewCPUSet(0, 1, 2),
want: cpuset.New(0, 1, 2),
}, {
name: "Socket IDs is not in CPUDetails.",
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {
@ -719,11 +719,11 @@ func TestCPUDetailsSocketsInNUMANodes(t *testing.T) {
}{{
name: "NUMANodes IDs is in CPUDetails.",
ids: []int{0, 1},
want: cpuset.NewCPUSet(0, 1, 2),
want: cpuset.New(0, 1, 2),
}, {
name: "NUMANodes IDs is not in CPUDetails.",
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {
@ -750,7 +750,7 @@ func TestCPUDetailsCores(t *testing.T) {
2: {CoreID: 1},
3: {CoreID: 1},
},
want: cpuset.NewCPUSet(0, 1),
want: cpuset.New(0, 1),
}}
for _, tt := range tests {
@ -780,11 +780,11 @@ func TestCPUDetailsCoresInNUMANodes(t *testing.T) {
}{{
name: "NUMANodes IDs is in CPUDetails.",
ids: []int{0, 1},
want: cpuset.NewCPUSet(0, 1, 2),
want: cpuset.New(0, 1, 2),
}, {
name: "NUMANodes IDs is not in CPUDetails.",
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {
@ -814,11 +814,11 @@ func TestCPUDetailsCoresInSockets(t *testing.T) {
}{{
name: "Socket IDs is in CPUDetails.",
ids: []int{0, 1},
want: cpuset.NewCPUSet(0, 1, 2),
want: cpuset.New(0, 1, 2),
}, {
name: "Socket IDs is not in CPUDetails.",
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {
@ -843,7 +843,7 @@ func TestCPUDetailsCPUs(t *testing.T) {
0: {},
1: {},
},
want: cpuset.NewCPUSet(0, 1),
want: cpuset.New(0, 1),
}}
for _, tt := range tests {
@ -873,11 +873,11 @@ func TestCPUDetailsCPUsInNUMANodes(t *testing.T) {
}{{
name: "NUMANode IDs is in CPUDetails.",
ids: []int{0, 1},
want: cpuset.NewCPUSet(0, 1, 2),
want: cpuset.New(0, 1, 2),
}, {
name: "NUMANode IDs is not in CPUDetails.",
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {
@ -907,11 +907,11 @@ func TestCPUDetailsCPUsInCores(t *testing.T) {
}{{
name: "Core IDs is in CPUDetails.",
ids: []int{0, 1},
want: cpuset.NewCPUSet(0, 1, 2),
want: cpuset.New(0, 1, 2),
}, {
name: "Core IDs is not in CPUDetails.",
ids: []int{3},
want: cpuset.NewCPUSet(),
want: cpuset.New(),
}}
for _, tt := range tests {

View file

@ -290,7 +290,7 @@ func TestGetPodTopologyHintsWithPolicyOptions(t *testing.T) {
description: "AlignBySocket:false, Preferred hints does not contains socket aligned hints",
pod: *testPod1,
container: *testContainer1,
defaultCPUSet: cpuset.NewCPUSet(2, 3, 11),
defaultCPUSet: cpuset.New(2, 3, 11),
topology: topoDualSocketMultiNumaPerSocketHT,
policyOptions: map[string]string{AlignBySocketOption: "false"},
expectedHints: []topologymanager.TopologyHint{
@ -333,7 +333,7 @@ func TestGetPodTopologyHintsWithPolicyOptions(t *testing.T) {
description: "AlignBySocket:true Preferred hints contains socket aligned hints",
pod: *testPod1,
container: *testContainer1,
defaultCPUSet: cpuset.NewCPUSet(2, 3, 11),
defaultCPUSet: cpuset.New(2, 3, 11),
topology: topoDualSocketMultiNumaPerSocketHT,
policyOptions: map[string]string{AlignBySocketOption: "true"},
expectedHints: []topologymanager.TopologyHint{
@ -456,7 +456,7 @@ func returnTestCases() []testCase {
name: "Request 2 CPUs, 4 available on NUMA 0, 6 available on NUMA 1",
pod: *testPod1,
container: *testContainer1,
defaultCPUSet: cpuset.NewCPUSet(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
defaultCPUSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: firstSocketMask,
@ -476,7 +476,7 @@ func returnTestCases() []testCase {
name: "Request 5 CPUs, 4 available on NUMA 0, 6 available on NUMA 1",
pod: *testPod2,
container: *testContainer2,
defaultCPUSet: cpuset.NewCPUSet(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
defaultCPUSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: secondSocketMask,
@ -492,7 +492,7 @@ func returnTestCases() []testCase {
name: "Request 7 CPUs, 4 available on NUMA 0, 6 available on NUMA 1",
pod: *testPod3,
container: *testContainer3,
defaultCPUSet: cpuset.NewCPUSet(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
defaultCPUSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: crossSocketMask,
@ -504,14 +504,14 @@ func returnTestCases() []testCase {
name: "Request 11 CPUs, 4 available on NUMA 0, 6 available on NUMA 1",
pod: *testPod4,
container: *testContainer4,
defaultCPUSet: cpuset.NewCPUSet(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
defaultCPUSet: cpuset.New(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
expectedHints: nil,
},
{
name: "Request 2 CPUs, 1 available on NUMA 0, 1 available on NUMA 1",
pod: *testPod1,
container: *testContainer1,
defaultCPUSet: cpuset.NewCPUSet(0, 3),
defaultCPUSet: cpuset.New(0, 3),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: crossSocketMask,
@ -523,7 +523,7 @@ func returnTestCases() []testCase {
name: "Request more CPUs than available",
pod: *testPod2,
container: *testContainer2,
defaultCPUSet: cpuset.NewCPUSet(0, 1, 2, 3),
defaultCPUSet: cpuset.New(0, 1, 2, 3),
expectedHints: nil,
},
{
@ -532,10 +532,10 @@ func returnTestCases() []testCase {
container: *testContainer1,
assignments: state.ContainerCPUAssignments{
string(testPod1.UID): map[string]cpuset.CPUSet{
testContainer1.Name: cpuset.NewCPUSet(0, 6),
testContainer1.Name: cpuset.New(0, 6),
},
},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: firstSocketMask,
@ -553,10 +553,10 @@ func returnTestCases() []testCase {
container: *testContainer1,
assignments: state.ContainerCPUAssignments{
string(testPod1.UID): map[string]cpuset.CPUSet{
testContainer1.Name: cpuset.NewCPUSet(3, 9),
testContainer1.Name: cpuset.New(3, 9),
},
},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: secondSocketMask,
@ -574,10 +574,10 @@ func returnTestCases() []testCase {
container: *testContainer4,
assignments: state.ContainerCPUAssignments{
string(testPod4.UID): map[string]cpuset.CPUSet{
testContainer4.Name: cpuset.NewCPUSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
testContainer4.Name: cpuset.New(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
},
},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
expectedHints: []topologymanager.TopologyHint{
{
NUMANodeAffinity: crossSocketMask,
@ -591,10 +591,10 @@ func returnTestCases() []testCase {
container: *testContainer1,
assignments: state.ContainerCPUAssignments{
string(testPod1.UID): map[string]cpuset.CPUSet{
testContainer1.Name: cpuset.NewCPUSet(0, 6, 3, 9),
testContainer1.Name: cpuset.New(0, 6, 3, 9),
},
},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
expectedHints: []topologymanager.TopologyHint{},
},
{
@ -603,10 +603,10 @@ func returnTestCases() []testCase {
container: *testContainer4,
assignments: state.ContainerCPUAssignments{
string(testPod4.UID): map[string]cpuset.CPUSet{
testContainer4.Name: cpuset.NewCPUSet(0, 6, 3, 9),
testContainer4.Name: cpuset.New(0, 6, 3, 9),
},
},
defaultCPUSet: cpuset.NewCPUSet(),
defaultCPUSet: cpuset.New(),
expectedHints: []topologymanager.TopologyHint{},
},
}

View file

@ -14,75 +14,48 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Package cpuset represents a collection of CPUs in a 'set' data structure.
//
// It can be used to represent core IDs, hyper thread siblings, CPU nodes, or processor IDs.
//
// The only special thing about this package is that
// methods are provided to convert back and forth from Linux 'list' syntax.
// See http://man7.org/linux/man-pages/man7/cpuset.7.html#FORMATS for details.
//
// Future work can migrate this to use a 'set' library, and relax the dubious 'immutable' property.
package cpuset
import (
"bytes"
"fmt"
"os"
"reflect"
"sort"
"strconv"
"strings"
"k8s.io/klog/v2"
)
// Builder is a mutable builder for CPUSet. Functions that mutate instances
// of this type are not thread-safe.
type Builder struct {
result CPUSet
done bool
}
// NewBuilder returns a mutable CPUSet builder.
func NewBuilder() *Builder {
return &Builder{
result: CPUSet{
elems: map[int]struct{}{},
},
}
}
// Add adds the supplied elements to the result. Calling Add after calling
// Result has no effect.
func (b *Builder) Add(elems ...int) {
if b.done {
return
}
for _, elem := range elems {
b.result.elems[elem] = struct{}{}
}
}
// Result returns the result CPUSet containing all elements that were
// previously added to this builder. Subsequent calls to Add have no effect.
func (b *Builder) Result() CPUSet {
b.done = true
return b.result
}
// CPUSet is a thread-safe, immutable set-like data structure for CPU IDs.
type CPUSet struct {
elems map[int]struct{}
}
// NewCPUSet returns a new CPUSet containing the supplied elements.
func NewCPUSet(cpus ...int) CPUSet {
b := NewBuilder()
for _, c := range cpus {
b.Add(c)
// New returns a new CPUSet containing the supplied elements.
func New(cpus ...int) CPUSet {
s := CPUSet{
elems: map[int]struct{}{},
}
return b.Result()
for _, c := range cpus {
s.add(c)
}
return s
}
// NewCPUSetInt64 returns a new CPUSet containing the supplied elements, as slice of int64.
func NewCPUSetInt64(cpus ...int64) CPUSet {
b := NewBuilder()
for _, c := range cpus {
b.Add(int(c))
// add adds the supplied elements to the CPUSet.
// It is intended for internal use only, since it mutates the CPUSet.
func (s CPUSet) add(elems ...int) {
for _, elem := range elems {
s.elems[elem] = struct{}{}
}
return b.Result()
}
// Size returns the number of elements in this set.
@ -107,29 +80,16 @@ func (s CPUSet) Equals(s2 CPUSet) bool {
return reflect.DeepEqual(s.elems, s2.elems)
}
// Filter returns a new CPU set that contains all of the elements from this
// filter returns a new CPU set that contains all of the elements from this
// set that match the supplied predicate, without mutating the source set.
func (s CPUSet) Filter(predicate func(int) bool) CPUSet {
b := NewBuilder()
func (s CPUSet) filter(predicate func(int) bool) CPUSet {
r := New()
for cpu := range s.elems {
if predicate(cpu) {
b.Add(cpu)
r.add(cpu)
}
}
return b.Result()
}
// FilterNot returns a new CPU set that contains all of the elements from this
// set that do not match the supplied predicate, without mutating the source
// set.
func (s CPUSet) FilterNot(predicate func(int) bool) CPUSet {
b := NewBuilder()
for cpu := range s.elems {
if !predicate(cpu) {
b.Add(cpu)
}
}
return b.Result()
return r
}
// IsSubsetOf returns true if the supplied set contains all the elements
@ -145,63 +105,46 @@ func (s CPUSet) IsSubsetOf(s2 CPUSet) bool {
}
// Union returns a new CPU set that contains all of the elements from this
// set and all of the elements from the supplied set, without mutating
// either source set.
func (s CPUSet) Union(s2 CPUSet) CPUSet {
b := NewBuilder()
for cpu := range s.elems {
b.Add(cpu)
}
for cpu := range s2.elems {
b.Add(cpu)
}
return b.Result()
}
// UnionAll returns a new CPU set that contains all of the elements from this
// set and all of the elements from the supplied sets, without mutating
// either source set.
func (s CPUSet) UnionAll(s2 []CPUSet) CPUSet {
b := NewBuilder()
func (s CPUSet) Union(s2 ...CPUSet) CPUSet {
r := New()
for cpu := range s.elems {
b.Add(cpu)
r.add(cpu)
}
for _, cs := range s2 {
for cpu := range cs.elems {
b.Add(cpu)
r.add(cpu)
}
}
return b.Result()
return r
}
// Intersection returns a new CPU set that contains all of the elements
// that are present in both this set and the supplied set, without mutating
// either source set.
func (s CPUSet) Intersection(s2 CPUSet) CPUSet {
return s.Filter(func(cpu int) bool { return s2.Contains(cpu) })
return s.filter(func(cpu int) bool { return s2.Contains(cpu) })
}
// Difference returns a new CPU set that contains all of the elements that
// are present in this set and not the supplied set, without mutating either
// source set.
func (s CPUSet) Difference(s2 CPUSet) CPUSet {
return s.FilterNot(func(cpu int) bool { return s2.Contains(cpu) })
return s.filter(func(cpu int) bool { return !s2.Contains(cpu) })
}
// ToSlice returns a slice of integers that contains all elements from
// this set.
func (s CPUSet) ToSlice() []int {
result := make([]int, 0, len(s.elems))
for cpu := range s.elems {
result = append(result, cpu)
}
// List returns a slice of integers that contains all elements from
// this set. The list is sorted.
func (s CPUSet) List() []int {
result := s.UnsortedList()
sort.Ints(result)
return result
}
// ToSliceNoSort returns a slice of integers that contains all elements from
// UnsortedList returns a slice of integers that contains all elements from
// this set.
func (s CPUSet) ToSliceNoSort() []int {
func (s CPUSet) UnsortedList() []int {
result := make([]int, 0, len(s.elems))
for cpu := range s.elems {
result = append(result, cpu)
@ -209,27 +152,6 @@ func (s CPUSet) ToSliceNoSort() []int {
return result
}
// ToSliceInt64 returns an ordered slice of int64 that contains all elements from
// this set
func (s CPUSet) ToSliceInt64() []int64 {
result := make([]int64, 0, len(s.elems))
for cpu := range s.elems {
result = append(result, int64(cpu))
}
sort.Slice(result, func(i, j int) bool { return result[i] < result[j] })
return result
}
// ToSliceNoSortInt64 returns a slice of int64 that contains all elements from
// this set.
func (s CPUSet) ToSliceNoSortInt64() []int64 {
result := make([]int64, 0, len(s.elems))
for cpu := range s.elems {
result = append(result, int64(cpu))
}
return result
}
// String returns a new string representation of the elements in this CPU set
// in canonical linux CPU list format.
//
@ -239,7 +161,7 @@ func (s CPUSet) String() string {
return ""
}
elems := s.ToSlice()
elems := s.List()
type rng struct {
start int
@ -273,29 +195,17 @@ func (s CPUSet) String() string {
return strings.TrimRight(result.String(), ",")
}
// MustParse CPUSet constructs a new CPU set from a Linux CPU list formatted
// string. Unlike Parse, it does not return an error but rather panics if the
// input cannot be used to construct a CPU set.
func MustParse(s string) CPUSet {
res, err := Parse(s)
if err != nil {
klog.ErrorS(err, "Failed to parse input as CPUSet", "input", s)
os.Exit(1)
}
return res
}
// Parse CPUSet constructs a new CPU set from a Linux CPU list formatted string.
//
// See: http://man7.org/linux/man-pages/man7/cpuset.7.html#FORMATS
func Parse(s string) (CPUSet, error) {
b := NewBuilder()
// Handle empty string.
if s == "" {
return b.Result(), nil
return New(), nil
}
result := New()
// Split CPU list string:
// "0-5,34,46-48" => ["0-5", "34", "46-48"]
ranges := strings.Split(s, ",")
@ -306,39 +216,39 @@ func Parse(s string) (CPUSet, error) {
// Handle ranges that consist of only one element like "34".
elem, err := strconv.Atoi(boundaries[0])
if err != nil {
return NewCPUSet(), err
return New(), err
}
b.Add(elem)
result.add(elem)
} else if len(boundaries) == 2 {
// Handle multi-element ranges like "0-5".
start, err := strconv.Atoi(boundaries[0])
if err != nil {
return NewCPUSet(), err
return New(), err
}
end, err := strconv.Atoi(boundaries[1])
if err != nil {
return NewCPUSet(), err
return New(), err
}
if start > end {
return NewCPUSet(), fmt.Errorf("invalid range %q (%d >= %d)", r, start, end)
return New(), fmt.Errorf("invalid range %q (%d >= %d)", r, start, end)
}
// start == end is acceptable (1-1 -> 1)
// Add all elements to the result.
// e.g. "0-5", "46-48" => [0, 1, 2, 3, 4, 5, 46, 47, 48].
for e := start; e <= end; e++ {
b.Add(e)
result.add(e)
}
}
}
return b.Result(), nil
return result, nil
}
// Clone returns a copy of this CPU set.
func (s CPUSet) Clone() CPUSet {
b := NewBuilder()
r := New()
for elem := range s.elems {
b.Add(elem)
r.add(elem)
}
return b.Result()
return r
}

View file

@ -19,38 +19,16 @@ package cpuset
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func TestCPUSetBuilder(t *testing.T) {
b := NewBuilder()
elems := []int{1, 2, 3, 4, 5}
for _, elem := range elems {
b.Add(elem)
}
result := b.Result()
for _, elem := range elems {
if !result.Contains(elem) {
t.Fatalf("expected cpuset to contain element %d: [%v]", elem, result)
}
}
if len(elems) != result.Size() {
t.Fatalf("expected cpuset %s to have the same size as %v", result, elems)
}
b.Add(6)
require.False(t, result.Contains(6), "expected calls to Add after calling Result() to have no effect")
}
func TestCPUSetSize(t *testing.T) {
testCases := []struct {
cpuset CPUSet
expected int
}{
{NewCPUSet(), 0},
{NewCPUSet(5), 1},
{NewCPUSet(1, 2, 3, 4, 5), 5},
{New(), 0},
{New(5), 1},
{New(1, 2, 3, 4, 5), 5},
}
for _, c := range testCases {
@ -66,9 +44,9 @@ func TestCPUSetIsEmpty(t *testing.T) {
cpuset CPUSet
expected bool
}{
{NewCPUSet(), true},
{NewCPUSet(5), false},
{NewCPUSet(1, 2, 3, 4, 5), false},
{New(), true},
{New(5), false},
{New(1, 2, 3, 4, 5), false},
}
for _, c := range testCases {
@ -85,9 +63,9 @@ func TestCPUSetContains(t *testing.T) {
mustContain []int
mustNotContain []int
}{
{NewCPUSet(), []int{}, []int{1, 2, 3, 4, 5}},
{NewCPUSet(5), []int{5}, []int{1, 2, 3, 4}},
{NewCPUSet(1, 2, 4, 5), []int{1, 2, 4, 5}, []int{0, 3, 6}},
{New(), []int{}, []int{1, 2, 3, 4, 5}},
{New(5), []int{5}, []int{1, 2, 3, 4}},
{New(1, 2, 4, 5), []int{1, 2, 4, 5}, []int{0, 3, 6}},
}
for _, c := range testCases {
@ -109,21 +87,21 @@ func TestCPUSetEqual(t *testing.T) {
s1 CPUSet
s2 CPUSet
}{
{NewCPUSet(), NewCPUSet()},
{NewCPUSet(5), NewCPUSet(5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{New(), New()},
{New(5), New(5)},
{New(1, 2, 3, 4, 5), New(1, 2, 3, 4, 5)},
}
shouldNotEqual := []struct {
s1 CPUSet
s2 CPUSet
}{
{NewCPUSet(), NewCPUSet(5)},
{NewCPUSet(5), NewCPUSet()},
{NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet()},
{NewCPUSet(5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(5)},
{New(), New(5)},
{New(5), New()},
{New(), New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), New()},
{New(5), New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), New(5)},
}
for _, c := range shouldEqual {
@ -144,18 +122,18 @@ func TestCPUSetIsSubsetOf(t *testing.T) {
s2 CPUSet
}{
// A set is a subset of itself
{NewCPUSet(), NewCPUSet()},
{NewCPUSet(5), NewCPUSet(5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{New(), New()},
{New(5), New(5)},
{New(1, 2, 3, 4, 5), New(1, 2, 3, 4, 5)},
// Empty set is a subset of every set
{NewCPUSet(), NewCPUSet(5)},
{NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5)},
{New(), New(5)},
{New(), New(1, 2, 3, 4, 5)},
{NewCPUSet(5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(2, 3), NewCPUSet(1, 2, 3, 4, 5)},
{New(5), New(1, 2, 3, 4, 5)},
{New(1, 2, 3), New(1, 2, 3, 4, 5)},
{New(4, 5), New(1, 2, 3, 4, 5)},
{New(2, 3), New(1, 2, 3, 4, 5)},
}
shouldNotBeSubset := []struct {
@ -175,55 +153,39 @@ func TestCPUSetIsSubsetOf(t *testing.T) {
}
}
func TestCPUSetUnionAll(t *testing.T) {
testCases := []struct {
s1 CPUSet
s2 CPUSet
s3 CPUSet
expected CPUSet
}{
{NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(), NewCPUSet(4), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 5), NewCPUSet(1, 2, 3, 4, 5)},
}
for _, c := range testCases {
s := []CPUSet{}
s = append(s, c.s2)
s = append(s, c.s3)
result := c.s1.UnionAll(s)
if !result.Equals(c.expected) {
t.Fatalf("expected the union of s1 and s2 to be [%v] (got [%v]), s1: [%v], s2: [%v]", c.expected, result, c.s1, c.s2)
}
}
}
func TestCPUSetUnion(t *testing.T) {
testCases := []struct {
s1 CPUSet
s2 CPUSet
others []CPUSet
expected CPUSet
}{
{NewCPUSet(), NewCPUSet(), NewCPUSet()},
{New(5), []CPUSet{}, New(5)},
{NewCPUSet(), NewCPUSet(5), NewCPUSet(5)},
{NewCPUSet(5), NewCPUSet(), NewCPUSet(5)},
{NewCPUSet(5), NewCPUSet(5), NewCPUSet(5)},
{New(), []CPUSet{New()}, New()},
{NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{New(), []CPUSet{New(5)}, New(5)},
{New(5), []CPUSet{New()}, New(5)},
{New(5), []CPUSet{New(5)}, New(5)},
{NewCPUSet(5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(5), NewCPUSet(1, 2, 3, 4, 5)},
{New(), []CPUSet{New(1, 2, 3, 4, 5)}, New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), []CPUSet{New()}, New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), []CPUSet{New(1, 2, 3, 4, 5)}, New(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2), NewCPUSet(3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3), NewCPUSet(3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{New(5), []CPUSet{New(1, 2, 3, 4, 5)}, New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), []CPUSet{New(5)}, New(1, 2, 3, 4, 5)},
{New(1, 2), []CPUSet{New(3, 4, 5)}, New(1, 2, 3, 4, 5)},
{New(1, 2, 3), []CPUSet{New(3, 4, 5)}, New(1, 2, 3, 4, 5)},
{New(), []CPUSet{New(1, 2, 3, 4, 5), New(4, 5)}, New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), []CPUSet{New(), New(4)}, New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), []CPUSet{New(1, 2, 3, 4, 5), New(1, 5)}, New(1, 2, 3, 4, 5)},
}
for _, c := range testCases {
result := c.s1.Union(c.s2)
result := c.s1.Union(c.others...)
if !result.Equals(c.expected) {
t.Fatalf("expected the union of s1 and s2 to be [%v] (got [%v]), s1: [%v], s2: [%v]", c.expected, result, c.s1, c.s2)
t.Fatalf("expected the union of s1 and s2 to be [%v] (got [%v]), others: [%v]", c.expected, result, c.others)
}
}
}
@ -234,21 +196,21 @@ func TestCPUSetIntersection(t *testing.T) {
s2 CPUSet
expected CPUSet
}{
{NewCPUSet(), NewCPUSet(), NewCPUSet()},
{New(), New(), New()},
{NewCPUSet(), NewCPUSet(5), NewCPUSet()},
{NewCPUSet(5), NewCPUSet(), NewCPUSet()},
{NewCPUSet(5), NewCPUSet(5), NewCPUSet(5)},
{New(), New(5), New()},
{New(5), New(), New()},
{New(5), New(5), New(5)},
{NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet()},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(), NewCPUSet()},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5)},
{New(), New(1, 2, 3, 4, 5), New()},
{New(1, 2, 3, 4, 5), New(), New()},
{New(1, 2, 3, 4, 5), New(1, 2, 3, 4, 5), New(1, 2, 3, 4, 5)},
{NewCPUSet(5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(5), NewCPUSet(5)},
{New(5), New(1, 2, 3, 4, 5), New(5)},
{New(1, 2, 3, 4, 5), New(5), New(5)},
{NewCPUSet(1, 2), NewCPUSet(3, 4, 5), NewCPUSet()},
{NewCPUSet(1, 2, 3), NewCPUSet(3, 4, 5), NewCPUSet(3)},
{New(1, 2), New(3, 4, 5), New()},
{New(1, 2, 3), New(3, 4, 5), New(3)},
}
for _, c := range testCases {
@ -265,21 +227,21 @@ func TestCPUSetDifference(t *testing.T) {
s2 CPUSet
expected CPUSet
}{
{NewCPUSet(), NewCPUSet(), NewCPUSet()},
{New(), New(), New()},
{NewCPUSet(), NewCPUSet(5), NewCPUSet()},
{NewCPUSet(5), NewCPUSet(), NewCPUSet(5)},
{NewCPUSet(5), NewCPUSet(5), NewCPUSet()},
{New(), New(5), New()},
{New(5), New(), New(5)},
{New(5), New(5), New()},
{NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet()},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(), NewCPUSet(1, 2, 3, 4, 5)},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet()},
{New(), New(1, 2, 3, 4, 5), New()},
{New(1, 2, 3, 4, 5), New(), New(1, 2, 3, 4, 5)},
{New(1, 2, 3, 4, 5), New(1, 2, 3, 4, 5), New()},
{NewCPUSet(5), NewCPUSet(1, 2, 3, 4, 5), NewCPUSet()},
{NewCPUSet(1, 2, 3, 4, 5), NewCPUSet(5), NewCPUSet(1, 2, 3, 4)},
{New(5), New(1, 2, 3, 4, 5), New()},
{New(1, 2, 3, 4, 5), New(5), New(1, 2, 3, 4)},
{NewCPUSet(1, 2), NewCPUSet(3, 4, 5), NewCPUSet(1, 2)},
{NewCPUSet(1, 2, 3), NewCPUSet(3, 4, 5), NewCPUSet(1, 2)},
{New(1, 2), New(3, 4, 5), New(1, 2)},
{New(1, 2, 3), New(3, 4, 5), New(1, 2)},
}
for _, c := range testCases {
@ -290,18 +252,18 @@ func TestCPUSetDifference(t *testing.T) {
}
}
func TestCPUSetToSlice(t *testing.T) {
func TestCPUSetList(t *testing.T) {
testCases := []struct {
set CPUSet
expected []int
}{
{NewCPUSet(), []int{}},
{NewCPUSet(5), []int{5}},
{NewCPUSet(1, 2, 3, 4, 5), []int{1, 2, 3, 4, 5}},
{New(), []int{}},
{New(5), []int{5}},
{New(1, 2, 3, 4, 5), []int{1, 2, 3, 4, 5}},
}
for _, c := range testCases {
result := c.set.ToSlice()
result := c.set.List()
if !reflect.DeepEqual(result, c.expected) {
t.Fatalf("expected set as slice to be [%v] (got [%v]), s: [%v]", c.expected, result, c.set)
}
@ -313,10 +275,10 @@ func TestCPUSetString(t *testing.T) {
set CPUSet
expected string
}{
{NewCPUSet(), ""},
{NewCPUSet(5), "5"},
{NewCPUSet(1, 2, 3, 4, 5), "1-5"},
{NewCPUSet(1, 2, 3, 5, 6, 8), "1-3,5-6,8"},
{New(), ""},
{New(5), "5"},
{New(1, 2, 3, 4, 5), "1-5"},
{New(1, 2, 3, 5, 6, 8), "1-3,5-6,8"},
}
for _, c := range testCases {
@ -332,14 +294,14 @@ func TestParse(t *testing.T) {
cpusetString string
expected CPUSet
}{
{"", NewCPUSet()},
{"5", NewCPUSet(5)},
{"1,2,3,4,5", NewCPUSet(1, 2, 3, 4, 5)},
{"1-5", NewCPUSet(1, 2, 3, 4, 5)},
{"1-2,3-5", NewCPUSet(1, 2, 3, 4, 5)},
{"5,4,3,2,1", NewCPUSet(1, 2, 3, 4, 5)}, // Range ordering
{"3-6,1-5", NewCPUSet(1, 2, 3, 4, 5, 6)}, // Overlapping ranges
{"3-3,5-5", NewCPUSet(3, 5)}, // Very short ranges
{"", New()},
{"5", New(5)},
{"1,2,3,4,5", New(1, 2, 3, 4, 5)},
{"1-5", New(1, 2, 3, 4, 5)},
{"1-2,3-5", New(1, 2, 3, 4, 5)},
{"5,4,3,2,1", New(1, 2, 3, 4, 5)}, // Range ordering
{"3-6,1-5", New(1, 2, 3, 4, 5, 6)}, // Overlapping ranges
{"3-3,5-5", New(3, 5)}, // Very short ranges
}
for _, c := range positiveTestCases {

View file

@ -79,7 +79,7 @@ var _ = SIGDescribe("CPU Manager Metrics [Serial][Feature:CPUManager]", func() {
newCfg := configureCPUManagerInKubelet(oldCfg,
&cpuManagerKubeletArguments{
policyName: string(cpumanager.PolicyStatic),
reservedSystemCPUs: cpuset.NewCPUSet(0),
reservedSystemCPUs: cpuset.New(0),
enableCPUManagerOptions: true,
options: cpuPolicyOptions,
},

View file

@ -280,6 +280,12 @@ func runNonGuPodTest(ctx context.Context, f *framework.Framework, cpuCap int64)
waitForContainerRemoval(ctx, pod.Spec.Containers[0].Name, pod.Name, pod.Namespace)
}
func mustParseCPUSet(s string) cpuset.CPUSet {
res, err := cpuset.Parse(s)
framework.ExpectNoError(err)
return res
}
func runMultipleGuNonGuPods(ctx context.Context, f *framework.Framework, cpuCap int64, cpuAlloc int64) {
var cpuListString, expAllowedCPUsListRegex string
var cpuList []int
@ -312,10 +318,10 @@ func runMultipleGuNonGuPods(ctx context.Context, f *framework.Framework, cpuCap
ginkgo.By("checking if the expected cpuset was assigned")
cpu1 = 1
if isHTEnabled() {
cpuList = cpuset.MustParse(getCPUSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCPUSiblingList(0)).List()
cpu1 = cpuList[1]
} else if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 1 {
cpu1 = cpuList[1]
}
@ -327,8 +333,8 @@ func runMultipleGuNonGuPods(ctx context.Context, f *framework.Framework, cpuCap
cpuListString = "0"
if cpuAlloc > 2 {
cset = cpuset.MustParse(fmt.Sprintf("0-%d", cpuCap-1))
cpuListString = fmt.Sprintf("%s", cset.Difference(cpuset.NewCPUSet(cpu1)))
cset = mustParseCPUSet(fmt.Sprintf("0-%d", cpuCap-1))
cpuListString = fmt.Sprintf("%s", cset.Difference(cpuset.New(cpu1)))
}
expAllowedCPUsListRegex = fmt.Sprintf("^%s\n$", cpuListString)
err = e2epod.NewPodClient(f).MatchContainerOutput(ctx, pod2.Name, pod2.Spec.Containers[0].Name, expAllowedCPUsListRegex)
@ -361,19 +367,19 @@ func runMultipleCPUGuPod(ctx context.Context, f *framework.Framework) {
ginkgo.By("checking if the expected cpuset was assigned")
cpuListString = "1-2"
if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 1 {
cset = cpuset.MustParse(getCPUSiblingList(int64(cpuList[1])))
cset = mustParseCPUSet(getCPUSiblingList(int64(cpuList[1])))
if !isHTEnabled() && len(cpuList) > 2 {
cset = cpuset.MustParse(fmt.Sprintf("%d-%d", cpuList[1], cpuList[2]))
cset = mustParseCPUSet(fmt.Sprintf("%d-%d", cpuList[1], cpuList[2]))
}
cpuListString = fmt.Sprintf("%s", cset)
}
} else if isHTEnabled() {
cpuListString = "2-3"
cpuList = cpuset.MustParse(getCPUSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCPUSiblingList(0)).List()
if cpuList[1] != 1 {
cset = cpuset.MustParse(getCPUSiblingList(1))
cset = mustParseCPUSet(getCPUSiblingList(1))
cpuListString = fmt.Sprintf("%s", cset)
}
}
@ -412,18 +418,18 @@ func runMultipleCPUContainersGuPod(ctx context.Context, f *framework.Framework)
ginkgo.By("checking if the expected cpuset was assigned")
cpu1, cpu2 = 1, 2
if isHTEnabled() {
cpuList = cpuset.MustParse(getCPUSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCPUSiblingList(0)).List()
if cpuList[1] != 1 {
cpu1, cpu2 = cpuList[1], 1
}
if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 1 {
cpu2 = cpuList[1]
}
}
} else if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 2 {
cpu1, cpu2 = cpuList[1], cpuList[2]
}
@ -474,18 +480,18 @@ func runMultipleGuPods(ctx context.Context, f *framework.Framework) {
ginkgo.By("checking if the expected cpuset was assigned")
cpu1, cpu2 = 1, 2
if isHTEnabled() {
cpuList = cpuset.MustParse(getCPUSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCPUSiblingList(0)).List()
if cpuList[1] != 1 {
cpu1, cpu2 = cpuList[1], 1
}
if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 1 {
cpu2 = cpuList[1]
}
}
} else if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 2 {
cpu1, cpu2 = cpuList[1], cpuList[2]
}
@ -582,10 +588,10 @@ func runCPUManagerTests(f *framework.Framework) {
ginkgo.By("checking if the expected cpuset was assigned")
cpu1 = 1
if isHTEnabled() {
cpuList = cpuset.MustParse(getCPUSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCPUSiblingList(0)).List()
cpu1 = cpuList[1]
} else if isMultiNUMA() {
cpuList = cpuset.MustParse(getCoreSiblingList(0)).ToSlice()
cpuList = mustParseCPUSet(getCoreSiblingList(0)).List()
if len(cpuList) > 1 {
cpu1 = cpuList[1]
}
@ -627,7 +633,7 @@ func runCPUManagerTests(f *framework.Framework) {
newCfg := configureCPUManagerInKubelet(oldCfg,
&cpuManagerKubeletArguments{
policyName: string(cpumanager.PolicyStatic),
reservedSystemCPUs: cpuset.NewCPUSet(0),
reservedSystemCPUs: cpuset.New(0),
enableCPUManagerOptions: true,
options: cpuPolicyOptions,
},
@ -727,13 +733,12 @@ func validateSMTAlignment(cpus cpuset.CPUSet, smtLevel int, pod *v1.Pod, cnt *v1
// now check all the given cpus are thread siblings.
// to do so the easiest way is to rebuild the expected set of siblings from all the cpus we got.
// if the expected set matches the given set, the given set was good.
b := cpuset.NewBuilder()
for _, cpuID := range cpus.ToSliceNoSort() {
siblingsCPUs := cpuset.New()
for _, cpuID := range cpus.UnsortedList() {
threadSiblings, err := cpuset.Parse(strings.TrimSpace(getCPUSiblingList(int64(cpuID))))
framework.ExpectNoError(err, "parsing cpuset from logs for [%s] of pod [%s]", cnt.Name, pod.Name)
b.Add(threadSiblings.ToSliceNoSort()...)
siblingsCPUs = siblingsCPUs.Union(threadSiblings)
}
siblingsCPUs := b.Result()
framework.Logf("siblings cpus: %v", siblingsCPUs)
if !siblingsCPUs.Equals(cpus) {

View file

@ -280,7 +280,7 @@ var _ = SIGDescribe("Memory Manager [Disruptive] [Serial] [Feature:MemoryManager
currentNUMANodeIDs, err := cpuset.Parse(strings.Trim(output, "\n"))
framework.ExpectNoError(err)
framework.ExpectEqual(numaNodeIDs, currentNUMANodeIDs.ToSlice())
framework.ExpectEqual(numaNodeIDs, currentNUMANodeIDs.List())
}
waitingForHugepages := func(ctx context.Context, hugepagesCount int) {

View file

@ -86,7 +86,7 @@ func getCPUsPerNUMANode(nodeNum int) ([]int, error) {
if err != nil {
return nil, err
}
return cpus.ToSlice(), nil
return cpus.List(), nil
}
func getCPUToNUMANodeMapFromEnv(f *framework.Framework, pod *v1.Pod, cnt *v1.Container, environ map[string]string, numaNodes int) (map[int]int, error) {
@ -99,7 +99,7 @@ func getCPUToNUMANodeMapFromEnv(f *framework.Framework, pod *v1.Pod, cnt *v1.Con
if err != nil {
return nil, err
}
cpuIDs = cpus.ToSlice()
cpuIDs = cpus.List()
}
}
if len(cpuIDs) == 0 {
@ -115,7 +115,7 @@ func getCPUToNUMANodeMapFromEnv(f *framework.Framework, pod *v1.Pod, cnt *v1.Con
if err != nil {
return nil, err
}
cpusPerNUMA[numaNode] = cpus.ToSlice()
cpusPerNUMA[numaNode] = cpus.List()
}
// CPU IDs -> NUMA Node ID

View file

@ -522,7 +522,11 @@ func podresourcesGetAllocatableResourcesTests(ctx context.Context, cli kubeletpo
resp, err := cli.GetAllocatableResources(ctx, &kubeletpodresourcesv1.AllocatableResourcesRequest{})
framework.ExpectNoErrorWithOffset(1, err)
devs := resp.GetDevices()
allocatableCPUs := cpuset.NewCPUSetInt64(resp.GetCpuIds()...)
var cpus []int
for _, cpuid := range resp.GetCpuIds() {
cpus = append(cpus, int(cpuid))
}
allocatableCPUs := cpuset.New(cpus...)
if onlineCPUs.Size() == 0 {
ginkgo.By("expecting no CPUs reported")
@ -557,7 +561,7 @@ var _ = SIGDescribe("POD Resources [Serial] [Feature:PodResources][NodeFeature:P
f := framework.NewDefaultFramework("podresources-test")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
reservedSystemCPUs := cpuset.MustParse("1")
reservedSystemCPUs := cpuset.New(1)
ginkgo.Context("with SRIOV devices in the system", func() {
ginkgo.BeforeEach(func() {