Update sysman events API for bug fixes
Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
parent
39d450bc84
commit
d89b51edd3
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Intel Corporation
|
* Copyright (C) 2020-2021 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
|
@ -22,7 +22,7 @@ bool LinuxEventsImp::isResetRequired(zes_event_type_flags_t &pEvent) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pState.reset) {
|
if (pState.reset) {
|
||||||
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -40,7 +40,7 @@ bool LinuxEventsImp::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (val == 1) {
|
if (val == 1) {
|
||||||
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
|
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -58,7 +58,7 @@ bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (val == 1) {
|
if (val == 1) {
|
||||||
pEvent = ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
|
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -66,7 +66,7 @@ bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
||||||
|
|
||||||
bool LinuxEventsImp::checkIfMemHealthChanged(zes_event_type_flags_t &pEvent) {
|
bool LinuxEventsImp::checkIfMemHealthChanged(zes_event_type_flags_t &pEvent) {
|
||||||
if (currentMemHealth() != memHealthAtEventRegister) {
|
if (currentMemHealth() != memHealthAtEventRegister) {
|
||||||
pEvent = ZES_EVENT_TYPE_FLAG_MEM_HEALTH;
|
pEvent |= ZES_EVENT_TYPE_FLAG_MEM_HEALTH;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,21 +75,25 @@ bool LinuxEventsImp::checkIfMemHealthChanged(zes_event_type_flags_t &pEvent) {
|
||||||
bool LinuxEventsImp::eventListen(zes_event_type_flags_t &pEvent, uint32_t timeout) {
|
bool LinuxEventsImp::eventListen(zes_event_type_flags_t &pEvent, uint32_t timeout) {
|
||||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
||||||
if (isResetRequired(pEvent)) {
|
if (isResetRequired(pEvent)) {
|
||||||
|
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED); //After receiving event unregister it
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
|
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
|
||||||
if (checkDeviceDetachEvent(pEvent)) {
|
if (checkDeviceDetachEvent(pEvent)) {
|
||||||
|
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_DETACH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
|
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
|
||||||
if (checkDeviceAttachEvent(pEvent)) {
|
if (checkDeviceAttachEvent(pEvent)) {
|
||||||
|
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
||||||
if (checkIfMemHealthChanged(pEvent)) {
|
if (checkIfMemHealthChanged(pEvent)) {
|
||||||
|
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +104,7 @@ ze_result_t LinuxEventsImp::eventRegister(zes_event_type_flags_t events) {
|
||||||
if (0x7fff < events) {
|
if (0x7fff < events) {
|
||||||
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
|
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
|
||||||
}
|
}
|
||||||
registeredEvents = events;
|
registeredEvents |= events;
|
||||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
||||||
memHealthAtEventRegister = currentMemHealth();
|
memHealthAtEventRegister = currentMemHealth();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2020 Intel Corporation
|
* Copyright (C) 2019-2021 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
|
@ -42,6 +42,7 @@ ze_result_t DriverHandleImp::sysmanEventsListen(
|
||||||
uint32_t *pNumDeviceEvents,
|
uint32_t *pNumDeviceEvents,
|
||||||
zes_event_type_flags_t *pEvents) {
|
zes_event_type_flags_t *pEvents) {
|
||||||
bool gotSysmanEvent = false;
|
bool gotSysmanEvent = false;
|
||||||
|
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
||||||
auto timeToExitLoop = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout);
|
auto timeToExitLoop = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout);
|
||||||
do {
|
do {
|
||||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Intel Corporation
|
* Copyright (C) 2020-2021 Intel Corporation
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
|
@ -133,6 +133,28 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEv
|
||||||
delete[] pDeviceEvents;
|
delete[] pDeviceEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEventsThenAfterReceivingEventRegisterEventAgainToReceiveEvent) {
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
|
||||||
|
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
|
||||||
|
.WillByDefault(::testing::Invoke(pFsAccess.get(), &Mock<EventsFsAccess>::getValReturnValAsOne));
|
||||||
|
zes_device_handle_t *phDevices = new zes_device_handle_t[1];
|
||||||
|
phDevices[0] = device->toHandle();
|
||||||
|
uint32_t numDeviceEvents = 0;
|
||||||
|
zes_event_type_flags_t *pDeviceEvents = new zes_event_type_flags_t[1];
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
|
||||||
|
EXPECT_EQ(1u, numDeviceEvents);
|
||||||
|
EXPECT_EQ(ZES_EVENT_TYPE_FLAG_DEVICE_DETACH, pDeviceEvents[0]);
|
||||||
|
numDeviceEvents = 0;
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
|
||||||
|
EXPECT_EQ(0u, numDeviceEvents);
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDriverEventListen(driverHandle->toHandle(), 100u, 1u, phDevices, &numDeviceEvents, pDeviceEvents));
|
||||||
|
EXPECT_EQ(1u, numDeviceEvents);
|
||||||
|
EXPECT_EQ(ZES_EVENT_TYPE_FLAG_DEVICE_DETACH, pDeviceEvents[0]);
|
||||||
|
delete[] phDevices;
|
||||||
|
delete[] pDeviceEvents;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEventsThenEventListenAPIWaitForTimeoutIfEventNotReceived) {
|
TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForDeviceDetachEventsThenEventListenAPIWaitForTimeoutIfEventNotReceived) {
|
||||||
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
|
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDeviceEventRegister(device->toHandle(), ZES_EVENT_TYPE_FLAG_DEVICE_DETACH));
|
||||||
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
|
ON_CALL(*pFsAccess.get(), read(_, Matcher<uint32_t &>(_)))
|
||||||
|
@ -192,7 +214,7 @@ TEST_F(SysmanEventsFixture, GivenValidDeviceHandleWhenListeningForMemHealthEvent
|
||||||
PublicLinuxEventsImp *pLinuxEventsImp = new PublicLinuxEventsImp(pOsSysman);
|
PublicLinuxEventsImp *pLinuxEventsImp = new PublicLinuxEventsImp(pOsSysman);
|
||||||
pLinuxEventsImp->eventRegister(ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
pLinuxEventsImp->eventRegister(ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||||
pLinuxEventsImp->memHealthAtEventRegister = ZES_MEM_HEALTH_OK;
|
pLinuxEventsImp->memHealthAtEventRegister = ZES_MEM_HEALTH_OK;
|
||||||
zes_event_type_flags_t events;
|
zes_event_type_flags_t events = 0;
|
||||||
uint32_t timeout = 100u;
|
uint32_t timeout = 100u;
|
||||||
EXPECT_TRUE(pLinuxEventsImp->eventListen(events, timeout));
|
EXPECT_TRUE(pLinuxEventsImp->eventListen(events, timeout));
|
||||||
EXPECT_EQ(events, ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
EXPECT_EQ(events, ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||||
|
|
Loading…
Reference in New Issue