mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-01 04:23:00 +08:00
Add process safety to cl_cache on Linux
Current flow will be to have one synchronization point config.file. Read remains unblocking, only write(caching) operation will be blocking (lock on config.file) Related-To: NEO-4262 Signed-off-by: Diedrich, Kamil <kamil.diedrich@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c9fdeb200c
commit
26ca64bb28
@@ -17,11 +17,13 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <string_view>
|
||||
#include <sys/ioctl.h>
|
||||
#include <system_error>
|
||||
|
||||
@@ -40,6 +42,7 @@ bool allowFakeDevicePath = false;
|
||||
constexpr unsigned long int invalidIoctl = static_cast<unsigned long int>(-1);
|
||||
int setErrno = 0;
|
||||
int fstatFuncRetVal = 0;
|
||||
int flockRetVal = 0;
|
||||
uint32_t preadFuncCalled = 0u;
|
||||
uint32_t pwriteFuncCalled = 0u;
|
||||
bool isInvalidAILTest = false;
|
||||
@@ -47,6 +50,12 @@ const char *drmVersion = "i915";
|
||||
int passedFileDescriptorFlagsToSet = 0;
|
||||
int getFileDescriptorFlagsCalled = 0;
|
||||
int setFileDescriptorFlagsCalled = 0;
|
||||
int unlinkCalled = 0;
|
||||
int scandirCalled = 0;
|
||||
int mkstempCalled = 0;
|
||||
int renameCalled = 0;
|
||||
int pathFileExistsCalled = 0;
|
||||
int flockCalled = 0;
|
||||
|
||||
std::vector<void *> mmapVector(64);
|
||||
std::vector<void *> mmapCapturedExtendedPointers(64);
|
||||
@@ -57,6 +66,8 @@ uint32_t mmapFuncCalled = 0u;
|
||||
uint32_t munmapFuncCalled = 0u;
|
||||
|
||||
int (*sysCallsOpen)(const char *pathname, int flags) = nullptr;
|
||||
int (*sysCallsClose)(int fileDescriptor) = nullptr;
|
||||
int (*sysCallsOpenWithMode)(const char *pathname, int flags, int mode) = nullptr;
|
||||
ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset) = nullptr;
|
||||
ssize_t (*sysCallsPwrite)(int fd, const void *buf, size_t count, off_t offset) = nullptr;
|
||||
int (*sysCallsReadlink)(const char *path, char *buf, size_t bufsize) = nullptr;
|
||||
@@ -67,6 +78,15 @@ ssize_t (*sysCallsWrite)(int fd, void *buf, size_t count) = nullptr;
|
||||
int (*sysCallsPipe)(int pipeFd[2]) = nullptr;
|
||||
int (*sysCallsFstat)(int fd, struct stat *buf) = nullptr;
|
||||
char *(*sysCallsRealpath)(const char *path, char *buf) = nullptr;
|
||||
int (*sysCallsRename)(const char *currName, const char *dstName);
|
||||
int (*sysCallsScandir)(const char *dirp,
|
||||
struct dirent ***namelist,
|
||||
int (*filter)(const struct dirent *),
|
||||
int (*compar)(const struct dirent **,
|
||||
const struct dirent **)) = nullptr;
|
||||
int (*sysCallsUnlink)(const std::string &pathname) = nullptr;
|
||||
int (*sysCallsStat)(const std::string &filePath, struct stat *statbuf) = nullptr;
|
||||
int (*sysCallsMkstemp)(char *fileName) = nullptr;
|
||||
|
||||
void exit(int code) {
|
||||
exitCalled = true;
|
||||
@@ -91,6 +111,22 @@ int open(const char *file, int flags) {
|
||||
if (strcmp(file, NEO_SHARED_TEST_FILES_DIR "/linux/by-path/pci-0000:00:02.0-render") == 0) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
std::string_view configFile = file;
|
||||
if (configFile.find("config.file") != configFile.npos) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int openWithMode(const char *file, int flags, int mode) {
|
||||
if (sysCallsOpenWithMode != nullptr) {
|
||||
return sysCallsOpenWithMode(file, flags, mode);
|
||||
}
|
||||
std::string_view configFile = file;
|
||||
if (configFile.find("config.file") != configFile.npos) {
|
||||
return fakeFileDescriptor;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -288,5 +324,66 @@ char *realpath(const char *path, char *buf) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int mkstemp(char *fileName) {
|
||||
mkstempCalled++;
|
||||
|
||||
if (sysCallsMkstemp != nullptr) {
|
||||
return sysCallsMkstemp(fileName);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flock(int fd, int flag) {
|
||||
flockCalled++;
|
||||
|
||||
if (fd > 0 && flockRetVal == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
int rename(const char *currName, const char *dstName) {
|
||||
renameCalled++;
|
||||
|
||||
if (sysCallsRename != nullptr) {
|
||||
return sysCallsRename(currName, dstName);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scandir(const char *dirp,
|
||||
struct dirent ***namelist,
|
||||
int (*filter)(const struct dirent *),
|
||||
int (*compar)(const struct dirent **,
|
||||
const struct dirent **)) {
|
||||
scandirCalled++;
|
||||
|
||||
if (sysCallsScandir != nullptr) {
|
||||
return sysCallsScandir(dirp, namelist, filter, compar);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unlink(const std::string &pathname) {
|
||||
unlinkCalled++;
|
||||
|
||||
if (sysCallsUnlink != nullptr) {
|
||||
return sysCallsUnlink(pathname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stat(const std::string &filePath, struct stat *statbuf) {
|
||||
if (sysCallsStat != nullptr) {
|
||||
return sysCallsStat(filePath, statbuf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace SysCalls
|
||||
} // namespace NEO
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <dirent.h>
|
||||
#include <iostream>
|
||||
#include <poll.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -16,6 +17,7 @@ namespace NEO {
|
||||
namespace SysCalls {
|
||||
|
||||
extern int (*sysCallsOpen)(const char *pathname, int flags);
|
||||
extern int (*sysCallsOpenWithMode)(const char *pathname, int flags, int mode);
|
||||
extern ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset);
|
||||
extern ssize_t (*sysCallsPwrite)(int fd, const void *buf, size_t count, off_t offset);
|
||||
extern int (*sysCallsReadlink)(const char *path, char *buf, size_t bufsize);
|
||||
@@ -26,7 +28,20 @@ extern ssize_t (*sysCallsWrite)(int fd, void *buf, size_t count);
|
||||
extern int (*sysCallsPipe)(int pipeFd[2]);
|
||||
extern int (*sysCallsFstat)(int fd, struct stat *buf);
|
||||
extern char *(*sysCallsRealpath)(const char *path, char *buf);
|
||||
extern ssize_t (*sysCallsPwrite)(int fd, const void *buf, size_t count, off_t offset);
|
||||
extern int (*sysCallsRename)(const char *currName, const char *dstName);
|
||||
extern int (*sysCallsScandir)(const char *dirp,
|
||||
struct dirent ***namelist,
|
||||
int (*filter)(const struct dirent *),
|
||||
int (*compar)(const struct dirent **,
|
||||
const struct dirent **));
|
||||
extern int (*sysCallsUnlink)(const std::string &pathname);
|
||||
extern int (*sysCallsStat)(const std::string &filePath, struct stat *statbuf);
|
||||
extern int (*sysCallsMkstemp)(char *fileName);
|
||||
|
||||
extern int flockRetVal;
|
||||
extern int closeFuncRetVal;
|
||||
extern int closeFuncArgPassed;
|
||||
extern const char *drmVersion;
|
||||
constexpr int fakeFileDescriptor = 123;
|
||||
extern int passedFileDescriptorFlagsToSet;
|
||||
@@ -35,6 +50,12 @@ extern int setFileDescriptorFlagsCalled;
|
||||
extern uint32_t closeFuncCalled;
|
||||
extern bool exitCalled;
|
||||
extern int latestExitCode;
|
||||
extern int unlinkCalled;
|
||||
extern int scandirCalled;
|
||||
extern int mkstempCalled;
|
||||
extern int renameCalled;
|
||||
extern int pathFileExistsCalled;
|
||||
extern int flockCalled;
|
||||
|
||||
extern std::vector<void *> mmapVector;
|
||||
extern std::vector<void *> mmapCapturedExtendedPointers;
|
||||
|
||||
Reference in New Issue
Block a user