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