Do not initialize Sysman if OsSysman Init failed

Related-To: LOCI-2552

Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2021-09-15 17:20:49 +05:30
committed by Compute-Runtime-Automation
parent aba7d74bcd
commit c46f591a99
12 changed files with 436 additions and 65 deletions

View File

@@ -11,14 +11,14 @@ ZE_APIEXPORT ze_result_t ZE_APICALL
zesDeviceGetProperties(
zes_device_handle_t hDevice,
zes_device_properties_t *pProperties) {
return L0::SysmanDevice::fromHandle(hDevice)->deviceGetProperties(pProperties);
return L0::SysmanDevice::deviceGetProperties(hDevice, pProperties);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zesDeviceGetState(
zes_device_handle_t hDevice,
zes_device_state_t *pState) {
return L0::SysmanDevice::fromHandle(hDevice)->deviceGetState(pState);
return L0::SysmanDevice::deviceGetState(hDevice, pState);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -26,7 +26,7 @@ zesDeviceEnumSchedulers(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_sched_handle_t *phScheduler) {
return L0::SysmanDevice::fromHandle(hDevice)->schedulerGet(pCount, phScheduler);
return L0::SysmanDevice::schedulerGet(hDevice, pCount, phScheduler);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -94,28 +94,28 @@ zesDeviceProcessesGetState(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_process_state_t *pProcesses) {
return L0::SysmanDevice::fromHandle(hDevice)->processesGetState(pCount, pProcesses);
return L0::SysmanDevice::processesGetState(hDevice, pCount, pProcesses);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zesDeviceReset(
zes_device_handle_t hDevice,
ze_bool_t force) {
return L0::SysmanDevice::fromHandle(hDevice)->deviceReset(force);
return L0::SysmanDevice::deviceReset(hDevice, force);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zesDevicePciGetProperties(
zes_device_handle_t hDevice,
zes_pci_properties_t *pProperties) {
return L0::SysmanDevice::fromHandle(hDevice)->pciGetProperties(pProperties);
return L0::SysmanDevice::pciGetProperties(hDevice, pProperties);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zesDevicePciGetState(
zes_device_handle_t hDevice,
zes_pci_state_t *pState) {
return L0::SysmanDevice::fromHandle(hDevice)->pciGetState(pState);
return L0::SysmanDevice::pciGetState(hDevice, pState);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -123,14 +123,14 @@ zesDevicePciGetBars(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_pci_bar_properties_t *pProperties) {
return L0::SysmanDevice::fromHandle(hDevice)->pciGetBars(pCount, pProperties);
return L0::SysmanDevice::pciGetBars(hDevice, pCount, pProperties);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
zesDevicePciGetStats(
zes_device_handle_t hDevice,
zes_pci_stats_t *pStats) {
return L0::SysmanDevice::fromHandle(hDevice)->pciGetStats(pStats);
return L0::SysmanDevice::pciGetStats(hDevice, pStats);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -138,7 +138,7 @@ zesDeviceEnumPowerDomains(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_pwr_handle_t *phPower) {
return L0::SysmanDevice::fromHandle(hDevice)->powerGet(pCount, phPower);
return L0::SysmanDevice::powerGet(hDevice, pCount, phPower);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -192,7 +192,7 @@ zesDeviceEnumFrequencyDomains(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_freq_handle_t *phFrequency) {
return L0::SysmanDevice::fromHandle(hDevice)->frequencyGet(pCount, phFrequency);
return L0::SysmanDevice::frequencyGet(hDevice, pCount, phFrequency);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -322,7 +322,7 @@ zesDeviceEnumEngineGroups(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_engine_handle_t *phEngine) {
return L0::SysmanDevice::fromHandle(hDevice)->engineGet(pCount, phEngine);
return L0::SysmanDevice::engineGet(hDevice, pCount, phEngine);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -344,7 +344,7 @@ zesDeviceEnumStandbyDomains(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_standby_handle_t *phStandby) {
return L0::SysmanDevice::fromHandle(hDevice)->standbyGet(pCount, phStandby);
return L0::SysmanDevice::standbyGet(hDevice, pCount, phStandby);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -373,7 +373,7 @@ zesDeviceEnumFirmwares(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_firmware_handle_t *phFirmware) {
return L0::SysmanDevice::fromHandle(hDevice)->firmwareGet(pCount, phFirmware);
return L0::SysmanDevice::firmwareGet(hDevice, pCount, phFirmware);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -396,7 +396,7 @@ zesDeviceEnumMemoryModules(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_mem_handle_t *phMemory) {
return L0::SysmanDevice::fromHandle(hDevice)->memoryGet(pCount, phMemory);
return L0::SysmanDevice::memoryGet(hDevice, pCount, phMemory);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -425,7 +425,7 @@ zesDeviceEnumFabricPorts(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_fabric_port_handle_t *phPort) {
return L0::SysmanDevice::fromHandle(hDevice)->fabricPortGet(pCount, phPort);
return L0::SysmanDevice::fabricPortGet(hDevice, pCount, phPort);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -475,7 +475,7 @@ zesDeviceEnumTemperatureSensors(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_temp_handle_t *phTemperature) {
return L0::SysmanDevice::fromHandle(hDevice)->temperatureGet(pCount, phTemperature);
return L0::SysmanDevice::temperatureGet(hDevice, pCount, phTemperature);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -533,7 +533,7 @@ zesDeviceEnumFans(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_fan_handle_t *phFan) {
return L0::SysmanDevice::fromHandle(hDevice)->fanGet(pCount, phFan);
return L0::SysmanDevice::fanGet(hDevice, pCount, phFan);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -619,7 +619,7 @@ zesDeviceEnumRasErrorSets(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_ras_handle_t *phRas) {
return L0::SysmanDevice::fromHandle(hDevice)->rasGet(pCount, phRas);
return L0::SysmanDevice::rasGet(hDevice, pCount, phRas);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -655,7 +655,7 @@ ZE_APIEXPORT ze_result_t ZE_APICALL
zesDeviceEventRegister(
zes_device_handle_t hDevice,
zes_event_type_flags_t events) {
return L0::SysmanDevice::fromHandle(hDevice)->deviceEventRegister(events);
return L0::SysmanDevice::deviceEventRegister(hDevice, events);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -685,7 +685,7 @@ zesDeviceEnumDiagnosticTestSuites(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_diag_handle_t *phDiagnostics) {
return L0::SysmanDevice::fromHandle(hDevice)->diagnosticsGet(pCount, phDiagnostics);
return L0::SysmanDevice::diagnosticsGet(hDevice, pCount, phDiagnostics);
}
ZE_APIEXPORT ze_result_t ZE_APICALL
@@ -717,7 +717,7 @@ zesDeviceEnumPerformanceFactorDomains(
zes_device_handle_t hDevice,
uint32_t *pCount,
zes_perf_handle_t *phPerf) {
return L0::SysmanDevice::fromHandle(hDevice)->performanceGet(pCount, phPerf);
return L0::SysmanDevice::performanceGet(hDevice, pCount, phPerf);
}
ZE_APIEXPORT ze_result_t ZE_APICALL

View File

@@ -14,13 +14,15 @@ namespace L0 {
ze_result_t LinuxSysmanImp::init() {
pFwUtilInterface = FirmwareUtil::create();
pFsAccess = FsAccess::create();
UNRECOVERABLE_IF(nullptr == pFsAccess);
DEBUG_BREAK_IF(nullptr == pFsAccess);
pProcfsAccess = ProcfsAccess::create();
UNRECOVERABLE_IF(nullptr == pProcfsAccess);
if (pProcfsAccess == nullptr) {
pProcfsAccess = ProcfsAccess::create();
}
DEBUG_BREAK_IF(nullptr == pProcfsAccess);
pDevice = Device::fromHandle(pParentSysmanDeviceImp->hCoreDevice);
UNRECOVERABLE_IF(nullptr == pDevice);
DEBUG_BREAK_IF(nullptr == pDevice);
NEO::OSInterface &OsInterface = pDevice->getOsInterface();
pDrm = OsInterface.getDriverModel()->as<NEO::Drm>();
int myDeviceFd = pDrm->getFileDescriptor();
@@ -30,8 +32,10 @@ ze_result_t LinuxSysmanImp::init() {
return result;
}
pSysfsAccess = SysfsAccess::create(myDeviceName);
UNRECOVERABLE_IF(nullptr == pSysfsAccess);
if (pSysfsAccess == nullptr) {
pSysfsAccess = SysfsAccess::create(myDeviceName);
}
DEBUG_BREAK_IF(nullptr == pSysfsAccess);
std::string realRootPath;
result = pSysfsAccess->getRealPath("device", realRootPath);
@@ -42,7 +46,7 @@ ze_result_t LinuxSysmanImp::init() {
PlatformMonitoringTech::create(pParentSysmanDeviceImp->deviceHandles, pFsAccess, rootPciPathOfGpuDevice, mapOfSubDeviceIdToPmtObject);
pPmuInterface = PmuInterface::create(this);
UNRECOVERABLE_IF(nullptr == pPmuInterface);
DEBUG_BREAK_IF(nullptr == pPmuInterface);
return ZE_RESULT_SUCCESS;
}

View File

@@ -18,8 +18,11 @@ namespace L0 {
SysmanDevice *SysmanDeviceHandleContext::init(ze_device_handle_t coreDevice) {
SysmanDeviceImp *sysmanDevice = new SysmanDeviceImp(coreDevice);
UNRECOVERABLE_IF(!sysmanDevice);
sysmanDevice->init();
DEBUG_BREAK_IF(!sysmanDevice);
if (ZE_RESULT_SUCCESS != sysmanDevice->init()) {
delete sysmanDevice;
sysmanDevice = nullptr;
}
L0::DeviceImp *device = static_cast<DeviceImp *>(Device::fromHandle(coreDevice));
for (auto &subDevice : device->subDevices) {
static_cast<DeviceImp *>(subDevice)->setSysmanHandle(sysmanDevice);
@@ -87,4 +90,179 @@ ze_result_t DriverHandleImp::sysmanEventsListenEx(
return ZE_RESULT_SUCCESS;
}
ze_result_t SysmanDevice::performanceGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_perf_handle_t *phPerformance) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->performanceGet(pCount, phPerformance);
}
ze_result_t SysmanDevice::powerGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_pwr_handle_t *phPower) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->powerGet(pCount, phPower);
}
ze_result_t SysmanDevice::frequencyGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_freq_handle_t *phFrequency) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->frequencyGet(pCount, phFrequency);
}
ze_result_t SysmanDevice::fabricPortGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fabric_port_handle_t *phPort) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->fabricPortGet(pCount, phPort);
}
ze_result_t SysmanDevice::temperatureGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_temp_handle_t *phTemperature) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->temperatureGet(pCount, phTemperature);
}
ze_result_t SysmanDevice::standbyGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_standby_handle_t *phStandby) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->standbyGet(pCount, phStandby);
}
ze_result_t SysmanDevice::deviceGetProperties(zes_device_handle_t hDevice, zes_device_properties_t *pProperties) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->deviceGetProperties(pProperties);
}
ze_result_t SysmanDevice::processesGetState(zes_device_handle_t hDevice, uint32_t *pCount, zes_process_state_t *pProcesses) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->processesGetState(pCount, pProcesses);
}
ze_result_t SysmanDevice::deviceReset(zes_device_handle_t hDevice, ze_bool_t force) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->deviceReset(force);
}
ze_result_t SysmanDevice::deviceGetState(zes_device_handle_t hDevice, zes_device_state_t *pState) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->deviceGetState(pState);
}
ze_result_t SysmanDevice::engineGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_engine_handle_t *phEngine) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->engineGet(pCount, phEngine);
}
ze_result_t SysmanDevice::pciGetProperties(zes_device_handle_t hDevice, zes_pci_properties_t *pProperties) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->pciGetProperties(pProperties);
}
ze_result_t SysmanDevice::pciGetState(zes_device_handle_t hDevice, zes_pci_state_t *pState) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->pciGetState(pState);
}
ze_result_t SysmanDevice::pciGetBars(zes_device_handle_t hDevice, uint32_t *pCount, zes_pci_bar_properties_t *pProperties) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->pciGetBars(pCount, pProperties);
}
ze_result_t SysmanDevice::pciGetStats(zes_device_handle_t hDevice, zes_pci_stats_t *pStats) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->pciGetStats(pStats);
}
ze_result_t SysmanDevice::schedulerGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_sched_handle_t *phScheduler) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->schedulerGet(pCount, phScheduler);
}
ze_result_t SysmanDevice::rasGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_ras_handle_t *phRas) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->rasGet(pCount, phRas);
}
ze_result_t SysmanDevice::memoryGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_mem_handle_t *phMemory) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->memoryGet(pCount, phMemory);
}
ze_result_t SysmanDevice::fanGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fan_handle_t *phFan) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->fanGet(pCount, phFan);
}
ze_result_t SysmanDevice::diagnosticsGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_diag_handle_t *phDiagnostics) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->diagnosticsGet(pCount, phDiagnostics);
}
ze_result_t SysmanDevice::firmwareGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_firmware_handle_t *phFirmware) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->firmwareGet(pCount, phFirmware);
}
ze_result_t SysmanDevice::deviceEventRegister(zes_device_handle_t hDevice, zes_event_type_flags_t events) {
auto pSysmanDevice = L0::SysmanDevice::fromHandle(hDevice);
if (pSysmanDevice == nullptr) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return pSysmanDevice->deviceEventRegister(events);
}
} // namespace L0

View File

@@ -31,6 +31,29 @@ struct Device;
struct SysmanDevice : _ze_device_handle_t {
static SysmanDevice *fromHandle(zes_device_handle_t handle) { return Device::fromHandle(handle)->getSysmanHandle(); }
static ze_result_t performanceGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_perf_handle_t *phPerformance);
static ze_result_t powerGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_pwr_handle_t *phPower);
static ze_result_t frequencyGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_freq_handle_t *phFrequency);
static ze_result_t fabricPortGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fabric_port_handle_t *phPort);
static ze_result_t temperatureGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_temp_handle_t *phTemperature);
static ze_result_t standbyGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_standby_handle_t *phStandby);
static ze_result_t deviceGetProperties(zes_device_handle_t hDevice, zes_device_properties_t *pProperties);
static ze_result_t processesGetState(zes_device_handle_t hDevice, uint32_t *pCount, zes_process_state_t *pProcesses);
static ze_result_t deviceReset(zes_device_handle_t hDevice, ze_bool_t force);
static ze_result_t deviceGetState(zes_device_handle_t hDevice, zes_device_state_t *pState);
static ze_result_t engineGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_engine_handle_t *phEngine);
static ze_result_t pciGetProperties(zes_device_handle_t hDevice, zes_pci_properties_t *pProperties);
static ze_result_t pciGetState(zes_device_handle_t hDevice, zes_pci_state_t *pState);
static ze_result_t pciGetBars(zes_device_handle_t hDevice, uint32_t *pCount, zes_pci_bar_properties_t *pProperties);
static ze_result_t pciGetStats(zes_device_handle_t hDevice, zes_pci_stats_t *pStats);
static ze_result_t schedulerGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_sched_handle_t *phScheduler);
static ze_result_t rasGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_ras_handle_t *phRas);
static ze_result_t memoryGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_mem_handle_t *phMemory);
static ze_result_t fanGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_fan_handle_t *phFan);
static ze_result_t diagnosticsGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_diag_handle_t *phDiagnostics);
static ze_result_t firmwareGet(zes_device_handle_t hDevice, uint32_t *pCount, zes_firmware_handle_t *phFirmware);
static ze_result_t deviceEventRegister(zes_device_handle_t hDevice, zes_event_type_flags_t events);
static bool deviceEventListen(zes_device_handle_t hDevice, zes_event_type_flags_t &pEvent, uint64_t timeout);
virtual ze_result_t performanceGet(uint32_t *pCount, zes_perf_handle_t *phPerformance) = 0;
virtual ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) = 0;

View File

@@ -60,7 +60,7 @@ SysmanDeviceImp::~SysmanDeviceImp() {
freeResource(pOsSysman);
}
void SysmanDeviceImp::init() {
ze_result_t SysmanDeviceImp::init() {
uint32_t subDeviceCount = 0;
// We received a device handle. Check for subdevices in this device
Device::fromHandle(hCoreDevice)->getSubDevices(&subDeviceCount, nullptr);
@@ -71,7 +71,10 @@ void SysmanDeviceImp::init() {
Device::fromHandle(hCoreDevice)->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pOsSysman->init();
auto result = pOsSysman->init();
if (ZE_RESULT_SUCCESS != result) {
return result;
}
if (pPowerHandleContext) {
pPowerHandleContext->init();
}
@@ -120,6 +123,7 @@ void SysmanDeviceImp::init() {
if (pPerformanceHandleContext) {
pPerformanceHandleContext->init(deviceHandles);
}
return result;
}
ze_result_t SysmanDeviceImp::frequencyGet(uint32_t *pCount, zes_freq_handle_t *phFrequency) {

View File

@@ -22,7 +22,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass {
~SysmanDeviceImp() override;
SysmanDeviceImp() = delete;
void init();
ze_result_t init();
ze_device_handle_t hCoreDevice = nullptr;
std::vector<ze_device_handle_t> deviceHandles; // handles of all subdevices

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2020 Intel Corporation
# Copyright (C) 2020-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -9,6 +9,8 @@ if(UNIX)
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysman_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_procfs_access_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_sysfs_access_fixture.h
)
endif()

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/tools/source/sysman/sysman.h"
#include "sysman/linux/os_sysman_imp.h"
using ::testing::_;
using ::testing::NiceMock;
using namespace NEO;
namespace L0 {
namespace ult {
const std::string mockedDeviceName("/MOCK_DEVICE_NAME");
class LinuxProcfsAccess : public ProcfsAccess {};
template <>
struct Mock<LinuxProcfsAccess> : public LinuxProcfsAccess {
::pid_t ourDevicePid = 0;
int ourDeviceFd = 0;
ze_result_t getMockFileName(const ::pid_t pid, const int fd, std::string &val) {
if (pid == ourDevicePid && fd == ourDeviceFd) {
val = mockedDeviceName;
} else {
// return fake filenames for other file descriptors
val = std::string("/FILENAME") + std::to_string(fd);
}
return ZE_RESULT_SUCCESS;
}
Mock<LinuxProcfsAccess>() = default;
MOCK_METHOD(ze_result_t, getFileName, (const ::pid_t pid, const int fd, std::string &val), (override));
};
} // namespace ult
} // namespace L0

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "test.h"
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/tools/source/sysman/sysman.h"
#include "sysman/linux/os_sysman_imp.h"
using ::testing::_;
using ::testing::NiceMock;
using namespace NEO;
namespace L0 {
namespace ult {
class LinuxSysfsAccess : public SysfsAccess {};
template <>
struct Mock<LinuxSysfsAccess> : public LinuxSysfsAccess {
ze_result_t getRealPathVal(const std::string file, std::string &val) {
val = "/random/path";
return ZE_RESULT_SUCCESS;
}
Mock<LinuxSysfsAccess>() = default;
MOCK_METHOD(ze_result_t, getRealPath, (const std::string path, std::string &val), (override));
};
} // namespace ult
} // namespace L0

View File

@@ -14,10 +14,13 @@
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/tools/source/sysman/sysman.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_procfs_access_fixture.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysfs_access_fixture.h"
#include "sysman/linux/os_sysman_imp.h"
using ::testing::_;
using ::testing::Matcher;
using ::testing::NiceMock;
using namespace NEO;
@@ -42,17 +45,31 @@ class PublicLinuxSysmanImp : public L0::LinuxSysmanImp {
class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test {
public:
Mock<LinuxSysfsAccess> *pSysfsAccess = nullptr;
Mock<LinuxProcfsAccess> *pProcfsAccess = nullptr;
void SetUp() override {
DeviceFixture::SetUp();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique<NEO::OSInterface>();
auto &osInterface = device->getOsInterface();
osInterface.setDriverModel(std::make_unique<SysmanMockDrm>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
setenv("ZES_ENABLE_SYSMAN", "1", 1);
device->setSysmanHandle(L0::SysmanDeviceHandleContext::init(device->toHandle()));
device->setSysmanHandle(new SysmanDeviceImp(device->toHandle()));
pSysmanDevice = device->getSysmanHandle();
pSysmanDeviceImp = static_cast<SysmanDeviceImp *>(pSysmanDevice);
pOsSysman = pSysmanDeviceImp->pOsSysman;
pLinuxSysmanImp = static_cast<PublicLinuxSysmanImp *>(pOsSysman);
pSysfsAccess = new NiceMock<Mock<LinuxSysfsAccess>>;
pProcfsAccess = new NiceMock<Mock<LinuxProcfsAccess>>;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess;
pLinuxSysmanImp->pProcfsAccess = pProcfsAccess;
ON_CALL(*pSysfsAccess, getRealPath(_, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<LinuxSysfsAccess>::getRealPathVal));
ON_CALL(*pProcfsAccess, getFileName(_, _, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pProcfsAccess, &Mock<LinuxProcfsAccess>::getMockFileName));
pSysmanDeviceImp->init();
}
void TearDown() override {
DeviceFixture::TearDown();
@@ -67,6 +84,8 @@ class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test {
class SysmanMultiDeviceFixture : public MultiDeviceFixture, public ::testing::Test {
public:
Mock<LinuxSysfsAccess> *pSysfsAccess = nullptr;
Mock<LinuxProcfsAccess> *pProcfsAccess = nullptr;
void SetUp() override {
MultiDeviceFixture::SetUp();
device = driverHandle->devices[0];
@@ -75,11 +94,27 @@ class SysmanMultiDeviceFixture : public MultiDeviceFixture, public ::testing::Te
auto &osInterface = device->getOsInterface();
osInterface.setDriverModel(std::make_unique<SysmanMockDrm>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
setenv("ZES_ENABLE_SYSMAN", "1", 1);
device->setSysmanHandle(L0::SysmanDeviceHandleContext::init(device->toHandle()));
device->setSysmanHandle(new SysmanDeviceImp(device->toHandle()));
pSysmanDevice = device->getSysmanHandle();
for (auto &subDevice : static_cast<DeviceImp *>(device)->subDevices) {
static_cast<DeviceImp *>(subDevice)->setSysmanHandle(pSysmanDevice);
}
pSysmanDeviceImp = static_cast<SysmanDeviceImp *>(pSysmanDevice);
pOsSysman = pSysmanDeviceImp->pOsSysman;
pLinuxSysmanImp = static_cast<PublicLinuxSysmanImp *>(pOsSysman);
pSysfsAccess = new NiceMock<Mock<LinuxSysfsAccess>>;
pProcfsAccess = new NiceMock<Mock<LinuxProcfsAccess>>;
pLinuxSysmanImp->pSysfsAccess = pSysfsAccess;
pLinuxSysmanImp->pProcfsAccess = pProcfsAccess;
ON_CALL(*pSysfsAccess, getRealPath(_, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<LinuxSysfsAccess>::getRealPathVal));
ON_CALL(*pProcfsAccess, getFileName(_, _, Matcher<std::string &>(_)))
.WillByDefault(::testing::Invoke(pProcfsAccess, &Mock<LinuxProcfsAccess>::getMockFileName));
pSysmanDeviceImp->init();
subDeviceCount = numSubDevices;
}
void TearDown() override {

View File

@@ -58,13 +58,62 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleInSysmanImpCreationWhenAllSysm
sysmanImp->pDiagnosticsHandleContext = nullptr;
sysmanImp->pPerformanceHandleContext = nullptr;
auto pLinuxSysmanImpTemp = static_cast<PublicLinuxSysmanImp *>(sysmanImp->pOsSysman);
pLinuxSysmanImpTemp->pSysfsAccess = pSysfsAccess;
pLinuxSysmanImpTemp->pProcfsAccess = pProcfsAccess;
sysmanImp->init();
// all sysman module contexts are null. Validating PowerHandleContext instead of all contexts
EXPECT_EQ(sysmanImp->pPowerHandleContext, nullptr);
pLinuxSysmanImpTemp->pSysfsAccess = nullptr;
pLinuxSysmanImpTemp->pProcfsAccess = nullptr;
delete sysmanImp;
sysmanImp = nullptr;
}
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleAndIfSysmanDeviceInitFailsThenErrorReturnedWhileQueryingSysmanAPIs) {
ze_device_handle_t hSysman = device->toHandle();
auto pSysmanDeviceOriginal = static_cast<DeviceImp *>(device)->getSysmanHandle();
// L0::SysmanDeviceHandleContext::init() would return nullptr as:
// L0::SysmanDeviceHandleContext::init() --> sysmanDevice->init() --> pOsSysman->init() --> pSysfsAccess->getRealPath()
// pSysfsAccess->getRealPath() would fail because pSysfsAccess is not mocked in this test case.
auto pSysmanDeviceLocal = L0::SysmanDeviceHandleContext::init(hSysman);
EXPECT_EQ(pSysmanDeviceLocal, nullptr);
static_cast<DeviceImp *>(device)->setSysmanHandle(pSysmanDeviceLocal);
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumSchedulers(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceProcessesGetState(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDevicePciGetBars(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumPowerDomains(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumFrequencyDomains(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumEngineGroups(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumStandbyDomains(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumFirmwares(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumMemoryModules(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumFabricPorts(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumTemperatureSensors(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumRasErrorSets(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumFans(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumDiagnosticTestSuites(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEnumPerformanceFactorDomains(hSysman, &count, nullptr));
zes_device_properties_t properties;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceGetProperties(hSysman, &properties));
zes_device_state_t state;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceGetState(hSysman, &state));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceReset(hSysman, true));
zes_pci_properties_t pciProperties;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDevicePciGetProperties(hSysman, &pciProperties));
zes_pci_state_t pciState;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDevicePciGetState(hSysman, &pciState));
zes_pci_stats_t pciStats;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDevicePciGetStats(hSysman, &pciStats));
zes_event_type_flags_t events = ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zesDeviceEventRegister(hSysman, events));
static_cast<DeviceImp *>(device)->setSysmanHandle(pSysmanDeviceOriginal);
}
using MockDeviceSysmanGetTest = Test<DeviceFixture>;
TEST_F(MockDeviceSysmanGetTest, GivenValidSysmanHandleSetInDeviceStructWhenGetThisSysmanHandleThenHandlesShouldBeSimilar) {
SysmanDeviceImp *sysman = new SysmanDeviceImp(device->toHandle());
@@ -72,12 +121,10 @@ TEST_F(MockDeviceSysmanGetTest, GivenValidSysmanHandleSetInDeviceStructWhenGetTh
EXPECT_EQ(sysman, device->getSysmanHandle());
}
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleInSysmanInitThenValidSysmanHandleReceived) {
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleButSysmanInitFailsThenValidNullptrReceived) {
ze_device_handle_t hSysman = device->toHandle();
auto pSysmanDevice = L0::SysmanDeviceHandleContext::init(hSysman);
EXPECT_NE(pSysmanDevice, nullptr);
delete pSysmanDevice;
pSysmanDevice = nullptr;
EXPECT_EQ(pSysmanDevice, nullptr);
}
TEST_F(SysmanDeviceFixture, GivenSetValidDrmHandleForDeviceWhenDoingOsSysmanDeviceInitThenSameDrmHandleIsRetrieved) {
@@ -198,6 +245,12 @@ TEST_F(SysmanDeviceFixture, GivenValidPciPathWhileGettingRootPciPortThenReturned
}
TEST_F(SysmanMultiDeviceFixture, GivenValidDeviceHandleHavingSubdevicesWhenValidatingSysmanHandlesForSubdevicesThenSysmanHandleForSubdeviceWillBeSameAsSysmanHandleForDevice) {
ze_device_handle_t hSysman = device->toHandle();
auto pSysmanDeviceOriginal = static_cast<DeviceImp *>(device)->getSysmanHandle();
auto pSysmanDeviceLocal = L0::SysmanDeviceHandleContext::init(hSysman);
EXPECT_EQ(pSysmanDeviceLocal, nullptr);
static_cast<DeviceImp *>(device)->setSysmanHandle(pSysmanDeviceLocal);
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, device->getSubDevices(&count, nullptr));
std::vector<ze_device_handle_t> subDeviceHandles(count, nullptr);
@@ -206,6 +259,7 @@ TEST_F(SysmanMultiDeviceFixture, GivenValidDeviceHandleHavingSubdevicesWhenValid
L0::DeviceImp *subDeviceHandleImp = static_cast<DeviceImp *>(Device::fromHandle(subDeviceHandle));
EXPECT_EQ(subDeviceHandleImp->getSysmanHandle(), device->getSysmanHandle());
}
static_cast<DeviceImp *>(device)->setSysmanHandle(pSysmanDeviceOriginal);
}
TEST_F(SysmanMultiDeviceFixture, GivenValidEffectiveUserIdCheckWhetherPermissionsReturnedByIsRootUserAreCorrect) {

View File

@@ -128,7 +128,7 @@ struct MockMemoryManagerPci : public MemoryManagerMock {
MockMemoryManagerPci(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
};
class ZesPciFixture : public ::testing::Test {
class ZesPciFixture : public SysmanDeviceFixture {
protected:
std::unique_ptr<Mock<PciSysfsAccess>> pSysfsAccess;
@@ -139,28 +139,15 @@ class ZesPciFixture : public ::testing::Test {
L0::PciImp *pPciImp;
OsPci *pOsPciPrev;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManager *pMemoryManagerOld;
void SetUp() override {
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
NEO::DeviceVector devices;
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
memoryManager = new ::testing::NiceMock<MockMemoryManagerPci>(*devices[0].get()->getExecutionEnvironment());
devices[0].get()->getExecutionEnvironment()->memoryManager.reset(memoryManager);
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
SysmanDeviceFixture::SetUp();
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique<NEO::OSInterface>();
auto &osInterface = device->getOsInterface();
osInterface.setDriverModel(std::make_unique<SysmanMockDrm>(const_cast<NEO::RootDeviceEnvironment &>(neoDevice->getRootDeviceEnvironment())));
setenv("ZES_ENABLE_SYSMAN", "1", 1);
device->setSysmanHandle(L0::SysmanDeviceHandleContext::init(device->toHandle()));
pSysmanDevice = device->getSysmanHandle();
pSysmanDeviceImp = static_cast<SysmanDeviceImp *>(pSysmanDevice);
pOsSysman = pSysmanDeviceImp->pOsSysman;
pLinuxSysmanImp = static_cast<PublicLinuxSysmanImp *>(pOsSysman);
pMemoryManagerOld = device->getDriverHandle()->getMemoryManager();
memoryManager = new ::testing::NiceMock<MockMemoryManagerPci>(*neoDevice->getExecutionEnvironment());
memoryManager->localMemorySupported[0] = false;
device->getDriverHandle()->setMemoryManager(memoryManager);
pSysfsAccess = std::make_unique<NiceMock<Mock<PciSysfsAccess>>>();
pOriginalSysfsAccess = pLinuxSysmanImp->pSysfsAccess;
@@ -202,6 +189,8 @@ class ZesPciFixture : public ::testing::Test {
}
void TearDown() override {
device->getDriverHandle()->setMemoryManager(pMemoryManagerOld);
SysmanDeviceFixture::TearDown();
if (nullptr != pPciImp->pOsPci) {
delete pPciImp->pOsPci;
}
@@ -210,11 +199,11 @@ class ZesPciFixture : public ::testing::Test {
unsetenv("ZES_ENABLE_SYSMAN");
pLinuxSysmanImp->pSysfsAccess = pOriginalSysfsAccess;
pLinuxSysmanImp->pFsAccess = pOriginalFsAccess;
if (memoryManager != nullptr) {
delete memoryManager;
memoryManager = nullptr;
}
}
SysmanDevice *pSysmanDevice = nullptr;
SysmanDeviceImp *pSysmanDeviceImp = nullptr;
OsSysman *pOsSysman = nullptr;
PublicLinuxSysmanImp *pLinuxSysmanImp = nullptr;
};
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropertiesThenVerifyzetSysmanPciGetPropertiesCallSucceeds) {