Skip to content

Commit e967c37

Browse files
tedyuyutedz
authored andcommitted
Union all CPUSets in one round
1 parent 1608578 commit e967c37

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/kubelet/cm/cpumanager/policy_static.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@ func (p *staticPolicy) validateState(s state.State) error {
154154
// topology that was received during CPU manager startup matches with
155155
// the set of CPUs stored in the state.
156156
totalKnownCPUs := tmpDefaultCPUset.Clone()
157+
tmpCPUSets := []cpuset.CPUSet{}
157158
for _, cset := range tmpAssignments {
158-
totalKnownCPUs = totalKnownCPUs.Union(cset)
159+
tmpCPUSets = append(tmpCPUSets, cset)
159160
}
161+
totalKnownCPUs = totalKnownCPUs.UnionAll(tmpCPUSets)
160162
if !totalKnownCPUs.Equals(p.topology.CPUDetails.CPUs()) {
161163
return fmt.Errorf("current set of available CPUs \"%s\" doesn't match with CPUs in state \"%s\"",
162164
p.topology.CPUDetails.CPUs().String(), totalKnownCPUs.String())

pkg/kubelet/cm/cpuset/cpuset.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ func (s CPUSet) Union(s2 CPUSet) CPUSet {
147147
return b.Result()
148148
}
149149

150+
// UnionAll returns a new CPU set that contains all of the elements from this
151+
// set and all of the elements from the supplied sets, without mutating
152+
// either source set.
153+
func (s CPUSet) UnionAll(s2 []CPUSet) CPUSet {
154+
b := NewBuilder()
155+
for cpu := range s.elems {
156+
b.Add(cpu)
157+
}
158+
for _, cs := range s2 {
159+
for cpu := range cs.elems {
160+
b.Add(cpu)
161+
}
162+
}
163+
return b.Result()
164+
}
165+
150166
// Intersection returns a new CPU set that contains all of the elements
151167
// that are present in both this set and the supplied set, without mutating
152168
// either source set.

0 commit comments

Comments
 (0)