Files
compute-runtime/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp
Bill Jordan 6e20dfafab Added limited XML parsing capability to L0 Sysman using libxml2.
XML parsing for linux only, hanging off the OsSysmanImp object.

Change-Id: I473dc8dde0611cc13f38a2c0b59e839fced2e59e
Signed-off-by: Bill Jordan <bill.jordan@intel.com>
2020-07-16 12:12:45 -07:00

122 lines
3.2 KiB
C++

/*
* Copyright (C) 2019-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/sysman/linux/os_sysman_imp.h"
#include "level_zero/tools/source/sysman/linux/fs_access.h"
namespace L0 {
ze_result_t LinuxSysmanImp::init() {
pXmlParser = XmlParser::create();
pFsAccess = FsAccess::create();
UNRECOVERABLE_IF(nullptr == pFsAccess);
pProcfsAccess = ProcfsAccess::create();
UNRECOVERABLE_IF(nullptr == pProcfsAccess);
Device *pDevice = nullptr;
if (pParentSysmanImp != nullptr) {
pDevice = Device::fromHandle(pParentSysmanImp->hCoreDevice);
} else if (pParentSysmanDeviceImp != nullptr) {
pDevice = Device::fromHandle(pParentSysmanDeviceImp->hCoreDevice);
} else {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
UNRECOVERABLE_IF(nullptr == pDevice);
NEO::OSInterface &OsInterface = pDevice->getOsInterface();
pDrm = OsInterface.get()->getDrm();
int myDeviceFd = pDrm->getFileDescriptor();
std::string myDeviceName;
ze_result_t result = pProcfsAccess->getFileName(pProcfsAccess->myProcessId(), myDeviceFd, myDeviceName);
if (ZE_RESULT_SUCCESS != result) {
return result;
}
pSysfsAccess = SysfsAccess::create(myDeviceName);
UNRECOVERABLE_IF(nullptr == pSysfsAccess);
pPmt = new PlatformMonitoringTech();
UNRECOVERABLE_IF(nullptr == pPmt);
pPmt->init(myDeviceName, pFsAccess);
return ZE_RESULT_SUCCESS;
}
XmlParser *LinuxSysmanImp::getXmlParser() {
return pXmlParser;
}
FsAccess &LinuxSysmanImp::getFsAccess() {
UNRECOVERABLE_IF(nullptr == pFsAccess);
return *pFsAccess;
}
ProcfsAccess &LinuxSysmanImp::getProcfsAccess() {
UNRECOVERABLE_IF(nullptr == pProcfsAccess);
return *pProcfsAccess;
}
SysfsAccess &LinuxSysmanImp::getSysfsAccess() {
UNRECOVERABLE_IF(nullptr == pSysfsAccess);
return *pSysfsAccess;
}
NEO::Drm &LinuxSysmanImp::getDrm() {
UNRECOVERABLE_IF(nullptr == pDrm);
return *pDrm;
}
PlatformMonitoringTech &LinuxSysmanImp::getPlatformMonitoringTechAccess() {
UNRECOVERABLE_IF(nullptr == pPmt);
return *pPmt;
}
LinuxSysmanImp::LinuxSysmanImp(SysmanImp *pParentSysmanImp) {
this->pParentSysmanImp = pParentSysmanImp;
}
LinuxSysmanImp::LinuxSysmanImp(SysmanDeviceImp *pParentSysmanDeviceImp) {
this->pParentSysmanDeviceImp = pParentSysmanDeviceImp;
}
LinuxSysmanImp::~LinuxSysmanImp() {
if (nullptr != pSysfsAccess) {
delete pSysfsAccess;
pSysfsAccess = nullptr;
}
if (nullptr != pProcfsAccess) {
delete pProcfsAccess;
pProcfsAccess = nullptr;
}
if (nullptr != pFsAccess) {
delete pFsAccess;
pFsAccess = nullptr;
}
if (nullptr != pXmlParser) {
delete pXmlParser;
pXmlParser = nullptr;
}
if (nullptr != pPmt) {
delete pPmt;
pPmt = nullptr;
}
}
OsSysman *OsSysman::create(SysmanImp *pParentSysmanImp) {
LinuxSysmanImp *pLinuxSysmanImp = new LinuxSysmanImp(pParentSysmanImp);
return static_cast<OsSysman *>(pLinuxSysmanImp);
}
OsSysman *OsSysman::create(SysmanDeviceImp *pParentSysmanDeviceImp) {
LinuxSysmanImp *pLinuxSysmanImp = new LinuxSysmanImp(pParentSysmanDeviceImp);
return static_cast<OsSysman *>(pLinuxSysmanImp);
}
} // namespace L0