mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
Revert "fix: use condition variables instead of busy waits in worker threads"
This reverts commit 9d1da44e08.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
ac296f76ba
commit
bafb847c73
@@ -67,7 +67,7 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(this->mtx);
|
||||
std::lock_guard<std::mutex> lock(this->mtx);
|
||||
if (svmData->device ? svmData->device->shouldLimitAllocationsReuse() : memoryManager->shouldLimitAllocationsReuse()) {
|
||||
return false;
|
||||
}
|
||||
@@ -107,12 +107,6 @@ bool SVMAllocsManager::SvmAllocationCache::insert(size_t size, void *ptr, SvmAll
|
||||
.operationType = CacheOperationType::insert,
|
||||
.isSuccess = isSuccess});
|
||||
}
|
||||
|
||||
if (auto usmReuseCleaner = this->memoryManager->peekExecutionEnvironment().unifiedMemoryReuseCleaner.get()) {
|
||||
lock.unlock();
|
||||
usmReuseCleaner->notifySvmAllocationsCacheUpdate();
|
||||
}
|
||||
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,6 @@ class SVMAllocsManager {
|
||||
static bool allocUtilizationAllows(size_t requestedSize, size_t reuseCandidateSize);
|
||||
static bool alignmentAllows(void *ptr, size_t alignment);
|
||||
bool isInUse(SvmCacheAllocationInfo &cacheAllocInfo);
|
||||
bool isEmpty() { return allocations.empty(); }
|
||||
void *get(size_t size, const UnifiedMemoryProperties &unifiedMemoryProperties);
|
||||
void trim();
|
||||
void trimOldAllocs(std::chrono::high_resolution_clock::time_point trimTimePoint, bool trimAll);
|
||||
|
||||
@@ -25,10 +25,6 @@ UnifiedMemoryReuseCleaner::~UnifiedMemoryReuseCleaner() {
|
||||
void UnifiedMemoryReuseCleaner::stopThread() {
|
||||
keepCleaning.store(false);
|
||||
runCleaning.store(false);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(condVarMutex);
|
||||
condVar.notify_one();
|
||||
}
|
||||
if (unifiedMemoryReuseCleanerThread) {
|
||||
unifiedMemoryReuseCleanerThread->join();
|
||||
unifiedMemoryReuseCleanerThread.reset();
|
||||
@@ -48,22 +44,11 @@ void *UnifiedMemoryReuseCleaner::cleanUnifiedMemoryReuse(void *self) {
|
||||
if (!cleaner->keepCleaning.load()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_lock lock(cleaner->condVarMutex);
|
||||
while (cleaner->keepCleaning.load() && cleaner->isEmpty()) {
|
||||
cleaner->wait(lock);
|
||||
}
|
||||
|
||||
NEO::sleep(sleepTime);
|
||||
cleaner->trimOldInCaches();
|
||||
}
|
||||
}
|
||||
|
||||
void UnifiedMemoryReuseCleaner::notifySvmAllocationsCacheUpdate() {
|
||||
std::lock_guard<std::mutex> lock(condVarMutex);
|
||||
condVar.notify_one();
|
||||
}
|
||||
|
||||
void UnifiedMemoryReuseCleaner::registerSvmAllocationCache(SvmAllocationCache *cache) {
|
||||
std::lock_guard<std::mutex> lockSvmAllocationCaches(this->svmAllocationCachesMutex);
|
||||
this->svmAllocationCaches.push_back(cache);
|
||||
@@ -98,4 +83,4 @@ void UnifiedMemoryReuseCleaner::startThread() {
|
||||
this->unifiedMemoryReuseCleanerThread = Thread::createFunc(cleanUnifiedMemoryReuse, reinterpret_cast<void *>(this));
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
} // namespace NEO
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "shared/source/memory_manager/unified_memory_manager.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
@@ -34,12 +33,6 @@ class UnifiedMemoryReuseCleaner : NEO::NonCopyableAndNonMovableClass {
|
||||
|
||||
void registerSvmAllocationCache(SvmAllocationCache *cache);
|
||||
void unregisterSvmAllocationCache(SvmAllocationCache *cache);
|
||||
MOCKABLE_VIRTUAL void wait(std::unique_lock<std::mutex> &lock) { condVar.wait(lock); }
|
||||
MOCKABLE_VIRTUAL bool isEmpty() {
|
||||
std::unique_lock<std::mutex> lock(svmAllocationCachesMutex);
|
||||
return std::all_of(svmAllocationCaches.begin(), svmAllocationCaches.end(), [](const auto &it) { return it->isEmpty(); });
|
||||
}
|
||||
void notifySvmAllocationsCacheUpdate();
|
||||
|
||||
protected:
|
||||
void startCleaning() { runCleaning.store(true); };
|
||||
@@ -50,9 +43,6 @@ class UnifiedMemoryReuseCleaner : NEO::NonCopyableAndNonMovableClass {
|
||||
std::vector<SvmAllocationCache *> svmAllocationCaches;
|
||||
std::mutex svmAllocationCachesMutex;
|
||||
|
||||
std::mutex condVarMutex;
|
||||
std::condition_variable condVar;
|
||||
|
||||
std::atomic_bool runCleaning = false;
|
||||
std::atomic_bool keepCleaning = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user