Skip to content

Commit 1898a82

Browse files
Defer Sysman Scheduler and Memory Initialization
With this change, init for sysman Scheduler/Memory API would not be done during zeInit. init and thereby Scheduler/Memory API handle creation would be done only when user explicitly requests to enumerate handles using zesDeviceEnumSchedulers/zesDeviceEnumMemory. Related-To: LOCI-3127 Signed-off-by: Kulkarni, Ashwin Kumar <[email protected]>
1 parent 4967e05 commit 1898a82

File tree

10 files changed

+21
-10
lines changed

10 files changed

+21
-10
lines changed

level_zero/tools/source/sysman/memory/memory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "level_zero/core/source/device/device.h"
1212
#include "level_zero/tools/source/sysman/memory/memory_imp.h"
13+
#include "level_zero/tools/source/sysman/os_sysman.h"
1314

1415
namespace L0 {
1516

@@ -36,6 +37,9 @@ ze_result_t MemoryHandleContext::init(std::vector<ze_device_handle_t> &deviceHan
3637
}
3738

3839
ze_result_t MemoryHandleContext::memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory) {
40+
std::call_once(initMemoryOnce, [this]() {
41+
this->init(pOsSysman->getDeviceHandles());
42+
});
3943
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
4044
uint32_t numToCopy = std::min(*pCount, handleListSize);
4145
if (0 == *pCount || *pCount > handleListSize) {

level_zero/tools/source/sysman/memory/memory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "level_zero/core/source/device/device.h"
1010
#include <level_zero/zes_api.h>
1111

12+
#include <mutex>
1213
#include <vector>
1314

1415
struct _zes_mem_handle_t {
@@ -46,6 +47,7 @@ struct MemoryHandleContext {
4647

4748
private:
4849
void createHandle(ze_device_handle_t deviceHandle);
50+
std::once_flag initMemoryOnce;
4951
};
5052

5153
} // namespace L0

level_zero/tools/source/sysman/scheduler/scheduler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "shared/source/helpers/basic_math.h"
99
#include "shared/source/helpers/debug_helpers.h"
1010

11+
#include "level_zero/tools/source/sysman/os_sysman.h"
1112
#include "level_zero/tools/source/sysman/scheduler/scheduler_imp.h"
1213

1314
class OsScheduler;
@@ -39,6 +40,9 @@ void SchedulerHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles
3940
}
4041

4142
ze_result_t SchedulerHandleContext::schedulerGet(uint32_t *pCount, zes_sched_handle_t *phScheduler) {
43+
std::call_once(initSchedulerOnce, [this]() {
44+
this->init(pOsSysman->getDeviceHandles());
45+
});
4246
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
4347
uint32_t numToCopy = std::min(*pCount, handleListSize);
4448
if (0 == *pCount || *pCount > handleListSize) {

level_zero/tools/source/sysman/scheduler/scheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <level_zero/zes_api.h>
1313

1414
#include <map>
15+
#include <mutex>
1516
#include <string>
1617
#include <vector>
1718

@@ -51,6 +52,7 @@ struct SchedulerHandleContext : NEO::NonCopyableOrMovableClass {
5152

5253
private:
5354
void createHandle(zes_engine_type_flag_t engineType, std::vector<std::string> &listOfEngines, ze_device_handle_t deviceHandle);
55+
std::once_flag initSchedulerOnce;
5456
};
5557

5658
} // namespace L0

level_zero/tools/source/sysman/sysman_imp.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ ze_result_t SysmanDeviceImp::init() {
100100
if (pEngineHandleContext) {
101101
pEngineHandleContext->init();
102102
}
103-
if (pSchedulerHandleContext) {
104-
pSchedulerHandleContext->init(deviceHandles);
105-
}
106-
if (pMemoryHandleContext) {
107-
pMemoryHandleContext->init(deviceHandles);
108-
}
109103
return result;
110104
}
111105

level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
4646
deviceHandles.resize(subDeviceCount, nullptr);
4747
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
4848
}
49-
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
49+
getMemoryHandles(0);
5050
}
5151

5252
void TearDown() override {

level_zero/tools/test/unit_tests/sources/sysman/memory/linux/test_sysman_memory_dg1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
5858
deviceHandles.resize(subDeviceCount, nullptr);
5959
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
6060
}
61-
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
61+
getMemoryHandles(0);
6262
}
6363

6464
void TearDown() override {

level_zero/tools/test/unit_tests/sources/sysman/memory/windows/test_zes_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
5656
deviceHandles.resize(subDeviceCount, nullptr);
5757
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
5858
}
59-
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
59+
getMemoryHandles(0);
6060
}
6161

6262
void TearDown() override {

level_zero/tools/test/unit_tests/sources/sysman/power/linux/test_zes_power_prelim.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
4343
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
4444
EXPECT_EQ(count, powerHandleComponentCount);
4545
}
46+
TEST_F(SysmanDeviceFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceDoesNotExistThenZeroCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
47+
uint32_t count = 0;
48+
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
49+
EXPECT_EQ(count, 0u);
50+
}
4651

4752
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
4853
uint32_t count = 0;

level_zero/tools/test/unit_tests/sources/sysman/scheduler/linux/test_zes_scheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SysmanDeviceSchedulerFixture : public SysmanDeviceFixture {
8484
deviceHandles.resize(subDeviceCount, nullptr);
8585
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
8686
}
87-
pSysmanDeviceImp->pSchedulerHandleContext->init(deviceHandles);
87+
getSchedHandles(0);
8888
}
8989

9090
void TearDown() override {

0 commit comments

Comments
 (0)