Skip to content

Commit b276043

Browse files
authored
Merge pull request kubernetes#77421 from tedyu/cpu-free-no-sort
Obtain unsorted slice in cpuAccumulator#freeCores
2 parents 109d61f + f83bac6 commit b276043

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/kubelet/cm/cpumanager/cpu_assignment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (a *cpuAccumulator) freeSockets() []int {
6969
// - socket ID, ascending
7070
// - core ID, ascending
7171
func (a *cpuAccumulator) freeCores() []int {
72-
socketIDs := a.details.Sockets().ToSlice()
72+
socketIDs := a.details.Sockets().ToSliceNoSort()
7373
sort.Slice(socketIDs,
7474
func(i, j int) bool {
7575
iCores := a.details.CoresInSocket(socketIDs[i]).Filter(a.isCoreFree)

pkg/kubelet/cm/cpuset/cpuset.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ func (s CPUSet) ToSlice() []int {
188188
return result
189189
}
190190

191+
// ToSliceNoSort returns a slice of integers that contains all elements from
192+
// this set.
193+
func (s CPUSet) ToSliceNoSort() []int {
194+
result := []int{}
195+
for cpu := range s.elems {
196+
result = append(result, cpu)
197+
}
198+
return result
199+
}
200+
191201
// String returns a new string representation of the elements in this CPU set
192202
// in canonical linux CPU list format.
193203
//

0 commit comments

Comments
 (0)