Skip to content

Commit 3adc92d

Browse files
committed
Fix availability math
1 parent 8c5a188 commit 3adc92d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/devices/mdev.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,25 @@ func countAvailableVFsForProfilesParallel(vfs []VirtualFunction, profiles []prof
231231
}
232232

233233
// countAvailableForSingleProfile counts available VFs for a single profile type.
234+
// For SR-IOV vGPU (e.g., L40S), each VF has its own available_instances (typically 0 or 1).
235+
// For time-sliced vGPU, available_instances may reflect shared GPU resources.
236+
// We sum across all free VFs to handle both cases correctly.
234237
func countAvailableForSingleProfile(freeVFsByParent map[string][]VirtualFunction, profileType string) int {
235238
count := 0
236239
for _, parentVFs := range freeVFsByParent {
237-
if len(parentVFs) == 0 {
238-
continue
239-
}
240-
// Sample just ONE VF per parent - available_instances reflects GPU-wide capacity
241-
sampleVF := parentVFs[0]
242-
availPath := filepath.Join(mdevBusPath, sampleVF.PCIAddress, "mdev_supported_types", profileType, "available_instances")
243-
data, err := os.ReadFile(availPath)
244-
if err != nil {
245-
continue
246-
}
247-
instances, err := strconv.Atoi(strings.TrimSpace(string(data)))
248-
if err != nil || instances < 1 {
249-
continue
240+
// Sum available_instances from all free VFs on this parent
241+
for _, vf := range parentVFs {
242+
availPath := filepath.Join(mdevBusPath, vf.PCIAddress, "mdev_supported_types", profileType, "available_instances")
243+
data, err := os.ReadFile(availPath)
244+
if err != nil {
245+
continue
246+
}
247+
instances, err := strconv.Atoi(strings.TrimSpace(string(data)))
248+
if err != nil {
249+
continue
250+
}
251+
count += instances
250252
}
251-
// available_instances reflects GPU-wide remaining capacity, not per-VF
252-
count += instances
253253
}
254254
return count
255255
}

0 commit comments

Comments
 (0)