Skip to content

Commit 9ad0825

Browse files
author
乔普
committed
scheduler: support designated vf
Signed-off-by: 乔普 <wangjianyu.wjy@alibaba-inc.com>
1 parent f559bd1 commit 9ad0825

File tree

2 files changed

+664
-4
lines changed

2 files changed

+664
-4
lines changed

pkg/scheduler/plugins/deviceshare/device_allocator.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type requestContext struct {
5757
preferred map[schedulingv1alpha1.DeviceType]sets.Int
5858
allocationScorer *resourceAllocationScorer
5959
nodeDevice *nodeDevice
60+
61+
designatedVF map[schedulingv1alpha1.DeviceType]map[int32]sets.Set[string]
6062
}
6163

6264
type AutopilotAllocator struct {
@@ -101,6 +103,7 @@ func (a *AutopilotAllocator) Allocate(
101103
return nil, status
102104
}
103105

106+
designatedVF := constructDesignatedVF(a.state.designatedAllocation)
104107
nodeDevice := a.filterNodeDevice(requiredDeviceResources, preemptibleDeviceResources)
105108
requestCtx := &requestContext{
106109
pod: a.pod,
@@ -114,6 +117,7 @@ func (a *AutopilotAllocator) Allocate(
114117
required: required,
115118
preferred: preferred,
116119
nodeDevice: a.nodeDevice,
120+
designatedVF: designatedVF,
117121
}
118122
var deviceAllocations apiext.DeviceAllocations
119123
var status *framework.Status
@@ -137,6 +141,30 @@ func (a *AutopilotAllocator) Allocate(
137141
return deviceAllocations, nil
138142
}
139143

144+
func constructDesignatedVF(designatedAllocation apiext.DeviceAllocations) map[schedulingv1alpha1.DeviceType]map[int32]sets.Set[string] {
145+
if designatedAllocation == nil {
146+
return nil
147+
}
148+
designatedVF := make(map[schedulingv1alpha1.DeviceType]map[int32]sets.Set[string])
149+
for deviceType, allocations := range designatedAllocation {
150+
vfOfType := make(map[int32]sets.Set[string])
151+
for _, allocation := range allocations {
152+
if allocation.Extension != nil && len(allocation.Extension.VirtualFunctions) != 0 {
153+
minor := allocation.Minor
154+
vfOfMinor := sets.New[string]()
155+
for _, function := range allocation.Extension.VirtualFunctions {
156+
vfOfMinor.Insert(function.BusID)
157+
}
158+
vfOfType[minor] = vfOfMinor
159+
}
160+
}
161+
if len(vfOfType) != 0 {
162+
designatedVF[deviceType] = vfOfType
163+
}
164+
}
165+
return designatedVF
166+
}
167+
140168
func (a *AutopilotAllocator) filterNodeDevice(
141169
requiredDeviceResources, preemptibleDeviceResources map[schedulingv1alpha1.DeviceType]deviceResources,
142170
) *nodeDevice {
@@ -370,6 +398,7 @@ func defaultAllocateDevices(
370398
minor := ptr.Deref[int32](v.Minor, 0)
371399
deviceInfos[int(minor)] = v
372400
}
401+
designatedVFOfType := requestCtx.designatedVF[deviceType]
373402

374403
var allocations []*apiext.DeviceAllocation
375404
resourceMinorPairs := scoreDevices(podRequestPerInstance, nodeDeviceTotal, freeDevices, requestCtx.allocationScorer)
@@ -396,9 +425,15 @@ func defaultAllocateDevices(
396425
Minor: int32(resourceMinorPair.minor),
397426
Resources: podRequestPerInstance,
398427
}
428+
429+
var designatedVFOfMinor sets.Set[string]
430+
if designatedVFOfType != nil {
431+
designatedVFOfMinor = designatedVFOfType[r.Minor]
432+
}
433+
399434
if mustAllocateVF(hint) {
400435
// TODO Device allocation logic hotspots discovered through flame graphs
401-
vf := allocateVF(vfAllocation, deviceInfos, resourceMinorPair.minor, vfSelector)
436+
vf := allocateVF(vfAllocation, deviceInfos, resourceMinorPair.minor, vfSelector, designatedVFOfMinor)
402437
if vf == nil {
403438
continue
404439
}
@@ -426,7 +461,7 @@ func defaultAllocateDevices(
426461
return allocations, nil
427462
}
428463

429-
func allocateVF(vfAllocation *VFAllocation, deviceInfos map[int]*schedulingv1alpha1.DeviceInfo, minor int, vfSelector labels.Selector) *schedulingv1alpha1.VirtualFunction {
464+
func allocateVF(vfAllocation *VFAllocation, deviceInfos map[int]*schedulingv1alpha1.DeviceInfo, minor int, vfSelector labels.Selector, designatedVFOfMinor sets.Set[string]) *schedulingv1alpha1.VirtualFunction {
430465
deviceInfo := deviceInfos[minor]
431466
if deviceInfo == nil {
432467
return nil
@@ -440,9 +475,13 @@ func allocateVF(vfAllocation *VFAllocation, deviceInfos map[int]*schedulingv1alp
440475
for _, vfGroup := range deviceInfo.VFGroups {
441476
if vfSelector == nil || vfSelector.Matches(labels.Set(vfGroup.Labels)) {
442477
for _, vf := range vfGroup.VFs {
443-
if !allocated.Has(vf.BusID) {
444-
remainingVFs = append(remainingVFs, vf)
478+
if allocated.Has(vf.BusID) {
479+
continue
480+
}
481+
if designatedVFOfMinor != nil && !designatedVFOfMinor.Has(vf.BusID) {
482+
continue
445483
}
484+
remainingVFs = append(remainingVFs, vf)
446485
}
447486
}
448487
}

0 commit comments

Comments
 (0)