diff --git a/level_zero/sysman/source/api/events/linux/sysman_os_events_imp.cpp b/level_zero/sysman/source/api/events/linux/sysman_os_events_imp.cpp index 03136e87e1..757fac979b 100644 --- a/level_zero/sysman/source/api/events/linux/sysman_os_events_imp.cpp +++ b/level_zero/sysman/source/api/events/linux/sysman_os_events_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,7 +11,7 @@ #include "shared/source/utilities/directory.h" #include "level_zero/sysman/source/api/events/sysman_events_imp.h" -#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h" +#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h" #include "level_zero/sysman/source/driver/sysman_driver_handle_imp.h" #include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" #include "level_zero/sysman/source/shared/linux/zes_os_sysman_driver_imp.h" diff --git a/level_zero/sysman/source/api/memory/linux/CMakeLists.txt b/level_zero/sysman/source/api/memory/linux/CMakeLists.txt index 062b926fa8..5067d3d837 100755 --- a/level_zero/sysman/source/api/memory/linux/CMakeLists.txt +++ b/level_zero/sysman/source/api/memory/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2023 Intel Corporation +# Copyright (C) 2020-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,20 +8,7 @@ if(UNIX) target_sources(${L0_STATIC_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.h + ${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.cpp ) - - if(NEO_ENABLE_i915_PRELIM_DETECTION) - target_sources(${L0_STATIC_LIB_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp_prelim.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp_prelim.h - ) - else() - target_sources(${L0_STATIC_LIB_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.h - ${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.cpp - ) - endif() - endif() diff --git a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp index 6b9fca308a..1306dd4147 100644 --- a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp +++ b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.cpp @@ -11,13 +11,14 @@ #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/memory_manager/memory_banks.h" #include "shared/source/os_interface/linux/drm_neo.h" +#include "shared/source/os_interface/linux/ioctl_helper.h" #include "shared/source/os_interface/linux/memory_info.h" -#include "shared/source/os_interface/linux/system_info.h" #include "level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h" #include "level_zero/sysman/source/shared/linux/pmt/sysman_pmt.h" #include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h" #include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h" +#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h" namespace L0 { namespace Sysman { @@ -37,43 +38,51 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) { } ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { + ze_result_t status = ZE_RESULT_SUCCESS; pState->health = ZES_MEM_HEALTH_UNKNOWN; FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); - if (pFwInterface != nullptr) { - pFwInterface->fwGetMemoryHealthIndicator(&pState->health); - } + // get memory health indicator if supported + auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper(); + pSysmanProductHelper->getMemoryHealthIndicator(pFwInterface, &pState->health); std::unique_ptr memoryInfo; - { - auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceIdInstance(); - memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo(); + auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceIdInstance(); + memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo(); + if (!memoryInfo) { + pState->free = 0; + pState->size = 0; + status = ZE_RESULT_ERROR_UNKNOWN; + if (errno == ENODEV) { + status = ZE_RESULT_ERROR_DEVICE_LOST; + } + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, + "Error@ %s():createMemoryInfo failed errno:%d \n", __FUNCTION__, errno); + return status; } auto region = memoryInfo->getMemoryRegion(MemoryBanks::getBankForLocalMemory(subdeviceId)); - pState->free = region.unallocatedSize; pState->size = region.probedSize; - - return ZE_RESULT_SUCCESS; + return status; } LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { pLinuxSysmanImp = static_cast(pOsSysman); - pDevice = pLinuxSysmanImp->getSysmanDeviceImp(); pDrm = pLinuxSysmanImp->getDrm(); + pDevice = pLinuxSysmanImp->getSysmanDeviceImp(); pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId); pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface(); } -std::unique_ptr OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) { - std::unique_ptr pLinuxMemoryImp = std::make_unique(pOsSysman, onSubdevice, subdeviceId); - return pLinuxMemoryImp; -} - bool LinuxMemoryImp::isMemoryModuleSupported() { auto &gfxCoreHelper = pDevice->getRootDeviceEnvironment().getHelper(); return gfxCoreHelper.getEnableLocalMemory(pDevice->getHardwareInfo()); } +std::unique_ptr OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) { + std::unique_ptr pLinuxMemoryImp = std::make_unique(pOsSysman, onSubdevice, subdeviceId); + return pLinuxMemoryImp; +} + } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h index 545f52c67a..b40b2b0659 100644 --- a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h +++ b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,10 +7,10 @@ #pragma once #include "shared/source/helpers/non_copyable_or_moveable.h" -#include "shared/source/os_interface/linux/drm_neo.h" #include "level_zero/sysman/source/api/memory/sysman_os_memory.h" -#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h" + +#include namespace NEO { class Drm; @@ -19,9 +19,10 @@ class Drm; namespace L0 { namespace Sysman { -class SysmanKmdInterface; class PlatformMonitoringTech; class LinuxSysmanImp; +class SysmanKmdInterface; +struct SysmanDeviceImp; class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { public: @@ -37,8 +38,8 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { LinuxSysmanImp *pLinuxSysmanImp = nullptr; NEO::Drm *pDrm = nullptr; SysmanDeviceImp *pDevice = nullptr; - SysmanKmdInterface *pSysmanKmdInterface = nullptr; PlatformMonitoringTech *pPmt = nullptr; + SysmanKmdInterface *pSysmanKmdInterface = nullptr; private: bool isSubdevice = false; diff --git a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.cpp b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.cpp deleted file mode 100644 index 068ebca47f..0000000000 --- a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h" - -#include "shared/source/debug_settings/debug_settings_manager.h" -#include "shared/source/helpers/gfx_core_helper.h" -#include "shared/source/memory_manager/memory_banks.h" -#include "shared/source/os_interface/linux/i915.h" -#include "shared/source/os_interface/linux/ioctl_helper.h" -#include "shared/source/os_interface/linux/memory_info.h" -#include "shared/source/os_interface/linux/system_info.h" - -#include "level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h" -#include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h" -#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" -#include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h" -#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h" -#include "level_zero/sysman/source/sysman_const.h" - -#include "igfxfmid.h" - -namespace L0 { -namespace Sysman { - -const std::string LinuxMemoryImp::deviceMemoryHealth("device_memory_health"); - -ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { - auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper(); - return pSysmanProductHelper->getMemoryProperties(pProperties, pLinuxSysmanImp, pDrm, pSysmanKmdInterface, subdeviceId, isSubdevice); -} - -ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) { - if (pPmt == nullptr) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - - auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper(); - return pSysmanProductHelper->getMemoryBandwidth(pBandwidth, pPmt, pDevice, pSysmanKmdInterface, subdeviceId); -} - -ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { - ze_result_t status = ZE_RESULT_SUCCESS; - pState->health = ZES_MEM_HEALTH_UNKNOWN; - FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); - // get memory health indicator if supported - auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper(); - pSysmanProductHelper->getMemoryHealthIndicator(pFwInterface, &pState->health); - - std::unique_ptr memoryInfo; - { - auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceIdInstance(); - memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo(); - } - - if (memoryInfo != nullptr) { - auto region = memoryInfo->getMemoryRegion(MemoryBanks::getBankForLocalMemory(subdeviceId)); - pState->free = region.unallocatedSize; - pState->size = region.probedSize; - } else { - pState->free = 0; - pState->size = 0; - status = ZE_RESULT_ERROR_UNKNOWN; - if (errno == ENODEV) { - status = ZE_RESULT_ERROR_DEVICE_LOST; - } - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, - "Error@ %s():createMemoryInfo failed errno:%d \n", __FUNCTION__, errno); - } - return status; -} - -LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { - pLinuxSysmanImp = static_cast(pOsSysman); - pDrm = pLinuxSysmanImp->getDrm(); - pDevice = pLinuxSysmanImp->getSysmanDeviceImp(); - pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId); - pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface(); -} - -bool LinuxMemoryImp::isMemoryModuleSupported() { - auto &gfxCoreHelper = pDevice->getRootDeviceEnvironment().getHelper(); - return gfxCoreHelper.getEnableLocalMemory(pDevice->getHardwareInfo()); -} - -std::unique_ptr OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) { - std::unique_ptr pLinuxMemoryImp = std::make_unique(pOsSysman, onSubdevice, subdeviceId); - return pLinuxMemoryImp; -} - -} // namespace Sysman -} // namespace L0 diff --git a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h b/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h deleted file mode 100644 index 8a95db8b42..0000000000 --- a/level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2022-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "shared/source/helpers/non_copyable_or_moveable.h" -#include "shared/source/os_interface/linux/drm_neo.h" - -#include "level_zero/sysman/source/api/memory/sysman_os_memory.h" -#include "level_zero/sysman/source/device/sysman_device_imp.h" -#include "level_zero/sysman/source/shared/linux/pmt/sysman_pmt.h" - -#include - -namespace L0 { -namespace Sysman { - -class SysFsAccessInterface; -struct Device; -class PlatformMonitoringTech; -class LinuxSysmanImp; -class SysmanKmdInterface; - -class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { - public: - ze_result_t getProperties(zes_mem_properties_t *pProperties) override; - ze_result_t getBandwidth(zes_mem_bandwidth_t *pBandwidth) override; - ze_result_t getState(zes_mem_state_t *pState) override; - bool isMemoryModuleSupported() override; - LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId); - LinuxMemoryImp() = default; - ~LinuxMemoryImp() override = default; - - protected: - LinuxSysmanImp *pLinuxSysmanImp = nullptr; - SysFsAccessInterface *pSysfsAccess = nullptr; - NEO::Drm *pDrm = nullptr; - SysmanDeviceImp *pDevice = nullptr; - PlatformMonitoringTech *pPmt = nullptr; - SysmanKmdInterface *pSysmanKmdInterface = nullptr; - - private: - static const std::string deviceMemoryHealth; - bool isSubdevice = false; - uint32_t subdeviceId = 0; - std::string physicalSizeFile; -}; - -} // namespace Sysman -} // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/CMakeLists.txt b/level_zero/sysman/test/unit_tests/sources/memory/linux/CMakeLists.txt index 2e6ef1f928..cdd988c32e 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/CMakeLists.txt +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/CMakeLists.txt @@ -1,26 +1,15 @@ # -# Copyright (C) 2020-2023 Intel Corporation +# Copyright (C) 2020-2024 Intel Corporation # # SPDX-License-Identifier: MIT # set(L0_TESTS_SYSMAN_MEMORY_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h ) -if(NEO_ENABLE_i915_PRELIM_DETECTION) - list(APPEND L0_TESTS_SYSMAN_MEMORY_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory_prelim.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_prelim.h - ) - -else() - list(APPEND L0_TESTS_SYSMAN_MEMORY_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h - ) -endif() - if(UNIX) target_sources(${TARGET_NAME} PRIVATE diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h index bb3ebe73e4..7c66d49477 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h @@ -20,6 +20,9 @@ using namespace NEO; +constexpr uint64_t hbmRP0Frequency = 4200; +constexpr uint64_t mockMaxBwDg2 = 1343616u; + constexpr uint32_t vF0HbmLRead = 16; constexpr uint32_t vF0HbmHRead = 2; constexpr uint32_t vF0HbmLWrite = 8; @@ -60,10 +63,12 @@ namespace L0 { namespace Sysman { namespace ult { -uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; +const std::string deviceMemoryHealth("device_memory_health"); + struct MockMemoryNeoDrm : public NEO::Drm { using Drm::ioctlHelper; const int mockFd = 33; + uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; std::vector mockQuerySystemInfoReturnValue{}; bool isRepeated = false; bool mockReturnEmptyRegions = false; @@ -98,6 +103,7 @@ struct MockMemoryNeoDrm : public NEO::Drm { return returnValue; } }; + struct MockMemoryPmt : public L0::Sysman::PlatformMonitoringTech { using L0::Sysman::PlatformMonitoringTech::guid; using L0::Sysman::PlatformMonitoringTech::keyOffsetMap; @@ -297,10 +303,41 @@ class PublicLinuxMemoryImp : public L0::Sysman::LinuxMemoryImp { using L0::Sysman::LinuxMemoryImp::pSysmanKmdInterface; }; -class MockSysFsAccessInterface : public L0::Sysman::SysFsAccessInterface { +class MockMemorySysmanKmdInterfaceXe : public L0::Sysman::SysmanKmdInterfaceXe { public: - MockSysFsAccessInterface() = default; - ~MockSysFsAccessInterface() override = default; + using L0::Sysman::SysmanKmdInterface::pProcfsAccess; + using L0::Sysman::SysmanKmdInterface::pSysfsAccess; + MockMemorySysmanKmdInterfaceXe(const PRODUCT_FAMILY productFamily) : SysmanKmdInterfaceXe(productFamily) {} + ~MockMemorySysmanKmdInterfaceXe() override = default; +}; + +struct MockMemorySysFsAccessInterface : public L0::Sysman::SysFsAccessInterface { + std::vector mockReadReturnStatus{}; + std::vector mockReadStringValue{}; + bool isRepeated = false; + + ze_result_t read(const std::string file, std::string &val) override { + ze_result_t result = ZE_RESULT_SUCCESS; + if (!mockReadReturnStatus.empty()) { + result = mockReadReturnStatus.front(); + if (!mockReadStringValue.empty()) { + val = mockReadStringValue.front(); + } + + if (isRepeated != true) { + mockReadReturnStatus.erase(mockReadReturnStatus.begin()); + if (!mockReadStringValue.empty()) { + mockReadStringValue.erase(mockReadStringValue.begin()); + } + } + return result; + } + + if (file.compare(deviceMemoryHealth) == 0) { + val = "OK"; + } + return result; + } }; class MockProcFsAccessInterface : public L0::Sysman::ProcFsAccessInterface { @@ -309,6 +346,13 @@ class MockProcFsAccessInterface : public L0::Sysman::ProcFsAccessInterface { ~MockProcFsAccessInterface() override = default; }; +class MockSysmanKmdInterfaceI915Prelim : public L0::Sysman::SysmanKmdInterfaceI915Prelim { + public: + using L0::Sysman::SysmanKmdInterface::pSysfsAccess; + MockSysmanKmdInterfaceI915Prelim(const PRODUCT_FAMILY productFamily) : SysmanKmdInterfaceI915Prelim(productFamily) {} + ~MockSysmanKmdInterfaceI915Prelim() override = default; +}; + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h deleted file mode 100644 index 8af9b5d1a3..0000000000 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright (C) 2021-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "shared/source/os_interface/linux/i915.h" -#include "shared/source/os_interface/linux/ioctl_helper.h" -#include "shared/source/os_interface/linux/memory_info.h" -#include "shared/source/os_interface/linux/system_info.h" - -#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h" -#include "level_zero/sysman/source/api/memory/sysman_memory_imp.h" -#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" -#include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h" -#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h" -#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_hw_device_id.h" - -using namespace NEO; - -constexpr uint16_t vF0VfidIndex = 88; -constexpr uint16_t vF0Hbm0ReadIndex = 92; -constexpr uint16_t vF0Hbm0WriteIndex = 96; -constexpr uint16_t vF0Hbm1ReadIndex = 104; -constexpr uint16_t vF0Hbm1WriteIndex = 108; -constexpr uint16_t vF0TimestampLIndex = 168; -constexpr uint16_t vF0TimestampHIndex = 172; -constexpr uint16_t vF1VfidIndex = 176; -constexpr uint16_t vF1Hbm0ReadIndex = 180; -constexpr uint16_t vF1Hbm0WriteIndex = 184; -constexpr uint16_t vF1Hbm1ReadIndex = 192; -constexpr uint16_t vF1Hbm1WriteIndex = 196; -constexpr uint16_t vF1TimestampLIndex = 256; -constexpr uint16_t vF1TimestampHIndex = 260; -constexpr uint16_t vF0Hbm2ReadIndex = 312; -constexpr uint16_t vF0Hbm2WriteIndex = 316; -constexpr uint16_t vF0Hbm3ReadIndex = 328; -constexpr uint16_t vF0Hbm3WriteIndex = 332; -constexpr uint16_t vF1Hbm2ReadIndex = 344; -constexpr uint16_t vF1Hbm2WriteIndex = 348; -constexpr uint16_t vF1Hbm3ReadIndex = 360; -constexpr uint16_t vF1Hbm3WriteIndex = 364; -constexpr uint32_t vF0HbmLRead = 16; -constexpr uint32_t vF0HbmHRead = 2; -constexpr uint32_t vF0HbmLWrite = 8; -constexpr uint32_t vF0HbmHWrite = 2; -constexpr uint32_t vF1HbmLRead = 16; -constexpr uint32_t vF1HbmHRead = 2; -constexpr uint32_t vF1HbmLWrite = 8; -constexpr uint32_t vF1HbmHWrite = 2; - -constexpr uint8_t vF0VfidValue = 1; -constexpr uint8_t vF0Hbm0ReadValue = 92; -constexpr uint8_t vF0Hbm0WriteValue = 96; -constexpr uint8_t vF0Hbm1ReadValue = 104; -constexpr uint8_t vF0Hbm1WriteValue = 108; -constexpr uint8_t vF0TimestampLValue = 168; -constexpr uint8_t vF0TimestampHValue = 172; -constexpr uint8_t vF1VfidValue = 0; -constexpr uint8_t vF0Hbm2ReadValue = 113; -constexpr uint8_t vF0Hbm2WriteValue = 125; -constexpr uint8_t vF0Hbm3ReadValue = 135; -constexpr uint8_t vF0Hbm3WriteValue = 20; - -constexpr uint8_t vF1Hbm0ReadValue = 92; -constexpr uint8_t vF1Hbm0WriteValue = 96; -constexpr uint8_t vF1Hbm1ReadValue = 104; -constexpr uint8_t vF1Hbm1WriteValue = 108; -constexpr uint8_t vF1TimestampLValue = 168; -constexpr uint8_t vF1TimestampHValue = 172; -constexpr uint8_t vF1Hbm2ReadValue = 113; -constexpr uint8_t vF1Hbm2WriteValue = 125; -constexpr uint8_t vF1Hbm3ReadValue = 135; -constexpr uint8_t vF1Hbm3WriteValue = 20; -constexpr uint64_t mockIdiReadVal = 8u; -constexpr uint64_t mockIdiWriteVal = 9u; -constexpr uint64_t mockDisplayVc1ReadVal = 10u; -constexpr uint64_t numberMcChannels = 16; -constexpr uint64_t transactionSize = 32; - -namespace L0 { -namespace Sysman { -namespace ult { - -uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; -const std::string deviceMemoryHealth("device_memory_health"); -std::string gpuUpstreamPortPathInMemory = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; -const std::string baseTelemSysFS("/sys/class/intel_pmt"); -const std::string realPathTelem1 = "/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"; -const std::string realPathTelem2 = "/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"; -const std::string realPathTelem3 = "/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/telem3"; -const std::string realPathTelem4 = "/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/telem4"; -const std::string realPathTelem5 = "/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/telem5"; -const std::string sysfsPahTelem1 = "/sys/class/intel_pmt/telem1"; -const std::string sysfsPahTelem2 = "/sys/class/intel_pmt/telem2"; -const std::string sysfsPahTelem3 = "/sys/class/intel_pmt/telem3"; -const std::string sysfsPahTelem4 = "/sys/class/intel_pmt/telem4"; -const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5"; - -struct MockMemorySysfsAccess : public L0::Sysman::SysFsAccessInterface { - - std::vector mockReadReturnStatus{}; - std::vector mockReadStringValue{}; - bool isRepeated = false; - - ze_result_t read(const std::string file, std::string &val) override { - ze_result_t result = ZE_RESULT_SUCCESS; - if (!mockReadReturnStatus.empty()) { - result = mockReadReturnStatus.front(); - if (!mockReadStringValue.empty()) { - val = mockReadStringValue.front(); - } - - if (isRepeated != true) { - mockReadReturnStatus.erase(mockReadReturnStatus.begin()); - if (!mockReadStringValue.empty()) { - mockReadStringValue.erase(mockReadStringValue.begin()); - } - } - return result; - } - - if (file.compare(deviceMemoryHealth) == 0) { - val = "OK"; - } - return result; - } -}; - -struct MockMemoryNeoDrm : public NEO::Drm { - using Drm::ioctlHelper; - const int mockFd = 33; - std::vector mockQuerySystemInfoReturnValue{}; - bool isRepeated = false; - bool mockReturnEmptyRegions = false; - MockMemoryNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(mockFd, ""), rootDeviceEnvironment) {} - - void setMemoryType(uint32_t memory) { - mockMemoryType = memory; - } - - std::vector getMemoryRegionsReturnsEmpty() { - return {}; - } - - void resetSystemInfo() { - systemInfo.reset(nullptr); - } - - bool querySystemInfo() override { - bool returnValue = true; - if (!mockQuerySystemInfoReturnValue.empty()) { - returnValue = mockQuerySystemInfoReturnValue.front(); - if (isRepeated != true) { - mockQuerySystemInfoReturnValue.erase(mockQuerySystemInfoReturnValue.begin()); - } - resetSystemInfo(); - return returnValue; - } - - uint32_t hwBlob[] = {NEO::DeviceBlobConstants::maxMemoryChannels, 1, 8, NEO::DeviceBlobConstants::memoryType, 0, mockMemoryType}; - std::vector inputBlobData(reinterpret_cast(hwBlob), reinterpret_cast(ptrOffset(hwBlob, sizeof(hwBlob)))); - this->systemInfo.reset(new SystemInfo(inputBlobData)); - return returnValue; - } -}; - -struct MockMemoryPmt : public L0::Sysman::PlatformMonitoringTech { - - using L0::Sysman::PlatformMonitoringTech::guid; - using L0::Sysman::PlatformMonitoringTech::keyOffsetMap; - std::vector mockReadValueReturnStatus{}; - std::vector mockReadArgumentValue{}; - ze_result_t mockIdiReadValueFailureReturnStatus = ZE_RESULT_SUCCESS; - ze_result_t mockIdiWriteFailureReturnStatus = ZE_RESULT_SUCCESS; - ze_result_t mockDisplayVc1ReadFailureReturnStatus = ZE_RESULT_SUCCESS; - ze_result_t mockReadTimeStampFailureReturnStatus = ZE_RESULT_SUCCESS; - bool mockVfid0Status = false; - bool mockVfid1Status = false; - bool isRepeated = false; - - void setGuid(std::string guid) { - this->guid = guid; - } - - MockMemoryPmt() = default; - ze_result_t readValue(const std::string key, uint32_t &val) override { - ze_result_t result = ZE_RESULT_SUCCESS; - - if (mockVfid0Status == true) { - return mockedReadValueWithVfid0True(key, val); - } - - if (mockVfid1Status == true) { - return mockedReadValueWithVfid1True(key, val); - } - - if (!mockReadValueReturnStatus.empty()) { - result = mockReadValueReturnStatus.front(); - if (!mockReadArgumentValue.empty()) { - val = mockReadArgumentValue.front(); - } - - if (isRepeated != true) { - mockReadValueReturnStatus.erase(mockReadValueReturnStatus.begin()); - if (!mockReadArgumentValue.empty()) { - mockReadArgumentValue.erase(mockReadArgumentValue.begin()); - } - } - } - return result; - } - - ze_result_t mockedReadValueWithVfid0True(const std::string key, uint32_t &val) { - if (key.compare("VF0_VFID") == 0) { - val = 1; - } else if (key.compare("VF1_VFID") == 0) { - val = 0; - } else if (key.compare("VF0_HBM0_READ") == 0) { - val = vF0Hbm0ReadValue; - } else if (key.compare("VF0_HBM0_WRITE") == 0) { - val = vF0Hbm0WriteValue; - } else if (key.compare("VF0_HBM1_READ") == 0) { - val = vF0Hbm1ReadValue; - } else if (key.compare("VF0_HBM1_WRITE") == 0) { - val = vF0Hbm1WriteValue; - } else if (key.compare("VF0_TIMESTAMP_L") == 0) { - val = vF0TimestampLValue; - } else if (key.compare("VF0_TIMESTAMP_H") == 0) { - val = vF0TimestampHValue; - } else if (key.compare("VF0_HBM2_READ") == 0) { - val = vF0Hbm2ReadValue; - } else if (key.compare("VF0_HBM2_WRITE") == 0) { - val = vF0Hbm2WriteValue; - } else if (key.compare("VF0_HBM3_READ") == 0) { - val = vF0Hbm3ReadValue; - } else if (key.compare("VF0_HBM3_WRITE") == 0) { - val = vF0Hbm3WriteValue; - } else if (key.compare("VF0_HBM_READ_L") == 0) { - val = vF0HbmLRead; - } else if (key.compare("VF0_HBM_READ_H") == 0) { - val = vF0HbmHRead; - } else if (key.compare("VF0_HBM_WRITE_L") == 0) { - val = vF0HbmLWrite; - } else if (key.compare("VF0_HBM_WRITE_H") == 0) { - val = vF0HbmHWrite; - } else { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t mockedReadValueWithVfid1True(const std::string key, uint32_t &val) { - if (key.compare("VF0_VFID") == 0) { - val = 0; - } else if (key.compare("VF1_VFID") == 0) { - val = 1; - } else if (key.compare("VF1_HBM0_READ") == 0) { - val = vF1Hbm0ReadValue; - } else if (key.compare("VF1_HBM0_WRITE") == 0) { - val = vF1Hbm0WriteValue; - } else if (key.compare("VF1_HBM1_READ") == 0) { - val = vF1Hbm1ReadValue; - } else if (key.compare("VF1_HBM1_WRITE") == 0) { - val = vF1Hbm1WriteValue; - } else if (key.compare("VF1_TIMESTAMP_L") == 0) { - val = vF1TimestampLValue; - } else if (key.compare("VF1_TIMESTAMP_H") == 0) { - val = vF1TimestampHValue; - } else if (key.compare("VF1_HBM2_READ") == 0) { - val = vF1Hbm2ReadValue; - } else if (key.compare("VF1_HBM2_WRITE") == 0) { - val = vF1Hbm2WriteValue; - } else if (key.compare("VF1_HBM3_READ") == 0) { - val = vF1Hbm3ReadValue; - } else if (key.compare("VF1_HBM3_WRITE") == 0) { - val = vF1Hbm3WriteValue; - } else if (key.compare("VF1_HBM_READ_L") == 0) { - val = vF1HbmLRead; - } else if (key.compare("VF1_HBM_READ_H") == 0) { - val = vF1HbmHRead; - } else if (key.compare("VF1_HBM_WRITE_L") == 0) { - val = vF1HbmLWrite; - } else if (key.compare("VF1_HBM_WRITE_H") == 0) { - val = vF1HbmHWrite; - } else { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t readValue(const std::string key, uint64_t &val) override { - ze_result_t result = ZE_RESULT_SUCCESS; - - if (mockIdiReadValueFailureReturnStatus != ZE_RESULT_SUCCESS) { - return mockIdiReadValueFailure(key, val); - } - - if (mockIdiWriteFailureReturnStatus != ZE_RESULT_SUCCESS) { - return mockIdiWriteFailure(key, val); - } - - if (mockDisplayVc1ReadFailureReturnStatus != ZE_RESULT_SUCCESS) { - return mockDisplayVc1ReadFailure(key, val); - } - - if (mockReadTimeStampFailureReturnStatus != ZE_RESULT_SUCCESS) { - return mockReadTimeStampFailure(key, val); - } - - if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) { - val = mockIdiReadVal; - } else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) { - val = mockIdiWriteVal; - } else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) { - val = mockDisplayVc1ReadVal; - } else { - result = ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return result; - } - - ze_result_t mockIdiReadValueFailure(const std::string key, uint64_t &val) { - return ZE_RESULT_ERROR_UNKNOWN; - } - - ze_result_t mockIdiWriteFailure(const std::string key, uint64_t &val) { - if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) { - val = mockIdiReadVal; - } else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t mockDisplayVc1ReadFailure(const std::string key, uint64_t &val) { - if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) { - val = mockIdiReadVal; - } else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) { - val = mockIdiWriteVal; - } else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t mockReadTimeStampFailure(const std::string key, uint64_t &val) { - if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) { - val = mockIdiReadVal; - } else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) { - val = mockIdiWriteVal; - } else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) { - val = mockDisplayVc1ReadVal; - } else { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return ZE_RESULT_SUCCESS; - } -}; - -class MockSysmanKmdInterfaceI915Prelim : public L0::Sysman::SysmanKmdInterfaceI915Prelim { - public: - using L0::Sysman::SysmanKmdInterface::pSysfsAccess; - MockSysmanKmdInterfaceI915Prelim(const PRODUCT_FAMILY productFamily) : SysmanKmdInterfaceI915Prelim(productFamily) {} - ~MockSysmanKmdInterfaceI915Prelim() override = default; -}; - -} // namespace ult -} // namespace Sysman -} // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp index d7c08d6b16..69104c7963 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory.cpp @@ -20,8 +20,23 @@ namespace Sysman { namespace ult { static const uint32_t memoryHandleComponentCount = 1u; -static uint64_t hbmRP0Frequency = 4200; -static uint64_t mockMaxBwDg2 = 1343616u; +static const std::string mockPhysicalSize = "0x00000040000000"; + +class SysmanMemoryMockIoctlHelper : public NEO::MockIoctlHelper { + + public: + using NEO::MockIoctlHelper::MockIoctlHelper; + bool returnEmptyMemoryInfo = false; + int32_t mockErrorNumber = 0; + + std::unique_ptr createMemoryInfo() override { + if (returnEmptyMemoryInfo) { + errno = mockErrorNumber; + return {}; + } + return NEO::MockIoctlHelper::createMemoryInfo(); + } +}; class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { protected: @@ -56,7 +71,7 @@ class SysmanDeviceMemoryFixtureI915 : public SysmanDeviceMemoryFixture { auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface; osInterface->setDriverModel(std::unique_ptr(pDrm)); pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2e); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); auto subdeviceId = 0u; auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount(); @@ -78,14 +93,14 @@ TEST_F(SysmanDeviceMemoryFixtureI915, GivenI915DriverVersionWhenValidCallingSysf EXPECT_STREQ("gt/gt0/mem_RPn_freq_mhz", pSysmanKmdInterface->getSysfsFilePath(SysfsName::sysfsNameMinMemoryFrequency, 0, true).c_str()); } -TEST_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { +TEST_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) { setLocalSupportedAndReinit(false); uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, 0u); } -TEST_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { +TEST_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) { setLocalSupportedAndReinit(false); uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); @@ -96,13 +111,13 @@ TEST_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingM EXPECT_EQ(count, 0u); } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsPVC) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsPVC) { uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsPVC) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsPVC) { uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); @@ -112,13 +127,13 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumerati EXPECT_EQ(count, memoryHandleComponentCount); } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsDG1) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsDG1) { uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsDG2) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsDG2) { uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); @@ -186,7 +201,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem } } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithHbmLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) { pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2); auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { @@ -254,7 +269,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem } } -TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceeds) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceeds, IsPVC) { auto pLinuxMemoryImp = std::make_unique(pOsSysman, true, 0); zes_mem_state_t state; ze_result_t result = pLinuxMemoryImp->getState(&state); @@ -323,7 +338,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem } } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVfid0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { std::ostringstream oStream; oStream << hbmRP0Frequency; @@ -363,7 +378,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem } } -HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { +HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVfid1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { std::ostringstream oStream; oStream << hbmRP0Frequency; @@ -474,18 +489,53 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSys } } +TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { + auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); + ioctlHelper->returnEmptyMemoryInfo = true; + ioctlHelper->mockErrorNumber = EBUSY; + auto handles = getMemoryHandles(memoryHandleComponentCount); + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + zes_mem_state_t state; + + ze_result_t result = zesMemoryGetState(handle, &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); + EXPECT_EQ(state.size, 0u); + EXPECT_EQ(state.free, 0u); + } +} + +TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndDeviceIsNotAvailableThenDeviceLostErrorIsReturned) { + auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); + ioctlHelper->returnEmptyMemoryInfo = true; + ioctlHelper->mockErrorNumber = ENODEV; + auto handles = getMemoryHandles(memoryHandleComponentCount); + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + zes_mem_state_t state; + + ze_result_t result = zesMemoryGetState(handle, &state); + + EXPECT_EQ(result, ZE_RESULT_ERROR_DEVICE_LOST); + EXPECT_EQ(state.size, 0u); + EXPECT_EQ(state.free, 0u); + errno = 0; + } +} + class SysmanDeviceMemoryFixtureXe : public SysmanDeviceMemoryFixture { protected: DebugManagerStateRestore restorer; MockMemoryNeoDrm *pDrm = nullptr; - MockSysmanKmdInterfaceXe *pSysmanKmdInterface = nullptr; + MockMemorySysmanKmdInterfaceXe *pSysmanKmdInterface = nullptr; void SetUp() override { debugManager.flags.EnableLocalMemory.set(1); SysmanDeviceFixture::SetUp(); - pSysmanKmdInterface = new MockSysmanKmdInterfaceXe(pLinuxSysmanImp->getProductFamily()); + pSysmanKmdInterface = new MockMemorySysmanKmdInterfaceXe(pLinuxSysmanImp->getProductFamily()); pSysmanKmdInterface->pProcfsAccess = std::make_unique(); - pSysmanKmdInterface->pSysfsAccess = std::make_unique(); + pSysmanKmdInterface->pSysfsAccess = std::make_unique(); device = pSysmanDeviceImp; pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); @@ -547,6 +597,94 @@ HWTEST2_F(SysmanDeviceMemoryFixtureXe, GivenValidMemoryHandleWhenCallingZesMemor } } +class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { + protected: + MockMemoryNeoDrm *pDrm = nullptr; + L0::Sysman::SysmanDevice *device = nullptr; + MockMemorySysFsAccessInterface *pSysfsAccess = nullptr; + MockSysmanKmdInterfaceI915Prelim *pSysmanKmdInterface = nullptr; + + void SetUp() override { + debugManager.flags.EnableLocalMemory.set(1); + SysmanMultiDeviceFixture::SetUp(); + + pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily()); + pSysfsAccess = new MockMemorySysFsAccessInterface(); + pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess); + pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface); + pLinuxSysmanImp->pSysfsAccess = pLinuxSysmanImp->pSysmanKmdInterface->getSysFsAccess(); + pDrm = new MockMemoryNeoDrm(const_cast(pSysmanDeviceImp->getRootDeviceEnvironment())); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface; + osInterface->setDriverModel(std::unique_ptr(pDrm)); + pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); + device = pSysmanDeviceImp; + } + + void TearDown() override { + SysmanMultiDeviceFixture::TearDown(); + } + + std::vector getMemoryHandles(uint32_t count) { + std::vector handles(count, nullptr); + EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); + return handles; + } +}; + +HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved, IsPVC) { + pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + pSysfsAccess->isRepeated = true; + + uint32_t count = 0; + EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); + EXPECT_EQ(count, std::max(pOsSysman->getSubDeviceCount(), 1u)); + + std::vector handles(count, nullptr); + EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); + for (auto handle : handles) { + zes_mem_properties_t properties = {}; + EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS); + EXPECT_TRUE(properties.onSubdevice); + EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.c_str(), nullptr, 16)); + } +} + +HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { + auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); + zes_mem_state_t state1; + ze_result_t result = zesMemoryGetState(handles[0], &state1); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(state1.health, ZES_MEM_HEALTH_OK); + EXPECT_EQ(state1.size, NEO::probedSizeRegionOne); + EXPECT_EQ(state1.free, NEO::unallocatedSizeRegionOne); + + zes_mem_state_t state2; + result = zesMemoryGetState(handles[1], &state2); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(state2.health, ZES_MEM_HEALTH_OK); + EXPECT_EQ(state2.size, NEO::probedSizeRegionFour); + EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); +} + +HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { + auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); + zes_mem_state_t state1; + ze_result_t result = zesMemoryGetState(handles[0], &state1); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(state1.health, ZES_MEM_HEALTH_UNKNOWN); + EXPECT_EQ(state1.size, NEO::probedSizeRegionOne); + EXPECT_EQ(state1.free, NEO::unallocatedSizeRegionOne); + + zes_mem_state_t state2; + result = zesMemoryGetState(handles[1], &state2); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(state2.health, ZES_MEM_HEALTH_UNKNOWN); + EXPECT_EQ(state2.size, NEO::probedSizeRegionFour); + EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); +} + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp deleted file mode 100644 index 72c1040774..0000000000 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp +++ /dev/null @@ -1,1034 +0,0 @@ -/* - * Copyright (C) 2021-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/os_interface/driver_info.h" -#include "shared/test/common/mocks/linux/mock_ioctl_helper.h" -#include "shared/test/common/test_macros/hw_test.h" - -#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h" -#include "level_zero/sysman/source/shared/linux/pmt/sysman_pmt_xml_offsets.h" -#include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h" -#include "level_zero/sysman/source/sysman_const.h" -#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h" -#include "level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h" - -namespace L0 { -namespace Sysman { -namespace ult { - -static std::string mockPhysicalSize = "0x00000040000000"; -static const uint64_t hbmRP0Frequency = 4200; -static const uint64_t hbmA0Frequency = 3200; -static const uint64_t mockMaxBwDg2 = 1343616u; -static const int32_t memoryBusWidth = 128; -static const int32_t numMemoryChannels = 8; -static const uint32_t memoryHandleComponentCount = 1u; -static const std::string sampleGuid1 = "0xb15a0edc"; - -class SysmanMemoryMockIoctlHelper : public NEO::MockIoctlHelper { - - public: - using NEO::MockIoctlHelper::MockIoctlHelper; - bool returnEmptyMemoryInfo = false; - int32_t mockErrorNumber = 0; - - std::unique_ptr createMemoryInfo() override { - if (returnEmptyMemoryInfo) { - errno = mockErrorNumber; - return {}; - } - return NEO::MockIoctlHelper::createMemoryInfo(); - } -}; - -class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { - protected: - MockMemoryNeoDrm *pDrm = nullptr; - L0::Sysman::SysmanDevice *device = nullptr; - DebugManagerStateRestore restorer; - uint16_t stepping; - - void SetUp() override { - debugManager.flags.EnableLocalMemory.set(1); - SysmanDeviceFixture::SetUp(); - auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - pLinuxSysmanImp->pSysmanProductHelper = std::move(pSysmanProductHelper); - pDrm = new MockMemoryNeoDrm(const_cast(pSysmanDeviceImp->getRootDeviceEnvironment())); - auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface; - osInterface->setDriverModel(std::unique_ptr(pDrm)); - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2e); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); - auto subdeviceId = 0u; - auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount(); - do { - auto pPmt = new MockMemoryPmt(); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt); - } while (++subdeviceId < subDeviceCount); - device = pSysmanDevice; - } - - void TearDown() override { - pLinuxSysmanImp->releasePmtObject(); - SysmanDeviceFixture::TearDown(); - } - - void setLocalSupportedAndReinit(bool supported) { - debugManager.flags.EnableLocalMemory.set(supported == true ? 1 : 0); - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount()); - } - - std::vector getMemoryHandles(uint32_t count) { - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - return handles; - } -}; - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); - - count = count + 1; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidHandlesIsReturned) { - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); - - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - for (auto handle : handles) { - EXPECT_NE(handle, nullptr); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) { - setLocalSupportedAndReinit(false); - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) { - setLocalSupportedAndReinit(false); - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); - - count = count + 1; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidHandlesAreReturned) { - setLocalSupportedAndReinit(false); - - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); - - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - for (auto handle : handles) { - EXPECT_NE(handle, nullptr); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesThenSuccessIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesAndQuerySystemInfoFailsThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown, IsPVC) { - pDrm->mockQuerySystemInfoReturnValue.push_back(false); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_EQ(properties.numChannels, -1); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesAndQuerySystemInfoSucceedsButMemSysInfoIsNullThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown, IsPVC) { - pDrm->mockQuerySystemInfoReturnValue.push_back(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_EQ(properties.numChannels, -1); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithLPDDR4LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr4); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_LPDDR4); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithLPDDR5LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr5); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_LPDDR5); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithDDRLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::gddr6); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - zes_mem_properties_t properties; - ze_result_t result = zesMemoryGetProperties(handle, &properties); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_DDR); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - ze_result_t result = zesMemoryGetState(handle, &state); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_UNKNOWN); - EXPECT_EQ(state.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - ze_result_t result = zesMemoryGetState(handle, &state); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { - auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); - ioctlHelper->returnEmptyMemoryInfo = true; - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - - ze_result_t result = zesMemoryGetState(handle, &state); - - EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(state.size, 0u); - EXPECT_EQ(state.free, 0u); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndDeviceIsNotAvailableThenDeviceLostErrorIsReturned) { - auto ioctlHelper = static_cast(pDrm->ioctlHelper.get()); - ioctlHelper->returnEmptyMemoryInfo = true; - ioctlHelper->mockErrorNumber = ENODEV; - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - - ze_result_t result = zesMemoryGetState(handle, &state); - - EXPECT_EQ(result, ZE_RESULT_ERROR_DEVICE_LOST); - EXPECT_EQ(state.size, 0u); - EXPECT_EQ(state.free, 0u); - errno = 0; - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - pLinuxSysmanImp->releaseSysmanDeviceResources(); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->reInitSysmanDeviceResources()); - - VariableBackup> pmtBackup(&pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); - auto subdeviceId = 0u; - auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount(); - do { - auto pPmt = new MockMemoryPmt(); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt); - } while (++subdeviceId < subDeviceCount); - - VariableBackup backup(&pLinuxSysmanImp->pFwUtilInterface); - pLinuxSysmanImp->pFwUtilInterface = new MockFwUtilInterface(); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - - ze_result_t result = zesMemoryGetState(handle, &state); - - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_UNKNOWN); - EXPECT_EQ(state.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); - } - - pLinuxSysmanImp->releasePmtObject(); - delete pLinuxSysmanImp->pFwUtilInterface; - pLinuxSysmanImp->pFwUtilInterface = nullptr; -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - pLinuxSysmanImp->releaseSysmanDeviceResources(); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->reInitSysmanDeviceResources()); - - VariableBackup> pmtBackup(&pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); - auto subdeviceId = 0u; - auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount(); - do { - auto pPmt = new MockMemoryPmt(); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt); - } while (++subdeviceId < subDeviceCount); - - VariableBackup backup(&pLinuxSysmanImp->pFwUtilInterface); - pLinuxSysmanImp->pFwUtilInterface = new MockFwUtilInterface(); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - - ze_result_t result = zesMemoryGetState(handle, &state); - - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); - } - - pLinuxSysmanImp->releasePmtObject(); - delete pLinuxSysmanImp->pFwUtilInterface; - pLinuxSysmanImp->pFwUtilInterface = nullptr; -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenPmtObjectIsNullThenFailureIsReturned, IsPVC) { - for (auto &subDeviceIdToPmtEntry : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) { - if (subDeviceIdToPmtEntry.second != nullptr) { - delete subDeviceIdToPmtEntry.second; - subDeviceIdToPmtEntry.second = nullptr; - } - } - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveAndReadingVFID0FailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveAndReadingVFID1FailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { - std::ostringstream oStream; - oStream << hbmRP0Frequency; - std::string value = oStream.str(); - memcpy(buf, value.data(), count); - return count; - }); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - uint64_t expectedReadCounters = 0, expectedWriteCounters = 0; - uint64_t expectedBandwidth = 0; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockVfid0Status = true; - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - expectedReadCounters |= vF0HbmHRead; - expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead; - expectedReadCounters = expectedReadCounters * transactionSize; - EXPECT_EQ(bandwidth.readCounter, expectedReadCounters); - expectedWriteCounters |= vF0HbmHWrite; - expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite; - expectedWriteCounters = expectedWriteCounters * transactionSize; - EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters); - expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; - EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveWhenReadingHBMReadLFailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveWhenReadingHBMReadHFailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0HbmLRead); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveWhenReadingHBMWriteLFailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0HbmLRead); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0HbmHRead); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveWhenReadingHBMWriteHFailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0HbmLRead); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0HbmHRead); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0HbmLWrite); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleAndGuidNotSetWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { - std::ostringstream oStream; - oStream << hbmRP0Frequency; - std::string value = oStream.str(); - memcpy(buf, value.data(), count); - return count; - }); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - uint64_t expectedReadCounters = vF0Hbm0ReadValue + vF0Hbm1ReadValue + vF0Hbm2ReadValue + vF0Hbm3ReadValue; - uint64_t expectedWriteCounters = vF0Hbm0WriteValue + vF0Hbm1WriteValue + vF0Hbm2WriteValue + vF0Hbm3WriteValue; - uint64_t expectedBandwidth = 0; - constexpr uint64_t transactionSize = 32; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->mockVfid0Status = true; - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - expectedReadCounters = expectedReadCounters * transactionSize; - EXPECT_EQ(bandwidth.readCounter, expectedReadCounters); - expectedWriteCounters = expectedWriteCounters * transactionSize; - EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters); - expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; - EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleAndGuidNotSetWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveWhenReadingHBM0ReadFailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleAndGuidNotSetWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveWhenReadingHBM0WriteFailsThenFailureIsReturned, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(vF0Hbm0ReadValue); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { - std::ostringstream oStream; - oStream << hbmRP0Frequency; - std::string value = oStream.str(); - memcpy(buf, value.data(), count); - return count; - }); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - uint64_t expectedReadCounters = 0, expectedWriteCounters = 0; - uint64_t expectedBandwidth = 0; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockVfid1Status = true; - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - expectedReadCounters |= vF0HbmHRead; - expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead; - expectedReadCounters = expectedReadCounters * transactionSize; - EXPECT_EQ(bandwidth.readCounter, expectedReadCounters); - expectedWriteCounters |= vF0HbmHWrite; - expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite; - expectedWriteCounters = expectedWriteCounters * transactionSize; - EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters); - expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; - EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreTrueThenErrorIsReturnedWhileGettingMemoryBandwidth, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - - zes_mem_bandwidth_t bandwidth; - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreFalseThenErrorIsReturnedWhileGettingMemoryBandwidth, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - - zes_mem_bandwidth_t bandwidth; - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID1IsActiveAndHwRevIdIsRevisionA0ThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - zes_mem_bandwidth_t bandwidth{}; - uint64_t expectedReadCounters = 0, expectedWriteCounters = 0; - uint64_t expectedBandwidth = 0; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pSysmanDeviceImp->getRootDeviceEnvironment().getHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_A0, *hwInfo); - - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockVfid1Status = true; - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - expectedReadCounters |= vF0HbmHRead; - expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead; - expectedReadCounters = expectedReadCounters * transactionSize; - EXPECT_EQ(bandwidth.readCounter, expectedReadCounters); - expectedWriteCounters |= vF0HbmHWrite; - expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite; - expectedWriteCounters = expectedWriteCounters * transactionSize; - EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters); - expectedBandwidth = 128 * hbmA0Frequency * 1000 * 1000 * 4; - EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthThenSuccessIsReturnedAndBandwidthIsValid, IsDG2) { - VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { - std::ostringstream oStream; - oStream << mockMaxBwDg2; - std::string value = oStream.str(); - memcpy(buf, value.data(), count); - return count; - }); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (const auto &handle : handles) { - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - zes_mem_bandwidth_t bandwidth; - uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - expectedReadCounters = numberMcChannels * (mockIdiReadVal + mockDisplayVc1ReadVal) * transactionSize; - EXPECT_EQ(expectedReadCounters, bandwidth.readCounter); - expectedWriteCounters = numberMcChannels * mockIdiWriteVal * transactionSize; - EXPECT_EQ(expectedWriteCounters, bandwidth.writeCounter); - expectedBandwidth = mockMaxBwDg2 * mbpsToBytesPerSecond; - EXPECT_EQ(expectedBandwidth, bandwidth.maxBandwidth); - EXPECT_GT(bandwidth.timestamp, 0u); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthIfIdiReadFailsTheFailureIsReturned, IsDG2) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - zes_mem_bandwidth_t bandwidth; - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->mockIdiReadValueFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthIfDisplayVc1ReadFailsTheFailureIsReturned, IsDG2) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - zes_mem_bandwidth_t bandwidth; - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->mockDisplayVc1ReadFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthThenUnsupportedFeatureIsReturned, IsDG1) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - zes_mem_bandwidth_t bandwidth; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetBandwidthForDg2PlatformAndReadingMaxBwFailsThenMaxBwIsReturnedAsZero, IsDG2) { - VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { - errno = ENOENT; - return -1; - }); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (const auto &handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - - zes_mem_bandwidth_t bandwidth; - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_NOT_AVAILABLE); - EXPECT_EQ(bandwidth.maxBandwidth, 0u); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiWriteFailsTheFailureIsReturned, IsDG2) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_properties_t properties = {}; - zesMemoryGetProperties(handle, &properties); - zes_mem_bandwidth_t bandwidth; - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->mockIdiWriteFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndFwUtilInterfaceIsAbsentThenMemoryHealthWillBeUnknown) { - auto handles = getMemoryHandles(memoryHandleComponentCount); - VariableBackup backup(&pLinuxSysmanImp->pFwUtilInterface); - pLinuxSysmanImp->pFwUtilInterface = nullptr; - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_state_t state; - ze_result_t result = zesMemoryGetState(handle, &state); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_UNKNOWN); - } -} - -class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { - protected: - MockMemoryNeoDrm *pDrm = nullptr; - L0::Sysman::SysmanDevice *device = nullptr; - MockMemorySysfsAccess *pSysfsAccess = nullptr; - MockSysmanKmdInterfaceI915Prelim *pSysmanKmdInterface = nullptr; - - void SetUp() override { - debugManager.flags.EnableLocalMemory.set(1); - SysmanMultiDeviceFixture::SetUp(); - - pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily()); - pSysfsAccess = new MockMemorySysfsAccess(); - pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess); - pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface); - pLinuxSysmanImp->pSysfsAccess = pLinuxSysmanImp->pSysmanKmdInterface->getSysFsAccess(); - pDrm = new MockMemoryNeoDrm(const_cast(pSysmanDeviceImp->getRootDeviceEnvironment())); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); - auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface; - osInterface->setDriverModel(std::unique_ptr(pDrm)); - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - device = pSysmanDeviceImp; - } - - void TearDown() override { - SysmanMultiDeviceFixture::TearDown(); - } - - void mockInitFsAccess() { - VariableBackup mockReadLink(&NEO::SysCalls::sysCallsReadlink, [](const char *path, char *buf, size_t bufsize) -> int { - constexpr size_t sizeofPath = sizeof("/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0"); - strcpy_s(buf, sizeofPath, "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0"); - return sizeofPath; - }); - pLinuxSysmanImp->pSysmanKmdInterface->initFsAccessInterface(*pLinuxSysmanImp->getDrm()); - } - - void setLocalSupportedAndReinit(bool supported) { - debugManager.flags.EnableLocalMemory.set(supported == true ? 1 : 0); - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount()); - } - - std::vector getMemoryHandles(uint32_t count) { - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - return handles; - } -}; - -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingMemoryPropertiesIsSysReadCallFailsThenValidMemoryPropertiesRetrieved, IsPVC) { - pSysfsAccess->mockReadStringValue.push_back("0"); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); - - pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount()); - for (auto subDeviceId = 0u; subDeviceId < pOsSysman->getSubDeviceCount(); subDeviceId++) { - zes_mem_properties_t properties = {}; - auto isSubDevice = pOsSysman->getSubDeviceCount() > 0u; - auto pLinuxMemoryImp = std::make_unique(pOsSysman, isSubDevice, subDeviceId); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); - EXPECT_EQ(properties.subdeviceId, subDeviceId); - EXPECT_EQ(properties.onSubdevice, isSubDevice); - EXPECT_EQ(properties.physicalSize, 0u); - } -} - -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWithNoSubdeviceWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved, IsPVC) { - pSysmanDeviceImp->pMemoryHandleContext->init(0); - zes_mem_properties_t properties = {}; - auto isSubDevice = false; - auto subDeviceId = 0u; - auto pLinuxMemoryImp = std::make_unique(pOsSysman, isSubDevice, subDeviceId); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); - EXPECT_EQ(properties.subdeviceId, subDeviceId); - EXPECT_EQ(properties.onSubdevice, isSubDevice); - EXPECT_EQ(properties.physicalSize, 0u); -} - -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved, IsPVC) { - pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - pSysfsAccess->isRepeated = true; - - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, std::max(pOsSysman->getSubDeviceCount(), 1u)); - - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - for (auto handle : handles) { - zes_mem_properties_t properties = {}; - EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS); - EXPECT_TRUE(properties.onSubdevice); - EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.c_str(), nullptr, 16)); - } -} - -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); - zes_mem_state_t state1; - ze_result_t result = zesMemoryGetState(handles[0], &state1); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state1.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state1.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state1.free, NEO::unallocatedSizeRegionOne); - - zes_mem_state_t state2; - result = zesMemoryGetState(handles[1], &state2); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state2.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state2.size, NEO::probedSizeRegionFour); - EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); -} - -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount()); - zes_mem_state_t state1; - ze_result_t result = zesMemoryGetState(handles[0], &state1); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state1.health, ZES_MEM_HEALTH_UNKNOWN); - EXPECT_EQ(state1.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state1.free, NEO::unallocatedSizeRegionOne); - - zes_mem_state_t state2; - result = zesMemoryGetState(handles[1], &state2); - EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(state2.health, ZES_MEM_HEALTH_UNKNOWN); - EXPECT_EQ(state2.size, NEO::probedSizeRegionFour); - EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); -} - -} // namespace ult -} // namespace Sysman -} // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp index c34b33d99f..13772487b5 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,129 +14,19 @@ #include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h" #include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h" #include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_hw_device_id.h" +#include "level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h" namespace L0 { namespace Sysman { namespace ult { -static const uint64_t hbmRP0Frequency = 4200; -static const uint64_t mockMaxBwDg2 = 1343616u; - -static uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; - -static const uint32_t vF0HbmLRead = 16; -static const uint32_t vF0HbmHRead = 2; -static const uint32_t vF0HbmLWrite = 8; -static const uint32_t vF0HbmHWrite = 2; - -static const uint8_t vF0Hbm0ReadValue = 92; -static const uint8_t vF0Hbm0WriteValue = 96; -static const uint8_t vF0Hbm1ReadValue = 104; -static const uint8_t vF0Hbm1WriteValue = 108; -static const uint8_t vF0TimestampLValue = 168; -static const uint8_t vF0TimestampHValue = 172; -static const uint8_t vF0Hbm2ReadValue = 113; -static const uint8_t vF0Hbm2WriteValue = 125; -static const uint8_t vF0Hbm3ReadValue = 135; -static const uint8_t vF0Hbm3WriteValue = 20; -static const uint64_t mockIdiReadVal = 8u; -static const uint64_t mockIdiWriteVal = 9u; -static const uint64_t mockDisplayVc1ReadVal = 10u; -static const uint64_t numberMcChannels = 16; -static const uint64_t transactionSize = 32; - -class MockDrm : public NEO::Drm { - public: - MockDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(mockFd, ""), rootDeviceEnvironment) {} - void resetSystemInfo() { - systemInfo.reset(nullptr); - } - - void setMemoryType(uint32_t memory) { - mockMemoryType = memory; - } - - bool querySystemInfo() override { - bool returnValue = true; - uint32_t hwBlob[] = {NEO::DeviceBlobConstants::maxMemoryChannels, 1, 8, NEO::DeviceBlobConstants::memoryType, 0, mockMemoryType}; - std::vector inputBlobData(reinterpret_cast(hwBlob), reinterpret_cast(ptrOffset(hwBlob, sizeof(hwBlob)))); - this->systemInfo.reset(new SystemInfo(inputBlobData)); - return returnValue; - } -}; - -class MockPmt : public L0::Sysman::PlatformMonitoringTech { - public: - using L0::Sysman::PlatformMonitoringTech::guid; - MockPmt() = default; - - void setGuid(std::string guid) { - this->guid = guid; - } - - ze_result_t readValue(const std::string key, uint32_t &val) override { - ze_result_t result = ZE_RESULT_SUCCESS; - - if (key.compare("VF0_VFID") == 0) { - val = 1; - } else if (key.compare("VF1_VFID") == 0) { - val = 0; - } else if (key.compare("VF0_HBM0_READ") == 0) { - val = vF0Hbm0ReadValue; - } else if (key.compare("VF0_HBM0_WRITE") == 0) { - val = vF0Hbm0WriteValue; - } else if (key.compare("VF0_HBM1_READ") == 0) { - val = vF0Hbm1ReadValue; - } else if (key.compare("VF0_HBM1_WRITE") == 0) { - val = vF0Hbm1WriteValue; - } else if (key.compare("VF0_TIMESTAMP_L") == 0) { - val = vF0TimestampLValue; - } else if (key.compare("VF0_TIMESTAMP_H") == 0) { - val = vF0TimestampHValue; - } else if (key.compare("VF0_HBM2_READ") == 0) { - val = vF0Hbm2ReadValue; - } else if (key.compare("VF0_HBM2_WRITE") == 0) { - val = vF0Hbm2WriteValue; - } else if (key.compare("VF0_HBM3_READ") == 0) { - val = vF0Hbm3ReadValue; - } else if (key.compare("VF0_HBM3_WRITE") == 0) { - val = vF0Hbm3WriteValue; - } else if (key.compare("VF0_HBM_READ_L") == 0) { - val = vF0HbmLRead; - } else if (key.compare("VF0_HBM_READ_H") == 0) { - val = vF0HbmHRead; - } else if (key.compare("VF0_HBM_WRITE_L") == 0) { - val = vF0HbmLWrite; - } else if (key.compare("VF0_HBM_WRITE_H") == 0) { - val = vF0HbmHWrite; - } else { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - return result; - } - - ze_result_t readValue(const std::string key, uint64_t &val) override { - ze_result_t result = ZE_RESULT_SUCCESS; - - if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) { - val = mockIdiReadVal; - } else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) { - val = mockIdiWriteVal; - } else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) { - val = mockDisplayVc1ReadVal; - } else { - result = ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return result; - } -}; +static const std::string mockPhysicalSize = "0x00000040000000"; class SysmanProductHelperMemoryTest : public SysmanDeviceFixture { protected: L0::Sysman::SysmanDevice *device = nullptr; DebugManagerStateRestore restorer; - MockDrm *pDrm = nullptr; + MockMemoryNeoDrm *pDrm = nullptr; void SetUp() override { debugManager.flags.EnableLocalMemory.set(1); @@ -145,14 +35,14 @@ class SysmanProductHelperMemoryTest : public SysmanDeviceFixture { auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); pLinuxSysmanImp->pSysmanProductHelper = std::move(pSysmanProductHelper); - pDrm = new MockDrm(const_cast(pSysmanDeviceImp->getRootDeviceEnvironment())); + pDrm = new MockMemoryNeoDrm(const_cast(pSysmanDeviceImp->getRootDeviceEnvironment())); auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface; - osInterface->setDriverModel(std::unique_ptr(pDrm)); + osInterface->setDriverModel(std::unique_ptr(pDrm)); pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); auto subdeviceId = 0u; auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount(); do { - auto pPmt = new MockPmt(); + auto pPmt = new MockMemoryPmt(); pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt); } while (++subdeviceId < subDeviceCount); } @@ -163,7 +53,7 @@ class SysmanProductHelperMemoryTest : public SysmanDeviceFixture { } }; -HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingMemoryAPIsThenErrorIsReturned, IsPVC) { +HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingGetMemoryBandwidthAndVfid0IsActiveThenVerifyBandWidthIsValid, IsPVC) { VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { std::ostringstream oStream; oStream << hbmRP0Frequency; @@ -174,37 +64,164 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); zes_mem_properties_t properties; - uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0; bool isSubdevice = true; uint32_t subDeviceId = 0; - ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice); + auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); - EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); - EXPECT_TRUE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, numMemoryChannels); - EXPECT_EQ(properties.busWidth, memoryBusWidth); - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->mockVfid0Status = true; - zes_mem_bandwidth_t bandwidth; + zes_mem_bandwidth_t bandwidth = {}; result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); EXPECT_EQ(result, ZE_RESULT_SUCCESS); - expectedReadCounters |= vF0HbmHRead; - expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead; + uint64_t expectedReadCounters = vF0Hbm0ReadValue + vF0Hbm1ReadValue + vF0Hbm2ReadValue + vF0Hbm3ReadValue; + uint64_t expectedWriteCounters = vF0Hbm0WriteValue + vF0Hbm1WriteValue + vF0Hbm2WriteValue + vF0Hbm3WriteValue; + uint64_t expectedBandwidth = 0; + expectedReadCounters = expectedReadCounters * transactionSize; EXPECT_EQ(bandwidth.readCounter, expectedReadCounters); - expectedWriteCounters |= vF0HbmHWrite; - expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite; expectedWriteCounters = expectedWriteCounters * transactionSize; EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters); expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); } +HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingGetMemoryBandwidthAndVfid1IsActiveThenVerifyBandWidthIsValid, IsPVC) { + VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { + std::ostringstream oStream; + oStream << hbmRP0Frequency; + std::string value = oStream.str(); + memcpy(buf, value.data(), count); + return count; + }); + + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + zes_mem_properties_t properties; + bool isSubdevice = true; + uint32_t subDeviceId = 0; + auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockVfid1Status = true; + + zes_mem_bandwidth_t bandwidth = {}; + result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + uint64_t expectedReadCounters = 0, expectedWriteCounters = 0; + expectedReadCounters |= vF0HbmHRead; + expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead; + expectedReadCounters = expectedReadCounters * transactionSize; + expectedWriteCounters |= vF0HbmHWrite; + expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite; + expectedWriteCounters = expectedWriteCounters * transactionSize; + uint64_t expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; + + EXPECT_EQ(bandwidth.readCounter, expectedReadCounters); + EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters); + EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenHbm0ReadFailsAndGuidNotSetWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + zes_mem_properties_t properties; + bool isSubdevice = true; + uint32_t subDeviceId = 0; + auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); + + zes_mem_bandwidth_t bandwidth = {}; + result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenHbm0WriteFailsAndGuidNotSetWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + zes_mem_properties_t properties; + bool isSubdevice = true; + uint32_t subDeviceId = 0; + auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(vF0Hbm0ReadValue); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); + + zes_mem_bandwidth_t bandwidth = {}; + result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenVfid0ReadFailsWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + uint32_t subDeviceId = 0; + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); + + zes_mem_bandwidth_t bandwidth{}; + auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenVfid0ReadFailsAndGuidNotSetBitWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + uint32_t subDeviceId = 0; + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId)); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); + + zes_mem_bandwidth_t bandwidth{}; + auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenVfid1ReadFailsWhenCallingGetBandwidthAndVfid1IsActiveThenFailureIsReturned, IsPVC) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + uint32_t subDeviceId = 0; + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN); + + zes_mem_bandwidth_t bandwidth{}; + auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenBothVfid0AndVfid1AreFalseWhenGettingMemoryBandwidthThenFailureIsReturned, IsPVC) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + uint32_t subDeviceId = 0; + + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + + zes_mem_bandwidth_t bandwidth{}; + auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN); +} + HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingGetMemoryBandwidthAPIsThenErrorIsReturned, IsDG1) { auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); zes_mem_properties_t properties; @@ -224,6 +241,50 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); } +HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWithPrelimInterfaceWhenCallingGetMemoryPropertiesThenVerifyPropertiesAreProper, IsDG2) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + zes_mem_properties_t properties; + bool isSubdevice = true; + uint32_t subDeviceId = 0; + + auto pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily()); + MockMemorySysFsAccessInterface *pSysfsAccess = new MockMemorySysFsAccessInterface(); + pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface); + pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess); + pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + pSysfsAccess->isRepeated = true; + + ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pSysmanKmdInterface, subDeviceId, isSubdevice); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM); + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_TRUE(properties.onSubdevice); + EXPECT_EQ(properties.subdeviceId, 0u); + EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.c_str(), nullptr, 16)); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); +} + +HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceAndPhysicalSizeReadFailsWhenCallingGetMemoryPropertiesThenVerifyPhysicalSizeIsZero, IsDG2) { + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + zes_mem_properties_t properties; + bool isSubdevice = true; + uint32_t subDeviceId = 0; + + auto pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily()); + MockMemorySysFsAccessInterface *pSysfsAccess = new MockMemorySysFsAccessInterface(); + pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface); + pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess); + pSysfsAccess->mockReadStringValue.push_back("0"); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); + pSysfsAccess->isRepeated = true; + + ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pSysmanKmdInterface, subDeviceId, isSubdevice); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(properties.physicalSize, 0u); +} + HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingMemoryAPIsThenErrorIsReturned, IsDG2) { VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { std::ostringstream oStream; @@ -259,6 +320,41 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal EXPECT_GT(bandwidth.timestamp, 0u); } +HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceAndPhysicalSizeSupportedWhenCallingMemoryAPIsThenErrorIsReturned, IsDG2) { + VariableBackup mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t { + std::ostringstream oStream; + oStream << mockMaxBwDg2; + std::string value = oStream.str(); + memcpy(buf, value.data(), count); + return count; + }); + + auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); + zes_mem_properties_t properties; + uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0; + bool isSubdevice = true; + uint32_t subDeviceId = 0; + ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE); + EXPECT_TRUE(properties.onSubdevice); + EXPECT_EQ(properties.subdeviceId, 0u); + EXPECT_EQ(properties.physicalSize, 0u); + EXPECT_EQ(properties.numChannels, numMemoryChannels); + EXPECT_EQ(properties.busWidth, memoryBusWidth); + + zes_mem_bandwidth_t bandwidth; + result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId); + EXPECT_EQ(result, ZE_RESULT_SUCCESS); + expectedReadCounters = numberMcChannels * (mockIdiReadVal + mockDisplayVc1ReadVal) * transactionSize; + EXPECT_EQ(expectedReadCounters, bandwidth.readCounter); + expectedWriteCounters = numberMcChannels * mockIdiWriteVal * transactionSize; + EXPECT_EQ(expectedWriteCounters, bandwidth.writeCounter); + expectedBandwidth = mockMaxBwDg2 * mbpsToBytesPerSecond; + EXPECT_EQ(expectedBandwidth, bandwidth.maxBandwidth); + EXPECT_GT(bandwidth.timestamp, 0u); +} + TEST(SysmanProductHelperTest, GivenInvalidProductFamilyWhenCallingProductHelperCreateThenNullPtrIsReturned) { auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(IGFX_UNKNOWN); EXPECT_EQ(nullptr, pSysmanProductHelper);