mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +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
@@ -10,6 +10,8 @@ set(L0_SRCS_SYSMAN_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fs_access.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fs_access.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.h
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
|
||||
52
level_zero/sysman/source/linux/hw_device_id_linux.cpp
Normal file
52
level_zero/sysman/source/linux/hw_device_id_linux.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/sysman/source/linux/hw_device_id_linux.h"
|
||||
|
||||
#include "shared/source/os_interface/linux/sys_calls.h"
|
||||
|
||||
#include "level_zero/sysman/source/sysman_hw_device_id.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
|
||||
int SysmanHwDeviceIdDrm::openFileDescriptor() {
|
||||
|
||||
std::unique_lock<std::mutex> lock(fdMutex);
|
||||
if (fileDescriptor == -1) {
|
||||
fileDescriptor = NEO::SysCalls::open(devNodePath.c_str(), O_RDWR);
|
||||
}
|
||||
++fdRefCounter;
|
||||
return fileDescriptor;
|
||||
}
|
||||
|
||||
int SysmanHwDeviceIdDrm::closeFileDescriptor() {
|
||||
|
||||
int closeStatus = 0;
|
||||
std::unique_lock<std::mutex> lock(fdMutex);
|
||||
|
||||
DEBUG_BREAK_IF(fdRefCounter == 0u);
|
||||
if (fdRefCounter > 0u) {
|
||||
--fdRefCounter;
|
||||
if (fdRefCounter == 0u && fileDescriptor >= 0) {
|
||||
closeStatus = NEO::SysCalls::close(fileDescriptor);
|
||||
fileDescriptor = -1;
|
||||
}
|
||||
}
|
||||
return closeStatus;
|
||||
}
|
||||
|
||||
std::unique_ptr<NEO::HwDeviceId> createSysmanHwDeviceId(std::unique_ptr<NEO::HwDeviceId> &hwDeviceId) {
|
||||
|
||||
const auto hwDeviceIdDrm = static_cast<NEO::HwDeviceIdDrm *>(hwDeviceId.get());
|
||||
return std::make_unique<SysmanHwDeviceIdDrm>(hwDeviceIdDrm->getFileDescriptor(), hwDeviceIdDrm->getPciPath(), hwDeviceIdDrm->getDeviceNode());
|
||||
}
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
29
level_zero/sysman/source/linux/hw_device_id_linux.h
Normal file
29
level_zero/sysman/source/linux/hw_device_id_linux.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/os_interface/linux/hw_device_id.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
class SysmanHwDeviceIdDrm : public NEO::HwDeviceIdDrm {
|
||||
|
||||
public:
|
||||
using NEO::HwDeviceIdDrm::HwDeviceIdDrm;
|
||||
SysmanHwDeviceIdDrm() = delete;
|
||||
int openFileDescriptor();
|
||||
int closeFileDescriptor();
|
||||
|
||||
private:
|
||||
std::mutex fdMutex{};
|
||||
uint32_t fdRefCounter = 0;
|
||||
};
|
||||
|
||||
} // namespace Sysman
|
||||
} // namespace L0
|
||||
@@ -33,8 +33,9 @@ ze_result_t LinuxSysmanImp::init() {
|
||||
if (osInterface.getDriverModel()->getDriverModelType() != NEO::DriverModelType::DRM) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
auto pDrm = osInterface.getDriverModel()->as<NEO::Drm>();
|
||||
int myDeviceFd = pDrm->getFileDescriptor();
|
||||
auto sysmanHwDeviceId = getSysmanHwDeviceId();
|
||||
sysmanHwDeviceId->openFileDescriptor();
|
||||
int myDeviceFd = sysmanHwDeviceId->getFileDescriptor();
|
||||
std::string myDeviceName;
|
||||
result = pProcfsAccess->getFileName(pProcfsAccess->myProcessId(), myDeviceFd, myDeviceName);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
@@ -53,10 +54,19 @@ ze_result_t LinuxSysmanImp::init() {
|
||||
|
||||
osInterface.getDriverModel()->as<NEO::Drm>()->cleanup();
|
||||
// Close Drm handles
|
||||
pDrm->closeFileDescriptor();
|
||||
sysmanHwDeviceId->closeFileDescriptor();
|
||||
return createPmtHandles();
|
||||
}
|
||||
|
||||
SysmanHwDeviceIdDrm *LinuxSysmanImp::getSysmanHwDeviceId() {
|
||||
return static_cast<SysmanHwDeviceIdDrm *>(getDrm()->getHwDeviceId().get());
|
||||
}
|
||||
|
||||
NEO::Drm *LinuxSysmanImp::getDrm() {
|
||||
const auto &osInterface = *pParentSysmanDeviceImp->getRootDeviceEnvironment().osInterface;
|
||||
return osInterface.getDriverModel()->as<NEO::Drm>();
|
||||
}
|
||||
|
||||
ze_result_t LinuxSysmanImp::createPmtHandles() {
|
||||
std::string gtDevicePCIPath;
|
||||
auto result = pSysfsAccess->getRealPath("device", gtDevicePCIPath);
|
||||
|
||||
@@ -9,11 +9,16 @@
|
||||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/sysman/source/linux/hw_device_id_linux.h"
|
||||
#include "level_zero/sysman/source/os_sysman.h"
|
||||
#include "level_zero/sysman/source/sysman_device_imp.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace NEO {
|
||||
class Drm;
|
||||
} // namespace NEO
|
||||
|
||||
namespace L0 {
|
||||
namespace Sysman {
|
||||
class PlatformMonitoringTech;
|
||||
@@ -36,6 +41,8 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
std::string getPciCardBusDirectoryPath(std::string realPciPath);
|
||||
PlatformMonitoringTech *getPlatformMonitoringTechAccess(uint32_t subDeviceId);
|
||||
PRODUCT_FAMILY getProductFamily() const { return pParentSysmanDeviceImp->getProductFamily(); }
|
||||
SysmanHwDeviceIdDrm *getSysmanHwDeviceId();
|
||||
NEO::Drm *getDrm();
|
||||
void releasePmtObject();
|
||||
ze_result_t createPmtHandles();
|
||||
std::string devicePciBdf = "";
|
||||
|
||||
Reference in New Issue
Block a user