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