Skip to content

Commit aadf424

Browse files
Defer Sysman Standby Module Initialization
With this change, init for sysman Standby API would not be done during zeInit. Rather init and thereby Standby API handle creation would be done only when user explicitly requests to enumerate handles using zesDeviceEnumStandbyDomains. Related-To: LOCI-3127 Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
1 parent e1748ad commit aadf424

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

level_zero/tools/source/sysman/standby/standby.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -36,6 +36,9 @@ ze_result_t StandbyHandleContext::init(std::vector<ze_device_handle_t> &deviceHa
3636
}
3737

3838
ze_result_t StandbyHandleContext::standbyGet(uint32_t *pCount, zes_standby_handle_t *phStandby) {
39+
std::call_once(initStandbyOnce, [this]() {
40+
this->init(pOsSysman->getDeviceHandles());
41+
});
3942
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
4043
uint32_t numToCopy = std::min(*pCount, handleListSize);
4144
if (0 == *pCount || *pCount > handleListSize) {

level_zero/tools/source/sysman/standby/standby.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_standby_handle_t {
@@ -47,6 +48,7 @@ struct StandbyHandleContext {
4748

4849
private:
4950
void createHandle(ze_device_handle_t deviceHandle);
51+
std::once_flag initStandbyOnce;
5052
};
5153

5254
} // namespace L0

level_zero/tools/source/sysman/sysman_imp.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ ze_result_t SysmanDeviceImp::init() {
106106
if (pPci) {
107107
pPci->init();
108108
}
109-
if (pStandbyHandleContext) {
110-
pStandbyHandleContext->init(deviceHandles);
111-
}
112109
if (pEngineHandleContext) {
113110
pEngineHandleContext->init();
114111
}

level_zero/tools/test/unit_tests/sources/sysman/standby/linux/test_zes_sysman_standby.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class ZesStandbyFixture : public SysmanDeviceFixture {
5151
deviceHandles.resize(subDeviceCount, nullptr);
5252
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
5353
}
54-
pSysmanDeviceImp->pStandbyHandleContext->init(deviceHandles);
5554
}
5655
void TearDown() override {
5756
if (!sysmanUltsEnable) {
@@ -68,6 +67,13 @@ class ZesStandbyFixture : public SysmanDeviceFixture {
6867
}
6968
};
7069

70+
TEST_F(ZesStandbyFixture, GivenStandbyModeFilesNotAvailableWhenCallingEnumerateThenSuccessResultAndZeroCountIsReturned) {
71+
uint32_t count = 0;
72+
ptestSysfsAccess->isStandbyModeFileAvailable = false;
73+
ze_result_t result = zesDeviceEnumStandbyDomains(device, &count, nullptr);
74+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
75+
EXPECT_EQ(count, 0u);
76+
}
7177
TEST_F(ZesStandbyFixture, GivenComponentCountZeroWhenCallingzesStandbyGetThenNonZeroCountIsReturnedAndVerifyzesStandbyGetCallSucceeds) {
7278
std::vector<zes_standby_handle_t> standbyHandle = {};
7379
uint32_t count = 0;
@@ -326,7 +332,6 @@ class ZesStandbyMultiDeviceFixture : public SysmanMultiDeviceFixture {
326332
deviceHandles.resize(subDeviceCount, nullptr);
327333
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
328334
}
329-
pSysmanDeviceImp->pStandbyHandleContext->init(deviceHandles);
330335
}
331336
void TearDown() override {
332337
if (!sysmanUltsEnable) {

0 commit comments

Comments
 (0)