mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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
|
||||
// the set of CPUs stored in the state.
|
||||
totalKnownCPUs := tmpDefaultCPUset.Clone()
|
||||
tmpCPUSets := []cpuset.CPUSet{}
|
||||
for _, cset := range tmpAssignments {
|
||||
totalKnownCPUs = totalKnownCPUs.Union(cset)
|
||||
tmpCPUSets = append(tmpCPUSets, cset)
|
||||
}
|
||||
totalKnownCPUs = totalKnownCPUs.UnionAll(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())
|
||||
|
@ -147,6 +147,22 @@ func (s CPUSet) Union(s2 CPUSet) CPUSet {
|
||||
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
|
||||
// that are present in both this set and the supplied set, without mutating
|
||||
// either source set.
|
||||
|
Loading…
Reference in New Issue
Block a user