diff --git a/level_zero/tools/source/sysman/events/linux/os_events_imp.cpp b/level_zero/tools/source/sysman/events/linux/os_events_imp.cpp index 50789f6cd2..9feaed7299 100644 --- a/level_zero/tools/source/sysman/events/linux/os_events_imp.cpp +++ b/level_zero/tools/source/sysman/events/linux/os_events_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,7 +13,7 @@ #include "level_zero/tools/source/sysman/events/events_imp.h" #include "level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h" #include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" -#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h" +#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp.h" #include diff --git a/level_zero/tools/source/sysman/memory/linux/CMakeLists.txt b/level_zero/tools/source/sysman/memory/linux/CMakeLists.txt index 298e450593..d7a315afa6 100755 --- a/level_zero/tools/source/sysman/memory/linux/CMakeLists.txt +++ b/level_zero/tools/source/sysman/memory/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2024 Intel Corporation +# Copyright (C) 2020-2025 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,26 +8,7 @@ if(UNIX) target_sources(${L0_STATIC_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp.h ) - - if(NEO_ENABLE_I915_PRELIM_DETECTION) - target_sources(${L0_STATIC_LIB_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp_prelim.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp_prelim.h - ) - elseif(SUPPORT_DG1 AND "${BRANCH_TYPE}" STREQUAL "") - target_sources(${L0_STATIC_LIB_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp.h - ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp_dg1.cpp - ) - else() - target_sources(${L0_STATIC_LIB_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp.h - ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_imp.cpp - ) - endif() - endif() diff --git a/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp b/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp index 5e63be429b..044a5119da 100644 --- a/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp +++ b/level_zero/tools/source/sysman/memory/linux/os_memory_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,38 +7,368 @@ #include "level_zero/tools/source/sysman/memory/linux/os_memory_imp.h" -#include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/device/device.h" +#include "shared/source/helpers/hw_info.h" +#include "shared/source/memory_manager/memory_banks.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/core/source/driver/driver_handle.h" +#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h" #include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" +#include "level_zero/tools/source/sysman/sysman_const.h" + +#include "igfxfmid.h" namespace L0 { -LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { - LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); - pDevice = pLinuxSysmanImp->getDeviceHandle(); +const std::string LinuxMemoryImp::deviceMemoryHealth("device_memory_health"); + +void memoryGetTimeStamp(uint64_t ×tamp) { + std::chrono::time_point ts = std::chrono::steady_clock::now(); + timestamp = std::chrono::duration_cast(ts.time_since_epoch()).count(); } + +void LinuxMemoryImp::init() { + if (isSubdevice) { + const std::string baseDir = "gt/gt" + std::to_string(subdeviceId) + "/"; + physicalSizeFile = baseDir + "addr_range"; + } +} + +LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { + pLinuxSysmanImp = static_cast(pOsSysman); + pDrm = &pLinuxSysmanImp->getDrm(); + pDevice = pLinuxSysmanImp->getDeviceHandle(); + pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); + pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId); + init(); +} + bool LinuxMemoryImp::isMemoryModuleSupported() { return pDevice->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(pDevice->getRootDeviceIndex()); } ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { pProperties->type = ZES_MEM_TYPE_DDR; + pProperties->numChannels = -1; + if (pDrm->querySystemInfo()) { + auto memSystemInfo = pDrm->getSystemInfo(); + if (memSystemInfo != nullptr) { + pProperties->numChannels = memSystemInfo->getMaxMemoryChannels(); + auto memType = memSystemInfo->getMemoryType(); + switch (memType) { + case NEO::DeviceBlobConstants::MemoryType::hbm2e: + case NEO::DeviceBlobConstants::MemoryType::hbm2: + pProperties->type = ZES_MEM_TYPE_HBM; + break; + case NEO::DeviceBlobConstants::MemoryType::lpddr4: + pProperties->type = ZES_MEM_TYPE_LPDDR4; + break; + case NEO::DeviceBlobConstants::MemoryType::lpddr5: + pProperties->type = ZES_MEM_TYPE_LPDDR5; + break; + default: + pProperties->type = ZES_MEM_TYPE_DDR; + break; + } + } + } pProperties->location = ZES_MEM_LOC_DEVICE; pProperties->onSubdevice = isSubdevice; pProperties->subdeviceId = subdeviceId; - pProperties->busWidth = -1; - pProperties->numChannels = -1; + pProperties->busWidth = memoryBusWidth; // Hardcode + pProperties->physicalSize = 0; + if (isSubdevice) { + std::string memval; + ze_result_t result = pSysfsAccess->read(physicalSizeFile, memval); + uint64_t intval = strtoull(memval.c_str(), nullptr, 16); + if (ZE_RESULT_SUCCESS != result) { + pProperties->physicalSize = 0u; + } else { + pProperties->physicalSize = intval; + } + } return ZE_RESULT_SUCCESS; } + +ze_result_t LinuxMemoryImp::getVFIDString(std::string &vfID) { + uint32_t vf0VfIdVal = 0; + std::string key = "VF0_VFID"; + auto result = pPmt->readValue(key, vf0VfIdVal); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for VF0_VFID is returning error:0x%x \n", __FUNCTION__, result); + return result; + } + + uint32_t vf1VfIdVal = 0; + key = "VF1_VFID"; + result = pPmt->readValue(key, vf1VfIdVal); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for VF1_VFID is returning error:0x%x \n", __FUNCTION__, result); + return result; + } + + // At any point of time only one VF(virtual function) could be active and thus would + // read greater than zero val. If both VF0 and VF1 are reading 0 or both are reading + // greater than 0, then we would be confused in taking the decision of correct VF. + // Lets assume and report this as a error condition + if (((vf0VfIdVal == 0) && (vf1VfIdVal == 0)) || + ((vf0VfIdVal > 0) && (vf1VfIdVal > 0))) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() VF0 returning 0x%x and VF1 returning 0x%x as both should not be the same \n", __FUNCTION__, vf0VfIdVal, vf1VfIdVal); + return ZE_RESULT_ERROR_UNKNOWN; + } + + if (vf0VfIdVal > 0) { + vfID = "VF0"; + } + if (vf1VfIdVal > 0) { + vfID = "VF1"; + } + return result; +} + +ze_result_t LinuxMemoryImp::readMcChannelCounters(uint64_t &readCounters, uint64_t &writeCounters) { + // For DG2 there are 8 memory instances each memory instance has 2 channels there are total 16 MC Channels + uint32_t numMcChannels = 16u; + ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; + std::vector nameOfCounters{"IDI_READS", "IDI_WRITES", "DISPLAY_VC1_READS"}; + std::vector counterValues(3, 0); // Will store the values of counters metioned in nameOfCounters + for (uint64_t counterIndex = 0; counterIndex < nameOfCounters.size(); counterIndex++) { + for (uint32_t mcChannelIndex = 0; mcChannelIndex < numMcChannels; mcChannelIndex++) { + uint64_t val = 0; + std::string readCounterKey = nameOfCounters[counterIndex] + "[" + std::to_string(mcChannelIndex) + "]"; + result = pPmt->readValue(readCounterKey, val); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterKey returning error:0x%x \n", __FUNCTION__, result); + return result; + } + counterValues[counterIndex] += val; + } + } + // PMT counters returns number of transactions that have occured and each tranaction is of 64 bytes + // Multiplying 32(tranaction size) with number of transactions gives the total reads or writes in bytes + constexpr uint64_t transactionSize = 32; + readCounters = (counterValues[0] + counterValues[2]) * transactionSize; // Read counters are summation of total IDI_READS and DISPLAY_VC1_READS + writeCounters = (counterValues[1]) * transactionSize; // Write counters are summation of IDI_WRITES + return result; +} + +void LinuxMemoryImp::getHbmFrequency(PRODUCT_FAMILY productFamily, unsigned short stepping, uint64_t &hbmFrequency) { + hbmFrequency = 0; + if (productFamily == IGFX_PVC) { + if (stepping >= REVISION_B) { + const std::string baseDir = "gt/gt" + std::to_string(subdeviceId) + "/"; + // Calculating bandwidth based on HBM max frequency + const std::string hbmRP0FreqFile = baseDir + "mem_RP0_freq_mhz"; + uint64_t hbmFreqValue = 0; + ze_result_t result = pSysfsAccess->read(hbmRP0FreqFile, hbmFreqValue); + if (ZE_RESULT_SUCCESS == result) { + hbmFrequency = hbmFreqValue * 1000 * 1000; // Converting MHz value to Hz + return; + } + } else if (stepping == REVISION_A0) { + // For IGFX_PVC REV A0 HBM frequency would be 3.2 GT/s = 3.2 * 1000 * 1000 * 1000 T/s = 3200000000 T/s + hbmFrequency = 3.2 * gigaUnitTransferToUnitTransfer; + } + } +} + +ze_result_t LinuxMemoryImp::getBandwidthForDg2(zes_mem_bandwidth_t *pBandwidth) { + pBandwidth->readCounter = 0; + pBandwidth->writeCounter = 0; + pBandwidth->timestamp = 0; + pBandwidth->maxBandwidth = 0; + ze_result_t result = readMcChannelCounters(pBandwidth->readCounter, pBandwidth->writeCounter); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readMcChannelCounters returning error:0x%x \n", __FUNCTION__, result); + return result; + } + pBandwidth->maxBandwidth = 0u; + const std::string maxBwFile = "prelim_lmem_max_bw_Mbps"; + uint64_t maxBw = 0; + result = pSysfsAccess->read(maxBwFile, maxBw); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():pSysfsAccess->read returning error:0x%x \n", __FUNCTION__, result); + } + pBandwidth->maxBandwidth = maxBw * mbpsToBytesPerSecond; + pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp(); + return ZE_RESULT_SUCCESS; +} + +ze_result_t LinuxMemoryImp::getHbmBandwidth(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth) { + pBandwidth->readCounter = 0; + pBandwidth->writeCounter = 0; + pBandwidth->timestamp = 0; + pBandwidth->maxBandwidth = 0; + ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; + std::string vfId = ""; + result = getVFIDString(vfId); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():getVFIDString returning error:0x%x while retriving VFID string \n", __FUNCTION__, result); + return result; + } + auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); + auto productFamily = hwInfo.platform.eProductFamily; + auto &productHelper = pDevice->getNEODevice()->getProductHelper(); + auto stepping = productHelper.getSteppingFromHwRevId(hwInfo); + for (auto hbmModuleIndex = 0u; hbmModuleIndex < numHbmModules; hbmModuleIndex++) { + uint32_t counterValue = 0; + // To read counters from VFID 0 and HBM module 0, key would be: VF0_HBM0_READ + std::string readCounterKey = vfId + "_HBM" + std::to_string(hbmModuleIndex) + "_READ"; + result = pPmt->readValue(readCounterKey, counterValue); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterKey returning error:0x%x \n", __FUNCTION__, result); + return result; + } + pBandwidth->readCounter += counterValue; + + counterValue = 0; + // To write counters to VFID 0 and HBM module 0, key would be: VF0_HBM0_Write + std::string writeCounterKey = vfId + "_HBM" + std::to_string(hbmModuleIndex) + "_WRITE"; + result = pPmt->readValue(writeCounterKey, counterValue); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for writeCounterKey returning error:0x%x \n", __FUNCTION__, result); + return result; + } + pBandwidth->writeCounter += counterValue; + } + constexpr uint64_t transactionSize = 32; + pBandwidth->readCounter = pBandwidth->readCounter * transactionSize; + pBandwidth->writeCounter = pBandwidth->writeCounter * transactionSize; + pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp(); + + uint64_t hbmFrequency = 0; + getHbmFrequency(productFamily, stepping, hbmFrequency); + + pBandwidth->maxBandwidth = memoryBusWidth * hbmFrequency * numHbmModules; // Value in bytes/secs + return result; +} + +ze_result_t LinuxMemoryImp::getHbmBandwidthPVC(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth) { + std::string guid = pPmt->getGuid(); + if (guid != guid64BitMemoryCounters) { + return getHbmBandwidth(numHbmModules, pBandwidth); + } + pBandwidth->readCounter = 0; + pBandwidth->writeCounter = 0; + pBandwidth->timestamp = 0; + pBandwidth->maxBandwidth = 0; + ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; + std::string vfId = ""; + result = getVFIDString(vfId); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():getVFIDString returning error:0x%x while retriving VFID string \n", __FUNCTION__, result); + return result; + } + auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); + auto productFamily = hwInfo.platform.eProductFamily; + auto &productHelper = pDevice->getNEODevice()->getProductHelper(); + auto stepping = productHelper.getSteppingFromHwRevId(hwInfo); + + uint32_t readCounterL = 0; + std::string readCounterKey = vfId + "_HBM_READ_L"; + result = pPmt->readValue(readCounterKey, readCounterL); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterL returning error:0x%x \n", __FUNCTION__, result); + return result; + } + + uint32_t readCounterH = 0; + readCounterKey = vfId + "_HBM_READ_H"; + result = pPmt->readValue(readCounterKey, readCounterH); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterH returning error:0x%x \n", __FUNCTION__, result); + return result; + } + + constexpr uint64_t transactionSize = 32; + pBandwidth->readCounter = readCounterH; + pBandwidth->readCounter = (pBandwidth->readCounter << 32) | static_cast(readCounterL); + pBandwidth->readCounter = (pBandwidth->readCounter * transactionSize); + + uint32_t writeCounterL = 0; + std::string writeCounterKey = vfId + "_HBM_WRITE_L"; + result = pPmt->readValue(writeCounterKey, writeCounterL); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for writeCounterL returning error:0x%x \n", __FUNCTION__, result); + return result; + } + + uint32_t writeCounterH = 0; + writeCounterKey = vfId + "_HBM_WRITE_H"; + result = pPmt->readValue(writeCounterKey, writeCounterH); + if (result != ZE_RESULT_SUCCESS) { + NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for writeCounterH returning error:0x%x \n", __FUNCTION__, result); + return result; + } + + pBandwidth->writeCounter = writeCounterH; + pBandwidth->writeCounter = (pBandwidth->writeCounter << 32) | static_cast(writeCounterL); + pBandwidth->writeCounter = (pBandwidth->writeCounter * transactionSize); + + uint64_t timeStampVal = 0; + memoryGetTimeStamp(timeStampVal); + pBandwidth->timestamp = timeStampVal; + + uint64_t hbmFrequency = 0; + getHbmFrequency(productFamily, stepping, hbmFrequency); + + pBandwidth->maxBandwidth = memoryBusWidth * hbmFrequency * numHbmModules; // Value in bytes/secs + return result; +} + ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + if (pPmt == nullptr) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; + auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); + auto productFamily = hwInfo.platform.eProductFamily; + uint32_t numHbmModules = 0u; + switch (productFamily) { + case IGFX_DG2: + result = getBandwidthForDg2(pBandwidth); + break; + case IGFX_PVC: + numHbmModules = 4u; + result = getHbmBandwidthPVC(numHbmModules, pBandwidth); + break; + default: + result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + break; + } + return result; } ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + ze_result_t status = ZE_RESULT_SUCCESS; + pState->health = ZES_MEM_HEALTH_UNKNOWN; + FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); + auto productFamily = SysmanDeviceImp::getProductFamily(pDevice); + if ((pFwInterface != nullptr) && (IGFX_PVC == productFamily)) { + pFwInterface->fwGetMemoryHealthIndicator(&pState->health); + } + auto 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; } std::unique_ptr OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) { diff --git a/level_zero/tools/source/sysman/memory/linux/os_memory_imp.h b/level_zero/tools/source/sysman/memory/linux/os_memory_imp.h index d40a8f4f66..405083e77b 100644 --- a/level_zero/tools/source/sysman/memory/linux/os_memory_imp.h +++ b/level_zero/tools/source/sysman/memory/linux/os_memory_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2022-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,11 +11,14 @@ #include "level_zero/tools/source/sysman/memory/os_memory.h" +#include + namespace L0 { class SysfsAccess; struct Device; - +class PlatformMonitoringTech; +class LinuxSysmanImp; class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { public: ze_result_t getProperties(zes_mem_properties_t *pProperties) override; @@ -28,11 +31,25 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { ~LinuxMemoryImp() override = default; protected: + L0::LinuxSysmanImp *pLinuxSysmanImp = nullptr; + SysfsAccess *pSysfsAccess = nullptr; NEO::Drm *pDrm = nullptr; Device *pDevice = nullptr; + PlatformMonitoringTech *pPmt = nullptr; + void getHbmFrequency(PRODUCT_FAMILY productFamily, unsigned short stepping, uint64_t &hbmFrequency); private: + ze_result_t readMcChannelCounters(uint64_t &readCounters, uint64_t &writeCounters); + ze_result_t getVFIDString(std::string &vfID); + ze_result_t getBandwidthForDg2(zes_mem_bandwidth_t *pBandwidth); + ze_result_t getHbmBandwidth(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth); + ze_result_t getHbmBandwidthPVC(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth); + ze_result_t getHbmBandwidthEx(uint32_t numHbmModules, uint32_t counterMaxValue, uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout); + void init(); + static const std::string deviceMemoryHealth; bool isSubdevice = false; uint32_t subdeviceId = 0; + std::string physicalSizeFile; }; + } // namespace L0 diff --git a/level_zero/tools/source/sysman/memory/linux/os_memory_imp_dg1.cpp b/level_zero/tools/source/sysman/memory/linux/os_memory_imp_dg1.cpp deleted file mode 100644 index b0839ca379..0000000000 --- a/level_zero/tools/source/sysman/memory/linux/os_memory_imp_dg1.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2020-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/memory_manager/memory_manager.h" -#include "shared/source/os_interface/linux/i915.h" -#include "shared/source/os_interface/linux/memory_info.h" - -#include "level_zero/core/source/driver/driver_handle_imp.h" -#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" -#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp.h" - -namespace L0 { - -LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { - LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); - pDrm = &pLinuxSysmanImp->getDrm(); - pDevice = pLinuxSysmanImp->getDeviceHandle(); -} - -bool LinuxMemoryImp::isMemoryModuleSupported() { - return pDevice->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(pDevice->getRootDeviceIndex()); -} - -ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { - pProperties->location = ZES_MEM_LOC_DEVICE; - pProperties->type = ZES_MEM_TYPE_DDR; - pProperties->onSubdevice = isSubdevice; - pProperties->subdeviceId = subdeviceId; - pProperties->busWidth = -1; - pProperties->numChannels = -1; - pProperties->physicalSize = 0; - - return ZE_RESULT_SUCCESS; -} - -ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -} - -ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { - std::vector deviceRegions; - if (pDrm->queryMemoryInfo() == false) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - - auto memoryInfo = pDrm->getMemoryInfo(); - if (!memoryInfo) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - for (auto region : memoryInfo->getDrmRegionInfos()) { - if (region.region.memoryClass == drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE) { - deviceRegions.push_back(region); - } - } - pState->free = deviceRegions[subdeviceId].unallocatedSize; - pState->size = deviceRegions[subdeviceId].probedSize; - pState->health = ZES_MEM_HEALTH_OK; - return ZE_RESULT_SUCCESS; -} - -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 L0 diff --git a/level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.cpp b/level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.cpp deleted file mode 100644 index 8199c07f8a..0000000000 --- a/level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (C) 2022-2024 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h" - -#include "shared/source/debug_settings/debug_settings_manager.h" -#include "shared/source/device/device.h" -#include "shared/source/helpers/hw_info.h" -#include "shared/source/memory_manager/memory_banks.h" -#include "shared/source/memory_manager/memory_manager.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/core/source/driver/driver_handle.h" -#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h" -#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" -#include "level_zero/tools/source/sysman/sysman_const.h" - -#include "igfxfmid.h" - -namespace L0 { - -const std::string LinuxMemoryImp::deviceMemoryHealth("device_memory_health"); - -void memoryGetTimeStamp(uint64_t ×tamp) { - std::chrono::time_point ts = std::chrono::steady_clock::now(); - timestamp = std::chrono::duration_cast(ts.time_since_epoch()).count(); -} - -void LinuxMemoryImp::init() { - if (isSubdevice) { - const std::string baseDir = "gt/gt" + std::to_string(subdeviceId) + "/"; - physicalSizeFile = baseDir + "addr_range"; - } -} - -LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) { - pLinuxSysmanImp = static_cast(pOsSysman); - pDrm = &pLinuxSysmanImp->getDrm(); - pDevice = pLinuxSysmanImp->getDeviceHandle(); - pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); - pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId); - init(); -} - -bool LinuxMemoryImp::isMemoryModuleSupported() { - return pDevice->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(pDevice->getRootDeviceIndex()); -} - -ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { - pProperties->type = ZES_MEM_TYPE_DDR; - pProperties->numChannels = -1; - if (pDrm->querySystemInfo()) { - auto memSystemInfo = pDrm->getSystemInfo(); - if (memSystemInfo != nullptr) { - pProperties->numChannels = memSystemInfo->getMaxMemoryChannels(); - auto memType = memSystemInfo->getMemoryType(); - switch (memType) { - case NEO::DeviceBlobConstants::MemoryType::hbm2e: - case NEO::DeviceBlobConstants::MemoryType::hbm2: - pProperties->type = ZES_MEM_TYPE_HBM; - break; - case NEO::DeviceBlobConstants::MemoryType::lpddr4: - pProperties->type = ZES_MEM_TYPE_LPDDR4; - break; - case NEO::DeviceBlobConstants::MemoryType::lpddr5: - pProperties->type = ZES_MEM_TYPE_LPDDR5; - break; - default: - pProperties->type = ZES_MEM_TYPE_DDR; - break; - } - } - } - pProperties->location = ZES_MEM_LOC_DEVICE; - pProperties->onSubdevice = isSubdevice; - pProperties->subdeviceId = subdeviceId; - pProperties->busWidth = memoryBusWidth; // Hardcode - - pProperties->physicalSize = 0; - if (isSubdevice) { - std::string memval; - ze_result_t result = pSysfsAccess->read(physicalSizeFile, memval); - uint64_t intval = strtoull(memval.c_str(), nullptr, 16); - if (ZE_RESULT_SUCCESS != result) { - pProperties->physicalSize = 0u; - } else { - pProperties->physicalSize = intval; - } - } - - return ZE_RESULT_SUCCESS; -} - -ze_result_t LinuxMemoryImp::getVFIDString(std::string &vfID) { - uint32_t vf0VfIdVal = 0; - std::string key = "VF0_VFID"; - auto result = pPmt->readValue(key, vf0VfIdVal); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for VF0_VFID is returning error:0x%x \n", __FUNCTION__, result); - return result; - } - - uint32_t vf1VfIdVal = 0; - key = "VF1_VFID"; - result = pPmt->readValue(key, vf1VfIdVal); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for VF1_VFID is returning error:0x%x \n", __FUNCTION__, result); - return result; - } - - // At any point of time only one VF(virtual function) could be active and thus would - // read greater than zero val. If both VF0 and VF1 are reading 0 or both are reading - // greater than 0, then we would be confused in taking the decision of correct VF. - // Lets assume and report this as a error condition - if (((vf0VfIdVal == 0) && (vf1VfIdVal == 0)) || - ((vf0VfIdVal > 0) && (vf1VfIdVal > 0))) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() VF0 returning 0x%x and VF1 returning 0x%x as both should not be the same \n", __FUNCTION__, vf0VfIdVal, vf1VfIdVal); - return ZE_RESULT_ERROR_UNKNOWN; - } - - if (vf0VfIdVal > 0) { - vfID = "VF0"; - } - if (vf1VfIdVal > 0) { - vfID = "VF1"; - } - return result; -} - -ze_result_t LinuxMemoryImp::readMcChannelCounters(uint64_t &readCounters, uint64_t &writeCounters) { - // For DG2 there are 8 memory instances each memory instance has 2 channels there are total 16 MC Channels - uint32_t numMcChannels = 16u; - ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; - std::vector nameOfCounters{"IDI_READS", "IDI_WRITES", "DISPLAY_VC1_READS"}; - std::vector counterValues(3, 0); // Will store the values of counters metioned in nameOfCounters - for (uint64_t counterIndex = 0; counterIndex < nameOfCounters.size(); counterIndex++) { - for (uint32_t mcChannelIndex = 0; mcChannelIndex < numMcChannels; mcChannelIndex++) { - uint64_t val = 0; - std::string readCounterKey = nameOfCounters[counterIndex] + "[" + std::to_string(mcChannelIndex) + "]"; - result = pPmt->readValue(readCounterKey, val); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterKey returning error:0x%x \n", __FUNCTION__, result); - return result; - } - counterValues[counterIndex] += val; - } - } - // PMT counters returns number of transactions that have occured and each tranaction is of 64 bytes - // Multiplying 32(tranaction size) with number of transactions gives the total reads or writes in bytes - constexpr uint64_t transactionSize = 32; - readCounters = (counterValues[0] + counterValues[2]) * transactionSize; // Read counters are summation of total IDI_READS and DISPLAY_VC1_READS - writeCounters = (counterValues[1]) * transactionSize; // Write counters are summation of IDI_WRITES - return result; -} - -void LinuxMemoryImp::getHbmFrequency(PRODUCT_FAMILY productFamily, unsigned short stepping, uint64_t &hbmFrequency) { - hbmFrequency = 0; - if (productFamily == IGFX_PVC) { - if (stepping >= REVISION_B) { - const std::string baseDir = "gt/gt" + std::to_string(subdeviceId) + "/"; - // Calculating bandwidth based on HBM max frequency - const std::string hbmRP0FreqFile = baseDir + "mem_RP0_freq_mhz"; - uint64_t hbmFreqValue = 0; - ze_result_t result = pSysfsAccess->read(hbmRP0FreqFile, hbmFreqValue); - if (ZE_RESULT_SUCCESS == result) { - hbmFrequency = hbmFreqValue * 1000 * 1000; // Converting MHz value to Hz - return; - } - } else if (stepping == REVISION_A0) { - // For IGFX_PVC REV A0 HBM frequency would be 3.2 GT/s = 3.2 * 1000 * 1000 * 1000 T/s = 3200000000 T/s - hbmFrequency = 3.2 * gigaUnitTransferToUnitTransfer; - } - } -} - -ze_result_t LinuxMemoryImp::getBandwidthForDg2(zes_mem_bandwidth_t *pBandwidth) { - pBandwidth->readCounter = 0; - pBandwidth->writeCounter = 0; - pBandwidth->timestamp = 0; - pBandwidth->maxBandwidth = 0; - ze_result_t result = readMcChannelCounters(pBandwidth->readCounter, pBandwidth->writeCounter); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readMcChannelCounters returning error:0x%x \n", __FUNCTION__, result); - return result; - } - pBandwidth->maxBandwidth = 0u; - const std::string maxBwFile = "prelim_lmem_max_bw_Mbps"; - uint64_t maxBw = 0; - result = pSysfsAccess->read(maxBwFile, maxBw); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():pSysfsAccess->read returning error:0x%x \n", __FUNCTION__, result); - } - pBandwidth->maxBandwidth = maxBw * mbpsToBytesPerSecond; - pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp(); - return ZE_RESULT_SUCCESS; -} - -ze_result_t LinuxMemoryImp::getHbmBandwidth(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth) { - pBandwidth->readCounter = 0; - pBandwidth->writeCounter = 0; - pBandwidth->timestamp = 0; - pBandwidth->maxBandwidth = 0; - ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; - std::string vfId = ""; - result = getVFIDString(vfId); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():getVFIDString returning error:0x%x while retriving VFID string \n", __FUNCTION__, result); - return result; - } - auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); - auto productFamily = hwInfo.platform.eProductFamily; - auto &productHelper = pDevice->getNEODevice()->getProductHelper(); - auto stepping = productHelper.getSteppingFromHwRevId(hwInfo); - for (auto hbmModuleIndex = 0u; hbmModuleIndex < numHbmModules; hbmModuleIndex++) { - uint32_t counterValue = 0; - // To read counters from VFID 0 and HBM module 0, key would be: VF0_HBM0_READ - std::string readCounterKey = vfId + "_HBM" + std::to_string(hbmModuleIndex) + "_READ"; - result = pPmt->readValue(readCounterKey, counterValue); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterKey returning error:0x%x \n", __FUNCTION__, result); - return result; - } - pBandwidth->readCounter += counterValue; - - counterValue = 0; - // To write counters to VFID 0 and HBM module 0, key would be: VF0_HBM0_Write - std::string writeCounterKey = vfId + "_HBM" + std::to_string(hbmModuleIndex) + "_WRITE"; - result = pPmt->readValue(writeCounterKey, counterValue); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for writeCounterKey returning error:0x%x \n", __FUNCTION__, result); - return result; - } - pBandwidth->writeCounter += counterValue; - } - constexpr uint64_t transactionSize = 32; - pBandwidth->readCounter = pBandwidth->readCounter * transactionSize; - pBandwidth->writeCounter = pBandwidth->writeCounter * transactionSize; - pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp(); - - uint64_t hbmFrequency = 0; - getHbmFrequency(productFamily, stepping, hbmFrequency); - - pBandwidth->maxBandwidth = memoryBusWidth * hbmFrequency * numHbmModules; // Value in bytes/secs - return result; -} - -ze_result_t LinuxMemoryImp::getHbmBandwidthPVC(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth) { - std::string guid = pPmt->getGuid(); - if (guid != guid64BitMemoryCounters) { - return getHbmBandwidth(numHbmModules, pBandwidth); - } - pBandwidth->readCounter = 0; - pBandwidth->writeCounter = 0; - pBandwidth->timestamp = 0; - pBandwidth->maxBandwidth = 0; - ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; - std::string vfId = ""; - result = getVFIDString(vfId); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():getVFIDString returning error:0x%x while retriving VFID string \n", __FUNCTION__, result); - return result; - } - auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); - auto productFamily = hwInfo.platform.eProductFamily; - auto &productHelper = pDevice->getNEODevice()->getProductHelper(); - auto stepping = productHelper.getSteppingFromHwRevId(hwInfo); - - uint32_t readCounterL = 0; - std::string readCounterKey = vfId + "_HBM_READ_L"; - result = pPmt->readValue(readCounterKey, readCounterL); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterL returning error:0x%x \n", __FUNCTION__, result); - return result; - } - - uint32_t readCounterH = 0; - readCounterKey = vfId + "_HBM_READ_H"; - result = pPmt->readValue(readCounterKey, readCounterH); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for readCounterH returning error:0x%x \n", __FUNCTION__, result); - return result; - } - - constexpr uint64_t transactionSize = 32; - pBandwidth->readCounter = readCounterH; - pBandwidth->readCounter = (pBandwidth->readCounter << 32) | static_cast(readCounterL); - pBandwidth->readCounter = (pBandwidth->readCounter * transactionSize); - - uint32_t writeCounterL = 0; - std::string writeCounterKey = vfId + "_HBM_WRITE_L"; - result = pPmt->readValue(writeCounterKey, writeCounterL); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for writeCounterL returning error:0x%x \n", __FUNCTION__, result); - return result; - } - - uint32_t writeCounterH = 0; - writeCounterKey = vfId + "_HBM_WRITE_H"; - result = pPmt->readValue(writeCounterKey, writeCounterH); - if (result != ZE_RESULT_SUCCESS) { - NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s():readValue for writeCounterH returning error:0x%x \n", __FUNCTION__, result); - return result; - } - - pBandwidth->writeCounter = writeCounterH; - pBandwidth->writeCounter = (pBandwidth->writeCounter << 32) | static_cast(writeCounterL); - pBandwidth->writeCounter = (pBandwidth->writeCounter * transactionSize); - - uint64_t timeStampVal = 0; - memoryGetTimeStamp(timeStampVal); - pBandwidth->timestamp = timeStampVal; - - uint64_t hbmFrequency = 0; - getHbmFrequency(productFamily, stepping, hbmFrequency); - - pBandwidth->maxBandwidth = memoryBusWidth * hbmFrequency * numHbmModules; // Value in bytes/secs - return result; -} - -ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) { - if (pPmt == nullptr) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - ze_result_t result = ZE_RESULT_ERROR_UNKNOWN; - auto &hwInfo = pDevice->getNEODevice()->getHardwareInfo(); - auto productFamily = hwInfo.platform.eProductFamily; - uint32_t numHbmModules = 0u; - switch (productFamily) { - case IGFX_DG2: - result = getBandwidthForDg2(pBandwidth); - break; - case IGFX_PVC: - numHbmModules = 4u; - result = getHbmBandwidthPVC(numHbmModules, pBandwidth); - break; - default: - result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - break; - } - return result; -} - -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(); - auto productFamily = SysmanDeviceImp::getProductFamily(pDevice); - if ((pFwInterface != nullptr) && (IGFX_PVC == productFamily)) { - pFwInterface->fwGetMemoryHealthIndicator(&pState->health); - } - auto 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; -} - -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 L0 diff --git a/level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h b/level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h deleted file mode 100644 index d122997311..0000000000 --- a/level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h +++ /dev/null @@ -1,55 +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/tools/source/sysman/memory/os_memory.h" - -#include - -namespace L0 { - -class SysfsAccess; -struct Device; -class PlatformMonitoringTech; -class LinuxSysmanImp; -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: - L0::LinuxSysmanImp *pLinuxSysmanImp = nullptr; - SysfsAccess *pSysfsAccess = nullptr; - NEO::Drm *pDrm = nullptr; - Device *pDevice = nullptr; - PlatformMonitoringTech *pPmt = nullptr; - void getHbmFrequency(PRODUCT_FAMILY productFamily, unsigned short stepping, uint64_t &hbmFrequency); - - private: - ze_result_t readMcChannelCounters(uint64_t &readCounters, uint64_t &writeCounters); - ze_result_t getVFIDString(std::string &vfID); - ze_result_t getBandwidthForDg2(zes_mem_bandwidth_t *pBandwidth); - ze_result_t getHbmBandwidth(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth); - ze_result_t getHbmBandwidthPVC(uint32_t numHbmModules, zes_mem_bandwidth_t *pBandwidth); - ze_result_t getHbmBandwidthEx(uint32_t numHbmModules, uint32_t counterMaxValue, uint64_t *pReadCounters, uint64_t *pWriteCounters, uint64_t *pMaxBandwidth, uint64_t timeout); - void init(); - static const std::string deviceMemoryHealth; - bool isSubdevice = false; - uint32_t subdeviceId = 0; - std::string physicalSizeFile; -}; - -} // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/CMakeLists.txt b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/CMakeLists.txt index 14189e0414..fadf8fec97 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2024 Intel Corporation +# Copyright (C) 2020-2025 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -8,25 +8,10 @@ set(L0_TESTS_TOOLS_SYSMAN_MEMORY_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ) -if(NEO_ENABLE_I915_PRELIM_DETECTION) - list(APPEND L0_TESTS_TOOLS_SYSMAN_MEMORY_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory_prelim.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_prelim.h - ) - -else() - if(SUPPORT_DG1) - list(APPEND L0_TESTS_TOOLS_SYSMAN_MEMORY_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory_dg1.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h - ) - else() - list(APPEND L0_TESTS_TOOLS_SYSMAN_MEMORY_LINUX - ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h - ) - endif() -endif() +list(APPEND L0_TESTS_TOOLS_SYSMAN_MEMORY_LINUX + ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h +) if(UNIX) target_sources(${TARGET_NAME} diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h index 4e1cd91903..8a6d53dc1b 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2021-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,7 +7,9 @@ #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/core/test/unit_tests/mocks/mock_memory_manager.h" #include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" @@ -15,16 +17,189 @@ #include "level_zero/tools/source/sysman/memory/memory_imp.h" using namespace NEO; -constexpr uint64_t probedSizeRegionZero = 8 * MemoryConstants::gigaByte; -constexpr uint64_t probedSizeRegionOne = 16 * MemoryConstants::gigaByte; -constexpr uint64_t probedSizeRegionTwo = 4 * MemoryConstants::gigaByte; -constexpr uint64_t probedSizeRegionThree = 16 * MemoryConstants::gigaByte; -constexpr uint64_t unallocatedSizeRegionZero = 6 * MemoryConstants::gigaByte; -constexpr uint64_t unallocatedSizeRegionOne = 12 * MemoryConstants::gigaByte; -constexpr uint64_t unallocatedSizeRegionTwo = 25 * MemoryConstants::gigaByte; -constexpr uint64_t unallocatedSizeRegionThree = 3 * MemoryConstants::gigaByte; + +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 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 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 ult { +uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; +constexpr uint64_t hbmRP0Frequency = 4200; // in MHz +constexpr std::string_view mockPhysicalSize = "0x00000040000000"; +constexpr std::string_view deviceMemoryHealth("device_memory_health"); +constexpr std::string_view baseTelemSysFS("/sys/class/intel_pmt"); +constexpr std::string_view 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"; +constexpr std::string_view 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"; +constexpr std::string_view 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"; +constexpr std::string_view 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"; +constexpr std::string_view 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"; +constexpr std::string_view sysfsPathTelem1 = "/sys/class/intel_pmt/telem1"; +constexpr std::string_view sysfsPathTelem2 = "/sys/class/intel_pmt/telem2"; +constexpr std::string_view sysfsPathTelem3 = "/sys/class/intel_pmt/telem3"; +constexpr std::string_view sysfsPathTelem4 = "/sys/class/intel_pmt/telem4"; +constexpr std::string_view sysfsPathTelem5 = "/sys/class/intel_pmt/telem5"; + +struct MockMemorySysfsAccess : public SysfsAccess { + + std::vector mockReadReturnStatus{}; + std::vector mockReadStringValue{}; + std::vector mockReadUInt64Value{}; + bool isRepeated = false; + + ze_result_t getVal(const std::string file, std::string &val) { + if ((file.compare("gt/gt0/addr_range") == 0) || (file.compare("gt/gt1/addr_range") == 0)) { + val = mockPhysicalSize; + return ZE_RESULT_SUCCESS; + } + val = "0"; + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + + ze_result_t getValError(const std::string file, std::string &val) { + val = "0"; + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + + ze_result_t getMemHealthValReturnErrorNotAvailable(const std::string file, std::string &val) { + if (file.compare(deviceMemoryHealth) == 0) { + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + return ZE_RESULT_SUCCESS; + } + + ze_result_t getMemHealthReturnErrorUnknown(const std::string file, std::string &val) { + if (file.compare(deviceMemoryHealth) == 0) { + return ZE_RESULT_ERROR_UNKNOWN; + } + return ZE_RESULT_SUCCESS; + } + + 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; + } + + ze_result_t read(const std::string file, uint64_t &val) override { + ze_result_t result = ZE_RESULT_SUCCESS; + if (!mockReadReturnStatus.empty()) { + result = mockReadReturnStatus.front(); + if (!mockReadUInt64Value.empty()) { + val = mockReadUInt64Value.front(); + } + + if (isRepeated != true) { + mockReadReturnStatus.erase(mockReadReturnStatus.begin()); + if (!mockReadUInt64Value.empty()) { + mockReadUInt64Value.erase(mockReadUInt64Value.begin()); + } + } + } + return result; + } + + ze_result_t getMemHealthDegraded(const std::string file, std::string &val) { + if (file.compare(deviceMemoryHealth) == 0) { + val = "REBOOT_ALARM"; + } + return ZE_RESULT_SUCCESS; + } + + ze_result_t getMemHealthCritical(const std::string file, std::string &val) { + if (file.compare(deviceMemoryHealth) == 0) { + val = "DEGRADED"; + } + return ZE_RESULT_SUCCESS; + } + + ze_result_t getMemHealthReplace(const std::string file, std::string &val) { + if (file.compare(deviceMemoryHealth) == 0) { + val = "DEGRADED_FAILED"; + } + return ZE_RESULT_SUCCESS; + } + + ze_result_t getMemHealthUnknown(const std::string file, std::string &val) { + if (file.compare(deviceMemoryHealth) == 0) { + val = "RANDOM"; + } + return ZE_RESULT_SUCCESS; + } +}; struct MockMemoryManagerSysman : public MemoryManagerMock { MockMemoryManagerSysman(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast(executionEnvironment)) {} @@ -32,27 +207,277 @@ struct MockMemoryManagerSysman : public MemoryManagerMock { struct MockMemoryNeoDrm : public Drm { using Drm::ioctlHelper; - using Drm::memoryInfo; const int mockFd = 33; + std::vector mockQuerySystemInfoReturnValue{}; + bool isRepeated = false; + bool mockReturnEmptyRegions = false; MockMemoryNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(mockFd, ""), rootDeviceEnvironment) {} - std::vector mockQueryMemoryInfoReturnStatus{}; - bool queryMemoryInfo() override { - if (!mockQueryMemoryInfoReturnStatus.empty()) { - return mockQueryMemoryInfoReturnStatus.front(); + + void setMemoryType(uint32_t memory) { + mockMemoryType = memory; + } + + std::vector getMemoryRegionsReturnsEmpty() { + return {}; + } + + bool querySystemInfo() override { + bool returnValue = true; + if (!mockQuerySystemInfoReturnValue.empty()) { + returnValue = mockQuerySystemInfoReturnValue.front(); + if (isRepeated != true) { + mockQuerySystemInfoReturnValue.erase(mockQuerySystemInfoReturnValue.begin()); + } + return returnValue; } - std::vector regionInfo(2); - regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0}; - regionInfo[0].probedSize = probedSizeRegionZero; - regionInfo[0].unallocatedSize = unallocatedSizeRegionZero; - regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 0}; - regionInfo[1].probedSize = probedSizeRegionOne; - regionInfo[1].unallocatedSize = unallocatedSizeRegionOne; - - this->memoryInfo.reset(new MemoryInfo(regionInfo, *this)); - return 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; } }; +struct MockMemoryPmt : public PlatformMonitoringTech { + + using PlatformMonitoringTech::guid; + using 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_view guid) { + this->guid = guid; + } + + MockMemoryPmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} + 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; + } +}; + +struct MockMemoryFsAccess : public FsAccess { + ze_result_t listDirectory(const std::string directory, std::vector &listOfTelemNodes) override { + if (directory.compare(baseTelemSysFS) == 0) { + listOfTelemNodes.push_back("telem1"); + listOfTelemNodes.push_back("telem2"); + listOfTelemNodes.push_back("telem3"); + listOfTelemNodes.push_back("telem4"); + listOfTelemNodes.push_back("telem5"); + return ZE_RESULT_SUCCESS; + } + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + + ze_result_t listDirectoryFailure(const std::string directory, std::vector &events) { + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + + ze_result_t getRealPath(const std::string path, std::string &buf) override { + if (path.compare(sysfsPathTelem1) == 0) { + buf = realPathTelem1; + } else if (path.compare(sysfsPathTelem2) == 0) { + buf = realPathTelem2; + } else if (path.compare(sysfsPathTelem3) == 0) { + buf = realPathTelem3; + } else if (path.compare(sysfsPathTelem4) == 0) { + buf = realPathTelem4; + } else if (path.compare(sysfsPathTelem5) == 0) { + buf = realPathTelem5; + } else { + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + return ZE_RESULT_SUCCESS; + } + + ze_result_t getRealPathFailure(const std::string path, std::string &buf) { + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + + MockMemoryFsAccess() = default; +}; + +class PublicLinuxMemoryImp : public L0::LinuxMemoryImp { + public: + PublicLinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : LinuxMemoryImp(pOsSysman, onSubdevice, subdeviceId) {} + PublicLinuxMemoryImp() = default; + using LinuxMemoryImp::getHbmFrequency; +}; + } // namespace ult } // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory_prelim.h b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory_prelim.h deleted file mode 100644 index bdac0c6ba0..0000000000 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory_prelim.h +++ /dev/null @@ -1,484 +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/core/test/unit_tests/mocks/mock_memory_manager.h" -#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h" -#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h" -#include "level_zero/tools/source/sysman/memory/memory_imp.h" - -using namespace NEO; - -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 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 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 ult { -uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e; -std::string mockPhysicalSize = "0x00000040000000"; -uint64_t hbmRP0Frequency = 4200; // in MHz -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 SysfsAccess { - - std::vector mockReadReturnStatus{}; - std::vector mockReadStringValue{}; - std::vector mockReadUInt64Value{}; - bool isRepeated = false; - - ze_result_t getVal(const std::string file, std::string &val) { - if ((file.compare("gt/gt0/addr_range") == 0) || (file.compare("gt/gt1/addr_range") == 0)) { - val = mockPhysicalSize; - return ZE_RESULT_SUCCESS; - } - val = "0"; - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - ze_result_t getValError(const std::string file, std::string &val) { - val = "0"; - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - ze_result_t getMemHealthValReturnErrorNotAvailable(const std::string file, std::string &val) { - if (file.compare(deviceMemoryHealth) == 0) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t getMemHealthReturnErrorUnknown(const std::string file, std::string &val) { - if (file.compare(deviceMemoryHealth) == 0) { - return ZE_RESULT_ERROR_UNKNOWN; - } - return ZE_RESULT_SUCCESS; - } - - 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; - } - - ze_result_t read(const std::string file, uint64_t &val) override { - ze_result_t result = ZE_RESULT_SUCCESS; - if (!mockReadReturnStatus.empty()) { - result = mockReadReturnStatus.front(); - if (!mockReadUInt64Value.empty()) { - val = mockReadUInt64Value.front(); - } - - if (isRepeated != true) { - mockReadReturnStatus.erase(mockReadReturnStatus.begin()); - if (!mockReadUInt64Value.empty()) { - mockReadUInt64Value.erase(mockReadUInt64Value.begin()); - } - } - } - return result; - } - - ze_result_t getMemHealthDegraded(const std::string file, std::string &val) { - if (file.compare(deviceMemoryHealth) == 0) { - val = "REBOOT_ALARM"; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t getMemHealthCritical(const std::string file, std::string &val) { - if (file.compare(deviceMemoryHealth) == 0) { - val = "DEGRADED"; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t getMemHealthReplace(const std::string file, std::string &val) { - if (file.compare(deviceMemoryHealth) == 0) { - val = "DEGRADED_FAILED"; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t getMemHealthUnknown(const std::string file, std::string &val) { - if (file.compare(deviceMemoryHealth) == 0) { - val = "RANDOM"; - } - return ZE_RESULT_SUCCESS; - } -}; - -struct MockMemoryManagerSysman : public MemoryManagerMock { - MockMemoryManagerSysman(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast(executionEnvironment)) {} -}; - -struct MockMemoryNeoDrm : public 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 {}; - } - - bool querySystemInfo() override { - bool returnValue = true; - if (!mockQuerySystemInfoReturnValue.empty()) { - returnValue = mockQuerySystemInfoReturnValue.front(); - if (isRepeated != true) { - mockQuerySystemInfoReturnValue.erase(mockQuerySystemInfoReturnValue.begin()); - } - 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 PlatformMonitoringTech { - - using PlatformMonitoringTech::guid; - using 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_view guid) { - this->guid = guid; - } - - MockMemoryPmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} - 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; - } -}; - -struct MockMemoryFsAccess : public FsAccess { - ze_result_t listDirectory(const std::string directory, std::vector &listOfTelemNodes) override { - if (directory.compare(baseTelemSysFS) == 0) { - listOfTelemNodes.push_back("telem1"); - listOfTelemNodes.push_back("telem2"); - listOfTelemNodes.push_back("telem3"); - listOfTelemNodes.push_back("telem4"); - listOfTelemNodes.push_back("telem5"); - return ZE_RESULT_SUCCESS; - } - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - ze_result_t listDirectoryFailure(const std::string directory, std::vector &events) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - ze_result_t getRealPath(const std::string path, std::string &buf) override { - if (path.compare(sysfsPahTelem1) == 0) { - buf = realPathTelem1; - } else if (path.compare(sysfsPahTelem2) == 0) { - buf = realPathTelem2; - } else if (path.compare(sysfsPahTelem3) == 0) { - buf = realPathTelem3; - } else if (path.compare(sysfsPahTelem4) == 0) { - buf = realPathTelem4; - } else if (path.compare(sysfsPahTelem5) == 0) { - buf = realPathTelem5; - } else { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - return ZE_RESULT_SUCCESS; - } - - ze_result_t getRealPathFailure(const std::string path, std::string &buf) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - MockMemoryFsAccess() = default; -}; - -class PublicLinuxMemoryImp : public L0::LinuxMemoryImp { - public: - PublicLinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : LinuxMemoryImp(pOsSysman, onSubdevice, subdeviceId) {} - PublicLinuxMemoryImp() = default; - using LinuxMemoryImp::getHbmFrequency; -}; - -} // namespace ult -} // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp index 2235e7f682..ce0c45f5a6 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp @@ -1,39 +1,87 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2021-2025 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp.h" -#include "level_zero/tools/source/sysman/sysman_imp.h" +#include "shared/source/os_interface/driver_info.h" +#include "shared/test/common/mocks/linux/mock_ioctl_helper.h" + +#include "level_zero/tools/source/sysman/linux/pmt/pmt_xml_offsets.h" #include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h" #include "level_zero/tools/test/unit_tests/sources/sysman/memory/linux/mock_memory.h" -#include "gtest/gtest.h" - extern bool sysmanUltsEnable; namespace L0 { namespace ult { -constexpr uint32_t memoryHandleComponentCount = 1u; +constexpr static int32_t memoryBusWidth = 128; // bus width in bytes +constexpr static int32_t numMemoryChannels = 8; +constexpr static uint32_t memoryHandleComponentCount = 1u; + +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 { + public: + MockMemoryNeoDrm *pDrm = nullptr; + protected: + std::unique_ptr pSysfsAccess; + std::unique_ptr pFsAccess; + SysfsAccess *pSysfsAccessOld = nullptr; + FsAccess *pFsAccessOriginal = nullptr; + Drm *pOriginalDrm = nullptr; + std::vector deviceHandles; + PRODUCT_FAMILY productFamily; + uint16_t stepping; + std::map pmtMapOriginal; + void SetUp() override { if (!sysmanUltsEnable) { GTEST_SKIP(); } SysmanDeviceFixture::SetUp(); + pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; + pSysfsAccess = std::make_unique(); + pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); + pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); pMemoryManager->localMemorySupported[0] = false; device->getDriverHandle()->setMemoryManager(pMemoryManager); + pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); + + pSysmanDevice = device->getSysmanHandle(); + pSysmanDeviceImp = static_cast(pSysmanDevice); + pOsSysman = pSysmanDeviceImp->pOsSysman; + pLinuxSysmanImp = static_cast(pOsSysman); + pLinuxSysmanImp->pDrm = pDrm; + pFsAccess = std::make_unique(); + pFsAccessOriginal = pLinuxSysmanImp->pFsAccess; + pLinuxSysmanImp->pFsAccess = pFsAccess.get(); + pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2e); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); uint32_t subDeviceCount = 0; - std::vector deviceHandles; // We received a device handle. Check for subdevices in this device Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); if (subDeviceCount == 0) { @@ -42,6 +90,19 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { deviceHandles.resize(subDeviceCount, nullptr); Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); } + pmtMapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject; + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); + for (auto &deviceHandle : deviceHandles) { + ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; + Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); + auto pPmt = new MockMemoryPmt(pFsAccess.get(), deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, + deviceProperties.subdeviceId); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); + } + auto &hwInfo = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getHardwareInfo(); + productFamily = hwInfo.platform.eProductFamily; + auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); + stepping = productHelper.getSteppingFromHwRevId(hwInfo); getMemoryHandles(0); } @@ -49,7 +110,16 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { if (!sysmanUltsEnable) { GTEST_SKIP(); } + pLinuxSysmanImp->releasePmtObject(); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = pmtMapOriginal; device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); + pLinuxSysmanImp->pFsAccess = pFsAccessOriginal; + pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; + pLinuxSysmanImp->pDrm = pOriginalDrm; + if (pDrm != nullptr) { + delete pDrm; + pDrm = nullptr; + } if (pMemoryManager != nullptr) { delete pMemoryManager; pMemoryManager = nullptr; @@ -84,33 +154,23 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { MemoryManager *pMemoryManagerOld; }; +TEST_F(SysmanDeviceMemoryFixture, GivenWhenGettingMemoryPropertiesThenSuccessIsReturned) { + zes_mem_properties_t properties = {}; + auto pLinuxMemoryImp = std::make_unique(pOsSysman, true, 0); + EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); +} + TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(false); + setLocalSupportedAndReinit(true); + uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, 0u); + EXPECT_EQ(count, memoryHandleComponentCount); } TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - 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, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned) { setLocalSupportedAndReinit(true); - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); -} -TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); @@ -120,8 +180,9 @@ TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemor EXPECT_EQ(count, memoryHandleComponentCount); } -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidHandlesIsReturned) { +TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidHandlesIsReturned) { setLocalSupportedAndReinit(true); + uint32_t count = 0; EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, memoryHandleComponentCount); @@ -133,45 +194,1044 @@ TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryMo } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesThenVerifySysmanMemoryGetPropertiesCallReturnSuccess) { +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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { setLocalSupportedAndReinit(true); + auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { + ASSERT_NE(nullptr, handle); zes_mem_properties_t properties; - EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS); + + 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); } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallReturnUnsupportedFeature) { +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesAndQuerySystemInfoFailsThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown) { + pDrm->mockQuerySystemInfoReturnValue.push_back(false); setLocalSupportedAndReinit(true); + auto handles = getMemoryHandles(memoryHandleComponentCount); for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + 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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesAndQuerySystemInfoSucceedsButMemSysInfoIsNullThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown) { + pDrm->mockQuerySystemInfoReturnValue.push_back(true); + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + 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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { + pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2); + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + 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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLPDDR4LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { + pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr4); + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + 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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLPDDR5LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { + pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr5); + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + 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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithDDRLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { + pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::gddr6); + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + 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, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); zes_mem_state_t state; - EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + + 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, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetBandwidthThenVerifySysmanMemoryGetBandwidthCallReturnUnsupportedFeature) { +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { setLocalSupportedAndReinit(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_SUCCESS); + EXPECT_EQ(state.health, ZES_MEM_HEALTH_UNKNOWN); + EXPECT_EQ(state.size, NEO::probedSizeRegionOne); + EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { + setLocalSupportedAndReinit(true); + + 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) { + setLocalSupportedAndReinit(true); + + 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, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { + pMemoryManager->localMemorySupported[0] = true; + + pLinuxSysmanImp->releaseSysmanDeviceResources(); + pLinuxSysmanImp->pDrm = pDrm; + pLinuxSysmanImp->reInitSysmanDeviceResources(); + + VariableBackup> pmtBackup(&pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); + for (auto &deviceHandle : deviceHandles) { + ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; + Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); + auto pPmt = new MockMemoryPmt(pFsAccess.get(), deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, + deviceProperties.subdeviceId); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); + } + + 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, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { + pMemoryManager->localMemorySupported[0] = true; + + pLinuxSysmanImp->releaseSysmanDeviceResources(); + pLinuxSysmanImp->pDrm = pDrm; + pLinuxSysmanImp->reInitSysmanDeviceResources(); + + VariableBackup> pmtBackup(&pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); + for (auto &deviceHandle : deviceHandles) { + ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; + Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); + auto pPmt = new MockMemoryPmt(pFsAccess.get(), deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, + deviceProperties.subdeviceId); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); + } + + 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; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenPmtObjectIsNullThenFailureRetuned) { + for (auto &subDeviceIdToPmtEntry : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) { + if (subDeviceIdToPmtEntry.second != nullptr) { + delete subDeviceIdToPmtEntry.second; + subDeviceIdToPmtEntry.second = nullptr; + } + } + setLocalSupportedAndReinit(true); + auto handles = getMemoryHandles(memoryHandleComponentCount); + for (auto &handle : handles) { + ASSERT_NE(nullptr, handle); zes_mem_bandwidth_t bandwidth; EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); } } +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { + setLocalSupportedAndReinit(true); + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto &handle : handles) { + ASSERT_NE(nullptr, handle); + 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 = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); + hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockVfid0Status = true; + pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + + 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, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenVFID1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { + setLocalSupportedAndReinit(true); + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto &handle : handles) { + ASSERT_NE(nullptr, handle); + 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 = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); + hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockVfid1Status = true; + pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + + 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, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_READ_LFailsThenFailureIsReturned, IsPVC) { + setLocalSupportedAndReinit(true); + 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); // Return success after reading VF0_VFID + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID + pPmt->mockReadArgumentValue.push_back(2); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_VFIDFailsForOldGuidThenFailureIsReturned, IsPVC) { + setLocalSupportedAndReinit(true); + 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("0xb15a0edd"); + pPmt->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF1_VFIDFailsForOldGuidThenFailureIsReturned, IsPVC) { + setLocalSupportedAndReinit(true); + 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("0xb15a0edd"); + pPmt->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_READ_HFailsThenFailureIsReturned, IsPVC) { + setLocalSupportedAndReinit(true); + 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); // Return success after reading VF0_VFID + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID + pPmt->mockReadArgumentValue.push_back(4); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(2); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_WRITE_LFailsThenFailureIsReturned, IsPVC) { + setLocalSupportedAndReinit(true); + 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(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(4); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(4); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(2); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_WRITE_HFailsThenFailureIsReturned, IsPVC) { + setLocalSupportedAndReinit(true); + 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); // Return success after reading VF0_VFID + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID + pPmt->mockReadArgumentValue.push_back(4); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(4); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(4); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); + pPmt->mockReadArgumentValue.push_back(2); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidUsRevIdForRevisionBWhenCallingzesSysmanMemoryGetBandwidthThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { + setLocalSupportedAndReinit(true); + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (auto &handle : handles) { + ASSERT_NE(nullptr, handle); + zes_mem_bandwidth_t bandwidth{}; + zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; + zesMemoryGetProperties(handle, &properties); + + auto hwInfo = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); + hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); + auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); + pPmt->setGuid(guid64BitMemoryCounters); + pPmt->mockVfid1Status = true; + pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); + uint64_t expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; + EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformThenSuccessIsReturnedAndBandwidthIsValid) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_DG2; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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; + uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0; + uint64_t mockMaxBwDg2 = 1343616u; + pSysfsAccess->mockReadUInt64Value.push_back(mockMaxBwDg2); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + 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); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForUnknownPlatformThenFailureIsReturned) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_UNKNOWN; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + auto handles = getMemoryHandles(memoryHandleComponentCount); + + for (const auto &handle : handles) { + ASSERT_NE(nullptr, handle); + zes_mem_bandwidth_t bandwidth; + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiReadFailsTheFailureIsReturned) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_DG2; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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->mockIdiReadValueFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); + } +} + +HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformAndReadingMaxBwFailsThenMaxBwIsReturnedAsZero, IsDG2) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_DG2; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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; + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); + + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); + EXPECT_EQ(bandwidth.maxBandwidth, 0u); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiWriteFailsTheFailureIsReturned) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_DG2; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfDisplayVc1ReadFailsTheFailureIsReturned) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_DG2; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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->mockDisplayVc1ReadFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCForSteppingIsBAndOnSubDeviceThenHbmFrequencyShouldNotBeZero) { + PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); + uint64_t hbmFrequency = 0; + pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_B, hbmFrequency); + EXPECT_EQ(hbmFrequency, hbmRP0Frequency * 1000 * 1000); + delete pLinuxMemoryImp; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCForSteppingA0ThenHbmFrequencyShouldBeNotZero) { + PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); + uint64_t hbmFrequency = 0; + pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_A0, hbmFrequency); + uint64_t expectedHbmFrequency = 3.2 * gigaUnitTransferToUnitTransfer; + EXPECT_EQ(hbmFrequency, expectedHbmFrequency); + delete pLinuxMemoryImp; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsUnsupportedThenHbmFrequencyShouldBeZero) { + PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); + uint64_t hbmFrequency = 0; + pLinuxMemoryImp->getHbmFrequency(PRODUCT_FAMILY_FORCE_ULONG, REVISION_B, hbmFrequency); + EXPECT_EQ(hbmFrequency, 0u); + delete pLinuxMemoryImp; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCWhenSteppingIsUnknownThenHbmFrequencyShouldBeZero) { + PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); + uint64_t hbmFrequency = 0; + pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, 255, hbmFrequency); + EXPECT_EQ(hbmFrequency, 0u); + delete pLinuxMemoryImp; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCForSteppingIsBAndFailedToReadFrequencyThenHbmFrequencyShouldBeZero) { + PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); + uint64_t hbmFrequency = 0; + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); + pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_B, hbmFrequency); + EXPECT_EQ(hbmFrequency, 0u); + delete pLinuxMemoryImp; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreTrueThenErrorIsReturnedWhileGettingMemoryBandwidth) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_PVC; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF0_VFID + pPmt->mockReadArgumentValue.push_back(1); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreFalseThenErrorIsReturnedWhileGettingMemoryBandwidth) { + setLocalSupportedAndReinit(true); + auto hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.platform.eProductFamily = IGFX_PVC; + pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); + 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); // Return success after reading VF0_VFID + pPmt->mockReadArgumentValue.push_back(0); + pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID + EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); + } +} + +TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCAndSteppingIsNotA0ThenHbmFrequencyWillBeZero) { + PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp; + uint64_t hbmFrequency = 0; + pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_A1, hbmFrequency); + EXPECT_EQ(hbmFrequency, 0u); + delete pLinuxMemoryImp; +} + +TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndFwUtilInterfaceIsAbsentThenMemoryHealthWillBeUnknown) { + setLocalSupportedAndReinit(true); + + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); + auto handles = getMemoryHandles(memoryHandleComponentCount); + + auto deviceImp = static_cast(pLinuxSysmanImp->getDeviceHandle()); + deviceImp->driverInfo.reset(nullptr); + 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); + } +} + TEST_F(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { zes_mem_properties_t properties = {}; - ze_device_properties_t deviceProperties = {}; + ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; ze_bool_t isSubDevice = deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE; Device::fromHandle(device)->getProperties(&deviceProperties); - std::unique_ptr pLinuxMemoryImp = std::make_unique(pOsSysman, isSubDevice, deviceProperties.subdeviceId); + LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, isSubDevice, deviceProperties.subdeviceId); EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); EXPECT_EQ(properties.subdeviceId, deviceProperties.subdeviceId); EXPECT_EQ(properties.onSubdevice, isSubDevice); + delete pLinuxMemoryImp; +} + +class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { + protected: + std::unique_ptr pSysfsAccess; + SysfsAccess *pSysfsAccessOld = nullptr; + MockMemoryNeoDrm *pDrm = nullptr; + Drm *pOriginalDrm = nullptr; + std::vector deviceHandles; + uint32_t subDeviceCount = 0; + + void SetUp() override { + if (!sysmanUltsEnable) { + GTEST_SKIP(); + } + SysmanMultiDeviceFixture::SetUp(); + + pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; + pSysfsAccess = std::make_unique(); + pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); + + pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); + pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); + pMemoryManager->localMemorySupported[0] = true; + device->getDriverHandle()->setMemoryManager(pMemoryManager); + + pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + + pSysmanDevice = device->getSysmanHandle(); + pSysmanDeviceImp = static_cast(pSysmanDevice); + pOsSysman = pSysmanDeviceImp->pOsSysman; + pLinuxSysmanImp = static_cast(pOsSysman); + pLinuxSysmanImp->pDrm = pDrm; + + pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); + // We received a device handle. Check for subdevices in this device + Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); + if (subDeviceCount == 0) { + deviceHandles.resize(1, device->toHandle()); + } else { + deviceHandles.resize(subDeviceCount, nullptr); + Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); + } + getMemoryHandles(0); + } + + void TearDown() override { + if (!sysmanUltsEnable) { + GTEST_SKIP(); + } + device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); + SysmanMultiDeviceFixture::TearDown(); + pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; + pLinuxSysmanImp->pDrm = pOriginalDrm; + if (pDrm != nullptr) { + delete pDrm; + pDrm = nullptr; + } + if (pMemoryManager != nullptr) { + delete pMemoryManager; + pMemoryManager = nullptr; + } + } + + void setLocalSupportedAndReinit(bool supported) { + pMemoryManager->localMemorySupported[0] = supported; + + pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); + uint32_t subDeviceCount = 0; + std::vector deviceHandles; + // We received a device handle. Check for subdevices in this device + Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); + if (subDeviceCount == 0) { + deviceHandles.resize(1, device->toHandle()); + } else { + deviceHandles.resize(subDeviceCount, nullptr); + Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); + } + pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); + } + + std::vector getMemoryHandles(uint32_t count) { + std::vector handles(count, nullptr); + EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); + return handles; + } + + MockMemoryManagerSysman *pMemoryManager = nullptr; + MemoryManager *pMemoryManagerOld; +}; + +TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingMemoryPropertiesWhileCallingGetValErrorThenValidMemoryPropertiesRetrieved) { + pSysfsAccess->mockReadStringValue.push_back("0"); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); + + pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); + for (auto deviceHandle : deviceHandles) { + zes_mem_properties_t properties = {}; + ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; + Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); + bool isSubDevice = deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE; + LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, isSubDevice, deviceProperties.subdeviceId); + EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); + EXPECT_EQ(properties.subdeviceId, deviceProperties.subdeviceId); + EXPECT_EQ(properties.onSubdevice, isSubDevice); + EXPECT_EQ(properties.physicalSize, 0u); + delete pLinuxMemoryImp; + } +} + +TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { + pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize.data()); + pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); + pSysfsAccess->isRepeated = true; + + setLocalSupportedAndReinit(true); + std::vector devicesProperties; + for (auto deviceHandle : deviceHandles) { + ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; + Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); + devicesProperties.push_back(deviceProperties); + } + uint32_t count = 0; + EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); + EXPECT_EQ(count, deviceHandles.size()); + + std::vector handles(count, nullptr); + EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); + uint32_t subDeviceIndex = 0; + for (auto handle : handles) { + zes_mem_properties_t properties = {}; + EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS); + EXPECT_EQ(properties.subdeviceId, devicesProperties[subDeviceIndex].subdeviceId); + EXPECT_TRUE(properties.onSubdevice); + EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.data(), nullptr, 16)); + subDeviceIndex++; + } +} + +HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(subDeviceCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + } + 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, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { + setLocalSupportedAndReinit(true); + + auto handles = getMemoryHandles(subDeviceCount); + + for (auto handle : handles) { + ASSERT_NE(nullptr, handle); + } + 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 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp deleted file mode 100644 index 3eff2aeae0..0000000000 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (C) 2021-2023 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "level_zero/tools/source/sysman/sysman_imp.h" -#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h" - -#include "mock_memory.h" - -extern bool sysmanUltsEnable; - -namespace L0 { -namespace ult { - -constexpr uint32_t memoryHandleComponentCount = 1u; -class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { - protected: - MockMemoryNeoDrm *pDrm = nullptr; - Drm *pOriginalDrm = nullptr; - - void SetUp() override { - if (!sysmanUltsEnable) { - GTEST_SKIP(); - } - SysmanDeviceFixture::SetUp(); - - pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); - pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); - pMemoryManager->localMemorySupported[0] = false; - device->getDriverHandle()->setMemoryManager(pMemoryManager); - - pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); - - pSysmanDevice = device->getSysmanHandle(); - pSysmanDeviceImp = static_cast(pSysmanDevice); - pOsSysman = pSysmanDeviceImp->pOsSysman; - pLinuxSysmanImp = static_cast(pOsSysman); - pLinuxSysmanImp->pDrm = pDrm; - - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - uint32_t subDeviceCount = 0; - std::vector deviceHandles; - // We received a device handle. Check for subdevices in this device - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); - if (subDeviceCount == 0) { - deviceHandles.resize(1, device->toHandle()); - } else { - deviceHandles.resize(subDeviceCount, nullptr); - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); - } - getMemoryHandles(0); - } - - void TearDown() override { - if (!sysmanUltsEnable) { - GTEST_SKIP(); - } - device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); - pLinuxSysmanImp->pDrm = pOriginalDrm; - if (pDrm != nullptr) { - delete pDrm; - pDrm = nullptr; - } - if (pMemoryManager != nullptr) { - delete pMemoryManager; - pMemoryManager = nullptr; - } - SysmanDeviceFixture::TearDown(); - } - - void setLocalSupportedAndReinit(bool supported) { - pMemoryManager->localMemorySupported[0] = supported; - - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - uint32_t subDeviceCount = 0; - std::vector deviceHandles; - // We received a device handle. Check for subdevices in this device - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); - if (subDeviceCount == 0) { - deviceHandles.resize(1, device->toHandle()); - } else { - deviceHandles.resize(subDeviceCount, nullptr); - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); - } - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); - } - - std::vector getMemoryHandles(uint32_t count) { - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - return handles; - } - - MockMemoryManagerSysman *pMemoryManager = nullptr; - MemoryManager *pMemoryManagerOld; -}; - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); - - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); - - 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) { - setLocalSupportedAndReinit(true); - - 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, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidHandlesIsReturned) { - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingPropertiesWithLocalMemoryThenCallSucceeds) { - setLocalSupportedAndReinit(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_FALSE(properties.onSubdevice); - EXPECT_EQ(properties.subdeviceId, 0u); - EXPECT_EQ(properties.physicalSize, 0u); - EXPECT_EQ(properties.numChannels, -1); - EXPECT_EQ(properties.busWidth, -1); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingStateThenCallSucceeds) { - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - 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, probedSizeRegionOne); - EXPECT_EQ(state.free, unallocatedSizeRegionOne); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleAndIfQueryMemoryInfoFailsWhenGettingStateThenErrorIsReturned) { - setLocalSupportedAndReinit(true); - pDrm->mockQueryMemoryInfoReturnStatus.push_back(false); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - zes_mem_state_t state; - EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleAndIfQueryMemoryInfoAndIfMemoryInfoIsNotCorrectWhenGettingStateThenErrorIsReturned) { - setLocalSupportedAndReinit(true); - pDrm->mockQueryMemoryInfoReturnStatus.push_back(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - zes_mem_state_t state; - EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingBandwidthThenZeResultErrorUnsupportedFeatureIsReturned) { - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - zes_mem_bandwidth_t bandwidth; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -TEST_F(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { - zes_mem_properties_t properties = {}; - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - ze_bool_t isSubDevice = deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE; - Device::fromHandle(device)->getProperties(&deviceProperties); - std::unique_ptr pLinuxMemoryImp = std::make_unique(pOsSysman, isSubDevice, deviceProperties.subdeviceId); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); - EXPECT_EQ(properties.subdeviceId, deviceProperties.subdeviceId); - EXPECT_EQ(properties.onSubdevice, isSubDevice); -} - -} // namespace ult -} // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_prelim.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_prelim.cpp deleted file mode 100644 index a8498fec04..0000000000 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_prelim.cpp +++ /dev/null @@ -1,1240 +0,0 @@ -/* - * Copyright (C) 2021-2025 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 "level_zero/tools/source/sysman/linux/pmt/pmt_xml_offsets.h" -#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h" -#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h" - -#include "mock_memory_prelim.h" - -extern bool sysmanUltsEnable; - -namespace L0 { -namespace ult { - -constexpr int32_t memoryBusWidth = 128; // bus width in bytes -constexpr int32_t numMemoryChannels = 8; -constexpr uint32_t memoryHandleComponentCount = 1u; - -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 { - public: - MockMemoryNeoDrm *pDrm = nullptr; - - protected: - std::unique_ptr pSysfsAccess; - std::unique_ptr pFsAccess; - SysfsAccess *pSysfsAccessOld = nullptr; - FsAccess *pFsAccessOriginal = nullptr; - Drm *pOriginalDrm = nullptr; - std::vector deviceHandles; - PRODUCT_FAMILY productFamily; - uint16_t stepping; - std::map pmtMapOriginal; - - void SetUp() override { - if (!sysmanUltsEnable) { - GTEST_SKIP(); - } - SysmanDeviceFixture::SetUp(); - - pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; - pSysfsAccess = std::make_unique(); - pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); - - pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); - pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); - pMemoryManager->localMemorySupported[0] = false; - device->getDriverHandle()->setMemoryManager(pMemoryManager); - - pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); - - pSysmanDevice = device->getSysmanHandle(); - pSysmanDeviceImp = static_cast(pSysmanDevice); - pOsSysman = pSysmanDeviceImp->pOsSysman; - pLinuxSysmanImp = static_cast(pOsSysman); - pLinuxSysmanImp->pDrm = pDrm; - pFsAccess = std::make_unique(); - pFsAccessOriginal = pLinuxSysmanImp->pFsAccess; - pLinuxSysmanImp->pFsAccess = pFsAccess.get(); - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2e); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); - - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - uint32_t subDeviceCount = 0; - // We received a device handle. Check for subdevices in this device - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); - if (subDeviceCount == 0) { - deviceHandles.resize(1, device->toHandle()); - } else { - deviceHandles.resize(subDeviceCount, nullptr); - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); - } - pmtMapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject; - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); - for (auto &deviceHandle : deviceHandles) { - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - auto pPmt = new MockMemoryPmt(pFsAccess.get(), deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, - deviceProperties.subdeviceId); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); - } - auto &hwInfo = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getHardwareInfo(); - productFamily = hwInfo.platform.eProductFamily; - auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); - stepping = productHelper.getSteppingFromHwRevId(hwInfo); - getMemoryHandles(0); - } - - void TearDown() override { - if (!sysmanUltsEnable) { - GTEST_SKIP(); - } - pLinuxSysmanImp->releasePmtObject(); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = pmtMapOriginal; - device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); - pLinuxSysmanImp->pFsAccess = pFsAccessOriginal; - pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; - pLinuxSysmanImp->pDrm = pOriginalDrm; - if (pDrm != nullptr) { - delete pDrm; - pDrm = nullptr; - } - if (pMemoryManager != nullptr) { - delete pMemoryManager; - pMemoryManager = nullptr; - } - SysmanDeviceFixture::TearDown(); - } - - void setLocalSupportedAndReinit(bool supported) { - pMemoryManager->localMemorySupported[0] = supported; - - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - uint32_t subDeviceCount = 0; - std::vector deviceHandles; - // We received a device handle. Check for subdevices in this device - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); - if (subDeviceCount == 0) { - deviceHandles.resize(1, device->toHandle()); - } else { - deviceHandles.resize(subDeviceCount, nullptr); - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); - } - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); - } - - std::vector getMemoryHandles(uint32_t count) { - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - return handles; - } - - MockMemoryManagerSysman *pMemoryManager = nullptr; - MemoryManager *pMemoryManagerOld; -}; - -TEST_F(SysmanDeviceMemoryFixture, GivenWhenGettingMemoryPropertiesThenSuccessIsReturned) { - zes_mem_properties_t properties = {}; - auto pLinuxMemoryImp = std::make_unique(pOsSysman, true, 0); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); - - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, memoryHandleComponentCount); -} - -TEST_F(SysmanDeviceMemoryFixture, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) { - setLocalSupportedAndReinit(true); - - 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) { - setLocalSupportedAndReinit(true); - - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesAndQuerySystemInfoFailsThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown) { - pDrm->mockQuerySystemInfoReturnValue.push_back(false); - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesAndQuerySystemInfoSucceedsButMemSysInfoIsNullThenVerifySysmanMemoryGetPropertiesCallReturnsMemoryTypeAsDdrAndNumberOfChannelsAsUnknown) { - pDrm->mockQuerySystemInfoReturnValue.push_back(true); - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2); - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLPDDR4LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr4); - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithLPDDR5LocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::lpddr5); - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetPropertiesWithDDRLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds) { - pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::gddr6); - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - 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, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - setLocalSupportedAndReinit(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_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - setLocalSupportedAndReinit(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_SUCCESS); - EXPECT_EQ(state.health, ZES_MEM_HEALTH_UNKNOWN); - EXPECT_EQ(state.size, NEO::probedSizeRegionOne); - EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) { - setLocalSupportedAndReinit(true); - - 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) { - setLocalSupportedAndReinit(true); - - 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, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - pMemoryManager->localMemorySupported[0] = true; - - pLinuxSysmanImp->releaseSysmanDeviceResources(); - pLinuxSysmanImp->pDrm = pDrm; - pLinuxSysmanImp->reInitSysmanDeviceResources(); - - VariableBackup> pmtBackup(&pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); - for (auto &deviceHandle : deviceHandles) { - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - auto pPmt = new MockMemoryPmt(pFsAccess.get(), deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, - deviceProperties.subdeviceId); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); - } - - 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, GivenSysmanResourcesAreReleasedAndReInitializedWhenCallingZesSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - pMemoryManager->localMemorySupported[0] = true; - - pLinuxSysmanImp->releaseSysmanDeviceResources(); - pLinuxSysmanImp->pDrm = pDrm; - pLinuxSysmanImp->reInitSysmanDeviceResources(); - - VariableBackup> pmtBackup(&pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear(); - for (auto &deviceHandle : deviceHandles) { - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - auto pPmt = new MockMemoryPmt(pFsAccess.get(), deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE, - deviceProperties.subdeviceId); - pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, pPmt); - } - - 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; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenPmtObjectIsNullThenFailureRetuned) { - for (auto &subDeviceIdToPmtEntry : pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject) { - if (subDeviceIdToPmtEntry.second != nullptr) { - delete subDeviceIdToPmtEntry.second; - subDeviceIdToPmtEntry.second = nullptr; - } - } - setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); - for (auto &handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_bandwidth_t bandwidth; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - ASSERT_NE(nullptr, handle); - 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 = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockVfid0Status = true; - pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - - 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, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthWhenVFID1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - ASSERT_NE(nullptr, handle); - 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 = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockVfid1Status = true; - pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - - 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, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_READ_LFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); - 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); // Return success after reading VF0_VFID - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID - pPmt->mockReadArgumentValue.push_back(2); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_VFIDFailsForOldGuidThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); - 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("0xb15a0edd"); - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF1_VFIDFailsForOldGuidThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); - 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("0xb15a0edd"); - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_READ_HFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); - 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); // Return success after reading VF0_VFID - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID - pPmt->mockReadArgumentValue.push_back(4); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(2); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_WRITE_LFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); - 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(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(4); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(4); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(2); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthAndVF0_HBM_WRITE_HFailsThenFailureIsReturned, IsPVC) { - setLocalSupportedAndReinit(true); - 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); // Return success after reading VF0_VFID - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID - pPmt->mockReadArgumentValue.push_back(4); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(4); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(4); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); - pPmt->mockReadArgumentValue.push_back(2); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidUsRevIdForRevisionBWhenCallingzesSysmanMemoryGetBandwidthThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) { - setLocalSupportedAndReinit(true); - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (auto &handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_bandwidth_t bandwidth{}; - zes_mem_properties_t properties = {ZES_STRUCTURE_TYPE_MEM_PROPERTIES}; - zesMemoryGetProperties(handle, &properties); - - auto hwInfo = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); - auto &productHelper = pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getProductHelper(); - hwInfo->platform.usRevId = productHelper.getHwRevIdFromStepping(REVISION_B, *hwInfo); - auto pPmt = static_cast(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId)); - pPmt->setGuid(guid64BitMemoryCounters); - pPmt->mockVfid1Status = true; - pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - uint64_t expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4; - EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformThenSuccessIsReturnedAndBandwidthIsValid) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_DG2; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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; - uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0; - uint64_t mockMaxBwDg2 = 1343616u; - pSysfsAccess->mockReadUInt64Value.push_back(mockMaxBwDg2); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - 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); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForUnknownPlatformThenFailureIsReturned) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_UNKNOWN; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - auto handles = getMemoryHandles(memoryHandleComponentCount); - - for (const auto &handle : handles) { - ASSERT_NE(nullptr, handle); - zes_mem_bandwidth_t bandwidth; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiReadFailsTheFailureIsReturned) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_DG2; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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->mockIdiReadValueFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -HWTEST2_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformAndReadingMaxBwFailsThenMaxBwIsReturnedAsZero, IsDG2) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_DG2; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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; - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE); - - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_SUCCESS); - EXPECT_EQ(bandwidth.maxBandwidth, 0u); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfIdiWriteFailsTheFailureIsReturned) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_DG2; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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, GivenValidMemoryHandleWhenCallingzesSysmanMemoryGetBandwidthForDg2PlatformIfDisplayVc1ReadFailsTheFailureIsReturned) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_DG2; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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->mockDisplayVc1ReadFailureReturnStatus = ZE_RESULT_ERROR_UNKNOWN; - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCForSteppingIsBAndOnSubDeviceThenHbmFrequencyShouldNotBeZero) { - PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); - uint64_t hbmFrequency = 0; - pSysfsAccess->mockReadUInt64Value.push_back(hbmRP0Frequency); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_B, hbmFrequency); - EXPECT_EQ(hbmFrequency, hbmRP0Frequency * 1000 * 1000); - delete pLinuxMemoryImp; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCForSteppingA0ThenHbmFrequencyShouldBeNotZero) { - PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); - uint64_t hbmFrequency = 0; - pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_A0, hbmFrequency); - uint64_t expectedHbmFrequency = 3.2 * gigaUnitTransferToUnitTransfer; - EXPECT_EQ(hbmFrequency, expectedHbmFrequency); - delete pLinuxMemoryImp; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsUnsupportedThenHbmFrequencyShouldBeZero) { - PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); - uint64_t hbmFrequency = 0; - pLinuxMemoryImp->getHbmFrequency(PRODUCT_FAMILY_FORCE_ULONG, REVISION_B, hbmFrequency); - EXPECT_EQ(hbmFrequency, 0u); - delete pLinuxMemoryImp; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCWhenSteppingIsUnknownThenHbmFrequencyShouldBeZero) { - PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); - uint64_t hbmFrequency = 0; - pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, 255, hbmFrequency); - EXPECT_EQ(hbmFrequency, 0u); - delete pLinuxMemoryImp; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCForSteppingIsBAndFailedToReadFrequencyThenHbmFrequencyShouldBeZero) { - PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp(pOsSysman, true, 1); - uint64_t hbmFrequency = 0; - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); - pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_B, hbmFrequency); - EXPECT_EQ(hbmFrequency, 0u); - delete pLinuxMemoryImp; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreTrueThenErrorIsReturnedWhileGettingMemoryBandwidth) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_PVC; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF0_VFID - pPmt->mockReadArgumentValue.push_back(1); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenBothVfid0AndVfid1AreFalseThenErrorIsReturnedWhileGettingMemoryBandwidth) { - setLocalSupportedAndReinit(true); - auto hwInfo = *NEO::defaultHwInfo.get(); - hwInfo.platform.eProductFamily = IGFX_PVC; - pLinuxSysmanImp->getDeviceHandle()->getNEODevice()->getRootDeviceEnvironmentRef().setHwInfoAndInitHelpers(&hwInfo); - 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); // Return success after reading VF0_VFID - pPmt->mockReadArgumentValue.push_back(0); - pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS); // Return success after reading VF1_VFID - EXPECT_EQ(zesMemoryGetBandwidth(handle, &bandwidth), ZE_RESULT_ERROR_UNKNOWN); - } -} - -TEST_F(SysmanDeviceMemoryFixture, GivenCallinggetHbmFrequencyWhenProductFamilyIsPVCAndSteppingIsNotA0ThenHbmFrequencyWillBeZero) { - PublicLinuxMemoryImp *pLinuxMemoryImp = new PublicLinuxMemoryImp; - uint64_t hbmFrequency = 0; - pLinuxMemoryImp->getHbmFrequency(IGFX_PVC, REVISION_A1, hbmFrequency); - EXPECT_EQ(hbmFrequency, 0u); - delete pLinuxMemoryImp; -} - -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndFwUtilInterfaceIsAbsentThenMemoryHealthWillBeUnknown) { - setLocalSupportedAndReinit(true); - - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); - auto handles = getMemoryHandles(memoryHandleComponentCount); - - auto deviceImp = static_cast(pLinuxSysmanImp->getDeviceHandle()); - deviceImp->driverInfo.reset(nullptr); - 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); - } -} - -TEST_F(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { - zes_mem_properties_t properties = {}; - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - ze_bool_t isSubDevice = deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE; - Device::fromHandle(device)->getProperties(&deviceProperties); - LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, isSubDevice, deviceProperties.subdeviceId); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); - EXPECT_EQ(properties.subdeviceId, deviceProperties.subdeviceId); - EXPECT_EQ(properties.onSubdevice, isSubDevice); - delete pLinuxMemoryImp; -} - -class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { - protected: - std::unique_ptr pSysfsAccess; - SysfsAccess *pSysfsAccessOld = nullptr; - MockMemoryNeoDrm *pDrm = nullptr; - Drm *pOriginalDrm = nullptr; - std::vector deviceHandles; - uint32_t subDeviceCount = 0; - - void SetUp() override { - if (!sysmanUltsEnable) { - GTEST_SKIP(); - } - SysmanMultiDeviceFixture::SetUp(); - - pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess; - pSysfsAccess = std::make_unique(); - pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); - - pMemoryManagerOld = device->getDriverHandle()->getMemoryManager(); - pMemoryManager = new MockMemoryManagerSysman(*neoDevice->getExecutionEnvironment()); - pMemoryManager->localMemorySupported[0] = true; - device->getDriverHandle()->setMemoryManager(pMemoryManager); - - pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); - - pSysmanDevice = device->getSysmanHandle(); - pSysmanDeviceImp = static_cast(pSysmanDevice); - pOsSysman = pSysmanDeviceImp->pOsSysman; - pLinuxSysmanImp = static_cast(pOsSysman); - pLinuxSysmanImp->pDrm = pDrm; - - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - // We received a device handle. Check for subdevices in this device - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); - if (subDeviceCount == 0) { - deviceHandles.resize(1, device->toHandle()); - } else { - deviceHandles.resize(subDeviceCount, nullptr); - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); - } - getMemoryHandles(0); - } - - void TearDown() override { - if (!sysmanUltsEnable) { - GTEST_SKIP(); - } - device->getDriverHandle()->setMemoryManager(pMemoryManagerOld); - SysmanMultiDeviceFixture::TearDown(); - pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOld; - pLinuxSysmanImp->pDrm = pOriginalDrm; - if (pDrm != nullptr) { - delete pDrm; - pDrm = nullptr; - } - if (pMemoryManager != nullptr) { - delete pMemoryManager; - pMemoryManager = nullptr; - } - } - - void setLocalSupportedAndReinit(bool supported) { - pMemoryManager->localMemorySupported[0] = supported; - - pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); - uint32_t subDeviceCount = 0; - std::vector deviceHandles; - // We received a device handle. Check for subdevices in this device - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr); - if (subDeviceCount == 0) { - deviceHandles.resize(1, device->toHandle()); - } else { - deviceHandles.resize(subDeviceCount, nullptr); - Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); - } - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); - } - - std::vector getMemoryHandles(uint32_t count) { - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - return handles; - } - - MockMemoryManagerSysman *pMemoryManager = nullptr; - MemoryManager *pMemoryManagerOld; -}; - -TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenGettingMemoryPropertiesWhileCallingGetValErrorThenValidMemoryPropertiesRetrieved) { - pSysfsAccess->mockReadStringValue.push_back("0"); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE); - - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); - for (auto deviceHandle : deviceHandles) { - zes_mem_properties_t properties = {}; - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - bool isSubDevice = deviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE; - LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, isSubDevice, deviceProperties.subdeviceId); - EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties)); - EXPECT_EQ(properties.subdeviceId, deviceProperties.subdeviceId); - EXPECT_EQ(properties.onSubdevice, isSubDevice); - EXPECT_EQ(properties.physicalSize, 0u); - delete pLinuxMemoryImp; - } -} - -TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { - pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize); - pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS); - pSysfsAccess->isRepeated = true; - - setLocalSupportedAndReinit(true); - std::vector devicesProperties; - for (auto deviceHandle : deviceHandles) { - ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; - Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); - devicesProperties.push_back(deviceProperties); - } - uint32_t count = 0; - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); - EXPECT_EQ(count, deviceHandles.size()); - - std::vector handles(count, nullptr); - EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); - uint32_t subDeviceIndex = 0; - for (auto handle : handles) { - zes_mem_properties_t properties = {}; - EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS); - EXPECT_EQ(properties.subdeviceId, devicesProperties[subDeviceIndex].subdeviceId); - EXPECT_TRUE(properties.onSubdevice); - EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.c_str(), nullptr, 16)); - subDeviceIndex++; - } -} - -HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) { - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(subDeviceCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - } - 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, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) { - setLocalSupportedAndReinit(true); - - auto handles = getMemoryHandles(subDeviceCount); - - for (auto handle : handles) { - ASSERT_NE(nullptr, handle); - } - 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 L0