fix: use condition variables instead of busy waits in worker threads

Resolves: NEO-16085, GSD-11678, HSD-14025819208

Signed-off-by: Igor Venevtsev <igor.venevtsev@intel.com>
This commit is contained in:
Igor Venevtsev
2025-10-21 10:48:44 +00:00
committed by Compute-Runtime-Automation
parent bc71b2f685
commit 1f6039676f
21 changed files with 283 additions and 177 deletions

View File

@@ -67,7 +67,7 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
return false;
}
std::lock_guard<std::mutex> lock(this->mtx);
std::unique_lock<std::mutex> lock(this->mtx);
if (svmData->device ? svmData->device->shouldLimitAllocationsReuse() : memoryManager->shouldLimitAllocationsReuse()) {
return false;
}
@@ -99,8 +99,11 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
}
svmData->isSavedForReuse = true;
allocations.emplace(std::lower_bound(allocations.begin(), allocations.end(), size), size, ptr, svmData, waitForCompletion);
if (memoryManager->peekExecutionEnvironment().unifiedMemoryReuseCleaner) {
memoryManager->peekExecutionEnvironment().unifiedMemoryReuseCleaner->startThread();
empty = false;
if (auto usmReuseCleaner = this->memoryManager->peekExecutionEnvironment().unifiedMemoryReuseCleaner.get()) {
lock.unlock();
usmReuseCleaner->startThread();
usmReuseCleaner->notifySvmAllocationsCacheUpdate();
}
}
if (enablePerformanceLogging) {
@@ -110,6 +113,7 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
.operationType = CacheOperationType::insert,
.isSuccess = isSuccess});
}
return isSuccess;
}
@@ -181,6 +185,7 @@ void *SVMAllocsManager::SvmAllocationCache::get(size_t size, const UnifiedMemory
svmAllocsManager->reinsertToAllocsForIndirectAccess(*allocationIter->svmData);
}
allocations.erase(allocationIter);
empty = allocations.empty();
return allocationPtr;
}
}
@@ -215,6 +220,7 @@ void SVMAllocsManager::SvmAllocationCache::trim() {
svmAllocsManager->freeSVMAllocImpl(cachedAllocationInfo.allocation, FreePolicyType::blocking, cachedAllocationInfo.svmData);
}
this->allocations.clear();
empty = true;
}
void SVMAllocsManager::SvmAllocationCache::cleanup() {
@@ -299,6 +305,7 @@ void SVMAllocsManager::SvmAllocationCache::trimOldAllocs(std::chrono::high_resol
if (trimAll) {
std::erase_if(allocations, SvmCacheAllocationInfo::isMarkedForDelete);
}
empty = allocations.empty();
}
SvmAllocationData *SVMAllocsManager::MapBasedAllocationTracker::get(const void *ptr) {