Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port improvements from start_civ to VM manager #252

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,4 @@ Requirements
### [extra]
- cmd: Set extra command.
- service: Set extra services, use `:` split different services.

- pwr_ctrl_multios: If set to "true", will create qmp socket in /tmp/ folder for suspend/hibernate feature. Setting to "false" will not create the sockeet.
2 changes: 1 addition & 1 deletion src/guest/config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ map<string_view, vector<string_view>> kConfigMap = {
{ kGroupPciPt, { kPciPtDev }},
{ kGroupMed, { kMedBattery, kMedThermal, kMedCamera } },
{ kGroupService, { kServTimeKeep, kServPmCtrl, kServVinput } },
{ kGroupExtra, { kExtraCmd, kExtraService } }
{ kGroupExtra, { kExtraCmd, kExtraService, kExtraPwrCtrlMultiOS } }
prashanth-intel marked this conversation as resolved.
Show resolved Hide resolved
};

bool CivConfig::SanitizeOpts(void) {
Expand Down
1 change: 1 addition & 0 deletions src/guest/config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ constexpr char kServVinput[] = "vinput";

constexpr char kExtraCmd[] = "cmd";
constexpr char kExtraService[] = "service";
constexpr char kExtraPwrCtrlMultiOS[] = "pwr_ctrl_multios";

/* Options for Key to select */
constexpr char kEmulTypeQemu[] = "QEMU";
Expand Down
47 changes: 42 additions & 5 deletions src/guest/vm_builder_qemu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "utils/log.h"
#include "utils/utils.h"

#define MAX_NUM_GUEST 7

namespace vm_manager {
constexpr const char *kPciDevicePath = "/sys/bus/pci/devices/";
constexpr const char *kPciDriverPath = "/sys/bus/pci/drivers/";
Expand Down Expand Up @@ -55,6 +57,15 @@ constexpr const char *kGvtgMdevV58Path = "/sys/bus/pci/devices/0000:00:02.0/mdev
constexpr const char *kSys2MFreeHugePages = "/sys/kernel/mm/hugepages/hugepages-2048kB/free_hugepages";
constexpr const char *kSys2MNrHugePages = "/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages";

constexpr const char *kDrmCard0Vf = "/sys/class/drm/card0/iov/vf";
constexpr const char *kGtPreemptTimeoutUs = "/gt/preempt_timeout_us";
constexpr const char *kGtExecQuantumMs = "/gt/exec_quantum_ms";

constexpr const unsigned int kPreemptTimeout = 50000;
constexpr const unsigned int kExecQuantum = 25;

constexpr const char *kQmpPowerSocket = "/tmp/qmp-pwr-socket-";

static bool CheckUuid(std::string uuid) {
try {
boost::uuids::string_generator gen;
Expand Down Expand Up @@ -202,12 +213,9 @@ static int SetAvailableVf(void) {
return -1;

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

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

Expand All @@ -229,8 +237,16 @@ static int SetAvailableVf(void) {
std::string sd(kIntelGpuDevPath);
sd.replace(sd.end() - 2, sd.end(), std::to_string(i) + "/enable");
int status = ReadSysFile(sd.c_str(), std::ios_base::dec);
if (status == 0)
if (status == 0) {
std::string timeoutPath = kDrmCard0Vf;
timeoutPath.append(std::to_string(i) + kGtPreemptTimeoutUs);
WriteSysFile(timeoutPath.c_str(), std::to_string(kPreemptTimeout));

std::string execQuantumPath = kDrmCard0Vf;
execQuantumPath.append(std::to_string(i) + kGtExecQuantumMs);
WriteSysFile(execQuantumPath.c_str(), std::to_string(kExecQuantum));
prashanth-intel marked this conversation as resolved.
Show resolved Hide resolved
return i;
}
}

LOG(error) << "Failed to find 1 available VF!";
Expand Down Expand Up @@ -265,6 +281,26 @@ bool VmBuilderQemu::SetupSriov(void) {
return true;
}

void VmBuilderQemu::BuildExtraGuestPmCtrlCmd(void) {
std::string ex_cmd = cfg_.GetValue(kGroupExtra, kExtraPwrCtrlMultiOS);
if (ex_cmd == "true") {
static std::string socketPath;
for(int avail = 0; avail < MAX_NUM_GUEST; avail++) {
socketPath = kQmpPowerSocket + std::to_string(avail);
if(access(socketPath.c_str(), F_OK) != 0) {
std::string qmpCmd = " -qmp unix:" + socketPath + ",server,nowait";
emul_cmd_.append(qmpCmd);
break;
}
}

end_call_.emplace([](){
boost::filesystem::remove(socketPath);
});
} else
return;
}

enum PciPassthroughAction {
kPciPassthrough,
kPciRestore
Expand Down Expand Up @@ -794,6 +830,7 @@ bool VmBuilderQemu::BuildVmArgs(void) {
BuildGuestTimeKeepCmd();

BuildGuestPmCtrlCmd();
BuildExtraGuestPmCtrlCmd();

BuildAudioCmd();

Expand Down
1 change: 1 addition & 0 deletions src/guest/vm_builder_qemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class VmBuilderQemu : public VmBuilder {
void BuildPtPciDevicesCmd(void);
void BuildGuestTimeKeepCmd(void);
void BuildGuestPmCtrlCmd(void);
void BuildExtraGuestPmCtrlCmd(void);
void BuildAudioCmd(void);
void BuildExtraCmd(void);

Expand Down