[Sysman] Add support to control lifetime of file descriptor

This patch adds support to open and close the drm fd,
so that more granular control of drm fd could be
achieved.

Related-To: LOCI-3986

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2023-03-01 09:29:12 +00:00
committed by Compute-Runtime-Automation
parent f7cf09d195
commit b180a83a24
19 changed files with 229 additions and 28 deletions

View File

@@ -484,10 +484,10 @@ int Drm::setupHardwareInfo(const DeviceDescriptor *device, bool setupFeatureTabl
return 0;
}
void appendHwDeviceId(std::vector<std::unique_ptr<HwDeviceId>> &hwDeviceIds, int fileDescriptor, const char *pciPath) {
void appendHwDeviceId(std::vector<std::unique_ptr<HwDeviceId>> &hwDeviceIds, int fileDescriptor, const char *pciPath, const char *devNodePath) {
if (fileDescriptor >= 0) {
if (Drm::isDrmSupported(fileDescriptor)) {
hwDeviceIds.push_back(std::make_unique<HwDeviceIdDrm>(fileDescriptor, pciPath));
hwDeviceIds.push_back(std::make_unique<HwDeviceIdDrm>(fileDescriptor, pciPath, devNodePath));
} else {
SysCalls::close(fileDescriptor);
}
@@ -524,7 +524,7 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
auto pciPath = NEO::getPciPath(fileDescriptor);
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.value_or("0000:00:02.0").c_str());
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.value_or("0000:00:02.0").c_str(), path.c_str());
if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) {
break;
}
@@ -564,7 +564,7 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
}
}
int fileDescriptor = SysCalls::open(file->c_str(), O_RDWR);
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.c_str());
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.c_str(), file->c_str());
if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) {
break;
}

View File

@@ -102,7 +102,6 @@ class Drm : public DriverModel {
MOCKABLE_VIRTUAL void checkPreemptionSupport();
inline int getFileDescriptor() const { return hwDeviceId->getFileDescriptor(); }
inline void closeFileDescriptor() const { return hwDeviceId->closeFileDescriptor(); }
ADAPTER_BDF getAdapterBDF() const {
return adapterBDF;
}
@@ -259,6 +258,7 @@ class Drm : public DriverModel {
void cleanup() override;
bool readSysFsAsString(const std::string &relativeFilePath, std::string &readString);
MOCKABLE_VIRTUAL std::string getSysFsPciPath();
std::unique_ptr<HwDeviceIdDrm> &getHwDeviceId() { return hwDeviceId; }
protected:
Drm(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);

View File

@@ -19,13 +19,17 @@ class HwDeviceIdDrm : public HwDeviceId {
HwDeviceIdDrm(int fileDescriptorIn, const char *pciPathIn)
: HwDeviceId(DriverModelType::DRM),
fileDescriptor(fileDescriptorIn), pciPath(pciPathIn) {}
HwDeviceIdDrm(int fileDescriptorIn, const char *pciPathIn, const char *devNodePathIn)
: HwDeviceId(DriverModelType::DRM),
fileDescriptor(fileDescriptorIn), pciPath(pciPathIn), devNodePath(devNodePathIn) {}
~HwDeviceIdDrm() override;
int getFileDescriptor() const { return fileDescriptor; }
void closeFileDescriptor();
const char *getPciPath() const { return pciPath.c_str(); }
const char *getDeviceNode() const { return devNodePath.c_str(); }
protected:
int fileDescriptor;
const std::string pciPath;
const std::string devNodePath;
};
} // namespace NEO

View File

@@ -10,15 +10,8 @@
namespace NEO {
void HwDeviceIdDrm::closeFileDescriptor() {
if (fileDescriptor > 0) {
SysCalls::close(fileDescriptor);
fileDescriptor = -1;
}
}
HwDeviceIdDrm::~HwDeviceIdDrm() {
closeFileDescriptor();
SysCalls::close(fileDescriptor);
}
} // namespace NEO