mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-30 01:35:20 +08:00
refactor: Move PMT common code to PMT specific class
Facilitate PMT utilization for other modules with refactoring common PMT calls. Related-To: NEO-8848 Signed-off-by: Bellekallu Rajkiran <bellekallu.rajkiran@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
433ecf4058
commit
0ce762a91c
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/os_interface/linux/file_descriptor.h"
|
||||
#include "shared/source/os_interface/linux/pmt_util.h"
|
||||
|
||||
#include "level_zero/sysman/source/device/sysman_device_imp.h"
|
||||
#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h"
|
||||
@@ -203,6 +204,46 @@ void PlatformMonitoringTech::create(LinuxSysmanImp *pLinuxSysmanImp, std::string
|
||||
}
|
||||
}
|
||||
|
||||
bool PlatformMonitoringTech::getTelemOffsetAndTelemDir(LinuxSysmanImp *pLinuxSysmanImp, uint64_t &telemOffset, std::string &telemDir) {
|
||||
std::string &rootPath = pLinuxSysmanImp->getPciRootPath();
|
||||
|
||||
std::map<uint32_t, std::string> telemPciPath;
|
||||
NEO::PmtUtil::getTelemNodesInPciPath(std::string_view(rootPath), telemPciPath);
|
||||
uint32_t subDeviceCount = pLinuxSysmanImp->getSubDeviceCount() + 1;
|
||||
if (telemPciPath.size() < subDeviceCount) {
|
||||
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Number of telemetry nodes:%d is lessthan %d \n", __FUNCTION__, telemPciPath.size(), subDeviceCount);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iterator = telemPciPath.begin();
|
||||
telemDir = iterator->second;
|
||||
|
||||
if (!NEO::PmtUtil::readOffset(telemDir, telemOffset)) {
|
||||
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read offset from %s\n", __FUNCTION__, telemDir.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformMonitoringTech::getTelemOffsetForContainer(const std::string &telemDir, const std::string &key, uint64_t &telemOffset) {
|
||||
std::array<char, NEO::PmtUtil::guidStringSize> guidString = {};
|
||||
if (!NEO::PmtUtil::readGuid(telemDir, guidString)) {
|
||||
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to read GUID from %s \n", __FUNCTION__, telemDir.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<std::string, uint64_t> keyOffsetMap;
|
||||
if (ZE_RESULT_SUCCESS == PlatformMonitoringTech::getKeyOffsetMap(guidString.data(), keyOffsetMap)) {
|
||||
auto keyOffset = keyOffsetMap.find(key.c_str());
|
||||
if (keyOffset != keyOffsetMap.end()) {
|
||||
telemOffset = keyOffset->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to find keyOffset in keyOffsetMap \n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
PlatformMonitoringTech::~PlatformMonitoringTech() {
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass {
|
||||
static void create(LinuxSysmanImp *pLinuxSysmanImp, std::string &gpuUpstreamPortPath,
|
||||
std::map<uint32_t, L0::Sysman::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject);
|
||||
static ze_result_t getKeyOffsetMap(std::string guid, std::map<std::string, uint64_t> &keyOffsetMap);
|
||||
static bool getTelemOffsetAndTelemDir(LinuxSysmanImp *pLinuxSysmanImp, uint64_t &telemOffset, std::string &telemDir);
|
||||
static bool getTelemOffsetForContainer(const std::string &telemDir, const std::string &key, uint64_t &telemOffset);
|
||||
|
||||
protected:
|
||||
static uint32_t rootDeviceTelemNodeIndex;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h"
|
||||
|
||||
#include "level_zero/sysman/source/shared/linux/zes_os_sysman_imp.h"
|
||||
|
||||
#include <csignal>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
@@ -18,18 +20,6 @@ namespace Sysman {
|
||||
|
||||
FsAccessInterface::~FsAccessInterface() = default;
|
||||
|
||||
static ze_result_t getResult(int err) {
|
||||
if ((EPERM == err) || (EACCES == err)) {
|
||||
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
} else if (ENOENT == err) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
} else if (EBUSY == err) {
|
||||
return ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE;
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void FdCacheInterface::eraseLeastUsedEntryFromCache() {
|
||||
auto it = fdMap.begin();
|
||||
uint32_t fdCountRef = it->second.second;
|
||||
@@ -76,12 +66,12 @@ ze_result_t FsAccessInterface::readValue(const std::string file, T &val) {
|
||||
std::string readVal(64, '\0');
|
||||
int fd = pFdCacheInterface->getFd(file);
|
||||
if (fd < 0) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
|
||||
ssize_t bytesRead = NEO::SysCalls::pread(fd, readVal.data(), readVal.size(), 0);
|
||||
if (bytesRead < 0) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
|
||||
std::istringstream stream(readVal);
|
||||
@@ -125,12 +115,12 @@ ze_result_t FsAccessInterface::read(const std::string file, std::string &val) {
|
||||
|
||||
fs.open(file.c_str());
|
||||
if (fs.fail()) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
fs >> val;
|
||||
if (fs.fail()) {
|
||||
fs.close();
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
fs.close();
|
||||
// Strip trailing newline
|
||||
@@ -148,12 +138,12 @@ ze_result_t FsAccessInterface::read(const std::string file, std::vector<std::str
|
||||
|
||||
fs.open(file.c_str());
|
||||
if (fs.fail()) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
while (std::getline(fs, line)) {
|
||||
if (fs.fail()) {
|
||||
fs.close();
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
if (line.back() == '\n') {
|
||||
line.pop_back();
|
||||
@@ -168,13 +158,13 @@ ze_result_t FsAccessInterface::read(const std::string file, std::vector<std::str
|
||||
ze_result_t FsAccessInterface::write(const std::string file, const std::string val) {
|
||||
int fd = NEO::SysCalls::open(file.c_str(), O_WRONLY);
|
||||
if (fd < 0) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
|
||||
ssize_t bytesWritten = NEO::SysCalls::pwrite(fd, val.data(), val.size(), 0);
|
||||
NEO::SysCalls::close(fd);
|
||||
if (bytesWritten < 0) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
|
||||
if (bytesWritten != static_cast<ssize_t>(val.size())) {
|
||||
@@ -216,7 +206,7 @@ bool FsAccessInterface::fileExists(const std::string file) {
|
||||
ze_result_t FsAccessInterface::getFileMode(const std::string file, ::mode_t &mode) {
|
||||
struct stat sb;
|
||||
if (0 != NEO::SysCalls::stat(file.c_str(), &sb)) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
mode = sb.st_mode;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
@@ -227,7 +217,7 @@ ze_result_t FsAccessInterface::readSymLink(const std::string path, std::string &
|
||||
char buf[PATH_MAX];
|
||||
ssize_t len = NEO::SysCalls::readlink(path.c_str(), buf, PATH_MAX - 1);
|
||||
if (len < 0) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
buf[len] = '\0';
|
||||
val = std::string(buf);
|
||||
@@ -239,7 +229,7 @@ ze_result_t FsAccessInterface::getRealPath(const std::string path, std::string &
|
||||
char buf[PATH_MAX];
|
||||
char *realPath = NEO::SysCalls::realpath(path.c_str(), buf);
|
||||
if (!realPath) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
val = std::string(buf);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
@@ -249,7 +239,7 @@ ze_result_t FsAccessInterface::listDirectory(const std::string path, std::vector
|
||||
list.clear();
|
||||
::DIR *procDir = NEO::SysCalls::opendir(path.c_str());
|
||||
if (!procDir) {
|
||||
return getResult(errno);
|
||||
return LinuxSysmanImp::getResult(errno);
|
||||
}
|
||||
struct ::dirent *ent;
|
||||
int err = 0;
|
||||
@@ -270,7 +260,7 @@ ze_result_t FsAccessInterface::listDirectory(const std::string path, std::vector
|
||||
// Check if in above while loop, readdir encountered any error.
|
||||
if ((err != 0) && (err != ENOENT)) {
|
||||
list.clear();
|
||||
return getResult(err);
|
||||
return LinuxSysmanImp::getResult(err);
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -63,12 +63,20 @@ ze_result_t LinuxSysmanImp::init() {
|
||||
return createPmtHandles();
|
||||
}
|
||||
|
||||
std::string &LinuxSysmanImp::getDeviceName() {
|
||||
return deviceName;
|
||||
ze_result_t LinuxSysmanImp::getResult(int err) {
|
||||
if ((EPERM == err) || (EACCES == err)) {
|
||||
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
} else if (ENOENT == err) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
} else if (EBUSY == err) {
|
||||
return ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE;
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
std::string &LinuxSysmanImp::getPciRootPath() {
|
||||
return rootPath;
|
||||
std::string &LinuxSysmanImp::getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
SysmanHwDeviceIdDrm::SingleInstance LinuxSysmanImp::getSysmanHwDeviceIdInstance() {
|
||||
|
||||
@@ -70,7 +70,7 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
decltype(&NEO::SysCalls::pwrite) pwriteFunction = NEO::SysCalls::pwrite;
|
||||
ze_result_t createPmtHandles();
|
||||
SysmanDeviceImp *getParentSysmanDeviceImp() { return pParentSysmanDeviceImp; }
|
||||
std::string &getPciRootPath();
|
||||
std::string &getPciRootPath() { return rootPath; }
|
||||
std::string &getDeviceName();
|
||||
std::string devicePciBdf = "";
|
||||
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
|
||||
@@ -79,6 +79,7 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
bool isMemoryDiagnostics = false;
|
||||
std::string gtDevicePath;
|
||||
SysmanKmdInterface *getSysmanKmdInterface() { return pSysmanKmdInterface.get(); }
|
||||
static ze_result_t getResult(int err);
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SysmanProductHelper> pSysmanProductHelper;
|
||||
|
||||
Reference in New Issue
Block a user