From fc9352cfcb5a563039c34e22856c02cc746bda34 Mon Sep 17 00:00:00 2001 From: Michal Mrozek Date: Mon, 19 Sep 2022 15:23:38 +0000 Subject: [PATCH] Optimize binding process. - Do not iterate when all devices are parsed - Early continue if given device not present in context 200ns (+10%) in below scenario from compute-benchmarks ZE_AFFINITY_MASK=0.0 PrintDebugSettings=1 ./api_overhead_benchmark_l0 --test=ExecuteCommandListImmediate --api=l0 --UseProfiling=0 --CallsCount=1 --MeasureCompletionTime=0 --useBarrierSynchronization=0 --KernelExecutionTime=1 --iterations=1000 Signed-off-by: Michal Mrozek --- .../drm_memory_operations_handler_bind.cpp | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) 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 2a699ae9c7..29598c9cf7 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 @@ -35,19 +35,26 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *devi } MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResidentWithinOsContext(OsContext *osContext, ArrayRef gfxAllocations, bool evictable) { + auto deviceBitfield = osContext->getDeviceBitfield(); + std::lock_guard lock(mutex); - for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) { - auto drmAllocation = static_cast(*gfxAllocation); - for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) { - if (osContext->getDeviceBitfield().test(drmIterator)) { - int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true); - if (result) { - return MemoryOperationsStatus::OUT_OF_MEMORY; - } - } + auto devicesDone = 0u; + for (auto drmIterator = 0u; devicesDone < deviceBitfield.count(); drmIterator++) { + if (!deviceBitfield.test(drmIterator)) { + continue; } - if (!evictable) { - drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId()); + devicesDone++; + + for (auto gfxAllocation = gfxAllocations.begin(); gfxAllocation != gfxAllocations.end(); gfxAllocation++) { + auto drmAllocation = static_cast(*gfxAllocation); + + int result = drmAllocation->makeBOsResident(osContext, drmIterator, nullptr, true); + if (result) { + return MemoryOperationsStatus::OUT_OF_MEMORY; + } + if (!evictable) { + drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId()); + } } } return MemoryOperationsStatus::SUCCESS;