mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
feature(sysman): Optimize Sysfs reads
Maintain cache of file names and file descriptor to avoid invoking open and close system calls on every read call. Related-To: LOCI-4556 Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
b529adf941
commit
8778a0acca
@@ -413,6 +413,87 @@ TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndIntegerWhenCallingReadThenSu
|
||||
delete tempSysfsAccess;
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndOpenSysCallFailsWhenCallingReadThenFailureIsReturned) {
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
|
||||
return -1;
|
||||
});
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
|
||||
std::string value = "123";
|
||||
memcpy(buf, value.data(), value.size());
|
||||
return value.size();
|
||||
});
|
||||
|
||||
PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess();
|
||||
const std::string fileName = "mockFile.txt";
|
||||
int iVal32;
|
||||
|
||||
errno = ENOENT;
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, tempSysfsAccess->read(fileName, iVal32));
|
||||
delete tempSysfsAccess;
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndIntegerWhenCallingReadOnMultipleFilesThenSuccessIsReturned) {
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
|
||||
return 1;
|
||||
});
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsPread)> mockPread(&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
|
||||
std::string value = "123";
|
||||
memcpy(buf, value.data(), value.size());
|
||||
return value.size();
|
||||
});
|
||||
|
||||
PublicSysfsAccess *tempSysfsAccess = new PublicSysfsAccess();
|
||||
std::string fileName = {};
|
||||
int iVal32;
|
||||
for (auto i = 0; i < L0::FdCache::maxSize + 2; i++) {
|
||||
fileName = "mockfile" + std::to_string(i) + ".txt";
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, tempSysfsAccess->read(fileName, iVal32));
|
||||
}
|
||||
delete tempSysfsAccess;
|
||||
}
|
||||
|
||||
TEST(FdCacheTest, GivenValidFdCacheWhenCallingGetFdOnSameFileThenVerifyCacheIsUpdatedProperly) {
|
||||
|
||||
class MockFdCache : public FdCache {
|
||||
public:
|
||||
using FdCache::fdMap;
|
||||
};
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
|
||||
return 1;
|
||||
});
|
||||
|
||||
std::unique_ptr<MockFdCache> pFdCache = std::make_unique<MockFdCache>();
|
||||
std::string fileName = {};
|
||||
for (auto i = 0; i < L0::FdCache::maxSize; i++) {
|
||||
fileName = "mockfile" + std::to_string(i) + ".txt";
|
||||
EXPECT_LE(0, pFdCache->getFd(fileName));
|
||||
}
|
||||
|
||||
fileName = "mockfile0.txt";
|
||||
for (auto i = 0; i < 3; i++) {
|
||||
EXPECT_LE(0, pFdCache->getFd(fileName));
|
||||
}
|
||||
|
||||
for (auto i = 1; i < L0::FdCache::maxSize - 1; i++) {
|
||||
fileName = "mockfile" + std::to_string(i) + ".txt";
|
||||
EXPECT_LE(0, pFdCache->getFd(fileName));
|
||||
}
|
||||
|
||||
// Get Fd after the cache is full.
|
||||
EXPECT_LE(0, pFdCache->getFd("dummy.txt"));
|
||||
|
||||
// Verify Cache have the elemets that are accessed more number of times
|
||||
EXPECT_NE(pFdCache->fdMap.end(), pFdCache->fdMap.find("mockfile0.txt"));
|
||||
|
||||
// Verify cache doesn't have an element that is accessed less number of times.
|
||||
EXPECT_EQ(pFdCache->fdMap.end(), pFdCache->fdMap.find("mockfile9.txt"));
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndUnsignedIntegerWhenCallingReadThenSuccessIsReturned) {
|
||||
|
||||
VariableBackup<decltype(NEO::SysCalls::sysCallsOpen)> mockOpen(&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
|
||||
|
||||
Reference in New Issue
Block a user