From 061af9c2840dda7182112f3ce7e42dc76dab95c9 Mon Sep 17 00:00:00 2001 From: Bellekallu Rajkiran Date: Wed, 9 Mar 2022 05:50:57 +0000 Subject: [PATCH] Sysman : Add check on engine handle creation Add check whether init succeeded on handle creation. Related-To: LOCI-3005 Signed-off-by: Bellekallu Rajkiran --- level_zero/tools/source/sysman/engine/engine.cpp | 8 ++++++-- level_zero/tools/source/sysman/engine/engine.h | 3 ++- level_zero/tools/source/sysman/engine/engine_imp.cpp | 7 +++++-- .../tools/source/sysman/engine/linux/os_engine_imp.cpp | 7 +++++++ .../tools/source/sysman/engine/linux/os_engine_imp.h | 3 ++- .../source/sysman/engine/linux/os_engine_imp_prelim.cpp | 7 +++++++ level_zero/tools/source/sysman/engine/os_engine.h | 3 ++- .../tools/source/sysman/engine/windows/os_engine_imp.cpp | 6 +++++- .../tools/source/sysman/engine/windows/os_engine_imp.h | 3 ++- 9 files changed, 38 insertions(+), 9 deletions(-) diff --git a/level_zero/tools/source/sysman/engine/engine.cpp b/level_zero/tools/source/sysman/engine/engine.cpp index d7945b2be0ee1..b4a6c4e0a5084 100644 --- a/level_zero/tools/source/sysman/engine/engine.cpp +++ b/level_zero/tools/source/sysman/engine/engine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -24,7 +24,11 @@ EngineHandleContext::~EngineHandleContext() { void EngineHandleContext::createHandle(zes_engine_group_t engineType, uint32_t engineInstance, uint32_t subDeviceId) { Engine *pEngine = new EngineImp(pOsSysman, engineType, engineInstance, subDeviceId); - handleList.push_back(pEngine); + if (pEngine->initSuccess == true) { + handleList.push_back(pEngine); + } else { + delete pEngine; + } } void EngineHandleContext::init() { diff --git a/level_zero/tools/source/sysman/engine/engine.h b/level_zero/tools/source/sysman/engine/engine.h index e1a97bc617048..099942c75fa30 100644 --- a/level_zero/tools/source/sysman/engine/engine.h +++ b/level_zero/tools/source/sysman/engine/engine.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -28,6 +28,7 @@ class Engine : _zes_engine_handle_t { return static_cast(handle); } inline zes_engine_handle_t toHandle() { return this; } + bool initSuccess = false; }; struct EngineHandleContext { diff --git a/level_zero/tools/source/sysman/engine/engine_imp.cpp b/level_zero/tools/source/sysman/engine/engine_imp.cpp index 81da320d7775c..9c5f7ad69cd17 100644 --- a/level_zero/tools/source/sysman/engine/engine_imp.cpp +++ b/level_zero/tools/source/sysman/engine/engine_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,7 +20,10 @@ ze_result_t EngineImp::engineGetProperties(zes_engine_properties_t *pProperties) } void EngineImp::init() { - pOsEngine->getProperties(engineProperties); + if (pOsEngine->isEngineModuleSupported()) { + pOsEngine->getProperties(engineProperties); + this->initSuccess = true; + } } EngineImp::EngineImp(OsSysman *pOsSysman, zes_engine_group_t engineType, uint32_t engineInstance, uint32_t subDeviceId) { diff --git a/level_zero/tools/source/sysman/engine/linux/os_engine_imp.cpp b/level_zero/tools/source/sysman/engine/linux/os_engine_imp.cpp index 690605ff69903..3de161dbb6562 100644 --- a/level_zero/tools/source/sysman/engine/linux/os_engine_imp.cpp +++ b/level_zero/tools/source/sysman/engine/linux/os_engine_imp.cpp @@ -72,6 +72,13 @@ void LinuxEngineImp::init() { fd = pPmuInterface->pmuInterfaceOpen(I915_PMU_ENGINE_BUSY(i915EngineClass->second, engineInstance), -1, PERF_FORMAT_TOTAL_TIME_ENABLED); } +bool LinuxEngineImp::isEngineModuleSupported() { + if (fd < 0) { + return false; + } + return true; +} + LinuxEngineImp::LinuxEngineImp(OsSysman *pOsSysman, zes_engine_group_t type, uint32_t engineInstance, uint32_t subDeviceId) : engineGroup(type), engineInstance(engineInstance), subDeviceId(subDeviceId) { LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); pDrm = &pLinuxSysmanImp->getDrm(); diff --git a/level_zero/tools/source/sysman/engine/linux/os_engine_imp.h b/level_zero/tools/source/sysman/engine/linux/os_engine_imp.h index e3eb255bb5e0a..ccb6eb0a687a4 100644 --- a/level_zero/tools/source/sysman/engine/linux/os_engine_imp.h +++ b/level_zero/tools/source/sysman/engine/linux/os_engine_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,6 +19,7 @@ class LinuxEngineImp : public OsEngine, NEO::NonCopyableOrMovableClass { public: ze_result_t getActivity(zes_engine_stats_t *pStats) override; ze_result_t getProperties(zes_engine_properties_t &properties) override; + bool isEngineModuleSupported() override; static zes_engine_group_t getGroupFromEngineType(zes_engine_group_t type); LinuxEngineImp() = default; LinuxEngineImp(OsSysman *pOsSysman, zes_engine_group_t type, uint32_t engineInstance, uint32_t subDeviceId); diff --git a/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp b/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp index e359ace525246..86103c5444cb6 100644 --- a/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp +++ b/level_zero/tools/source/sysman/engine/linux/os_engine_imp_prelim.cpp @@ -115,6 +115,13 @@ void LinuxEngineImp::init() { fd = pPmuInterface->pmuInterfaceOpen(config, -1, PERF_FORMAT_TOTAL_TIME_ENABLED); } +bool LinuxEngineImp::isEngineModuleSupported() { + if (fd < 0) { + return false; + } + return true; +} + LinuxEngineImp::LinuxEngineImp(OsSysman *pOsSysman, zes_engine_group_t type, uint32_t engineInstance, uint32_t subDeviceId) : engineGroup(type), engineInstance(engineInstance), subDeviceId(subDeviceId) { LinuxSysmanImp *pLinuxSysmanImp = static_cast(pOsSysman); pDrm = &pLinuxSysmanImp->getDrm(); diff --git a/level_zero/tools/source/sysman/engine/os_engine.h b/level_zero/tools/source/sysman/engine/os_engine.h index bd8555d52bd41..a60f826df236d 100644 --- a/level_zero/tools/source/sysman/engine/os_engine.h +++ b/level_zero/tools/source/sysman/engine/os_engine.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,6 +21,7 @@ class OsEngine { public: virtual ze_result_t getActivity(zes_engine_stats_t *pStats) = 0; virtual ze_result_t getProperties(zes_engine_properties_t &properties) = 0; + virtual bool isEngineModuleSupported() = 0; static OsEngine *create(OsSysman *pOsSysman, zes_engine_group_t engineType, uint32_t engineInstance, uint32_t subDeviceId); static ze_result_t getNumEngineTypeAndInstances(std::set> &engineGroupInstance, OsSysman *pOsSysman); virtual ~OsEngine() = default; diff --git a/level_zero/tools/source/sysman/engine/windows/os_engine_imp.cpp b/level_zero/tools/source/sysman/engine/windows/os_engine_imp.cpp index 796d39e196a6e..1f6a91a620dd8 100644 --- a/level_zero/tools/source/sysman/engine/windows/os_engine_imp.cpp +++ b/level_zero/tools/source/sysman/engine/windows/os_engine_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -57,6 +57,10 @@ ze_result_t WddmEngineImp::getProperties(zes_engine_properties_t &properties) { return ZE_RESULT_SUCCESS; } +bool WddmEngineImp::isEngineModuleSupported() { + return true; +} + WddmEngineImp::WddmEngineImp(OsSysman *pOsSysman, zes_engine_group_t engineType, uint32_t engineInstance, uint32_t subDeviceId) { WddmSysmanImp *pWddmSysmanImp = static_cast(pOsSysman); this->engineGroup = engineType; diff --git a/level_zero/tools/source/sysman/engine/windows/os_engine_imp.h b/level_zero/tools/source/sysman/engine/windows/os_engine_imp.h index d514b1a678bb1..211f49a3ef499 100644 --- a/level_zero/tools/source/sysman/engine/windows/os_engine_imp.h +++ b/level_zero/tools/source/sysman/engine/windows/os_engine_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,6 +17,7 @@ class WddmEngineImp : public OsEngine, NEO::NonCopyableOrMovableClass { public: ze_result_t getActivity(zes_engine_stats_t *pStats) override; ze_result_t getProperties(zes_engine_properties_t &properties) override; + bool isEngineModuleSupported() override; WddmEngineImp() = default; WddmEngineImp(OsSysman *pOsSysman, zes_engine_group_t type, uint32_t engineInstance, uint32_t subDeviceId);