feature: Remove support for min power limit property

Max limit to be same as default power limit.

Related-To: NEO-10525

Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
Bellekallu Rajkiran 2024-03-08 16:46:46 +00:00 committed by Compute-Runtime-Automation
parent 8520181008
commit 072304296c
10 changed files with 28 additions and 437 deletions

View File

@ -19,33 +19,6 @@
namespace L0 {
namespace Sysman {
class LinuxPowerImp::PowerLimitRestorer : NEO::NonCopyableOrMovableClass {
public:
PowerLimitRestorer(L0::Sysman::SysFsAccessInterface *pSysfsAccess, std::string powerLimit) : pSysfsAccess(pSysfsAccess), powerLimit(powerLimit) {
result = pSysfsAccess->read(powerLimit, powerLimitValue);
}
~PowerLimitRestorer() {
if (result == ZE_RESULT_SUCCESS) {
result = pSysfsAccess->write(powerLimit, powerLimitValue);
DEBUG_BREAK_IF(result != ZE_RESULT_SUCCESS);
}
}
operator ze_result_t() const {
return result;
}
protected:
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
SysFsAccessInterface *pSysfsAccess = nullptr;
std::string powerLimit = {};
uint64_t powerLimitValue = 0;
};
std::unique_lock<std::mutex> LinuxPowerImp::obtainMutex() {
return std::unique_lock<std::mutex>(this->powerLimitMutex);
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@ -64,59 +37,7 @@ ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
return result;
}
auto lock = this->obtainMutex();
auto powerLimitRestorer = L0::Sysman::LinuxPowerImp::PowerLimitRestorer(pSysfsAccess, sustainedPowerLimit);
if (powerLimitRestorer != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(powerLimitRestorer));
return getErrorCode(powerLimitRestorer);
}
result = getMinLimit(pProperties->minLimit);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
return getMaxLimit(pProperties->maxLimit);
}
ze_result_t LinuxPowerImp::getMinLimit(int32_t &minLimit) {
// Fw clamps to minimum value if power limit requested to set is less than min limit, Set to 100 micro watt to get min limit
uint64_t powerLimit = 100;
auto result = pSysfsAccess->write(sustainedPowerLimit, powerLimit);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
result = pSysfsAccess->read(sustainedPowerLimit, powerLimit);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
pSysmanKmdInterface->convertSysfsValueUnit(SysmanKmdInterface::milli, pSysmanKmdInterface->getNativeUnit(SysfsName::sysfsNameSustainedPowerLimit), powerLimit, powerLimit);
minLimit = static_cast<int32_t>(powerLimit);
return result;
}
ze_result_t LinuxPowerImp::getMaxLimit(int32_t &maxLimit) {
// Fw clamps to maximum value if power limit requested to set is greater than max limit, Set to max value to get max limit
uint64_t powerLimit = std::numeric_limits<int32_t>::max();
auto result = pSysfsAccess->write(sustainedPowerLimit, powerLimit);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
result = pSysfsAccess->read(sustainedPowerLimit, powerLimit);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
pSysmanKmdInterface->convertSysfsValueUnit(SysmanKmdInterface::milli, pSysmanKmdInterface->getNativeUnit(SysfsName::sysfsNameSustainedPowerLimit), powerLimit, powerLimit);
maxLimit = static_cast<int32_t>(powerLimit);
pProperties->maxLimit = pProperties->defaultLimit;
return result;
}

View File

@ -45,19 +45,16 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
SysFsAccessInterface *pSysfsAccess = nullptr;
SysmanKmdInterface *pSysmanKmdInterface = nullptr;
SysmanProductHelper *pSysmanProductHelper = nullptr;
virtual std::unique_lock<std::mutex> obtainMutex();
private:
std::string intelGraphicsHwmonDir = {};
std::string criticalPowerLimit = {};
std::string sustainedPowerLimit = {};
std::string sustainedPowerLimitInterval = {};
std::mutex powerLimitMutex{};
bool canControl = false;
bool isSubdevice = false;
uint32_t subdeviceId = 0;
uint32_t powerLimitCount = 0;
class PowerLimitRestorer;
ze_result_t getErrorCode(ze_result_t result) {
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {
@ -66,8 +63,6 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
return result;
}
ze_result_t getMinLimit(int32_t &minLimit);
ze_result_t getMaxLimit(int32_t &maxLimit);
ze_result_t getDefaultLimit(int32_t &defaultLimit);
};
} // namespace Sysman

View File

@ -41,7 +41,7 @@ const std::string defaultPowerLimit("power1_rated_max");
constexpr uint64_t expectedEnergyCounter = 123456785u;
constexpr uint64_t expectedEnergyCounterTile0 = 123456785u;
constexpr uint64_t expectedEnergyCounterTile1 = 128955785u;
constexpr uint32_t mockDefaultPowerLimitVal = 300000000;
constexpr uint32_t mockDefaultPowerLimitVal = 600000000;
constexpr uint64_t mockMinPowerLimitVal = 300000000;
constexpr uint64_t mockMaxPowerLimitVal = 600000000;

View File

@ -100,36 +100,11 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerProper
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
EXPECT_EQ(properties.defaultLimit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, static_cast<int32_t>(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidMockMutexPowerImpWhenGettingPowerPropertiesThenMutexLockCounterMatchesNumberOfGetCalls) {
class MockMutexPowerImp : public L0::Sysman::LinuxPowerImp {
public:
using L0::Sysman::LinuxPowerImp::pSysfsAccess;
MockMutexPowerImp(L0::Sysman::OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId) {}
uint32_t mutexLockCounter = 0;
std::unique_lock<std::mutex> obtainMutex() override {
mutexLockCounter++;
std::unique_lock<std::mutex> mutexLock = L0::Sysman::LinuxPowerImp::obtainMutex();
EXPECT_TRUE(mutexLock.owns_lock());
return mutexLock;
}
};
std::unique_ptr<MockMutexPowerImp> pLinuxPowerImp(new MockMutexPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
zes_power_properties_t properties{};
uint32_t testReadCount = 0;
for (uint32_t i = 0; i < testReadCount; i++) {
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
}
EXPECT_EQ(pLinuxPowerImp->mutexLockCounter, testReadCount);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndExtPropertiesThenCallSucceeds) {
auto handles = getPowerHandles(powerHandleComponentCount);
@ -148,8 +123,8 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerProper
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));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_TRUE(defaultLimit.limitValueLocked);
EXPECT_TRUE(defaultLimit.enabledStateLocked);
@ -177,8 +152,8 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWithNoStypeForExtPrope
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));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
}
@ -194,102 +169,6 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerProper
EXPECT_EQ(properties.defaultLimit, -1);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndSustainedLimitReadFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, -1);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndMinLimitReadFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.minLimit, -1);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndMaxLimitReadFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.maxLimit, -1);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndSysfsWriteForMinLimitFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.minLimit, -1);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndSysfsWriteForMaxLimitFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.maxLimit, -1);
}
HWTEST2_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerPropertiesAndSysfsWriteToOriginalLimitFailsThenVerifySustainedLimitIsMaximum, IsPVC) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess;
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
uint32_t limitCount = mockLimitCount;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
for (uint32_t i = 0; i < limitCount; i++) {
if (allLimits[i].level == ZES_POWER_LEVEL_SUSTAINED) {
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
EXPECT_EQ(allLimits[i].limit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
}
}
}
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();

View File

@ -67,8 +67,8 @@ TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGetti
} else {
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}
@ -101,8 +101,8 @@ TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGetti
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_EQ(defaultLimit.limit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}
@ -128,8 +128,8 @@ TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleAndExtPro
EXPECT_TRUE(properties.canControl);
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}

View File

@ -22,33 +22,6 @@ const std::string LinuxPowerImp::sustainedPowerLimitInterval("power1_max_interva
const std::string LinuxPowerImp::energyCounterNode("energy1_input");
const std::string LinuxPowerImp::defaultPowerLimit("power1_rated_max");
class LinuxPowerImp::PowerLimitRestorer : NEO::NonCopyableOrMovableClass {
public:
PowerLimitRestorer(SysfsAccess *pSysfsAccess, std::string powerLimit) : pSysfsAccess(pSysfsAccess), powerLimit(powerLimit) {
result = pSysfsAccess->read(powerLimit, powerLimitValue);
}
~PowerLimitRestorer() {
if (result == ZE_RESULT_SUCCESS) {
result = pSysfsAccess->write(powerLimit, powerLimitValue);
DEBUG_BREAK_IF(result != ZE_RESULT_SUCCESS);
}
}
operator ze_result_t() const {
return result;
}
protected:
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
SysfsAccess *pSysfsAccess = nullptr;
std::string powerLimit = {};
uint64_t powerLimitValue = 0;
};
std::unique_lock<std::mutex> LinuxPowerImp::obtainMutex() {
return std::unique_lock<std::mutex>(this->powerLimitMutex);
}
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
pProperties->onSubdevice = isSubdevice;
pProperties->subdeviceId = subdeviceId;
@ -67,61 +40,8 @@ ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
return result;
}
std::string sustainedLimit = i915HwmonDir + "/" + sustainedPowerLimit;
auto lock = this->obtainMutex();
auto powerLimitRestorer = L0::LinuxPowerImp::PowerLimitRestorer(pSysfsAccess, sustainedLimit); // 600
if (powerLimitRestorer != ZE_RESULT_SUCCESS) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(powerLimitRestorer));
return getErrorCode(powerLimitRestorer);
}
pProperties->maxLimit = pProperties->defaultLimit;
result = getMinLimit(pProperties->minLimit);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
return getMaxLimit(pProperties->maxLimit);
}
ze_result_t LinuxPowerImp::getMinLimit(int32_t &minLimit) {
// Fw clamps to minimum value if power limit requested to set is less than min limit, Set to 100 micro watt to get min limit
uint64_t powerLimit = 100;
std::string sustainedLimit = i915HwmonDir + "/" + sustainedPowerLimit;
auto result = pSysfsAccess->write(sustainedLimit, powerLimit);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
result = pSysfsAccess->read(sustainedLimit, powerLimit); // 300
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
// Values are retrieved from KMD in micro watts, Conversion to milli is required.
minLimit = static_cast<int32_t>(powerLimit / milliFactor);
return result;
}
ze_result_t LinuxPowerImp::getMaxLimit(int32_t &maxLimit) {
// Fw clamps to maximum value if power limit requested to set is greater than max limit, Set to max value to get max limit
uint64_t powerLimit = std::numeric_limits<int32_t>::max();
std::string sustainedLimit = i915HwmonDir + "/" + sustainedPowerLimit;
auto result = pSysfsAccess->write(sustainedLimit, powerLimit);
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to write %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
result = pSysfsAccess->read(sustainedLimit, powerLimit); // 600
if (ZE_RESULT_SUCCESS != result) {
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read %s and returning error:0x%x \n", __FUNCTION__, sustainedPowerLimit.c_str(), getErrorCode(result));
return getErrorCode(result);
}
// Values are retrieved from KMD in micro watts, Conversion to milli is required.
maxLimit = static_cast<int32_t>(powerLimit / milliFactor);
return result;
}

View File

@ -42,12 +42,10 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
protected:
PlatformMonitoringTech *pPmt = nullptr;
SysfsAccess *pSysfsAccess = nullptr;
virtual std::unique_lock<std::mutex> obtainMutex();
private:
std::string i915HwmonDir;
std::string criticalPowerLimit;
std::mutex powerLimitMutex{};
static const std::string hwmonDir;
static const std::string i915;
static const std::string sustainedPowerLimit;
@ -59,7 +57,6 @@ class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
uint32_t subdeviceId = 0;
uint32_t powerLimitCount = 0;
PRODUCT_FAMILY productFamily{};
class PowerLimitRestorer;
ze_result_t getErrorCode(ze_result_t result) {
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {

View File

@ -38,7 +38,7 @@ const std::string defaultPowerLimit("power1_rated_max");
constexpr uint64_t expectedEnergyCounter = 123456785u;
constexpr uint64_t expectedEnergyCounterTile0 = 123456785u;
constexpr uint64_t expectedEnergyCounterTile1 = 128955785u;
constexpr uint32_t mockDefaultPowerLimitVal = 300000000;
constexpr uint32_t mockDefaultPowerLimitVal = 600000000;
constexpr uint64_t mockMinPowerLimitVal = 300000000;
constexpr uint64_t mockMaxPowerLimitVal = 600000000;
const std::map<std::string, uint64_t> deviceKeyOffsetMapPower = {

View File

@ -70,8 +70,8 @@ TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGetti
} else {
EXPECT_EQ(properties.canControl, true);
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}
@ -104,8 +104,8 @@ TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGetti
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_EQ(defaultLimit.limit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}
@ -131,8 +131,8 @@ TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleAndExtPro
EXPECT_TRUE(properties.canControl);
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_EQ(properties.defaultLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}

View File

@ -116,36 +116,11 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
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));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidMockMutexPowerImpWhenGettingPowerPropertiesThenMutexLockCounterMatchesNumberOfGetCalls) {
class MockMutexPowerImp : public L0::LinuxPowerImp {
public:
using L0::LinuxPowerImp::pSysfsAccess;
MockMutexPowerImp(L0::OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId) {}
uint32_t mutexLockCounter = 0;
std::unique_lock<std::mutex> obtainMutex() override {
mutexLockCounter++;
std::unique_lock<std::mutex> mutexLock = L0::LinuxPowerImp::obtainMutex();
EXPECT_TRUE(mutexLock.owns_lock());
return mutexLock;
}
};
std::unique_ptr<MockMutexPowerImp> pLinuxPowerImp(new MockMutexPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
uint32_t testReadCount = 0;
zes_power_properties_t properties{};
for (uint32_t i = 0; i < testReadCount; i++) {
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
}
EXPECT_EQ(pLinuxPowerImp->mutexLockCounter, testReadCount);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndExtPropertiesThenCallSucceeds) {
auto handles = getPowerHandles(powerHandleComponentCount);
@ -164,15 +139,14 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
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));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_TRUE(defaultLimit.limitValueLocked);
EXPECT_TRUE(defaultLimit.enabledStateLocked);
EXPECT_TRUE(defaultLimit.intervalValueLocked);
EXPECT_EQ(ZES_POWER_SOURCE_ANY, defaultLimit.source);
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, defaultLimit.limitUnit);
EXPECT_EQ(defaultLimit.limit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
}
}
@ -193,8 +167,8 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWithNoStypeForExtPropertie
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));
EXPECT_EQ(properties.maxLimit, (int32_t)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
}
}
@ -210,101 +184,6 @@ TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerProperties
EXPECT_EQ(properties.defaultLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndSustainedLimitReadFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndMinLimitReadFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.minLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndMaxLimitReadFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.maxLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndSysfsWriteForMinLimitFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.minLimit, -1);
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndSysfsWriteForMaxLimitFailsThenFailureIsReturned) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxPowerImp->getProperties(&properties));
EXPECT_EQ(properties.maxLimit, -1);
}
HWTEST2_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndSysfsWriteToOriginalLimitFailsThenVerifySustainedLimitIsMaximum, IsPVC) {
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0));
pLinuxPowerImp->pSysfsAccess = pSysfsAccess.get();
pLinuxPowerImp->pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(0));
pLinuxPowerImp->isPowerModuleSupported();
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->mockWriteUnsignedResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_properties_t properties{};
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getProperties(&properties));
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
uint32_t limitCount = mockLimitCount;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
for (uint32_t i = 0; i < limitCount; i++) {
if (allLimits[i].level == ZES_POWER_LEVEL_SUSTAINED) {
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
EXPECT_EQ(allLimits[i].limit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
}
}
}
}
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
auto handles = getPowerHandles(powerHandleComponentCount);