2020-03-06 11:09:57 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2020-2021 Intel Corporation
|
2020-03-06 11:09:57 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "level_zero/tools/source/sysman/sysman.h"
|
|
|
|
|
|
2020-07-03 20:05:35 +05:30
|
|
|
#include "level_zero/core/source/device/device_imp.h"
|
2020-03-18 22:21:57 -07:00
|
|
|
#include "level_zero/core/source/driver/driver.h"
|
|
|
|
|
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
2020-03-06 11:09:57 +01:00
|
|
|
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace L0 {
|
|
|
|
|
|
2020-08-05 14:03:39 -07:00
|
|
|
SysmanDevice *SysmanDeviceHandleContext::init(ze_device_handle_t coreDevice) {
|
|
|
|
|
SysmanDeviceImp *sysmanDevice = new SysmanDeviceImp(coreDevice);
|
|
|
|
|
UNRECOVERABLE_IF(!sysmanDevice);
|
|
|
|
|
sysmanDevice->init();
|
2020-10-29 15:20:21 +05:30
|
|
|
L0::DeviceImp *device = static_cast<DeviceImp *>(Device::fromHandle(coreDevice));
|
|
|
|
|
for (auto &subDevice : device->subDevices) {
|
|
|
|
|
static_cast<DeviceImp *>(subDevice)->setSysmanHandle(sysmanDevice);
|
|
|
|
|
}
|
2020-08-05 14:03:39 -07:00
|
|
|
return sysmanDevice;
|
2020-07-03 20:05:35 +05:30
|
|
|
}
|
|
|
|
|
|
2020-08-05 14:03:39 -07:00
|
|
|
void DeviceImp::setSysmanHandle(SysmanDevice *pSysmanDev) {
|
|
|
|
|
pSysmanDevice = pSysmanDev;
|
2020-07-03 20:05:35 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SysmanDevice *DeviceImp::getSysmanHandle() {
|
|
|
|
|
return pSysmanDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-09 11:04:35 +05:30
|
|
|
ze_result_t DriverHandleImp::sysmanEventsListen(
|
|
|
|
|
uint32_t timeout,
|
|
|
|
|
uint32_t count,
|
|
|
|
|
zes_device_handle_t *phDevices,
|
|
|
|
|
uint32_t *pNumDeviceEvents,
|
|
|
|
|
zes_event_type_flags_t *pEvents) {
|
|
|
|
|
bool gotSysmanEvent = false;
|
2021-03-22 11:56:44 +05:30
|
|
|
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
2021-04-05 09:38:22 +05:30
|
|
|
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::milliseconds(timeout);
|
2020-10-09 11:04:35 +05:30
|
|
|
do {
|
|
|
|
|
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
2020-11-05 18:23:38 -08:00
|
|
|
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
|
2020-10-09 11:04:35 +05:30
|
|
|
if (gotSysmanEvent) {
|
|
|
|
|
*pNumDeviceEvents = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (gotSysmanEvent) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
|
2021-04-05 09:38:22 +05:30
|
|
|
} while ((L0::steadyClock::now() <= timeToExitLoop));
|
|
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t DriverHandleImp::sysmanEventsListenEx(
|
|
|
|
|
uint64_t timeout,
|
|
|
|
|
uint32_t count,
|
|
|
|
|
zes_device_handle_t *phDevices,
|
|
|
|
|
uint32_t *pNumDeviceEvents,
|
|
|
|
|
zes_event_type_flags_t *pEvents) {
|
|
|
|
|
bool gotSysmanEvent = false;
|
|
|
|
|
memset(pEvents, 0, count * sizeof(zes_event_type_flags_t));
|
|
|
|
|
auto timeToExitLoop = L0::steadyClock::now() + std::chrono::duration<uint64_t, std::milli>(timeout);
|
|
|
|
|
do {
|
|
|
|
|
for (uint32_t devIndex = 0; devIndex < count; devIndex++) {
|
|
|
|
|
gotSysmanEvent = L0::SysmanDevice::fromHandle(phDevices[devIndex])->deviceEventListen(pEvents[devIndex], timeout);
|
|
|
|
|
if (gotSysmanEvent) {
|
|
|
|
|
*pNumDeviceEvents = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (gotSysmanEvent) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10)); // Sleep for 10 milliseconds before next check of events
|
|
|
|
|
} while ((L0::steadyClock::now() <= timeToExitLoop));
|
2020-10-09 11:04:35 +05:30
|
|
|
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:09:57 +01:00
|
|
|
} // namespace L0
|