Refactor TopologyManager to be more explicit about bestHint calculation
Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
parent
d12787bc2c
commit
f8601cb5a3
@ -94,51 +94,60 @@ func filterProvidersHints(providersHints []map[string][]TopologyHint) [][]Topolo
|
||||
return allProviderHints
|
||||
}
|
||||
|
||||
func mergeFilteredHints(numaNodes []int, filteredHints [][]TopologyHint) TopologyHint {
|
||||
// Set the default affinity as an any-numa affinity containing the list
|
||||
// of NUMA Nodes available on this machine.
|
||||
defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
||||
func compareHints(current *TopologyHint, candidate *TopologyHint) *TopologyHint {
|
||||
// Only consider candidates that result in a NUMANodeAffinity > 0 to
|
||||
// replace the current bestHint.
|
||||
if candidate.NUMANodeAffinity.Count() == 0 {
|
||||
return current
|
||||
}
|
||||
|
||||
// Set the bestHint to return from this function as {nil false}.
|
||||
// This will only be returned if no better hint can be found when
|
||||
// merging hints from each hint provider.
|
||||
bestHint := TopologyHint{defaultAffinity, false}
|
||||
// If no current bestHint is set, return the candidate as the bestHint.
|
||||
if current == nil {
|
||||
return candidate
|
||||
}
|
||||
|
||||
// If the current bestHint is non-preferred and the candidate hint is
|
||||
// preferred, always choose the preferred hint over the non-preferred one.
|
||||
if !current.Preferred && candidate.Preferred {
|
||||
return candidate
|
||||
}
|
||||
|
||||
// If the current bestHint is preferred and the candidate hint is
|
||||
// non-preferred, never update the bestHint, regardless of the
|
||||
// candidate hint's narowness.
|
||||
if current.Preferred && !candidate.Preferred {
|
||||
return current
|
||||
}
|
||||
|
||||
// If the current bestHint and the candidate hint have the same
|
||||
// preference, only consider candidate hints that have a narrower
|
||||
// NUMANodeAffinity than the NUMANodeAffinity in the current bestHint.
|
||||
if !candidate.NUMANodeAffinity.IsNarrowerThan(current.NUMANodeAffinity) {
|
||||
return current
|
||||
}
|
||||
|
||||
// In all other cases, update the bestHint to the candidate hint.
|
||||
return candidate
|
||||
}
|
||||
|
||||
func mergeFilteredHints(numaNodes []int, filteredHints [][]TopologyHint) TopologyHint {
|
||||
var bestHint *TopologyHint
|
||||
iterateAllProviderTopologyHints(filteredHints, func(permutation []TopologyHint) {
|
||||
// Get the NUMANodeAffinity from each hint in the permutation and see if any
|
||||
// of them encode unpreferred allocations.
|
||||
mergedHint := mergePermutation(numaNodes, permutation)
|
||||
// Only consider mergedHints that result in a NUMANodeAffinity > 0 to
|
||||
// replace the current bestHint.
|
||||
if mergedHint.NUMANodeAffinity.Count() == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// If the current bestHint is non-preferred and the new mergedHint is
|
||||
// preferred, always choose the preferred hint over the non-preferred one.
|
||||
if mergedHint.Preferred && !bestHint.Preferred {
|
||||
bestHint = mergedHint
|
||||
return
|
||||
}
|
||||
|
||||
// If the current bestHint is preferred and the new mergedHint is
|
||||
// non-preferred, never update bestHint, regardless of mergedHint's
|
||||
// narowness.
|
||||
if !mergedHint.Preferred && bestHint.Preferred {
|
||||
return
|
||||
}
|
||||
|
||||
// If mergedHint and bestHint has the same preference, only consider
|
||||
// mergedHints that have a narrower NUMANodeAffinity than the
|
||||
// NUMANodeAffinity in the current bestHint.
|
||||
if !mergedHint.NUMANodeAffinity.IsNarrowerThan(bestHint.NUMANodeAffinity) {
|
||||
return
|
||||
}
|
||||
|
||||
// In all other cases, update bestHint to the current mergedHint
|
||||
bestHint = mergedHint
|
||||
// Compare the current bestHint with the candidate mergedHint and
|
||||
// update bestHint if appropriate.
|
||||
bestHint = compareHints(bestHint, &mergedHint)
|
||||
})
|
||||
|
||||
return bestHint
|
||||
if bestHint == nil {
|
||||
defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
|
||||
bestHint = &TopologyHint{defaultAffinity, false}
|
||||
}
|
||||
|
||||
return *bestHint
|
||||
}
|
||||
|
||||
// Iterate over all permutations of hints in 'allProviderHints [][]TopologyHint'.
|
||||
|
Loading…
Reference in New Issue
Block a user