@@ -48,54 +48,16 @@ func (p *bestEffortPolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.PodAd
48
48
}
49
49
50
50
func (p * bestEffortPolicy ) Merge (providersHints []map [string ][]TopologyHint ) (TopologyHint , lifecycle.PodAdmitResult ) {
51
- hint := mergeProvidersHints ( p , p . numaNodes , providersHints )
51
+ hint := p . mergeProvidersHints ( providersHints )
52
52
admit := p .canAdmitPodResult (& hint )
53
53
return hint , admit
54
54
}
55
55
56
- // Iterate over all permutations of hints in 'allProviderHints [][]TopologyHint'.
57
- //
58
- // This procedure is implemented as a recursive function over the set of hints
59
- // in 'allproviderHints[i]'. It applies the function 'callback' to each
60
- // permutation as it is found. It is the equivalent of:
61
- //
62
- // for i := 0; i < len(providerHints[0]); i++
63
- // for j := 0; j < len(providerHints[1]); j++
64
- // for k := 0; k < len(providerHints[2]); k++
65
- // ...
66
- // for z := 0; z < len(providerHints[-1]); z++
67
- // permutation := []TopologyHint{
68
- // providerHints[0][i],
69
- // providerHints[1][j],
70
- // providerHints[2][k],
71
- // ...
72
- // providerHints[-1][z]
73
- // }
74
- // callback(permutation)
75
- func iterateAllProviderTopologyHints (allProviderHints [][]TopologyHint , callback func ([]TopologyHint )) {
76
- // Internal helper function to accumulate the permutation before calling the callback.
77
- var iterate func (i int , accum []TopologyHint )
78
- iterate = func (i int , accum []TopologyHint ) {
79
- // Base case: we have looped through all providers and have a full permutation.
80
- if i == len (allProviderHints ) {
81
- callback (accum )
82
- return
83
- }
84
-
85
- // Loop through all hints for provider 'i', and recurse to build the
86
- // the permutation of this hint with all hints from providers 'i++'.
87
- for j := range allProviderHints [i ] {
88
- iterate (i + 1 , append (accum , allProviderHints [i ][j ]))
89
- }
90
- }
91
- iterate (0 , []TopologyHint {})
92
- }
93
-
94
56
// Merge the hints from all hint providers to find the best one.
95
- func mergeProvidersHints ( policy Policy , numaNodes [] int , providersHints []map [string ][]TopologyHint ) TopologyHint {
57
+ func ( p * bestEffortPolicy ) mergeProvidersHints ( providersHints []map [string ][]TopologyHint ) TopologyHint {
96
58
// Set the default affinity as an any-numa affinity containing the list
97
59
// of NUMA Nodes available on this machine.
98
- defaultAffinity , _ := bitmask .NewBitMask (numaNodes ... )
60
+ defaultAffinity , _ := bitmask .NewBitMask (p . numaNodes ... )
99
61
100
62
// Loop through all hint providers and save an accumulated list of the
101
63
// hints returned by each hint provider. If no hints are provided, assume
@@ -136,33 +98,7 @@ func mergeProvidersHints(policy Policy, numaNodes []int, providersHints []map[st
136
98
iterateAllProviderTopologyHints (allProviderHints , func (permutation []TopologyHint ) {
137
99
// Get the NUMANodeAffinity from each hint in the permutation and see if any
138
100
// of them encode unpreferred allocations.
139
- preferred := true
140
- var numaAffinities []bitmask.BitMask
141
- for _ , hint := range permutation {
142
- if hint .NUMANodeAffinity == nil {
143
- numaAffinities = append (numaAffinities , defaultAffinity )
144
- } else {
145
- numaAffinities = append (numaAffinities , hint .NUMANodeAffinity )
146
- }
147
-
148
- if ! hint .Preferred {
149
- preferred = false
150
- }
151
-
152
- // Special case PolicySingleNumaNode to only prefer hints where
153
- // all providers have a single NUMA affinity set.
154
- if policy != nil && policy .Name () == PolicySingleNumaNode && hint .NUMANodeAffinity != nil && hint .NUMANodeAffinity .Count () > 1 {
155
- preferred = false
156
- }
157
- }
158
-
159
- // Merge the affinities using a bitwise-and operation.
160
- mergedAffinity , _ := bitmask .NewBitMask (numaNodes ... )
161
- mergedAffinity .And (numaAffinities ... )
162
-
163
- // Build a mergedHintfrom the merged affinity mask, indicating if an
164
- // preferred allocation was used to generate the affinity mask or not.
165
- mergedHint := TopologyHint {mergedAffinity , preferred }
101
+ mergedHint := mergePermutation (p .numaNodes , permutation )
166
102
167
103
// Only consider mergedHints that result in a NUMANodeAffinity > 0 to
168
104
// replace the current bestHint.
0 commit comments