diff --git a/opencl/source/os_interface/linux/drm_command_stream.inl b/opencl/source/os_interface/linux/drm_command_stream.inl index aaced7892d..3b45f63eac 100644 --- a/opencl/source/os_interface/linux/drm_command_stream.inl +++ b/opencl/source/os_interface/linux/drm_command_stream.inl @@ -73,7 +73,11 @@ bool DrmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, Reside auto memoryOperationsInterface = static_cast(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get()); - auto lock = memoryOperationsInterface->lockHandlerForExecWA(); + std::unique_lock lock; + if (!this->directSubmission.get() && !this->blitterDirectSubmission.get()) { + lock = memoryOperationsInterface->lockHandlerIfUsed(); + } + memoryOperationsInterface->mergeWithResidencyContainer(this->osContext, allocationsForResidency); if (this->directSubmission.get()) { diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp index 28d0214433..bf7acb0378 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp @@ -105,7 +105,33 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThen EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(rootDeviceIndex, 0xF)); } -HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMakeAllBuffersResidentSetWhenFlushThenDrmMemoryOperationHandlerIsLocked) { +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenNoAllocsInMemoryOperationHandlerDefaultWhenFlushThenDrmMemoryOperationHandlerIsNotLocked) { + struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { + using DrmMemoryOperationsHandler::mutex; + }; + + struct MockDrmCsr : public DrmCommandStreamReceiver { + using DrmCommandStreamReceiver::DrmCommandStreamReceiver; + void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override { + auto memoryOperationsInterface = static_cast(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get()); + ASSERT_TRUE(memoryOperationsInterface->mutex.try_lock()); + memoryOperationsInterface->mutex.unlock(); + } + }; + + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + LinearStream cs(commandBuffer); + CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); + CommandStreamReceiverHw::alignToCacheLine(cs); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr}; + + MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive); + mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations()); + + mm->freeGraphicsMemory(commandBuffer); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocsInMemoryOperationHandlerDefaultWhenFlushThenDrmMemoryOperationHandlerIsLocked) { struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { using DrmMemoryOperationsHandler::mutex; }; @@ -118,8 +144,8 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMakeAllBuffersResidentSetW } }; - DebugManagerStateRestore restorer; - DebugManager.flags.MakeAllBuffersResident.set(true); + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); LinearStream cs(commandBuffer); @@ -131,6 +157,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMakeAllBuffersResidentSetW mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations()); mm->freeGraphicsMemory(commandBuffer); + mm->freeGraphicsMemory(allocation); } HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInterfaceWhenFlushThenAllocIsResident) { diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler.h b/shared/source/os_interface/linux/drm_memory_operations_handler.h index c114bbc1b6..8923f7ddc1 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler.h @@ -23,7 +23,7 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler { virtual MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) = 0; virtual MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) = 0; virtual void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0; - virtual std::unique_lock lockHandlerForExecWA() = 0; + virtual std::unique_lock lockHandlerIfUsed() = 0; static std::unique_ptr create(Drm &drm, uint32_t rootDeviceIndex); diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 3600406540..449d52fc23 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -96,7 +96,7 @@ void DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osCo residencyContainer.clear(); } -std::unique_lock DrmMemoryOperationsHandlerBind::lockHandlerForExecWA() { +std::unique_lock DrmMemoryOperationsHandlerBind::lockHandlerIfUsed() { return std::unique_lock(); } diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h index f1ee6c9f70..532d3e7eaa 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.h @@ -23,7 +23,7 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler { MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override; void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override; - std::unique_lock lockHandlerForExecWA() override; + std::unique_lock lockHandlerIfUsed() override; MOCKABLE_VIRTUAL void evictUnusedAllocations(); diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp index 27a36557bb..f80f4ba89a 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp @@ -56,9 +56,10 @@ void DrmMemoryOperationsHandlerDefault::mergeWithResidencyContainer(OsContext *o } } -std::unique_lock DrmMemoryOperationsHandlerDefault::lockHandlerForExecWA() { - if (DebugManager.flags.MakeAllBuffersResident.get()) { - return std::unique_lock(this->mutex); +std::unique_lock DrmMemoryOperationsHandlerDefault::lockHandlerIfUsed() { + std::unique_lock lock(this->mutex); + if (this->residency.size()) { + return lock; } return std::unique_lock(); } diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_default.h b/shared/source/os_interface/linux/drm_memory_operations_handler_default.h index ca6c93dadc..e79b62a48b 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_default.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_default.h @@ -24,7 +24,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler { MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override; void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override; - std::unique_lock lockHandlerForExecWA() override; + std::unique_lock lockHandlerIfUsed() override; protected: std::unordered_set residency;