Revert "feature: Remove support for min power limit property"

This reverts commit cb924cfe6e.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2024-03-07 20:04:43 +01:00
committed by Compute-Runtime-Automation
parent 10313b7b84
commit b44725b371
10 changed files with 437 additions and 28 deletions

View File

@@ -19,6 +19,33 @@
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;
@@ -37,7 +64,59 @@ ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
return result;
}
pProperties->maxLimit = pProperties->defaultLimit;
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);
return result;
}

View File

@@ -45,16 +45,19 @@ 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) {
@@ -63,6 +66,8 @@ 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 = 600000000;
constexpr uint32_t mockDefaultPowerLimitVal = 300000000;
constexpr uint64_t mockMinPowerLimitVal = 300000000;
constexpr uint64_t mockMaxPowerLimitVal = 600000000;

View File

@@ -100,11 +100,36 @@ 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>(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, static_cast<int32_t>(mockMinPowerLimitVal / milliFactor));
}
}
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);
@@ -123,8 +148,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)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
EXPECT_TRUE(defaultLimit.limitValueLocked);
EXPECT_TRUE(defaultLimit.enabledStateLocked);
@@ -152,8 +177,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)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
}
}
@@ -169,6 +194,102 @@ 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)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
}
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)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
}
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)(mockDefaultPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, -1);
EXPECT_EQ(properties.maxLimit, (int32_t)(mockMaxPowerLimitVal / milliFactor));
EXPECT_EQ(properties.minLimit, (int32_t)(mockMinPowerLimitVal / milliFactor));
}
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
}