From 5936734550bebc5477bf734e7d00e58990077744 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Sun, 26 Mar 2023 23:22:14 +0000 Subject: [PATCH] Add regkey to set preferred location for kmd-migrated shared allocation The regkey SetVmAdvisePreferredLocation sets the KMD VM advise with preferred location for KMD-migrated shared allocation (default - none, 1 - system, 2 - device memory). Related-To: NEO-7252 Signed-off-by: Milczarek, Slawomir --- .../debug_settings/debug_variables_base.inl | 1 + .../os_interface/linux/drm_memory_manager.cpp | 18 +++++++ .../libult/linux/drm_mock_prelim_context.cpp | 8 +++- .../libult/linux/drm_mock_prelim_context.h | 4 +- shared/test/common/test_files/igdrcl.config | 1 + ...m_memory_manager_localmem_prelim_tests.cpp | 48 +++++++++++++++++++ 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 5690e796d4..d422b2138b 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -207,6 +207,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideTimestampEvents, -1, "-1: default (based DECLARE_DEBUG_VARIABLE(int32_t, ForcePreParserEnabledForMiArbCheck, -1, "-1: default , 0: PreParser disabled, 1: PreParser enabled") DECLARE_DEBUG_VARIABLE(int32_t, BatchBufferStartPrepatchingWaEnabled, -1, "-1: default , 0: disabled, 1: enabled. WA applies valid VA pointing to 'self' instead of 0x0. This mitigates incorrect VA preparsing.") DECLARE_DEBUG_VARIABLE(int32_t, SetVmAdviseAtomicAttribute, -1, "-1: default - atomic system, 0: atomic none, 1: atomic device, 2: atomic system)") +DECLARE_DEBUG_VARIABLE(int32_t, SetVmAdvisePreferredLocation, -1, "-1: default - none, 0: system, 1: device memory. Set preferred location for kmd-migrated shared allocation") DECLARE_DEBUG_VARIABLE(int32_t, ReadBackCommandBufferAllocation, -1, "Read command buffer allocation back on the host side. -1: default, 0 - disabled, 1 - local memory only, 2 - local and system memory") DECLARE_DEBUG_VARIABLE(int32_t, UseContextEndOffsetForEventCompletion, -1, "Use Context End or Context Start for event completion signalling. -1: default: platform dependent, 0 - Use Context Start, 1 - Use Context End") DECLARE_DEBUG_VARIABLE(int32_t, ForceWddmLowPriorityContextValue, -1, "Force scheduling priority value during Wddm low priority context creation. -1 - default.") diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 0e6832b6c4..b1b9bebdec 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -2155,6 +2155,24 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const return nullptr; } + if (DebugManager.flags.SetVmAdvisePreferredLocation.get() != -1) { + MemoryClassInstance region{}; + auto preferredLocation = DebugManager.flags.SetVmAdvisePreferredLocation.get(); + switch (preferredLocation) { + case 0: + region.memoryClass = ioctlHelper->getDrmParamValue(DrmParam::MemoryClassSystem); + region.memoryInstance = 0; + break; + case 1: + default: + region.memoryClass = ioctlHelper->getDrmParamValue(DrmParam::MemoryClassDevice); + region.memoryInstance = handleId; + break; + } + [[maybe_unused]] auto success = ioctlHelper->setVmBoAdvise(bo->peekHandle(), ioctlHelper->getPreferredLocationAdvise(), ®ion); + DEBUG_BREAK_IF(!success); + } + uint64_t mmapOffsetWb = ioctlHelper->getDrmParamValue(DrmParam::MmapOffsetWb); uint64_t offset = 0; if (!retrieveMmapOffsetForBufferObject(allocationData.rootDeviceIndex, *bo, mmapOffsetWb, offset)) { diff --git a/shared/test/common/libult/linux/drm_mock_prelim_context.cpp b/shared/test/common/libult/linux/drm_mock_prelim_context.cpp index 4a9c5790d7..077ed3ce45 100644 --- a/shared/test/common/libult/linux/drm_mock_prelim_context.cpp +++ b/shared/test/common/libult/linux/drm_mock_prelim_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -228,7 +228,7 @@ int DrmMockPrelimContext::handlePrelimRequest(DrmIoctl request, void *arg) { } break; case DrmIoctl::GemVmAdvise: { const auto req = reinterpret_cast(arg); - receivedVmAdvise = VmAdvise{req->handle, req->attribute}; + receivedVmAdvise = VmAdvise{req->handle, req->attribute, {req->region.memory_class, req->region.memory_instance}}; return vmAdviseReturn; } break; case DrmIoctl::UuidRegister: { @@ -572,3 +572,7 @@ uint32_t DrmPrelimHelper::getVmAdviseDeviceFlag() { uint32_t DrmPrelimHelper::getVmAdviseSystemFlag() { return PRELIM_I915_VM_ADVISE_ATOMIC_SYSTEM; } + +uint32_t DrmPrelimHelper::getPreferredLocationAdvise() { + return PRELIM_I915_VM_ADVISE_PREFERRED_LOCATION; +} diff --git a/shared/test/common/libult/linux/drm_mock_prelim_context.h b/shared/test/common/libult/linux/drm_mock_prelim_context.h index e03c39c442..7717e1c7cc 100644 --- a/shared/test/common/libult/linux/drm_mock_prelim_context.h +++ b/shared/test/common/libult/linux/drm_mock_prelim_context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -75,6 +75,7 @@ struct UserFenceVmBindExt { struct VmAdvise { uint32_t handle{0}; uint32_t flags{0}; + MemoryClassInstance memoryRegions{0}; }; struct UuidVmBindExt { @@ -179,4 +180,5 @@ uint64_t getMemoryRegionsParamFlag(); uint32_t getVmAdviseNoneFlag(); uint32_t getVmAdviseDeviceFlag(); uint32_t getVmAdviseSystemFlag(); +uint32_t getPreferredLocationAdvise(); }; // namespace DrmPrelimHelper diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index f6ea4df665..99f8fa031b 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -445,6 +445,7 @@ ForcePreParserEnabledForMiArbCheck = -1 UseDynamicEventPacketsCount = -1 BatchBufferStartPrepatchingWaEnabled = -1 SetVmAdviseAtomicAttribute = -1 +SetVmAdvisePreferredLocation = -1 DirectSubmissionForceLocalMemoryStorageMode = -1 EnableRingSwitchTagUpdateWa = -1 PlaformSupportEvictIfNecessaryFlag = -1 diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index 478e7377ca..9f35470d9c 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -580,6 +580,54 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenSetVmAdviseAtomicAttributeWhe } } +TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenSetVmAdviseDevicePreferredLocationWhenCreatingKmdMigratedAllocationThenApplyVmAdvisePreferredLocationCorrectly) { + DebugManagerStateRestore restorer; + DebugManager.flags.UseKmdMigration.set(1); + RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex}; + std::map deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}}; + + std::vector regionInfo(2); + regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 1}; + regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)}; + + mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock)); + mock->queryEngineInfo(); + + SVMAllocsManager unifiedMemoryManager(memoryManager, false); + + SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields); + unifiedMemoryProperties.device = device.get(); + + for (auto preferredLocation : {0, 1, 2}) { + DebugManager.flags.SetVmAdvisePreferredLocation.set(preferredLocation); + + auto ptr = unifiedMemoryManager.createSharedUnifiedMemoryAllocation(MemoryConstants::pageSize64k, unifiedMemoryProperties, nullptr); + ASSERT_NE(ptr, nullptr); + + auto allocation = unifiedMemoryManager.getSVMAlloc(ptr)->gpuAllocations.getDefaultGraphicsAllocation(); + ASSERT_NE(allocation, nullptr); + + const auto &vmAdvise = mock->context.receivedVmAdvise.value(); + EXPECT_EQ(static_cast(allocation)->getBO()->peekHandle(), static_cast(vmAdvise.handle)); + + EXPECT_EQ(DrmPrelimHelper::getPreferredLocationAdvise(), vmAdvise.flags); + + switch (preferredLocation) { + case 0: + EXPECT_EQ(drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, vmAdvise.memoryRegions.memoryClass); + EXPECT_EQ(0u, vmAdvise.memoryRegions.memoryInstance); + break; + case 1: + default: + EXPECT_EQ(drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, vmAdvise.memoryRegions.memoryClass); + EXPECT_EQ(0u, vmAdvise.memoryRegions.memoryInstance); + break; + } + + unifiedMemoryManager.freeSVMAlloc(ptr); + } +} + TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenUseKmdMigrationAndUsmInitialPlacementSetToGpuWhenCreateUnifiedSharedMemoryWithOverridenMultiStoragePlacementThenKmdMigratedAllocationIsCreatedWithCorrectRegionsOrder) { DebugManagerStateRestore restorer; DebugManager.flags.UseKmdMigration.set(1);