mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Update CPUManager topology helpers to accept multiple ids
This commit is contained in:
parent
dcc9f66311
commit
e0e8b3e4fd
@ -50,12 +50,12 @@ func (a *cpuAccumulator) take(cpus cpuset.CPUSet) {
|
||||
|
||||
// Returns true if the supplied socket is fully available in `topoDetails`.
|
||||
func (a *cpuAccumulator) isSocketFree(socketID int) bool {
|
||||
return a.details.CPUsInSocket(socketID).Size() == a.topo.CPUsPerSocket()
|
||||
return a.details.CPUsInSockets(socketID).Size() == a.topo.CPUsPerSocket()
|
||||
}
|
||||
|
||||
// Returns true if the supplied core is fully available in `topoDetails`.
|
||||
func (a *cpuAccumulator) isCoreFree(coreID int) bool {
|
||||
return a.details.CPUsInCore(coreID).Size() == a.topo.CPUsPerCore()
|
||||
return a.details.CPUsInCores(coreID).Size() == a.topo.CPUsPerCore()
|
||||
}
|
||||
|
||||
// Returns free socket IDs as a slice sorted by:
|
||||
@ -72,14 +72,14 @@ func (a *cpuAccumulator) freeCores() []int {
|
||||
socketIDs := a.details.Sockets().ToSliceNoSort()
|
||||
sort.Slice(socketIDs,
|
||||
func(i, j int) bool {
|
||||
iCores := a.details.CoresInSocket(socketIDs[i]).Filter(a.isCoreFree)
|
||||
jCores := a.details.CoresInSocket(socketIDs[j]).Filter(a.isCoreFree)
|
||||
iCores := a.details.CoresInSockets(socketIDs[i]).Filter(a.isCoreFree)
|
||||
jCores := a.details.CoresInSockets(socketIDs[j]).Filter(a.isCoreFree)
|
||||
return iCores.Size() < jCores.Size() || socketIDs[i] < socketIDs[j]
|
||||
})
|
||||
|
||||
coreIDs := []int{}
|
||||
for _, s := range socketIDs {
|
||||
coreIDs = append(coreIDs, a.details.CoresInSocket(s).Filter(a.isCoreFree).ToSlice()...)
|
||||
coreIDs = append(coreIDs, a.details.CoresInSockets(s).Filter(a.isCoreFree).ToSlice()...)
|
||||
}
|
||||
return coreIDs
|
||||
}
|
||||
@ -100,25 +100,25 @@ func (a *cpuAccumulator) freeCPUs() []int {
|
||||
iCore := cores[i]
|
||||
jCore := cores[j]
|
||||
|
||||
iCPUs := a.topo.CPUDetails.CPUsInCore(iCore).ToSlice()
|
||||
jCPUs := a.topo.CPUDetails.CPUsInCore(jCore).ToSlice()
|
||||
iCPUs := a.topo.CPUDetails.CPUsInCores(iCore).ToSlice()
|
||||
jCPUs := a.topo.CPUDetails.CPUsInCores(jCore).ToSlice()
|
||||
|
||||
iSocket := a.topo.CPUDetails[iCPUs[0]].SocketID
|
||||
jSocket := a.topo.CPUDetails[jCPUs[0]].SocketID
|
||||
|
||||
// Compute the number of CPUs in the result reside on the same socket
|
||||
// as each core.
|
||||
iSocketColoScore := a.topo.CPUDetails.CPUsInSocket(iSocket).Intersection(a.result).Size()
|
||||
jSocketColoScore := a.topo.CPUDetails.CPUsInSocket(jSocket).Intersection(a.result).Size()
|
||||
iSocketColoScore := a.topo.CPUDetails.CPUsInSockets(iSocket).Intersection(a.result).Size()
|
||||
jSocketColoScore := a.topo.CPUDetails.CPUsInSockets(jSocket).Intersection(a.result).Size()
|
||||
|
||||
// Compute the number of available CPUs available on the same socket
|
||||
// as each core.
|
||||
iSocketFreeScore := a.details.CPUsInSocket(iSocket).Size()
|
||||
jSocketFreeScore := a.details.CPUsInSocket(jSocket).Size()
|
||||
iSocketFreeScore := a.details.CPUsInSockets(iSocket).Size()
|
||||
jSocketFreeScore := a.details.CPUsInSockets(jSocket).Size()
|
||||
|
||||
// Compute the number of available CPUs on each core.
|
||||
iCoreFreeScore := a.details.CPUsInCore(iCore).Size()
|
||||
jCoreFreeScore := a.details.CPUsInCore(jCore).Size()
|
||||
iCoreFreeScore := a.details.CPUsInCores(iCore).Size()
|
||||
jCoreFreeScore := a.details.CPUsInCores(jCore).Size()
|
||||
|
||||
return iSocketColoScore > jSocketColoScore ||
|
||||
iSocketFreeScore < jSocketFreeScore ||
|
||||
@ -129,7 +129,7 @@ func (a *cpuAccumulator) freeCPUs() []int {
|
||||
|
||||
// For each core, append sorted CPU IDs to result.
|
||||
for _, core := range cores {
|
||||
result = append(result, a.details.CPUsInCore(core).ToSlice()...)
|
||||
result = append(result, a.details.CPUsInCores(core).ToSlice()...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@ -161,7 +161,7 @@ func takeByTopology(topo *topology.CPUTopology, availableCPUs cpuset.CPUSet, num
|
||||
if acc.needs(acc.topo.CPUsPerSocket()) {
|
||||
for _, s := range acc.freeSockets() {
|
||||
klog.V(4).Infof("[cpumanager] takeByTopology: claiming socket [%d]", s)
|
||||
acc.take(acc.details.CPUsInSocket(s))
|
||||
acc.take(acc.details.CPUsInSockets(s))
|
||||
if acc.isSatisfied() {
|
||||
return acc.result, nil
|
||||
}
|
||||
@ -176,7 +176,7 @@ func takeByTopology(topo *topology.CPUTopology, availableCPUs cpuset.CPUSet, num
|
||||
if acc.needs(acc.topo.CPUsPerCore()) {
|
||||
for _, c := range acc.freeCores() {
|
||||
klog.V(4).Infof("[cpumanager] takeByTopology: claiming core [%d]", c)
|
||||
acc.take(acc.details.CPUsInCore(c))
|
||||
acc.take(acc.details.CPUsInCores(c))
|
||||
if acc.isSatisfied() {
|
||||
return acc.result, nil
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func (p *staticPolicy) allocateCPUs(s state.State, numCPUs int, numaAffinity soc
|
||||
if numaAffinity != nil {
|
||||
alignedCPUs := cpuset.NewCPUSet()
|
||||
for _, numaNodeID := range numaAffinity.GetSockets() {
|
||||
alignedCPUs = alignedCPUs.Union(p.assignableCPUs(s).Intersection(p.topology.CPUDetails.CPUsInNUMANode(numaNodeID)))
|
||||
alignedCPUs = alignedCPUs.Union(p.assignableCPUs(s).Intersection(p.topology.CPUDetails.CPUsInNUMANodes(numaNodeID)))
|
||||
}
|
||||
|
||||
numAlignedToAlloc := alignedCPUs.Size()
|
||||
|
@ -90,13 +90,15 @@ func (d CPUDetails) NUMANodes() cpuset.CPUSet {
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// NUMANodesInSocket returns all of the logical NUMANode IDs associated with
|
||||
// the given Socket ID in this CPUDetails.
|
||||
func (d CPUDetails) NUMANodesInSocket(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for _, info := range d {
|
||||
if info.SocketID == id {
|
||||
b.Add(info.NUMANodeID)
|
||||
for _, id := range ids {
|
||||
for _, info := range d {
|
||||
if info.SocketID == id {
|
||||
b.Add(info.NUMANodeID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
@ -112,25 +114,29 @@ func (d CPUDetails) Sockets() cpuset.CPUSet {
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// CPUsInSocket returns all of the logical CPU IDs associated with the
|
||||
// given socket ID in this CPUDetails.
|
||||
func (d CPUDetails) CPUsInSocket(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for cpu, info := range d {
|
||||
if info.SocketID == id {
|
||||
b.Add(cpu)
|
||||
for _, id := range ids {
|
||||
for cpu, info := range d {
|
||||
if info.SocketID == id {
|
||||
b.Add(cpu)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// SocketsInNUMANode returns all of the logical Socket IDs associated with the
|
||||
// given NUMANode ID in this CPUDetails.
|
||||
func (d CPUDetails) SocketsInNUMANode(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for _, info := range d {
|
||||
if info.NUMANodeID == id {
|
||||
b.Add(info.SocketID)
|
||||
for _, id := range ids {
|
||||
for _, info := range d {
|
||||
if info.NUMANodeID == id {
|
||||
b.Add(info.SocketID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
@ -146,25 +152,29 @@ func (d CPUDetails) Cores() cpuset.CPUSet {
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// CoresInNUMANode returns all of the core IDs associated with the given
|
||||
// NUMA ID in this CPUDetails.
|
||||
func (d CPUDetails) CoresInNUMANode(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for _, info := range d {
|
||||
if info.NUMANodeID == id {
|
||||
b.Add(info.CoreID)
|
||||
for _, id := range ids {
|
||||
for _, info := range d {
|
||||
if info.NUMANodeID == id {
|
||||
b.Add(info.CoreID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// CoresInSocket returns all of the core IDs associated with the given
|
||||
// socket ID in this CPUDetails.
|
||||
func (d CPUDetails) CoresInSocket(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for _, info := range d {
|
||||
if info.SocketID == id {
|
||||
b.Add(info.CoreID)
|
||||
for _, id := range ids {
|
||||
for _, info := range d {
|
||||
if info.SocketID == id {
|
||||
b.Add(info.CoreID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
@ -179,25 +189,29 @@ func (d CPUDetails) CPUs() cpuset.CPUSet {
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// CPUsInNUMANode returns all of the logical CPU IDs associated with the given
|
||||
// NUMANode ID in this CPUDetails.
|
||||
func (d CPUDetails) CPUsInNUMANode(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for cpu, info := range d {
|
||||
if info.NUMANodeID == id {
|
||||
b.Add(cpu)
|
||||
for _, id := range ids {
|
||||
for cpu, info := range d {
|
||||
if info.NUMANodeID == id {
|
||||
b.Add(cpu)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
}
|
||||
|
||||
// CPUsInCore returns all of the logical CPU IDs associated with the
|
||||
// given core ID in this CPUDetails.
|
||||
func (d CPUDetails) CPUsInCore(id int) cpuset.CPUSet {
|
||||
// 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()
|
||||
for cpu, info := range d {
|
||||
if info.CoreID == id {
|
||||
b.Add(cpu)
|
||||
for _, id := range ids {
|
||||
for cpu, info := range d {
|
||||
if info.CoreID == id {
|
||||
b.Add(cpu)
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.Result()
|
||||
|
Loading…
Reference in New Issue
Block a user