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

@@ -22,6 +22,33 @@ 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;
@@ -40,8 +67,61 @@ ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
return result;
}
pProperties->maxLimit = pProperties->defaultLimit;
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);
}
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,10 +42,12 @@ 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;
@@ -57,6 +59,7 @@ 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) {