Defer Sysman Engine Module Initialization

With this change, init for sysman Engine API would not be done during zeInit.
init and thereby Engine API handle creation would be done only
when user explicitly requests to enumerate handles
using zesDeviceEnumEngineGroups

Related-To: LOCI-3127

Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
This commit is contained in:
Kulkarni, Ashwin Kumar
2022-08-11 13:42:59 +00:00
committed by Compute-Runtime-Automation
parent 94ff080c2a
commit 44649faa0f
14 changed files with 110 additions and 10 deletions

View File

@@ -36,6 +36,7 @@ void DiagnosticsHandleContext::init() {
ze_result_t DiagnosticsHandleContext::diagnosticsGet(uint32_t *pCount, zes_diag_handle_t *phDiagnostics) {
std::call_once(initDiagnosticsOnce, [this]() {
this->init();
this->diagnosticsInitDone = true;
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);

View File

@@ -45,10 +45,14 @@ struct DiagnosticsHandleContext {
std::vector<std::string> supportedDiagTests = {};
OsSysman *pOsSysman = nullptr;
std::vector<Diagnostics *> handleList = {};
bool isDiagnosticsInitDone() {
return diagnosticsInitDone;
}
private:
void createHandle(const std::string &diagTests);
std::once_flag initDiagnosticsOnce;
bool diagnosticsInitDone = false;
};
} // namespace L0

View File

@@ -47,6 +47,10 @@ void EngineHandleContext::releaseEngines() {
}
ze_result_t EngineHandleContext::engineGet(uint32_t *pCount, zes_engine_handle_t *phEngine) {
std::call_once(initEngineOnce, [this]() {
this->init();
this->engineInitDone = true;
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {

View File

@@ -9,6 +9,7 @@
#include <level_zero/zes_api.h>
#include <map>
#include <mutex>
#include <vector>
struct _zes_engine_handle_t {
@@ -42,9 +43,14 @@ struct EngineHandleContext {
OsSysman *pOsSysman = nullptr;
std::vector<Engine *> handleList = {};
bool isEngineInitDone() {
return engineInitDone;
}
private:
void createHandle(zes_engine_group_t engineType, uint32_t engineInstance, uint32_t subDeviceId);
std::once_flag initEngineOnce;
bool engineInitDone = false;
};
} // namespace L0

View File

@@ -41,6 +41,7 @@ void FirmwareHandleContext::init() {
ze_result_t FirmwareHandleContext::firmwareGet(uint32_t *pCount, zes_firmware_handle_t *phFirmware) {
std::call_once(initFirmwareOnce, [this]() {
this->init();
this->firmwareInitDone = true;
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);

View File

@@ -45,10 +45,14 @@ struct FirmwareHandleContext {
OsSysman *pOsSysman = nullptr;
std::vector<Firmware *> handleList = {};
bool isFirmwareInitDone() {
return firmwareInitDone;
}
private:
void createHandle(const std::string &fwType);
std::once_flag initFirmwareOnce;
bool firmwareInitDone = false;
};
} // namespace L0

View File

@@ -284,14 +284,22 @@ void LinuxSysmanImp::reInitSysmanDeviceResources() {
getSysmanDeviceImp()->updateSubDeviceHandlesLocally();
createPmtHandles();
createFwUtilInterface();
if (getSysmanDeviceImp()->pRasHandleContext->isRasInitDone()) {
getSysmanDeviceImp()->pRasHandleContext->init(getSysmanDeviceImp()->deviceHandles);
}
if (getSysmanDeviceImp()->pEngineHandleContext->isEngineInitDone()) {
getSysmanDeviceImp()->pEngineHandleContext->init();
}
if (!diagnosticsReset) {
if (getSysmanDeviceImp()->pDiagnosticsHandleContext->isDiagnosticsInitDone()) {
getSysmanDeviceImp()->pDiagnosticsHandleContext->init();
}
}
this->diagnosticsReset = false;
if (getSysmanDeviceImp()->pFirmwareHandleContext->isFirmwareInitDone()) {
getSysmanDeviceImp()->pFirmwareHandleContext->init();
}
}
ze_result_t LinuxSysmanImp::initDevice() {
ze_result_t result = ZE_RESULT_SUCCESS;

View File

@@ -41,6 +41,7 @@ ze_result_t RasHandleContext::rasGet(uint32_t *pCount,
zes_ras_handle_t *phRas) {
std::call_once(initRasOnce, [this]() {
this->init(pOsSysman->getDeviceHandles());
this->rasInitDone = true;
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);

View File

@@ -46,10 +46,14 @@ struct RasHandleContext {
OsSysman *pOsSysman = nullptr;
std::vector<Ras *> handleList = {};
bool isRasInitDone() {
return rasInitDone;
}
private:
void createHandle(zes_ras_error_type_t type, ze_device_handle_t deviceHandle);
std::once_flag initRasOnce;
bool rasInitDone = false;
};
} // namespace L0

View File

@@ -97,9 +97,6 @@ ze_result_t SysmanDeviceImp::init() {
if (ZE_RESULT_SUCCESS != result) {
return result;
}
if (pEngineHandleContext) {
pEngineHandleContext->init();
}
return result;
}

View File

@@ -629,6 +629,29 @@ TEST_F(ZesDiagnosticsFixture, GivenValidSysmanImpPointerWhenCallingReleaseResour
pLinuxSysmanImp->releaseDeviceResources();
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxSysmanImp->initDevice());
}
TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleAndHandleCountZeroWhenCallingReInitThenValidCountIsReturnedAndVerifyzesDeviceEnumDiagnosticTestSuitesSucceeds) {
uint32_t count = 0;
if (productFamily != IGFX_PVC) {
mockDiagHandleCount = 0;
}
ze_result_t result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
for (const auto &handle : pSysmanDeviceImp->pDiagnosticsHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.clear();
pSysmanDeviceImp->pDiagnosticsHandleContext->supportedDiagTests.clear();
pLinuxSysmanImp->diagnosticsReset = false;
pLinuxSysmanImp->reInitSysmanDeviceResources();
count = 0;
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, mockDiagHandleCount);
}
}; // namespace ult
}; // namespace L0

View File

@@ -48,7 +48,6 @@ class ZesEngineFixture : public SysmanDeviceFixture {
pFsAccess = std::make_unique<NiceMock<Mock<EngineFsAccess>>>();
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
EngineHandleContext *pEngineHandleContext = pSysmanDeviceImp->pEngineHandleContext;
pDrm = std::make_unique<NiceMock<Mock<EngineNeoDrm>>>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment()));
pDrm->setupIoctlHelper(neoDevice->getRootDeviceEnvironment().getHardwareInfo()->platform.eProductFamily);
pPmuInterface = std::make_unique<NiceMock<Mock<MockPmuInterfaceImp>>>(pLinuxSysmanImp);
@@ -69,7 +68,7 @@ class ZesEngineFixture : public SysmanDeviceFixture {
ON_CALL(*pFsAccess.get(), read(_, _))
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EngineFsAccess>::readValSuccess));
pEngineHandleContext->init();
getEngineHandles(0);
}
void TearDown() override {

View File

@@ -38,7 +38,7 @@ class SysmanDeviceEngineFixture : public SysmanDeviceFixture {
}
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
pSysmanDeviceImp->pEngineHandleContext->init();
get_engine_handles(0);
}
void TearDown() override {

View File

@@ -8,6 +8,9 @@
#include "shared/test/common/mocks/mock_driver_info.h"
#include "shared/test/common/test_macros/test.h"
#include "level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h"
#include "level_zero/tools/source/sysman/firmware/linux/os_firmware_imp.h"
#include "level_zero/tools/source/sysman/ras/ras_imp.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
namespace L0 {
@@ -334,6 +337,51 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenGettingFwUtilInterfaceAndG
pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
}
TEST_F(SysmanDeviceFixture, GivenValidEnumeratedHandlesWhenReleaseIsCalledThenHandleCountZeroIsReturned) {
uint32_t count = 0;
const std::vector<std::string> mockSupportedDiagTypes = {"MOCKSUITE1", "MOCKSUITE2"};
std::vector<std::string> mockSupportedFirmwareTypes = {"GSC", "OptionROM", "PSC"};
FirmwareImp *ptestFirmwareImp = new FirmwareImp(pSysmanDeviceImp->pFirmwareHandleContext->pOsSysman, mockSupportedFirmwareTypes[0]);
pSysmanDeviceImp->pFirmwareHandleContext->handleList.push_back(ptestFirmwareImp);
count = 0;
ze_result_t result = zesDeviceEnumFirmwares(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, 1u);
count = 0;
DiagnosticsImp *ptestDiagnosticsImp = new DiagnosticsImp(pSysmanDeviceImp->pDiagnosticsHandleContext->pOsSysman, mockSupportedDiagTypes[0]);
pSysmanDeviceImp->pDiagnosticsHandleContext->handleList.push_back(ptestDiagnosticsImp);
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, 1u);
count = 0;
RasImp *pRas = new RasImp(pSysmanDeviceImp->pRasHandleContext->pOsSysman, ZES_RAS_ERROR_TYPE_CORRECTABLE, device->toHandle());
pSysmanDeviceImp->pRasHandleContext->handleList.push_back(pRas);
result = zesDeviceEnumRasErrorSets(device->toHandle(), &count, NULL);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, 3u);
pLinuxSysmanImp->releaseSysmanDeviceResources();
count = 0;
result = zesDeviceEnumFirmwares(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, 0u);
count = 0;
result = zesDeviceEnumDiagnosticTestSuites(device->toHandle(), &count, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, 0u);
count = 0;
result = zesDeviceEnumRasErrorSets(device->toHandle(), &count, NULL);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(count, 0u);
}
TEST_F(SysmanMultiDeviceFixture, GivenValidDeviceHandleHavingSubdevicesWhenValidatingSysmanHandlesForSubdevicesThenSysmanHandleForSubdeviceWillBeSameAsSysmanHandleForDevice) {
ze_device_handle_t hSysman = device->toHandle();
auto pSysmanDeviceOriginal = static_cast<DeviceImp *>(device)->getSysmanHandle();