Skip to content

Commit 396a86c

Browse files
feature(sysman): Support events for multiple devices
Related-To: LOCI-3683 Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com> Source: 2282f26
1 parent cb9ca84 commit 396a86c

22 files changed

+835
-964
lines changed

level_zero/core/source/windows/driver_teardown.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "level_zero/core/source/driver/driver_handle_imp.h"
99
#include "level_zero/sysman/source/sysman_driver_handle_imp.h"
10+
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
11+
#include "level_zero/tools/source/sysman/sysman.h"
1012

1113
#include <windows.h>
1214

@@ -22,6 +24,10 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
2224
delete Sysman::GlobalSysmanDriver;
2325
Sysman::GlobalSysmanDriver = nullptr;
2426
}
27+
if (GlobalOsSysmanDriver != nullptr) {
28+
delete GlobalOsSysmanDriver;
29+
GlobalOsSysmanDriver = nullptr;
30+
}
2531
}
2632
return TRUE;
2733
}

level_zero/tools/source/sysman/events/linux/os_events_imp_prelim.cpp

Lines changed: 163 additions & 188 deletions
Large diffs are not rendered by default.
Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -16,33 +16,43 @@ class LinuxEventsImp : public OsEvents, NEO::NonCopyableOrMovableClass {
1616
public:
1717
bool eventListen(zes_event_type_flags_t &pEvent, uint64_t timeout) override;
1818
ze_result_t eventRegister(zes_event_type_flags_t events) override;
19-
LinuxEventsImp() = default;
19+
LinuxEventsImp() = delete;
2020
LinuxEventsImp(OsSysman *pOsSysman);
2121
~LinuxEventsImp() override = default;
2222

2323
protected:
2424
LinuxSysmanImp *pLinuxSysmanImp = nullptr;
25+
};
26+
27+
class LinuxEventsUtil {
28+
29+
public:
30+
LinuxEventsUtil() = default;
31+
~LinuxEventsUtil() = default;
32+
33+
ze_result_t eventsListen(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents);
34+
void eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice);
35+
36+
protected:
37+
UdevLib *pUdevLib = nullptr;
38+
bool checkRasEvent(zes_event_type_flags_t &pEvent, SysmanDeviceImp *pSysmanDeviceImp, zes_event_type_flags_t registeredEvents);
2539
bool isResetRequired(void *dev, zes_event_type_flags_t &pEvent);
2640
bool checkDeviceDetachEvent(zes_event_type_flags_t &pEvent);
2741
bool checkDeviceAttachEvent(zes_event_type_flags_t &pEvent);
2842
bool checkIfMemHealthChanged(void *dev, zes_event_type_flags_t &pEvent);
29-
bool checkIfFabricPortStatusChanged(void *dev, zes_event_type_flags_t &pEvent);
30-
bool checkRasEvent(zes_event_type_flags_t &pEvent);
31-
ze_result_t readFabricDeviceStats(const std::string &devicePciPath, struct stat &iafStat);
32-
bool listenSystemEvents(zes_event_type_flags_t &pEvent, uint64_t timeout);
33-
uint32_t fabricEventTrackAtRegister = 0;
34-
L0::UdevLib *pUdevLib = nullptr;
35-
zes_event_type_flags_t registeredEvents = 0;
43+
bool listenSystemEvents(zes_event_type_flags_t *pEvents, uint32_t count, std::vector<zes_event_type_flags_t> &registeredEvents, zes_device_handle_t *phDevices, uint64_t timeout);
3644

3745
private:
38-
FsAccess *pFsAccess = nullptr;
39-
SysfsAccess *pSysfsAccess = nullptr;
46+
std::map<SysmanDeviceImp *, zes_event_type_flags_t> deviceEventsMap;
4047
std::string action;
4148
static const std::string add;
4249
static const std::string remove;
4350
static const std::string change;
4451
static const std::string unbind;
4552
static const std::string bind;
53+
static bool checkRasEventOccured(Ras *rasHandle);
54+
std::once_flag initEventsOnce;
55+
void init();
4656
};
4757

4858
} // namespace L0

level_zero/tools/source/sysman/linux/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2020-2022 Intel Corporation
2+
# Copyright (C) 2020-2023 Intel Corporation
33
#
44
# SPDX-License-Identifier: MIT
55
#
@@ -8,6 +8,8 @@ set(L0_SRCS_TOOLS_SYSMAN_LINUX
88
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
99
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.h
1010
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver_imp.h
12+
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_driver_imp.cpp
1113
${CMAKE_CURRENT_SOURCE_DIR}/fs_access.cpp
1214
)
1315

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2020-2023 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "level_zero/tools/source/sysman/linux/os_sysman_driver_imp.h"
9+
10+
#include "shared/source/debug_settings/debug_settings_manager.h"
11+
12+
#include <sys/stat.h>
13+
14+
namespace L0 {
15+
16+
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) {
17+
return pLinuxEventsUtil->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
18+
}
19+
20+
void LinuxSysmanDriverImp::eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice) {
21+
pLinuxEventsUtil->eventRegister(events, pSysmanDevice);
22+
}
23+
24+
L0::UdevLib *LinuxSysmanDriverImp::getUdevLibHandle() {
25+
if (pUdevLib == nullptr) {
26+
pUdevLib = UdevLib::create();
27+
}
28+
return pUdevLib;
29+
}
30+
31+
LinuxSysmanDriverImp::LinuxSysmanDriverImp() {
32+
pLinuxEventsUtil = new LinuxEventsUtil();
33+
}
34+
35+
LinuxSysmanDriverImp::~LinuxSysmanDriverImp() {
36+
if (nullptr != pUdevLib) {
37+
delete pUdevLib;
38+
pUdevLib = nullptr;
39+
}
40+
41+
if (nullptr != pLinuxEventsUtil) {
42+
delete pLinuxEventsUtil;
43+
pLinuxEventsUtil = nullptr;
44+
}
45+
}
46+
47+
OsSysmanDriver *OsSysmanDriver::create() {
48+
LinuxSysmanDriverImp *pLinuxSysmanDriverImp = new LinuxSysmanDriverImp();
49+
DEBUG_BREAK_IF(nullptr == pLinuxSysmanDriverImp);
50+
return static_cast<OsSysmanDriver *>(pLinuxSysmanDriverImp);
51+
}
52+
53+
void __attribute__((destructor)) osSysmanDriverDestructor() {
54+
if (GlobalOsSysmanDriver != nullptr) {
55+
delete GlobalOsSysmanDriver;
56+
GlobalOsSysmanDriver = nullptr;
57+
}
58+
}
59+
60+
} // namespace L0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2020-2023 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "level_zero/tools/source/sysman/events/linux/os_events_imp_prelim.h"
11+
#include "level_zero/tools/source/sysman/linux/udev/udev_lib.h"
12+
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
13+
14+
namespace L0 {
15+
16+
class LinuxSysmanDriverImp : public OsSysmanDriver {
17+
public:
18+
LinuxSysmanDriverImp();
19+
~LinuxSysmanDriverImp() override;
20+
21+
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;
22+
void eventRegister(zes_event_type_flags_t events, SysmanDeviceImp *pSysmanDevice);
23+
L0::UdevLib *getUdevLibHandle();
24+
25+
protected:
26+
L0::UdevLib *pUdevLib = nullptr;
27+
L0::LinuxEventsUtil *pLinuxEventsUtil = nullptr;
28+
};
29+
30+
void __attribute__((destructor)) osSysmanDriverDestructor();
31+
32+
} // namespace L0

level_zero/tools/source/sysman/linux/os_sysman_imp.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ FirmwareUtil *LinuxSysmanImp::getFwUtilInterface() {
9090
return pFwUtilInterface;
9191
}
9292

93-
L0::UdevLib *LinuxSysmanImp::getUdevLibHandle() {
94-
if (pUdevLib == nullptr) {
95-
pUdevLib = UdevLib::create();
96-
}
97-
return pUdevLib;
98-
}
99-
10093
FsAccess &LinuxSysmanImp::getFsAccess() {
10194
UNRECOVERABLE_IF(nullptr == pFsAccess);
10295
return *pFsAccess;

level_zero/tools/source/sysman/linux/os_sysman_imp.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Intel Corporation
2+
* Copyright (C) 2020-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -46,7 +46,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
4646

4747
ze_result_t init() override;
4848

49-
L0::UdevLib *getUdevLibHandle();
5049
PmuInterface *getPmuInterface();
5150
FirmwareUtil *getFwUtilInterface();
5251
FsAccess &getFsAccess();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) 2023 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
#include "level_zero/zes_api.h"
10+
11+
namespace L0 {
12+
13+
struct OsSysmanDriver {
14+
virtual ~OsSysmanDriver(){};
15+
16+
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;
17+
static OsSysmanDriver *create();
18+
};
19+
20+
} // namespace L0

level_zero/tools/source/sysman/sysman.cpp

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
#include "level_zero/tools/source/sysman/sysman.h"
99

10+
#include "shared/source/debug_settings/debug_settings_manager.h"
1011
#include "shared/source/helpers/sleep.h"
1112

1213
#include "level_zero/core/source/device/device_imp.h"
1314
#include "level_zero/core/source/driver/driver.h"
1415
#include "level_zero/core/source/driver/driver_handle_imp.h"
16+
#include "level_zero/tools/source/sysman/os_sysman_driver.h"
1517
#include "level_zero/tools/source/sysman/sysman_imp.h"
1618

1719
#include <cstring>
@@ -20,6 +22,8 @@
2022
namespace L0 {
2123
bool sysmanInitFromCore = false;
2224

25+
struct OsSysmanDriver *GlobalOsSysmanDriver = nullptr;
26+
2327
void DeviceImp::createSysmanHandle(bool isSubDevice) {
2428
if (static_cast<DriverHandleImp *>(driverHandle)->enableSysman && !isSubDevice) {
2529
if (this->getSysmanHandle() == nullptr) {
@@ -42,6 +46,10 @@ SysmanDevice *SysmanDeviceHandleContext::init(ze_device_handle_t coreDevice) {
4246
for (auto &subDevice : device->subDevices) {
4347
static_cast<DeviceImp *>(subDevice)->setSysmanHandle(sysmanDevice);
4448
}
49+
50+
if (GlobalOsSysmanDriver == nullptr) {
51+
GlobalOsSysmanDriver = L0::OsSysmanDriver::create();
52+
}
4553
return sysmanDevice;
4654
}
4755

@@ -59,24 +67,14 @@ ze_result_t DriverHandleImp::sysmanEventsListen(
5967
zes_device_handle_t *phDevices,
6068
uint32_t *pNumDeviceEvents,
6169
zes_event_type_flags_t *pEvents) {
62-
bool gotSysmanEvent = false;
63-
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
64-
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::milliseconds(timeout);
65-
do {
66-
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
67-
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
68-
if (gotSysmanEvent) {
69-
*pNumDeviceEvents = 1;
70-
break;
71-
}
72-
}
73-
if (gotSysmanEvent) {
74-
break;
75-
}
76-
NEO::sleep(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
77-
} while ((L0::steadyClock::now() <= timeToExitLoop));
7870

79-
return ZE_RESULT_SUCCESS;
71+
if (GlobalOsSysmanDriver == nullptr) {
72+
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
73+
"%s", "Os Sysman Driver Not initialized\n");
74+
return ZE_RESULT_ERROR_UNINITIALIZED;
75+
}
76+
77+
return GlobalOsSysmanDriver->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
8078
}
8179

8280
ze_result_t DriverHandleImp::sysmanEventsListenEx(
@@ -85,24 +83,13 @@ ze_result_t DriverHandleImp::sysmanEventsListenEx(
8583
zes_device_handle_t *phDevices,
8684
uint32_t *pNumDeviceEvents,
8785
zes_event_type_flags_t *pEvents) {
88-
bool gotSysmanEvent = false;
89-
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
90-
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::duration<uint64_t, std::milli>(timeout);
91-
do {
92-
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
93-
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
94-
if (gotSysmanEvent) {
95-
*pNumDeviceEvents = 1;
96-
break;
97-
}
98-
}
99-
if (gotSysmanEvent) {
100-
break;
101-
}
102-
NEO::sleep(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
103-
} while ((L0::steadyClock::now() <= timeToExitLoop));
10486

105-
return ZE_RESULT_SUCCESS;
87+
if (GlobalOsSysmanDriver == nullptr) {
88+
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
89+
"%s", "Os Sysman Driver Not initialized\n");
90+
return ZE_RESULT_ERROR_UNINITIALIZED;
91+
}
92+
return GlobalOsSysmanDriver->eventsListen(timeout, count, phDevices, pNumDeviceEvents, pEvents);
10693
}
10794

10895
ze_result_t SysmanDevice::performanceGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_perf_handle_t *phPerformance) {

0 commit comments

Comments
 (0)