From 2d8176fdbd56b65c330e36134296401cc47717d2 Mon Sep 17 00:00:00 2001 From: "Kulkarni, Ashwin Kumar" Date: Wed, 20 Jul 2022 09:51:46 +0000 Subject: [PATCH] Defer Sysman Fabric Port and Fan Module Initialization With this change, init for sysman Fabric Port/Fan API would not be done during zeInit. init and thereby Fabric Port/Fan API handle creation would be done only when user explicitly requests to enumerate handles using zesDeviceEnumFabricPorts/zesDeviceEnumFans. Also, ECC module init calls are cleared as they are no longer needed. Related-To: LOCI-3127 Signed-off-by: Kulkarni, Ashwin Kumar --- .../tools/source/sysman/fabric_port/fabric_port.cpp | 5 ++++- level_zero/tools/source/sysman/fabric_port/fabric_port.h | 4 ++++ level_zero/tools/source/sysman/fan/fan.cpp | 5 ++++- level_zero/tools/source/sysman/fan/fan.h | 8 ++++++-- level_zero/tools/source/sysman/sysman_imp.cpp | 9 --------- .../unit_tests/sources/sysman/ecc/linux/test_zes_ecc.cpp | 5 ----- .../sources/sysman/ecc/windows/test_zes_ecc.cpp | 5 ----- .../sysman/fabric_port/linux/test_zes_fabric_port.cpp | 1 - .../unit_tests/sources/sysman/fan/linux/test_zes_fan.cpp | 1 - .../sources/sysman/fan/windows/test_zes_sysman_fan.cpp | 1 - 10 files changed, 18 insertions(+), 26 deletions(-) diff --git a/level_zero/tools/source/sysman/fabric_port/fabric_port.cpp b/level_zero/tools/source/sysman/fabric_port/fabric_port.cpp index 37924cf0c5..6a82de64cb 100644 --- a/level_zero/tools/source/sysman/fabric_port/fabric_port.cpp +++ b/level_zero/tools/source/sysman/fabric_port/fabric_port.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -43,6 +43,9 @@ ze_result_t FabricPortHandleContext::init() { } ze_result_t FabricPortHandleContext::fabricPortGet(uint32_t *pCount, zes_fabric_port_handle_t *phPort) { + std::call_once(initFabricPortOnce, [this]() { + this->init(); + }); uint32_t handleListSize = static_cast(handleList.size()); uint32_t numToCopy = std::min(*pCount, handleListSize); if (0 == *pCount || *pCount > handleListSize) { diff --git a/level_zero/tools/source/sysman/fabric_port/fabric_port.h b/level_zero/tools/source/sysman/fabric_port/fabric_port.h index 5718ee3528..2b3d9d0083 100644 --- a/level_zero/tools/source/sysman/fabric_port/fabric_port.h +++ b/level_zero/tools/source/sysman/fabric_port/fabric_port.h @@ -10,6 +10,7 @@ #include +#include #include struct _zes_fabric_port_handle_t { @@ -55,6 +56,9 @@ struct FabricPortHandleContext : NEO::NonCopyableOrMovableClass { FabricDevice *pFabricDevice = nullptr; std::vector handleList = {}; + + private: + std::once_flag initFabricPortOnce; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/fan/fan.cpp b/level_zero/tools/source/sysman/fan/fan.cpp index 804963763a..dab0190624 100644 --- a/level_zero/tools/source/sysman/fan/fan.cpp +++ b/level_zero/tools/source/sysman/fan/fan.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,6 +29,9 @@ void FanHandleContext::init() { } ze_result_t FanHandleContext::fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) { + std::call_once(initFanOnce, [this]() { + this->init(); + }); uint32_t handleListSize = static_cast(handleList.size()); uint32_t numToCopy = std::min(*pCount, handleListSize); if (0 == *pCount || *pCount > handleListSize) { diff --git a/level_zero/tools/source/sysman/fan/fan.h b/level_zero/tools/source/sysman/fan/fan.h index 171b05d796..5df36846f0 100644 --- a/level_zero/tools/source/sysman/fan/fan.h +++ b/level_zero/tools/source/sysman/fan/fan.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #pragma once #include +#include #include struct _zes_fan_handle_t { @@ -42,6 +43,9 @@ struct FanHandleContext { OsSysman *pOsSysman = nullptr; std::vector handleList = {}; + + private: + std::once_flag initFanOnce; }; -} // namespace L0 \ No newline at end of file +} // namespace L0 diff --git a/level_zero/tools/source/sysman/sysman_imp.cpp b/level_zero/tools/source/sysman/sysman_imp.cpp index 7f4b8bdfbb..bd3e0bc2ec 100644 --- a/level_zero/tools/source/sysman/sysman_imp.cpp +++ b/level_zero/tools/source/sysman/sysman_imp.cpp @@ -100,9 +100,6 @@ ze_result_t SysmanDeviceImp::init() { if (pPowerHandleContext) { pPowerHandleContext->init(deviceHandles, hCoreDevice); } - if (pFabricPortHandleContext) { - pFabricPortHandleContext->init(); - } if (pPci) { pPci->init(); } @@ -121,15 +118,9 @@ ze_result_t SysmanDeviceImp::init() { if (pEvents) { pEvents->init(); } - if (pFanHandleContext) { - pFanHandleContext->init(); - } if (pPerformanceHandleContext) { pPerformanceHandleContext->init(deviceHandles, hCoreDevice); } - if (pEcc) { - pEcc->init(); - } return result; } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/ecc/linux/test_zes_ecc.cpp b/level_zero/tools/test/unit_tests/sources/sysman/ecc/linux/test_zes_ecc.cpp index f6a5ce377a..df275c36c8 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/ecc/linux/test_zes_ecc.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/ecc/linux/test_zes_ecc.cpp @@ -33,8 +33,6 @@ class ZesEccFixture : public SysmanDeviceFixture { pLinuxSysmanImp->pFwUtilInterface = pMockFwInterface.get(); pEccImp = static_cast(pSysmanDeviceImp->pEcc); - - pEccImp->init(); } void TearDown() override { @@ -51,7 +49,6 @@ class ZesEccFixture : public SysmanDeviceFixture { TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceEccAvailableThenVerifyApiCallSucceeds) { ze_bool_t eccAvailable = false; - pEccImp->init(); EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccAvailable(device, &eccAvailable)); EXPECT_EQ(true, eccAvailable); } @@ -59,7 +56,6 @@ TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingze TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceEccConfigurableThenVerifyApiCallSucceeds) { ze_bool_t eccConfigurable = false; - pEccImp->init(); EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccConfigurable(device, &eccConfigurable)); EXPECT_EQ(true, eccConfigurable); } @@ -88,7 +84,6 @@ TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwDeviceInitFailsThenVerifyApiCal pMockFwInterface->mockFwDeviceInit = ZE_RESULT_ERROR_UNKNOWN; EccImp *tempEccImp = new EccImp(pOsSysman); - tempEccImp->init(); EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccAvailable(&eccAvailable)); EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccConfigurable(&eccConfigurable)); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/ecc/windows/test_zes_ecc.cpp b/level_zero/tools/test/unit_tests/sources/sysman/ecc/windows/test_zes_ecc.cpp index 9fe7611c7b..076a3131d4 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/ecc/windows/test_zes_ecc.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/ecc/windows/test_zes_ecc.cpp @@ -34,8 +34,6 @@ class ZesEccFixture : public SysmanDeviceFixture { pWddmSysmanImp->pFwUtilInterface = pMockFwInterface.get(); pEccImp = static_cast(pSysmanDeviceImp->pEcc); - - pEccImp->init(); } void TearDown() override { @@ -52,7 +50,6 @@ class ZesEccFixture : public SysmanDeviceFixture { TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceEccAvailableThenVerifyApiCallSucceeds) { ze_bool_t eccAvailable = false; - pEccImp->init(); EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccAvailable(device, &eccAvailable)); EXPECT_EQ(true, eccAvailable); } @@ -60,7 +57,6 @@ TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingze TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwInterfaceIsPresentWhenCallingzesDeviceEccConfigurableThenVerifyApiCallSucceeds) { ze_bool_t eccConfigurable = false; - pEccImp->init(); EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEccConfigurable(device, &eccConfigurable)); EXPECT_EQ(true, eccConfigurable); } @@ -89,7 +85,6 @@ TEST_F(ZesEccFixture, GivenValidSysmanHandleAndFwDeviceInitFailsThenVerifyApiCal pMockFwInterface->mockFwDeviceInit = ZE_RESULT_ERROR_UNKNOWN; EccImp *tempEccImp = new EccImp(pOsSysman); - tempEccImp->init(); EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccAvailable(&eccAvailable)); EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, tempEccImp->deviceEccConfigurable(&eccConfigurable)); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/fabric_port/linux/test_zes_fabric_port.cpp b/level_zero/tools/test/unit_tests/sources/sysman/fabric_port/linux/test_zes_fabric_port.cpp index c0e9b43bd2..c02a229fd0 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/fabric_port/linux/test_zes_fabric_port.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/fabric_port/linux/test_zes_fabric_port.cpp @@ -43,7 +43,6 @@ class ZesFabricPortFixture : public SysmanDeviceFixture { .WillByDefault(Return(numPorts)); pFabricPortHandleContext->pFabricDevice = mockFabricDevice; - pFabricPortHandleContext->init(); } void TearDown() override { if (!sysmanUltsEnable) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/fan/linux/test_zes_fan.cpp b/level_zero/tools/test/unit_tests/sources/sysman/fan/linux/test_zes_fan.cpp index 228d4cb2b8..501fe02561 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/fan/linux/test_zes_fan.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/fan/linux/test_zes_fan.cpp @@ -23,7 +23,6 @@ class SysmanDeviceFanFixture : public SysmanDeviceFixture { GTEST_SKIP(); } SysmanDeviceFixture::SetUp(); - pSysmanDeviceImp->pFanHandleContext->init(); } void TearDown() override { if (!sysmanUltsEnable) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/fan/windows/test_zes_sysman_fan.cpp b/level_zero/tools/test/unit_tests/sources/sysman/fan/windows/test_zes_sysman_fan.cpp index 9d2a074ce0..734b83ed92 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/fan/windows/test_zes_sysman_fan.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/fan/windows/test_zes_sysman_fan.cpp @@ -44,7 +44,6 @@ class SysmanDeviceFanFixture : public SysmanDeviceFixture { } pSysmanDeviceImp->pFanHandleContext->handleList.clear(); - pSysmanDeviceImp->pFanHandleContext->init(); } void TearDown() override { if (!sysmanUltsEnable) {