refactor: Merge Prelim and non-prelim files for memory

Related-To: NEO-11203

Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
Bellekallu Rajkiran
2024-05-20 13:04:51 +00:00
committed by Compute-Runtime-Automation
parent ce7f578548
commit 1ffc826808
12 changed files with 471 additions and 1763 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -11,7 +11,7 @@
#include "shared/source/utilities/directory.h"
#include "level_zero/sysman/source/api/events/sysman_events_imp.h"
#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h"
#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp.h"
#include "level_zero/sysman/source/driver/sysman_driver_handle_imp.h"
#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h"
#include "level_zero/sysman/source/shared/linux/zes_os_sysman_driver_imp.h"

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2020-2023 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -8,20 +8,7 @@ if(UNIX)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.cpp
)
if(NEO_ENABLE_i915_PRELIM_DETECTION)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp_prelim.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp_prelim.h
)
else()
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.h
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_memory_imp.cpp
)
endif()
endif()

View File

@@ -11,13 +11,14 @@
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/memory_manager/memory_banks.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/source/os_interface/linux/memory_info.h"
#include "shared/source/os_interface/linux/system_info.h"
#include "level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h"
#include "level_zero/sysman/source/shared/linux/pmt/sysman_pmt.h"
#include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h"
#include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h"
#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h"
namespace L0 {
namespace Sysman {
@@ -37,43 +38,51 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
}
ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
ze_result_t status = ZE_RESULT_SUCCESS;
pState->health = ZES_MEM_HEALTH_UNKNOWN;
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
if (pFwInterface != nullptr) {
pFwInterface->fwGetMemoryHealthIndicator(&pState->health);
}
// get memory health indicator if supported
auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper();
pSysmanProductHelper->getMemoryHealthIndicator(pFwInterface, &pState->health);
std::unique_ptr<NEO::MemoryInfo> memoryInfo;
{
auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceIdInstance();
memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo();
auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceIdInstance();
memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo();
if (!memoryInfo) {
pState->free = 0;
pState->size = 0;
status = ZE_RESULT_ERROR_UNKNOWN;
if (errno == ENODEV) {
status = ZE_RESULT_ERROR_DEVICE_LOST;
}
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
"Error@ %s():createMemoryInfo failed errno:%d \n", __FUNCTION__, errno);
return status;
}
auto region = memoryInfo->getMemoryRegion(MemoryBanks::getBankForLocalMemory(subdeviceId));
pState->free = region.unallocatedSize;
pState->size = region.probedSize;
return ZE_RESULT_SUCCESS;
return status;
}
LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pDevice = pLinuxSysmanImp->getSysmanDeviceImp();
pDrm = pLinuxSysmanImp->getDrm();
pDevice = pLinuxSysmanImp->getSysmanDeviceImp();
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId);
pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface();
}
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pLinuxMemoryImp;
}
bool LinuxMemoryImp::isMemoryModuleSupported() {
auto &gfxCoreHelper = pDevice->getRootDeviceEnvironment().getHelper<NEO::GfxCoreHelper>();
return gfxCoreHelper.getEnableLocalMemory(pDevice->getHardwareInfo());
}
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pLinuxMemoryImp;
}
} // namespace Sysman
} // namespace L0

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,10 +7,10 @@
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "level_zero/sysman/source/api/memory/sysman_os_memory.h"
#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h"
#include <string>
namespace NEO {
class Drm;
@@ -19,9 +19,10 @@ class Drm;
namespace L0 {
namespace Sysman {
class SysmanKmdInterface;
class PlatformMonitoringTech;
class LinuxSysmanImp;
class SysmanKmdInterface;
struct SysmanDeviceImp;
class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass {
public:
@@ -37,8 +38,8 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass {
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
NEO::Drm *pDrm = nullptr;
SysmanDeviceImp *pDevice = nullptr;
SysmanKmdInterface *pSysmanKmdInterface = nullptr;
PlatformMonitoringTech *pPmt = nullptr;
SysmanKmdInterface *pSysmanKmdInterface = nullptr;
private:
bool isSubdevice = false;

View File

@@ -1,96 +0,0 @@
/*
* Copyright (C) 2022-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/memory_manager/memory_banks.h"
#include "shared/source/os_interface/linux/i915.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/source/os_interface/linux/memory_info.h"
#include "shared/source/os_interface/linux/system_info.h"
#include "level_zero/sysman/source/shared/firmware_util/sysman_firmware_util.h"
#include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h"
#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h"
#include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h"
#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h"
#include "level_zero/sysman/source/sysman_const.h"
#include "igfxfmid.h"
namespace L0 {
namespace Sysman {
const std::string LinuxMemoryImp::deviceMemoryHealth("device_memory_health");
ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) {
auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper();
return pSysmanProductHelper->getMemoryProperties(pProperties, pLinuxSysmanImp, pDrm, pSysmanKmdInterface, subdeviceId, isSubdevice);
}
ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
if (pPmt == nullptr) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper();
return pSysmanProductHelper->getMemoryBandwidth(pBandwidth, pPmt, pDevice, pSysmanKmdInterface, subdeviceId);
}
ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
ze_result_t status = ZE_RESULT_SUCCESS;
pState->health = ZES_MEM_HEALTH_UNKNOWN;
FirmwareUtil *pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
// get memory health indicator if supported
auto pSysmanProductHelper = pLinuxSysmanImp->getSysmanProductHelper();
pSysmanProductHelper->getMemoryHealthIndicator(pFwInterface, &pState->health);
std::unique_ptr<NEO::MemoryInfo> memoryInfo;
{
auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceIdInstance();
memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo();
}
if (memoryInfo != nullptr) {
auto region = memoryInfo->getMemoryRegion(MemoryBanks::getBankForLocalMemory(subdeviceId));
pState->free = region.unallocatedSize;
pState->size = region.probedSize;
} else {
pState->free = 0;
pState->size = 0;
status = ZE_RESULT_ERROR_UNKNOWN;
if (errno == ENODEV) {
status = ZE_RESULT_ERROR_DEVICE_LOST;
}
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
"Error@ %s():createMemoryInfo failed errno:%d \n", __FUNCTION__, errno);
}
return status;
}
LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pDrm = pLinuxSysmanImp->getDrm();
pDevice = pLinuxSysmanImp->getSysmanDeviceImp();
pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId);
pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface();
}
bool LinuxMemoryImp::isMemoryModuleSupported() {
auto &gfxCoreHelper = pDevice->getRootDeviceEnvironment().getHelper<NEO::GfxCoreHelper>();
return gfxCoreHelper.getEnableLocalMemory(pDevice->getHardwareInfo());
}
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pLinuxMemoryImp;
}
} // namespace Sysman
} // namespace L0

View File

@@ -1,53 +0,0 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "level_zero/sysman/source/api/memory/sysman_os_memory.h"
#include "level_zero/sysman/source/device/sysman_device_imp.h"
#include "level_zero/sysman/source/shared/linux/pmt/sysman_pmt.h"
#include <map>
namespace L0 {
namespace Sysman {
class SysFsAccessInterface;
struct Device;
class PlatformMonitoringTech;
class LinuxSysmanImp;
class SysmanKmdInterface;
class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass {
public:
ze_result_t getProperties(zes_mem_properties_t *pProperties) override;
ze_result_t getBandwidth(zes_mem_bandwidth_t *pBandwidth) override;
ze_result_t getState(zes_mem_state_t *pState) override;
bool isMemoryModuleSupported() override;
LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
LinuxMemoryImp() = default;
~LinuxMemoryImp() override = default;
protected:
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
SysFsAccessInterface *pSysfsAccess = nullptr;
NEO::Drm *pDrm = nullptr;
SysmanDeviceImp *pDevice = nullptr;
PlatformMonitoringTech *pPmt = nullptr;
SysmanKmdInterface *pSysmanKmdInterface = nullptr;
private:
static const std::string deviceMemoryHealth;
bool isSubdevice = false;
uint32_t subdeviceId = 0;
std::string physicalSizeFile;
};
} // namespace Sysman
} // namespace L0

View File

@@ -1,26 +1,15 @@
#
# Copyright (C) 2020-2023 Intel Corporation
# Copyright (C) 2020-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(L0_TESTS_SYSMAN_MEMORY_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h
)
if(NEO_ENABLE_i915_PRELIM_DETECTION)
list(APPEND L0_TESTS_SYSMAN_MEMORY_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory_prelim.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_prelim.h
)
else()
list(APPEND L0_TESTS_SYSMAN_MEMORY_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_memory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory.h
)
endif()
if(UNIX)
target_sources(${TARGET_NAME}
PRIVATE

View File

@@ -20,6 +20,9 @@
using namespace NEO;
constexpr uint64_t hbmRP0Frequency = 4200;
constexpr uint64_t mockMaxBwDg2 = 1343616u;
constexpr uint32_t vF0HbmLRead = 16;
constexpr uint32_t vF0HbmHRead = 2;
constexpr uint32_t vF0HbmLWrite = 8;
@@ -60,10 +63,12 @@ namespace L0 {
namespace Sysman {
namespace ult {
uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e;
const std::string deviceMemoryHealth("device_memory_health");
struct MockMemoryNeoDrm : public NEO::Drm {
using Drm::ioctlHelper;
const int mockFd = 33;
uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e;
std::vector<bool> mockQuerySystemInfoReturnValue{};
bool isRepeated = false;
bool mockReturnEmptyRegions = false;
@@ -98,6 +103,7 @@ struct MockMemoryNeoDrm : public NEO::Drm {
return returnValue;
}
};
struct MockMemoryPmt : public L0::Sysman::PlatformMonitoringTech {
using L0::Sysman::PlatformMonitoringTech::guid;
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
@@ -297,10 +303,41 @@ class PublicLinuxMemoryImp : public L0::Sysman::LinuxMemoryImp {
using L0::Sysman::LinuxMemoryImp::pSysmanKmdInterface;
};
class MockSysFsAccessInterface : public L0::Sysman::SysFsAccessInterface {
class MockMemorySysmanKmdInterfaceXe : public L0::Sysman::SysmanKmdInterfaceXe {
public:
MockSysFsAccessInterface() = default;
~MockSysFsAccessInterface() override = default;
using L0::Sysman::SysmanKmdInterface::pProcfsAccess;
using L0::Sysman::SysmanKmdInterface::pSysfsAccess;
MockMemorySysmanKmdInterfaceXe(const PRODUCT_FAMILY productFamily) : SysmanKmdInterfaceXe(productFamily) {}
~MockMemorySysmanKmdInterfaceXe() override = default;
};
struct MockMemorySysFsAccessInterface : public L0::Sysman::SysFsAccessInterface {
std::vector<ze_result_t> mockReadReturnStatus{};
std::vector<std::string> mockReadStringValue{};
bool isRepeated = false;
ze_result_t read(const std::string file, std::string &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (!mockReadReturnStatus.empty()) {
result = mockReadReturnStatus.front();
if (!mockReadStringValue.empty()) {
val = mockReadStringValue.front();
}
if (isRepeated != true) {
mockReadReturnStatus.erase(mockReadReturnStatus.begin());
if (!mockReadStringValue.empty()) {
mockReadStringValue.erase(mockReadStringValue.begin());
}
}
return result;
}
if (file.compare(deviceMemoryHealth) == 0) {
val = "OK";
}
return result;
}
};
class MockProcFsAccessInterface : public L0::Sysman::ProcFsAccessInterface {
@@ -309,6 +346,13 @@ class MockProcFsAccessInterface : public L0::Sysman::ProcFsAccessInterface {
~MockProcFsAccessInterface() override = default;
};
class MockSysmanKmdInterfaceI915Prelim : public L0::Sysman::SysmanKmdInterfaceI915Prelim {
public:
using L0::Sysman::SysmanKmdInterface::pSysfsAccess;
MockSysmanKmdInterfaceI915Prelim(const PRODUCT_FAMILY productFamily) : SysmanKmdInterfaceI915Prelim(productFamily) {}
~MockSysmanKmdInterfaceI915Prelim() override = default;
};
} // namespace ult
} // namespace Sysman
} // namespace L0

View File

@@ -1,373 +0,0 @@
/*
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/linux/i915.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/source/os_interface/linux/memory_info.h"
#include "shared/source/os_interface/linux/system_info.h"
#include "level_zero/sysman/source/api/memory/linux/sysman_os_memory_imp_prelim.h"
#include "level_zero/sysman/source/api/memory/sysman_memory_imp.h"
#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h"
#include "level_zero/sysman/source/shared/linux/sysman_kmd_interface.h"
#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h"
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_hw_device_id.h"
using namespace NEO;
constexpr uint16_t vF0VfidIndex = 88;
constexpr uint16_t vF0Hbm0ReadIndex = 92;
constexpr uint16_t vF0Hbm0WriteIndex = 96;
constexpr uint16_t vF0Hbm1ReadIndex = 104;
constexpr uint16_t vF0Hbm1WriteIndex = 108;
constexpr uint16_t vF0TimestampLIndex = 168;
constexpr uint16_t vF0TimestampHIndex = 172;
constexpr uint16_t vF1VfidIndex = 176;
constexpr uint16_t vF1Hbm0ReadIndex = 180;
constexpr uint16_t vF1Hbm0WriteIndex = 184;
constexpr uint16_t vF1Hbm1ReadIndex = 192;
constexpr uint16_t vF1Hbm1WriteIndex = 196;
constexpr uint16_t vF1TimestampLIndex = 256;
constexpr uint16_t vF1TimestampHIndex = 260;
constexpr uint16_t vF0Hbm2ReadIndex = 312;
constexpr uint16_t vF0Hbm2WriteIndex = 316;
constexpr uint16_t vF0Hbm3ReadIndex = 328;
constexpr uint16_t vF0Hbm3WriteIndex = 332;
constexpr uint16_t vF1Hbm2ReadIndex = 344;
constexpr uint16_t vF1Hbm2WriteIndex = 348;
constexpr uint16_t vF1Hbm3ReadIndex = 360;
constexpr uint16_t vF1Hbm3WriteIndex = 364;
constexpr uint32_t vF0HbmLRead = 16;
constexpr uint32_t vF0HbmHRead = 2;
constexpr uint32_t vF0HbmLWrite = 8;
constexpr uint32_t vF0HbmHWrite = 2;
constexpr uint32_t vF1HbmLRead = 16;
constexpr uint32_t vF1HbmHRead = 2;
constexpr uint32_t vF1HbmLWrite = 8;
constexpr uint32_t vF1HbmHWrite = 2;
constexpr uint8_t vF0VfidValue = 1;
constexpr uint8_t vF0Hbm0ReadValue = 92;
constexpr uint8_t vF0Hbm0WriteValue = 96;
constexpr uint8_t vF0Hbm1ReadValue = 104;
constexpr uint8_t vF0Hbm1WriteValue = 108;
constexpr uint8_t vF0TimestampLValue = 168;
constexpr uint8_t vF0TimestampHValue = 172;
constexpr uint8_t vF1VfidValue = 0;
constexpr uint8_t vF0Hbm2ReadValue = 113;
constexpr uint8_t vF0Hbm2WriteValue = 125;
constexpr uint8_t vF0Hbm3ReadValue = 135;
constexpr uint8_t vF0Hbm3WriteValue = 20;
constexpr uint8_t vF1Hbm0ReadValue = 92;
constexpr uint8_t vF1Hbm0WriteValue = 96;
constexpr uint8_t vF1Hbm1ReadValue = 104;
constexpr uint8_t vF1Hbm1WriteValue = 108;
constexpr uint8_t vF1TimestampLValue = 168;
constexpr uint8_t vF1TimestampHValue = 172;
constexpr uint8_t vF1Hbm2ReadValue = 113;
constexpr uint8_t vF1Hbm2WriteValue = 125;
constexpr uint8_t vF1Hbm3ReadValue = 135;
constexpr uint8_t vF1Hbm3WriteValue = 20;
constexpr uint64_t mockIdiReadVal = 8u;
constexpr uint64_t mockIdiWriteVal = 9u;
constexpr uint64_t mockDisplayVc1ReadVal = 10u;
constexpr uint64_t numberMcChannels = 16;
constexpr uint64_t transactionSize = 32;
namespace L0 {
namespace Sysman {
namespace ult {
uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e;
const std::string deviceMemoryHealth("device_memory_health");
std::string gpuUpstreamPortPathInMemory = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0";
const std::string baseTelemSysFS("/sys/class/intel_pmt");
const std::string realPathTelem1 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1";
const std::string realPathTelem2 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem2";
const std::string realPathTelem3 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem3";
const std::string realPathTelem4 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem4";
const std::string realPathTelem5 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem5";
const std::string sysfsPahTelem1 = "/sys/class/intel_pmt/telem1";
const std::string sysfsPahTelem2 = "/sys/class/intel_pmt/telem2";
const std::string sysfsPahTelem3 = "/sys/class/intel_pmt/telem3";
const std::string sysfsPahTelem4 = "/sys/class/intel_pmt/telem4";
const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5";
struct MockMemorySysfsAccess : public L0::Sysman::SysFsAccessInterface {
std::vector<ze_result_t> mockReadReturnStatus{};
std::vector<std::string> mockReadStringValue{};
bool isRepeated = false;
ze_result_t read(const std::string file, std::string &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (!mockReadReturnStatus.empty()) {
result = mockReadReturnStatus.front();
if (!mockReadStringValue.empty()) {
val = mockReadStringValue.front();
}
if (isRepeated != true) {
mockReadReturnStatus.erase(mockReadReturnStatus.begin());
if (!mockReadStringValue.empty()) {
mockReadStringValue.erase(mockReadStringValue.begin());
}
}
return result;
}
if (file.compare(deviceMemoryHealth) == 0) {
val = "OK";
}
return result;
}
};
struct MockMemoryNeoDrm : public NEO::Drm {
using Drm::ioctlHelper;
const int mockFd = 33;
std::vector<bool> mockQuerySystemInfoReturnValue{};
bool isRepeated = false;
bool mockReturnEmptyRegions = false;
MockMemoryNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<MockSysmanHwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
void setMemoryType(uint32_t memory) {
mockMemoryType = memory;
}
std::vector<uint64_t> getMemoryRegionsReturnsEmpty() {
return {};
}
void resetSystemInfo() {
systemInfo.reset(nullptr);
}
bool querySystemInfo() override {
bool returnValue = true;
if (!mockQuerySystemInfoReturnValue.empty()) {
returnValue = mockQuerySystemInfoReturnValue.front();
if (isRepeated != true) {
mockQuerySystemInfoReturnValue.erase(mockQuerySystemInfoReturnValue.begin());
}
resetSystemInfo();
return returnValue;
}
uint32_t hwBlob[] = {NEO::DeviceBlobConstants::maxMemoryChannels, 1, 8, NEO::DeviceBlobConstants::memoryType, 0, mockMemoryType};
std::vector<uint32_t> inputBlobData(reinterpret_cast<uint32_t *>(hwBlob), reinterpret_cast<uint32_t *>(ptrOffset(hwBlob, sizeof(hwBlob))));
this->systemInfo.reset(new SystemInfo(inputBlobData));
return returnValue;
}
};
struct MockMemoryPmt : public L0::Sysman::PlatformMonitoringTech {
using L0::Sysman::PlatformMonitoringTech::guid;
using L0::Sysman::PlatformMonitoringTech::keyOffsetMap;
std::vector<ze_result_t> mockReadValueReturnStatus{};
std::vector<uint32_t> mockReadArgumentValue{};
ze_result_t mockIdiReadValueFailureReturnStatus = ZE_RESULT_SUCCESS;
ze_result_t mockIdiWriteFailureReturnStatus = ZE_RESULT_SUCCESS;
ze_result_t mockDisplayVc1ReadFailureReturnStatus = ZE_RESULT_SUCCESS;
ze_result_t mockReadTimeStampFailureReturnStatus = ZE_RESULT_SUCCESS;
bool mockVfid0Status = false;
bool mockVfid1Status = false;
bool isRepeated = false;
void setGuid(std::string guid) {
this->guid = guid;
}
MockMemoryPmt() = default;
ze_result_t readValue(const std::string key, uint32_t &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (mockVfid0Status == true) {
return mockedReadValueWithVfid0True(key, val);
}
if (mockVfid1Status == true) {
return mockedReadValueWithVfid1True(key, val);
}
if (!mockReadValueReturnStatus.empty()) {
result = mockReadValueReturnStatus.front();
if (!mockReadArgumentValue.empty()) {
val = mockReadArgumentValue.front();
}
if (isRepeated != true) {
mockReadValueReturnStatus.erase(mockReadValueReturnStatus.begin());
if (!mockReadArgumentValue.empty()) {
mockReadArgumentValue.erase(mockReadArgumentValue.begin());
}
}
}
return result;
}
ze_result_t mockedReadValueWithVfid0True(const std::string key, uint32_t &val) {
if (key.compare("VF0_VFID") == 0) {
val = 1;
} else if (key.compare("VF1_VFID") == 0) {
val = 0;
} else if (key.compare("VF0_HBM0_READ") == 0) {
val = vF0Hbm0ReadValue;
} else if (key.compare("VF0_HBM0_WRITE") == 0) {
val = vF0Hbm0WriteValue;
} else if (key.compare("VF0_HBM1_READ") == 0) {
val = vF0Hbm1ReadValue;
} else if (key.compare("VF0_HBM1_WRITE") == 0) {
val = vF0Hbm1WriteValue;
} else if (key.compare("VF0_TIMESTAMP_L") == 0) {
val = vF0TimestampLValue;
} else if (key.compare("VF0_TIMESTAMP_H") == 0) {
val = vF0TimestampHValue;
} else if (key.compare("VF0_HBM2_READ") == 0) {
val = vF0Hbm2ReadValue;
} else if (key.compare("VF0_HBM2_WRITE") == 0) {
val = vF0Hbm2WriteValue;
} else if (key.compare("VF0_HBM3_READ") == 0) {
val = vF0Hbm3ReadValue;
} else if (key.compare("VF0_HBM3_WRITE") == 0) {
val = vF0Hbm3WriteValue;
} else if (key.compare("VF0_HBM_READ_L") == 0) {
val = vF0HbmLRead;
} else if (key.compare("VF0_HBM_READ_H") == 0) {
val = vF0HbmHRead;
} else if (key.compare("VF0_HBM_WRITE_L") == 0) {
val = vF0HbmLWrite;
} else if (key.compare("VF0_HBM_WRITE_H") == 0) {
val = vF0HbmHWrite;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t mockedReadValueWithVfid1True(const std::string key, uint32_t &val) {
if (key.compare("VF0_VFID") == 0) {
val = 0;
} else if (key.compare("VF1_VFID") == 0) {
val = 1;
} else if (key.compare("VF1_HBM0_READ") == 0) {
val = vF1Hbm0ReadValue;
} else if (key.compare("VF1_HBM0_WRITE") == 0) {
val = vF1Hbm0WriteValue;
} else if (key.compare("VF1_HBM1_READ") == 0) {
val = vF1Hbm1ReadValue;
} else if (key.compare("VF1_HBM1_WRITE") == 0) {
val = vF1Hbm1WriteValue;
} else if (key.compare("VF1_TIMESTAMP_L") == 0) {
val = vF1TimestampLValue;
} else if (key.compare("VF1_TIMESTAMP_H") == 0) {
val = vF1TimestampHValue;
} else if (key.compare("VF1_HBM2_READ") == 0) {
val = vF1Hbm2ReadValue;
} else if (key.compare("VF1_HBM2_WRITE") == 0) {
val = vF1Hbm2WriteValue;
} else if (key.compare("VF1_HBM3_READ") == 0) {
val = vF1Hbm3ReadValue;
} else if (key.compare("VF1_HBM3_WRITE") == 0) {
val = vF1Hbm3WriteValue;
} else if (key.compare("VF1_HBM_READ_L") == 0) {
val = vF1HbmLRead;
} else if (key.compare("VF1_HBM_READ_H") == 0) {
val = vF1HbmHRead;
} else if (key.compare("VF1_HBM_WRITE_L") == 0) {
val = vF1HbmLWrite;
} else if (key.compare("VF1_HBM_WRITE_H") == 0) {
val = vF1HbmHWrite;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t readValue(const std::string key, uint64_t &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (mockIdiReadValueFailureReturnStatus != ZE_RESULT_SUCCESS) {
return mockIdiReadValueFailure(key, val);
}
if (mockIdiWriteFailureReturnStatus != ZE_RESULT_SUCCESS) {
return mockIdiWriteFailure(key, val);
}
if (mockDisplayVc1ReadFailureReturnStatus != ZE_RESULT_SUCCESS) {
return mockDisplayVc1ReadFailure(key, val);
}
if (mockReadTimeStampFailureReturnStatus != ZE_RESULT_SUCCESS) {
return mockReadTimeStampFailure(key, val);
}
if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) {
val = mockIdiReadVal;
} else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) {
val = mockIdiWriteVal;
} else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) {
val = mockDisplayVc1ReadVal;
} else {
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return result;
}
ze_result_t mockIdiReadValueFailure(const std::string key, uint64_t &val) {
return ZE_RESULT_ERROR_UNKNOWN;
}
ze_result_t mockIdiWriteFailure(const std::string key, uint64_t &val) {
if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) {
val = mockIdiReadVal;
} else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t mockDisplayVc1ReadFailure(const std::string key, uint64_t &val) {
if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) {
val = mockIdiReadVal;
} else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) {
val = mockIdiWriteVal;
} else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t mockReadTimeStampFailure(const std::string key, uint64_t &val) {
if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) {
val = mockIdiReadVal;
} else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) {
val = mockIdiWriteVal;
} else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) {
val = mockDisplayVc1ReadVal;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
};
class MockSysmanKmdInterfaceI915Prelim : public L0::Sysman::SysmanKmdInterfaceI915Prelim {
public:
using L0::Sysman::SysmanKmdInterface::pSysfsAccess;
MockSysmanKmdInterfaceI915Prelim(const PRODUCT_FAMILY productFamily) : SysmanKmdInterfaceI915Prelim(productFamily) {}
~MockSysmanKmdInterfaceI915Prelim() override = default;
};
} // namespace ult
} // namespace Sysman
} // namespace L0

View File

@@ -20,8 +20,23 @@ namespace Sysman {
namespace ult {
static const uint32_t memoryHandleComponentCount = 1u;
static uint64_t hbmRP0Frequency = 4200;
static uint64_t mockMaxBwDg2 = 1343616u;
static const std::string mockPhysicalSize = "0x00000040000000";
class SysmanMemoryMockIoctlHelper : public NEO::MockIoctlHelper {
public:
using NEO::MockIoctlHelper::MockIoctlHelper;
bool returnEmptyMemoryInfo = false;
int32_t mockErrorNumber = 0;
std::unique_ptr<MemoryInfo> createMemoryInfo() override {
if (returnEmptyMemoryInfo) {
errno = mockErrorNumber;
return {};
}
return NEO::MockIoctlHelper::createMemoryInfo();
}
};
class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
protected:
@@ -56,7 +71,7 @@ class SysmanDeviceMemoryFixtureI915 : public SysmanDeviceMemoryFixture {
auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface;
osInterface->setDriverModel(std::unique_ptr<MockMemoryNeoDrm>(pDrm));
pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2e);
pDrm->ioctlHelper = static_cast<std::unique_ptr<NEO::IoctlHelper>>(std::make_unique<NEO::MockIoctlHelper>(*pDrm));
pDrm->ioctlHelper = static_cast<std::unique_ptr<NEO::IoctlHelper>>(std::make_unique<SysmanMemoryMockIoctlHelper>(*pDrm));
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
auto subdeviceId = 0u;
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
@@ -78,14 +93,14 @@ TEST_F(SysmanDeviceMemoryFixtureI915, GivenI915DriverVersionWhenValidCallingSysf
EXPECT_STREQ("gt/gt0/mem_RPn_freq_mhz", pSysmanKmdInterface->getSysfsFilePath(SysfsName::sysfsNameMinMemoryFrequency, 0, true).c_str());
}
TEST_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) {
TEST_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) {
setLocalSupportedAndReinit(false);
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, 0u);
}
TEST_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithLocalMemorySupportThenValidCountIsReturned) {
TEST_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenZeroCountIsReturned) {
setLocalSupportedAndReinit(false);
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
@@ -96,13 +111,13 @@ TEST_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingM
EXPECT_EQ(count, 0u);
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsPVC) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsPVC) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, memoryHandleComponentCount);
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsPVC) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsPVC) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, memoryHandleComponentCount);
@@ -112,13 +127,13 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenInvalidComponentCountWhenEnumerati
EXPECT_EQ(count, memoryHandleComponentCount);
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsDG1) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsDG1) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, memoryHandleComponentCount);
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesWithNoLocalMemorySupportThenValidCountIsReturned, IsDG2) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenComponentCountZeroWhenEnumeratingMemoryModulesThenValidCountIsReturned, IsDG2) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, memoryHandleComponentCount);
@@ -186,7 +201,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem
}
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithHBMLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetPropertiesWithHbmLocalMemoryThenVerifySysmanMemoryGetPropertiesCallSucceeds, IsPVC) {
pDrm->setMemoryType(NEO::DeviceBlobConstants::MemoryType::hbm2);
auto handles = getMemoryHandles(memoryHandleComponentCount);
for (auto handle : handles) {
@@ -254,7 +269,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem
}
}
TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceeds) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceeds, IsPVC) {
auto pLinuxMemoryImp = std::make_unique<PublicLinuxMemoryImp>(pOsSysman, true, 0);
zes_mem_state_t state;
ze_result_t result = pLinuxMemoryImp->getState(&state);
@@ -323,7 +338,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem
}
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVfid0IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::ostringstream oStream;
oStream << hbmRP0Frequency;
@@ -363,7 +378,7 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMem
}
}
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVFID1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) {
HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesMemoryGetBandwidthWhenVfid1IsActiveThenSuccessIsReturnedAndBandwidthIsValid, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::ostringstream oStream;
oStream << hbmRP0Frequency;
@@ -474,18 +489,53 @@ HWTEST2_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSys
}
}
TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndIoctlReturnedErrorThenApiReturnsError) {
auto ioctlHelper = static_cast<SysmanMemoryMockIoctlHelper *>(pDrm->ioctlHelper.get());
ioctlHelper->returnEmptyMemoryInfo = true;
ioctlHelper->mockErrorNumber = EBUSY;
auto handles = getMemoryHandles(memoryHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_mem_state_t state;
ze_result_t result = zesMemoryGetState(handle, &state);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
EXPECT_EQ(state.size, 0u);
EXPECT_EQ(state.free, 0u);
}
}
TEST_F(SysmanDeviceMemoryFixtureI915, GivenValidMemoryHandleWhenCallingZesSysmanMemoryGetStateAndDeviceIsNotAvailableThenDeviceLostErrorIsReturned) {
auto ioctlHelper = static_cast<SysmanMemoryMockIoctlHelper *>(pDrm->ioctlHelper.get());
ioctlHelper->returnEmptyMemoryInfo = true;
ioctlHelper->mockErrorNumber = ENODEV;
auto handles = getMemoryHandles(memoryHandleComponentCount);
for (auto handle : handles) {
ASSERT_NE(nullptr, handle);
zes_mem_state_t state;
ze_result_t result = zesMemoryGetState(handle, &state);
EXPECT_EQ(result, ZE_RESULT_ERROR_DEVICE_LOST);
EXPECT_EQ(state.size, 0u);
EXPECT_EQ(state.free, 0u);
errno = 0;
}
}
class SysmanDeviceMemoryFixtureXe : public SysmanDeviceMemoryFixture {
protected:
DebugManagerStateRestore restorer;
MockMemoryNeoDrm *pDrm = nullptr;
MockSysmanKmdInterfaceXe *pSysmanKmdInterface = nullptr;
MockMemorySysmanKmdInterfaceXe *pSysmanKmdInterface = nullptr;
void SetUp() override {
debugManager.flags.EnableLocalMemory.set(1);
SysmanDeviceFixture::SetUp();
pSysmanKmdInterface = new MockSysmanKmdInterfaceXe(pLinuxSysmanImp->getProductFamily());
pSysmanKmdInterface = new MockMemorySysmanKmdInterfaceXe(pLinuxSysmanImp->getProductFamily());
pSysmanKmdInterface->pProcfsAccess = std::make_unique<MockProcFsAccessInterface>();
pSysmanKmdInterface->pSysfsAccess = std::make_unique<MockSysFsAccessInterface>();
pSysmanKmdInterface->pSysfsAccess = std::make_unique<MockMemorySysFsAccessInterface>();
device = pSysmanDeviceImp;
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
@@ -547,6 +597,94 @@ HWTEST2_F(SysmanDeviceMemoryFixtureXe, GivenValidMemoryHandleWhenCallingZesMemor
}
}
class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture {
protected:
MockMemoryNeoDrm *pDrm = nullptr;
L0::Sysman::SysmanDevice *device = nullptr;
MockMemorySysFsAccessInterface *pSysfsAccess = nullptr;
MockSysmanKmdInterfaceI915Prelim *pSysmanKmdInterface = nullptr;
void SetUp() override {
debugManager.flags.EnableLocalMemory.set(1);
SysmanMultiDeviceFixture::SetUp();
pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily());
pSysfsAccess = new MockMemorySysFsAccessInterface();
pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess);
pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface);
pLinuxSysmanImp->pSysfsAccess = pLinuxSysmanImp->pSysmanKmdInterface->getSysFsAccess();
pDrm = new MockMemoryNeoDrm(const_cast<NEO::RootDeviceEnvironment &>(pSysmanDeviceImp->getRootDeviceEnvironment()));
pDrm->ioctlHelper = static_cast<std::unique_ptr<NEO::IoctlHelper>>(std::make_unique<NEO::MockIoctlHelper>(*pDrm));
auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface;
osInterface->setDriverModel(std::unique_ptr<MockMemoryNeoDrm>(pDrm));
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
device = pSysmanDeviceImp;
}
void TearDown() override {
SysmanMultiDeviceFixture::TearDown();
}
std::vector<zes_mem_handle_t> getMemoryHandles(uint32_t count) {
std::vector<zes_mem_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
return handles;
}
};
HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved, IsPVC) {
pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize);
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->isRepeated = true;
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, std::max(pOsSysman->getSubDeviceCount(), 1u));
std::vector<zes_mem_handle_t> handles(count, nullptr);
EXPECT_EQ(zesDeviceEnumMemoryModules(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS);
for (auto handle : handles) {
zes_mem_properties_t properties = {};
EXPECT_EQ(zesMemoryGetProperties(handle, &properties), ZE_RESULT_SUCCESS);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.c_str(), nullptr, 16));
}
}
HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsOK, IsPVC) {
auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount());
zes_mem_state_t state1;
ze_result_t result = zesMemoryGetState(handles[0], &state1);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(state1.health, ZES_MEM_HEALTH_OK);
EXPECT_EQ(state1.size, NEO::probedSizeRegionOne);
EXPECT_EQ(state1.free, NEO::unallocatedSizeRegionOne);
zes_mem_state_t state2;
result = zesMemoryGetState(handles[1], &state2);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(state2.health, ZES_MEM_HEALTH_OK);
EXPECT_EQ(state2.size, NEO::probedSizeRegionFour);
EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour);
}
HWTEST2_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesMemoryGetStateThenVerifySysmanMemoryGetStateCallSucceedsAndHealthIsUnknown, IsNotPVC) {
auto handles = getMemoryHandles(pOsSysman->getSubDeviceCount());
zes_mem_state_t state1;
ze_result_t result = zesMemoryGetState(handles[0], &state1);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(state1.health, ZES_MEM_HEALTH_UNKNOWN);
EXPECT_EQ(state1.size, NEO::probedSizeRegionOne);
EXPECT_EQ(state1.free, NEO::unallocatedSizeRegionOne);
zes_mem_state_t state2;
result = zesMemoryGetState(handles[1], &state2);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(state2.health, ZES_MEM_HEALTH_UNKNOWN);
EXPECT_EQ(state2.size, NEO::probedSizeRegionFour);
EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour);
}
} // namespace ult
} // namespace Sysman
} // namespace L0

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Intel Corporation
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -14,129 +14,19 @@
#include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h"
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_fixture.h"
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_hw_device_id.h"
#include "level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory.h"
namespace L0 {
namespace Sysman {
namespace ult {
static const uint64_t hbmRP0Frequency = 4200;
static const uint64_t mockMaxBwDg2 = 1343616u;
static uint32_t mockMemoryType = NEO::DeviceBlobConstants::MemoryType::hbm2e;
static const uint32_t vF0HbmLRead = 16;
static const uint32_t vF0HbmHRead = 2;
static const uint32_t vF0HbmLWrite = 8;
static const uint32_t vF0HbmHWrite = 2;
static const uint8_t vF0Hbm0ReadValue = 92;
static const uint8_t vF0Hbm0WriteValue = 96;
static const uint8_t vF0Hbm1ReadValue = 104;
static const uint8_t vF0Hbm1WriteValue = 108;
static const uint8_t vF0TimestampLValue = 168;
static const uint8_t vF0TimestampHValue = 172;
static const uint8_t vF0Hbm2ReadValue = 113;
static const uint8_t vF0Hbm2WriteValue = 125;
static const uint8_t vF0Hbm3ReadValue = 135;
static const uint8_t vF0Hbm3WriteValue = 20;
static const uint64_t mockIdiReadVal = 8u;
static const uint64_t mockIdiWriteVal = 9u;
static const uint64_t mockDisplayVc1ReadVal = 10u;
static const uint64_t numberMcChannels = 16;
static const uint64_t transactionSize = 32;
class MockDrm : public NEO::Drm {
public:
MockDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<MockSysmanHwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
void resetSystemInfo() {
systemInfo.reset(nullptr);
}
void setMemoryType(uint32_t memory) {
mockMemoryType = memory;
}
bool querySystemInfo() override {
bool returnValue = true;
uint32_t hwBlob[] = {NEO::DeviceBlobConstants::maxMemoryChannels, 1, 8, NEO::DeviceBlobConstants::memoryType, 0, mockMemoryType};
std::vector<uint32_t> inputBlobData(reinterpret_cast<uint32_t *>(hwBlob), reinterpret_cast<uint32_t *>(ptrOffset(hwBlob, sizeof(hwBlob))));
this->systemInfo.reset(new SystemInfo(inputBlobData));
return returnValue;
}
};
class MockPmt : public L0::Sysman::PlatformMonitoringTech {
public:
using L0::Sysman::PlatformMonitoringTech::guid;
MockPmt() = default;
void setGuid(std::string guid) {
this->guid = guid;
}
ze_result_t readValue(const std::string key, uint32_t &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (key.compare("VF0_VFID") == 0) {
val = 1;
} else if (key.compare("VF1_VFID") == 0) {
val = 0;
} else if (key.compare("VF0_HBM0_READ") == 0) {
val = vF0Hbm0ReadValue;
} else if (key.compare("VF0_HBM0_WRITE") == 0) {
val = vF0Hbm0WriteValue;
} else if (key.compare("VF0_HBM1_READ") == 0) {
val = vF0Hbm1ReadValue;
} else if (key.compare("VF0_HBM1_WRITE") == 0) {
val = vF0Hbm1WriteValue;
} else if (key.compare("VF0_TIMESTAMP_L") == 0) {
val = vF0TimestampLValue;
} else if (key.compare("VF0_TIMESTAMP_H") == 0) {
val = vF0TimestampHValue;
} else if (key.compare("VF0_HBM2_READ") == 0) {
val = vF0Hbm2ReadValue;
} else if (key.compare("VF0_HBM2_WRITE") == 0) {
val = vF0Hbm2WriteValue;
} else if (key.compare("VF0_HBM3_READ") == 0) {
val = vF0Hbm3ReadValue;
} else if (key.compare("VF0_HBM3_WRITE") == 0) {
val = vF0Hbm3WriteValue;
} else if (key.compare("VF0_HBM_READ_L") == 0) {
val = vF0HbmLRead;
} else if (key.compare("VF0_HBM_READ_H") == 0) {
val = vF0HbmHRead;
} else if (key.compare("VF0_HBM_WRITE_L") == 0) {
val = vF0HbmLWrite;
} else if (key.compare("VF0_HBM_WRITE_H") == 0) {
val = vF0HbmHWrite;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return result;
}
ze_result_t readValue(const std::string key, uint64_t &val) override {
ze_result_t result = ZE_RESULT_SUCCESS;
if (key.compare("IDI_READS[0]") == 0 || key.compare("IDI_READS[1]") == 0 || key.compare("IDI_READS[2]") == 0 || key.compare("IDI_READS[3]") == 0 || key.compare("IDI_READS[4]") == 0 || key.compare("IDI_READS[5]") == 0 || key.compare("IDI_READS[6]") == 0 || key.compare("IDI_READS[7]") == 0 || key.compare("IDI_READS[8]") == 0 || key.compare("IDI_READS[9]") == 0 || key.compare("IDI_READS[10]") == 0 || key.compare("IDI_READS[11]") == 0 || key.compare("IDI_READS[12]") == 0 || key.compare("IDI_READS[13]") == 0 || key.compare("IDI_READS[14]") == 0 || key.compare("IDI_READS[15]") == 0) {
val = mockIdiReadVal;
} else if (key.compare("IDI_WRITES[0]") == 0 || key.compare("IDI_WRITES[1]") == 0 || key.compare("IDI_WRITES[2]") == 0 || key.compare("IDI_WRITES[3]") == 0 || key.compare("IDI_WRITES[4]") == 0 || key.compare("IDI_WRITES[5]") == 0 || key.compare("IDI_WRITES[6]") == 0 || key.compare("IDI_WRITES[7]") == 0 || key.compare("IDI_WRITES[8]") == 0 || key.compare("IDI_WRITES[9]") == 0 || key.compare("IDI_WRITES[10]") == 0 || key.compare("IDI_WRITES[11]") == 0 || key.compare("IDI_WRITES[12]") == 0 || key.compare("IDI_WRITES[13]") == 0 || key.compare("IDI_WRITES[14]") == 0 || key.compare("IDI_WRITES[15]") == 0) {
val = mockIdiWriteVal;
} else if (key.compare("DISPLAY_VC1_READS[0]") == 0 || key.compare("DISPLAY_VC1_READS[1]") == 0 || key.compare("DISPLAY_VC1_READS[2]") == 0 || key.compare("DISPLAY_VC1_READS[3]") == 0 || key.compare("DISPLAY_VC1_READS[4]") == 0 || key.compare("DISPLAY_VC1_READS[5]") == 0 || key.compare("DISPLAY_VC1_READS[6]") == 0 || key.compare("DISPLAY_VC1_READS[7]") == 0 || key.compare("DISPLAY_VC1_READS[8]") == 0 || key.compare("DISPLAY_VC1_READS[9]") == 0 || key.compare("DISPLAY_VC1_READS[10]") == 0 || key.compare("DISPLAY_VC1_READS[11]") == 0 || key.compare("DISPLAY_VC1_READS[12]") == 0 || key.compare("DISPLAY_VC1_READS[13]") == 0 || key.compare("DISPLAY_VC1_READS[14]") == 0 || key.compare("DISPLAY_VC1_READS[15]") == 0) {
val = mockDisplayVc1ReadVal;
} else {
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return result;
}
};
static const std::string mockPhysicalSize = "0x00000040000000";
class SysmanProductHelperMemoryTest : public SysmanDeviceFixture {
protected:
L0::Sysman::SysmanDevice *device = nullptr;
DebugManagerStateRestore restorer;
MockDrm *pDrm = nullptr;
MockMemoryNeoDrm *pDrm = nullptr;
void SetUp() override {
debugManager.flags.EnableLocalMemory.set(1);
@@ -145,14 +35,14 @@ class SysmanProductHelperMemoryTest : public SysmanDeviceFixture {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
pLinuxSysmanImp->pSysmanProductHelper = std::move(pSysmanProductHelper);
pDrm = new MockDrm(const_cast<NEO::RootDeviceEnvironment &>(pSysmanDeviceImp->getRootDeviceEnvironment()));
pDrm = new MockMemoryNeoDrm(const_cast<NEO::RootDeviceEnvironment &>(pSysmanDeviceImp->getRootDeviceEnvironment()));
auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface;
osInterface->setDriverModel(std::unique_ptr<MockDrm>(pDrm));
osInterface->setDriverModel(std::unique_ptr<MockMemoryNeoDrm>(pDrm));
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
auto subdeviceId = 0u;
auto subDeviceCount = pLinuxSysmanImp->getSubDeviceCount();
do {
auto pPmt = new MockPmt();
auto pPmt = new MockMemoryPmt();
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt);
} while (++subdeviceId < subDeviceCount);
}
@@ -163,7 +53,7 @@ class SysmanProductHelperMemoryTest : public SysmanDeviceFixture {
}
};
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingMemoryAPIsThenErrorIsReturned, IsPVC) {
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingGetMemoryBandwidthAndVfid0IsActiveThenVerifyBandWidthIsValid, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::ostringstream oStream;
oStream << hbmRP0Frequency;
@@ -174,37 +64,164 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice);
auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM);
EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.physicalSize, 0u);
EXPECT_EQ(properties.numChannels, numMemoryChannels);
EXPECT_EQ(properties.busWidth, memoryBusWidth);
auto pPmt = static_cast<MockPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId));
pPmt->setGuid(guid64BitMemoryCounters);
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId));
pPmt->mockVfid0Status = true;
zes_mem_bandwidth_t bandwidth;
zes_mem_bandwidth_t bandwidth = {};
result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
expectedReadCounters |= vF0HbmHRead;
expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead;
uint64_t expectedReadCounters = vF0Hbm0ReadValue + vF0Hbm1ReadValue + vF0Hbm2ReadValue + vF0Hbm3ReadValue;
uint64_t expectedWriteCounters = vF0Hbm0WriteValue + vF0Hbm1WriteValue + vF0Hbm2WriteValue + vF0Hbm3WriteValue;
uint64_t expectedBandwidth = 0;
expectedReadCounters = expectedReadCounters * transactionSize;
EXPECT_EQ(bandwidth.readCounter, expectedReadCounters);
expectedWriteCounters |= vF0HbmHWrite;
expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite;
expectedWriteCounters = expectedWriteCounters * transactionSize;
EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters);
expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4;
EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingGetMemoryBandwidthAndVfid1IsActiveThenVerifyBandWidthIsValid, IsPVC) {
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::ostringstream oStream;
oStream << hbmRP0Frequency;
std::string value = oStream.str();
memcpy(buf, value.data(), count);
return count;
});
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId));
pPmt->setGuid(guid64BitMemoryCounters);
pPmt->mockVfid1Status = true;
zes_mem_bandwidth_t bandwidth = {};
result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
uint64_t expectedReadCounters = 0, expectedWriteCounters = 0;
expectedReadCounters |= vF0HbmHRead;
expectedReadCounters = (expectedReadCounters << 32) | vF0HbmLRead;
expectedReadCounters = expectedReadCounters * transactionSize;
expectedWriteCounters |= vF0HbmHWrite;
expectedWriteCounters = (expectedWriteCounters << 32) | vF0HbmLWrite;
expectedWriteCounters = expectedWriteCounters * transactionSize;
uint64_t expectedBandwidth = 128 * hbmRP0Frequency * 1000 * 1000 * 4;
EXPECT_EQ(bandwidth.readCounter, expectedReadCounters);
EXPECT_EQ(bandwidth.writeCounter, expectedWriteCounters);
EXPECT_EQ(bandwidth.maxBandwidth, expectedBandwidth);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenHbm0ReadFailsAndGuidNotSetWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId));
pPmt->mockReadArgumentValue.push_back(1);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadArgumentValue.push_back(0);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
zes_mem_bandwidth_t bandwidth = {};
result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenHbm0WriteFailsAndGuidNotSetWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
auto result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(properties.subdeviceId));
pPmt->mockReadArgumentValue.push_back(1);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadArgumentValue.push_back(0);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadArgumentValue.push_back(vF0Hbm0ReadValue);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
zes_mem_bandwidth_t bandwidth = {};
result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenVfid0ReadFailsWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
uint32_t subDeviceId = 0;
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId));
pPmt->setGuid(guid64BitMemoryCounters);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
zes_mem_bandwidth_t bandwidth{};
auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenVfid0ReadFailsAndGuidNotSetBitWhenCallingGetBandwidthAndVfid0IsActiveThenFailureIsReturned, IsPVC) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
uint32_t subDeviceId = 0;
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId));
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
zes_mem_bandwidth_t bandwidth{};
auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenVfid1ReadFailsWhenCallingGetBandwidthAndVfid1IsActiveThenFailureIsReturned, IsPVC) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
uint32_t subDeviceId = 0;
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId));
pPmt->setGuid(guid64BitMemoryCounters);
pPmt->mockReadArgumentValue.push_back(1);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_ERROR_UNKNOWN);
zes_mem_bandwidth_t bandwidth{};
auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenBothVfid0AndVfid1AreFalseWhenGettingMemoryBandwidthThenFailureIsReturned, IsPVC) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
uint32_t subDeviceId = 0;
auto pPmt = static_cast<MockMemoryPmt *>(pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId));
pPmt->setGuid(guid64BitMemoryCounters);
pPmt->mockReadArgumentValue.push_back(0);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
pPmt->mockReadArgumentValue.push_back(0);
pPmt->mockReadValueReturnStatus.push_back(ZE_RESULT_SUCCESS);
zes_mem_bandwidth_t bandwidth{};
auto result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_ERROR_UNKNOWN);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingGetMemoryBandwidthAPIsThenErrorIsReturned, IsDG1) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
@@ -224,6 +241,50 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWithPrelimInterfaceWhenCallingGetMemoryPropertiesThenVerifyPropertiesAreProper, IsDG2) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
auto pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily());
MockMemorySysFsAccessInterface *pSysfsAccess = new MockMemorySysFsAccessInterface();
pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface);
pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess);
pSysfsAccess->mockReadStringValue.push_back(mockPhysicalSize);
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_SUCCESS);
pSysfsAccess->isRepeated = true;
ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pSysmanKmdInterface, subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(properties.type, ZES_MEM_TYPE_HBM);
EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.physicalSize, strtoull(mockPhysicalSize.c_str(), nullptr, 16));
EXPECT_EQ(properties.numChannels, numMemoryChannels);
EXPECT_EQ(properties.busWidth, memoryBusWidth);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceAndPhysicalSizeReadFailsWhenCallingGetMemoryPropertiesThenVerifyPhysicalSizeIsZero, IsDG2) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
auto pSysmanKmdInterface = new MockSysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getProductFamily());
MockMemorySysFsAccessInterface *pSysfsAccess = new MockMemorySysFsAccessInterface();
pLinuxSysmanImp->pSysmanKmdInterface.reset(pSysmanKmdInterface);
pSysmanKmdInterface->pSysfsAccess.reset(pSysfsAccess);
pSysfsAccess->mockReadStringValue.push_back("0");
pSysfsAccess->mockReadReturnStatus.push_back(ZE_RESULT_ERROR_NOT_AVAILABLE);
pSysfsAccess->isRepeated = true;
ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pSysmanKmdInterface, subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(properties.physicalSize, 0u);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCallingMemoryAPIsThenErrorIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::ostringstream oStream;
@@ -259,6 +320,41 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal
EXPECT_GT(bandwidth.timestamp, 0u);
}
HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceAndPhysicalSizeSupportedWhenCallingMemoryAPIsThenErrorIsReturned, IsDG2) {
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
std::ostringstream oStream;
oStream << mockMaxBwDg2;
std::string value = oStream.str();
memcpy(buf, value.data(), count);
return count;
});
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily);
zes_mem_properties_t properties;
uint64_t expectedReadCounters = 0, expectedWriteCounters = 0, expectedBandwidth = 0;
bool isSubdevice = true;
uint32_t subDeviceId = 0;
ze_result_t result = pSysmanProductHelper->getMemoryProperties(&properties, pLinuxSysmanImp, pDrm, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId, isSubdevice);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
EXPECT_EQ(properties.location, ZES_MEM_LOC_DEVICE);
EXPECT_TRUE(properties.onSubdevice);
EXPECT_EQ(properties.subdeviceId, 0u);
EXPECT_EQ(properties.physicalSize, 0u);
EXPECT_EQ(properties.numChannels, numMemoryChannels);
EXPECT_EQ(properties.busWidth, memoryBusWidth);
zes_mem_bandwidth_t bandwidth;
result = pSysmanProductHelper->getMemoryBandwidth(&bandwidth, pLinuxSysmanImp->getPlatformMonitoringTechAccess(subDeviceId), pSysmanDeviceImp, pLinuxSysmanImp->getSysmanKmdInterface(), subDeviceId);
EXPECT_EQ(result, ZE_RESULT_SUCCESS);
expectedReadCounters = numberMcChannels * (mockIdiReadVal + mockDisplayVc1ReadVal) * transactionSize;
EXPECT_EQ(expectedReadCounters, bandwidth.readCounter);
expectedWriteCounters = numberMcChannels * mockIdiWriteVal * transactionSize;
EXPECT_EQ(expectedWriteCounters, bandwidth.writeCounter);
expectedBandwidth = mockMaxBwDg2 * mbpsToBytesPerSecond;
EXPECT_EQ(expectedBandwidth, bandwidth.maxBandwidth);
EXPECT_GT(bandwidth.timestamp, 0u);
}
TEST(SysmanProductHelperTest, GivenInvalidProductFamilyWhenCallingProductHelperCreateThenNullPtrIsReturned) {
auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(IGFX_UNKNOWN);
EXPECT_EQ(nullptr, pSysmanProductHelper);