diff --git a/level_zero/tools/source/sysman/memory/memory.cpp b/level_zero/tools/source/sysman/memory/memory.cpp index b783850e53..725e1f7dd9 100644 --- a/level_zero/tools/source/sysman/memory/memory.cpp +++ b/level_zero/tools/source/sysman/memory/memory.cpp @@ -10,6 +10,7 @@ #include "level_zero/core/source/device/device.h" #include "level_zero/tools/source/sysman/memory/memory_imp.h" +#include "level_zero/tools/source/sysman/os_sysman.h" namespace L0 { @@ -36,6 +37,9 @@ ze_result_t MemoryHandleContext::init(std::vector &deviceHan } ze_result_t MemoryHandleContext::memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory) { + std::call_once(initMemoryOnce, [this]() { + this->init(pOsSysman->getDeviceHandles()); + }); 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/memory/memory.h b/level_zero/tools/source/sysman/memory/memory.h index 24797d6d41..128ebdd424 100644 --- a/level_zero/tools/source/sysman/memory/memory.h +++ b/level_zero/tools/source/sysman/memory/memory.h @@ -9,6 +9,7 @@ #include "level_zero/core/source/device/device.h" #include +#include #include struct _zes_mem_handle_t { @@ -46,6 +47,7 @@ struct MemoryHandleContext { private: void createHandle(ze_device_handle_t deviceHandle); + std::once_flag initMemoryOnce; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/scheduler/scheduler.cpp b/level_zero/tools/source/sysman/scheduler/scheduler.cpp index d331345af1..08cdc1561e 100644 --- a/level_zero/tools/source/sysman/scheduler/scheduler.cpp +++ b/level_zero/tools/source/sysman/scheduler/scheduler.cpp @@ -8,6 +8,7 @@ #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/debug_helpers.h" +#include "level_zero/tools/source/sysman/os_sysman.h" #include "level_zero/tools/source/sysman/scheduler/scheduler_imp.h" class OsScheduler; @@ -39,6 +40,9 @@ void SchedulerHandleContext::init(std::vector &deviceHandles } ze_result_t SchedulerHandleContext::schedulerGet(uint32_t *pCount, zes_sched_handle_t *phScheduler) { + std::call_once(initSchedulerOnce, [this]() { + this->init(pOsSysman->getDeviceHandles()); + }); 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/scheduler/scheduler.h b/level_zero/tools/source/sysman/scheduler/scheduler.h index b8666e0d48..29f8644993 100644 --- a/level_zero/tools/source/sysman/scheduler/scheduler.h +++ b/level_zero/tools/source/sysman/scheduler/scheduler.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -51,6 +52,7 @@ struct SchedulerHandleContext : NEO::NonCopyableOrMovableClass { private: void createHandle(zes_engine_type_flag_t engineType, std::vector &listOfEngines, ze_device_handle_t deviceHandle); + std::once_flag initSchedulerOnce; }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/sysman_imp.cpp b/level_zero/tools/source/sysman/sysman_imp.cpp index 8685f8128f..dca0b84989 100644 --- a/level_zero/tools/source/sysman/sysman_imp.cpp +++ b/level_zero/tools/source/sysman/sysman_imp.cpp @@ -100,12 +100,6 @@ ze_result_t SysmanDeviceImp::init() { if (pEngineHandleContext) { pEngineHandleContext->init(); } - if (pSchedulerHandleContext) { - pSchedulerHandleContext->init(deviceHandles); - } - if (pMemoryHandleContext) { - pMemoryHandleContext->init(deviceHandles); - } return result; } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp index 34e334c371..b1523f2f7a 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp @@ -46,7 +46,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { deviceHandles.resize(subDeviceCount, nullptr); Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); } - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); + getMemoryHandles(0); } void TearDown() override { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp index de80228fe6..ca032e9bf7 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp @@ -58,7 +58,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { deviceHandles.resize(subDeviceCount, nullptr); Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); } - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); + getMemoryHandles(0); } void TearDown() override { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/memory/windows/test_zes_memory.cpp b/level_zero/tools/test/unit_tests/sources/sysman/memory/windows/test_zes_memory.cpp index ad761b350b..8a3e64a257 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/memory/windows/test_zes_memory.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/memory/windows/test_zes_memory.cpp @@ -56,7 +56,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture { deviceHandles.resize(subDeviceCount, nullptr); Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); } - pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles); + getMemoryHandles(0); } void TearDown() override { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp index 84d8033ed0..b003e65b59 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp @@ -43,6 +43,11 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); EXPECT_EQ(count, powerHandleComponentCount); } +TEST_F(SysmanDeviceFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceDoesNotExistThenZeroCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) { + uint32_t count = 0; + EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS); + EXPECT_EQ(count, 0u); +} TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) { uint32_t count = 0; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/scheduler/linux/test_zes_scheduler.cpp b/level_zero/tools/test/unit_tests/sources/sysman/scheduler/linux/test_zes_scheduler.cpp index e7b8f753c6..b9a950de5f 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/scheduler/linux/test_zes_scheduler.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/scheduler/linux/test_zes_scheduler.cpp @@ -84,7 +84,7 @@ class SysmanDeviceSchedulerFixture : public SysmanDeviceFixture { deviceHandles.resize(subDeviceCount, nullptr); Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data()); } - pSysmanDeviceImp->pSchedulerHandleContext->init(deviceHandles); + getSchedHandles(0); } void TearDown() override {