Skip to content

Commit

Permalink
Refine VF creating policy for SRIOV
Browse files Browse the repository at this point in the history
If there are already VFs created, then do not setup
VFs. And compare with totalvfs when probe numvfs.

Tracked-On: OAM-104042
Signed-off-by: Yadong Qi <yadong.qi@intel.com>
  • Loading branch information
YadongQi committed Sep 22, 2022
1 parent 45c3bf7 commit 7619e34
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/guest/vm_builder_qemu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ constexpr const char *kIntelGpuDriver = "/sys/bus/pci/devices/0000:00:02.0/drive
constexpr const char *kIntelGpuDriverUnbind = "/sys/bus/pci/devices/0000:00:02.0/driver/unbind";
constexpr const char *kIntelGpuSriovTotalVfs = "/sys/bus/pci/devices/0000:00:02.0/sriov_totalvfs";
constexpr const char *kIntelGpuSriovAutoProbe = "/sys/bus/pci/devices/0000:00:02.0/sriov_drivers_autoprobe";
constexpr const char *kDrmCard0DevSriovNumVfs = "/sys/class/drm/card0/device/sriov_numvfs";
constexpr const char *kIntelGpuSriovNumVfs = "/sys/bus/pci/devices/0000:00:02.0/sriov_numvfs";

constexpr const char *kVfioPciNewId = "/sys/bus/pci/drivers/vfio-pci/new_id";
constexpr const char *kVfioPciRemoveId = "/sys/bus/pci/drivers/vfio-pci/remove_id";
Expand Down Expand Up @@ -197,12 +197,17 @@ static int SetAvailableVf(void) {
if (totalvfs <= 0)
return -1;

/* Limit total VFs to conserve memory */
if (totalvfs > 4) {
totalvfs = 4;
/* Re-Probe SRIOV with limited VFs */
int current_vfs = ReadSysFile(kIntelGpuSriovNumVfs, std::ios_base::dec);
if (current_vfs < 0)
return -1;

if (current_vfs == 0) {
/* Limit VF's number to conserve memory */
int num_vfs = (totalvfs < 4) ? totalvfs : 4;

WriteSysFile(kIntelGpuSriovAutoProbe, "0");
WriteSysFile(kDrmCard0DevSriovNumVfs, std::to_string(totalvfs));
WriteSysFile(kIntelGpuSriovNumVfs, "0");
WriteSysFile(kIntelGpuSriovNumVfs, std::to_string(num_vfs));
WriteSysFile(kIntelGpuSriovAutoProbe, "1");
}

Expand All @@ -228,6 +233,8 @@ static int SetAvailableVf(void) {
return i;
}

LOG(error) << "Failed to find 1 available VF!";

return -1;
}

Expand Down

0 comments on commit 7619e34

Please sign in to comment.