fix: add FileDescriptor class to ensure file descriptor is closed

Related-To: NEO-9038
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-10-09 10:55:30 +00:00
committed by Compute-Runtime-Automation
parent c2d69e5857
commit 099a3f30e3
15 changed files with 139 additions and 217 deletions

View File

@@ -12,6 +12,7 @@
#include "shared/source/helpers/sleep.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/linux/file_descriptor.h"
#include "shared/source/os_interface/linux/system_info.h"
#include "level_zero/core/source/device/device_imp.h"
@@ -391,8 +392,7 @@ ze_result_t LinuxSysmanImp::resizeVfBar(uint8_t size) {
std::string pciConfigNode;
pciConfigNode = gtDevicePath + "/config";
int fdConfig = -1;
fdConfig = this->openFunction(pciConfigNode.c_str(), O_RDWR);
auto fdConfig = NEO::FileDescriptor(pciConfigNode.c_str(), O_RDWR);
if (fdConfig < 0) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
"Config node open failed\n");
@@ -418,11 +418,6 @@ ze_result_t LinuxSysmanImp::resizeVfBar(uint8_t size) {
"Write to change VF bar size failed\n");
return ZE_RESULT_ERROR_UNKNOWN;
}
if (this->closeFunction(fdConfig) < 0) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
"Config node close failed\n");
return ZE_RESULT_ERROR_UNKNOWN;
}
return ZE_RESULT_SUCCESS;
}
@@ -435,9 +430,8 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
std::string rootPortPath;
rootPortPath = getPciRootPortDirectoryPath(gtDevicePath);
int fd = 0;
std::string configFilePath = rootPortPath + '/' + "config";
fd = this->openFunction(configFilePath.c_str(), O_RDWR);
auto fd = NEO::FileDescriptor(configFilePath.c_str(), O_RDWR);
if (fd < 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
@@ -479,11 +473,6 @@ ze_result_t LinuxSysmanImp::osWarmReset() {
}
NEO::sleep(std::chrono::seconds(10)); // Sleep for 10seconds, allows the rescan to complete on all devices attached to the root port.
int ret = this->closeFunction(fd);
if (ret < 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
// PCIe port driver uses the BIOS allocated VF bars on bootup. A known bug exists in pcie port driver
// and is causing VF bar allocation failure in PCIe port driver after an SBR - https://bugzilla.kernel.org/show_bug.cgi?id=216795

View File

@@ -75,8 +75,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
MOCKABLE_VIRTUAL ze_result_t osColdReset();
ze_result_t gpuProcessCleanup();
std::string getAddressFromPath(std::string &rootPortPath);
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
decltype(&NEO::SysCalls::pwrite) pwriteFunction = NEO::SysCalls::pwrite;
std::string devicePciBdf = "";

View File

@@ -9,6 +9,7 @@
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/os_interface/linux/file_descriptor.h"
#include "shared/source/utilities/directory.h"
#include "level_zero/core/source/driver/driver_handle.h"
@@ -294,8 +295,7 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &
return false;
}
int fd = -1;
fd = this->openFunction(pciPath.c_str(), O_RDONLY);
auto fd = NEO::FileDescriptor(pciPath.c_str(), O_RDONLY);
if (fd < 0) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config File Open Failed \n", __FUNCTION__);
return false;
@@ -304,10 +304,6 @@ bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector<uint8_t> &
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config Mem Read Failed \n", __FUNCTION__);
return false;
}
if (this->closeFunction(fd) < 0) {
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s() Config file close Failed \n", __FUNCTION__);
return false;
}
return true;
}