mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #77422 from tedyu/policy-set-union
Union all CPUSets in one round
This commit is contained in:
commit
b4211dea98
@ -154,9 +154,11 @@ func (p *staticPolicy) validateState(s state.State) error {
|
|||||||
// topology that was received during CPU manager startup matches with
|
// topology that was received during CPU manager startup matches with
|
||||||
// the set of CPUs stored in the state.
|
// the set of CPUs stored in the state.
|
||||||
totalKnownCPUs := tmpDefaultCPUset.Clone()
|
totalKnownCPUs := tmpDefaultCPUset.Clone()
|
||||||
|
tmpCPUSets := []cpuset.CPUSet{}
|
||||||
for _, cset := range tmpAssignments {
|
for _, cset := range tmpAssignments {
|
||||||
totalKnownCPUs = totalKnownCPUs.Union(cset)
|
tmpCPUSets = append(tmpCPUSets, cset)
|
||||||
}
|
}
|
||||||
|
totalKnownCPUs = totalKnownCPUs.UnionAll(tmpCPUSets)
|
||||||
if !totalKnownCPUs.Equals(p.topology.CPUDetails.CPUs()) {
|
if !totalKnownCPUs.Equals(p.topology.CPUDetails.CPUs()) {
|
||||||
return fmt.Errorf("current set of available CPUs \"%s\" doesn't match with CPUs in state \"%s\"",
|
return fmt.Errorf("current set of available CPUs \"%s\" doesn't match with CPUs in state \"%s\"",
|
||||||
p.topology.CPUDetails.CPUs().String(), totalKnownCPUs.String())
|
p.topology.CPUDetails.CPUs().String(), totalKnownCPUs.String())
|
||||||
|
@ -147,6 +147,22 @@ func (s CPUSet) Union(s2 CPUSet) CPUSet {
|
|||||||
return b.Result()
|
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()
|
||||||
|
for cpu := range s.elems {
|
||||||
|
b.Add(cpu)
|
||||||
|
}
|
||||||
|
for _, cs := range s2 {
|
||||||
|
for cpu := range cs.elems {
|
||||||
|
b.Add(cpu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b.Result()
|
||||||
|
}
|
||||||
|
|
||||||
// Intersection returns a new CPU set that contains all of the elements
|
// 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
|
// that are present in both this set and the supplied set, without mutating
|
||||||
// either source set.
|
// either source set.
|
||||||
|
Loading…
Reference in New Issue
Block a user