mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 18:00:01 +08:00
Revert "refactor: linux cl_cache eviction mechanism"
This reverts commit 2aa0ae0eca.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
560b588cbe
commit
a8d404f859
@@ -428,189 +428,9 @@ TEST(CompilerCacheTests, GivenCompilerCacheWhenLockConfigFileThenFdIsSetProperSi
|
||||
EXPECT_EQ(directory, LockConfigFileAndConfigFileIsCreatedInMeantime::configSize);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheTests, GivenCacheBinaryWhenBinarySizeIsOverCacheLimitThenEarlyReturnFalse) {
|
||||
const size_t cacheSize = MemoryConstants::megaByte;
|
||||
CompilerCacheMockLinux cache({true, ".cl_cache", "/home/cl_cache/", cacheSize});
|
||||
|
||||
auto result = cache.cacheBinary("fileHash", "123456", cacheSize * 2);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
namespace PWriteCallsCountedAndDirSizeWritten {
|
||||
size_t pWriteCalled = 0u;
|
||||
size_t dirSize = 0u;
|
||||
decltype(NEO::SysCalls::sysCallsPwrite) mockPwrite = [](int fd, const void *buf, size_t count, off_t offset) -> ssize_t {
|
||||
pWriteCalled++;
|
||||
memcpy(&dirSize, buf, sizeof(dirSize));
|
||||
return 0;
|
||||
};
|
||||
} // namespace PWriteCallsCountedAndDirSizeWritten
|
||||
|
||||
class CompilerCacheEvictionTestsMockLinux : public CompilerCache {
|
||||
class CompilerCacheFailingLokcConfigFileAndReadSizeLinux : public CompilerCache {
|
||||
public:
|
||||
CompilerCacheEvictionTestsMockLinux(const CompilerCacheConfig &config) : CompilerCache(config) {}
|
||||
using CompilerCache::createUniqueTempFileAndWriteData;
|
||||
using CompilerCache::evictCache;
|
||||
using CompilerCache::lockConfigFileAndReadSize;
|
||||
using CompilerCache::renameTempFileBinaryToProperName;
|
||||
|
||||
bool createUniqueTempFileAndWriteData(char *tmpFilePathTemplate, const char *pBinary, size_t binarySize) override {
|
||||
createUniqueTempFileAndWriteDataCalled++;
|
||||
return createUniqueTempFileAndWriteDataResult;
|
||||
}
|
||||
size_t createUniqueTempFileAndWriteDataCalled = 0u;
|
||||
bool createUniqueTempFileAndWriteDataResult = true;
|
||||
|
||||
bool renameTempFileBinaryToProperName(const std::string &oldName, const std::string &kernelFileHash) override {
|
||||
renameTempFileBinaryToProperNameCalled++;
|
||||
return renameTempFileBinaryToProperNameResult;
|
||||
}
|
||||
size_t renameTempFileBinaryToProperNameCalled = 0u;
|
||||
bool renameTempFileBinaryToProperNameResult = true;
|
||||
|
||||
bool evictCache(uint64_t &bytesEvicted) override {
|
||||
bytesEvicted = evictCacheBytesEvicted;
|
||||
return evictCacheResult;
|
||||
}
|
||||
uint64_t evictCacheBytesEvicted = 0u;
|
||||
bool evictCacheResult = true;
|
||||
|
||||
void lockConfigFileAndReadSize(const std::string &configFilePath, UnifiedHandle &fd, size_t &directorySize) override {
|
||||
lockConfigFileAndReadSizeCalled++;
|
||||
std::get<int>(fd) = lockConfigFileAndReadSizeFd;
|
||||
directorySize = lockConfigFileAndReadSizeDirSize;
|
||||
return;
|
||||
}
|
||||
size_t lockConfigFileAndReadSizeCalled = 0u;
|
||||
int lockConfigFileAndReadSizeFd = -1;
|
||||
size_t lockConfigFileAndReadSizeDirSize = 0u;
|
||||
};
|
||||
|
||||
TEST(CompilerCacheTests, GivenCacheDirectoryFilledToTheLimitWhenNewBinaryFitsAfterEvictionThenWriteCacheAndUpdateConfigAndReturnTrue) {
|
||||
const size_t cacheSize = 10;
|
||||
CompilerCacheEvictionTestsMockLinux cache({true, ".cl_cache", "/home/cl_cache/", cacheSize});
|
||||
|
||||
cache.lockConfigFileAndReadSizeFd = 1;
|
||||
cache.lockConfigFileAndReadSizeDirSize = 6;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, [](const std::string &filePath, struct stat *statbuf) -> int { return -1; });
|
||||
|
||||
cache.evictCacheResult = true;
|
||||
cache.evictCacheBytesEvicted = cacheSize / 3;
|
||||
|
||||
cache.createUniqueTempFileAndWriteDataResult = true;
|
||||
cache.renameTempFileBinaryToProperNameResult = true;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPwrite)> pWriteBackup(&NEO::SysCalls::sysCallsPwrite, PWriteCallsCountedAndDirSizeWritten::mockPwrite);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::pWriteCalled)> pWriteCalledBackup(&PWriteCallsCountedAndDirSizeWritten::pWriteCalled, 0);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::dirSize)> dirSizeBackup(&PWriteCallsCountedAndDirSizeWritten::dirSize, 0);
|
||||
|
||||
const std::string kernelFileHash = "7e3291364d8df42";
|
||||
const char *binary = "123456";
|
||||
const size_t binarySize = strlen(binary);
|
||||
auto result = cache.cacheBinary(kernelFileHash, binary, binarySize);
|
||||
|
||||
const size_t expectedDirectorySize = 6 - (cacheSize / 3) + binarySize;
|
||||
|
||||
EXPECT_TRUE(result);
|
||||
EXPECT_EQ(1u, cache.lockConfigFileAndReadSizeCalled);
|
||||
EXPECT_EQ(1u, cache.createUniqueTempFileAndWriteDataCalled);
|
||||
EXPECT_EQ(1u, cache.renameTempFileBinaryToProperNameCalled);
|
||||
EXPECT_EQ(1u, PWriteCallsCountedAndDirSizeWritten::pWriteCalled);
|
||||
|
||||
EXPECT_EQ(expectedDirectorySize, PWriteCallsCountedAndDirSizeWritten::dirSize);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheTests, GivenCacheBinaryWhenBinaryDoesntFitAfterEvictionThenWriteToConfigAndReturnFalse) {
|
||||
const size_t cacheSize = 10;
|
||||
CompilerCacheEvictionTestsMockLinux cache({true, ".cl_cache", "/home/cl_cache/", cacheSize});
|
||||
cache.lockConfigFileAndReadSizeFd = 1;
|
||||
cache.lockConfigFileAndReadSizeDirSize = 9;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, [](const std::string &filePath, struct stat *statbuf) -> int { return -1; });
|
||||
|
||||
cache.evictCacheResult = true;
|
||||
cache.evictCacheBytesEvicted = cacheSize / 3;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPwrite)> pWriteBackup(&NEO::SysCalls::sysCallsPwrite, PWriteCallsCountedAndDirSizeWritten::mockPwrite);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::pWriteCalled)> pWriteCalledBackup(&PWriteCallsCountedAndDirSizeWritten::pWriteCalled, 0);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::dirSize)> dirSizeBackup(&PWriteCallsCountedAndDirSizeWritten::dirSize, 0);
|
||||
|
||||
const std::string kernelFileHash = "7e3291364d8df42";
|
||||
const char *binary = "123456";
|
||||
const size_t binarySize = strlen(binary);
|
||||
auto result = cache.cacheBinary(kernelFileHash, binary, binarySize);
|
||||
|
||||
const size_t expectedDirectorySize = 9 - (cacheSize / 3);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_EQ(1u, cache.lockConfigFileAndReadSizeCalled);
|
||||
EXPECT_EQ(1u, PWriteCallsCountedAndDirSizeWritten::pWriteCalled);
|
||||
|
||||
EXPECT_EQ(0u, cache.createUniqueTempFileAndWriteDataCalled);
|
||||
EXPECT_EQ(0u, cache.renameTempFileBinaryToProperNameCalled);
|
||||
|
||||
EXPECT_EQ(expectedDirectorySize, PWriteCallsCountedAndDirSizeWritten::dirSize);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheTests, GivenCacheDirectoryFilledToTheLimitWhenNoBytesHaveBeenEvictedAndNewBinaryDoesntFitAfterEvictionThenDontWriteToConfigAndReturnFalse) {
|
||||
const size_t cacheSize = 10;
|
||||
CompilerCacheEvictionTestsMockLinux cache({true, ".cl_cache", "/home/cl_cache/", cacheSize});
|
||||
cache.lockConfigFileAndReadSizeFd = 1;
|
||||
cache.lockConfigFileAndReadSizeDirSize = 9;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, [](const std::string &filePath, struct stat *statbuf) -> int { return -1; });
|
||||
|
||||
cache.evictCacheResult = true;
|
||||
cache.evictCacheBytesEvicted = 0;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPwrite)> pWriteBackup(&NEO::SysCalls::sysCallsPwrite, PWriteCallsCountedAndDirSizeWritten::mockPwrite);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::pWriteCalled)> pWriteCalledBackup(&PWriteCallsCountedAndDirSizeWritten::pWriteCalled, 0);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::dirSize)> dirSizeBackup(&PWriteCallsCountedAndDirSizeWritten::dirSize, 0);
|
||||
|
||||
const std::string kernelFileHash = "7e3291364d8df42";
|
||||
const char *binary = "123456";
|
||||
const size_t binarySize = strlen(binary);
|
||||
auto result = cache.cacheBinary(kernelFileHash, binary, binarySize);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_EQ(1u, cache.lockConfigFileAndReadSizeCalled);
|
||||
|
||||
EXPECT_EQ(0u, PWriteCallsCountedAndDirSizeWritten::pWriteCalled);
|
||||
EXPECT_EQ(0u, cache.createUniqueTempFileAndWriteDataCalled);
|
||||
EXPECT_EQ(0u, cache.renameTempFileBinaryToProperNameCalled);
|
||||
}
|
||||
|
||||
TEST(CompilerCacheTests, GivenCacheBinaryWhenEvictCacheFailsThenReturnFalse) {
|
||||
const size_t cacheSize = 10;
|
||||
CompilerCacheEvictionTestsMockLinux cache({true, ".cl_cache", "/home/cl_cache/", cacheSize});
|
||||
cache.lockConfigFileAndReadSizeFd = 1;
|
||||
cache.lockConfigFileAndReadSizeDirSize = 5;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsStat)> statBackup(&NEO::SysCalls::sysCallsStat, [](const std::string &filePath, struct stat *statbuf) -> int { return -1; });
|
||||
|
||||
cache.evictCacheResult = false;
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPwrite)> pWriteBackup(&NEO::SysCalls::sysCallsPwrite, PWriteCallsCountedAndDirSizeWritten::mockPwrite);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::pWriteCalled)> pWriteCalledBackup(&PWriteCallsCountedAndDirSizeWritten::pWriteCalled, 0);
|
||||
VariableBackup<decltype(PWriteCallsCountedAndDirSizeWritten::dirSize)> dirSizeBackup(&PWriteCallsCountedAndDirSizeWritten::dirSize, 0);
|
||||
|
||||
const std::string kernelFileHash = "7e3291364d8df42";
|
||||
const char *binary = "123456";
|
||||
const size_t binarySize = strlen(binary);
|
||||
auto result = cache.cacheBinary(kernelFileHash, binary, binarySize);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_EQ(1u, cache.lockConfigFileAndReadSizeCalled);
|
||||
|
||||
EXPECT_EQ(0u, PWriteCallsCountedAndDirSizeWritten::pWriteCalled);
|
||||
EXPECT_EQ(0u, cache.createUniqueTempFileAndWriteDataCalled);
|
||||
EXPECT_EQ(0u, cache.renameTempFileBinaryToProperNameCalled);
|
||||
}
|
||||
|
||||
class CompilerCacheFailingLockConfigFileAndReadSizeLinux : public CompilerCache {
|
||||
public:
|
||||
CompilerCacheFailingLockConfigFileAndReadSizeLinux(const CompilerCacheConfig &config) : CompilerCache(config) {}
|
||||
CompilerCacheFailingLokcConfigFileAndReadSizeLinux(const CompilerCacheConfig &config) : CompilerCache(config) {}
|
||||
using CompilerCache::createUniqueTempFileAndWriteData;
|
||||
using CompilerCache::evictCache;
|
||||
using CompilerCache::lockConfigFileAndReadSize;
|
||||
@@ -623,7 +443,7 @@ class CompilerCacheFailingLockConfigFileAndReadSizeLinux : public CompilerCache
|
||||
};
|
||||
|
||||
TEST(CompilerCacheTests, GivenCompilerCacheWhenLockConfigFileFailThenCacheBinaryReturnsFalse) {
|
||||
CompilerCacheFailingLockConfigFileAndReadSizeLinux cache({true, ".cl_cache", "/home/cl_cache/", MemoryConstants::megaByte});
|
||||
CompilerCacheFailingLokcConfigFileAndReadSizeLinux cache({true, ".cl_cache", "/home/cl_cache/", MemoryConstants::megaByte});
|
||||
|
||||
EXPECT_FALSE(cache.cacheBinary("config.file", "1", 1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user