diff --git a/level_zero/sysman/source/linux/zes_os_sysman_imp.cpp b/level_zero/sysman/source/linux/zes_os_sysman_imp.cpp index 90ed21a140..bc47611434 100644 --- a/level_zero/sysman/source/linux/zes_os_sysman_imp.cpp +++ b/level_zero/sysman/source/linux/zes_os_sysman_imp.cpp @@ -64,7 +64,6 @@ ze_result_t LinuxSysmanImp::init() { rootPath = NEO::getPciRootPath(myDeviceFd).value_or(""); pSysfsAccess->getRealPath(deviceDir, gtDevicePath); - osInterface.getDriverModel()->as()->cleanup(); // Close Drm handles sysmanHwDeviceId->closeFileDescriptor(); diff --git a/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.cpp b/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.cpp index 282c8b2ec5..6613e4754b 100644 --- a/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.cpp +++ b/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.cpp @@ -9,8 +9,10 @@ #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/firmware_util/sysman_firmware_util.h" @@ -30,20 +32,12 @@ void memoryGetTimeStamp(uint64_t ×tamp) { 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->getSysmanDeviceImp(); pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess(); pPmt = pLinuxSysmanImp->getPlatformMonitoringTechAccess(subdeviceId); - init(); } bool LinuxMemoryImp::isMemoryModuleSupported() { @@ -89,6 +83,7 @@ ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { pProperties->physicalSize = 0; if (isSubdevice) { std::string memval; + physicalSizeFile = pDrm->getIoctlHelper()->getFileForMemoryAddrRange(subdeviceId); ze_result_t result = pSysfsAccess->read(physicalSizeFile, memval); uint64_t intval = strtoull(memval.c_str(), nullptr, 16); if (ZE_RESULT_SUCCESS != result) { @@ -170,9 +165,7 @@ void LinuxMemoryImp::getHbmFrequency(PRODUCT_FAMILY productFamily, unsigned shor hbmFrequency = 2.8 * gigaUnitTransferToUnitTransfer; } else 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"; + const std::string hbmRP0FreqFile = pDrm->getIoctlHelper()->getFileForMaxMemoryFrequencyOfSubDevice(subdeviceId); uint64_t hbmFreqValue = 0; ze_result_t result = pSysfsAccess->read(hbmRP0FreqFile, hbmFreqValue); if (ZE_RESULT_SUCCESS == result) { @@ -305,26 +298,15 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { pFwInterface->fwGetMemoryHealthIndicator(&pState->health); } - std::vector deviceRegions; auto hwDeviceId = pLinuxSysmanImp->getSysmanHwDeviceId(); hwDeviceId->openFileDescriptor(); - auto memRegions = pDrm->getMemoryRegions(); + auto memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo(); hwDeviceId->closeFileDescriptor(); - if (memRegions.empty()) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - auto regions = pDrm->getIoctlHelper()->translateToMemoryRegions(memRegions); - for (auto region : regions) { - if (region.region.memoryClass == drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE) { - deviceRegions.push_back(region); - } - } + auto region = memoryInfo->getMemoryRegion(MemoryBanks::getBankForLocalMemory(subdeviceId)); - UNRECOVERABLE_IF(deviceRegions.size() <= subdeviceId); - - pState->free = deviceRegions[subdeviceId].unallocatedSize; - pState->size = deviceRegions[subdeviceId].probedSize; + pState->free = region.unallocatedSize; + pState->size = region.probedSize; return ZE_RESULT_SUCCESS; } diff --git a/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.h b/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.h index c9e4388741..b3b2df52e0 100644 --- a/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.h +++ b/level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.h @@ -50,7 +50,6 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { bool isSubdevice = false; uint32_t subdeviceId = 0; std::string physicalSizeFile; - void init(); }; } // namespace Sysman diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h index cf90ba266f..98de2fd5fc 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/mock_memory_prelim.h @@ -19,16 +19,6 @@ #include "drm/intel_hwconfig_types.h" using namespace NEO; -constexpr uint64_t probedSizeRegionZero = 8 * GB; -constexpr uint64_t probedSizeRegionOne = 16 * GB; -constexpr uint64_t probedSizeRegionTwo = 4 * GB; -constexpr uint64_t probedSizeRegionThree = 16 * GB; -constexpr uint64_t probedSizeRegionFour = 32 * GB; -constexpr uint64_t unallocatedSizeRegionZero = 6 * GB; -constexpr uint64_t unallocatedSizeRegionOne = 12 * GB; -constexpr uint64_t unallocatedSizeRegionTwo = 25 * GB; -constexpr uint64_t unallocatedSizeRegionThree = 3 * GB; -constexpr uint64_t unallocatedSizeRegionFour = 4 * GB; constexpr uint16_t vF0VfidIndex = 88; constexpr uint16_t vF0Hbm0ReadIndex = 92; @@ -214,29 +204,6 @@ struct MockMemoryNeoDrm : public NEO::Drm { bool mockReturnEmptyRegions = false; MockMemoryNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(mockFd, ""), rootDeviceEnvironment) {} - std::vector getMemoryRegions() override { - if (mockReturnEmptyRegions == true) { - return {}; - } - - uint32_t regionCount = 3; - uint32_t allocSize = sizeof(drm_i915_query_memory_regions) + regionCount * sizeof(drm_i915_memory_region_info); - auto regions = std::vector(allocSize, 0); - drm_i915_query_memory_regions *memRegions = reinterpret_cast(regions.data()); - memRegions->regions[0].region = {I915_MEMORY_CLASS_SYSTEM, 0}; - memRegions->regions[0].probed_size = probedSizeRegionZero; - memRegions->regions[0].unallocated_size = unallocatedSizeRegionZero; - memRegions->regions[1].region = {I915_MEMORY_CLASS_DEVICE, 0}; - memRegions->regions[1].probed_size = probedSizeRegionOne; - memRegions->regions[1].unallocated_size = unallocatedSizeRegionOne; - memRegions->regions[2].region = {I915_MEMORY_CLASS_DEVICE, 1}; - memRegions->regions[2].probed_size = probedSizeRegionFour; - memRegions->regions[2].unallocated_size = unallocatedSizeRegionFour; - memRegions->num_regions = 3; - - return regions; - } - void setMemoryType(uint32_t memory) { mockMemoryType = memory; } diff --git a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp index 087f25868a..8e50e29d95 100644 --- a/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp +++ b/level_zero/sysman/test/unit_tests/sources/memory/linux/test_sysman_memory_prelim.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/os_interface/driver_info.h" +#include "shared/test/common/mocks/linux/mock_ioctl_helper.h" #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/sysman/source/linux/pmt/sysman_pmt_xml_offsets.h" @@ -51,7 +52,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { pFsAccessOriginal = pLinuxSysmanImp->pFsAccess; pLinuxSysmanImp->pFsAccess = pFsAccess.get(); pDrm->setMemoryType(INTEL_HWCONFIG_MEMORY_TYPE_HBM2e); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); pmtMapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject; @@ -329,8 +330,8 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo EXPECT_EQ(result, ZE_RESULT_SUCCESS); EXPECT_EQ(state.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state.size, probedSizeRegionOne); - EXPECT_EQ(state.free, unallocatedSizeRegionOne); + EXPECT_EQ(state.size, NEO::probedSizeRegionOne); + EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); } } @@ -709,18 +710,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemo } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndIfGetMemoryRegionsFailsThenErrorIsReturned) { - setLocalSupportedAndReinit(true); - - pDrm->mockReturnEmptyRegions = 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(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { zes_mem_properties_t properties = {}; ze_bool_t isSubdevice = pLinuxSysmanImp->getSubDeviceCount() == 0 ? false : true; @@ -748,7 +737,7 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { pSysfsAccess = std::make_unique(); pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get(); pDrm = new MockMemoryNeoDrm(const_cast(pSysmanDeviceImp->getRootDeviceEnvironment())); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface; osInterface->setDriverModel(std::unique_ptr(pDrm)); @@ -823,15 +812,15 @@ TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysma 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, probedSizeRegionOne); - EXPECT_EQ(state1.free, unallocatedSizeRegionOne); + 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, probedSizeRegionFour); - EXPECT_EQ(state2.free, unallocatedSizeRegionFour); + EXPECT_EQ(state2.size, NEO::probedSizeRegionFour); + EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); } } // namespace ult 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 index 96b58621d7..4326fa5ae9 100644 --- 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 @@ -10,9 +10,11 @@ #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" @@ -32,20 +34,12 @@ void memoryGetTimeStamp(uint64_t ×tamp) { 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() { @@ -85,6 +79,7 @@ ze_result_t LinuxMemoryImp::getProperties(zes_mem_properties_t *pProperties) { pProperties->physicalSize = 0; if (isSubdevice) { std::string memval; + physicalSizeFile = pDrm->getIoctlHelper()->getFileForMemoryAddrRange(subdeviceId); ze_result_t result = pSysfsAccess->read(physicalSizeFile, memval); uint64_t intval = strtoull(memval.c_str(), nullptr, 16); if (ZE_RESULT_SUCCESS != result) { @@ -166,9 +161,7 @@ void LinuxMemoryImp::getHbmFrequency(PRODUCT_FAMILY productFamily, unsigned shor hbmFrequency = 2.8 * gigaUnitTransferToUnitTransfer; } else 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"; + const std::string hbmRP0FreqFile = pDrm->getIoctlHelper()->getFileForMaxMemoryFrequencyOfSubDevice(subdeviceId); uint64_t hbmFreqValue = 0; ze_result_t result = pSysfsAccess->read(hbmRP0FreqFile, hbmFreqValue); if (ZE_RESULT_SUCCESS == result) { @@ -391,22 +384,11 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) { pFwInterface->fwGetMemoryHealthIndicator(&pState->health); } - std::vector deviceRegions; - auto memRegions = pDrm->getMemoryRegions(); - if (memRegions.empty()) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; - } - auto regions = pDrm->getIoctlHelper()->translateToMemoryRegions(memRegions); - for (auto region : regions) { - if (region.region.memoryClass == drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE) { - deviceRegions.push_back(region); - } - } + auto memoryInfo = pDrm->getIoctlHelper()->createMemoryInfo(); + auto region = memoryInfo->getMemoryRegion(MemoryBanks::getBankForLocalMemory(subdeviceId)); - UNRECOVERABLE_IF(deviceRegions.size() <= subdeviceId); - - pState->free = deviceRegions[subdeviceId].unallocatedSize; - pState->size = deviceRegions[subdeviceId].probedSize; + pState->free = region.unallocatedSize; + pState->size = region.probedSize; return ZE_RESULT_SUCCESS; } 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 index 1ce4dd2781..0aa43bf709 100644 --- 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 @@ -49,7 +49,6 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass { bool isSubdevice = false; uint32_t subdeviceId = 0; std::string physicalSizeFile; - void init(); }; } // 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 index 3ae3f15542..488dceb4ff 100644 --- 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 @@ -19,16 +19,6 @@ #include "drm/intel_hwconfig_types.h" using namespace NEO; -constexpr uint64_t probedSizeRegionZero = 8 * GB; -constexpr uint64_t probedSizeRegionOne = 16 * GB; -constexpr uint64_t probedSizeRegionTwo = 4 * GB; -constexpr uint64_t probedSizeRegionThree = 16 * GB; -constexpr uint64_t probedSizeRegionFour = 32 * GB; -constexpr uint64_t unallocatedSizeRegionZero = 6 * GB; -constexpr uint64_t unallocatedSizeRegionOne = 12 * GB; -constexpr uint64_t unallocatedSizeRegionTwo = 25 * GB; -constexpr uint64_t unallocatedSizeRegionThree = 3 * GB; -constexpr uint64_t unallocatedSizeRegionFour = 4 * GB; constexpr uint16_t vF0VfidIndex = 88; constexpr uint16_t vF0Hbm0ReadIndex = 92; @@ -218,29 +208,6 @@ struct MockMemoryNeoDrm : public Drm { bool mockReturnEmptyRegions = false; MockMemoryNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(mockFd, ""), rootDeviceEnvironment) {} - std::vector getMemoryRegions() override { - if (mockReturnEmptyRegions == true) { - return {}; - } - - uint32_t regionCount = 3; - uint32_t allocSize = sizeof(drm_i915_query_memory_regions) + regionCount * sizeof(drm_i915_memory_region_info); - auto regions = std::vector(allocSize, 0); - drm_i915_query_memory_regions *memRegions = reinterpret_cast(regions.data()); - memRegions->regions[0].region = {I915_MEMORY_CLASS_SYSTEM, 0}; - memRegions->regions[0].probed_size = probedSizeRegionZero; - memRegions->regions[0].unallocated_size = unallocatedSizeRegionZero; - memRegions->regions[1].region = {I915_MEMORY_CLASS_DEVICE, 0}; - memRegions->regions[1].probed_size = probedSizeRegionOne; - memRegions->regions[1].unallocated_size = unallocatedSizeRegionOne; - memRegions->regions[2].region = {I915_MEMORY_CLASS_DEVICE, 1}; - memRegions->regions[2].probed_size = probedSizeRegionFour; - memRegions->regions[2].unallocated_size = unallocatedSizeRegionFour; - memRegions->num_regions = 3; - - return regions; - } - void setMemoryType(uint32_t memory) { mockMemoryType = memory; } 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 index 981bd24f95..8c8e3015b2 100644 --- 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 @@ -6,6 +6,7 @@ */ #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" @@ -61,7 +62,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { pFsAccessOriginal = pLinuxSysmanImp->pFsAccess; pLinuxSysmanImp->pFsAccess = pFsAccess.get(); pDrm->setMemoryType(INTEL_HWCONFIG_MEMORY_TYPE_HBM2e); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); pSysmanDeviceImp->pMemoryHandleContext->handleList.clear(); uint32_t subDeviceCount = 0; @@ -371,8 +372,8 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemo EXPECT_EQ(result, ZE_RESULT_SUCCESS); EXPECT_EQ(state.health, ZES_MEM_HEALTH_OK); - EXPECT_EQ(state.size, probedSizeRegionOne); - EXPECT_EQ(state.free, unallocatedSizeRegionOne); + EXPECT_EQ(state.size, NEO::probedSizeRegionOne); + EXPECT_EQ(state.free, NEO::unallocatedSizeRegionOne); } } @@ -822,18 +823,6 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZesSysmanMemo } } -TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysmanMemoryGetStateAndIfGetMemoryRegionsFailsThenErrorIsReturned) { - setLocalSupportedAndReinit(true); - - pDrm->mockReturnEmptyRegions = 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(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropertiesThenValidMemoryPropertiesRetrieved) { zes_mem_properties_t properties = {}; ze_device_properties_t deviceProperties = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; @@ -871,7 +860,7 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture { device->getDriverHandle()->setMemoryManager(pMemoryManager); pDrm = new MockMemoryNeoDrm(const_cast(neoDevice->getRootDeviceEnvironment())); - pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); + pDrm->ioctlHelper = static_cast>(std::make_unique(*pDrm)); pSysmanDevice = device->getSysmanHandle(); pSysmanDeviceImp = static_cast(pSysmanDevice); @@ -992,15 +981,15 @@ TEST_F(SysmanMultiDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingZetSysma 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, probedSizeRegionOne); - EXPECT_EQ(state1.free, unallocatedSizeRegionOne); + 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, probedSizeRegionFour); - EXPECT_EQ(state2.free, unallocatedSizeRegionFour); + EXPECT_EQ(state2.size, NEO::probedSizeRegionFour); + EXPECT_EQ(state2.free, NEO::unallocatedSizeRegionFour); } } // namespace ult diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index 650ff532f9..c9b0dd7bc3 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -387,6 +387,10 @@ std::string IoctlHelper::getFileForMaxMemoryFrequencyOfSubDevice(int subDeviceId return "/gt/gt" + std::to_string(subDeviceId) + "/mem_RP0_freq_mhz"; } +std::string IoctlHelper::getFileForMemoryAddrRange(int subDeviceId) const { + return "gt/gt" + std::to_string(subDeviceId) + "/addr_range"; +} + bool IoctlHelper::checkIfIoctlReinvokeRequired(int error, DrmIoctl ioctlRequest) const { return (error == EINTR || error == EAGAIN || error == EBUSY || error == -EBUSY); } diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 14defdda2e..a01dda9b5d 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -142,6 +142,7 @@ class IoctlHelper { virtual std::string getFileForMaxGpuFrequency() const; virtual std::string getFileForMaxGpuFrequencyOfSubDevice(int subDeviceId) const; virtual std::string getFileForMaxMemoryFrequencyOfSubDevice(int subDeviceId) const; + virtual std::string getFileForMemoryAddrRange(int subdeviceId) const; virtual bool getFabricLatency(uint32_t fabricId, uint32_t &latency, uint32_t &bandwidth) = 0; virtual bool isWaitBeforeBindRequired(bool bind) const = 0; virtual void *pciBarrierMmap() { return nullptr; }; diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 19cab58a70..1ad5a94000 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -1356,6 +1356,10 @@ std::string IoctlHelperXe::getFileForMaxMemoryFrequencyOfSubDevice(int subDevice return "/device/gt" + std::to_string(subDeviceId) + "/freq_rp0"; } +std::string IoctlHelperXe::getFileForMemoryAddrRange(int subDeviceId) const { + return "device/tile" + std::to_string(subDeviceId) + "/addr_range"; +} + struct drm_xe_engine_class_instance * IoctlHelperXe::xeFindMatchingEngine(uint16_t engineClass, uint16_t engineInstance) { for (auto &engine : allEngines) { diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 5cc641d094..05fcb3190c 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -96,6 +96,7 @@ class IoctlHelperXe : public IoctlHelper { std::string getFileForMaxGpuFrequency() const override; std::string getFileForMaxGpuFrequencyOfSubDevice(int subDeviceId) const override; std::string getFileForMaxMemoryFrequencyOfSubDevice(int subDeviceId) const override; + std::string getFileForMemoryAddrRange(int subdeviceId) const override; bool getFabricLatency(uint32_t fabricId, uint32_t &latency, uint32_t &bandwidth) override; bool isWaitBeforeBindRequired(bool bind) const override; std::unique_ptr createEngineInfo(bool isSysmanEnabled) override; diff --git a/shared/test/common/mocks/linux/mock_ioctl_helper.h b/shared/test/common/mocks/linux/mock_ioctl_helper.h index ee25fe21eb..4ef42ccc1d 100644 --- a/shared/test/common/mocks/linux/mock_ioctl_helper.h +++ b/shared/test/common/mocks/linux/mock_ioctl_helper.h @@ -6,12 +6,23 @@ */ #pragma once +#include "shared/source/helpers/constants.h" #include "shared/source/os_interface/linux/ioctl_helper.h" +#include "shared/source/os_interface/linux/memory_info.h" + +#include "drm/i915_drm.h" #include namespace NEO { +constexpr uint64_t probedSizeRegionZero = 8 * GB; +constexpr uint64_t probedSizeRegionOne = 16 * GB; +constexpr uint64_t probedSizeRegionFour = 32 * GB; +constexpr uint64_t unallocatedSizeRegionZero = 6 * GB; +constexpr uint64_t unallocatedSizeRegionOne = 12 * GB; +constexpr uint64_t unallocatedSizeRegionFour = 4 * GB; + class MockIoctlHelper : public IoctlHelperPrelim20 { public: using IoctlHelperPrelim20::IoctlHelperPrelim20; @@ -20,6 +31,9 @@ class MockIoctlHelper : public IoctlHelperPrelim20 { }; int getDrmParamValue(DrmParam drmParam) const override { + if (drmParam == DrmParam::MemoryClassSystem || drmParam == DrmParam::MemoryClassDevice) { + return IoctlHelperPrelim20::getDrmParamValue(drmParam); + } return drmParamValue; } int vmBind(const VmBindParams &vmBindParams) override { @@ -41,6 +55,23 @@ class MockIoctlHelper : public IoctlHelperPrelim20 { return IoctlHelperPrelim20::isWaitBeforeBindRequired(bind); } + std::unique_ptr createMemoryInfo() override { + + std::vector regionInfo(3); + 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; + regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, 1}; + regionInfo[2].probedSize = probedSizeRegionFour; + regionInfo[2].unallocatedSize = unallocatedSizeRegionFour; + + std::unique_ptr memoryInfo = std::make_unique(regionInfo, drm); + return memoryInfo; + } + unsigned int ioctlRequestValue = 1234u; int drmParamValue = 1234; std::optional failBind{}; diff --git a/shared/test/unit_test/os_interface/linux/drm_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_tests.cpp index fdd0dceff5..a0a2cc8e5e 100644 --- a/shared/test/unit_test/os_interface/linux/drm_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_tests.cpp @@ -1563,6 +1563,13 @@ TEST(IoctlHelperTest, whenGettingFileNameForFrequencyFilesThenProperStringIsRetu EXPECT_STREQ("/gt/gt1/mem_RP0_freq_mhz", ioctlHelper->getFileForMaxMemoryFrequencyOfSubDevice(1).c_str()); } +TEST(IoctlHelperTest, whenGettingFileNameForMemoryAddrRangeThenProperStringIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto ioctlHelper = drm.getIoctlHelper(); + EXPECT_STREQ("gt/gt0/addr_range", ioctlHelper->getFileForMemoryAddrRange(0).c_str()); +} + TEST(DistanceInfoTest, givenDistanceInfosWhenAssignRegionsFromDistancesThenCorrectRegionsSet) { auto executionEnvironment = std::make_unique(); DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index 9d3d00eaf5..a5a0d01c9d 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -494,6 +494,13 @@ TEST(IoctlHelperXeTest, whenGettingFileNamesForFrequencyThenProperStringIsReturn EXPECT_STREQ("/device/gt1/freq_rp0", ioctlHelper->getFileForMaxMemoryFrequencyOfSubDevice(1).c_str()); } +TEST(IoctlHelperXeTest, whenGettingFileNameForMemoryAddrRangeThenProperStringIsReturned) { + auto executionEnvironment = std::make_unique(); + DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + auto ioctlHelper = std::make_unique(drm); + EXPECT_STREQ("device/tile0/addr_range", ioctlHelper->getFileForMemoryAddrRange(0).c_str()); +} + inline constexpr int testValueVmId = 0x5764; inline constexpr int testValueMapOff = 0x7788; inline constexpr int testValuePrime = 0x4321;