refactor(sysman): Move getEnergyCounter implementation to product specific file

Related-To: NEO-11296

Signed-off-by: Anvesh Bakwad <anvesh.bakwad@intel.com>
This commit is contained in:
Anvesh Bakwad 2025-02-21 16:17:16 +00:00 committed by Compute-Runtime-Automation
parent 51f275dc09
commit a017025e67
10 changed files with 150 additions and 256 deletions

View File

@ -76,38 +76,11 @@ ze_result_t LinuxPowerImp::getPropertiesExt(zes_power_ext_properties_t *pExtPope
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxPowerImp::getPmtEnergyCounter(zes_power_energy_counter_t *pEnergy) {
std::string telemDir = "";
std::string guid = "";
uint64_t telemOffset = 0;
if (!pLinuxSysmanImp->getTelemData(subdeviceId, telemDir, guid, telemOffset)) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
std::map<std::string, uint64_t> keyOffsetMap;
if (!PlatformMonitoringTech::getKeyOffsetMap(pSysmanProductHelper, guid, keyOffsetMap)) {
return ZE_RESULT_ERROR_UNKNOWN;
}
const std::string key("PACKAGE_ENERGY");
uint64_t energy = 0;
constexpr uint64_t fixedPointToJoule = 1048576;
if (!PlatformMonitoringTech::readValue(keyOffsetMap, telemDir, key, telemOffset, energy)) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
// 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 ZE_RESULT_SUCCESS;
}
ze_result_t LinuxPowerImp::getEnergyCounter(zes_power_energy_counter_t *pEnergy) {
ze_result_t result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
if (isTelemetrySupportAvailable) {
result = getPmtEnergyCounter(pEnergy);
result = pSysmanProductHelper->getPowerEnergyCounter(pEnergy, pLinuxSysmanImp, powerDomain, subdeviceId);
}
if (result != ZE_RESULT_SUCCESS) {

View File

@ -19,13 +19,11 @@ constexpr static auto gfxProduct = IGFX_DG1;
static std::map<std::string, std::map<std::string, uint64_t>> guidToKeyOffsetMap = {
{"0x490e01", // DG1 B stepping
{{"PACKAGE_ENERGY", 0x420},
{"COMPUTE_TEMPERATURES", 0x68},
{{"COMPUTE_TEMPERATURES", 0x68},
{"SOC_TEMPERATURES", 0x60},
{"CORE_TEMPERATURES", 0x6c}}},
{"0x490e", // DG1 A stepping
{{"PACKAGE_ENERGY", 0x400},
{"COMPUTE_TEMPERATURES", 0x68},
{{"COMPUTE_TEMPERATURES", 0x68},
{"SOC_TEMPERATURES", 0x60},
{"CORE_TEMPERATURES", 0x6c}}}};

View File

@ -81,6 +81,7 @@ class SysmanProductHelper {
virtual bool isPowerSetLimitSupported() = 0;
virtual std::string getPackageCriticalPowerLimitFile() = 0;
virtual SysfsValueUnit getPackageCriticalPowerLimitNativeUnit() = 0;
virtual ze_result_t getPowerEnergyCounter(zes_power_energy_counter_t *pEnergy, LinuxSysmanImp *pLinuxSysmanImp, zes_power_domain_t powerDomain, uint32_t subDeviceId) = 0;
// standby
virtual bool isStandbySupported(SysmanKmdInterface *pSysmanKmdInterface) = 0;

View File

@ -56,6 +56,7 @@ class SysmanProductHelperHw : public SysmanProductHelper {
bool isPowerSetLimitSupported() override;
std::string getPackageCriticalPowerLimitFile() override;
SysfsValueUnit getPackageCriticalPowerLimitNativeUnit() override;
ze_result_t getPowerEnergyCounter(zes_power_energy_counter_t *pEnergy, LinuxSysmanImp *pLinuxSysmanImp, zes_power_domain_t powerDomain, uint32_t subDeviceId) override;
// standby
bool isStandbySupported(SysmanKmdInterface *pSysmanKmdInterface) override;

View File

@ -318,6 +318,11 @@ SysfsValueUnit SysmanProductHelperHw<gfxProduct>::getPackageCriticalPowerLimitNa
return SysfsValueUnit::micro;
}
template <PRODUCT_FAMILY gfxProduct>
ze_result_t SysmanProductHelperHw<gfxProduct>::getPowerEnergyCounter(zes_power_energy_counter_t *pEnergy, LinuxSysmanImp *pLinuxSysmanImp, zes_power_domain_t powerDomain, uint32_t subdeviceId) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
template <PRODUCT_FAMILY gfxProduct>
bool SysmanProductHelperHw<gfxProduct>::isStandbySupported(SysmanKmdInterface *pSysmanKmdInterface) {
return pSysmanKmdInterface->isStandbyModeControlAvailable();

View File

@ -202,6 +202,36 @@ ze_result_t SysmanProductHelperHw<gfxProduct>::getMemoryBandwidth(zes_mem_bandwi
return result;
}
template <>
ze_result_t SysmanProductHelperHw<gfxProduct>::getPowerEnergyCounter(zes_power_energy_counter_t *pEnergy, LinuxSysmanImp *pLinuxSysmanImp, zes_power_domain_t powerDomain, uint32_t subdeviceId) {
std::string telemDir = "";
std::string guid = "";
uint64_t telemOffset = 0;
if (!pLinuxSysmanImp->getTelemData(subdeviceId, telemDir, guid, telemOffset)) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
std::map<std::string, uint64_t> keyOffsetMap;
if (!PlatformMonitoringTech::getKeyOffsetMap(this, guid, keyOffsetMap)) {
return ZE_RESULT_ERROR_UNKNOWN;
}
const std::string key("PACKAGE_ENERGY");
uint64_t energyCounter = 0;
constexpr uint64_t fixedPointToJoule = 1048576;
if (!PlatformMonitoringTech::readValue(keyOffsetMap, telemDir, key, telemOffset, energyCounter)) {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
// 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 = (energyCounter / fixedPointToJoule) * convertJouleToMicroJoule;
return ZE_RESULT_SUCCESS;
}
template <>
bool SysmanProductHelperHw<gfxProduct>::isEccConfigurationSupported() {
return true;

View File

@ -21,7 +21,6 @@ namespace L0 {
namespace Sysman {
namespace ult {
constexpr uint64_t setEnergyCounter = (83456u * 1048576u);
constexpr uint64_t mockKeyOffset = 0x420;
constexpr uint32_t mockLimitCount = 2u;
const std::string hwmonDir("device/hwmon");

View File

@ -561,6 +561,14 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenHwMonDoesNotExistAndTelemDataNotAvaila
}
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode) {
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0, ZES_POWER_DOMAIN_PACKAGE));
pLinuxPowerImp->isTelemetrySupportAvailable = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxPowerImp->getEnergyCounter(&energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandleWhenGettingPowerEnergyThresholdThenUnsupportedFeatureErrorIsReturned) {
zes_energy_threshold_t threshold;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -17,13 +17,13 @@ using SysmanProductHelperPmtTest = ::testing::Test;
HWTEST2_F(SysmanProductHelperPmtTest, GivenSysmanProductHelperInstanceWhenGetGuidToKeyOffsetMapIsCalledThenValidMapIsReturned, IsDG1) {
const std::map<std::string, std::map<std::string, uint64_t>> mockDg1GuidToKeyOffsetMap = {{"0x490e01",
{{"PACKAGE_ENERGY", 0x420},
{{"SOC_TEMPERATURES", 0x60},
{"COMPUTE_TEMPERATURES", 0x68}}}};
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
auto pGuidToKeyOffsetMap = pSysmanProductHelper->getGuidToKeyOffsetMap();
EXPECT_NE(nullptr, pGuidToKeyOffsetMap);
EXPECT_EQ(mockDg1GuidToKeyOffsetMap.at("0x490e01").at("PACKAGE_ENERGY"), (*pGuidToKeyOffsetMap).at("0x490e01").at("PACKAGE_ENERGY"));
EXPECT_EQ(mockDg1GuidToKeyOffsetMap.at("0x490e01").at("SOC_TEMPERATURES"), (*pGuidToKeyOffsetMap).at("0x490e01").at("SOC_TEMPERATURES"));
EXPECT_EQ(mockDg1GuidToKeyOffsetMap.at("0x490e01").at("COMPUTE_TEMPERATURES"), (*pGuidToKeyOffsetMap).at("0x490e01").at("COMPUTE_TEMPERATURES"));
}

View File

@ -58,9 +58,6 @@ static ssize_t mockReadSuccess(int fd, void *buf, size_t count, off_t offset) {
} else if (fd == 5) {
oStream << "0x490e01";
} else if (fd == 6) {
if (offset == mockKeyOffset) {
val = setEnergyCounter;
}
memcpy(buf, &val, count);
return count;
} else if (fd == 7) {
@ -143,7 +140,13 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidProductHelperHandleWhenCalling
EXPECT_TRUE(pSysmanProductHelper->isPowerSetLimitSupported());
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWhenGettingPowerEnergyCounterThenFailureIsReturned, IsNotDG2) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pSysmanProductHelper->getPowerEnergyCounter(&energyCounter, pLinuxSysmanImp, ZES_POWER_DOMAIN_PACKAGE, 0));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
@ -151,18 +154,20 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackag
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackageDomainWithTelemetryDataNotAvailableAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetryDataNotAvailableAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0xb15a0ede";
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
@ -173,6 +178,94 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidRootDevicePowerHandleForPackag
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetryOffsetReadFailsAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::string invalidGuid = "0x4f9302";
if (fd == 4) {
count = -1;
}
return count;
});
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0, ZES_POWER_DOMAIN_PACKAGE));
pLinuxPowerImp->isTelemetrySupportAvailable = true;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleForPackageDomainWithTelemetryKeyOffsetMapNotAvailableAndSysfsNodeReadAlsoFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string invalidGuid = "0xABCDEFG";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, invalidGuid.data(), count);
}
return count;
});
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, false, 0, ZES_POWER_DOMAIN_PACKAGE));
pLinuxPowerImp->isTelemetrySupportAvailable = true;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportAvailableWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromPmtNode, IsDG2) {
static uint64_t setEnergyCounter = 123456u;
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
memcpy(buf, &setEnergyCounter, count);
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
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(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
// Calculate output energyCounter value
constexpr uint64_t fixedPointToJoule = 1048576;
uint64_t outputEnergyCounter = static_cast<uint64_t>((setEnergyCounter / fixedPointToJoule) * convertJouleToMicroJoule);
EXPECT_EQ(energyCounter.energy, outputEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackagePackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
@ -181,220 +274,6 @@ HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackage
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackageDomainWithTelemetrySupportAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0xb15a0ede";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
}
return count;
});
pSysfsAccess->mockReadValUnsignedLongResult.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
zes_power_energy_counter_t energyCounter = {};
std::unique_ptr<PublicLinuxPowerImp> pLinuxPowerImp(new PublicLinuxPowerImp(pOsSysman, true, 0, ZES_POWER_DOMAIN_PACKAGE));
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pLinuxPowerImp->getEnergyCounter(&energyCounter));
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0xb15a0ede";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
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(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportAvailableWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromPmtNode, IsDG1) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x490e01";
// uint32_t mockKeyValue = 0x3;
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
memcpy(buf, &setEnergyCounter, count);
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
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(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode, IsDG1) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x490e01";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
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(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportAvailableWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromPmtNode, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
memcpy(buf, &setEnergyCounter, count);
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
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(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
uint64_t expectedEnergyCounter = convertJouleToMicroJoule * (setEnergyCounter / 1048576);
EXPECT_EQ(energyCounter.energy, expectedEnergyCounter);
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess);
VariableBackup<bool> allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true);
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
uint64_t telem1Offset = 0;
std::string validGuid = "0x4f9302";
if (fd == 4) {
memcpy(buf, &telem1Offset, count);
} else if (fd == 5) {
memcpy(buf, validGuid.data(), count);
} else if (fd == 6) {
count = -1;
}
return count;
});
auto handles = getPowerHandles(powerHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
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(ZES_POWER_DOMAIN_PACKAGE, extProperties.domain);
zes_power_energy_counter_t energyCounter = {};
EXPECT_EQ(ZE_RESULT_SUCCESS, zesPowerGetEnergyCounter(handle, &energyCounter));
}
}
HWTEST2_F(SysmanProductHelperPowerTest, GivenValidPowerHandleWhenSettingPowerLimitsThenUnsupportedFeatureErrorIsReturned, IsDG1) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);