@@ -81,9 +81,13 @@ func (s vendorVFIOSysfs) discoverVFs() ([]VirtualFunction, error) {
8181 return vfs , nil
8282}
8383
84+ // listProfiles aggregates creatable profiles per parent GPU. Free VFs on the
85+ // same GPU share its framebuffer, so counting each advertising VF overreports
86+ // availability. The driver only guarantees that a GPU still advertising a
87+ // type can fit one more instance of it, so report that per-GPU lower bound.
8488func (s vendorVFIOSysfs ) listProfiles (vfs []VirtualFunction ) ([]GPUProfile , error ) {
8589 profilesByType := make (map [string ]profileMetadata )
86- availability := make (map [string ]int )
90+ creatableGPUs := make (map [string ]map [ string ] struct {} )
8791 for _ , vf := range vfs {
8892 creatable , err := s .readCreatableProfiles (vf .PCIAddress )
8993 if err != nil {
@@ -92,7 +96,14 @@ func (s vendorVFIOSysfs) listProfiles(vfs []VirtualFunction) ([]GPUProfile, erro
9296 for _ , profile := range creatable {
9397 profilesByType [profile .TypeName ] = profile
9498 if ! vf .Allocated {
95- availability [profile .TypeName ]++
99+ gpu := vf .ParentGPU
100+ if gpu == "" {
101+ gpu = vf .PCIAddress
102+ }
103+ if creatableGPUs [profile .TypeName ] == nil {
104+ creatableGPUs [profile .TypeName ] = make (map [string ]struct {})
105+ }
106+ creatableGPUs [profile.TypeName ][gpu ] = struct {}{}
96107 }
97108 }
98109 }
@@ -108,7 +119,7 @@ func (s vendorVFIOSysfs) listProfiles(vfs []VirtualFunction) ([]GPUProfile, erro
108119 profiles = append (profiles , GPUProfile {
109120 Name : profile .Name ,
110121 FramebufferMB : profile .FramebufferMB ,
111- Available : availability [profile .TypeName ],
122+ Available : len ( creatableGPUs [profile .TypeName ]) ,
112123 })
113124 }
114125 return profiles , nil
0 commit comments