@@ -81,13 +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 .
84+ // listProfiles counts each free VF advertising a type as one creatable
85+ // instance, matching the driver-reported units that mdev sums through
86+ // available_instances. This is a best-effort snapshot because creating on one
87+ // VF may revoke the type from siblings that share its GPU framebuffer .
8888func (s vendorVFIOSysfs ) listProfiles (vfs []VirtualFunction ) ([]GPUProfile , error ) {
8989 profilesByType := make (map [string ]profileMetadata )
90- creatableGPUs := make (map [string ]map [ string ] struct {} )
90+ creatableVFs := make (map [string ]int )
9191 for _ , vf := range vfs {
9292 creatable , err := s .readCreatableProfiles (vf .PCIAddress )
9393 if err != nil {
@@ -96,14 +96,7 @@ func (s vendorVFIOSysfs) listProfiles(vfs []VirtualFunction) ([]GPUProfile, erro
9696 for _ , profile := range creatable {
9797 profilesByType [profile .TypeName ] = profile
9898 if ! vf .Allocated {
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 {}{}
99+ creatableVFs [profile .TypeName ]++
107100 }
108101 }
109102 }
@@ -119,7 +112,7 @@ func (s vendorVFIOSysfs) listProfiles(vfs []VirtualFunction) ([]GPUProfile, erro
119112 profiles = append (profiles , GPUProfile {
120113 Name : profile .Name ,
121114 FramebufferMB : profile .FramebufferMB ,
122- Available : len ( creatableGPUs [profile .TypeName ]) ,
115+ Available : creatableVFs [profile .TypeName ],
123116 })
124117 }
125118 return profiles , nil
0 commit comments