mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
feature(sysman): Support events for multiple devices
Related-To: LOCI-3683 Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
9acba4ea2a
commit
2282f26734
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/sysman/source/sysman_driver_handle_imp.h"
|
||||
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
|
||||
#include "level_zero/tools/source/sysman/sysman.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@@ -22,6 +24,10 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
||||
delete Sysman::GlobalSysmanDriver;
|
||||
Sysman::GlobalSysmanDriver = nullptr;
|
||||
}
|
||||
if (GlobalOsSysmanDriver != nullptr) {
|
||||
delete GlobalOsSysmanDriver;
|
||||
GlobalOsSysmanDriver = nullptr;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/utilities/directory.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h"
|
||||
#include "level_zero/tools/source/sysman/memory/linux/os_memory_imp_prelim.h"
|
||||
|
||||
#include "sysman/events/events_imp.h"
|
||||
@@ -19,13 +20,62 @@
|
||||
|
||||
namespace L0 {
|
||||
|
||||
const std::string LinuxEventsImp::add("add");
|
||||
const std::string LinuxEventsImp::remove("remove");
|
||||
const std::string LinuxEventsImp::change("change");
|
||||
const std::string LinuxEventsImp::unbind("unbind");
|
||||
const std::string LinuxEventsImp::bind("bind");
|
||||
const std::string LinuxEventsUtil::add("add");
|
||||
const std::string LinuxEventsUtil::remove("remove");
|
||||
const std::string LinuxEventsUtil::change("change");
|
||||
const std::string LinuxEventsUtil::unbind("unbind");
|
||||
const std::string LinuxEventsUtil::bind("bind");
|
||||
|
||||
static bool checkRasEventOccured(Ras *rasHandle) {
|
||||
bool LinuxEventsImp::eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||
// This is dummy implementation, Actual implementation is handled at driver level
|
||||
// for all devices.
|
||||
return false;
|
||||
}
|
||||
|
||||
ze_result_t LinuxEventsImp::eventRegister(zes_event_type_flags_t events) {
|
||||
if (0x7fff < events) {
|
||||
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
|
||||
}
|
||||
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||
"%s", "Os Sysman driver not initialized\n");
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
static_cast<LinuxSysmanDriverImp *>(GlobalOsSysmanDriver)->eventRegister(events, pLinuxSysmanImp->getSysmanDeviceImp());
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
LinuxEventsImp::LinuxEventsImp(OsSysman *pOsSysman) {
|
||||
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
}
|
||||
|
||||
OsEvents *OsEvents::create(OsSysman *pOsSysman) {
|
||||
LinuxEventsImp *pLinuxEventsImp = new LinuxEventsImp(pOsSysman);
|
||||
return static_cast<OsEvents *>(pLinuxEventsImp);
|
||||
}
|
||||
|
||||
bool LinuxEventsUtil::checkRasEvent(zes_event_type_flags_t &pEvent, SysmanDeviceImp *pSysmanDeviceImp, zes_event_type_flags_t registeredEvents) {
|
||||
for (auto rasHandle : pSysmanDeviceImp->pRasHandleContext->handleList) {
|
||||
zes_ras_properties_t properties = {};
|
||||
rasHandle->rasGetProperties(&properties);
|
||||
if ((registeredEvents & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) && (properties.type == ZES_RAS_ERROR_TYPE_CORRECTABLE)) {
|
||||
if (LinuxEventsUtil::checkRasEventOccured(rasHandle) == true) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ((registeredEvents & ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS) && (properties.type == ZES_RAS_ERROR_TYPE_UNCORRECTABLE)) {
|
||||
if (LinuxEventsUtil::checkRasEventOccured(rasHandle) == true) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxEventsUtil::checkRasEventOccured(Ras *rasHandle) {
|
||||
zes_ras_config_t config = {};
|
||||
zes_ras_state_t state = {};
|
||||
rasHandle->rasGetConfig(&config);
|
||||
@@ -44,27 +94,69 @@ static bool checkRasEventOccured(Ras *rasHandle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::checkRasEvent(zes_event_type_flags_t &pEvent) {
|
||||
for (auto rasHandle : pLinuxSysmanImp->getSysmanDeviceImp()->pRasHandleContext->handleList) {
|
||||
zes_ras_properties_t properties = {};
|
||||
rasHandle->rasGetProperties(&properties);
|
||||
if ((registeredEvents & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) && (properties.type == ZES_RAS_ERROR_TYPE_CORRECTABLE)) {
|
||||
if (checkRasEventOccured(rasHandle) == true) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS;
|
||||
return true;
|
||||
}
|
||||
void LinuxEventsUtil::eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice) {
|
||||
std::call_once(initEventsOnce, [this]() {
|
||||
this->init();
|
||||
});
|
||||
|
||||
if (!events) {
|
||||
// If user is trying to register events with empty events argument, then clear all the registered events
|
||||
deviceEventsMap.emplace(pSysmanDevice, events);
|
||||
} else {
|
||||
zes_event_type_flags_t registeredEvents = 0;
|
||||
// supportedEventMask --> this mask checks for events that supported currently
|
||||
zes_event_type_flags_t supportedEventMask = ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH |
|
||||
ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH | ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED |
|
||||
ZES_EVENT_TYPE_FLAG_MEM_HEALTH | ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS |
|
||||
ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS;
|
||||
if (deviceEventsMap.find(pSysmanDevice) != deviceEventsMap.end()) {
|
||||
registeredEvents = deviceEventsMap[pSysmanDevice];
|
||||
}
|
||||
if ((registeredEvents & ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS) && (properties.type == ZES_RAS_ERROR_TYPE_UNCORRECTABLE)) {
|
||||
if (checkRasEventOccured(rasHandle) == true) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS;
|
||||
return true;
|
||||
registeredEvents |= (events & supportedEventMask);
|
||||
deviceEventsMap.emplace(pSysmanDevice, registeredEvents);
|
||||
}
|
||||
}
|
||||
|
||||
void LinuxEventsUtil::init() {
|
||||
pUdevLib = static_cast<LinuxSysmanDriverImp *>(GlobalOsSysmanDriver)->getUdevLibHandle();
|
||||
}
|
||||
|
||||
ze_result_t LinuxEventsUtil::eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) {
|
||||
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
||||
std::vector<zes_event_type_flags_t> registeredEvents(count);
|
||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||
auto device = static_cast<SysmanDeviceImp *>(L0::SysmanDevice::fromHandle(phDevices[devIndex]));
|
||||
if (deviceEventsMap.find(device) != deviceEventsMap.end()) {
|
||||
registeredEvents[devIndex] = deviceEventsMap[device];
|
||||
}
|
||||
if (registeredEvents[devIndex]) {
|
||||
if ((registeredEvents[devIndex] & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) || (registeredEvents[devIndex] & ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS)) {
|
||||
if (checkRasEvent(pEvents[devIndex], device, registeredEvents[devIndex])) {
|
||||
*pNumDeviceEvents = 1;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (registeredEvents[devIndex] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
||||
zes_device_state_t deviceState = {};
|
||||
device->pGlobalOperations->deviceGetState(&deviceState);
|
||||
if (deviceState.reset & ZES_RESET_REASON_FLAG_REPAIR) {
|
||||
pEvents[devIndex] |= ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||
*pNumDeviceEvents = 1;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
if (listenSystemEvents(pEvents, count, registeredEvents, phDevices, timeout)) {
|
||||
*pNumDeviceEvents = 1;
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::isResetRequired(void *dev, zes_event_type_flags_t &pEvent) {
|
||||
bool LinuxEventsUtil::isResetRequired(void *dev, zes_event_type_flags_t &pEvent) {
|
||||
if (action.compare(change) != 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -74,11 +166,10 @@ bool LinuxEventsImp::isResetRequired(void *dev, zes_event_type_flags_t &pEvent)
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
|
||||
bool LinuxEventsUtil::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
|
||||
if (action.compare(remove) == 0) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
|
||||
return true;
|
||||
@@ -86,7 +177,7 @@ bool LinuxEventsImp::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
||||
bool LinuxEventsUtil::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
||||
if (action.compare(add) == 0) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
|
||||
return true;
|
||||
@@ -94,7 +185,7 @@ bool LinuxEventsImp::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::checkIfMemHealthChanged(void *dev, zes_event_type_flags_t &pEvent) {
|
||||
bool LinuxEventsUtil::checkIfMemHealthChanged(void *dev, zes_event_type_flags_t &pEvent) {
|
||||
if (action.compare(change) != 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -110,60 +201,15 @@ bool LinuxEventsImp::checkIfMemHealthChanged(void *dev, zes_event_type_flags_t &
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::checkIfFabricPortStatusChanged(void *dev, zes_event_type_flags_t &pEvent) {
|
||||
if (action.compare(change) != 0) {
|
||||
return false;
|
||||
}
|
||||
bool LinuxEventsUtil::listenSystemEvents(zes_event_type_flags_t *pEvents, uint32_t count, std::vector<zes_event_type_flags_t> ®isteredEvents, zes_device_handle_t *phDevices, uint64_t timeout) {
|
||||
std::call_once(initEventsOnce, [this]() {
|
||||
this->init();
|
||||
});
|
||||
|
||||
const char *str = pUdevLib->getEventPropertyValue(dev, "TYPE");
|
||||
if (str == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const char *expectedStr = "PORT_CHANGE";
|
||||
const size_t expectedStrLen = 11; // length of "PORT_CHANGE" is 11
|
||||
if (strlen(str) != strlen(expectedStr)) {
|
||||
return false;
|
||||
}
|
||||
if (strncmp(str, expectedStr, expectedStrLen) == 0) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ze_result_t LinuxEventsImp::readFabricDeviceStats(const std::string &devicePciPath, struct stat &iafStat) {
|
||||
const std::string iafDirectoryLegacy = "iaf.";
|
||||
const std::string iafDirectory = "i915.iaf.";
|
||||
const std::string fabricIdFile = "/iaf_fabric_id";
|
||||
int fd = -1;
|
||||
std::string path;
|
||||
path.clear();
|
||||
std::vector<std::string> list = NEO::Directory::getFiles(devicePciPath);
|
||||
for (auto entry : list) {
|
||||
if ((entry.find(iafDirectory) != std::string::npos) ||
|
||||
(entry.find(iafDirectoryLegacy) != std::string::npos)) {
|
||||
path = entry + fabricIdFile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (path.empty()) {
|
||||
// This device does not have a fabric
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
fd = NEO::SysCalls::open(path.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
||||
}
|
||||
NEO::SysCalls::fstat(fd, &iafStat);
|
||||
NEO::SysCalls::close(fd);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||
bool retval = false;
|
||||
struct pollfd pfd;
|
||||
struct stat iafStat;
|
||||
std::vector<std::string> subsystemList;
|
||||
std::multimap<uint32_t, dev_t> mapOfDevIndexToDevNum;
|
||||
|
||||
if (pUdevLib == nullptr) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||
@@ -171,36 +217,37 @@ bool LinuxEventsImp::listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t
|
||||
return retval;
|
||||
}
|
||||
|
||||
// Get fabric device stats
|
||||
const std::string iafPath = "device/";
|
||||
std::string iafRealPath = {};
|
||||
pLinuxSysmanImp->getSysfsAccess().getRealPath(iafPath, iafRealPath);
|
||||
auto result = readFabricDeviceStats(iafRealPath, iafStat);
|
||||
if (result == ZE_RESULT_SUCCESS) {
|
||||
subsystemList.push_back("platform");
|
||||
}
|
||||
|
||||
subsystemList.push_back("drm");
|
||||
pfd.fd = pUdevLib->registerEventsFromSubsystemAndGetFd(subsystemList);
|
||||
pfd.events = POLLIN;
|
||||
|
||||
auto pDrm = &pLinuxSysmanImp->getDrm();
|
||||
struct stat drmStat;
|
||||
NEO::SysCalls::fstat(pDrm->getFileDescriptor(), &drmStat);
|
||||
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
auto start = L0::steadyClock::now();
|
||||
std::chrono::duration<double, std::milli> timeElapsed;
|
||||
while (NEO::SysCalls::poll(&pfd, 1, static_cast<int>(timeout)) > 0) {
|
||||
// Check again for registered events. Its possible while we are looping for events, registered events are cleared
|
||||
if (!registeredEvents) {
|
||||
return true;
|
||||
mapOfDevIndexToDevNum.clear();
|
||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||
auto device = static_cast<SysmanDeviceImp *>(L0::SysmanDevice::fromHandle(phDevices[devIndex]));
|
||||
registeredEvents[devIndex] = deviceEventsMap[device];
|
||||
if (!registeredEvents[devIndex]) {
|
||||
continue;
|
||||
} else {
|
||||
auto pDrm = &static_cast<L0::LinuxSysmanImp *>(device->deviceGetOsInterface())->getDrm();
|
||||
struct stat drmStat = {};
|
||||
NEO::SysCalls::fstat(pDrm->getFileDescriptor(), &drmStat);
|
||||
mapOfDevIndexToDevNum.insert({devIndex, drmStat.st_rdev});
|
||||
mapOfDevIndexToDevNum.insert({devIndex, drmStat.st_rdev - 127});
|
||||
}
|
||||
}
|
||||
|
||||
if (mapOfDevIndexToDevNum.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
dev_t devnum;
|
||||
void *dev = nullptr;
|
||||
dev = pUdevLib->allocateDeviceToReceiveData();
|
||||
if (dev == nullptr) {
|
||||
timeElapsed = std::chrono::steady_clock::now() - start;
|
||||
timeElapsed = L0::steadyClock::now() - start;
|
||||
if (timeout > timeElapsed.count()) {
|
||||
timeout = timeout - timeElapsed.count();
|
||||
continue;
|
||||
@@ -210,43 +257,33 @@ bool LinuxEventsImp::listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t
|
||||
}
|
||||
|
||||
devnum = pUdevLib->getEventGenerationSourceDevice(dev);
|
||||
|
||||
if ((memcmp(&drmStat.st_rdev, &devnum, sizeof(dev_t)) == 0) ||
|
||||
(memcmp(&iafStat.st_rdev, &devnum, sizeof(dev_t)) == 0)) {
|
||||
auto eventTypePtr = pUdevLib->getEventType(dev);
|
||||
|
||||
if (eventTypePtr != nullptr) {
|
||||
action = std::string(eventTypePtr);
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH) {
|
||||
if (checkIfFabricPortStatusChanged(dev, pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH);
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
|
||||
if (checkDeviceDetachEvent(pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_DETACH); // After receiving event unregister it
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
|
||||
if (checkDeviceAttachEvent(pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH);
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
||||
if (isResetRequired(dev, pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED);
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
||||
if (checkIfMemHealthChanged(dev, pEvent)) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_MEM_HEALTH);
|
||||
retval = true;
|
||||
for (auto it = mapOfDevIndexToDevNum.begin(); it != mapOfDevIndexToDevNum.end(); it++) {
|
||||
if (it->second == devnum) {
|
||||
auto eventTypePtr = pUdevLib->getEventType(dev);
|
||||
if (eventTypePtr != nullptr) {
|
||||
action = std::string(eventTypePtr);
|
||||
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_DETACH) {
|
||||
if (checkDeviceDetachEvent(pEvents[it->first])) {
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH) {
|
||||
if (checkDeviceAttachEvent(pEvents[it->first])) {
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
||||
if (isResetRequired(dev, pEvents[it->first])) {
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_MEM_HEALTH) {
|
||||
if (checkIfMemHealthChanged(dev, pEvents[it->first])) {
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +291,7 @@ bool LinuxEventsImp::listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t
|
||||
if (retval) {
|
||||
break;
|
||||
}
|
||||
timeElapsed = std::chrono::steady_clock::now() - start;
|
||||
timeElapsed = L0::steadyClock::now() - start;
|
||||
if (timeout > timeElapsed.count()) {
|
||||
timeout = timeout - timeElapsed.count();
|
||||
continue;
|
||||
@@ -262,69 +299,7 @@ bool LinuxEventsImp::listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool LinuxEventsImp::eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||
bool retval = false;
|
||||
if (!registeredEvents) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
pEvent = 0;
|
||||
if ((registeredEvents & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) || (registeredEvents & ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS)) {
|
||||
if (checkRasEvent(pEvent)) {
|
||||
if (pEvent & ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS) {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS);
|
||||
} else {
|
||||
registeredEvents &= ~(ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// check if any reset required for reason field repair
|
||||
if (registeredEvents & ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED) {
|
||||
zes_device_state_t deviceState = {};
|
||||
pLinuxSysmanImp->getSysmanDeviceImp()->pGlobalOperations->deviceGetState(&deviceState);
|
||||
if (deviceState.reset & ZES_RESET_REASON_FLAG_REPAIR) {
|
||||
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return listenSystemEvents(pEvent, timeout);
|
||||
}
|
||||
|
||||
ze_result_t LinuxEventsImp::eventRegister(zes_event_type_flags_t events) {
|
||||
if (0x7fff < events) {
|
||||
return ZE_RESULT_ERROR_INVALID_ENUMERATION;
|
||||
}
|
||||
if (!events) {
|
||||
// If user is trying to register events with empty events argument, then clear all the registered events
|
||||
registeredEvents = events;
|
||||
} else {
|
||||
// supportedEventMask --> this mask checks for events that supported currently
|
||||
zes_event_type_flags_t supportedEventMask = ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH | ZES_EVENT_TYPE_FLAG_DEVICE_DETACH |
|
||||
ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH | ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED |
|
||||
ZES_EVENT_TYPE_FLAG_MEM_HEALTH | ZES_EVENT_TYPE_FLAG_RAS_CORRECTABLE_ERRORS |
|
||||
ZES_EVENT_TYPE_FLAG_RAS_UNCORRECTABLE_ERRORS;
|
||||
registeredEvents |= (events & supportedEventMask);
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
LinuxEventsImp::LinuxEventsImp(OsSysman *pOsSysman) {
|
||||
pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
|
||||
pFsAccess = &pLinuxSysmanImp->getFsAccess();
|
||||
pUdevLib = pLinuxSysmanImp->getUdevLibHandle();
|
||||
}
|
||||
|
||||
OsEvents *OsEvents::create(OsSysman *pOsSysman) {
|
||||
LinuxEventsImp *pLinuxEventsImp = new LinuxEventsImp(pOsSysman);
|
||||
return static_cast<OsEvents *>(pLinuxEventsImp);
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
* Copyright (C) 2022-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -16,33 +16,43 @@ class LinuxEventsImp : public OsEvents, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
bool eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
|
||||
ze_result_t eventRegister(zes_event_type_flags_t events) override;
|
||||
LinuxEventsImp() = default;
|
||||
LinuxEventsImp() = delete;
|
||||
LinuxEventsImp(OsSysman *pOsSysman);
|
||||
~LinuxEventsImp() override = default;
|
||||
|
||||
protected:
|
||||
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
|
||||
};
|
||||
|
||||
class LinuxEventsUtil {
|
||||
|
||||
public:
|
||||
LinuxEventsUtil() = default;
|
||||
~LinuxEventsUtil() = default;
|
||||
|
||||
ze_result_t eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents);
|
||||
void eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice);
|
||||
|
||||
protected:
|
||||
UdevLib *pUdevLib = nullptr;
|
||||
bool checkRasEvent(zes_event_type_flags_t &pEvent, SysmanDeviceImp *pSysmanDeviceImp, zes_event_type_flags_t registeredEvents);
|
||||
bool isResetRequired(void *dev, zes_event_type_flags_t &pEvent);
|
||||
bool checkDeviceDetachEvent(zes_event_type_flags_t &pEvent);
|
||||
bool checkDeviceAttachEvent(zes_event_type_flags_t &pEvent);
|
||||
bool checkIfMemHealthChanged(void *dev, zes_event_type_flags_t &pEvent);
|
||||
bool checkIfFabricPortStatusChanged(void *dev, zes_event_type_flags_t &pEvent);
|
||||
bool checkRasEvent(zes_event_type_flags_t &pEvent);
|
||||
ze_result_t readFabricDeviceStats(const std::string &devicePciPath, struct stat &iafStat);
|
||||
bool listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t timeout);
|
||||
uint32_t fabricEventTrackAtRegister = 0;
|
||||
L0::UdevLib *pUdevLib = nullptr;
|
||||
zes_event_type_flags_t registeredEvents = 0;
|
||||
bool listenSystemEvents(zes_event_type_flags_t *pEvents, uint32_t count, std::vector<zes_event_type_flags_t> ®isteredEvents, zes_device_handle_t *phDevices, uint64_t timeout);
|
||||
|
||||
private:
|
||||
FsAccess *pFsAccess = nullptr;
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
std::map<SysmanDeviceImp *, zes_event_type_flags_t> deviceEventsMap;
|
||||
std::string action;
|
||||
static const std::string add;
|
||||
static const std::string remove;
|
||||
static const std::string change;
|
||||
static const std::string unbind;
|
||||
static const std::string bind;
|
||||
static bool checkRasEventOccured(Ras *rasHandle);
|
||||
std::once_flag initEventsOnce;
|
||||
void init();
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2020-2022 Intel Corporation
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -8,6 +8,8 @@ set(L0_SRCS_TOOLS_SYSMAN_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fs_access.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h"
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t LinuxSysmanDriverImp::eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) {
|
||||
return pLinuxEventsUtil->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||
}
|
||||
|
||||
void LinuxSysmanDriverImp::eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice) {
|
||||
pLinuxEventsUtil->eventRegister(events, pSysmanDevice);
|
||||
}
|
||||
|
||||
L0::UdevLib *LinuxSysmanDriverImp::getUdevLibHandle() {
|
||||
if (pUdevLib == nullptr) {
|
||||
pUdevLib = UdevLib::create();
|
||||
}
|
||||
return pUdevLib;
|
||||
}
|
||||
|
||||
LinuxSysmanDriverImp::LinuxSysmanDriverImp() {
|
||||
pLinuxEventsUtil = new LinuxEventsUtil();
|
||||
}
|
||||
|
||||
LinuxSysmanDriverImp::~LinuxSysmanDriverImp() {
|
||||
if (nullptr != pUdevLib) {
|
||||
delete pUdevLib;
|
||||
pUdevLib = nullptr;
|
||||
}
|
||||
|
||||
if (nullptr != pLinuxEventsUtil) {
|
||||
delete pLinuxEventsUtil;
|
||||
pLinuxEventsUtil = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
OsSysmanDriver *OsSysmanDriver::create() {
|
||||
LinuxSysmanDriverImp *pLinuxSysmanDriverImp = new LinuxSysmanDriverImp();
|
||||
DEBUG_BREAK_IF(nullptr == pLinuxSysmanDriverImp);
|
||||
return static_cast<OsSysmanDriver *>(pLinuxSysmanDriverImp);
|
||||
}
|
||||
|
||||
void __attribute__((destructor)) osSysmanDriverDestructor() {
|
||||
if (GlobalOsSysmanDriver != nullptr) {
|
||||
delete GlobalOsSysmanDriver;
|
||||
GlobalOsSysmanDriver = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
32
level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h
Normal file
32
level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "level_zero/tools/source/sysman/events/linux/os_events_imp_prelim.h"
|
||||
#include "level_zero/tools/source/sysman/linux/udev/udev_lib.h"
|
||||
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class LinuxSysmanDriverImp : public OsSysmanDriver {
|
||||
public:
|
||||
LinuxSysmanDriverImp();
|
||||
~LinuxSysmanDriverImp() override;
|
||||
|
||||
ze_result_t eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) override;
|
||||
void eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice);
|
||||
L0::UdevLib *getUdevLibHandle();
|
||||
|
||||
protected:
|
||||
L0::UdevLib *pUdevLib = nullptr;
|
||||
L0::LinuxEventsUtil *pLinuxEventsUtil = nullptr;
|
||||
};
|
||||
|
||||
void __attribute__((destructor)) osSysmanDriverDestructor();
|
||||
|
||||
} // namespace L0
|
||||
@@ -90,13 +90,6 @@ FirmwareUtil *LinuxSysmanImp::getFwUtilInterface() {
|
||||
return pFwUtilInterface;
|
||||
}
|
||||
|
||||
L0::UdevLib *LinuxSysmanImp::getUdevLibHandle() {
|
||||
if (pUdevLib == nullptr) {
|
||||
pUdevLib = UdevLib::create();
|
||||
}
|
||||
return pUdevLib;
|
||||
}
|
||||
|
||||
FsAccess &LinuxSysmanImp::getFsAccess() {
|
||||
UNRECOVERABLE_IF(nullptr == pFsAccess);
|
||||
return *pFsAccess;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -46,7 +46,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
|
||||
ze_result_t init() override;
|
||||
|
||||
L0::UdevLib *getUdevLibHandle();
|
||||
PmuInterface *getPmuInterface();
|
||||
FirmwareUtil *getFwUtilInterface();
|
||||
FsAccess &getFsAccess();
|
||||
|
||||
20
level_zero/tools/source/sysman/os_sysman_driver.h
Normal file
20
level_zero/tools/source/sysman/os_sysman_driver.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/zes_api.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
struct OsSysmanDriver {
|
||||
virtual ~OsSysmanDriver(){};
|
||||
|
||||
virtual ze_result_t eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0;
|
||||
static OsSysmanDriver *create();
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -7,11 +7,13 @@
|
||||
|
||||
#include "level_zero/tools/source/sysman/sysman.h"
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/helpers/sleep.h"
|
||||
|
||||
#include "level_zero/core/source/device/device_imp.h"
|
||||
#include "level_zero/core/source/driver/driver.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
|
||||
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
||||
|
||||
#include <cstring>
|
||||
@@ -20,6 +22,8 @@
|
||||
namespace L0 {
|
||||
bool sysmanInitFromCore = false;
|
||||
|
||||
struct OsSysmanDriver *GlobalOsSysmanDriver = nullptr;
|
||||
|
||||
void DeviceImp::createSysmanHandle(bool isSubDevice) {
|
||||
if (static_cast<DriverHandleImp *>(driverHandle)->enableSysman && !isSubDevice) {
|
||||
if (this->getSysmanHandle() == nullptr) {
|
||||
@@ -42,6 +46,10 @@ SysmanDevice *SysmanDeviceHandleContext::init(ze_device_handle_t coreDevice) {
|
||||
for (auto &subDevice : device->subDevices) {
|
||||
static_cast<DeviceImp *>(subDevice)->setSysmanHandle(sysmanDevice);
|
||||
}
|
||||
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
GlobalOsSysmanDriver = L0::OsSysmanDriver::create();
|
||||
}
|
||||
return sysmanDevice;
|
||||
}
|
||||
|
||||
@@ -59,24 +67,14 @@ ze_result_t DriverHandleImp::sysmanEventsListen(
|
||||
zes_device_handle_t *phDevices,
|
||||
uint32_t *pNumDeviceEvents,
|
||||
zes_event_type_flags_t *pEvents) {
|
||||
bool gotSysmanEvent = false;
|
||||
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
||||
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::milliseconds(timeout);
|
||||
do {
|
||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
|
||||
if (gotSysmanEvent) {
|
||||
*pNumDeviceEvents = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gotSysmanEvent) {
|
||||
break;
|
||||
}
|
||||
NEO::sleep(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
|
||||
} while ((L0::steadyClock::now() <= timeToExitLoop));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||
"%s", "Os Sysman Driver Not initialized\n");
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
return GlobalOsSysmanDriver->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::sysmanEventsListenEx(
|
||||
@@ -85,24 +83,13 @@ ze_result_t DriverHandleImp::sysmanEventsListenEx(
|
||||
zes_device_handle_t *phDevices,
|
||||
uint32_t *pNumDeviceEvents,
|
||||
zes_event_type_flags_t *pEvents) {
|
||||
bool gotSysmanEvent = false;
|
||||
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
||||
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::duration<uint64_t, std::milli>(timeout);
|
||||
do {
|
||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
|
||||
if (gotSysmanEvent) {
|
||||
*pNumDeviceEvents = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gotSysmanEvent) {
|
||||
break;
|
||||
}
|
||||
NEO::sleep(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
|
||||
} while ((L0::steadyClock::now() <= timeToExitLoop));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||
"%s", "Os Sysman Driver Not initialized\n");
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
return GlobalOsSysmanDriver->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||
}
|
||||
|
||||
ze_result_t SysmanDevice::performanceGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_perf_handle_t *phPerformance) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -89,9 +89,12 @@ struct SysmanDevice : _ze_device_handle_t {
|
||||
virtual ze_result_t deviceGetEccState(zes_device_ecc_properties_t *pState) = 0;
|
||||
virtual ze_result_t deviceSetEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) = 0;
|
||||
virtual bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) = 0;
|
||||
virtual OsSysman *deviceGetOsInterface() = 0;
|
||||
virtual ~SysmanDevice() = default;
|
||||
};
|
||||
|
||||
extern struct OsSysmanDriver *GlobalOsSysmanDriver;
|
||||
|
||||
class SysmanDeviceHandleContext {
|
||||
public:
|
||||
SysmanDeviceHandleContext() = delete;
|
||||
|
||||
@@ -132,6 +132,10 @@ ze_result_t SysmanDeviceImp::deviceEventRegister(zes_event_type_flags_t events)
|
||||
return pEvents->eventRegister(events);
|
||||
}
|
||||
|
||||
OsSysman *SysmanDeviceImp::deviceGetOsInterface() {
|
||||
return pOsSysman;
|
||||
}
|
||||
|
||||
bool SysmanDeviceImp::deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||
return pEvents->eventListen(pEvent, timeout);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -73,6 +73,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
|
||||
ze_result_t deviceGetEccState(zes_device_ecc_properties_t *pState) override;
|
||||
ze_result_t deviceSetEccState(const zes_device_ecc_desc_t *newState, zes_device_ecc_properties_t *pState) override;
|
||||
bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
|
||||
OsSysman *deviceGetOsInterface() override;
|
||||
static void getSysmanDeviceInfo(zes_device_handle_t hDevice, uint32_t &subdeviceId, ze_bool_t &onSubdevice, ze_bool_t useMultiArchEnabled);
|
||||
static PRODUCT_FAMILY getProductFamily(Device *pDevice);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2020-2021 Intel Corporation
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
@@ -11,6 +11,8 @@ set(L0_SRCS_TOOLS_SYSMAN_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kmd_sys_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kmd_sys_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver_imp.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/source/sysman/windows/os_sysman_driver_imp.h"
|
||||
|
||||
#include "shared/source/helpers/sleep.h"
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/sysman.h"
|
||||
#include "level_zero/tools/source/sysman/sysman_const.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t WddmSysmanDriverImp::eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) {
|
||||
bool gotSysmanEvent = false;
|
||||
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
||||
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::duration<uint64_t, std::milli>(timeout);
|
||||
do {
|
||||
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
|
||||
if (gotSysmanEvent) {
|
||||
*pNumDeviceEvents = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gotSysmanEvent) {
|
||||
break;
|
||||
}
|
||||
NEO::sleep(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
|
||||
} while ((L0::steadyClock::now() <= timeToExitLoop));
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
OsSysmanDriver *OsSysmanDriver::create() {
|
||||
WddmSysmanDriverImp *pWddmSysmanDriverImp = new WddmSysmanDriverImp();
|
||||
return static_cast<OsSysmanDriver *>(pWddmSysmanDriverImp);
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class WddmSysmanDriverImp : public OsSysmanDriver {
|
||||
public:
|
||||
WddmSysmanDriverImp() = default;
|
||||
~WddmSysmanDriverImp() override = default;
|
||||
|
||||
ze_result_t eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) override;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "level_zero/tools/source/sysman/events/events_imp.h"
|
||||
#include "level_zero/tools/source/sysman/events/linux/os_events_imp_prelim.h"
|
||||
#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h"
|
||||
#include "level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
@@ -58,6 +59,7 @@ struct MockEventsFsAccess : public FsAccess {
|
||||
bool mockReadValOne = false;
|
||||
bool mockReadValZero = false;
|
||||
bool mockFileNotFoundError = false;
|
||||
ze_result_t mockListDirectoryResult = ZE_RESULT_SUCCESS;
|
||||
|
||||
ze_result_t getValReturnValAsOne(const std::string file, uint32_t &val) {
|
||||
if (file.compare(ueventWedgedFile) == 0) {
|
||||
@@ -109,6 +111,10 @@ struct MockEventsFsAccess : public FsAccess {
|
||||
}
|
||||
|
||||
ze_result_t listDirectory(const std::string directory, std::vector<std::string> &events) override {
|
||||
if (mockListDirectoryResult != ZE_RESULT_SUCCESS) {
|
||||
return mockListDirectoryResult;
|
||||
}
|
||||
|
||||
if (directory.compare(eventsDir) == 0) {
|
||||
events.push_back("error--correctable-eu-grf");
|
||||
events.push_back("error--engine-reset");
|
||||
@@ -200,18 +206,6 @@ struct MockEventsSysfsAccess : public SysfsAccess {
|
||||
MockEventsSysfsAccess() = default;
|
||||
};
|
||||
|
||||
class UdevLibMock : public UdevLib {
|
||||
public:
|
||||
UdevLibMock() = default;
|
||||
|
||||
ADDMETHOD_NOBASE(registerEventsFromSubsystemAndGetFd, int, 5, (std::vector<std::string> & subsystemList));
|
||||
ADDMETHOD_NOBASE(getEventGenerationSourceDevice, dev_t, 0, (void *dev));
|
||||
ADDMETHOD_NOBASE(getEventType, const char *, "change", (void *dev));
|
||||
ADDMETHOD_NOBASE(getEventPropertyValue, const char *, "MOCK", (void *dev, const char *key));
|
||||
ADDMETHOD_NOBASE(allocateDeviceToReceiveData, void *, (void *)(0x12345678), ());
|
||||
ADDMETHOD_NOBASE_VOIDRETURN(dropDeviceReference, (void *dev));
|
||||
};
|
||||
|
||||
struct MockEventsFwInterface : public FirmwareUtil {
|
||||
bool mockIfrStatus = false;
|
||||
ze_result_t fwIfrApplied(bool &ifrStatus) override {
|
||||
@@ -236,11 +230,13 @@ struct MockEventsFwInterface : public FirmwareUtil {
|
||||
class PublicLinuxEventsImp : public L0::LinuxEventsImp {
|
||||
public:
|
||||
PublicLinuxEventsImp(OsSysman *pOsSysman) : LinuxEventsImp(pOsSysman) {}
|
||||
using LinuxEventsImp::checkIfFabricPortStatusChanged;
|
||||
using LinuxEventsImp::listenSystemEvents;
|
||||
using LinuxEventsImp::pUdevLib;
|
||||
using LinuxEventsImp::readFabricDeviceStats;
|
||||
using LinuxEventsImp::registeredEvents;
|
||||
};
|
||||
|
||||
class PublicLinuxEventsUtil : public L0::LinuxEventsUtil {
|
||||
public:
|
||||
PublicLinuxEventsUtil() : LinuxEventsUtil() {}
|
||||
using LinuxEventsUtil::listenSystemEvents;
|
||||
using LinuxEventsUtil::pUdevLib;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h"
|
||||
#include "level_zero/tools/source/sysman/sysman.h"
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/firmware_util/mock_fw_util_fixture.h"
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_procfs_access_fixture.h"
|
||||
@@ -73,6 +74,10 @@ class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test {
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess;
|
||||
pLinuxSysmanImp->pProcfsAccess = pProcfsAccess;
|
||||
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
GlobalOsSysmanDriver = L0::OsSysmanDriver::create();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->init();
|
||||
}
|
||||
void TearDown() override {
|
||||
@@ -80,6 +85,11 @@ class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
if (GlobalOsSysmanDriver != nullptr) {
|
||||
delete GlobalOsSysmanDriver;
|
||||
GlobalOsSysmanDriver = nullptr;
|
||||
}
|
||||
|
||||
DeviceFixture::tearDown();
|
||||
unsetenv("ZES_ENABLE_SYSMAN");
|
||||
}
|
||||
@@ -122,6 +132,11 @@ class SysmanMultiDeviceFixture : public MultiDeviceFixture, public ::testing::Te
|
||||
pLinuxSysmanImp->pFwUtilInterface = pFwUtilInterface;
|
||||
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess;
|
||||
pLinuxSysmanImp->pProcfsAccess = pProcfsAccess;
|
||||
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
GlobalOsSysmanDriver = L0::OsSysmanDriver::create();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->init();
|
||||
subDeviceCount = numSubDevices;
|
||||
}
|
||||
@@ -129,6 +144,10 @@ class SysmanMultiDeviceFixture : public MultiDeviceFixture, public ::testing::Te
|
||||
if (!sysmanUltsEnable) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
if (GlobalOsSysmanDriver != nullptr) {
|
||||
delete GlobalOsSysmanDriver;
|
||||
GlobalOsSysmanDriver = nullptr;
|
||||
}
|
||||
unsetenv("ZES_ENABLE_SYSMAN");
|
||||
MultiDeviceFixture::tearDown();
|
||||
}
|
||||
@@ -153,5 +172,24 @@ class PublicSysfsAccess : public L0::SysfsAccess {
|
||||
using SysfsAccess::accessSyscall;
|
||||
};
|
||||
|
||||
class UdevLibMock : public UdevLib {
|
||||
public:
|
||||
UdevLibMock() = default;
|
||||
|
||||
ADDMETHOD_NOBASE(registerEventsFromSubsystemAndGetFd, int, 5, (std::vector<std::string> & subsystemList));
|
||||
ADDMETHOD_NOBASE(getEventGenerationSourceDevice, dev_t, 0, (void *dev));
|
||||
ADDMETHOD_NOBASE(getEventType, const char *, "change", (void *dev));
|
||||
ADDMETHOD_NOBASE(getEventPropertyValue, const char *, "MOCK", (void *dev, const char *key));
|
||||
ADDMETHOD_NOBASE(allocateDeviceToReceiveData, void *, (void *)(0x12345678), ());
|
||||
ADDMETHOD_NOBASE_VOIDRETURN(dropDeviceReference, (void *dev));
|
||||
};
|
||||
|
||||
class PublicLinuxSysmanDriverImp : public L0::LinuxSysmanDriverImp {
|
||||
public:
|
||||
PublicLinuxSysmanDriverImp() : LinuxSysmanDriverImp() {}
|
||||
using LinuxSysmanDriverImp::pLinuxEventsUtil;
|
||||
using LinuxSysmanDriverImp::pUdevLib;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
@@ -377,6 +377,19 @@ TEST_F(SysmanDeviceFixture, GivenValidEnumeratedHandlesWhenReleaseIsCalledThenHa
|
||||
EXPECT_EQ(count, 0u);
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenDriverEventsUtilAsNullWhenSysmanDriverDestructorIsCalledThenVerifyNoExceptionOccured) {
|
||||
VariableBackup<L0::OsSysmanDriver *> driverBackup(&GlobalOsSysmanDriver);
|
||||
auto pPublicLinuxSysmanDriverImp = new PublicLinuxSysmanDriverImp();
|
||||
GlobalOsSysmanDriver = static_cast<L0::OsSysmanDriver *>(pPublicLinuxSysmanDriverImp);
|
||||
|
||||
auto pUdevLib = new UdevLibMock();
|
||||
pPublicLinuxSysmanDriverImp->pUdevLib = pUdevLib;
|
||||
|
||||
delete pPublicLinuxSysmanDriverImp->pLinuxEventsUtil;
|
||||
pPublicLinuxSysmanDriverImp->pLinuxEventsUtil = nullptr;
|
||||
EXPECT_NO_THROW(L0::osSysmanDriverDestructor());
|
||||
}
|
||||
|
||||
TEST_F(SysmanMultiDeviceFixture, GivenValidDeviceHandleHavingSubdevicesWhenValidatingSysmanHandlesForSubdevicesThenSysmanHandleForSubdeviceWillBeSameAsSysmanHandleForDevice) {
|
||||
ze_device_handle_t hSysman = device->toHandle();
|
||||
auto pSysmanDeviceOriginal = static_cast<DeviceImp *>(device)->getSysmanHandle();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/tools/source/sysman/sysman.h"
|
||||
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
||||
#include "level_zero/tools/source/sysman/windows/os_sysman_driver_imp.h"
|
||||
#include "level_zero/tools/test/unit_tests/sources/sysman/mocks/mock_sysman_env_vars.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
@@ -48,12 +49,22 @@ class SysmanDeviceFixture : public DeviceFixture, public SysmanEnabledFixture {
|
||||
pSysmanDeviceImp = static_cast<SysmanDeviceImp *>(pSysmanDevice);
|
||||
pOsSysman = pSysmanDeviceImp->pOsSysman;
|
||||
pWddmSysmanImp = static_cast<PublicWddmSysmanImp *>(pOsSysman);
|
||||
|
||||
if (GlobalOsSysmanDriver == nullptr) {
|
||||
GlobalOsSysmanDriver = L0::OsSysmanDriver::create();
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (!sysmanUltsEnable) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
if (GlobalOsSysmanDriver != nullptr) {
|
||||
delete GlobalOsSysmanDriver;
|
||||
GlobalOsSysmanDriver = nullptr;
|
||||
}
|
||||
|
||||
SysmanEnabledFixture::TearDown();
|
||||
DeviceFixture::tearDown();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -47,5 +47,10 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenGettingFwUtilInterfaceAndG
|
||||
pWddmSysmanImp->pFwUtilInterface = pFwUtilInterfaceOld;
|
||||
}
|
||||
|
||||
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenGetOsInterfaceIsInvokedThenVerifyThatOsInterfaceIsValid) {
|
||||
auto osInterface = pSysmanDeviceImp->deviceGetOsInterface();
|
||||
EXPECT_EQ(pWddmSysmanImp, osInterface);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user