diff --git a/level_zero/sysman/source/api/power/linux/sysman_os_power_imp.cpp b/level_zero/sysman/source/api/power/linux/sysman_os_power_imp.cpp index 54fb8b1054..92d79892aa 100644 --- a/level_zero/sysman/source/api/power/linux/sysman_os_power_imp.cpp +++ b/level_zero/sysman/source/api/power/linux/sysman_os_power_imp.cpp @@ -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 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) { diff --git a/level_zero/sysman/source/shared/linux/product_helper/gen12lp/dg1/sysman_product_helper_dg1.cpp b/level_zero/sysman/source/shared/linux/product_helper/gen12lp/dg1/sysman_product_helper_dg1.cpp index 6f65287bcf..1c63a2b6c2 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/gen12lp/dg1/sysman_product_helper_dg1.cpp +++ b/level_zero/sysman/source/shared/linux/product_helper/gen12lp/dg1/sysman_product_helper_dg1.cpp @@ -19,13 +19,11 @@ constexpr static auto gfxProduct = IGFX_DG1; static std::map> 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}}}}; diff --git a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h index 05eeeaeebf..e7a6461c9f 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h +++ b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h @@ -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; diff --git a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.h b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.h index 211d5c28ca..79ff87f322 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.h +++ b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.h @@ -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; diff --git a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl index 4e73567907..571025cc7a 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl +++ b/level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper_hw.inl @@ -318,6 +318,11 @@ SysfsValueUnit SysmanProductHelperHw::getPackageCriticalPowerLimitNa return SysfsValueUnit::micro; } +template +ze_result_t SysmanProductHelperHw::getPowerEnergyCounter(zes_power_energy_counter_t *pEnergy, LinuxSysmanImp *pLinuxSysmanImp, zes_power_domain_t powerDomain, uint32_t subdeviceId) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + template bool SysmanProductHelperHw::isStandbySupported(SysmanKmdInterface *pSysmanKmdInterface) { return pSysmanKmdInterface->isStandbyModeControlAvailable(); diff --git a/level_zero/sysman/source/shared/linux/product_helper/xe_hpg_core/dg2/sysman_product_helper_dg2.cpp b/level_zero/sysman/source/shared/linux/product_helper/xe_hpg_core/dg2/sysman_product_helper_dg2.cpp index fec7d9007f..9aa929c8c3 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/xe_hpg_core/dg2/sysman_product_helper_dg2.cpp +++ b/level_zero/sysman/source/shared/linux/product_helper/xe_hpg_core/dg2/sysman_product_helper_dg2.cpp @@ -202,6 +202,36 @@ ze_result_t SysmanProductHelperHw::getMemoryBandwidth(zes_mem_bandwi return result; } +template <> +ze_result_t SysmanProductHelperHw::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 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::isEccConfigurationSupported() { return true; diff --git a/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h b/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h index bc9ce7b2a1..f64b59cf4b 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h +++ b/level_zero/sysman/test/unit_tests/sources/power/linux/mock_sysfs_power.h @@ -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"); diff --git a/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp b/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp index ad6e5dba68..18189804d5 100644 --- a/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp +++ b/level_zero/sysman/test/unit_tests/sources/power/linux/test_zes_power.cpp @@ -561,6 +561,14 @@ TEST_F(SysmanDevicePowerFixtureI915, GivenHwMonDoesNotExistAndTelemDataNotAvaila } } +TEST_F(SysmanDevicePowerFixtureI915, GivenValidPowerHandlesWithTelemetrySupportNotAvailableButSysfsReadSucceedsWhenGettingPowerEnergyCounterThenValidPowerReadingsRetrievedFromSysfsNode) { + zes_power_energy_counter_t energyCounter = {}; + std::unique_ptr 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; diff --git a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_pmt_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_pmt_tests.cpp index 1f03e9845a..6df2365532 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_pmt_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_pmt_tests.cpp @@ -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> 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")); } diff --git a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_power_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_power_tests.cpp index 66c4c33f89..151f050e29 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_power_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_power_tests.cpp @@ -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 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); + VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); + VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); + VariableBackup 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 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); + VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); + VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); + VariableBackup 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 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); + VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); + VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); + VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); + VariableBackup 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((setEnergyCounter / fixedPointToJoule) * convertJouleToMicroJoule); + + EXPECT_EQ(energyCounter.energy, outputEnergyCounter); + } +} + HWTEST2_F(SysmanProductHelperPowerTest, GivenValidSubdevicePowerHandleForPackagePackageDomainWithTelemetrySupportNotAvailableAndSysfsNodeReadFailsWhenGettingPowerEnergyCounterThenFailureIsReturned, IsPVC) { VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); - VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); - VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); - VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); - VariableBackup 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 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); - VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); - VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); - VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); - VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); - VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); - VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); - VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); - VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); - VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); - VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); - VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); - VariableBackup mockStat(&NEO::SysCalls::sysCallsStat, &mockStatSuccess); - VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); - VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); - VariableBackup mockOpen(&NEO::SysCalls::sysCallsOpen, &mockOpenSuccess); - VariableBackup allowFakeDevicePathBackup(&NEO::SysCalls::allowFakeDevicePath, true); - VariableBackup 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 mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);