mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 15:53:45 +08:00
[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:
committed by
Compute-Runtime-Automation
parent
f7cf09d195
commit
b180a83a24
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user