mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Added support for Power APIs
- Added support for the Power APIs in the new sysman design. - Added ULTs for the Power APIs in the new sysman design. - Added change to measure the average power in the black box test for Power. Related-To: LOCI-3891 Signed-off-by: Bari, Pratik <pratik.bari@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
790ef57c3f
commit
adbda5906a
25
level_zero/sysman/source/power/CMakeLists.txt
Normal file
25
level_zero/sysman/source/power/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Copyright (C) 2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_SYSMAN_POWER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/power.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/power.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/power_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/power_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power.h
|
||||
)
|
||||
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_SYSMAN_POWER}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_SYSMAN_POWER ${L0_SRCS_SYSMAN_POWER})
|
||||
|
||||
32
level_zero/sysman/source/power/linux/CMakeLists.txt
Normal file
32
level_zero/sysman/source/power/linux/CMakeLists.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright (C) 2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
if(NEO_ENABLE_i915_PRELIM_DETECTION)
|
||||
list(APPEND L0_SRCS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp_prelim.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp_prelim.h
|
||||
|
||||
)
|
||||
else()
|
||||
list(APPEND L0_SRCS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.h
|
||||
)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_SYSMAN_POWER_LINUX}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_SYSMAN_POWER_LINUX ${L0_SRCS_SYSMAN_POWER_LINUX})
|
||||
246
level_zero/sysman/source/power/linux/os_power_imp.cpp
Normal file
246
level_zero/sysman/source/power/linux/os_power_imp.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/source/power/linux/os_power_imp.h"
|
||||
|
||||
#include "level_zero/sysman/source/linux/os_sysman_imp.h"
|
||||
#include "level_zero/sysman/source/linux/pmt/pmt.h"
|
||||
#include "level_zero/sysman/source/sysman_const.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
|
||||
pProperties->onSubdevice = isSubdevice;
|
||||
pProperties->subdeviceId = subdeviceId;
|
||||
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 && val != 0) {
|
||||
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::getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
const std::string key("PACKAGE_ENERGY");
|
||||
uint64_t energy = 0;
|
||||
constexpr uint64_t fixedPointToJoule = 1048576;
|
||||
ze_result_t 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 / fixedPointToJoule) * convertJouleToMicroJoule;
|
||||
return result;
|
||||
}
|
||||
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
powerGetTimestamp(pEnergy->timestamp);
|
||||
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
if (pPmt != nullptr) {
|
||||
return getPmtEnergyCounter(pEnergy);
|
||||
}
|
||||
}
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
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 != static_cast<uint64_t>(pSustained->enabled)) {
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + sustainedPowerLimitEnabled, static_cast<int>(pSustained->enabled));
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
isSustainedPowerLimitEnabled = static_cast<uint64_t>(pSustained->enabled);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
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) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::setEnergyThreshold(double threshold) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
bool LinuxPowerImp::isHwmonDir(std::string name) {
|
||||
if (isSubdevice == false && (name == i915)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxPowerImp::isPowerModuleSupported() {
|
||||
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 (isHwmonDir(name)) {
|
||||
i915HwmonDir = hwmonDir + "/" + tempHwmonDirEntry;
|
||||
hwmonDirExists = true;
|
||||
canControl = true;
|
||||
}
|
||||
}
|
||||
if (hwmonDirExists == false) {
|
||||
return (pPmt != nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LinuxPowerImp::LinuxPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId);
|
||||
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
|
||||
}
|
||||
|
||||
OsPower *OsPower::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
|
||||
LinuxPowerImp *pLinuxPowerImp = new LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId);
|
||||
return static_cast<OsPower *>(pLinuxPowerImp);
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
70
level_zero/sysman/source/power/linux/os_power_imp.h
Normal file
70
level_zero/sysman/source/power/linux/os_power_imp.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/sysman/source/power/os_power.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
class SysfsAccess;
|
||||
class PlatformMonitoringTech;
|
||||
class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t getProperties(zes_power_properties_t *pProperties) override;
|
||||
ze_result_t getEnergyCounter(zes_power_energy_counter_t *pEnergy) override;
|
||||
ze_result_t getLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t setLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t getEnergyThreshold(zes_energy_threshold_t *pThreshold) override;
|
||||
ze_result_t setEnergyThreshold(double threshold) override;
|
||||
ze_result_t getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) override;
|
||||
|
||||
bool isPowerModuleSupported() override;
|
||||
bool isHwmonDir(std::string name);
|
||||
ze_result_t getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy);
|
||||
LinuxPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
|
||||
LinuxPowerImp() = default;
|
||||
~LinuxPowerImp() override = default;
|
||||
|
||||
protected:
|
||||
PlatformMonitoringTech *pPmt = nullptr;
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
|
||||
private:
|
||||
std::string i915HwmonDir;
|
||||
std::string energyHwmonDir;
|
||||
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;
|
||||
bool isSubdevice = false;
|
||||
uint32_t subdeviceId = 0;
|
||||
|
||||
ze_result_t getErrorCode(ze_result_t result) {
|
||||
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {
|
||||
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
314
level_zero/sysman/source/power/linux/os_power_imp_prelim.cpp
Normal file
314
level_zero/sysman/source/power/linux/os_power_imp_prelim.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/source/power/linux/os_power_imp_prelim.h"
|
||||
|
||||
#include "level_zero/sysman/source/linux/os_sysman_imp.h"
|
||||
#include "level_zero/sysman/source/linux/pmt/pmt.h"
|
||||
#include "level_zero/sysman/source/sysman_const.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
const std::string LinuxPowerImp::hwmonDir("device/hwmon");
|
||||
const std::string LinuxPowerImp::i915("i915");
|
||||
const std::string LinuxPowerImp::sustainedPowerLimit("power1_max");
|
||||
const std::string LinuxPowerImp::sustainedPowerLimitInterval("power1_max_interval");
|
||||
const std::string LinuxPowerImp::energyCounterNode("energy1_input");
|
||||
const std::string LinuxPowerImp::defaultPowerLimit("power1_rated_max");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getProperties(zes_power_properties_t *pProperties) {
|
||||
pProperties->onSubdevice = isSubdevice;
|
||||
pProperties->subdeviceId = subdeviceId;
|
||||
pProperties->canControl = canControl;
|
||||
pProperties->isEnergyThresholdSupported = false;
|
||||
pProperties->defaultLimit = -1;
|
||||
pProperties->minLimit = -1;
|
||||
pProperties->maxLimit = -1;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) {
|
||||
pExtPoperties->domain = isSubdevice ? ZES_POWER_DOMAIN_PACKAGE : ZES_POWER_DOMAIN_CARD;
|
||||
if (pExtPoperties->defaultLimit) {
|
||||
if (!isSubdevice) {
|
||||
uint32_t val = 0;
|
||||
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + defaultPowerLimit, val);
|
||||
if (result == ZE_RESULT_SUCCESS) {
|
||||
pExtPoperties->defaultLimit->limit = static_cast<int32_t>(val / milliFactor); // need to convert from microwatt to milliwatt
|
||||
} else {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
} else {
|
||||
pExtPoperties->defaultLimit->limit = -1;
|
||||
}
|
||||
pExtPoperties->defaultLimit->limitUnit = ZES_LIMIT_UNIT_POWER;
|
||||
pExtPoperties->defaultLimit->enabledStateLocked = true;
|
||||
pExtPoperties->defaultLimit->intervalValueLocked = true;
|
||||
pExtPoperties->defaultLimit->limitValueLocked = true;
|
||||
pExtPoperties->defaultLimit->source = ZES_POWER_SOURCE_ANY;
|
||||
pExtPoperties->defaultLimit->level = ZES_POWER_LEVEL_UNKNOWN;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
const std::string key("PACKAGE_ENERGY");
|
||||
uint64_t energy = 0;
|
||||
constexpr uint64_t fixedPointToJoule = 1048576;
|
||||
ze_result_t 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 / fixedPointToJoule) * convertJouleToMicroJoule;
|
||||
return result;
|
||||
}
|
||||
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
powerGetTimestamp(pEnergy->timestamp);
|
||||
ze_result_t result = pSysfsAccess->read(i915HwmonDir + "/" + energyCounterNode, pEnergy->energy);
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
if (pPmt != nullptr) {
|
||||
return getPmtEnergyCounter(pEnergy);
|
||||
}
|
||||
}
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
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) {
|
||||
ze_result_t result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
if (!isSubdevice) {
|
||||
uint64_t val = 0;
|
||||
if (pSustained != nullptr) {
|
||||
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);
|
||||
pSustained->enabled = true;
|
||||
pSustained->interval = -1;
|
||||
}
|
||||
if (pBurst != nullptr) {
|
||||
pBurst->power = -1;
|
||||
pBurst->enabled = false;
|
||||
}
|
||||
if (pPeak != nullptr) {
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + criticalPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
val /= milliFactor; // Convert microwatts to milliwatts
|
||||
pPeak->powerAC = static_cast<int32_t>(val);
|
||||
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) {
|
||||
ze_result_t result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
if (!isSubdevice) {
|
||||
int32_t val = 0;
|
||||
if (pSustained != nullptr) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (pPeak != nullptr) {
|
||||
val = static_cast<uint32_t>(pPeak->powerAC) * milliFactor; // Convert milliwatts to microwatts
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + criticalPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
}
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if ((*pCount == 0) || (powerLimitCount < *pCount)) {
|
||||
*pCount = powerLimitCount;
|
||||
}
|
||||
|
||||
if (pSustained != nullptr) {
|
||||
uint64_t val = 0;
|
||||
uint8_t count = 0;
|
||||
if (count < *pCount) {
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
|
||||
int32_t interval = 0;
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimitInterval, interval);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
|
||||
val /= milliFactor; // Convert microwatts to milliwatts
|
||||
pSustained[count].limit = static_cast<int32_t>(val);
|
||||
pSustained[count].enabledStateLocked = true;
|
||||
pSustained[count].intervalValueLocked = false;
|
||||
pSustained[count].limitValueLocked = false;
|
||||
pSustained[count].source = ZES_POWER_SOURCE_ANY;
|
||||
pSustained[count].level = ZES_POWER_LEVEL_SUSTAINED;
|
||||
pSustained[count].limitUnit = ZES_LIMIT_UNIT_POWER;
|
||||
pSustained[count].interval = interval;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count < *pCount) {
|
||||
result = pSysfsAccess->read(i915HwmonDir + "/" + criticalPowerLimit, val);
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
pSustained[count].enabledStateLocked = true;
|
||||
pSustained[count].intervalValueLocked = true;
|
||||
pSustained[count].limitValueLocked = false;
|
||||
pSustained[count].source = ZES_POWER_SOURCE_ANY;
|
||||
pSustained[count].level = ZES_POWER_LEVEL_PEAK;
|
||||
pSustained[count].interval = 0; // Hardcode to 100 micro seconds i.e 0.1 milli seconds
|
||||
if ((productFamily == IGFX_PVC) || (productFamily == IGFX_XE_HP_SDV)) {
|
||||
pSustained[count].limit = static_cast<int32_t>(val);
|
||||
pSustained[count].limitUnit = ZES_LIMIT_UNIT_CURRENT;
|
||||
} else {
|
||||
val /= milliFactor; // Convert microwatts to milliwatts
|
||||
pSustained[count].limit = static_cast<int32_t>(val);
|
||||
pSustained[count].limitUnit = ZES_LIMIT_UNIT_POWER;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
ze_result_t result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
if (!isSubdevice) {
|
||||
uint64_t val = 0;
|
||||
for (uint32_t i = 0; i < *pCount; i++) {
|
||||
if (pSustained[i].level == ZES_POWER_LEVEL_SUSTAINED) {
|
||||
val = pSustained[i].limit * 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[i].interval);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
} else if (pSustained[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
if ((productFamily == IGFX_PVC) || (productFamily == IGFX_XE_HP_SDV)) {
|
||||
val = pSustained[i].limit;
|
||||
} else {
|
||||
val = pSustained[i].limit * milliFactor; // Convert milliwatts to microwatts
|
||||
}
|
||||
result = pSysfsAccess->write(i915HwmonDir + "/" + criticalPowerLimit, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return getErrorCode(result);
|
||||
}
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
}
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::getEnergyThreshold(zes_energy_threshold_t *pThreshold) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPowerImp::setEnergyThreshold(double threshold) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
// The top-level hwmon(hwmon1 in example) contains all the power related information and device level
|
||||
// energy counters. The other hwmon directories contain per tile energy counters.
|
||||
// ex:- device/hwmon/hwmon1/energy1_input name = "i915" (Top level hwmon)
|
||||
// device/hwmon/hwmon2/energy1_input name = "i915_gt0" (Tile 0)
|
||||
// device/hwmon/hwmon3/energy1_input name = "i915_gt1" (Tile 1)
|
||||
|
||||
bool LinuxPowerImp::isHwmonDir(std::string name) {
|
||||
if (isSubdevice == true) {
|
||||
if (name == (i915 + "_gt" + std::to_string(subdeviceId))) {
|
||||
return true;
|
||||
}
|
||||
} else if (name == i915) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxPowerImp::isPowerModuleSupported() {
|
||||
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 (isHwmonDir(name)) {
|
||||
i915HwmonDir = hwmonDir + "/" + tempHwmonDirEntry;
|
||||
hwmonDirExists = true;
|
||||
canControl = isSubdevice ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSubdevice) {
|
||||
uint64_t val = 0;
|
||||
if (ZE_RESULT_SUCCESS == pSysfsAccess->read(i915HwmonDir + "/" + sustainedPowerLimit, val)) {
|
||||
powerLimitCount++;
|
||||
}
|
||||
|
||||
if (ZE_RESULT_SUCCESS == pSysfsAccess->read(i915HwmonDir + "/" + criticalPowerLimit, val)) {
|
||||
powerLimitCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (hwmonDirExists == false) {
|
||||
return (pPmt != nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LinuxPowerImp::LinuxPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId);
|
||||
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
|
||||
productFamily = pLinuxSysmanImp->getProductFamily();
|
||||
if ((productFamily == IGFX_PVC) || (productFamily == IGFX_XE_HP_SDV)) {
|
||||
criticalPowerLimit = "curr1_crit";
|
||||
} else {
|
||||
criticalPowerLimit = "power1_crit";
|
||||
}
|
||||
}
|
||||
|
||||
OsPower *OsPower::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
|
||||
LinuxPowerImp *pLinuxPowerImp = new LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId);
|
||||
return static_cast<OsPower *>(pLinuxPowerImp);
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
69
level_zero/sysman/source/power/linux/os_power_imp_prelim.h
Normal file
69
level_zero/sysman/source/power/linux/os_power_imp_prelim.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/sysman/source/power/os_power.h"
|
||||
|
||||
#include "igfxfmid.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
class SysfsAccess;
|
||||
class PlatformMonitoringTech;
|
||||
class LinuxPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t getProperties(zes_power_properties_t *pProperties) override;
|
||||
ze_result_t getEnergyCounter(zes_power_energy_counter_t *pEnergy) override;
|
||||
ze_result_t getLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t setLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t getEnergyThreshold(zes_energy_threshold_t *pThreshold) override;
|
||||
ze_result_t setEnergyThreshold(double threshold) override;
|
||||
ze_result_t getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) override;
|
||||
|
||||
bool isPowerModuleSupported() override;
|
||||
bool isHwmonDir(std::string name);
|
||||
ze_result_t getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy);
|
||||
LinuxPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
|
||||
LinuxPowerImp() = default;
|
||||
~LinuxPowerImp() override = default;
|
||||
|
||||
protected:
|
||||
PlatformMonitoringTech *pPmt = nullptr;
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
|
||||
private:
|
||||
std::string i915HwmonDir;
|
||||
std::string criticalPowerLimit;
|
||||
static const std::string hwmonDir;
|
||||
static const std::string i915;
|
||||
static const std::string sustainedPowerLimit;
|
||||
static const std::string sustainedPowerLimitInterval;
|
||||
static const std::string energyCounterNode;
|
||||
static const std::string defaultPowerLimit;
|
||||
bool canControl = false;
|
||||
bool isSubdevice = false;
|
||||
uint32_t subdeviceId = 0;
|
||||
uint32_t powerLimitCount = 0;
|
||||
PRODUCT_FAMILY productFamily{};
|
||||
|
||||
ze_result_t getErrorCode(ze_result_t result) {
|
||||
if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) {
|
||||
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
34
level_zero/sysman/source/power/os_power.h
Normal file
34
level_zero/sysman/source/power/os_power.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
struct OsSysman;
|
||||
class OsPower {
|
||||
public:
|
||||
virtual ze_result_t getProperties(zes_power_properties_t *pProperties) = 0;
|
||||
virtual ze_result_t getEnergyCounter(zes_power_energy_counter_t *pEnergy) = 0;
|
||||
virtual ze_result_t getLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) = 0;
|
||||
virtual ze_result_t setLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) = 0;
|
||||
virtual ze_result_t getEnergyThreshold(zes_energy_threshold_t *pThreshold) = 0;
|
||||
virtual ze_result_t setEnergyThreshold(double threshold) = 0;
|
||||
virtual ze_result_t getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) = 0;
|
||||
virtual ze_result_t setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) = 0;
|
||||
virtual ze_result_t getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) = 0;
|
||||
|
||||
virtual bool isPowerModuleSupported() = 0;
|
||||
static OsPower *create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
|
||||
virtual ~OsPower() = default;
|
||||
};
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
80
level_zero/sysman/source/power/power.cpp
Normal file
80
level_zero/sysman/source/power/power.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/source/power/power.h"
|
||||
|
||||
#include "shared/source/helpers/basic_math.h"
|
||||
|
||||
#include "level_zero/sysman/source/os_sysman.h"
|
||||
#include "level_zero/sysman/source/power/power_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
PowerHandleContext::~PowerHandleContext() {
|
||||
for (Power *pPower : handleList) {
|
||||
delete pPower;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerHandleContext::createHandle(ze_bool_t isSubDevice, uint32_t subDeviceId) {
|
||||
Power *pPower = new PowerImp(pOsSysman, isSubDevice, subDeviceId);
|
||||
if (pPower->initSuccess == true) {
|
||||
handleList.push_back(pPower);
|
||||
} else {
|
||||
delete pPower;
|
||||
}
|
||||
}
|
||||
ze_result_t PowerHandleContext::init(uint32_t subDeviceCount) {
|
||||
// Create Handle for card level power
|
||||
createHandle(false, 0);
|
||||
|
||||
for (uint32_t subDeviceId = 0; subDeviceId < subDeviceCount; subDeviceId++) {
|
||||
createHandle(true, subDeviceId);
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void PowerHandleContext::initPower() {
|
||||
std::call_once(initPowerOnce, [this]() {
|
||||
this->init(pOsSysman->getSubDeviceCount());
|
||||
});
|
||||
}
|
||||
|
||||
ze_result_t PowerHandleContext::powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) {
|
||||
initPower();
|
||||
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
|
||||
uint32_t numToCopy = std::min(*pCount, handleListSize);
|
||||
if (0 == *pCount || *pCount > handleListSize) {
|
||||
*pCount = handleListSize;
|
||||
}
|
||||
if (nullptr != phPower) {
|
||||
for (uint32_t i = 0; i < numToCopy; i++) {
|
||||
phPower[i] = handleList[i]->toHandle();
|
||||
}
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t PowerHandleContext::powerGetCardDomain(zes_pwr_handle_t *phPower) {
|
||||
initPower();
|
||||
if (nullptr == phPower) {
|
||||
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < handleList.size(); i++) {
|
||||
if (handleList[i]->isCardPower) {
|
||||
*phPower = handleList[i]->toHandle();
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
55
level_zero/sysman/source/power/power.h
Normal file
55
level_zero/sysman/source/power/power.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/api/sysman/zes_handles_struct.h"
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
struct OsSysman;
|
||||
class Power : _zes_pwr_handle_t {
|
||||
public:
|
||||
virtual ze_result_t powerGetProperties(zes_power_properties_t *pProperties) = 0;
|
||||
virtual ze_result_t powerGetEnergyCounter(zes_power_energy_counter_t *pEnergy) = 0;
|
||||
virtual ze_result_t powerGetLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) = 0;
|
||||
virtual ze_result_t powerSetLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) = 0;
|
||||
virtual ze_result_t powerGetEnergyThreshold(zes_energy_threshold_t *pThreshold) = 0;
|
||||
virtual ze_result_t powerSetEnergyThreshold(double threshold) = 0;
|
||||
virtual ze_result_t powerGetLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) = 0;
|
||||
virtual ze_result_t powerSetLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) = 0;
|
||||
|
||||
static Power *fromHandle(zes_pwr_handle_t handle) {
|
||||
return static_cast<Power *>(handle);
|
||||
}
|
||||
inline zes_pwr_handle_t toHandle() { return this; }
|
||||
bool initSuccess = false;
|
||||
bool isCardPower = false;
|
||||
};
|
||||
struct PowerHandleContext {
|
||||
PowerHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
|
||||
~PowerHandleContext();
|
||||
|
||||
ze_result_t init(uint32_t subDeviceCount);
|
||||
ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower);
|
||||
ze_result_t powerGetCardDomain(zes_pwr_handle_t *phPower);
|
||||
|
||||
OsSysman *pOsSysman = nullptr;
|
||||
std::vector<Power *> handleList = {};
|
||||
|
||||
private:
|
||||
void createHandle(ze_bool_t isSubDevice, uint32_t subDeviceId);
|
||||
std::once_flag initPowerOnce;
|
||||
void initPower();
|
||||
};
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
88
level_zero/sysman/source/power/power_imp.cpp
Normal file
88
level_zero/sysman/source/power/power_imp.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/source/power/power_imp.h"
|
||||
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
|
||||
#include "level_zero/sysman/source/power/os_power.h"
|
||||
#include "level_zero/sysman/source/sysman_device_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
ze_result_t PowerImp::powerGetProperties(zes_power_properties_t *pProperties) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
void *pNext = pProperties->pNext;
|
||||
*pProperties = powerProperties;
|
||||
pProperties->pNext = pNext;
|
||||
while (pNext) {
|
||||
zes_power_ext_properties_t *pExtProps = reinterpret_cast<zes_power_ext_properties_t *>(pNext);
|
||||
if (pExtProps->stype == ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES) {
|
||||
result = pOsPower->getPropertiesExt(pExtProps);
|
||||
if (result != ZE_RESULT_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
pNext = pExtProps->pNext;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerGetEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
return pOsPower->getEnergyCounter(pEnergy);
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerGetLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) {
|
||||
return pOsPower->getLimits(pSustained, pBurst, pPeak);
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerSetLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) {
|
||||
return pOsPower->setLimits(pSustained, pBurst, pPeak);
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerGetLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
return pOsPower->getLimitsExt(pCount, pSustained);
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerSetLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
return pOsPower->setLimitsExt(pCount, pSustained);
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerGetEnergyThreshold(zes_energy_threshold_t *pThreshold) {
|
||||
return pOsPower->getEnergyThreshold(pThreshold);
|
||||
}
|
||||
|
||||
ze_result_t PowerImp::powerSetEnergyThreshold(double threshold) {
|
||||
return pOsPower->setEnergyThreshold(threshold);
|
||||
}
|
||||
|
||||
PowerImp::PowerImp(OsSysman *pOsSysman, ze_bool_t isSubDevice, uint32_t subDeviceId) {
|
||||
|
||||
pOsPower = OsPower::create(pOsSysman, isSubDevice, subDeviceId);
|
||||
UNRECOVERABLE_IF(nullptr == pOsPower);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
void PowerImp::init() {
|
||||
if (pOsPower->isPowerModuleSupported()) {
|
||||
pOsPower->getProperties(&powerProperties);
|
||||
this->initSuccess = true;
|
||||
this->isCardPower = powerProperties.onSubdevice ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
PowerImp::~PowerImp() {
|
||||
if (nullptr != pOsPower) {
|
||||
delete pOsPower;
|
||||
pOsPower = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
39
level_zero/sysman/source/power/power_imp.h
Normal file
39
level_zero/sysman/source/power/power_imp.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/sysman/source/power/power.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
class OsPower;
|
||||
class PowerImp : public Power, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t powerGetProperties(zes_power_properties_t *pProperties) override;
|
||||
ze_result_t powerGetEnergyCounter(zes_power_energy_counter_t *pEnergy) override;
|
||||
ze_result_t powerGetLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t powerSetLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t powerGetEnergyThreshold(zes_energy_threshold_t *pThreshold) override;
|
||||
ze_result_t powerSetEnergyThreshold(double threshold) override;
|
||||
ze_result_t powerGetLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t powerSetLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
|
||||
PowerImp() = default;
|
||||
PowerImp(OsSysman *pOsSysman, ze_bool_t isSubDevice, uint32_t subDeviceId);
|
||||
~PowerImp() override;
|
||||
|
||||
OsPower *pOsPower = nullptr;
|
||||
void init();
|
||||
|
||||
private:
|
||||
zes_power_properties_t powerProperties = {};
|
||||
};
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
21
level_zero/sysman/source/power/windows/CMakeLists.txt
Normal file
21
level_zero/sysman/source/power/windows/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# Copyright (C) 2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_SRCS_SYSMAN_POWER_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_power_imp.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_SYSMAN_POWER_WINDOWS}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_SYSMAN_POWER_WINDOWS ${L0_SRCS_SYSMAN_POWER_WINDOWS})
|
||||
63
level_zero/sysman/source/power/windows/os_power_imp.cpp
Normal file
63
level_zero/sysman/source/power/windows/os_power_imp.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/source/power/windows/os_power_imp.h"
|
||||
|
||||
#include "level_zero/sysman/source/windows/os_sysman_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
ze_result_t WddmPowerImp::getProperties(zes_power_properties_t *pProperties) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t WddmPowerImp::getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t WddmPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t WddmPowerImp::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 WddmPowerImp::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 WddmPowerImp::getEnergyThreshold(zes_energy_threshold_t *pThreshold) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t WddmPowerImp::setEnergyThreshold(double threshold) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
bool WddmPowerImp::isPowerModuleSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
ze_result_t WddmPowerImp::getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t WddmPowerImp::setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
WddmPowerImp::WddmPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
|
||||
}
|
||||
|
||||
OsPower *OsPower::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
35
level_zero/sysman/source/power/windows/os_power_imp.h
Normal file
35
level_zero/sysman/source/power/windows/os_power_imp.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/sysman/source/power/os_power.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
class KmdSysManager;
|
||||
class WddmPowerImp : public OsPower, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t getProperties(zes_power_properties_t *pProperties) override;
|
||||
ze_result_t getEnergyCounter(zes_power_energy_counter_t *pEnergy) override;
|
||||
ze_result_t getLimits(zes_power_sustained_limit_t *pSustained, zes_power_burst_limit_t *pBurst, zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t setLimits(const zes_power_sustained_limit_t *pSustained, const zes_power_burst_limit_t *pBurst, const zes_power_peak_limit_t *pPeak) override;
|
||||
ze_result_t getEnergyThreshold(zes_energy_threshold_t *pThreshold) override;
|
||||
ze_result_t setEnergyThreshold(double threshold) override;
|
||||
ze_result_t getLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t setLimitsExt(uint32_t *pCount, zes_power_limit_ext_desc_t *pSustained) override;
|
||||
ze_result_t getPropertiesExt(zes_power_ext_properties_t *pExtPoperties) override;
|
||||
|
||||
bool isPowerModuleSupported() override;
|
||||
WddmPowerImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
|
||||
WddmPowerImp() = default;
|
||||
~WddmPowerImp() override = default;
|
||||
};
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
@@ -35,5 +35,21 @@ ze_result_t SysmanDevice::memoryGet(zes_device_handle_t hDevice, uint32_t *pCoun
|
||||
return pSysmanDevice->memoryGet(pCount, phMemory);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDevice::powerGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_pwr_handle_t *phPower) {
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(hDevice);
|
||||
if (pSysmanDevice == nullptr) {
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
return pSysmanDevice->powerGet(pCount, phPower);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDevice::powerGetCardDomain(zes_device_handle_t hDevice, zes_pwr_handle_t *phPower) {
|
||||
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(hDevice);
|
||||
if (pSysmanDevice == nullptr) {
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
return pSysmanDevice->powerGetCardDomain(phPower);
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
#include "level_zero/sysman/source/fabric_port/fabric_port.h"
|
||||
#include "level_zero/sysman/source/memory/memory.h"
|
||||
#include "level_zero/sysman/source/power/power.h"
|
||||
#include <level_zero/ze_api.h>
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
@@ -19,6 +20,12 @@ namespace Sysman {
|
||||
|
||||
struct SysmanDevice : _ze_device_handle_t {
|
||||
|
||||
static ze_result_t powerGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_pwr_handle_t *phPower);
|
||||
static ze_result_t powerGetCardDomain(zes_device_handle_t hDevice, zes_pwr_handle_t *phPower);
|
||||
|
||||
virtual ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) = 0;
|
||||
virtual ze_result_t powerGetCardDomain(zes_pwr_handle_t *phPower) = 0;
|
||||
|
||||
static SysmanDevice *fromHandle(zes_device_handle_t handle) { return static_cast<SysmanDevice *>(handle); }
|
||||
inline zes_device_handle_t toHandle() { return this; }
|
||||
virtual ~SysmanDevice() = default;
|
||||
|
||||
@@ -23,10 +23,12 @@ SysmanDeviceImp::SysmanDeviceImp(NEO::ExecutionEnvironment *executionEnvironment
|
||||
UNRECOVERABLE_IF(nullptr == pOsSysman);
|
||||
pFabricPortHandleContext = new FabricPortHandleContext(pOsSysman);
|
||||
pMemoryHandleContext = new MemoryHandleContext(pOsSysman);
|
||||
pPowerHandleContext = new PowerHandleContext(pOsSysman);
|
||||
}
|
||||
|
||||
SysmanDeviceImp::~SysmanDeviceImp() {
|
||||
executionEnvironment->decRefInternal();
|
||||
freeResource(pPowerHandleContext);
|
||||
freeResource(pFabricPortHandleContext);
|
||||
freeResource(pMemoryHandleContext);
|
||||
freeResource(pOsSysman);
|
||||
@@ -48,5 +50,13 @@ ze_result_t SysmanDeviceImp::memoryGet(uint32_t *pCount, zes_mem_handle_t *phMem
|
||||
return pMemoryHandleContext->memoryGet(pCount, phMemory);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDeviceImp::powerGetCardDomain(zes_pwr_handle_t *phPower) {
|
||||
return pPowerHandleContext->powerGetCardDomain(phPower);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDeviceImp::powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) {
|
||||
return pPowerHandleContext->powerGet(pCount, phPower);
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
|
||||
@@ -28,6 +28,11 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
|
||||
ze_result_t init();
|
||||
|
||||
OsSysman *pOsSysman = nullptr;
|
||||
PowerHandleContext *pPowerHandleContext = nullptr;
|
||||
|
||||
ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) override;
|
||||
ze_result_t powerGetCardDomain(zes_pwr_handle_t *phPower) override;
|
||||
|
||||
const NEO::RootDeviceEnvironment &getRootDeviceEnvironment() const {
|
||||
return *executionEnvironment->rootDeviceEnvironments[rootDeviceIndex];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
#include "shared/test/common/test_macros/hw_test.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/sysman/source/linux/fs_access.h"
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(L0_TESTS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
)
|
||||
|
||||
if(NEO_ENABLE_i915_PRELIM_DETECTION)
|
||||
list(APPEND L0_TESTS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_power_prelim.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_power_helper_prelim.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysfs_power_prelim.h
|
||||
|
||||
)
|
||||
else()
|
||||
list(APPEND L0_TESTS_SYSMAN_POWER_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_power.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_power_helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysfs_power.h
|
||||
)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
${L0_TESTS_SYSMAN_POWER_LINUX}
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,455 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/string.h"
|
||||
|
||||
#include "level_zero/sysman/source/linux/pmt/pmt.h"
|
||||
#include "level_zero/sysman/source/power/linux/os_power_imp.h"
|
||||
#include "level_zero/sysman/source/power/power_imp.h"
|
||||
#include "level_zero/sysman/source/sysman_const.h"
|
||||
#include "level_zero/sysman/source/sysman_device_imp.h"
|
||||
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
constexpr uint64_t setEnergyCounter = (83456u * 1048576u);
|
||||
constexpr uint64_t offset = 0x400;
|
||||
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/hwmon2");
|
||||
const std::string nonI915HwmonDir("device/hwmon/hwmon1");
|
||||
const std::vector<std::string> listOfMockedHwmonDirs = {"hwmon0", "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 = 10;
|
||||
|
||||
const std::map<std::string, uint64_t> deviceKeyOffsetMapPower = {
|
||||
{"PACKAGE_ENERGY", 0x400},
|
||||
{"COMPUTE_TEMPERATURES", 0x68},
|
||||
{"SOC_TEMPERATURES", 0x60},
|
||||
{"CORE_TEMPERATURES", 0x6c}};
|
||||
|
||||
struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess {
|
||||
|
||||
std::vector<ze_result_t> mockReadReturnStatus{};
|
||||
std::vector<ze_result_t> mockWriteReturnStatus{};
|
||||
std::vector<ze_result_t> mockScanDirEntriesReturnStatus{};
|
||||
std::vector<uint64_t> mockReadUnsignedLongValue{};
|
||||
std::vector<uint32_t> mockReadUnsignedIntValue{};
|
||||
bool isRepeated = false;
|
||||
|
||||
ze_result_t read(const std::string file, std::string &val) override {
|
||||
|
||||
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 getValUnsignedLongReturnErrorForBurstPowerLimit(const std::string file, uint64_t &val) {
|
||||
if (file.compare(i915HwmonDir + "/" + burstPowerLimitEnabled) == 0) {
|
||||
val = burstPowerLimitEnabledVal;
|
||||
}
|
||||
if (file.compare(i915HwmonDir + "/" + burstPowerLimit) == 0) {
|
||||
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
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 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 setValUnsignedLongReturnErrorForSustainedPowerLimitEnabled(const std::string file, const int val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t setValUnsignedLongReturnInsufficientForSustainedPowerLimitEnabled(const std::string file, const int val) {
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
}
|
||||
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 read(const std::string file, uint64_t &val) override {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (!mockReadReturnStatus.empty()) {
|
||||
result = mockReadReturnStatus.front();
|
||||
if (!mockReadUnsignedLongValue.empty()) {
|
||||
val = mockReadUnsignedLongValue.front();
|
||||
}
|
||||
if (isRepeated != true) {
|
||||
if (mockReadUnsignedLongValue.size() != 0) {
|
||||
mockReadUnsignedLongValue.erase(mockReadUnsignedLongValue.begin());
|
||||
}
|
||||
mockReadReturnStatus.erase(mockReadReturnStatus.begin());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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 read(const std::string file, uint32_t &val) override {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (!mockReadReturnStatus.empty()) {
|
||||
result = mockReadReturnStatus.front();
|
||||
if (!mockReadUnsignedIntValue.empty()) {
|
||||
val = mockReadUnsignedIntValue.front();
|
||||
}
|
||||
if (isRepeated != true) {
|
||||
if (mockReadUnsignedIntValue.size() != 0) {
|
||||
mockReadUnsignedIntValue.erase(mockReadUnsignedIntValue.begin());
|
||||
}
|
||||
mockReadReturnStatus.erase(mockReadReturnStatus.begin());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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 write(const std::string file, const int val) override {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (!mockWriteReturnStatus.empty()) {
|
||||
ze_result_t result = mockWriteReturnStatus.front();
|
||||
if (isRepeated != true) {
|
||||
mockWriteReturnStatus.erase(mockWriteReturnStatus.begin());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitEnabled) == 0) {
|
||||
sustainedPowerLimitEnabledVal = static_cast<uint64_t>(val);
|
||||
} else 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 scanDirEntries(const std::string file, std::vector<std::string> &listOfEntries) override {
|
||||
ze_result_t result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
if (!mockScanDirEntriesReturnStatus.empty()) {
|
||||
ze_result_t result = mockScanDirEntriesReturnStatus.front();
|
||||
if (isRepeated != true) {
|
||||
mockScanDirEntriesReturnStatus.erase(mockScanDirEntriesReturnStatus.begin());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (file.compare(hwmonDir) == 0) {
|
||||
listOfEntries = listOfMockedHwmonDirs;
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MockPowerSysfsAccess() = default;
|
||||
};
|
||||
|
||||
struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech {
|
||||
using L0::Sysman::PlatformMonitoringTech::closeFunction;
|
||||
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
|
||||
using L0::Sysman::PlatformMonitoringTech::openFunction;
|
||||
using L0::Sysman::PlatformMonitoringTech::preadFunction;
|
||||
using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry;
|
||||
|
||||
MockPowerPmt(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
|
||||
~MockPowerPmt() override {
|
||||
rootDeviceTelemNodeIndex = 0;
|
||||
}
|
||||
|
||||
void mockedInit(L0::Sysman::FsAccess *pFsAccess) {
|
||||
std::string gpuUpstreamPortPath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0";
|
||||
if (ZE_RESULT_SUCCESS != L0::Sysman::PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, gpuUpstreamPortPath)) {
|
||||
return;
|
||||
}
|
||||
telemetryDeviceEntry = "/sys/class/intel_pmt/telem2/telem";
|
||||
}
|
||||
};
|
||||
|
||||
struct MockPowerFsAccess : public L0::Sysman::FsAccess {
|
||||
|
||||
ze_result_t listDirectory(const std::string directory, std::vector<std::string> &listOfTelemNodes) override {
|
||||
if (directory.compare(baseTelemSysFS) == 0) {
|
||||
listOfTelemNodes.push_back("telem1");
|
||||
listOfTelemNodes.push_back("telem2");
|
||||
listOfTelemNodes.push_back("telem3");
|
||||
listOfTelemNodes.push_back("telem4");
|
||||
listOfTelemNodes.push_back("telem5");
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t listDirectoryFailure(const std::string directory, std::vector<std::string> &events) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getRealPath(const std::string path, std::string &buf) override {
|
||||
if (path.compare("/sys/class/intel_pmt/telem1") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem2") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem2";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem3") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem3";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem4") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem4";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem5") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem5";
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t getRealPathFailure(const std::string path, std::string &buf) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
MockPowerFsAccess() = default;
|
||||
};
|
||||
|
||||
class PublicLinuxPowerImp : public L0::Sysman::LinuxPowerImp {
|
||||
public:
|
||||
PublicLinuxPowerImp(L0::Sysman::OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId) {}
|
||||
using L0::Sysman::LinuxPowerImp::pPmt;
|
||||
};
|
||||
|
||||
class SysmanDevicePowerFixture : public SysmanDeviceFixture {
|
||||
protected:
|
||||
L0::Sysman::SysmanDevice *device = nullptr;
|
||||
std::unique_ptr<PublicLinuxPowerImp> pPublicLinuxPowerImp;
|
||||
std::unique_ptr<MockPowerPmt> pPmt;
|
||||
std::unique_ptr<MockPowerFsAccess> pFsAccess;
|
||||
std::unique_ptr<MockPowerSysfsAccess> pSysfsAccess;
|
||||
L0::Sysman::SysfsAccess *pSysfsAccessOld = nullptr;
|
||||
L0::Sysman::FsAccess *pFsAccessOriginal = nullptr;
|
||||
L0::Sysman::OsPower *pOsPowerOriginal = nullptr;
|
||||
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> pmtMapOriginal;
|
||||
void SetUp() override {
|
||||
SysmanDeviceFixture::SetUp();
|
||||
device = pSysmanDevice;
|
||||
pFsAccess = std::make_unique<MockPowerFsAccess>();
|
||||
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
|
||||
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess;
|
||||
pSysfsAccess = std::make_unique<MockPowerSysfsAccess>();
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
|
||||
|
||||
pmtMapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
auto pPmt = new MockPowerPmt(pFsAccess.get(), onSubdevice, subdeviceId);
|
||||
pPmt->mockedInit(pFsAccess.get());
|
||||
pPmt->keyOffsetMap = deviceKeyOffsetMapPower;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt);
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
getPowerHandles(0);
|
||||
}
|
||||
void TearDown() override {
|
||||
pLinuxSysmanImp->releasePmtObject();
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = pmtMapOriginal;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld;
|
||||
SysmanDeviceFixture::TearDown();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
|
||||
protected:
|
||||
L0::Sysman::SysmanDevice *device = nullptr;
|
||||
std::unique_ptr<PublicLinuxPowerImp> pPublicLinuxPowerImp;
|
||||
std::unique_ptr<MockPowerPmt> pPmt;
|
||||
std::unique_ptr<MockPowerFsAccess> pFsAccess;
|
||||
std::unique_ptr<MockPowerSysfsAccess> pSysfsAccess;
|
||||
L0::Sysman::SysfsAccess *pSysfsAccessOld = nullptr;
|
||||
L0::Sysman::FsAccess *pFsAccessOriginal = nullptr;
|
||||
L0::Sysman::OsPower *pOsPowerOriginal = nullptr;
|
||||
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> mapOriginal;
|
||||
void SetUp() override {
|
||||
SysmanMultiDeviceFixture::SetUp();
|
||||
device = pSysmanDevice;
|
||||
pFsAccess = std::make_unique<MockPowerFsAccess>();
|
||||
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
|
||||
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess;
|
||||
pSysfsAccess = std::make_unique<MockPowerSysfsAccess>();
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
|
||||
|
||||
mapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
auto pPmt = new MockPowerPmt(pFsAccess.get(), onSubdevice, subdeviceId);
|
||||
pPmt->mockedInit(pFsAccess.get());
|
||||
pPmt->keyOffsetMap = deviceKeyOffsetMapPower;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt);
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
}
|
||||
void TearDown() override {
|
||||
for (const auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
delete pmtMapElement.second;
|
||||
}
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = mapOriginal;
|
||||
SysmanMultiDeviceFixture::TearDown();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/string.h"
|
||||
|
||||
#include "level_zero/sysman/source/linux/pmt/pmt.h"
|
||||
#include "level_zero/sysman/source/power/linux/os_power_imp_prelim.h"
|
||||
#include "level_zero/sysman/source/power/power_imp.h"
|
||||
#include "level_zero/sysman/source/sysman_const.h"
|
||||
#include "level_zero/sysman/source/sysman_device_imp.h"
|
||||
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
constexpr uint64_t setEnergyCounter = (83456u * 1048576u);
|
||||
constexpr uint64_t offset = 0x400;
|
||||
constexpr uint32_t mockLimitCount = 2u;
|
||||
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/hwmon2");
|
||||
const std::string nonI915HwmonDir("device/hwmon/hwmon1");
|
||||
const std::string i915HwmonDirTile0("device/hwmon/hwmon3");
|
||||
const std::string i915HwmonDirTile1("device/hwmon/hwmon4");
|
||||
const std::vector<std::string> listOfMockedHwmonDirs = {"hwmon0", "hwmon1", "hwmon2", "hwmon3", "hwmon4"};
|
||||
const std::string sustainedPowerLimit("power1_max");
|
||||
const std::string sustainedPowerLimitInterval("power1_max_interval");
|
||||
const std::string criticalPowerLimit1("curr1_crit");
|
||||
const std::string criticalPowerLimit2("power1_crit");
|
||||
const std::string energyCounterNode("energy1_input");
|
||||
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;
|
||||
const std::map<std::string, uint64_t> deviceKeyOffsetMapPower = {
|
||||
{"PACKAGE_ENERGY", 0x400},
|
||||
{"COMPUTE_TEMPERATURES", 0x68},
|
||||
{"SOC_TEMPERATURES", 0x60},
|
||||
{"CORE_TEMPERATURES", 0x6c}};
|
||||
|
||||
struct MockPowerSysfsAccess : public L0::Sysman::SysfsAccess {
|
||||
ze_result_t mockReadResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockReadValUnsignedLongResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockReadPeakResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockWriteResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockWriteUnsignedResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockReadIntResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockWritePeakLimitResult = ZE_RESULT_SUCCESS;
|
||||
ze_result_t mockscanDirEntriesResult = ZE_RESULT_SUCCESS;
|
||||
|
||||
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 if (file.compare(i915HwmonDirTile1 + "/" + "name") == 0) {
|
||||
val = "i915_gt1";
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
} else if (file.compare(i915HwmonDirTile0 + "/" + "name") == 0) {
|
||||
val = "i915_gt0";
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
} else {
|
||||
val = "garbageI915";
|
||||
result = ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t sustainedPowerLimitVal = 0;
|
||||
uint64_t criticalPowerLimitVal = 0;
|
||||
int32_t sustainedPowerLimitIntervalVal = 0;
|
||||
|
||||
ze_result_t getValUnsignedLongHelper(const std::string file, uint64_t &val);
|
||||
ze_result_t getValUnsignedLong(const std::string file, uint64_t &val) {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
|
||||
val = sustainedPowerLimitVal;
|
||||
} else if ((file.compare(i915HwmonDir + "/" + criticalPowerLimit1) == 0) || (file.compare(i915HwmonDir + "/" + criticalPowerLimit2) == 0)) {
|
||||
if (mockReadPeakResult != ZE_RESULT_SUCCESS) {
|
||||
return mockReadPeakResult;
|
||||
}
|
||||
val = criticalPowerLimitVal;
|
||||
} else if (file.compare(i915HwmonDirTile0 + "/" + energyCounterNode) == 0) {
|
||||
val = expectedEnergyCounterTile0;
|
||||
} else if (file.compare(i915HwmonDirTile1 + "/" + energyCounterNode) == 0) {
|
||||
val = expectedEnergyCounterTile1;
|
||||
} else if (file.compare(i915HwmonDir + "/" + energyCounterNode) == 0) {
|
||||
val = expectedEnergyCounter;
|
||||
} 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 {
|
||||
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 = val;
|
||||
} else if ((file.compare(i915HwmonDir + "/" + criticalPowerLimit1) == 0) || (file.compare(i915HwmonDir + "/" + criticalPowerLimit2) == 0)) {
|
||||
if (mockWritePeakLimitResult != ZE_RESULT_SUCCESS) {
|
||||
return mockWritePeakLimitResult;
|
||||
}
|
||||
criticalPowerLimitVal = 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 read(const std::string file, uint64_t &val) override {
|
||||
if (mockReadValUnsignedLongResult != ZE_RESULT_SUCCESS) {
|
||||
return mockReadValUnsignedLongResult;
|
||||
}
|
||||
|
||||
return getValUnsignedLong(file, val);
|
||||
}
|
||||
|
||||
ze_result_t read(const std::string file, int32_t &val) override {
|
||||
if (mockReadIntResult != ZE_RESULT_SUCCESS) {
|
||||
return mockReadIntResult;
|
||||
}
|
||||
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimitInterval) == 0) {
|
||||
val = sustainedPowerLimitIntervalVal;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t read(const std::string file, std::string &val) override {
|
||||
if (mockReadResult != ZE_RESULT_SUCCESS) {
|
||||
return mockReadResult;
|
||||
}
|
||||
|
||||
return getValString(file, val);
|
||||
}
|
||||
|
||||
ze_result_t read(const std::string file, uint32_t &val) override {
|
||||
if (mockReadResult != ZE_RESULT_SUCCESS) {
|
||||
return mockReadResult;
|
||||
}
|
||||
return getValUnsignedInt(file, val);
|
||||
}
|
||||
|
||||
ze_result_t write(const std::string file, const int val) override {
|
||||
if (mockWriteResult != ZE_RESULT_SUCCESS) {
|
||||
return mockWriteResult;
|
||||
}
|
||||
|
||||
return setVal(file, val);
|
||||
}
|
||||
|
||||
ze_result_t write(const std::string file, const uint64_t val) override {
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
if (mockWriteUnsignedResult != ZE_RESULT_SUCCESS) {
|
||||
return mockWriteUnsignedResult;
|
||||
}
|
||||
|
||||
if (file.compare(i915HwmonDir + "/" + sustainedPowerLimit) == 0) {
|
||||
sustainedPowerLimitVal = val;
|
||||
} else if ((file.compare(i915HwmonDir + "/" + criticalPowerLimit1) == 0) || (file.compare(i915HwmonDir + "/" + criticalPowerLimit2) == 0)) {
|
||||
if (mockWritePeakLimitResult != ZE_RESULT_SUCCESS) {
|
||||
return mockWritePeakLimitResult;
|
||||
}
|
||||
criticalPowerLimitVal = val;
|
||||
} else {
|
||||
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ze_result_t scanDirEntries(const std::string file, std::vector<std::string> &listOfEntries) override {
|
||||
if (mockscanDirEntriesResult != ZE_RESULT_SUCCESS) {
|
||||
return mockscanDirEntriesResult;
|
||||
}
|
||||
|
||||
return getscanDirEntries(file, listOfEntries);
|
||||
}
|
||||
|
||||
MockPowerSysfsAccess() = default;
|
||||
};
|
||||
|
||||
struct MockPowerPmt : public L0::Sysman::PlatformMonitoringTech {
|
||||
|
||||
MockPowerPmt(L0::Sysman::FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {}
|
||||
using L0::Sysman::PlatformMonitoringTech::closeFunction;
|
||||
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
|
||||
using L0::Sysman::PlatformMonitoringTech::openFunction;
|
||||
using L0::Sysman::PlatformMonitoringTech::preadFunction;
|
||||
using L0::Sysman::PlatformMonitoringTech::telemetryDeviceEntry;
|
||||
~MockPowerPmt() override {
|
||||
rootDeviceTelemNodeIndex = 0;
|
||||
}
|
||||
|
||||
void mockedInit(L0::Sysman::FsAccess *pFsAccess) {
|
||||
std::string gpuUpstreamPortPath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0";
|
||||
if (ZE_RESULT_SUCCESS != L0::Sysman::PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, gpuUpstreamPortPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
telemetryDeviceEntry = "/sys/class/intel_pmt/telem2/telem";
|
||||
}
|
||||
};
|
||||
|
||||
struct MockPowerFsAccess : public L0::Sysman::FsAccess {
|
||||
|
||||
ze_result_t listDirectory(const std::string directory, std::vector<std::string> &listOfTelemNodes) override {
|
||||
if (directory.compare(baseTelemSysFS) == 0) {
|
||||
listOfTelemNodes.push_back("telem1");
|
||||
listOfTelemNodes.push_back("telem2");
|
||||
listOfTelemNodes.push_back("telem3");
|
||||
listOfTelemNodes.push_back("telem4");
|
||||
listOfTelemNodes.push_back("telem5");
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getRealPath(const std::string path, std::string &buf) override {
|
||||
if (path.compare("/sys/class/intel_pmt/telem1") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem2") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem2";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem3") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem3";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem4") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem4";
|
||||
} else if (path.compare("/sys/class/intel_pmt/telem5") == 0) {
|
||||
buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem5";
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
MockPowerFsAccess() = default;
|
||||
};
|
||||
|
||||
class PublicLinuxPowerImp : public L0::Sysman::LinuxPowerImp {
|
||||
public:
|
||||
PublicLinuxPowerImp(L0::Sysman::OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : L0::Sysman::LinuxPowerImp(pOsSysman, onSubdevice, subdeviceId) {}
|
||||
using L0::Sysman::LinuxPowerImp::pPmt;
|
||||
};
|
||||
|
||||
class SysmanDevicePowerFixture : public SysmanDeviceFixture {
|
||||
protected:
|
||||
L0::Sysman::SysmanDevice *device = nullptr;
|
||||
std::unique_ptr<PublicLinuxPowerImp> pPublicLinuxPowerImp;
|
||||
std::unique_ptr<MockPowerPmt> pPmt;
|
||||
std::unique_ptr<MockPowerFsAccess> pFsAccess;
|
||||
std::unique_ptr<MockPowerSysfsAccess> pSysfsAccess;
|
||||
L0::Sysman::SysfsAccess *pSysfsAccessOld = nullptr;
|
||||
L0::Sysman::FsAccess *pFsAccessOriginal = nullptr;
|
||||
L0::Sysman::OsPower *pOsPowerOriginal = nullptr;
|
||||
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> pmtMapOriginal;
|
||||
void SetUp() override {
|
||||
SysmanDeviceFixture::SetUp();
|
||||
device = pSysmanDevice;
|
||||
pFsAccess = std::make_unique<MockPowerFsAccess>();
|
||||
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
|
||||
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess;
|
||||
pSysfsAccess = std::make_unique<MockPowerSysfsAccess>();
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
|
||||
|
||||
pmtMapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
auto pPmt = new MockPowerPmt(pFsAccess.get(), onSubdevice, subdeviceId);
|
||||
pPmt->mockedInit(pFsAccess.get());
|
||||
pPmt->keyOffsetMap = deviceKeyOffsetMapPower;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt);
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
getPowerHandles(0);
|
||||
}
|
||||
void TearDown() override {
|
||||
pLinuxSysmanImp->releasePmtObject();
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = pmtMapOriginal;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld;
|
||||
SysmanDeviceFixture::TearDown();
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
|
||||
protected:
|
||||
L0::Sysman::SysmanDevice *device = nullptr;
|
||||
std::unique_ptr<PublicLinuxPowerImp> pPublicLinuxPowerImp;
|
||||
std::unique_ptr<MockPowerPmt> pPmt;
|
||||
std::unique_ptr<MockPowerFsAccess> pFsAccess;
|
||||
std::unique_ptr<MockPowerSysfsAccess> pSysfsAccess;
|
||||
L0::Sysman::SysfsAccess *pSysfsAccessOld = nullptr;
|
||||
L0::Sysman::FsAccess *pFsAccessOriginal = nullptr;
|
||||
L0::Sysman::OsPower *pOsPowerOriginal = nullptr;
|
||||
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> mapOriginal;
|
||||
void SetUp() override {
|
||||
SysmanMultiDeviceFixture::SetUp();
|
||||
device = pSysmanDevice;
|
||||
pFsAccess = std::make_unique<MockPowerFsAccess>();
|
||||
pFsAccessOriginal = pLinuxSysmanImp->pFsAccess;
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
|
||||
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess;
|
||||
pSysfsAccess = std::make_unique<MockPowerSysfsAccess>();
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get();
|
||||
|
||||
mapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
auto pPmt = new MockPowerPmt(pFsAccess.get(), onSubdevice, subdeviceId);
|
||||
pPmt->mockedInit(pFsAccess.get());
|
||||
pPmt->keyOffsetMap = deviceKeyOffsetMapPower;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt);
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
for (auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
if (pmtMapElement.second) {
|
||||
delete pmtMapElement.second;
|
||||
pmtMapElement.second = nullptr;
|
||||
}
|
||||
}
|
||||
pLinuxSysmanImp->pFsAccess = pFsAccessOriginal;
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = mapOriginal;
|
||||
SysmanMultiDeviceFixture::TearDown();
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,714 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
static int fakeFileDescriptor = 123;
|
||||
constexpr uint64_t convertJouleToMicroJoule = 1000000u;
|
||||
constexpr uint32_t powerHandleComponentCount = 1u;
|
||||
|
||||
inline static int openMockPower(const char *pathname, int flags) {
|
||||
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline static int closeMockPower(int fd) {
|
||||
if (fd == fakeFileDescriptor) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
|
||||
uint64_t *mockBuf = static_cast<uint64_t *>(buf);
|
||||
*mockBuf = setEnergyCounter;
|
||||
return count;
|
||||
}
|
||||
|
||||
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, GivenValidPowerPointerWhenGettingCardPowerDomainWhenhwmonInterfaceExistsAndThenCallSucceeds) {
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenInvalidPowerPointerWhenGettingCardPowerDomainAndThenReturnsFailure) {
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenUninitializedPowerHandlesAndWhenGettingCardPowerDomainThenReturnsFailure) {
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
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, 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));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesWhenHwmonInterfaceExistThenLimitsReturnsUnknown) {
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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) {
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->mockReadUnsignedIntValue.push_back(std::numeric_limits<uint32_t>::max());
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->mockReadUnsignedIntValue.push_back(std::numeric_limits<uint32_t>::max());
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
|
||||
pSysfsAccess->mockReadUnsignedIntValue.push_back(std::numeric_limits<uint32_t>::max());
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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, GivenValidPowerHandleWhenGettingPowerPropertiesThenHwmonInterfaceExistAndMinLimitIsUnknown) {
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->mockReadUnsignedIntValue.push_back(0);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
|
||||
pSysfsAccess->mockReadUnsignedIntValue.push_back(0);
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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, static_cast<int32_t>(mockMaxPowerLimitVal / milliFactor));
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
|
||||
pPmt->openFunction = openMockPower;
|
||||
pPmt->closeFunction = closeMockPower;
|
||||
pPmt->preadFunction = preadMockPower;
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
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.enabled = 1;
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(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);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.enabled = 1;
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.enabled = 1;
|
||||
sustainedSet.interval = 10;
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenWritingToSustainedPowerEnableNodeWithoutPermissionsThenValidErrorIsReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWriteReturnStatus.push_back(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS);
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.enabled = 0;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndPermissionsThenFirstDisableSustainedPowerLimitAndThenEnableItAndCheckSuccesIsReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
sustainedSet.enabled = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
sustainedSet.enabled = 1;
|
||||
sustainedSet.interval = 10;
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], &sustainedGet, nullptr, nullptr));
|
||||
EXPECT_EQ(sustainedGet.enabled, sustainedSet.enabled);
|
||||
EXPECT_EQ(sustainedGet.power, sustainedSet.power);
|
||||
EXPECT_EQ(sustainedGet.interval, sustainedSet.interval);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenGetPowerLimitsWhenPowerLimitsAreDisabledWhenHwmonInterfaceExistThenAllPowerValuesAreIgnored) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
|
||||
pSysfsAccess->mockReadUnsignedLongValue.push_back(0);
|
||||
|
||||
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, GivenScanDirectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
uint32_t subdeviceId = 0;
|
||||
PublicLinuxPowerImp *pPowerImp = new PublicLinuxPowerImp(pOsSysman, onSubdevice, subdeviceId);
|
||||
EXPECT_TRUE(pPowerImp->isPowerModuleSupported());
|
||||
delete pPowerImp;
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidPowerHandlesIsReturned) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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, GivenValidPowerHandleWhenGettingPowerPropertiesThenCallSucceeds) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
|
||||
pPmt->openFunction = openMockPower;
|
||||
pPmt->closeFunction = closeMockPower;
|
||||
pPmt->preadFunction = preadMockPower;
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
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, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFileReturnsErrorAndPmtFailsThenFailureIsReturned) {
|
||||
|
||||
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
for (auto &subDeviceIdToPmtEntry : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
delete subDeviceIdToPmtEntry.second;
|
||||
}
|
||||
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
do {
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, nullptr);
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_energy_counter_t energyCounter = {};
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetEnergyCounter(handle, &energyCounter));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
zes_energy_threshold_t threshold;
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetEnergyThreshold(handle, &threshold));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenScanDirectoriesFailAndPmtIsNullWhenGettingCardPowerThenReturnsFailure) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
for (auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
if (pmtMapElement.second) {
|
||||
delete pmtMapElement.second;
|
||||
pmtMapElement.second = nullptr;
|
||||
}
|
||||
}
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
double threshold = 0;
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetEnergyThreshold(handle, threshold));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustained;
|
||||
zes_power_burst_limit_t burst;
|
||||
zes_power_peak_limit_t peak;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustained, &burst, &peak));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustained;
|
||||
zes_power_burst_limit_t burst;
|
||||
zes_power_peak_limit_t peak;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, &sustained, &burst, &peak));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFailsThenValidPowerReadingsRetrievedFromPmt) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
|
||||
pPmt->openFunction = openMockPower;
|
||||
pPmt->closeFunction = closeMockPower;
|
||||
pPmt->preadFunction = preadMockPower;
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
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, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtWhenHwmonInterfaceExistThenUnsupportedFeatureIsReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
uint32_t limitCount = 0;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &limitCount, nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesExtThenApiReturnsFailure) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
|
||||
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
|
||||
properties.pNext = &extProperties;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetProperties(handle, &properties));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesExtWithoutStypeThenExtPropertiesAreNotReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
|
||||
properties.pNext = &extProperties;
|
||||
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, 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));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
constexpr uint32_t powerHandleComponentCount = 1u;
|
||||
using SysmanDevicePowerFixtureHelper = SysmanDevicePowerFixture;
|
||||
|
||||
TEST_F(SysmanDevicePowerFixtureHelper, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
using SysmanDevicePowerMultiDeviceFixtureHelper = SysmanDevicePowerMultiDeviceFixture;
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidDeviceHandlesAndHwmonInterfaceExistThenSuccessIsReturned) {
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
PublicLinuxPowerImp *pPowerImp = new PublicLinuxPowerImp(pOsSysman, onSubdevice, subdeviceId);
|
||||
EXPECT_TRUE(pPowerImp->isPowerModuleSupported());
|
||||
delete pPowerImp;
|
||||
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerPointerWhenGettingCardPowerDomainWhenhwmonInterfaceExistsAndThenCallSucceeds) {
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenScanDirectoriesFailAndPmtIsNullForSubDeviceZeroWhenGettingCardPowerThenReturnsFailure) {
|
||||
|
||||
pSysfsAccess->mockScanDirEntriesReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
|
||||
pSysfsAccess->isRepeated = true;
|
||||
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
for (auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
if (pmtMapElement.first == 0) {
|
||||
delete pmtMapElement.second;
|
||||
pmtMapElement.second = nullptr;
|
||||
}
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power_prelim.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
constexpr uint32_t powerHandleComponentCountMultiDevice = 3u;
|
||||
|
||||
class SysmanDevicePowerMultiDeviceFixtureHelper : public SysmanDevicePowerMultiDeviceFixture {
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SysmanDevicePowerMultiDeviceFixture::SetUp();
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
SysmanDevicePowerMultiDeviceFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenInvalidComponentCountWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCountMultiDevice);
|
||||
|
||||
count = count + 1;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCountMultiDevice);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerPointerWhenGettingCardPowerDomainWhenhwmonInterfaceExistsAndThenCallSucceds) {
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGettingPowerPropertiesThenCallSucceeds) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
if (properties.onSubdevice) {
|
||||
EXPECT_FALSE(properties.canControl);
|
||||
EXPECT_EQ(properties.defaultLimit, -1);
|
||||
|
||||
} else {
|
||||
EXPECT_EQ(properties.canControl, true);
|
||||
EXPECT_EQ(properties.defaultLimit, -1);
|
||||
}
|
||||
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGettingPowerPropertiesAndExtPropertiesThenCallSucceeds) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
zes_power_limit_ext_desc_t defaultLimit = {};
|
||||
|
||||
extProperties.defaultLimit = &defaultLimit;
|
||||
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
|
||||
properties.pNext = &extProperties;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
EXPECT_EQ(properties.defaultLimit, -1);
|
||||
EXPECT_TRUE(defaultLimit.limitValueLocked);
|
||||
EXPECT_TRUE(defaultLimit.enabledStateLocked);
|
||||
EXPECT_TRUE(defaultLimit.intervalValueLocked);
|
||||
EXPECT_EQ(defaultLimit.level, ZES_POWER_LEVEL_UNKNOWN);
|
||||
EXPECT_EQ(defaultLimit.source, ZES_POWER_SOURCE_ANY);
|
||||
EXPECT_EQ(defaultLimit.limitUnit, ZES_LIMIT_UNIT_POWER);
|
||||
if (properties.onSubdevice) {
|
||||
EXPECT_FALSE(properties.canControl);
|
||||
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_PACKAGE);
|
||||
EXPECT_EQ(defaultLimit.limit, -1);
|
||||
} else {
|
||||
EXPECT_TRUE(properties.canControl);
|
||||
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
|
||||
EXPECT_EQ(defaultLimit.limit, static_cast<int32_t>(mockDefaultPowerLimitVal / milliFactor));
|
||||
}
|
||||
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleAndExtPropertiesWithNullDescWhenGettingPowerPropertiesThenCallSucceeds) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
|
||||
properties.pNext = &extProperties;
|
||||
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
EXPECT_EQ(properties.defaultLimit, -1);
|
||||
if (properties.onSubdevice) {
|
||||
EXPECT_FALSE(properties.canControl);
|
||||
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_PACKAGE);
|
||||
} else {
|
||||
EXPECT_TRUE(properties.canControl);
|
||||
EXPECT_EQ(extProperties.domain, ZES_POWER_DOMAIN_CARD);
|
||||
}
|
||||
EXPECT_EQ(properties.isEnergyThresholdSupported, false);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenScanDiectoriesFailAndPmtIsNullForSubDeviceZeroWhenGettingCardPowerThenReturnsFailure) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
for (auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
if (pmtMapElement.first == 0) {
|
||||
delete pmtMapElement.second;
|
||||
pmtMapElement.second = nullptr;
|
||||
}
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenReadingToSysNodesFailsWhenCallingGetPowerLimitsExtThenPowerLimitCountIsZero) {
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
for (auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
if (pmtMapElement.first == 0) {
|
||||
delete pmtMapElement.second;
|
||||
pmtMapElement.second = nullptr;
|
||||
}
|
||||
}
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, nullptr));
|
||||
EXPECT_EQ(count, 0u);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
zes_power_energy_counter_t energyCounter = {};
|
||||
ASSERT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
|
||||
if (properties.subdeviceId == 0) {
|
||||
EXPECT_EQ(energyCounter.energy, expectedEnergyCounterTile0);
|
||||
} else if (properties.subdeviceId == 1) {
|
||||
EXPECT_EQ(energyCounter.energy, expectedEnergyCounterTile1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenSetPowerLimitsWhenGettingPowerLimitsThenLimitsSetEarlierAreRetrieved) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
sustainedSet.power = 300000;
|
||||
if (!properties.onSubdevice) {
|
||||
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);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, &sustainedSet, nullptr, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustainedGet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
EXPECT_EQ(burstGet.enabled, false);
|
||||
EXPECT_EQ(burstGet.power, -1);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
}
|
||||
|
||||
zes_power_peak_limit_t peakSet = {};
|
||||
zes_power_peak_limit_t peakGet = {};
|
||||
peakSet.powerAC = 300000;
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, nullptr, &peakSet));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
|
||||
EXPECT_EQ(peakGet.powerAC, peakSet.powerAC);
|
||||
EXPECT_EQ(peakGet.powerDC, -1);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtThenLimitsSetEarlierAreRetrieved, IsPVC) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
|
||||
uint32_t limitCount = 0;
|
||||
const int32_t testLimit = 3000000;
|
||||
const int32_t testInterval = 10;
|
||||
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_limit_ext_desc_t limits = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, &limits));
|
||||
EXPECT_EQ(limitCount, 0u);
|
||||
}
|
||||
|
||||
limitCount++;
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, 0u);
|
||||
}
|
||||
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(limitCount);
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
EXPECT_EQ(limitCount, 0u);
|
||||
}
|
||||
for (uint32_t i = 0; i < limitCount; i++) {
|
||||
if (allLimits[i].level == ZES_POWER_LEVEL_SUSTAINED) {
|
||||
EXPECT_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_FALSE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
allLimits[i].interval = testInterval;
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_TRUE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_CURRENT, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
}
|
||||
}
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
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(testInterval, allLimits[i].interval);
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_EQ(0, allLimits[i].interval);
|
||||
}
|
||||
EXPECT_EQ(testLimit, allLimits[i].limit);
|
||||
}
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDevicePowerMultiDeviceFixtureHelper, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtThenLimitsSetEarlierAreRetrieved, IsDG1) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCountMultiDevice);
|
||||
for (auto handle : handles) {
|
||||
uint32_t limitCount = 0;
|
||||
const int32_t testLimit = 3000000;
|
||||
const int32_t testInterval = 10;
|
||||
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_limit_ext_desc_t limits = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetProperties(handle, &properties));
|
||||
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, &limits));
|
||||
EXPECT_EQ(limitCount, 0u);
|
||||
}
|
||||
|
||||
limitCount++;
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, 0u);
|
||||
}
|
||||
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(limitCount);
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
EXPECT_EQ(limitCount, 0u);
|
||||
}
|
||||
for (uint32_t i = 0; i < limitCount; i++) {
|
||||
if (allLimits[i].level == ZES_POWER_LEVEL_SUSTAINED) {
|
||||
EXPECT_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_FALSE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
allLimits[i].interval = testInterval;
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_TRUE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
}
|
||||
}
|
||||
if (!properties.onSubdevice) {
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
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(testInterval, allLimits[i].interval);
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_EQ(0, allLimits[i].interval);
|
||||
}
|
||||
EXPECT_EQ(testLimit, allLimits[i].limit);
|
||||
}
|
||||
} else {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,794 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power_prelim.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
static int fakeFileDescriptor = 123;
|
||||
constexpr uint64_t convertJouleToMicroJoule = 1000000u;
|
||||
constexpr uint32_t powerHandleComponentCount = 1u;
|
||||
|
||||
inline static int openMockPower(const char *pathname, int flags) {
|
||||
if (strcmp(pathname, "/sys/class/intel_pmt/telem2/telem") == 0) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
if (strcmp(pathname, "/sys/class/intel_pmt/telem3/telem") == 0) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline static int closeMockPower(int fd) {
|
||||
if (fd == fakeFileDescriptor) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t preadMockPower(int fd, void *buf, size_t count, off_t offset) {
|
||||
uint64_t *mockBuf = static_cast<uint64_t *>(buf);
|
||||
*mockBuf = setEnergyCounter;
|
||||
return count;
|
||||
}
|
||||
|
||||
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, GivenValidPowerPointerWhenGettingCardPowerDomainWhenhwmonInterfaceExistsAndThenCallSucceds) {
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_SUCCESS);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenInvalidPowerPointerWhenGettingCardPowerDomainAndThenReturnsFailure) {
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), nullptr), ZE_RESULT_ERROR_INVALID_NULL_POINTER);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenUninitializedPowerHandlesAndWhenGettingCardPowerDomainThenReurnsFailure) {
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenScanDiectoriesFailAndPmtIsNullWhenGettingCardPowerThenReturnsFailure) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
for (auto &pmtMapElement : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
if (pmtMapElement.second) {
|
||||
delete pmtMapElement.second;
|
||||
pmtMapElement.second = nullptr;
|
||||
}
|
||||
}
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
|
||||
zes_pwr_handle_t phPower = {};
|
||||
EXPECT_EQ(zesDeviceGetCardPowerDomain(device->toHandle(), &phPower), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
|
||||
}
|
||||
|
||||
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, -1);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesAndExtPropertiesThenCallSucceeds) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
zes_power_limit_ext_desc_t defaultLimit = {};
|
||||
|
||||
extProperties.defaultLimit = &defaultLimit;
|
||||
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
|
||||
properties.pNext = &extProperties;
|
||||
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, -1);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWithNoStypeForExtPropertiesWhenGettingPowerPropertiesAndExtPropertiesThenCallSucceeds) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
zes_power_limit_ext_desc_t defaultLimit = {};
|
||||
|
||||
extProperties.defaultLimit = &defaultLimit;
|
||||
properties.pNext = &extProperties;
|
||||
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, -1);
|
||||
EXPECT_EQ(properties.maxLimit, -1);
|
||||
EXPECT_EQ(properties.minLimit, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerPropertiesThenUnknownLimitsAreReturned) {
|
||||
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, GivenValidPowerHandleWhenGettingPowerEnergyCounterFailedWhenHwmonInterfaceExistThenValidErrorCodeReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
|
||||
pPmt->openFunction = openMockPower;
|
||||
pPmt->closeFunction = closeMockPower;
|
||||
pPmt->preadFunction = preadMockPower;
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
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.enabled = 1;
|
||||
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);
|
||||
|
||||
zes_power_burst_limit_t burstGet = {};
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, nullptr, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, &burstGet, nullptr));
|
||||
EXPECT_EQ(burstGet.enabled, false);
|
||||
EXPECT_EQ(burstGet.power, -1);
|
||||
|
||||
zes_power_peak_limit_t peakSet = {};
|
||||
zes_power_peak_limit_t peakGet = {};
|
||||
peakSet.powerAC = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handle, nullptr, nullptr, &peakSet));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
|
||||
EXPECT_EQ(peakGet.powerAC, peakSet.powerAC);
|
||||
EXPECT_EQ(peakGet.powerDC, -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenDefaultLimitSysfsNodesNotAvailableWhenGettingPowerPropertiesAndExtPropertiesThenApiCallReturnsFailure) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_properties_t properties = {};
|
||||
zes_power_ext_properties_t extProperties = {};
|
||||
zes_power_limit_ext_desc_t defaultLimit = {};
|
||||
|
||||
extProperties.defaultLimit = &defaultLimit;
|
||||
extProperties.stype = ZES_STRUCTURE_TYPE_POWER_EXT_PROPERTIES;
|
||||
properties.pNext = &extProperties;
|
||||
pSysfsAccess->mockReadResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetProperties(handle, &properties));
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDevicePowerFixture, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtThenLimitsSetEarlierAreRetrieved, IsPVC) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
|
||||
uint32_t limitCount = 0;
|
||||
const int32_t testLimit = 3000000;
|
||||
const int32_t testInterval = 10;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
|
||||
limitCount++;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(limitCount);
|
||||
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_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_FALSE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
allLimits[i].interval = testInterval;
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_TRUE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_CURRENT, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
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(testInterval, allLimits[i].interval);
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_EQ(0, allLimits[i].interval);
|
||||
}
|
||||
EXPECT_EQ(testLimit, allLimits[i].limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDevicePowerFixture, GivenValidPowerHandlesWhenCallingSetAndGetPowerLimitExtThenLimitsSetEarlierAreRetrieved, IsDG1) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
|
||||
uint32_t limitCount = 0;
|
||||
const int32_t testLimit = 3000000;
|
||||
const int32_t testInterval = 10;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
|
||||
limitCount++;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &limitCount, nullptr));
|
||||
EXPECT_EQ(limitCount, mockLimitCount);
|
||||
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(limitCount);
|
||||
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_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_FALSE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
allLimits[i].interval = testInterval;
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_FALSE(allLimits[i].limitValueLocked);
|
||||
EXPECT_TRUE(allLimits[i].enabledStateLocked);
|
||||
EXPECT_TRUE(allLimits[i].intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits[i].source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits[i].limitUnit);
|
||||
allLimits[i].limit = testLimit;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimitsExt(handle, &limitCount, allLimits.data()));
|
||||
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(testInterval, allLimits[i].interval);
|
||||
} else if (allLimits[i].level == ZES_POWER_LEVEL_PEAK) {
|
||||
EXPECT_EQ(0, allLimits[i].interval);
|
||||
}
|
||||
EXPECT_EQ(testLimit, allLimits[i].limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerLimitNodeReturnErrorWhenSetOrGetPowerLimitsWhenHwmonInterfaceExistForSustainedPowerLimitEnabledThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWriteResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
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, GivenValidPowerHandleAndWritingToSustainedLimitSysNodesFailsWhenCallingSetPowerLimitsExtThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWriteResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = mockLimitCount;
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
|
||||
pSysfsAccess->mockWriteUnsignedResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &count, allLimits.data()));
|
||||
pSysfsAccess->mockWriteUnsignedResult = ZE_RESULT_SUCCESS;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &count, allLimits.data()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndReadingToSustainedLimitSysNodesFailsWhenCallingGetPowerLimitsExtThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = mockLimitCount;
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_SUCCESS;
|
||||
count = mockLimitCount;
|
||||
pSysfsAccess->mockReadIntResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingToSysNodesFailsWhenCallingGetPowerLimitsExtThenPowerLimitCountIsZero) {
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, nullptr));
|
||||
EXPECT_EQ(count, 0u);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndWritingToPeakLimitSysNodesFailsWhenCallingSetPowerLimitsExtThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWritePeakLimitResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = mockLimitCount;
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &count, allLimits.data()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndReadingToPeakLimitSysNodesFailsWhenCallingGetPowerLimitsExtThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockReadPeakResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = mockLimitCount;
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingBurstPowerLimitThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_limit_ext_desc_t allLimits{};
|
||||
uint32_t count = 1;
|
||||
allLimits.level = ZES_POWER_LEVEL_BURST;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &count, &allLimits));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenCallingGetPowerLimitsExtThenProperValuesAreReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_limit_ext_desc_t allLimits{};
|
||||
uint32_t count = 0;
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, nullptr));
|
||||
EXPECT_EQ(count, mockLimitCount);
|
||||
|
||||
count = 1;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, &allLimits));
|
||||
EXPECT_EQ(count, 1u);
|
||||
EXPECT_EQ(false, allLimits.limitValueLocked);
|
||||
EXPECT_EQ(true, allLimits.enabledStateLocked);
|
||||
EXPECT_EQ(false, allLimits.intervalValueLocked);
|
||||
EXPECT_EQ(ZES_POWER_SOURCE_ANY, allLimits.source);
|
||||
EXPECT_EQ(ZES_LIMIT_UNIT_POWER, allLimits.limitUnit);
|
||||
EXPECT_EQ(ZES_POWER_LEVEL_SUSTAINED, allLimits.level);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndWritingToPeakLimitSysNodesFailsWhenCallingSetPowerLimitsExtThenProperErrorCodesReturned, IsPVC) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWritePeakLimitResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = mockLimitCount;
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &count, allLimits.data()));
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST2_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndWritingToPeakLimitSysNodesFailsWhenCallingSetPowerLimitsExtThenProperErrorCodesReturned, IsDG1) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWritePeakLimitResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
uint32_t count = mockLimitCount;
|
||||
std::vector<zes_power_limit_ext_desc_t> allLimits(mockLimitCount);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimitsExt(handle, &count, allLimits.data()));
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimitsExt(handle, &count, allLimits.data()));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingPeakPowerLimitNodeReturnErrorWhenSetOrGetPowerLimitsWhenHwmonInterfaceExistForPeakPowerLimitEnabledThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWriteResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_peak_limit_t peakSet = {};
|
||||
zes_power_peak_limit_t peakGet = {};
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, nullptr, nullptr, &peakSet));
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenReadingSustainedPowerNodeReturnErrorWhenGetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
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, GivenReadingpeakPowerNodeReturnErrorWhenGetPowerLimitsForpeakPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_peak_limit_t peakGet = {};
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, nullptr, nullptr, &peakGet));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenwritingSustainedPowerNodeReturnErrorWhenSetPowerLimitsForSustainedPowerWhenHwmonInterfaceExistThenProperErrorCodesReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWriteResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.enabled = 1;
|
||||
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);
|
||||
|
||||
pSysfsAccess->mockWriteResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.enabled = 1;
|
||||
sustainedSet.interval = 10;
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenWritingToSustainedPowerEnableNodeWithoutPermissionsThenValidErrorIsReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
pSysfsAccess->mockWriteResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
sustainedSet.enabled = 0;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleAndPermissionsThenFirstDisableSustainedPowerLimitAndThenEnableItAndCheckSuccesIsReturned) {
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
zes_power_sustained_limit_t sustainedSet = {};
|
||||
zes_power_sustained_limit_t sustainedGet = {};
|
||||
sustainedSet.enabled = 0;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
sustainedSet.power = 300000;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerSetLimits(handles[0], &sustainedSet, nullptr, nullptr));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetLimits(handles[0], &sustainedGet, nullptr, nullptr));
|
||||
EXPECT_EQ(sustainedGet.power, sustainedSet.power);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenScanDirectoriesFailAndPmtIsNotNullPointerThenPowerModuleIsSupported) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
ze_bool_t onSubdevice = (subDeviceCount == 0) ? false : true;
|
||||
uint32_t subdeviceId = 0;
|
||||
PublicLinuxPowerImp *pPowerImp = new PublicLinuxPowerImp(pOsSysman, onSubdevice, subdeviceId);
|
||||
EXPECT_TRUE(pPowerImp->isPowerModuleSupported());
|
||||
delete pPowerImp;
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
uint32_t count = 0;
|
||||
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
|
||||
EXPECT_EQ(count, powerHandleComponentCount);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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, GivenComponentCountZeroWhenEnumeratingPowerDomainsThenValidPowerHandlesIsReturned) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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, GivenValidPowerHandleWhenGettingPowerPropertiesThenCallSucceeds) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrieved) {
|
||||
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
|
||||
pPmt->openFunction = openMockPower;
|
||||
pPmt->closeFunction = closeMockPower;
|
||||
pPmt->preadFunction = preadMockPower;
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
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, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFileReturnsErrorAndPmtFailsThenFailureIsReturned) {
|
||||
pSysfsAccess->mockReadValUnsignedLongResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
for (auto &subDeviceIdToPmtEntry : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) {
|
||||
delete subDeviceIdToPmtEntry.second;
|
||||
}
|
||||
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
uint32_t subdeviceId = 0;
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
|
||||
do {
|
||||
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, nullptr);
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
for (auto handle : handles) {
|
||||
zes_power_energy_counter_t energyCounter = {};
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetEnergyCounter(handle, &energyCounter));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
zes_energy_threshold_t threshold;
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetEnergyThreshold(handle, &threshold));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
double threshold = 0;
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetEnergyThreshold(handle, threshold));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenGettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustained;
|
||||
zes_power_burst_limit_t burst;
|
||||
zes_power_peak_limit_t peak;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerGetLimits(handle, &sustained, &burst, &peak));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerFixture, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned) {
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(pLinuxSysmanImp->getSubDeviceCount());
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
for (auto handle : handles) {
|
||||
zes_power_sustained_limit_t sustained;
|
||||
zes_power_burst_limit_t burst;
|
||||
zes_power_peak_limit_t peak;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesPowerSetLimits(handle, &sustained, &burst, &peak));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(SysmanDevicePowerMultiDeviceFixture, GivenValidPowerHandleWhenGettingPowerEnergyCounterWhenEnergyHwmonFailsThenValidPowerReadingsRetrievedFromPmt) {
|
||||
pSysfsAccess->mockscanDirEntriesResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
for (const auto &handle : pSysmanDeviceImp->pPowerHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPowerHandleContext->handleList.clear();
|
||||
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
|
||||
pSysmanDeviceImp->pPowerHandleContext->init(subDeviceCount);
|
||||
auto handles = getPowerHandles(powerHandleComponentCount);
|
||||
|
||||
uint32_t subdeviceId = 0;
|
||||
do {
|
||||
auto pPmt = static_cast<MockPowerPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId));
|
||||
pPmt->openFunction = openMockPower;
|
||||
pPmt->closeFunction = closeMockPower;
|
||||
pPmt->preadFunction = preadMockPower;
|
||||
} while (++subdeviceId < subDeviceCount);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user