2021-01-20 23:52:47 +05:30
|
|
|
/*
|
2023-01-09 17:14:18 +00:00
|
|
|
* Copyright (C) 2021-2023 Intel Corporation
|
2021-01-20 23:52:47 +05:30
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "level_zero/tools/source/sysman/linux/pmt/pmt.h"
|
|
|
|
|
|
|
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2023-01-09 17:14:18 +00:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
2021-01-20 23:52:47 +05:30
|
|
|
|
2022-01-11 11:10:46 +05:30
|
|
|
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
|
|
|
|
|
2021-01-20 23:52:47 +05:30
|
|
|
#include <algorithm>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
namespace L0 {
|
2021-02-15 18:30:29 +05:30
|
|
|
const std::string PlatformMonitoringTech::baseTelemSysFS("/sys/class/intel_pmt");
|
2021-01-20 23:52:47 +05:30
|
|
|
const std::string PlatformMonitoringTech::telem("telem");
|
|
|
|
|
uint32_t PlatformMonitoringTech::rootDeviceTelemNodeIndex = 0;
|
|
|
|
|
|
2023-07-05 06:56:31 +00:00
|
|
|
std::string PlatformMonitoringTech::getGuid() {
|
|
|
|
|
return guid;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 20:39:43 +05:30
|
|
|
ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint32_t &value) {
|
|
|
|
|
auto offset = keyOffsetMap.find(key);
|
|
|
|
|
if (offset == keyOffsetMap.end()) {
|
|
|
|
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
|
|
|
|
}
|
2021-12-02 08:13:03 +00:00
|
|
|
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
|
|
|
|
|
if (fd == -1) {
|
2021-03-17 20:39:43 +05:30
|
|
|
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 08:13:03 +00:00
|
|
|
ze_result_t res = ZE_RESULT_SUCCESS;
|
|
|
|
|
if (this->preadFunction(fd, &value, sizeof(uint32_t), baseOffset + offset->second) != sizeof(uint32_t)) {
|
|
|
|
|
res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this->closeFunction(fd) < 0) {
|
|
|
|
|
return ZE_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t PlatformMonitoringTech::readValue(const std::string key, uint64_t &value) {
|
2021-03-17 20:39:43 +05:30
|
|
|
auto offset = keyOffsetMap.find(key);
|
|
|
|
|
if (offset == keyOffsetMap.end()) {
|
|
|
|
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
|
|
|
|
}
|
2021-12-02 08:13:03 +00:00
|
|
|
int fd = this->openFunction(telemetryDeviceEntry.c_str(), O_RDONLY);
|
|
|
|
|
if (fd == -1) {
|
|
|
|
|
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t res = ZE_RESULT_SUCCESS;
|
|
|
|
|
if (this->preadFunction(fd, &value, sizeof(uint64_t), baseOffset + offset->second) != sizeof(uint64_t)) {
|
|
|
|
|
res = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this->closeFunction(fd) < 0) {
|
|
|
|
|
return ZE_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2021-03-17 20:39:43 +05:30
|
|
|
}
|
|
|
|
|
|
2021-04-01 20:42:54 +05:30
|
|
|
bool compareTelemNodes(std::string &telemNode1, std::string &telemNode2) {
|
|
|
|
|
std::string telem = "telem";
|
|
|
|
|
auto indexString1 = telemNode1.substr(telem.size(), telemNode1.size());
|
|
|
|
|
auto indexForTelemNode1 = stoi(indexString1);
|
|
|
|
|
auto indexString2 = telemNode2.substr(telem.size(), telemNode2.size());
|
|
|
|
|
auto indexForTelemNode2 = stoi(indexString2);
|
|
|
|
|
return indexForTelemNode1 < indexForTelemNode2;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 13:02:42 +00:00
|
|
|
// Check if Telemetry node(say /sys/class/intel_pmt/telem1) and gpuUpstreamPortPath share same PCI Root port
|
|
|
|
|
static bool isValidTelemNode(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, const std::string sysfsTelemNode) {
|
2021-06-07 15:21:41 +00:00
|
|
|
std::string realPathOfTelemNode;
|
|
|
|
|
auto result = pFsAccess->getRealPath(sysfsTelemNode, realPathOfTelemNode);
|
|
|
|
|
if (result != ZE_RESULT_SUCCESS) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example: If
|
2022-06-16 13:02:42 +00:00
|
|
|
// gpuUpstreamPortPath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0";
|
2021-06-07 15:21:41 +00:00
|
|
|
// realPathOfTelemNode = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1";
|
2022-06-16 13:02:42 +00:00
|
|
|
// As gpuUpstreamPortPath is a substring of realPathOfTelemNode , hence both sysfs telemNode and GPU device share same PCI Root.
|
|
|
|
|
// the PMT is part of the OOBMSM sitting on a switch port 0000:8b:02.0 attached to the upstream port/ Also known as CardBus
|
2021-06-07 15:21:41 +00:00
|
|
|
// Hence this telem node entry is valid for GPU device.
|
2022-06-16 13:02:42 +00:00
|
|
|
return (realPathOfTelemNode.compare(0, gpuUpstreamPortPath.size(), gpuUpstreamPortPath) == 0);
|
2021-06-07 15:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 13:02:42 +00:00
|
|
|
ze_result_t PlatformMonitoringTech::enumerateRootTelemIndex(FsAccess *pFsAccess, std::string &gpuUpstreamPortPath) {
|
2021-01-20 23:52:47 +05:30
|
|
|
std::vector<std::string> listOfTelemNodes;
|
|
|
|
|
auto result = pFsAccess->listDirectory(baseTelemSysFS, listOfTelemNodes);
|
|
|
|
|
if (ZE_RESULT_SUCCESS != result) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 10:35:58 +00:00
|
|
|
// listOfTelemNodes vector could contain non "telem" entries which are not interested to us.
|
|
|
|
|
// Lets refactor listOfTelemNodes vector as below
|
|
|
|
|
for (auto iterator = listOfTelemNodes.begin(); iterator != listOfTelemNodes.end(); iterator++) {
|
|
|
|
|
if (iterator->compare(0, telem.size(), telem) != 0) {
|
|
|
|
|
listOfTelemNodes.erase(iterator--); // Remove entry if its suffix is not "telem"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 23:52:47 +05:30
|
|
|
// Exmaple: For below directory
|
2021-02-15 18:30:29 +05:30
|
|
|
// # /sys/class/intel_pmt$ ls
|
2021-01-20 23:52:47 +05:30
|
|
|
// telem1 telem2 telem3
|
|
|
|
|
// Then listOfTelemNodes would contain telem1, telem2, telem3
|
2021-04-01 20:42:54 +05:30
|
|
|
std::sort(listOfTelemNodes.begin(), listOfTelemNodes.end(), compareTelemNodes); // sort listOfTelemNodes, to arange telem nodes in ascending order
|
2021-01-20 23:52:47 +05:30
|
|
|
for (const auto &telemNode : listOfTelemNodes) {
|
2022-06-16 13:02:42 +00:00
|
|
|
if (isValidTelemNode(pFsAccess, gpuUpstreamPortPath, baseTelemSysFS + "/" + telemNode)) {
|
2021-01-20 23:52:47 +05:30
|
|
|
auto indexString = telemNode.substr(telem.size(), telemNode.size());
|
|
|
|
|
rootDeviceTelemNodeIndex = stoi(indexString); // if telemNode is telemN, then rootDeviceTelemNodeIndex = N
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-17 20:39:43 +05:30
|
|
|
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
|
|
|
|
|
2022-08-23 08:50:53 +00:00
|
|
|
ze_result_t PlatformMonitoringTech::init(FsAccess *pFsAccess, const std::string &gpuUpstreamPortPath, PRODUCT_FAMILY productFamily) {
|
2021-01-20 23:52:47 +05:30
|
|
|
std::string telemNode = telem + std::to_string(rootDeviceTelemNodeIndex);
|
2022-08-23 08:50:53 +00:00
|
|
|
// For XE_HP_SDV and PVC single tile devices, telemetry info is retrieved from
|
|
|
|
|
// tile's telem node rather from root device telem node.
|
2023-07-18 13:52:42 +00:00
|
|
|
if ((isSubdevice) || (productFamily == IGFX_PVC)) {
|
2021-01-20 23:52:47 +05:30
|
|
|
uint32_t telemNodeIndex = 0;
|
|
|
|
|
// If rootDeviceTelemNode is telem1, then rootDeviceTelemNodeIndex = 1
|
|
|
|
|
// And thus for subdevice0 --> telem node will be telem2,
|
|
|
|
|
// for subdevice1 --> telem node will be telem3 etc
|
|
|
|
|
telemNodeIndex = rootDeviceTelemNodeIndex + subdeviceId + 1;
|
|
|
|
|
telemNode = telem + std::to_string(telemNodeIndex);
|
|
|
|
|
}
|
|
|
|
|
std::string baseTelemSysFSNode = baseTelemSysFS + "/" + telemNode;
|
2022-06-16 13:02:42 +00:00
|
|
|
if (!isValidTelemNode(pFsAccess, gpuUpstreamPortPath, baseTelemSysFSNode)) {
|
2021-06-07 15:21:41 +00:00
|
|
|
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 08:13:03 +00:00
|
|
|
telemetryDeviceEntry = baseTelemSysFSNode + "/" + telem;
|
2021-01-20 23:52:47 +05:30
|
|
|
if (!pFsAccess->fileExists(telemetryDeviceEntry)) {
|
|
|
|
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
|
|
|
|
"Telemetry support not available. No file %s\n", telemetryDeviceEntry.c_str());
|
2021-03-17 20:39:43 +05:30
|
|
|
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
|
|
|
|
|
2023-07-04 14:05:08 +02:00
|
|
|
std::string guid;
|
2021-01-20 23:52:47 +05:30
|
|
|
std::string guidPath = baseTelemSysFSNode + std::string("/guid");
|
|
|
|
|
ze_result_t result = pFsAccess->read(guidPath, guid);
|
|
|
|
|
if (ZE_RESULT_SUCCESS != result) {
|
|
|
|
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
|
|
|
|
"Telemetry sysfs entry not available %s\n", guidPath.c_str());
|
2021-03-17 20:39:43 +05:30
|
|
|
return result;
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
2022-10-09 11:16:33 +00:00
|
|
|
result = PlatformMonitoringTech::getKeyOffsetMap(guid, keyOffsetMap);
|
2021-06-07 15:21:41 +00:00
|
|
|
if (ZE_RESULT_SUCCESS != result) {
|
2021-03-03 12:34:30 +05:30
|
|
|
// We didnt have any entry for this guid in guidToKeyOffsetMap
|
2021-03-17 20:39:43 +05:30
|
|
|
return result;
|
2021-03-03 12:34:30 +05:30
|
|
|
}
|
2021-01-20 23:52:47 +05:30
|
|
|
|
|
|
|
|
std::string offsetPath = baseTelemSysFSNode + std::string("/offset");
|
|
|
|
|
result = pFsAccess->read(offsetPath, baseOffset);
|
|
|
|
|
if (ZE_RESULT_SUCCESS != result) {
|
|
|
|
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr,
|
|
|
|
|
"Telemetry sysfs entry not available %s\n", offsetPath.c_str());
|
2021-03-17 20:39:43 +05:30
|
|
|
return result;
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
|
|
|
|
|
2021-03-17 20:39:43 +05:30
|
|
|
return ZE_RESULT_SUCCESS;
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlatformMonitoringTech::PlatformMonitoringTech(FsAccess *pFsAccess, ze_bool_t onSubdevice,
|
|
|
|
|
uint32_t subdeviceId) : subdeviceId(subdeviceId), isSubdevice(onSubdevice) {
|
2021-03-17 20:39:43 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlatformMonitoringTech::doInitPmtObject(FsAccess *pFsAccess, uint32_t subdeviceId, PlatformMonitoringTech *pPmt,
|
2022-06-16 13:02:42 +00:00
|
|
|
const std::string &gpuUpstreamPortPath,
|
2022-08-23 08:50:53 +00:00
|
|
|
std::map<uint32_t, L0::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject, PRODUCT_FAMILY productFamily) {
|
|
|
|
|
if (pPmt->init(pFsAccess, gpuUpstreamPortPath, productFamily) == ZE_RESULT_SUCCESS) {
|
2021-03-17 20:39:43 +05:30
|
|
|
mapOfSubDeviceIdToPmtObject.emplace(subdeviceId, pPmt);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
delete pPmt; // We are here as pPmt->init failed and thus this pPmt object is not useful. Let's delete that.
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlatformMonitoringTech::create(const std::vector<ze_device_handle_t> &deviceHandles,
|
2022-06-16 13:02:42 +00:00
|
|
|
FsAccess *pFsAccess, std::string &gpuUpstreamPortPath,
|
2021-01-20 23:52:47 +05:30
|
|
|
std::map<uint32_t, L0::PlatformMonitoringTech *> &mapOfSubDeviceIdToPmtObject) {
|
2022-06-16 13:02:42 +00:00
|
|
|
if (ZE_RESULT_SUCCESS == PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, gpuUpstreamPortPath)) {
|
2021-01-20 23:52:47 +05:30
|
|
|
for (const auto &deviceHandle : deviceHandles) {
|
2022-01-11 11:10:46 +05:30
|
|
|
uint32_t subdeviceId = 0;
|
|
|
|
|
ze_bool_t onSubdevice = false;
|
2022-11-28 11:55:07 +00:00
|
|
|
SysmanDeviceImp::getSysmanDeviceInfo(deviceHandle, subdeviceId, onSubdevice, true);
|
2022-08-23 08:50:53 +00:00
|
|
|
auto productFamily = SysmanDeviceImp::getProductFamily(Device::fromHandle(deviceHandle));
|
2022-01-11 11:10:46 +05:30
|
|
|
auto pPmt = new PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId);
|
2021-01-20 23:52:47 +05:30
|
|
|
UNRECOVERABLE_IF(nullptr == pPmt);
|
2022-01-11 11:10:46 +05:30
|
|
|
PlatformMonitoringTech::doInitPmtObject(pFsAccess, subdeviceId, pPmt,
|
2022-08-23 08:50:53 +00:00
|
|
|
gpuUpstreamPortPath, mapOfSubDeviceIdToPmtObject, productFamily);
|
2021-01-20 23:52:47 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlatformMonitoringTech::~PlatformMonitoringTech() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace L0
|