Add support for hwmon interface for sysman power
Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
parent
229ab9e30c
commit
0f2754e943
|
@ -6,8 +6,8 @@
|
|||
|
||||
set(L0_SRCS_TOOLS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/os_power_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/os_power_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.h
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
|
|
|
@ -14,6 +14,18 @@
|
|||
|
||||
namespace L0 {
|
||||
|
||||
const std::string LinuxPowerImp::hwmonDir("device/hwmon");
|
||||
const std::string LinuxPowerImp::i915("i915");
|
||||
const std::string LinuxPowerImp::sustainedPowerLimitEnabled("power1_max_enable");
|
||||
const std::string LinuxPowerImp::sustainedPowerLimit("power1_max");
|
||||
const std::string LinuxPowerImp::sustainedPowerLimitInterval("power1_max_interval");
|
||||
const std::string LinuxPowerImp::burstPowerLimitEnabled("power1_cap_enable");
|
||||
const std::string LinuxPowerImp::burstPowerLimit("power1_cap");
|
||||
const std::string LinuxPowerImp::energyCounterNode("energy1_input");
|
||||
const std::string LinuxPowerImp::defaultPowerLimit("power_default_limit");
|
||||
const std::string LinuxPowerImp::minPowerLimit("power_min_limit");
|
||||
const std::string LinuxPowerImp::maxPowerLimit("power_max_limit");
|
||||
|
||||
void powerGetTimestamp(uint64_t ×tamp) {
|
||||
std::chrono::time_point<std::chrono::steady_clock> ts = std::chrono::steady_clock::now();
|
||||
timestamp = std::chrono::duration_cast<std::chrono::microseconds>(ts.time_since_epoch()).count();
|
||||
|
@ -22,27 +34,133 @@ void powerGetTimestamp(uint64_t ×tamp) {
|
|||
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
|
||||
pProperties->onSubdevice = false;
|
||||
pProperties->subdeviceId = 0;
|
||||
pProperties->canControl = canControl;
|
||||
pProperties->isEnergyThresholdSupported = false;
|
||||
pProperties->defaultLimit = -1;
|
||||
pProperties->minLimit = -1;
|
||||
pProperties->maxLimit = -1;
|
||||
|
||||
uint32_t val = 0;
|
||||
auto result = pSysfsAccess->read(i915HwmonDir + "/" + defaultPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS == result) {
|
||||
pProperties->defaultLimit = static_cast<int32_t>(val / milliFactor); // need to convert from microwatt to milliwatt
|
||||
}
|
||||
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + minPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS == result) {
|
||||
pProperties->minLimit = static_cast<int32_t>(val / milliFactor); // need to convert from microwatt to milliwatt
|
||||
}
|
||||
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + maxPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS == result && val != std::numeric_limits<uint32_t>::max()) {
|
||||
pProperties->maxLimit = static_cast<int32_t>(val / milliFactor); // need to convert from microwatt to milliwatt
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
const std::string key("PACKAGE_ENERGY");
|
||||
uint64_t energy = 0;
|
||||
ze_result_t result = pPmt->readValue(key, energy);
|
||||
// PMT will return in joules and need to convert into microjoules
|
||||
pEnergy->energy = energy * convertJouleToMicroJoule;
|
||||
|
||||
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
const std::string key("PACKAGE_ENERGY");
|
||||
uint64_t energy = 0;
|
||||
result = pPmt->readValue(key, energy);
|
||||
// PMT will return energy counter in Q20 format(fixed point representation) where first 20 bits(from LSB) represent decimal part and remaining integral part which is converted into joule by division with 1048576(2^20) and then converted into microjoules
|
||||
pEnergy->energy = (energy / 1048576) * convertJouleToMicroJoule;
|
||||
}
|
||||
powerGetTimestamp(pEnergy->timestamp);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
|
||||
uint64_t val = 0;
|
||||
if (pSustained != nullptr) {
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimitEnabled, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
pSustained->enabled = static_cast<ze_bool_t>(val);
|
||||
|
||||
if (pSustained->enabled) {
|
||||
val = 0;
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
val /= milliFactor; // Convert microWatts to milliwatts
|
||||
pSustained->power = static_cast<int32_t>(val);
|
||||
|
||||
val = 0;
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimitInterval, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
pSustained->interval = static_cast<int32_t>(val);
|
||||
}
|
||||
}
|
||||
if (pBurst != nullptr) {
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + burstPowerLimitEnabled, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
pBurst->enabled = static_cast<ze_bool_t>(val);
|
||||
|
||||
if (pBurst->enabled) {
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + burstPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
val /= milliFactor; // Convert microWatts to milliwatts
|
||||
pBurst->power = static_cast<int32_t>(val);
|
||||
}
|
||||
}
|
||||
if (pPeak != nullptr) {
|
||||
pPeak->powerAC = -1;
|
||||
pPeak->powerDC = -1;
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::setLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
|
||||
int32_t val = 0;
|
||||
if (pSustained != nullptr) {
|
||||
uint64_t isSustainedPowerLimitEnabled = 0;
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimitEnabled, isSustainedPowerLimitEnabled);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
|
||||
if (isSustainedPowerLimitEnabled) {
|
||||
val = static_cast<uint32_t>(pSustained->power) * milliFactor; // Convert milliWatts to microwatts
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + sustainedPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + sustainedPowerLimitInterval, pSustained->interval);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pBurst != nullptr) {
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + burstPowerLimitEnabled, static_cast<int>(pBurst->enabled));
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
|
||||
if (pBurst->enabled) {
|
||||
val = static_cast<uint32_t>(pBurst->power) * milliFactor; // Convert milliWatts to microwatts
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + burstPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getEnergyThreshold(zes_energy_threshold_t *pThreshold) {
|
||||
|
@ -54,13 +172,36 @@ ze_result_t LinuxPowerImp::setEnergyThreshold(double threshold) {
|
|||
}
|
||||
|
||||
bool LinuxPowerImp::isPowerModuleSupported() {
|
||||
return (pPmt != nullptr);
|
||||
std::vector<std::string> listOfAllHwmonDirs = {};
|
||||
bool hwmonDirExists = false;
|
||||
if (ZE_RESULT_SUCCESS != pSysfsAccess->scanDirEntries(hwmonDir, listOfAllHwmonDirs)) {
|
||||
hwmonDirExists = false;
|
||||
}
|
||||
for (const auto &tempHwmonDirEntry : listOfAllHwmonDirs) {
|
||||
const std::string i915NameFile = hwmonDir + "/" + tempHwmonDirEntry + "/" + "name";
|
||||
std::string name;
|
||||
if (ZE_RESULT_SUCCESS != pSysfsAccess->read(i915NameFile, name)) {
|
||||
continue;
|
||||
}
|
||||
if (name == i915) {
|
||||
i915HwmonDir = hwmonDir + "/" + tempHwmonDirEntry;
|
||||
hwmonDirExists = true;
|
||||
canControl = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hwmonDirExists == false) {
|
||||
return (pPmt != nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LinuxPowerImp::LinuxPowerImp(OsSysman *pOsSysman) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
// Lets hardcode subDeviceId to 0, as we are expecting this code to execute on device without subdevice
|
||||
uint32_t subDeviceId = 0;
|
||||
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId);
|
||||
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
|
||||
}
|
||||
|
||||
OsPower *OsPower::create(OsSysman *pOsSysman) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "level_zero/tools/source/sysman/power/os_power.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
|
@ -32,5 +33,28 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
|
|||
|
||||
protected:
|
||||
PlatformMonitoringTech *pPmt = nullptr;
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
|
||||
private:
|
||||
std::string i915HwmonDir;
|
||||
static const std::string hwmonDir;
|
||||
static const std::string i915;
|
||||
static const std::string sustainedPowerLimitEnabled;
|
||||
static const std::string sustainedPowerLimit;
|
||||
static const std::string sustainedPowerLimitInterval;
|
||||
static const std::string burstPowerLimitEnabled;
|
||||
static const std::string burstPowerLimit;
|
||||
static const std::string energyCounterNode;
|
||||
static const std::string defaultPowerLimit;
|
||||
static const std::string minPowerLimit;
|
||||
static const std::string maxPowerLimit;
|
||||
bool canControl = false;
|
||||
|
||||
ze_result_t getErrorCode(ze_result_t result) {
|
||||
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {
|
||||
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace L0
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
set(L0_TESTS_TOOLS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/test_zes_power.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mock_sysfs_power.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_power.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysfs_power.h
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
|
|
|
@ -17,11 +17,223 @@
|
|||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
constexpr uint64_t setEnergyCounter = 83456;
|
||||
constexpr uint64_t setEnergyCounter = (83456u * 1048576u);
|
||||
constexpr uint64_t offset = 0x400;
|
||||
constexpr uint64_t mappedLength = 2048;
|
||||
const std::string deviceName("device");
|
||||
const std::string baseTelemSysFS("/sys/class/intel_pmt");
|
||||
const std::string hwmonDir("device/hwmon");
|
||||
const std::string i915HwmonDir("device/hwmon/hwmon4");
|
||||
const std::string nonI915HwmonDir("device/hwmon/hwmon1");
|
||||
const std::vector<std::string> listOfMockedHwmonDirs = {"hwmon1", "hwmon2", "hwmon3", "hwmon4"};
|
||||
const std::string sustainedPowerLimitEnabled("power1_max_enable");
|
||||
const std::string sustainedPowerLimit("power1_max");
|
||||
const std::string sustainedPowerLimitInterval("power1_max_interval");
|
||||
const std::string burstPowerLimitEnabled("power1_cap_enable");
|
||||
const std::string burstPowerLimit("power1_cap");
|
||||
const std::string energyCounterNode("energy1_input");
|
||||
const std::string defaultPowerLimit("power_default_limit");
|
||||
const std::string minPowerLimit("power_min_limit");
|
||||
const std::string maxPowerLimit("power_max_limit");
|
||||
constexpr uint64_t expectedEnergyCounter = 123456785u;
|
||||
constexpr uint32_t mockDefaultPowerLimitVal = 300000000;
|
||||
constexpr uint32_t mockMaxPowerLimitVal = 490000000;
|
||||
constexpr uint32_t mockMinPowerLimitVal = 0;
|
||||
class PowerSysfsAccess : public SysfsAccess {};
|
||||
|
||||
template <>
|
||||
struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
|
||||
|
||||
ze_result_t getValString(const std::string file, std::string &val) {
|
||||
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
|
||||
if (file.compare(i915HwmonDir + "/" + "name") == 0) {
|
||||
val = "i915";
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
} else if (file.compare(nonI915HwmonDir + "/" + "name") == 0) {
|
||||
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
} else {
|
||||
val = "garbageI915";
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t sustainedPowerLimitEnabledVal = 1u;
|
||||
uint64_t sustainedPowerLimitVal = 0;
|
||||
uint64_t sustainedPowerLimitIntervalVal = 0;
|
||||
uint64_t burstPowerLimitEnabledVal = 0;
|
||||
uint64_t burstPowerLimitVal = 0;
|
||||
uint64_t energyCounterNodeVal = expectedEnergyCounter;
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorForEnergyCounter(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + energyCounterNode) == 0) {
|
||||
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorForBurstPowerLimit(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
val = burstPowerLimitEnabledVal;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorForBurstPowerLimitEnabled(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE; // mocking the condition when user passes nullptr for sustained and peak power in zesPowerGetLimit and burst power file is absent
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorForSustainedPowerLimitEnabled(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE; // mocking the condition when user passes nullptr for burst and peak power in zesPowerGetLimit and sustained power file is absent
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnsPowerLimitEnabledAsDisabled(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
val = 0;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
val = 0;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorForSustainedPower(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
val = 1;
|
||||
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorForSustainedPowerInterval(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
val = 1;
|
||||
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLongReturnErrorUnknown(const std::string file, uint64_t &val) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
ze_result_t setValUnsignedLongReturnErrorForBurstPowerLimit(const std::string file, const int val) {
|
||||
if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t setValUnsignedLongReturnErrorForBurstPowerLimitEnabled(const std::string file, const int val) {
|
||||
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t setValReturnErrorForSustainedPower(const std::string file, const int val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t setValReturnErrorForSustainedPowerInterval(const std::string file, const int val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedLong(const std::string file, uint64_t &val) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
val = sustainedPowerLimitEnabledVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
|
||||
val = sustainedPowerLimitVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
|
||||
val = sustainedPowerLimitIntervalVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
val = burstPowerLimitEnabledVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
|
||||
val = burstPowerLimitVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + energyCounterNode) == 0) {
|
||||
val = energyCounterNodeVal;
|
||||
} else {
|
||||
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedInt(const std::string file, uint32_t &val) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (file.compare(i915HwmonDir + "/" + defaultPowerLimit) == 0) {
|
||||
val = mockDefaultPowerLimitVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + maxPowerLimit) == 0) {
|
||||
val = mockMaxPowerLimitVal;
|
||||
} else if (file.compare(i915HwmonDir + "/" + minPowerLimit) == 0) {
|
||||
val = mockMinPowerLimitVal;
|
||||
} else {
|
||||
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t getValUnsignedIntMax(const std::string file, uint32_t &val) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (file.compare(i915HwmonDir + "/" + maxPowerLimit) == 0) {
|
||||
val = std::numeric_limits<uint32_t>::max();
|
||||
} else {
|
||||
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t setVal(const std::string file, const int val) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
|
||||
sustainedPowerLimitVal = static_cast<uint64_t>(val);
|
||||
} else if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
|
||||
sustainedPowerLimitIntervalVal = static_cast<uint64_t>(val);
|
||||
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
burstPowerLimitEnabledVal = static_cast<uint64_t>(val);
|
||||
} else if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
|
||||
burstPowerLimitVal = static_cast<uint64_t>(val);
|
||||
} else {
|
||||
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
ze_result_t getscanDirEntries(const std::string file, std::vector<std::string> &listOfEntries) {
|
||||
if (file.compare(hwmonDir) == 0) {
|
||||
listOfEntries = listOfMockedHwmonDirs;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
ze_result_t getscanDirEntriesStatusReturnError(const std::string file, std::vector<std::string> &listOfEntries) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
Mock<PowerSysfsAccess>() = default;
|
||||
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, uint64_t &val), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, std::string &val), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, uint32_t &val), (override));
|
||||
MOCK_METHOD(ze_result_t, write, (const std::string file, const int val), (override));
|
||||
MOCK_METHOD(ze_result_t, scanDirEntries, (const std::string file, std::vector<std::string> &listOfEntries), (override));
|
||||
};
|
||||
|
||||
class PowerPmt : public PlatformMonitoringTech {
|
||||
public:
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
#include "mock_sysfs_power.h"
|
||||
#include "sysman/power/power_imp.h"
|
||||
|
||||
using ::testing::DoDefault;
|
||||
using ::testing::Matcher;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
|
@ -29,6 +33,8 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
|
|||
std::unique_ptr<PublicLinuxPowerImp> pPublicLinuxPowerImp;
|
||||
std::unique_ptr<Mock<PowerPmt>> pPmt;
|
||||
std::unique_ptr<Mock<PowerFsAccess>> pFsAccess;
|
||||
std::unique_ptr<Mock<PowerSysfsAccess>> pSysfsAccess;
|
||||
SysfsAccess *pSysfsAccessOld = nullptr;
|
||||
FsAccess *pFsAccessOriginal = nullptr;
|
||||
OsPower *pOsPowerOriginal = nullptr;
|
||||
std::vector<ze_device_handle_t> deviceHandles;
|
||||
|
@ -37,10 +43,23 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
|
|||
pFsAccess = std::make_unique<NiceMock<Mock<PowerFsAccess>>>();
|
||||
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
|
||||
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess;
|
||||
pSysfsAccess = std::make_unique<NiceMock<Mock<PowerSysfsAccess>>>();
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
|
||||
ON_CALL(*pFsAccess.get(), listDirectory(_, _))
|
||||
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<PowerFsAccess>::listDirectorySuccess));
|
||||
ON_CALL(*pFsAccess.get(), getRealPath(_, _))
|
||||
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<PowerFsAccess>::getRealPathSuccess));
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<std::string &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValString));
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLong));
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint32_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedInt));
|
||||
ON_CALL(*pSysfsAccess.get(), write(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::setVal));
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntries));
|
||||
|
||||
uint32_t subDeviceCount = 0;
|
||||
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr);
|
||||
|
@ -66,22 +85,340 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
|
|||
void TearDown() override {
|
||||
SysmanDeviceFixture::TearDown();
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld;
|
||||
}
|
||||
|
||||
std::vector<zes_pwr_handle_t> get_power_handles(uint32_t count) {
|
||||
std::vector<zes_pwr_handle_t> getPowerHandles(uint32_t count) {
|
||||
std::vector<zes_pwr_handle_t> handles(count, nullptr);
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
|
||||
return handles;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
|
||||
count = count + 1;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidPowerHandlesIsReturned) {
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
|
||||
std::vector<zes_pwr_handle_t> handles(count, nullptr);
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_NE(handle, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenhwmonInterfaceExistsThenCallSucceeds) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
EXPECT_FALSE(properties.onSubdevice);
|
||||
EXPECT_EQ(properties.subdeviceId, 0u);
|
||||
EXPECT_EQ(properties.canControl, true);
|
||||
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
|
||||
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
|
||||
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
|
||||
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenLimitsReturnsUnkown) {
|
||||
|
||||
EXPECT_CALL(*pSysfsAccess.get(), read(_, Matcher<uint32_t &>(_)))
|
||||
.WillRepeatedly(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
EXPECT_FALSE(properties.onSubdevice);
|
||||
EXPECT_EQ(properties.subdeviceId, 0u);
|
||||
EXPECT_EQ(properties.defaultLimit, -1);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenMaxLimitIsUnsupported) {
|
||||
|
||||
EXPECT_CALL(*pSysfsAccess.get(), read(_, Matcher<uint32_t &>(_)))
|
||||
.WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE))
|
||||
.WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE))
|
||||
.WillOnce(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedIntMax))
|
||||
.WillRepeatedly(DoDefault());
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
EXPECT_FALSE(properties.onSubdevice);
|
||||
EXPECT_EQ(properties.subdeviceId, 0u);
|
||||
EXPECT_EQ(properties.defaultLimit, -1);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenHwmonInterfaceExistThenValidPowerReadingsRetrieved) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_energy_counter_t energyCounter = {};
|
||||
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
|
||||
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorForEnergyCounter));
|
||||
for (auto handle : handles) {
|
||||
zes_power_energy_counter_t energyCounter = {};
|
||||
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
|
||||
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
|
||||
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenSetPowerLimitsWhenGettingPowerLimitsWhenHwmonInterfaceExistThenLimitsSetEarlierAreRetrieved) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
sustainedSet.interval = 10;
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, &sustainedSet, nullptr, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
|
||||
EXPECT_EQ(sustainedGet.power, sustainedSet.power);
|
||||
EXPECT_EQ(sustainedGet.interval, sustainedSet.interval);
|
||||
|
||||
zes_power_burst_limit_t burstSet = {};
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
burstSet.enabled = 1;
|
||||
burstSet.power = 375000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
EXPECT_EQ(burstSet.enabled, burstGet.enabled);
|
||||
EXPECT_EQ(burstSet.power, burstGet.power);
|
||||
|
||||
burstSet.enabled = 0;
|
||||
burstGet.enabled = 0;
|
||||
burstGet.power = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
EXPECT_EQ(burstSet.enabled, burstGet.enabled);
|
||||
EXPECT_EQ(burstGet.power, 0);
|
||||
|
||||
zes_power_peak_limit_t peakGet = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
|
||||
EXPECT_EQ(peakGet.powerAC, -1);
|
||||
EXPECT_EQ(peakGet.powerDC, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsReturnErrorWhenGettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
EXPECT_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillOnce(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorForBurstPowerLimit))
|
||||
.WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));
|
||||
for (auto handle : handles) {
|
||||
zes_power_burst_limit_t burstSet = {};
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
burstSet.enabled = 1;
|
||||
burstSet.power = 375000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsReturnErrorWhenGettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesIsReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorUnknown));
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_burst_limit_t burstSet = {};
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
burstSet.enabled = 1;
|
||||
burstSet.power = 375000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenSetPowerLimitsReturnErrorWhenSettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), write(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::setValUnsignedLongReturnErrorForBurstPowerLimit));
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_burst_limit_t burstSet = {};
|
||||
burstSet.enabled = 1;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenSetPowerLimitsReturnErrorWhenSettingPowerLimitsWhenHwmonInterfaceExistForBurstPowerLimitEnabledThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), write(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::setValUnsignedLongReturnErrorForBurstPowerLimitEnabled));
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorForBurstPowerLimitEnabled));
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_burst_limit_t burstSet = {};
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
burstSet.enabled = 1;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, nullptr, &burstSet, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerLimitNodeReturnErrorWhenSetOrGetPowerLimitsWhenHwmonInterfaceExistForSustainedPowerLimitEnabledThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorForSustainedPowerLimitEnabled));
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, &sustainedSet, nullptr, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorForSustainedPower));
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerIntervalNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnErrorForSustainedPowerInterval));
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenwritingSustainedPowerNodeReturnErrorWhenSetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), write(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::setValReturnErrorForSustainedPower));
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.interval = 10;
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenwritingSustainedPowerIntervalNodeReturnErrorWhenSetPowerLimitsForSustainedPowerIntervalWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), write(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::setValReturnErrorForSustainedPowerInterval));
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.interval = 10;
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsWhenPowerLimitsAreDisabledWhenHwmonInterfaceExistThenAllPowerValuesAreIgnored) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
ON_CALL(*pSysfsAccess.get(), read(_, Matcher<uint64_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getValUnsignedLongReturnsPowerLimitEnabledAsDisabled));
|
||||
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], &sustainedGet, nullptr, nullptr));
|
||||
EXPECT_EQ(sustainedGet.interval, 0);
|
||||
EXPECT_EQ(sustainedGet.power, 0);
|
||||
EXPECT_EQ(sustainedGet.enabled, 0);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], nullptr, &burstGet, nullptr));
|
||||
EXPECT_EQ(burstGet.enabled, 0);
|
||||
EXPECT_EQ(burstGet.power, 0);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedGet, nullptr, nullptr));
|
||||
zes_power_burst_limit_t burstSet = {};
|
||||
burstSet.enabled = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], nullptr, &burstSet, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenScanDiectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) {
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
PublicLinuxPowerImp *pPowerImp = new PublicLinuxPowerImp(pOsSysman);
|
||||
EXPECT_TRUE(pPowerImp->isPowerModuleSupported());
|
||||
delete pPowerImp;
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
|
@ -92,6 +429,13 @@ TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerD
|
|||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidPowerHandlesIsReturned) {
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
|
@ -104,7 +448,14 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
|
|||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesThenCallSucceeds) {
|
||||
auto handles = get_power_handles(powerHandleComponentCount);
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties;
|
||||
|
@ -115,34 +466,62 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
|
|||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
|
||||
auto handles = get_power_handles(powerHandleComponentCount);
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_energy_counter_t energyCounter;
|
||||
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * setEnergyCounter;
|
||||
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
|
||||
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
|
||||
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
zes_energy_threshold_t threshold;
|
||||
auto handles = get_power_handles(powerHandleComponentCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetEnergyThreshold(handle, &threshold));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
double threshold = 0;
|
||||
auto handles = get_power_handles(powerHandleComponentCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetEnergyThreshold(handle, threshold));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
|
||||
auto handles = get_power_handles(powerHandleComponentCount);
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustained;
|
||||
zes_power_burst_limit_t burst;
|
||||
|
@ -152,7 +531,14 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThen
|
|||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
|
||||
auto handles = get_power_handles(powerHandleComponentCount);
|
||||
ON_CALL(*pSysfsAccess.get(), scanDirEntries(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PowerSysfsAccess>::getscanDirEntriesStatusReturnError));
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init();
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustained;
|
||||
zes_power_burst_limit_t burst;
|
||||
|
|
Loading…
Reference in New Issue