mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
feature(sysman): Add support for events module
- Port events module to new sysman design - Add events ULTs for new sysman interface Related-To: LOCI-4120 Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
a15e8a9679
commit
fe4330e588
@@ -943,7 +943,10 @@ ze_result_t zesRasGetState(
|
|||||||
ze_result_t zesDeviceEventRegister(
|
ze_result_t zesDeviceEventRegister(
|
||||||
zes_device_handle_t hDevice,
|
zes_device_handle_t hDevice,
|
||||||
zes_event_type_flags_t events) {
|
zes_event_type_flags_t events) {
|
||||||
return L0::SysmanDevice::deviceEventRegister(hDevice, events);
|
if (L0::sysmanInitFromCore) {
|
||||||
|
return L0::SysmanDevice::deviceEventRegister(hDevice, events);
|
||||||
|
}
|
||||||
|
return L0::Sysman::SysmanDevice::deviceEventRegister(hDevice, events);
|
||||||
}
|
}
|
||||||
|
|
||||||
ze_result_t zesDriverEventListen(
|
ze_result_t zesDriverEventListen(
|
||||||
@@ -953,7 +956,10 @@ ze_result_t zesDriverEventListen(
|
|||||||
zes_device_handle_t *phDevices,
|
zes_device_handle_t *phDevices,
|
||||||
uint32_t *pNumDeviceEvents,
|
uint32_t *pNumDeviceEvents,
|
||||||
zes_event_type_flags_t *pEvents) {
|
zes_event_type_flags_t *pEvents) {
|
||||||
return L0::DriverHandle::fromHandle(hDriver)->sysmanEventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
if (L0::sysmanInitFromCore) {
|
||||||
|
return L0::DriverHandle::fromHandle(hDriver)->sysmanEventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||||
|
}
|
||||||
|
return L0::Sysman::SysmanDriverHandle::fromHandle(hDriver)->sysmanEventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
ze_result_t zesDriverEventListenEx(
|
ze_result_t zesDriverEventListenEx(
|
||||||
@@ -963,7 +969,10 @@ ze_result_t zesDriverEventListenEx(
|
|||||||
zes_device_handle_t *phDevices,
|
zes_device_handle_t *phDevices,
|
||||||
uint32_t *pNumDeviceEvents,
|
uint32_t *pNumDeviceEvents,
|
||||||
zes_event_type_flags_t *pEvents) {
|
zes_event_type_flags_t *pEvents) {
|
||||||
return L0::DriverHandle::fromHandle(hDriver)->sysmanEventsListenEx(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
if (L0::sysmanInitFromCore) {
|
||||||
|
return L0::DriverHandle::fromHandle(hDriver)->sysmanEventsListenEx(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||||
|
}
|
||||||
|
return L0::Sysman::SysmanDriverHandle::fromHandle(hDriver)->sysmanEventsListenEx(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
ze_result_t zesDeviceEnumDiagnosticTestSuites(
|
ze_result_t zesDeviceEnumDiagnosticTestSuites(
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ target_sources(${L0_STATIC_LIB_NAME}
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_device_imp.h
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_device_imp.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman.h
|
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id.h
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectories()
|
add_subdirectories()
|
||||||
|
|||||||
17
level_zero/sysman/source/events/CMakeLists.txt
Normal file
17
level_zero/sysman/source/events/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2023 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
target_sources(${L0_STATIC_LIB_NAME}
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_events.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_events_imp.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_events_imp.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_events.h
|
||||||
|
)
|
||||||
|
|
||||||
|
add_subdirectories()
|
||||||
|
|
||||||
14
level_zero/sysman/source/events/linux/CMakeLists.txt
Normal file
14
level_zero/sysman/source/events/linux/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2023 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
target_sources(${L0_STATIC_LIB_NAME}
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_events_imp.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_events_imp.h
|
||||||
|
)
|
||||||
|
endif()
|
||||||
437
level_zero/sysman/source/events/linux/sysman_os_events_imp.cpp
Normal file
437
level_zero/sysman/source/events/linux/sysman_os_events_imp.cpp
Normal file
@@ -0,0 +1,437 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/linux/sysman_os_events_imp.h"
|
||||||
|
|
||||||
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||||
|
#include "shared/source/utilities/directory.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/sysman_events_imp.h"
|
||||||
|
#include "level_zero/sysman/source/linux/zes_os_sysman_driver_imp.h"
|
||||||
|
#include "level_zero/sysman/source/linux/zes_os_sysman_imp.h"
|
||||||
|
#include "level_zero/sysman/source/memory/linux/sysman_os_memory_imp_prelim.h"
|
||||||
|
#include "level_zero/sysman/source/sysman_driver_handle_imp.h"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pLinuxSysmanDriverImp = static_cast<LinuxSysmanDriverImp *>(GlobalSysmanDriver->pOsSysmanDriver);
|
||||||
|
if (pLinuxSysmanDriverImp == nullptr) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Os Sysman driver not initialized\n");
|
||||||
|
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||||
|
}
|
||||||
|
pLinuxSysmanDriverImp->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
LinuxEventsUtil::LinuxEventsUtil(LinuxSysmanDriverImp *pOsSysmanDriverImp) : pLinuxSysmanDriverImp(pOsSysmanDriverImp) {
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (ZE_RESULT_SUCCESS == rasHandle->rasGetState(&state, 0)) {
|
||||||
|
uint64_t totalCategoryThreshold = 0;
|
||||||
|
for (int i = 0; i < ZES_MAX_RAS_ERROR_CATEGORY_COUNT; i++) {
|
||||||
|
totalCategoryThreshold += state.category[i];
|
||||||
|
if ((config.detailedThresholds.category[i] > 0) && (state.category[i] > config.detailedThresholds.category[i])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((config.totalThreshold > 0) && (totalCategoryThreshold > config.totalThreshold)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxEventsUtil::eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice) {
|
||||||
|
std::call_once(initEventsOnce, [this]() {
|
||||||
|
this->init();
|
||||||
|
});
|
||||||
|
|
||||||
|
zes_event_type_flags_t prevRegisteredEvents = 0;
|
||||||
|
if (deviceEventsMap.find(pSysmanDevice) != deviceEventsMap.end()) {
|
||||||
|
prevRegisteredEvents = deviceEventsMap[pSysmanDevice];
|
||||||
|
}
|
||||||
|
|
||||||
|
eventsMutex.lock();
|
||||||
|
if (!events) {
|
||||||
|
// If user is trying to register events with empty events argument, then clear all the registered events
|
||||||
|
if (deviceEventsMap.find(pSysmanDevice) != deviceEventsMap.end()) {
|
||||||
|
deviceEventsMap[pSysmanDevice] = events;
|
||||||
|
} else {
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
registeredEvents |= (events & supportedEventMask);
|
||||||
|
deviceEventsMap.emplace(pSysmanDevice, registeredEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to Pipe only if eventregister() is called during listen and previously registered events are modified.
|
||||||
|
if ((pipeFd[1] != -1) && (prevRegisteredEvents != deviceEventsMap[pSysmanDevice])) {
|
||||||
|
uint8_t value = 0x00;
|
||||||
|
if (NEO::SysCalls::write(pipeFd[1], &value, 1) < 0) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Write to Pipe failed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eventsMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxEventsUtil::init() {
|
||||||
|
pUdevLib = pLinuxSysmanDriverImp->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::Sysman::SysmanDevice::fromHandle(phDevices[devIndex]));
|
||||||
|
eventsMutex.lock();
|
||||||
|
if (deviceEventsMap.find(device) != deviceEventsMap.end()) {
|
||||||
|
registeredEvents[devIndex] = deviceEventsMap[device];
|
||||||
|
}
|
||||||
|
eventsMutex.unlock();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listenSystemEvents(pEvents, count, registeredEvents, phDevices, timeout)) {
|
||||||
|
*pNumDeviceEvents = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxEventsUtil::isResetRequired(void *dev, zes_event_type_flags_t &pEvent) {
|
||||||
|
if (action.compare(change) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> properties{"RESET_FAILED", "RESET_REQUIRED"};
|
||||||
|
for (auto &property : properties) {
|
||||||
|
const char *propVal = nullptr;
|
||||||
|
propVal = pUdevLib->getEventPropertyValue(dev, property.c_str());
|
||||||
|
if (propVal && atoi(propVal) == 1) {
|
||||||
|
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_RESET_REQUIRED;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxEventsUtil::checkDeviceDetachEvent(zes_event_type_flags_t &pEvent) {
|
||||||
|
if (action.compare(remove) == 0) {
|
||||||
|
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxEventsUtil::checkDeviceAttachEvent(zes_event_type_flags_t &pEvent) {
|
||||||
|
if (action.compare(add) == 0) {
|
||||||
|
pEvent |= ZES_EVENT_TYPE_FLAG_DEVICE_ATTACH;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxEventsUtil::checkIfMemHealthChanged(void *dev, zes_event_type_flags_t &pEvent) {
|
||||||
|
if (action.compare(change) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> properties{"MEM_HEALTH_ALARM", "RESET_REQUIRED", "EC_PENDING", "DEGRADED", "EC_FAILED", "SPARING_STATUS_UNKNOWN"};
|
||||||
|
for (auto &property : properties) {
|
||||||
|
const char *propVal = nullptr;
|
||||||
|
propVal = pUdevLib->getEventPropertyValue(dev, property.c_str());
|
||||||
|
if (propVal && atoi(propVal) == 1) {
|
||||||
|
pEvent |= ZES_EVENT_TYPE_FLAG_MEM_HEALTH;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxEventsUtil::checkIfFabricPortStatusChanged(void *dev, zes_event_type_flags_t &pEvent) {
|
||||||
|
if (action.compare(change) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *str = pUdevLib->getEventPropertyValue(dev, "TYPE");
|
||||||
|
if (str == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string expectedStr = "PORT_CHANGE";
|
||||||
|
if (expectedStr == str) {
|
||||||
|
pEvent |= ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxEventsUtil::getDevIndexToDevPathMap(std::vector<zes_event_type_flags_t> ®isteredEvents, uint32_t count, zes_device_handle_t *phDevices, std::map<uint32_t, std::string> &mapOfDevIndexToDevPath) {
|
||||||
|
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||||
|
auto device = static_cast<SysmanDeviceImp *>(L0::Sysman::SysmanDevice::fromHandle(phDevices[devIndex]));
|
||||||
|
registeredEvents[devIndex] = deviceEventsMap[device];
|
||||||
|
if (!registeredEvents[devIndex]) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
std::string bdf;
|
||||||
|
auto pSysfsAccess = &static_cast<L0::Sysman::LinuxSysmanImp *>(device->deviceGetOsInterface())->getSysfsAccess();
|
||||||
|
if (pSysfsAccess->getRealPath("device", bdf) == ZE_RESULT_SUCCESS) {
|
||||||
|
// /sys needs to be removed from real path inorder to equate with
|
||||||
|
// DEVPATH property of uevent.
|
||||||
|
// Example of real path: /sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0
|
||||||
|
// Example of DEVPATH: /devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0/i915.iaf.0
|
||||||
|
const auto loc = bdf.find("/devices");
|
||||||
|
if (loc == std::string::npos) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Invalid device path\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bdf = bdf.substr(loc);
|
||||||
|
mapOfDevIndexToDevPath.insert({devIndex, bdf});
|
||||||
|
} else {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Failed to get real path of device\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxEventsUtil::checkDeviceEvents(std::vector<zes_event_type_flags_t> ®isteredEvents, std::map<uint32_t, std::string> mapOfDevIndexToDevPath, zes_event_type_flags_t *pEvents, void *dev) {
|
||||||
|
const char *devicePath = pUdevLib->getEventPropertyValue(dev, "DEVPATH");
|
||||||
|
bool retVal = false;
|
||||||
|
if (devicePath != nullptr) {
|
||||||
|
std::string devPath(devicePath);
|
||||||
|
for (auto it = mapOfDevIndexToDevPath.begin(); it != mapOfDevIndexToDevPath.end(); it++) {
|
||||||
|
if (devPath.find(it->second.c_str()) != std::string::npos) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (registeredEvents[it->first] & ZES_EVENT_TYPE_FLAG_FABRIC_PORT_HEALTH) {
|
||||||
|
if (checkIfFabricPortStatusChanged(dev, pEvents[it->first])) {
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
bool retval = false;
|
||||||
|
struct pollfd pfd[2];
|
||||||
|
std::vector<std::string> subsystemList;
|
||||||
|
std::map<uint32_t, std::string> mapOfDevIndexToDevPath = {};
|
||||||
|
|
||||||
|
if (pUdevLib == nullptr) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "libudev library instantiation failed\n");
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
subsystemList.push_back("drm");
|
||||||
|
subsystemList.push_back("auxiliary");
|
||||||
|
pfd[0].fd = pUdevLib->registerEventsFromSubsystemAndGetFd(subsystemList);
|
||||||
|
pfd[0].events = POLLIN;
|
||||||
|
pfd[0].revents = 0;
|
||||||
|
|
||||||
|
eventsMutex.lock();
|
||||||
|
if (NEO::SysCalls::pipe(pipeFd) < 0) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Creation of pipe failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
pfd[1].fd = pipeFd[0];
|
||||||
|
pfd[1].events = POLLIN;
|
||||||
|
pfd[1].revents = 0;
|
||||||
|
|
||||||
|
auto start = L0::Sysman::SteadyClock::now();
|
||||||
|
std::chrono::duration<double, std::milli> timeElapsed;
|
||||||
|
getDevIndexToDevPathMap(registeredEvents, count, phDevices, mapOfDevIndexToDevPath);
|
||||||
|
eventsMutex.unlock();
|
||||||
|
while (NEO::SysCalls::poll(pfd, 2, static_cast<int>(timeout)) > 0) {
|
||||||
|
bool eventReceived = false;
|
||||||
|
for (auto i = 0; i < 2; i++) {
|
||||||
|
if (pfd[i].revents != 0) {
|
||||||
|
if (pfd[i].fd == pipeFd[0]) {
|
||||||
|
eventsMutex.lock();
|
||||||
|
uint8_t dummy;
|
||||||
|
NEO::SysCalls::read(pipeFd[0], &dummy, 1);
|
||||||
|
mapOfDevIndexToDevPath.clear();
|
||||||
|
getDevIndexToDevPathMap(registeredEvents, count, phDevices, mapOfDevIndexToDevPath);
|
||||||
|
eventsMutex.unlock();
|
||||||
|
} else {
|
||||||
|
eventReceived = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapOfDevIndexToDevPath.empty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!eventReceived) {
|
||||||
|
timeElapsed = L0::Sysman::SteadyClock::now() - start;
|
||||||
|
if (timeout > timeElapsed.count()) {
|
||||||
|
timeout = timeout - timeElapsed.count();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *dev = nullptr;
|
||||||
|
dev = pUdevLib->allocateDeviceToReceiveData();
|
||||||
|
if (dev == nullptr) {
|
||||||
|
timeElapsed = L0::Sysman::SteadyClock::now() - start;
|
||||||
|
if (timeout > timeElapsed.count()) {
|
||||||
|
timeout = timeout - timeElapsed.count();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto eventTypePtr = pUdevLib->getEventType(dev);
|
||||||
|
if (eventTypePtr != nullptr) {
|
||||||
|
action = std::string(eventTypePtr);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = checkDeviceEvents(registeredEvents, mapOfDevIndexToDevPath, pEvents, dev);
|
||||||
|
pUdevLib->dropDeviceReference(dev);
|
||||||
|
if (retval) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
timeElapsed = L0::Sysman::SteadyClock::now() - start;
|
||||||
|
if (timeout > timeElapsed.count()) {
|
||||||
|
timeout = timeout - timeElapsed.count();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eventsMutex.lock();
|
||||||
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
|
if (pipeFd[i] != -1) {
|
||||||
|
NEO::SysCalls::close(pipeFd[i]);
|
||||||
|
pipeFd[i] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eventsMutex.unlock();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
69
level_zero/sysman/source/events/linux/sysman_os_events_imp.h
Normal file
69
level_zero/sysman/source/events/linux/sysman_os_events_imp.h
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "level_zero/sysman/source/events/sysman_os_events.h"
|
||||||
|
#include "level_zero/sysman/source/linux/udev/udev_lib.h"
|
||||||
|
#include "level_zero/sysman/source/linux/zes_os_sysman_imp.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
class LinuxSysmanDriverImp;
|
||||||
|
|
||||||
|
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() = delete;
|
||||||
|
LinuxEventsImp(OsSysman *pOsSysman);
|
||||||
|
~LinuxEventsImp() override = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class LinuxEventsUtil {
|
||||||
|
|
||||||
|
public:
|
||||||
|
LinuxEventsUtil() = delete;
|
||||||
|
LinuxEventsUtil(LinuxSysmanDriverImp *pOsSysmanDriverImp);
|
||||||
|
~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;
|
||||||
|
LinuxSysmanDriverImp *pLinuxSysmanDriverImp = nullptr;
|
||||||
|
int pipeFd[2] = {-1, -1};
|
||||||
|
std::map<SysmanDeviceImp *, zes_event_type_flags_t> deviceEventsMap;
|
||||||
|
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 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:
|
||||||
|
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);
|
||||||
|
void getDevIndexToDevPathMap(std::vector<zes_event_type_flags_t> ®isteredEvents, uint32_t count, zes_device_handle_t *phDevices, std::map<uint32_t, std::string> &mapOfDevIndexToDevPath);
|
||||||
|
bool checkDeviceEvents(std::vector<zes_event_type_flags_t> ®isteredEvents, std::map<uint32_t, std::string> mapOfDevIndexToDevPath, zes_event_type_flags_t *pEvents, void *dev);
|
||||||
|
std::once_flag initEventsOnce;
|
||||||
|
std::mutex eventsMutex;
|
||||||
|
void init();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
22
level_zero/sysman/source/events/sysman_events.h
Normal file
22
level_zero/sysman/source/events/sysman_events.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <level_zero/zes_api.h>
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
class Events {
|
||||||
|
public:
|
||||||
|
virtual ~Events(){};
|
||||||
|
virtual ze_result_t eventRegister(zes_event_type_flags_t events) = 0;
|
||||||
|
virtual bool eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) = 0;
|
||||||
|
virtual void init() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
43
level_zero/sysman/source/events/sysman_events_imp.cpp
Normal file
43
level_zero/sysman/source/events/sysman_events_imp.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/sysman_events_imp.h"
|
||||||
|
|
||||||
|
#include "shared/source/helpers/debug_helpers.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
ze_result_t EventsImp::eventRegister(zes_event_type_flags_t events) {
|
||||||
|
initEvents();
|
||||||
|
return pOsEvents->eventRegister(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EventsImp::eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||||
|
initEvents();
|
||||||
|
return pOsEvents->eventListen(pEvent, timeout);
|
||||||
|
}
|
||||||
|
void EventsImp::initEvents() {
|
||||||
|
std::call_once(initEventsOnce, [this]() {
|
||||||
|
this->init();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
void EventsImp::init() {
|
||||||
|
if (pOsEvents == nullptr) {
|
||||||
|
pOsEvents = OsEvents::create(pOsSysman);
|
||||||
|
}
|
||||||
|
UNRECOVERABLE_IF(nullptr == pOsEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventsImp::~EventsImp() {
|
||||||
|
if (nullptr != pOsEvents) {
|
||||||
|
delete pOsEvents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
37
level_zero/sysman/source/events/sysman_events_imp.h
Normal file
37
level_zero/sysman/source/events/sysman_events_imp.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/sysman_events.h"
|
||||||
|
#include "level_zero/sysman/source/events/sysman_os_events.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
class EventsImp : public Events, NEO::NonCopyableOrMovableClass {
|
||||||
|
public:
|
||||||
|
void init() override;
|
||||||
|
ze_result_t eventRegister(zes_event_type_flags_t events) override;
|
||||||
|
bool eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
|
||||||
|
OsEvents *pOsEvents = nullptr;
|
||||||
|
|
||||||
|
EventsImp() = default;
|
||||||
|
EventsImp(OsSysman *pOsSysman) : pOsSysman(pOsSysman){};
|
||||||
|
~EventsImp() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
OsSysman *pOsSysman = nullptr;
|
||||||
|
std::once_flag initEventsOnce;
|
||||||
|
void initEvents();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
25
level_zero/sysman/source/events/sysman_os_events.h
Normal file
25
level_zero/sysman/source/events/sysman_os_events.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/os_sysman.h"
|
||||||
|
#include <level_zero/zes_api.h>
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
class OsEvents {
|
||||||
|
public:
|
||||||
|
static OsEvents *create(OsSysman *pOsSysman);
|
||||||
|
virtual bool eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) = 0;
|
||||||
|
virtual ze_result_t eventRegister(zes_event_type_flags_t events) = 0;
|
||||||
|
virtual ~OsEvents() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
14
level_zero/sysman/source/events/windows/CMakeLists.txt
Normal file
14
level_zero/sysman/source/events/windows/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2023 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
target_sources(${L0_STATIC_LIB_NAME}
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_events_imp.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_os_events_imp.cpp
|
||||||
|
)
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/windows/sysman_os_events_imp.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
ze_result_t WddmEventsImp::eventRegister(zes_event_type_flags_t events) {
|
||||||
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WddmEventsImp::eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WddmEventsImp::WddmEventsImp(OsSysman *pOsSysman) {
|
||||||
|
}
|
||||||
|
|
||||||
|
OsEvents *OsEvents::create(OsSysman *pOsSysman) {
|
||||||
|
WddmEventsImp *pWddmEventsImp = new WddmEventsImp(pOsSysman);
|
||||||
|
return static_cast<OsEvents *>(pWddmEventsImp);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/sysman_os_events.h"
|
||||||
|
#include "level_zero/sysman/source/windows/zes_os_sysman_imp.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
class WddmEventsImp : 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;
|
||||||
|
WddmEventsImp(OsSysman *pOsSysman);
|
||||||
|
WddmEventsImp() = default;
|
||||||
|
~WddmEventsImp() override = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
@@ -14,6 +14,8 @@ if(UNIX)
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_fs_access.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_fs_access.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id_linux.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id_linux.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id_linux.h
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id_linux.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/zes_os_sysman_driver_imp.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/zes_os_sysman_driver_imp.h
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
22
level_zero/sysman/source/linux/udev/CMakeLists.txt
Normal file
22
level_zero/sysman/source/linux/udev/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2023 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
if(LIBUDEV_FOUND)
|
||||||
|
target_sources(${L0_STATIC_LIB_NAME}
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/udev_lib_imp.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/udev_lib_imp.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/udev_lib.h
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
target_sources(${L0_STATIC_LIB_NAME}
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/udev_lib_imp_stub.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/udev_lib.h
|
||||||
|
)
|
||||||
|
endif()
|
||||||
28
level_zero/sysman/source/linux/udev/udev_lib.h
Normal file
28
level_zero/sysman/source/linux/udev/udev_lib.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
class UdevLib {
|
||||||
|
public:
|
||||||
|
UdevLib() = default;
|
||||||
|
static UdevLib *create();
|
||||||
|
virtual int registerEventsFromSubsystemAndGetFd(std::vector<std::string> &subsystemList) = 0;
|
||||||
|
virtual dev_t getEventGenerationSourceDevice(void *dev) = 0;
|
||||||
|
virtual const char *getEventType(void *dev) = 0;
|
||||||
|
virtual const char *getEventPropertyValue(void *dev, const char *key) = 0;
|
||||||
|
virtual void *allocateDeviceToReceiveData() = 0;
|
||||||
|
virtual void dropDeviceReference(void *dev) = 0;
|
||||||
|
virtual ~UdevLib() {}
|
||||||
|
};
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
92
level_zero/sysman/source/linux/udev/udev_lib_imp.cpp
Normal file
92
level_zero/sysman/source/linux/udev/udev_lib_imp.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/linux/udev/udev_lib_imp.h"
|
||||||
|
|
||||||
|
#include "shared/source/helpers/debug_helpers.h"
|
||||||
|
#include "shared/source/utilities/directory.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
static constexpr std::string_view libUdevlFile = "libudev.so";
|
||||||
|
const std::string udevNewRoutine = "udev_new";
|
||||||
|
const std::string udevMonitorNewFromNetlinkRoutine = "udev_monitor_new_from_netlink";
|
||||||
|
const std::string udevMonitorFilterAddMatchSubsystemDevtypeRoutine = "udev_monitor_filter_add_match_subsystem_devtype";
|
||||||
|
const std::string udevMonitorEnableReceivingRoutine = "udev_monitor_enable_receiving";
|
||||||
|
const std::string udevMonitorGetFdRoutine = "udev_monitor_get_fd";
|
||||||
|
const std::string udevMonitorReceiveDeviceRoutine = "udev_monitor_receive_device";
|
||||||
|
const std::string udevDeviceGetDevnumRoutine = "udev_device_get_devnum";
|
||||||
|
const std::string udevDeviceGetActionRoutine = "udev_device_get_action";
|
||||||
|
const std::string udevDeviceGetPropertyValueRoutine = "udev_device_get_property_value";
|
||||||
|
const std::string udevDeviceUnrefRoutine = "udev_device_unref";
|
||||||
|
|
||||||
|
bool UdevLibImp::loadEntryPoints() {
|
||||||
|
bool ok = getSymbolAddr(udevMonitorNewFromNetlinkRoutine, pUdevMonitorNewFromNetlinkEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevNewRoutine, pUdevNewEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevMonitorFilterAddMatchSubsystemDevtypeRoutine, pUdevMonitorFilterAddMatchSubsystemDevtypeEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevMonitorEnableReceivingRoutine, pUdevMonitorEnableReceivingEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevMonitorGetFdRoutine, pUdevMonitorGetFdEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevMonitorReceiveDeviceRoutine, pUdevMonitorReceiveDeviceEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevDeviceGetDevnumRoutine, pUdevDeviceGetDevnumEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevDeviceGetActionRoutine, pUdevDeviceGetActionEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevDeviceGetPropertyValueRoutine, pUdevDeviceGetPropertyValueEntry);
|
||||||
|
ok = ok && getSymbolAddr(udevDeviceUnrefRoutine, pUdevDeviceUnrefEntry);
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *UdevLibImp::getEventPropertyValue(void *dev, const char *key) {
|
||||||
|
return pUdevDeviceGetPropertyValueEntry(reinterpret_cast<struct udev_device *>(dev), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *UdevLibImp::getEventType(void *dev) {
|
||||||
|
return pUdevDeviceGetActionEntry(reinterpret_cast<struct udev_device *>(dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
void *UdevLibImp::allocateDeviceToReceiveData() {
|
||||||
|
struct udev_device *dev = pUdevMonitorReceiveDeviceEntry(mon);
|
||||||
|
return reinterpret_cast<void *>(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_t UdevLibImp::getEventGenerationSourceDevice(void *dev) {
|
||||||
|
return pUdevDeviceGetDevnumEntry(reinterpret_cast<struct udev_device *>(dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
int UdevLibImp::registerEventsFromSubsystemAndGetFd(std::vector<std::string> &subsystemList) {
|
||||||
|
for (const auto &subsystem : subsystemList) {
|
||||||
|
pUdevMonitorFilterAddMatchSubsystemDevtypeEntry(mon, subsystem.c_str(), NULL);
|
||||||
|
}
|
||||||
|
if (pUdevMonitorEnableReceivingEntry(mon) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return pUdevMonitorGetFdEntry(mon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdevLibImp::dropDeviceReference(void *dev) {
|
||||||
|
pUdevDeviceUnrefEntry(reinterpret_cast<struct udev_device *>(dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UdevLibImp::init() {
|
||||||
|
mon = pUdevMonitorNewFromNetlinkEntry(pUdevNewEntry(), "kernel");
|
||||||
|
return (mon != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
UdevLibImp::~UdevLibImp(){};
|
||||||
|
|
||||||
|
UdevLib *UdevLib::create() {
|
||||||
|
UdevLibImp *pUdevLib = new UdevLibImp();
|
||||||
|
UNRECOVERABLE_IF(nullptr == pUdevLib);
|
||||||
|
pUdevLib->libraryHandle.reset(NEO::OsLibrary::load(std::string(libUdevlFile)));
|
||||||
|
if (pUdevLib->libraryHandle == nullptr || pUdevLib->loadEntryPoints() == false || !pUdevLib->init()) {
|
||||||
|
delete pUdevLib;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return static_cast<UdevLib *>(pUdevLib);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
72
level_zero/sysman/source/linux/udev/udev_lib_imp.h
Normal file
72
level_zero/sysman/source/linux/udev/udev_lib_imp.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||||
|
#include "shared/source/os_interface/os_library.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/linux/udev/udev_lib.h"
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
typedef struct udev *(*pUdevNew)(void);
|
||||||
|
typedef struct udev_monitor *(*pUdevMonitorNewFromNetlink)(struct udev *, const char *);
|
||||||
|
typedef int (*pUdevMonitorFilterAddMatchSubsystemDevtype)(struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype);
|
||||||
|
typedef int (*pUdevMonitorEnableReceiving)(struct udev_monitor *udev_monitor);
|
||||||
|
typedef int (*pUdevMonitorGetFd)(struct udev_monitor *udev_monitor);
|
||||||
|
typedef struct udev_device *(*pUdevMonitorReceiveDevice)(struct udev_monitor *udev_monitor);
|
||||||
|
typedef dev_t (*pUdevDeviceGetDevnum)(struct udev_device *udev_device);
|
||||||
|
typedef const char *(*pUdevDeviceGetAction)(struct udev_device *udev_device);
|
||||||
|
typedef const char *(*pUdevDeviceGetPropertyValue)(struct udev_device *udev_device, const char *key);
|
||||||
|
typedef struct udev_device *(*pUdevDeviceUnref)(struct udev_device *udev_device);
|
||||||
|
|
||||||
|
class UdevLibImp : public UdevLib {
|
||||||
|
public:
|
||||||
|
UdevLibImp() = default;
|
||||||
|
~UdevLibImp() override;
|
||||||
|
std::unique_ptr<NEO::OsLibrary> libraryHandle;
|
||||||
|
bool loadEntryPoints();
|
||||||
|
template <class T>
|
||||||
|
bool getSymbolAddr(const std::string name, T &proc) {
|
||||||
|
void *addr = libraryHandle->getProcAddress(name);
|
||||||
|
proc = reinterpret_cast<T>(addr);
|
||||||
|
return nullptr != proc;
|
||||||
|
}
|
||||||
|
bool init();
|
||||||
|
int registerEventsFromSubsystemAndGetFd(std::vector<std::string> &subsystemList) override;
|
||||||
|
dev_t getEventGenerationSourceDevice(void *dev) override;
|
||||||
|
const char *getEventType(void *dev) override;
|
||||||
|
const char *getEventPropertyValue(void *dev, const char *key) override;
|
||||||
|
void *allocateDeviceToReceiveData() override;
|
||||||
|
void dropDeviceReference(void *dev) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
pUdevNew pUdevNewEntry = nullptr;
|
||||||
|
pUdevMonitorNewFromNetlink pUdevMonitorNewFromNetlinkEntry = nullptr;
|
||||||
|
pUdevMonitorFilterAddMatchSubsystemDevtype pUdevMonitorFilterAddMatchSubsystemDevtypeEntry = nullptr;
|
||||||
|
pUdevMonitorEnableReceiving pUdevMonitorEnableReceivingEntry = nullptr;
|
||||||
|
pUdevMonitorGetFd pUdevMonitorGetFdEntry = nullptr;
|
||||||
|
pUdevMonitorReceiveDevice pUdevMonitorReceiveDeviceEntry = nullptr;
|
||||||
|
pUdevDeviceGetDevnum pUdevDeviceGetDevnumEntry = nullptr;
|
||||||
|
pUdevDeviceGetAction pUdevDeviceGetActionEntry = nullptr;
|
||||||
|
pUdevDeviceGetPropertyValue pUdevDeviceGetPropertyValueEntry = nullptr;
|
||||||
|
pUdevDeviceUnref pUdevDeviceUnrefEntry = nullptr;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct udev_monitor *mon = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
18
level_zero/sysman/source/linux/udev/udev_lib_imp_stub.cpp
Normal file
18
level_zero/sysman/source/linux/udev/udev_lib_imp_stub.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/linux/udev/udev_lib.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
UdevLib *UdevLib::create() {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
57
level_zero/sysman/source/linux/zes_os_sysman_driver_imp.cpp
Normal file
57
level_zero/sysman/source/linux/zes_os_sysman_driver_imp.cpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/linux/zes_os_sysman_driver_imp.h"
|
||||||
|
|
||||||
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/linux/sysman_os_events_imp.h"
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
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::Sysman::UdevLib *LinuxSysmanDriverImp::getUdevLibHandle() {
|
||||||
|
if (pUdevLib == nullptr) {
|
||||||
|
pUdevLib = UdevLib::create();
|
||||||
|
}
|
||||||
|
return pUdevLib;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinuxSysmanDriverImp::LinuxSysmanDriverImp() {
|
||||||
|
pLinuxEventsUtil = new LinuxEventsUtil(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
33
level_zero/sysman/source/linux/zes_os_sysman_driver_imp.h
Normal file
33
level_zero/sysman/source/linux/zes_os_sysman_driver_imp.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "level_zero/sysman/source/linux/udev/udev_lib.h"
|
||||||
|
#include "level_zero/sysman/source/os_sysman_driver.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
class LinuxEventsUtil;
|
||||||
|
struct SysmanDeviceImp;
|
||||||
|
|
||||||
|
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::Sysman::UdevLib *getUdevLibHandle();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
L0::Sysman::UdevLib *pUdevLib = nullptr;
|
||||||
|
L0::Sysman::LinuxEventsUtil *pLinuxEventsUtil = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
22
level_zero/sysman/source/os_sysman_driver.h
Normal file
22
level_zero/sysman/source/os_sysman_driver.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "level_zero/zes_api.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
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 Sysman
|
||||||
|
} // namespace L0
|
||||||
@@ -154,5 +154,10 @@ ze_result_t SysmanDevice::fanGet(zes_device_handle_t hDevice, uint32_t *pCount,
|
|||||||
return pSysmanDevice->fanGet(pCount, phFan);
|
return pSysmanDevice->fanGet(pCount, phFan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ze_result_t SysmanDevice::deviceEventRegister(zes_device_handle_t hDevice, zes_event_type_flags_t events) {
|
||||||
|
auto pSysmanDevice = L0::Sysman::SysmanDevice::fromHandle(hDevice);
|
||||||
|
return pSysmanDevice->deviceEventRegister(events);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sysman
|
} // namespace Sysman
|
||||||
} // namespace L0
|
} // namespace L0
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "level_zero/sysman/source/diagnostics/sysman_diagnostics.h"
|
#include "level_zero/sysman/source/diagnostics/sysman_diagnostics.h"
|
||||||
#include "level_zero/sysman/source/ecc/sysman_ecc.h"
|
#include "level_zero/sysman/source/ecc/sysman_ecc.h"
|
||||||
#include "level_zero/sysman/source/engine/sysman_engine.h"
|
#include "level_zero/sysman/source/engine/sysman_engine.h"
|
||||||
|
#include "level_zero/sysman/source/events/sysman_events.h"
|
||||||
#include "level_zero/sysman/source/fabric_port/sysman_fabric_port.h"
|
#include "level_zero/sysman/source/fabric_port/sysman_fabric_port.h"
|
||||||
#include "level_zero/sysman/source/fan/sysman_fan.h"
|
#include "level_zero/sysman/source/fan/sysman_fan.h"
|
||||||
#include "level_zero/sysman/source/firmware/sysman_firmware.h"
|
#include "level_zero/sysman/source/firmware/sysman_firmware.h"
|
||||||
@@ -114,6 +115,13 @@ struct SysmanDevice : _ze_device_handle_t {
|
|||||||
virtual ze_result_t pciGetStats(zes_pci_stats_t *pStats) = 0;
|
virtual ze_result_t pciGetStats(zes_pci_stats_t *pStats) = 0;
|
||||||
static ze_result_t fanGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fan_handle_t *phFan);
|
static ze_result_t fanGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fan_handle_t *phFan);
|
||||||
virtual ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) = 0;
|
virtual ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) = 0;
|
||||||
|
|
||||||
|
static ze_result_t deviceEventRegister(zes_device_handle_t hDevice, zes_event_type_flags_t events);
|
||||||
|
virtual ze_result_t deviceEventRegister(zes_event_type_flags_t events) = 0;
|
||||||
|
|
||||||
|
virtual bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) = 0;
|
||||||
|
|
||||||
|
virtual OsSysman *deviceGetOsInterface() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Sysman
|
} // namespace Sysman
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "shared/source/helpers/debug_helpers.h"
|
#include "shared/source/helpers/debug_helpers.h"
|
||||||
|
|
||||||
#include "level_zero/sysman/source/ecc/sysman_ecc_imp.h"
|
#include "level_zero/sysman/source/ecc/sysman_ecc_imp.h"
|
||||||
|
#include "level_zero/sysman/source/events/sysman_events_imp.h"
|
||||||
#include "level_zero/sysman/source/fan/sysman_fan_imp.h"
|
#include "level_zero/sysman/source/fan/sysman_fan_imp.h"
|
||||||
#include "level_zero/sysman/source/global_operations/sysman_global_operations_imp.h"
|
#include "level_zero/sysman/source/global_operations/sysman_global_operations_imp.h"
|
||||||
#include "level_zero/sysman/source/os_sysman.h"
|
#include "level_zero/sysman/source/os_sysman.h"
|
||||||
@@ -41,6 +42,7 @@ SysmanDeviceImp::SysmanDeviceImp(NEO::ExecutionEnvironment *executionEnvironment
|
|||||||
pTempHandleContext = new TemperatureHandleContext(pOsSysman);
|
pTempHandleContext = new TemperatureHandleContext(pOsSysman);
|
||||||
pPci = new PciImp(pOsSysman);
|
pPci = new PciImp(pOsSysman);
|
||||||
pFanHandleContext = new FanHandleContext(pOsSysman);
|
pFanHandleContext = new FanHandleContext(pOsSysman);
|
||||||
|
pEvents = new EventsImp(pOsSysman);
|
||||||
}
|
}
|
||||||
|
|
||||||
SysmanDeviceImp::~SysmanDeviceImp() {
|
SysmanDeviceImp::~SysmanDeviceImp() {
|
||||||
@@ -61,6 +63,7 @@ SysmanDeviceImp::~SysmanDeviceImp() {
|
|||||||
freeResource(pPci);
|
freeResource(pPci);
|
||||||
freeResource(pFanHandleContext);
|
freeResource(pFanHandleContext);
|
||||||
freeResource(pOsSysman);
|
freeResource(pOsSysman);
|
||||||
|
freeResource(pEvents);
|
||||||
executionEnvironment->decRefInternal();
|
executionEnvironment->decRefInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,5 +179,17 @@ ze_result_t SysmanDeviceImp::fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) {
|
|||||||
return pFanHandleContext->fanGet(pCount, phFan);
|
return pFanHandleContext->fanGet(pCount, phFan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ze_result_t SysmanDeviceImp::deviceEventRegister(zes_event_type_flags_t events) {
|
||||||
|
return pEvents->eventRegister(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SysmanDeviceImp::deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) {
|
||||||
|
return pEvents->eventListen(pEvent, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
OsSysman *SysmanDeviceImp::deviceGetOsInterface() {
|
||||||
|
return pOsSysman;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sysman
|
} // namespace Sysman
|
||||||
} // namespace L0
|
} // namespace L0
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
|
|||||||
TemperatureHandleContext *pTempHandleContext = nullptr;
|
TemperatureHandleContext *pTempHandleContext = nullptr;
|
||||||
Pci *pPci = nullptr;
|
Pci *pPci = nullptr;
|
||||||
FanHandleContext *pFanHandleContext = nullptr;
|
FanHandleContext *pFanHandleContext = nullptr;
|
||||||
|
Events *pEvents = nullptr;
|
||||||
|
|
||||||
ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) override;
|
ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) override;
|
||||||
ze_result_t powerGetCardDomain(zes_pwr_handle_t *phPower) override;
|
ze_result_t powerGetCardDomain(zes_pwr_handle_t *phPower) override;
|
||||||
@@ -80,6 +81,10 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
|
|||||||
ze_result_t pciGetBars(uint32_t *pCount, zes_pci_bar_properties_t *pProperties) override;
|
ze_result_t pciGetBars(uint32_t *pCount, zes_pci_bar_properties_t *pProperties) override;
|
||||||
ze_result_t pciGetStats(zes_pci_stats_t *pStats) override;
|
ze_result_t pciGetStats(zes_pci_stats_t *pStats) override;
|
||||||
ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) override;
|
ze_result_t fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) override;
|
||||||
|
ze_result_t deviceEventRegister(zes_event_type_flags_t events) override;
|
||||||
|
bool deviceEventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
|
||||||
|
|
||||||
|
OsSysman *deviceGetOsInterface() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
|
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ struct SysmanDriverHandle : BaseDriver {
|
|||||||
|
|
||||||
static SysmanDriverHandle *create(NEO::ExecutionEnvironment &executionEnvironment, ze_result_t *returnValue);
|
static SysmanDriverHandle *create(NEO::ExecutionEnvironment &executionEnvironment, ze_result_t *returnValue);
|
||||||
virtual ze_result_t getDevice(uint32_t *pCount, zes_device_handle_t *phDevices) = 0;
|
virtual ze_result_t getDevice(uint32_t *pCount, zes_device_handle_t *phDevices) = 0;
|
||||||
|
virtual ze_result_t sysmanEventsListen(uint32_t timeout, uint32_t count, zes_device_handle_t *phDevices,
|
||||||
|
uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0;
|
||||||
|
virtual ze_result_t sysmanEventsListenEx(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices,
|
||||||
|
uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Sysman
|
} // namespace Sysman
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "shared/source/os_interface/os_interface.h"
|
#include "shared/source/os_interface/os_interface.h"
|
||||||
|
|
||||||
#include "level_zero/core/source/get_extension_function_lookup_map.h"
|
#include "level_zero/core/source/get_extension_function_lookup_map.h"
|
||||||
|
#include "level_zero/sysman/source/os_sysman_driver.h"
|
||||||
#include "level_zero/sysman/source/sysman_device.h"
|
#include "level_zero/sysman/source/sysman_device.h"
|
||||||
#include "level_zero/sysman/source/sysman_driver.h"
|
#include "level_zero/sysman/source/sysman_driver.h"
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ ze_result_t SysmanDriverHandleImp::initialize(NEO::ExecutionEnvironment &executi
|
|||||||
if (this->sysmanDevices.size() == 0) {
|
if (this->sysmanDevices.size() == 0) {
|
||||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pOsSysmanDriver = L0::Sysman::OsSysmanDriver::create();
|
||||||
this->numDevices = static_cast<uint32_t>(this->sysmanDevices.size());
|
this->numDevices = static_cast<uint32_t>(this->sysmanDevices.size());
|
||||||
return ZE_RESULT_SUCCESS;
|
return ZE_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -93,11 +96,34 @@ ze_result_t SysmanDriverHandleImp::getDevice(uint32_t *pCount, zes_device_handle
|
|||||||
return ZE_RESULT_SUCCESS;
|
return ZE_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ze_result_t SysmanDriverHandleImp::sysmanEventsListen(uint32_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) {
|
||||||
|
if (pOsSysmanDriver == nullptr) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Os Sysman Driver Not initialized\n");
|
||||||
|
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||||
|
}
|
||||||
|
return pOsSysmanDriver->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t SysmanDriverHandleImp::sysmanEventsListenEx(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) {
|
||||||
|
if (pOsSysmanDriver == nullptr) {
|
||||||
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
||||||
|
"%s", "Os Sysman Driver Not initialized\n");
|
||||||
|
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||||
|
}
|
||||||
|
return pOsSysmanDriver->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
|
||||||
|
};
|
||||||
|
|
||||||
SysmanDriverHandleImp::~SysmanDriverHandleImp() {
|
SysmanDriverHandleImp::~SysmanDriverHandleImp() {
|
||||||
for (auto &device : this->sysmanDevices) {
|
for (auto &device : this->sysmanDevices) {
|
||||||
delete device;
|
delete device;
|
||||||
}
|
}
|
||||||
this->sysmanDevices.clear();
|
this->sysmanDevices.clear();
|
||||||
|
|
||||||
|
if (pOsSysmanDriver != nullptr) {
|
||||||
|
delete pOsSysmanDriver;
|
||||||
|
pOsSysmanDriver = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Sysman
|
} // namespace Sysman
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ struct SysmanDriverHandleImp : SysmanDriverHandle {
|
|||||||
SysmanDriverHandleImp();
|
SysmanDriverHandleImp();
|
||||||
ze_result_t initialize(NEO::ExecutionEnvironment &executionEnvironment);
|
ze_result_t initialize(NEO::ExecutionEnvironment &executionEnvironment);
|
||||||
ze_result_t getDevice(uint32_t *pCount, zes_device_handle_t *phDevices) override;
|
ze_result_t getDevice(uint32_t *pCount, zes_device_handle_t *phDevices) override;
|
||||||
|
ze_result_t sysmanEventsListen(uint32_t timeout, uint32_t count, zes_device_handle_t *phDevices,
|
||||||
|
uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) override;
|
||||||
|
ze_result_t sysmanEventsListenEx(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices,
|
||||||
|
uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) override;
|
||||||
std::vector<SysmanDevice *> sysmanDevices;
|
std::vector<SysmanDevice *> sysmanDevices;
|
||||||
uint32_t numDevices = 0;
|
uint32_t numDevices = 0;
|
||||||
|
|
||||||
ze_result_t getExtensionFunctionAddress(const char *pFuncName, void **pfunc) override;
|
ze_result_t getExtensionFunctionAddress(const char *pFuncName, void **pfunc) override;
|
||||||
std::unordered_map<std::string, void *> extensionFunctionsLookupMap;
|
std::unordered_map<std::string, void *> extensionFunctionsLookupMap;
|
||||||
|
struct OsSysmanDriver *pOsSysmanDriver = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct SysmanDriverHandleImp *GlobalSysmanDriver;
|
extern struct SysmanDriverHandleImp *GlobalSysmanDriver;
|
||||||
|
|||||||
@@ -14,5 +14,7 @@ if(WIN32)
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/zes_os_sysman_imp.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/zes_os_sysman_imp.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_kmd_sys_manager.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_kmd_sys_manager.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id_windows.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/sysman_hw_device_id_windows.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/zes_os_sysman_driver_imp.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/zes_os_sysman_driver_imp.h
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/windows/zes_os_sysman_driver_imp.h"
|
||||||
|
|
||||||
|
#include "shared/source/helpers/sleep.h"
|
||||||
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/os_sysman.h"
|
||||||
|
#include "level_zero/sysman/source/sysman_const.h"
|
||||||
|
#include "level_zero/sysman/source/sysman_device.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
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::Sysman::SteadyClock::now() + std::chrono::duration<uint64_t, std::milli>(timeout);
|
||||||
|
do {
|
||||||
|
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
||||||
|
gotSysmanEvent = L0::Sysman::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::Sysman::SteadyClock::now() <= timeToExitLoop));
|
||||||
|
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
OsSysmanDriver *OsSysmanDriver::create() {
|
||||||
|
WddmSysmanDriverImp *pWddmSysmanDriverImp = new WddmSysmanDriverImp();
|
||||||
|
return static_cast<OsSysmanDriver *>(pWddmSysmanDriverImp);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Sysman
|
||||||
|
} // namespace L0
|
||||||
24
level_zero/sysman/source/windows/zes_os_sysman_driver_imp.h
Normal file
24
level_zero/sysman/source/windows/zes_os_sysman_driver_imp.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/os_sysman_driver.h"
|
||||||
|
|
||||||
|
namespace L0 {
|
||||||
|
namespace Sysman {
|
||||||
|
|
||||||
|
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 Sysman
|
||||||
|
} // namespace L0
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2023 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
target_sources(${TARGET_NAME} PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||||
|
)
|
||||||
|
add_subdirectories()
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2023 Intel Corporation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
#
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
target_sources(${TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
${L0_TESTS_SYSMAN_EVENTS_LINUX}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,307 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||||
|
#include "shared/source/os_interface/linux/ioctl_helper.h"
|
||||||
|
#include "shared/source/os_interface/linux/system_info.h"
|
||||||
|
#include "shared/source/os_interface/os_interface.h"
|
||||||
|
#include "shared/test/common/test_macros/mock_method_macros.h"
|
||||||
|
|
||||||
|
#include "level_zero/sysman/source/events/linux/sysman_os_events_imp.h"
|
||||||
|
#include "level_zero/sysman/source/events/sysman_events_imp.h"
|
||||||
|
#include "level_zero/sysman/source/firmware_util/sysman_firmware_util.h"
|
||||||
|
#include "level_zero/sysman/source/linux/pmu/sysman_pmu_imp.h"
|
||||||
|
#include "level_zero/sysman/source/linux/zes_os_sysman_driver_imp.h"
|
||||||
|
#include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_hw_device_id.h"
|
||||||
|
|
||||||
|
#include "drm/intel_hwconfig_types.h"
|
||||||
|
|
||||||
|
using namespace NEO;
|
||||||
|
namespace L0 {
|
||||||
|
namespace ult {
|
||||||
|
|
||||||
|
const std::string ueventWedgedFile("/var/lib/libze_intel_gpu/wedged_file");
|
||||||
|
const std::string ueventDetachFile("/var/lib/libze_intel_gpu/remove-pci-0000_03_00_0");
|
||||||
|
const std::string ueventAttachFile("/var/lib/libze_intel_gpu/add-pci-0000_03_00_0");
|
||||||
|
const std::string ueventFabricFile("/var/lib/libze_intel_gpu/fabric-pci-0000_03_00_0");
|
||||||
|
const std::string deviceDir("device");
|
||||||
|
const std::string deviceMemoryHealth("device_memory_health");
|
||||||
|
const std::string eventsDir("/sys/devices/i915_0000_03_00.0/events");
|
||||||
|
constexpr int64_t mockPmuFd = 10;
|
||||||
|
constexpr uint64_t errorCount = 10u;
|
||||||
|
constexpr uint64_t mockTimeStamp = 1100u;
|
||||||
|
constexpr int mockUdevFd = 1;
|
||||||
|
|
||||||
|
struct MockPmuInterfaceImpForEvents : public L0::Sysman::PmuInterfaceImp {
|
||||||
|
using PmuInterfaceImp::perfEventOpen;
|
||||||
|
MockPmuInterfaceImpForEvents(L0::Sysman::LinuxSysmanImp *pLinuxSysmanImp) : PmuInterfaceImp(pLinuxSysmanImp) {}
|
||||||
|
|
||||||
|
bool mockPmuReadFail = false;
|
||||||
|
|
||||||
|
int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags) override {
|
||||||
|
return mockPmuFd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) override {
|
||||||
|
|
||||||
|
if (mockPmuReadFail == true) {
|
||||||
|
return mockedPmuReadAndFailureReturn(fd, data, sizeOfdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
data[0] = 0;
|
||||||
|
data[1] = mockTimeStamp;
|
||||||
|
data[2] = errorCount;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int mockedPmuReadAndFailureReturn(int fd, uint64_t *data, ssize_t sizeOfdata) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MockEventsFsAccess : public L0::Sysman::FsAccess {
|
||||||
|
|
||||||
|
bool mockReadValSuccess = false;
|
||||||
|
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) {
|
||||||
|
val = 1;
|
||||||
|
} else if (file.compare(ueventDetachFile) == 0) {
|
||||||
|
val = 1;
|
||||||
|
} else if (file.compare(ueventAttachFile) == 0) {
|
||||||
|
val = 1;
|
||||||
|
} else if (file.compare(ueventFabricFile) == 0) {
|
||||||
|
val = 1;
|
||||||
|
} else {
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t getValReturnValAsZero(const std::string file, uint32_t &val) {
|
||||||
|
if (file.compare(ueventWedgedFile) == 0) {
|
||||||
|
val = 0;
|
||||||
|
} else if (file.compare(ueventDetachFile) == 0) {
|
||||||
|
val = 0;
|
||||||
|
} else if (file.compare(ueventAttachFile) == 0) {
|
||||||
|
val = 0;
|
||||||
|
} else if (file.compare(ueventFabricFile) == 0) {
|
||||||
|
val = 0;
|
||||||
|
} else {
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t read(const std::string file, std::string &config) override {
|
||||||
|
if (file.compare(eventsDir + "/" + "error--correctable-eu-grf") == 0) {
|
||||||
|
config = "config=0x0000000000000001";
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
} else if (file.compare(eventsDir + "/" + "error--engine-reset") == 0) {
|
||||||
|
config = "config=0x000000000000010";
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t getValFileNotFound(const std::string file, uint32_t &val) {
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t getValFileInsufficientPermissions(const std::string file, uint32_t &val) {
|
||||||
|
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t readValSuccess(const std::string file, uint32_t &val) {
|
||||||
|
val = 23;
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t read(const std::string file, uint32_t &val) override {
|
||||||
|
|
||||||
|
if (mockReadValOne == true) {
|
||||||
|
return getValReturnValAsOne(file, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (mockReadValZero == true) {
|
||||||
|
return getValReturnValAsZero(file, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (mockFileNotFoundError == true) {
|
||||||
|
return getValFileNotFound(file, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (mockReadValSuccess == true) {
|
||||||
|
val = 23;
|
||||||
|
return readValSuccess(file, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isRootUser() override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool userIsNotRoot() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MockEventsFsAccess() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MockEventsSysfsAccess : public L0::Sysman::SysfsAccess {
|
||||||
|
ze_result_t getRealPathResult = ZE_RESULT_SUCCESS;
|
||||||
|
std::string realPath = "/sys/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0";
|
||||||
|
|
||||||
|
ze_result_t getRealPath(const std::string file, std::string &val) override {
|
||||||
|
val = realPath;
|
||||||
|
return getRealPathResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t readSymLink(const std::string file, std::string &val) override {
|
||||||
|
|
||||||
|
if (file.compare(deviceDir) == 0) {
|
||||||
|
val = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/0000:03:00.0";
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ze_result_t read(const std::string file, uint64_t &val) override {
|
||||||
|
if (file.compare("gt/gt0/error_counter/correctable_eu_grf") == 0) {
|
||||||
|
val = 5u;
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
} else if (file.compare("gt/gt0/error_counter/engine_reset") == 0) {
|
||||||
|
val = 8u;
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
MockEventsSysfsAccess() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventsUdevLibMock : public L0::Sysman::UdevLib {
|
||||||
|
public:
|
||||||
|
EventsUdevLibMock() = default;
|
||||||
|
std::string eventPropertyValueTypeResult = "PORT_CHANGE";
|
||||||
|
std::string eventPropertyValueDevPathResult = "/devices/pci0000:97/0000:97:02.0/0000:98:00.0/0000:99:01.0/0000:9a:00.0/i915.iaf.0";
|
||||||
|
std::string getEventPropertyValueResult = "1";
|
||||||
|
|
||||||
|
const char *getEventPropertyValue(void *dev, const char *key) override {
|
||||||
|
if (strcmp(key, "TYPE") == 0) {
|
||||||
|
if (!eventPropertyValueTypeResult.empty()) {
|
||||||
|
return eventPropertyValueTypeResult.c_str();
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} else if (strcmp(key, "DEVPATH") == 0) {
|
||||||
|
if (eventPropertyValueDevPathResult.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return eventPropertyValueDevPathResult.c_str();
|
||||||
|
} else if (getEventPropertyValueResult.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return getEventPropertyValueResult.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
ADDMETHOD_NOBASE(registerEventsFromSubsystemAndGetFd, int, mockUdevFd, (std::vector<std::string> & subsystemList));
|
||||||
|
ADDMETHOD_NOBASE(getEventGenerationSourceDevice, dev_t, 0, (void *dev));
|
||||||
|
ADDMETHOD_NOBASE(getEventType, const char *, "change", (void *dev));
|
||||||
|
ADDMETHOD_NOBASE(allocateDeviceToReceiveData, void *, (void *)(0x12345678), ());
|
||||||
|
ADDMETHOD_NOBASE_VOIDRETURN(dropDeviceReference, (void *dev));
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MockEventsFwInterface : public L0::Sysman::FirmwareUtil {
|
||||||
|
bool mockIfrStatus = false;
|
||||||
|
ze_result_t fwIfrApplied(bool &ifrStatus) override {
|
||||||
|
ifrStatus = mockIfrStatus;
|
||||||
|
return ZE_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
MockEventsFwInterface() = default;
|
||||||
|
|
||||||
|
ADDMETHOD_NOBASE(fwDeviceInit, ze_result_t, ZE_RESULT_SUCCESS, (void));
|
||||||
|
ADDMETHOD_NOBASE(getFirstDevice, ze_result_t, ZE_RESULT_SUCCESS, (igsc_device_info * info));
|
||||||
|
ADDMETHOD_NOBASE(getFwVersion, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, std::string &firmwareVersion));
|
||||||
|
ADDMETHOD_NOBASE(flashFirmware, ze_result_t, ZE_RESULT_SUCCESS, (std::string fwType, void *pImage, uint32_t size));
|
||||||
|
ADDMETHOD_NOBASE(fwSupportedDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::vector<std::string> & supportedDiagTests));
|
||||||
|
ADDMETHOD_NOBASE(fwRunDiagTests, ze_result_t, ZE_RESULT_SUCCESS, (std::string & osDiagType, zes_diag_result_t *pResult));
|
||||||
|
ADDMETHOD_NOBASE(fwGetMemoryErrorCount, ze_result_t, ZE_RESULT_SUCCESS, (zes_ras_error_type_t category, uint32_t subDeviceCount, uint32_t subDeviceId, uint64_t &count));
|
||||||
|
ADDMETHOD_NOBASE(fwGetEccConfig, ze_result_t, ZE_RESULT_SUCCESS, (uint8_t * currentState, uint8_t *pendingState));
|
||||||
|
ADDMETHOD_NOBASE(fwSetEccConfig, ze_result_t, ZE_RESULT_SUCCESS, (uint8_t newState, uint8_t *currentState, uint8_t *pendingState));
|
||||||
|
ADDMETHOD_NOBASE_VOIDRETURN(getDeviceSupportedFwTypes, (std::vector<std::string> & fwTypes));
|
||||||
|
ADDMETHOD_NOBASE_VOIDRETURN(fwGetMemoryHealthIndicator, (zes_mem_health_t * health));
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MockEventNeoDrm : public Drm {
|
||||||
|
using Drm::setupIoctlHelper;
|
||||||
|
uint32_t mockMemoryType = INTEL_HWCONFIG_MEMORY_TYPE_HBM2e;
|
||||||
|
const int mockFd = 33;
|
||||||
|
std::vector<bool> mockQuerySystemInfoReturnValue{};
|
||||||
|
bool isRepeated = false;
|
||||||
|
bool mockReturnEmptyRegions = false;
|
||||||
|
MockEventNeoDrm(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<MockSysmanHwDeviceIdDrm>(mockFd, ""), rootDeviceEnvironment) {}
|
||||||
|
|
||||||
|
void setMemoryType(uint32_t memory) {
|
||||||
|
mockMemoryType = memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> getMemoryRegionsReturnsEmpty() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool querySystemInfo() override {
|
||||||
|
bool returnValue = true;
|
||||||
|
if (!mockQuerySystemInfoReturnValue.empty()) {
|
||||||
|
returnValue = mockQuerySystemInfoReturnValue.front();
|
||||||
|
if (isRepeated != true) {
|
||||||
|
mockQuerySystemInfoReturnValue.erase(mockQuerySystemInfoReturnValue.begin());
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t hwBlob[] = {INTEL_HWCONFIG_MAX_MEMORY_CHANNELS, 1, 8, INTEL_HWCONFIG_MEMORY_TYPE, 0, mockMemoryType};
|
||||||
|
std::vector<uint8_t> inputBlobData(reinterpret_cast<uint8_t *>(hwBlob), reinterpret_cast<uint8_t *>(hwBlob) + sizeof(hwBlob));
|
||||||
|
this->systemInfo.reset(new SystemInfo(inputBlobData));
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PublicLinuxEventsImp : public L0::Sysman::LinuxEventsImp {
|
||||||
|
public:
|
||||||
|
PublicLinuxEventsImp(OsSysman *pOsSysman) : LinuxEventsImp(pOsSysman) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PublicLinuxEventsUtil : public L0::Sysman::LinuxEventsUtil {
|
||||||
|
public:
|
||||||
|
PublicLinuxEventsUtil(L0::Sysman::LinuxSysmanDriverImp *pLinuxSysmanDriverImp) : LinuxEventsUtil(pLinuxSysmanDriverImp) {}
|
||||||
|
using LinuxEventsUtil::deviceEventsMap;
|
||||||
|
using LinuxEventsUtil::listenSystemEvents;
|
||||||
|
using LinuxEventsUtil::pipeFd;
|
||||||
|
using LinuxEventsUtil::pUdevLib;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ult
|
||||||
|
} // namespace L0
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||||
#include "level_zero/sysman/source/linux/sysman_fs_access.h"
|
#include "level_zero/sysman/source/linux/sysman_fs_access.h"
|
||||||
|
#include "level_zero/sysman/source/linux/zes_os_sysman_driver_imp.h"
|
||||||
#include "level_zero/sysman/source/linux/zes_os_sysman_imp.h"
|
#include "level_zero/sysman/source/linux/zes_os_sysman_imp.h"
|
||||||
#include "level_zero/sysman/source/sysman_device.h"
|
#include "level_zero/sysman/source/sysman_device.h"
|
||||||
#include "level_zero/sysman/source/sysman_driver_handle_imp.h"
|
#include "level_zero/sysman/source/sysman_driver_handle_imp.h"
|
||||||
@@ -66,6 +67,7 @@ class SysmanDeviceFixture : public ::testing::Test {
|
|||||||
driverHandle = std::make_unique<L0::Sysman::SysmanDriverHandleImp>();
|
driverHandle = std::make_unique<L0::Sysman::SysmanDriverHandleImp>();
|
||||||
driverHandle->initialize(*execEnv);
|
driverHandle->initialize(*execEnv);
|
||||||
pSysmanDevice = driverHandle->sysmanDevices[0];
|
pSysmanDevice = driverHandle->sysmanDevices[0];
|
||||||
|
L0::Sysman::GlobalSysmanDriver = driverHandle.get();
|
||||||
|
|
||||||
pSysmanDeviceImp = static_cast<L0::Sysman::SysmanDeviceImp *>(pSysmanDevice);
|
pSysmanDeviceImp = static_cast<L0::Sysman::SysmanDeviceImp *>(pSysmanDevice);
|
||||||
pOsSysman = pSysmanDeviceImp->pOsSysman;
|
pOsSysman = pSysmanDeviceImp->pOsSysman;
|
||||||
@@ -73,6 +75,7 @@ class SysmanDeviceFixture : public ::testing::Test {
|
|||||||
pLinuxSysmanImp->pFwUtilInterface = new MockFwUtilInterface();
|
pLinuxSysmanImp->pFwUtilInterface = new MockFwUtilInterface();
|
||||||
}
|
}
|
||||||
void TearDown() override {
|
void TearDown() override {
|
||||||
|
L0::Sysman::GlobalSysmanDriver = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
L0::Sysman::SysmanDevice *pSysmanDevice = nullptr;
|
L0::Sysman::SysmanDevice *pSysmanDevice = nullptr;
|
||||||
@@ -144,5 +147,12 @@ class PublicSysfsAccess : public L0::Sysman::SysfsAccess {
|
|||||||
using SysfsAccess::accessSyscall;
|
using SysfsAccess::accessSyscall;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PublicLinuxSysmanDriverImp : public L0::Sysman::LinuxSysmanDriverImp {
|
||||||
|
public:
|
||||||
|
PublicLinuxSysmanDriverImp() : LinuxSysmanDriverImp() {}
|
||||||
|
using LinuxSysmanDriverImp::pLinuxEventsUtil;
|
||||||
|
using LinuxSysmanDriverImp::pUdevLib;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ult
|
} // namespace ult
|
||||||
} // namespace L0
|
} // namespace L0
|
||||||
|
|||||||
@@ -228,10 +228,6 @@ LinuxSysmanImp::~LinuxSysmanImp() {
|
|||||||
delete pPmuInterface;
|
delete pPmuInterface;
|
||||||
pPmuInterface = nullptr;
|
pPmuInterface = nullptr;
|
||||||
}
|
}
|
||||||
if (nullptr != pUdevLib) {
|
|
||||||
delete pUdevLib;
|
|
||||||
pUdevLib = nullptr;
|
|
||||||
}
|
|
||||||
releaseFwUtilInterface();
|
releaseFwUtilInterface();
|
||||||
releasePmtObject();
|
releasePmtObject();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
|||||||
NEO::Drm *pDrm = nullptr;
|
NEO::Drm *pDrm = nullptr;
|
||||||
PmuInterface *pPmuInterface = nullptr;
|
PmuInterface *pPmuInterface = nullptr;
|
||||||
FirmwareUtil *pFwUtilInterface = nullptr;
|
FirmwareUtil *pFwUtilInterface = nullptr;
|
||||||
L0::UdevLib *pUdevLib = nullptr;
|
|
||||||
std::map<uint32_t, L0::PlatformMonitoringTech *> mapOfSubDeviceIdToPmtObject;
|
std::map<uint32_t, L0::PlatformMonitoringTech *> mapOfSubDeviceIdToPmtObject;
|
||||||
ze_result_t initLocalDeviceAndDrmHandles();
|
ze_result_t initLocalDeviceAndDrmHandles();
|
||||||
uint32_t memType = unknownMemoryType;
|
uint32_t memType = unknownMemoryType;
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ class SysmanEventsFixture : public SysmanDeviceFixture {
|
|||||||
|
|
||||||
pEventsImp = static_cast<L0::EventsImp *>(pSysmanDeviceImp->pEvents);
|
pEventsImp = static_cast<L0::EventsImp *>(pSysmanDeviceImp->pEvents);
|
||||||
|
|
||||||
// Assign pUdevLib library handle to LinuxEventImp object, so that udev library handle methods could be mocked
|
|
||||||
pLinuxSysmanImp->pUdevLib = new EventsUdevLibMock();
|
|
||||||
pLinuxEventsImp = new PublicLinuxEventsImp(pOsSysman);
|
pLinuxEventsImp = new PublicLinuxEventsImp(pOsSysman);
|
||||||
pEventsImp->pOsEvents = pLinuxEventsImp;
|
pEventsImp->pOsEvents = pLinuxEventsImp;
|
||||||
pPmuInterface = std::make_unique<MockPmuInterfaceImpForEvents>(pLinuxSysmanImp);
|
pPmuInterface = std::make_unique<MockPmuInterfaceImpForEvents>(pLinuxSysmanImp);
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class PublicLinuxSysmanImp : public L0::LinuxSysmanImp {
|
|||||||
using LinuxSysmanImp::pPmuInterface;
|
using LinuxSysmanImp::pPmuInterface;
|
||||||
using LinuxSysmanImp::pProcfsAccess;
|
using LinuxSysmanImp::pProcfsAccess;
|
||||||
using LinuxSysmanImp::pSysfsAccess;
|
using LinuxSysmanImp::pSysfsAccess;
|
||||||
using LinuxSysmanImp::pUdevLib;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test {
|
class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test {
|
||||||
|
|||||||
Reference in New Issue
Block a user