Skip to content

Commit

Permalink
Add power control qmp socket for Android 12
Browse files Browse the repository at this point in the history
Add qmp socket for CiV guest VM that required by suspend/hibernate power control feature.

We need to add a qmp socket for pwr_ctrl_multios.sh to use
even CiV currently doesn't support suspend/hibernate power
control feature.
With this qmp socket, pwr_ctrl_multios.sh can tell there
is a civ guest vm running and won't do suspend/hibernate
in this case.

Tracked-On: OAM-104723
Signed-off-by: Suresh, Prashanth <prashanth.suresh@intel.com>
  • Loading branch information
prashanth-intel committed Nov 16, 2022
1 parent 32216fd commit 53f227d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
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 } }
};

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 kExtraPwrCtrlMutliOS[] = "pwr_ctrl_multios";

/* Options for Key to select */
constexpr char kEmulTypeQemu[] = "QEMU";
Expand Down
43 changes: 34 additions & 9 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,13 +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 *kTimeoutPath = "/sys/class/drm/card0/iov/vf";
constexpr const char *kTimeoutPremptFile = "/gt/preempt_timeout_us";
constexpr const char *kTimeoutExecQuantum = "/gt/exec_quantum_ms";
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 kPreintTimeout = 50000;
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 @@ -234,12 +238,12 @@ static int SetAvailableVf(void) {
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) {
std::string timeoutPath = kTimeoutPath;
timeoutPath.append(std::to_string(i) + kTimeoutPremptFile);
WriteSysFile(timeoutPath.c_str(), std::to_string(kPreintTimeout));
std::string timeoutPath = kDrmCard0Vf;
timeoutPath.append(std::to_string(i) + kGtPreemptTimeoutUs);
WriteSysFile(timeoutPath.c_str(), std::to_string(kPreemptTimeout));

std::string execQuantumPath = kTimeoutPath;
execQuantumPath.append(std::to_string(i) + kTimeoutExecQuantum);
std::string execQuantumPath = kDrmCard0Vf;
execQuantumPath.append(std::to_string(i) + kGtExecQuantumMs);
WriteSysFile(execQuantumPath.c_str(), std::to_string(kExecQuantum));
return i;
}
Expand Down Expand Up @@ -277,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 @@ -806,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

0 comments on commit 53f227d

Please sign in to comment.