fix(sysman): fixes multithread access issue with FSAccess

Related-To: NEO-9720

Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
This commit is contained in:
Kulkarni, Ashwin Kumar
2023-12-08 15:22:42 +00:00
committed by Compute-Runtime-Automation
parent a2994e9b29
commit b33d9955a1
6 changed files with 81 additions and 62 deletions

View File

@@ -46,7 +46,6 @@ void FdCache::eraseLeastUsedEntryFromCache() {
}
int FdCache::getFd(std::string file) {
std::unique_lock<std::mutex> lock(fdMutex);
int fd = -1;
if (fdMap.find(file) == fdMap.end()) {
fd = NEO::SysCalls::open(file.c_str(), O_RDONLY);
@@ -73,6 +72,7 @@ FdCache::~FdCache() {
template <typename T>
ze_result_t FsAccess::readValue(const std::string file, T &val) {
auto lock = this->obtainMutex();
std::string readVal(64, '\0');
int fd = pFdCache->getFd(file);
@@ -308,6 +308,10 @@ bool FsAccess::directoryExists(const std::string path) {
return true;
}
std::unique_lock<std::mutex> FsAccess::obtainMutex() {
return std::unique_lock<std::mutex>(this->fsMutex);
}
// Procfs Access
const std::string ProcfsAccess::procDir = "/proc/";
const std::string ProcfsAccess::fdDir = "/fd/";

View File

@@ -42,7 +42,6 @@ class FdCache {
std::map<std::string, std::pair<int, uint32_t>> fdMap = {};
private:
std::mutex fdMutex{};
void eraseLeastUsedEntryFromCache();
};
@@ -79,11 +78,13 @@ class FsAccess {
FsAccess();
decltype(&NEO::SysCalls::access) accessSyscall = NEO::SysCalls::access;
decltype(&stat) statSyscall = stat;
MOCKABLE_VIRTUAL std::unique_lock<std::mutex> obtainMutex();
private:
template <typename T>
ze_result_t readValue(const std::string file, T &val);
std::unique_ptr<FdCache> pFdCache = nullptr;
std::mutex fsMutex{};
};
class ProcfsAccess : private FsAccess {