Skip to content

Commit

Permalink
scheduler: permit other plugin to set numaAffinity (#2182)
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu.wjy <wangjianyu.wjy@alibaba-inc.com>
Co-authored-by: wangjianyu.wjy <wangjianyu.wjy@alibaba-inc.com>
  • Loading branch information
ZiMengSheng and wangjianyu.wjy authored Sep 2, 2024
1 parent 4d89c84 commit cb89d6d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
17 changes: 9 additions & 8 deletions pkg/scheduler/frameworkext/topologymanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ func (m *topologyManager) Admit(ctx context.Context, cycleState *framework.Cycle
store := s.(*Store)

policy := createNUMATopologyPolicy(policyType, numaNodes)

bestHint, admit := m.calculateAffinity(ctx, cycleState, policy, pod, nodeName, exclusivePolicy, allNUMANodeStatus)
klog.V(5).Infof("Best TopologyHint for (pod: %v): %v on node: %v", klog.KObj(pod), bestHint, nodeName)
if !admit {
return framework.NewStatus(framework.Unschedulable, "node(s) NUMA Topology affinity error")
bestHint, ok := store.GetAffinity(nodeName)
if !ok {
var admit bool
bestHint, admit = m.calculateAffinity(ctx, cycleState, policy, pod, nodeName, exclusivePolicy, allNUMANodeStatus)
klog.V(5).Infof("Best TopologyHint for (pod: %v): %v on node: %v", klog.KObj(pod), bestHint, nodeName)
if !admit {
return framework.NewStatus(framework.Unschedulable, "node(s) NUMA Topology affinity error")
}
store.SetAffinity(nodeName, bestHint)
}

store.SetAffinity(nodeName, bestHint)

status := m.allocateResources(ctx, cycleState, bestHint, pod, nodeName)
if !status.IsSuccess() {
return status
Expand Down
6 changes: 3 additions & 3 deletions pkg/scheduler/frameworkext/topologymanager/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (s *Store) SetAffinity(nodeName string, affinity NUMATopologyHint) {
s.affinityMap.Store(nodeName, &affinity)
}

func (s *Store) GetAffinity(nodeName string) NUMATopologyHint {
func (s *Store) GetAffinity(nodeName string) (NUMATopologyHint, bool) {
val, ok := s.affinityMap.Load(nodeName)
if !ok {
return NUMATopologyHint{}
return NUMATopologyHint{}, false
}
hint := val.(*NUMATopologyHint)
return *hint
return *hint, true
}
6 changes: 3 additions & 3 deletions pkg/scheduler/plugins/deviceshare/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (p *Plugin) Filter(ctx context.Context, cycleState *framework.CycleState, p
var affinity topologymanager.NUMATopologyHint
if !p.disableDeviceNUMATopologyAlignment {
store := topologymanager.GetStore(cycleState)
affinity = store.GetAffinity(nodeInfo.Node().Name)
affinity, _ = store.GetAffinity(nodeInfo.Node().Name)
}

allocator := &AutopilotAllocator{
Expand Down Expand Up @@ -369,7 +369,7 @@ func (p *Plugin) FilterReservation(ctx context.Context, cycleState *framework.Cy
var affinity topologymanager.NUMATopologyHint
if !p.disableDeviceNUMATopologyAlignment {
store := topologymanager.GetStore(cycleState)
affinity = store.GetAffinity(nodeInfo.Node().Name)
affinity, _ = store.GetAffinity(nodeInfo.Node().Name)
}

allocator := &AutopilotAllocator{
Expand Down Expand Up @@ -417,7 +417,7 @@ func (p *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,
var affinity topologymanager.NUMATopologyHint
if !p.disableDeviceNUMATopologyAlignment {
store := topologymanager.GetStore(cycleState)
affinity = store.GetAffinity(nodeInfo.Node().Name)
affinity, _ = store.GetAffinity(nodeInfo.Node().Name)
}

allocator := &AutopilotAllocator{
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/plugins/deviceshare/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *Plugin) Score(ctx context.Context, cycleState *framework.CycleState, po
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)

allocator := &AutopilotAllocator{
state: state,
Expand Down Expand Up @@ -130,7 +130,7 @@ func (p *Plugin) ScoreReservation(ctx context.Context, cycleState *framework.Cyc
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeInfo.Node().Name)
affinity, _ := store.GetAffinity(nodeInfo.Node().Name)

allocator := &AutopilotAllocator{
state: state,
Expand Down
4 changes: 2 additions & 2 deletions pkg/scheduler/plugins/nodenumaresource/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (p *Plugin) FilterReservation(ctx context.Context, cycleState *framework.Cy
restoreState := reservationRestoreState.getNodeState(nodeName)

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)
resourceOptions, err := p.getResourceOptions(state, node, pod, requestCPUBind, affinity, topologyOptions)
if err != nil {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, err.Error())
Expand Down Expand Up @@ -541,7 +541,7 @@ func (p *Plugin) Reserve(ctx context.Context, cycleState *framework.CycleState,

// TODO: de-duplicate logic done by the Filter phase and move head the pre-process of the resource options
store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)
resourceOptions, err := p.getResourceOptions(state, node, pod, requestCPUBind, affinity, topologyOptions)
if err != nil {
return framework.AsStatus(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/nodenumaresource/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@ func TestFilterWithNUMANodeScoring(t *testing.T) {
assert.NoError(t, err)
status = pl.Filter(context.TODO(), cycleState, tt.requestedPod, nodeInfo)
assert.True(t, status.IsSuccess())
hint := topologymanager.GetStore(cycleState).GetAffinity(tt.node.Name)
hint, _ := topologymanager.GetStore(cycleState).GetAffinity(tt.node.Name)
assert.Equal(t, tt.wantAffinity.GetBits(), hint.NUMANodeAffinity.GetBits())
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/plugins/nodenumaresource/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (p *Plugin) Score(ctx context.Context, cycleState *framework.CycleState, po
}

store := topologymanager.GetStore(cycleState)
affinity := store.GetAffinity(nodeName)
affinity, _ := store.GetAffinity(nodeName)
resourceOptions, err := p.getResourceOptions(state, node, pod, requestCPUBind, affinity, topologyOptions)
if err != nil {
return 0, nil
Expand Down

0 comments on commit cb89d6d

Please sign in to comment.