Globalize a few TopologyManager functions

This is in preparation for a larger refactoring effort that will add a
'Merge()'  API to the TopologyManager policy API.
This commit is contained in:
Adrian Chiris 2019-11-04 11:38:56 +01:00 committed by Kevin Klues
parent e72847676f
commit 78d7856288

View File

@ -198,7 +198,7 @@ func (m *manager) accumulateProvidersHints(pod v1.Pod, container v1.Container) (
// provideryHints[-1][z] // provideryHints[-1][z]
// } // }
// callback(permutation) // callback(permutation)
func (m *manager) iterateAllProviderTopologyHints(allProviderHints [][]TopologyHint, callback func([]TopologyHint)) { func iterateAllProviderTopologyHints(allProviderHints [][]TopologyHint, callback func([]TopologyHint)) {
// Internal helper function to accumulate the permutation before calling the callback. // Internal helper function to accumulate the permutation before calling the callback.
var iterate func(i int, accum []TopologyHint) var iterate func(i int, accum []TopologyHint)
iterate = func(i int, accum []TopologyHint) { iterate = func(i int, accum []TopologyHint) {
@ -218,10 +218,10 @@ func (m *manager) iterateAllProviderTopologyHints(allProviderHints [][]TopologyH
} }
// Merge the hints from all hint providers to find the best one. // Merge the hints from all hint providers to find the best one.
func (m *manager) mergeProvidersHints(providersHints []map[string][]TopologyHint) TopologyHint { func mergeProvidersHints(policy Policy, numaNodes []int, providersHints []map[string][]TopologyHint) TopologyHint {
// Set the default affinity as an any-numa affinity containing the list // Set the default affinity as an any-numa affinity containing the list
// of NUMA Nodes available on this machine. // of NUMA Nodes available on this machine.
defaultAffinity, _ := bitmask.NewBitMask(m.numaNodes...) defaultAffinity, _ := bitmask.NewBitMask(numaNodes...)
// Loop through all hint providers and save an accumulated list of the // Loop through all hint providers and save an accumulated list of the
// hints returned by each hint provider. If no hints are provided, assume // hints returned by each hint provider. If no hints are provided, assume
@ -259,7 +259,7 @@ func (m *manager) mergeProvidersHints(providersHints []map[string][]TopologyHint
// permutations that have at least one NUMA ID set. If no merged mask can be // permutations that have at least one NUMA ID set. If no merged mask can be
// found that has at least one NUMA ID set, return the 'defaultAffinity'. // found that has at least one NUMA ID set, return the 'defaultAffinity'.
bestHint := TopologyHint{defaultAffinity, false} bestHint := TopologyHint{defaultAffinity, false}
m.iterateAllProviderTopologyHints(allProviderHints, func(permutation []TopologyHint) { iterateAllProviderTopologyHints(allProviderHints, 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.
preferred := true preferred := true
@ -277,13 +277,13 @@ func (m *manager) mergeProvidersHints(providersHints []map[string][]TopologyHint
// Special case PolicySingleNumaNode to only prefer hints where // Special case PolicySingleNumaNode to only prefer hints where
// all providers have a single NUMA affinity set. // all providers have a single NUMA affinity set.
if m.policy != nil && m.policy.Name() == PolicySingleNumaNode && hint.NUMANodeAffinity != nil && hint.NUMANodeAffinity.Count() > 1 { if policy != nil && policy.Name() == PolicySingleNumaNode && hint.NUMANodeAffinity != nil && hint.NUMANodeAffinity.Count() > 1 {
preferred = false preferred = false
} }
} }
// Merge the affinities using a bitwise-and operation. // Merge the affinities using a bitwise-and operation.
mergedAffinity, _ := bitmask.NewBitMask(m.numaNodes...) mergedAffinity, _ := bitmask.NewBitMask(numaNodes...)
mergedAffinity.And(numaAffinities...) mergedAffinity.And(numaAffinities...)
// Build a mergedHintfrom the merged affinity mask, indicating if an // Build a mergedHintfrom the merged affinity mask, indicating if an
@ -327,7 +327,7 @@ func (m *manager) mergeProvidersHints(providersHints []map[string][]TopologyHint
// Collect Hints from hint providers and pass to policy to retrieve the best one. // Collect Hints from hint providers and pass to policy to retrieve the best one.
func (m *manager) calculateAffinity(pod v1.Pod, container v1.Container) TopologyHint { func (m *manager) calculateAffinity(pod v1.Pod, container v1.Container) TopologyHint {
providersHints := m.accumulateProvidersHints(pod, container) providersHints := m.accumulateProvidersHints(pod, container)
bestHint := m.mergeProvidersHints(providersHints) bestHint := mergeProvidersHints(m.policy, m.numaNodes, providersHints)
klog.Infof("[topologymanager] ContainerTopologyHint: %v", bestHint) klog.Infof("[topologymanager] ContainerTopologyHint: %v", bestHint)
return bestHint return bestHint
} }