From e1a1e961100d78ece817f4928d920ec778fe0df8 Mon Sep 17 00:00:00 2001 From: T J Vivek Vilvaraj Date: Tue, 9 Nov 2021 14:12:15 +0000 Subject: [PATCH] sysman:close diagnostics handles before reset Relates-to:LOCI-2650 Signed-off-by: T J Vivek Vilvaraj --- .../source/sysman/diagnostics/diagnostics.cpp | 5 +++- .../source/sysman/diagnostics/diagnostics.h | 1 + .../tools/source/sysman/firmware/firmware.cpp | 5 +++- .../tools/source/sysman/firmware/firmware.h | 1 + .../linux/os_global_operations_imp.cpp | 21 +++++++++------ .../linux/os_global_operations_imp.h | 2 -- .../source/sysman/linux/os_sysman_imp.cpp | 27 +++++++++++++++---- .../tools/source/sysman/linux/os_sysman_imp.h | 2 ++ 8 files changed, 47 insertions(+), 17 deletions(-) diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp b/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp index cf35d6d2f1..87afe6b31d 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics.cpp @@ -12,12 +12,15 @@ namespace L0 { class OsDiagnostics; DiagnosticsHandleContext::~DiagnosticsHandleContext() { + releaseDiagnosticsHandles(); +} + +void DiagnosticsHandleContext::releaseDiagnosticsHandles() { for (Diagnostics *pDiagnostics : handleList) { delete pDiagnostics; } handleList.clear(); } - void DiagnosticsHandleContext::createHandle(ze_device_handle_t deviceHandle, const std::string &diagTests) { Diagnostics *pDiagnostics = new DiagnosticsImp(pOsSysman, diagTests, deviceHandle); handleList.push_back(pDiagnostics); diff --git a/level_zero/tools/source/sysman/diagnostics/diagnostics.h b/level_zero/tools/source/sysman/diagnostics/diagnostics.h index 0c84b5aa30..f459d6bfae 100644 --- a/level_zero/tools/source/sysman/diagnostics/diagnostics.h +++ b/level_zero/tools/source/sysman/diagnostics/diagnostics.h @@ -35,6 +35,7 @@ class Diagnostics : _zes_diag_handle_t { struct DiagnosticsHandleContext { DiagnosticsHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; + void releaseDiagnosticsHandles(); ~DiagnosticsHandleContext(); void init(std::vector &deviceHandles); diff --git a/level_zero/tools/source/sysman/firmware/firmware.cpp b/level_zero/tools/source/sysman/firmware/firmware.cpp index 65eb0cdcf7..a1f7ebf5cf 100644 --- a/level_zero/tools/source/sysman/firmware/firmware.cpp +++ b/level_zero/tools/source/sysman/firmware/firmware.cpp @@ -12,12 +12,15 @@ namespace L0 { class OsFirmware; FirmwareHandleContext::~FirmwareHandleContext() { + releaseFwHandles(); +} + +void FirmwareHandleContext::releaseFwHandles() { for (Firmware *pFirmware : handleList) { delete pFirmware; } handleList.clear(); } - void FirmwareHandleContext::createHandle(const std::string &fwType) { Firmware *pFirmware = new FirmwareImp(pOsSysman, fwType); if (pFirmware->isFirmwareEnabled == true) { diff --git a/level_zero/tools/source/sysman/firmware/firmware.h b/level_zero/tools/source/sysman/firmware/firmware.h index c9102d4906..cf809e04d9 100644 --- a/level_zero/tools/source/sysman/firmware/firmware.h +++ b/level_zero/tools/source/sysman/firmware/firmware.h @@ -36,6 +36,7 @@ class Firmware : _zes_firmware_handle_t { struct FirmwareHandleContext { FirmwareHandleContext(OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; ~FirmwareHandleContext(); + void releaseFwHandles(); void init(); diff --git a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp index 977118e4ba..7a35718d2b 100644 --- a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp +++ b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp @@ -124,7 +124,10 @@ static void getPidFdsForOpenDevice(ProcfsAccess *pProcfsAccess, SysfsAccess *pSy void LinuxGlobalOperationsImp::releaseSysmanDeviceResources() { pLinuxSysmanImp->getSysmanDeviceImp()->pEngineHandleContext->releaseEngines(); pLinuxSysmanImp->getSysmanDeviceImp()->pRasHandleContext->releaseRasHandles(); + pLinuxSysmanImp->getSysmanDeviceImp()->pDiagnosticsHandleContext->releaseDiagnosticsHandles(); + pLinuxSysmanImp->getSysmanDeviceImp()->pFirmwareHandleContext->releaseFwHandles(); pLinuxSysmanImp->releasePmtObject(); + pLinuxSysmanImp->releaseFwUtilInterface(); pLinuxSysmanImp->releaseLocalDrmHandle(); } @@ -140,8 +143,11 @@ void LinuxGlobalOperationsImp::releaseDeviceResources() { void LinuxGlobalOperationsImp::reInitSysmanDeviceResources() { pLinuxSysmanImp->getSysmanDeviceImp()->updateSubDeviceHandlesLocally(); pLinuxSysmanImp->createPmtHandles(); + pLinuxSysmanImp->createFwUtilInterface(); pLinuxSysmanImp->getSysmanDeviceImp()->pRasHandleContext->init(pLinuxSysmanImp->getSysmanDeviceImp()->deviceHandles); pLinuxSysmanImp->getSysmanDeviceImp()->pEngineHandleContext->init(); + pLinuxSysmanImp->getSysmanDeviceImp()->pDiagnosticsHandleContext->init(pLinuxSysmanImp->getSysmanDeviceImp()->deviceHandles); + pLinuxSysmanImp->getSysmanDeviceImp()->pFirmwareHandleContext->init(); } ze_result_t LinuxGlobalOperationsImp::initDevice() { @@ -322,9 +328,9 @@ ze_result_t LinuxGlobalOperationsImp::scanProcessesState(std::vectorscanDirEntries(busyDirForEngines, engineNums); if (ZE_RESULT_SUCCESS != result) { if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) { - //update the result as Success as ZE_RESULT_ERROR_NOT_AVAILABLE is expected if the "realClientPidPath" folder is empty - //this condition(when encountered) must not prevent the information accumulated for other clientIds - //this situation occurs when there is no call modifying result, - //Here its seen when the last element of clientIds returns ZE_RESULT_ERROR_NOT_AVAILABLE for some reason. + // update the result as Success as ZE_RESULT_ERROR_NOT_AVAILABLE is expected if the "realClientPidPath" folder is empty + // this condition(when encountered) must not prevent the information accumulated for other clientIds + // this situation occurs when there is no call modifying result, + // Here its seen when the last element of clientIds returns ZE_RESULT_ERROR_NOT_AVAILABLE for some reason. engineType = ZES_ENGINE_TYPE_FLAG_OTHER; // When busy node is absent assign engine type with ZES_ENGINE_TYPE_FLAG_OTHER } else { return result; @@ -444,7 +450,6 @@ LinuxGlobalOperationsImp::LinuxGlobalOperationsImp(OsSysman *pOsSysman) { pProcfsAccess = &pLinuxSysmanImp->getProcfsAccess(); pFsAccess = &pLinuxSysmanImp->getFsAccess(); pDevice = pLinuxSysmanImp->getDeviceHandle(); - pFwInterface = pLinuxSysmanImp->getFwUtilInterface(); auto device = static_cast(pDevice); devicePciBdf = device->getNEODevice()->getRootDeviceEnvironment().osInterface->getDriverModel()->as()->getPciPath(); executionEnvironment = device->getNEODevice()->getExecutionEnvironment(); diff --git a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.h b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.h index a911b9da0d..67b3aa2498 100644 --- a/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.h +++ b/level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.h @@ -37,8 +37,6 @@ class LinuxGlobalOperationsImp : public OsGlobalOperations, NEO::NonCopyableOrMo SysfsAccess *pSysfsAccess = nullptr; LinuxSysmanImp *pLinuxSysmanImp = nullptr; Device *pDevice = nullptr; - FirmwareUtil *pFwInterface = nullptr; - int resetTimeout = 10000; // in milliseconds void releaseSysmanDeviceResources(); void releaseDeviceResources(); diff --git a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp index 8e4cc1dc9a..ac85c87103 100644 --- a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp +++ b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp @@ -9,6 +9,8 @@ #include "level_zero/tools/source/sysman/linux/fs_access.h" +#include "sysman/linux/firmware_util/firmware_util.h" + namespace L0 { ze_result_t LinuxSysmanImp::init() { @@ -39,10 +41,22 @@ ze_result_t LinuxSysmanImp::init() { pPmuInterface = PmuInterface::create(this); DEBUG_BREAK_IF(nullptr == pPmuInterface); - pFwUtilInterface = FirmwareUtil::create(pDrm->getPciPath()); + + createFwUtilInterface(); return createPmtHandles(); } +void LinuxSysmanImp::createFwUtilInterface() { + std::string realRootPath; + auto result = pSysfsAccess->getRealPath("device", realRootPath); + if (ZE_RESULT_SUCCESS != result) { + return; + } + auto rootPciPathOfGpuDevice = getPciRootPortDirectoryPath(realRootPath); + auto loc = realRootPath.find_last_of('/'); + pFwUtilInterface = FirmwareUtil::create(realRootPath.substr(loc + 1, std::string::npos)); +} + ze_result_t LinuxSysmanImp::createPmtHandles() { std::string realRootPath; auto result = pSysfsAccess->getRealPath("device", realRootPath); @@ -146,6 +160,12 @@ void LinuxSysmanImp::releasePmtObject() { } mapOfSubDeviceIdToPmtObject.clear(); } +void LinuxSysmanImp::releaseFwUtilInterface() { + if (nullptr != pFwUtilInterface) { + delete pFwUtilInterface; + pFwUtilInterface = nullptr; + } +} LinuxSysmanImp::~LinuxSysmanImp() { if (nullptr != pSysfsAccess) { @@ -160,14 +180,11 @@ LinuxSysmanImp::~LinuxSysmanImp() { delete pFsAccess; pFsAccess = nullptr; } - if (nullptr != pFwUtilInterface) { - delete pFwUtilInterface; - pFwUtilInterface = nullptr; - } if (nullptr != pPmuInterface) { delete pPmuInterface; pPmuInterface = nullptr; } + releaseFwUtilInterface(); releasePmtObject(); } diff --git a/level_zero/tools/source/sysman/linux/os_sysman_imp.h b/level_zero/tools/source/sysman/linux/os_sysman_imp.h index 6bbdd69792..8bcca80911 100644 --- a/level_zero/tools/source/sysman/linux/os_sysman_imp.h +++ b/level_zero/tools/source/sysman/linux/os_sysman_imp.h @@ -41,6 +41,8 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass { std::string getPciRootPortDirectoryPath(std::string realPciPath); void releasePmtObject(); ze_result_t createPmtHandles(); + void createFwUtilInterface(); + void releaseFwUtilInterface(); void releaseLocalDrmHandle(); protected: