diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index 88fc6186f7..36f4904f52 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -336,12 +336,9 @@ bool DrmAllocation::shouldAllocationPageFault(const Drm *drm) { return DebugManager.flags.EnableImplicitMigrationOnFaultableHardware.get(); } - auto &productHelper = drm->getRootDeviceEnvironment().getHelper(); - auto isKmdMigrationSupported = productHelper.isKmdMigrationSupported(); - switch (this->allocationType) { case AllocationType::UNIFIED_SHARED_MEMORY: - return (DebugManager.flags.UseKmdMigration.get() == -1) ? isKmdMigrationSupported : DebugManager.flags.UseKmdMigration.get(); + return drm->hasKmdMigrationSupport(); case AllocationType::BUFFER: return DebugManager.flags.UseKmdMigrationForBuffers.get() > 0; default: diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 828b3d113e..82896ee742 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -245,14 +245,8 @@ bool DrmMemoryManager::hasPageFaultsEnabled(const Device &neoDevice) { } bool DrmMemoryManager::isKmdMigrationAvailable(uint32_t rootDeviceIndex) { - const auto &productHelper = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHelper(); - auto useKmdMigration = productHelper.isKmdMigrationSupported(); - - if (DebugManager.flags.UseKmdMigration.get() != -1) { - useKmdMigration = DebugManager.flags.UseKmdMigration.get(); - } - - return useKmdMigration; + auto &drm = this->getDrm(rootDeviceIndex); + return drm.hasKmdMigrationSupport(); } bool DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) { diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 0086180dc7..cfbaddc4bc 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1132,6 +1132,17 @@ bool Drm::hasPageFaultSupport() const { return pageFaultSupported; } +bool Drm::hasKmdMigrationSupport() const { + const auto &productHelper = this->getRootDeviceEnvironment().getHelper(); + auto kmdMigrationSupported = hasPageFaultSupport() && productHelper.isKmdMigrationSupported(); + + if (DebugManager.flags.UseKmdMigration.get() != -1) { + return !!DebugManager.flags.UseKmdMigration.get(); + } + + return kmdMigrationSupported; +} + unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice) { auto engineInfo = this->engineInfo.get(); diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index cc9f353066..8a3d58d060 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -169,6 +169,7 @@ class Drm : public DriverModel { MOCKABLE_VIRTUAL void queryPageFaultSupport(); bool hasPageFaultSupport() const; + bool hasKmdMigrationSupport() const; MOCKABLE_VIRTUAL uint32_t registerResource(DrmResourceClass classType, const void *data, size_t size); MOCKABLE_VIRTUAL void unregisterResource(uint32_t handle); diff --git a/shared/test/unit_test/os_interface/linux/drm_query_topology_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_query_topology_prelim_tests.cpp index 6ed3aa5065..eaf7a94dfa 100644 --- a/shared/test/unit_test/os_interface/linux/drm_query_topology_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_query_topology_prelim_tests.cpp @@ -403,3 +403,39 @@ TEST(DrmQueryTest, givenEnableImplicitMigrationOnFaultableHardwareWhenShouldAllo MockDrmAllocation allocation(0u, AllocationType::BUFFER, MemoryPool::MemoryNull); EXPECT_TRUE(allocation.shouldAllocationPageFault(&drm)); } + +TEST(DrmQueryTest, givenUseKmdMigrationSetWhenCallingHasKmdMigrationSupportThenReturnCorrectValue) { + DebugManagerStateRestore restorer; + + auto executionEnvironment = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); + executionEnvironment->initializeMemoryManager(); + + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + drm.pageFaultSupported = true; + + for (auto useKmdMigration : {-1, 0, 1}) { + DebugManager.flags.UseKmdMigration.set(useKmdMigration); + if (useKmdMigration == -1) { + auto &productHelper = drm.getRootDeviceEnvironment().getHelper(); + EXPECT_EQ(productHelper.isKmdMigrationSupported(), drm.hasKmdMigrationSupport()); + } else { + EXPECT_EQ(useKmdMigration, drm.hasKmdMigrationSupport()); + } + } +} + +TEST(DrmQueryTest, givenKmdMigrationSupportedWhenShouldAllocationPageFaultIsCalledOnUnifiedSharedMemoryThenReturnTrue) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->initGmm(); + executionEnvironment->initializeMemoryManager(); + + DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]); + drm.pageFaultSupported = true; + + MockBufferObject bo(0u, &drm, 3, 0, 0, 1); + MockDrmAllocation allocation(0u, AllocationType::UNIFIED_SHARED_MEMORY, MemoryPool::LocalMemory); + allocation.bufferObjects[0] = &bo; + + EXPECT_EQ(drm.hasKmdMigrationSupport(), allocation.shouldAllocationPageFault(&drm)); +} diff --git a/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp index 17ef6f9b13..0c71478d0b 100644 --- a/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_vm_bind_prelim_tests.cpp @@ -123,7 +123,7 @@ TEST(DrmVmBindTest, givenUseKmdMigrationWhenCallingBindBoOnUnifiedSharedMemoryTh EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag(), drm.context.receivedVmBind->flags); } -TEST(DrmVmBindTest, givenDefaultDriverSettingsWhenCallingBindBoOnUnifiedSharedMemoryThenMarkAllocationShouldPageFaultWhenKmdMigrationIsSupported) { +TEST(DrmVmBindTest, givenDrmWithPageFaultSupportWhenCallingBindBoOnUnifiedSharedMemoryThenMarkAllocationShouldPageFaultWhenKmdMigrationIsSupported) { auto executionEnvironment = std::make_unique(); executionEnvironment->rootDeviceEnvironments[0]->initGmm(); executionEnvironment->initializeMemoryManager(); @@ -142,7 +142,15 @@ TEST(DrmVmBindTest, givenDefaultDriverSettingsWhenCallingBindBoOnUnifiedSharedMe allocation.bindBO(&bo, &osContext, vmHandleId, nullptr, true); auto &productHelper = drm.getRootDeviceEnvironment().getHelper(); - auto isKmdMigrationSupported = productHelper.isKmdMigrationSupported(); + auto kmdMigrationSupported = productHelper.isKmdMigrationSupported(); - EXPECT_EQ(isKmdMigrationSupported, allocation.shouldAllocationPageFault(&drm)); + if (kmdMigrationSupported) { + EXPECT_TRUE(allocation.shouldAllocationPageFault(&drm)); + EXPECT_FALSE(bo.isExplicitResidencyRequired()); + EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag(), drm.context.receivedVmBind->flags); + } else { + EXPECT_FALSE(allocation.shouldAllocationPageFault(&drm)); + EXPECT_TRUE(bo.isExplicitResidencyRequired()); + EXPECT_EQ(DrmPrelimHelper::getImmediateVmBindFlag() | DrmPrelimHelper::getMakeResidentVmBindFlag(), drm.context.receivedVmBind->flags); + } }