| 1 |
/* |
| 2 |
* Copyright (C) 2021-2025 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
|
| 10 |
#include "level_zero/tools/source/sysman/linux/fs_access.h" |
| 11 |
#include "level_zero/tools/source/sysman/linux/pmt/pmt.h" |
| 12 |
|
| 13 |
namespace L0 { |
| 14 |
namespace ult { |
| 15 |
|
| 16 |
const std::string baseTelemSysFS("/sys/class/intel_pmt"); |
| 17 |
const std::string telem("telem"); |
| 18 |
const std::string telemNodeForSubdevice0("telem2"); |
| 19 |
const std::string telemNodeForSubdevice1("telem3"); |
| 20 |
std::string gpuUpstreamPortPathInPmt = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; |
| 21 |
const std::string realPathTelem1 = "/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"; |
| 22 |
const std::string realPathTelem2 = "/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/telem2"; |
| 23 |
const std::string realPathTelem3 = "/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/telem3"; |
| 24 |
const std::string realPathTelem4 = "/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/telem4"; |
| 25 |
const std::string realPathTelem5 = "/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/telem5"; |
| 26 |
const std::string invalidRealPath = "/sys/devices/pci0000:89/0000:89:02.0/0000:8e:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1"; |
| 27 |
const std::string sysfsPahTelem1 = "/sys/class/intel_pmt/telem1"; |
| 28 |
const std::string sysfsPahTelem2 = "/sys/class/intel_pmt/telem2"; |
| 29 |
const std::string sysfsPahTelem3 = "/sys/class/intel_pmt/telem3"; |
| 30 |
const std::string sysfsPahTelem4 = "/sys/class/intel_pmt/telem4"; |
| 31 |
const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5"; |
| 32 |
|
| 33 |
struct MockPmtFsAccess : public FsAccess { |
| 34 |
|
| 35 |
ze_result_t listDirectoryResult = ZE_RESULT_SUCCESS; |
| 36 |
ze_result_t getRealPathResult = ZE_RESULT_SUCCESS; |
| 37 |
ze_result_t readUnsignedResult = ZE_RESULT_SUCCESS; |
| 38 |
ze_result_t readStringResult = ZE_RESULT_SUCCESS; |
| 39 |
ze_bool_t returnTelemNodes = true; |
| 40 |
ze_bool_t returnInvalidRealPath = false; |
| 41 |
ze_bool_t readInvalidString = false; |
| 42 |
|
| 43 |
MockPmtFsAccess() { |
| 44 |
baseTelemSysFSNodeForSubdevice0 = baseTelemSysFS + "/" + telemNodeForSubdevice0; |
| 45 |
baseTelemSysFSNodeForSubdevice1 = baseTelemSysFS + "/" + telemNodeForSubdevice1; |
| 46 |
telemetryDeviceEntryForSubdevice0 = baseTelemSysFSNodeForSubdevice0 + "/" + telem; |
| 47 |
telemetryDeviceEntryForSubdevice1 = baseTelemSysFSNodeForSubdevice1 + "/" + telem; |
| 48 |
} |
| 49 |
|
| 50 |
ze_result_t read(const std::string file, std::string &val) override { |
| 51 |
if (readStringResult != ZE_RESULT_SUCCESS) { |
| 52 |
return readStringResult; |
| 53 |
} |
| 54 |
|
| 55 |
if (readInvalidString) { |
| 56 |
val = ""; |
| 57 |
return ZE_RESULT_SUCCESS; |
| 58 |
} |
| 59 |
|
| 60 |
std::string guidPathForSubdevice0 = baseTelemSysFSNodeForSubdevice0 + std::string("/guid"); |
| 61 |
std::string guidPathForSubdevice1 = baseTelemSysFSNodeForSubdevice1 + std::string("/guid"); |
| 62 |
if ((file.compare(guidPathForSubdevice0) == 0) || |
| 63 |
(file.compare(guidPathForSubdevice1) == 0)) { |
| 64 |
val = "0x490e01"; |
| 65 |
return ZE_RESULT_SUCCESS; |
| 66 |
} |
| 67 |
return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 68 |
} |
| 69 |
|
| 70 |
ze_result_t read(const std::string file, uint64_t &val) override { |
| 71 |
if (readUnsignedResult != ZE_RESULT_SUCCESS) { |
| 72 |
return readUnsignedResult; |
| 73 |
} |
| 74 |
|
| 75 |
if ((file.compare(baseTelemSysFSNodeForSubdevice0 + std::string("/size")) == 0) || |
| 76 |
(file.compare(baseTelemSysFSNodeForSubdevice1 + std::string("/size")) == 0) || |
| 77 |
(file.compare(baseTelemSysFSNodeForSubdevice0 + std::string("/offset")) == 0) || |
| 78 |
(file.compare(baseTelemSysFSNodeForSubdevice1 + std::string("/offset")) == 0)) { |
| 79 |
val = 0; |
| 80 |
return ZE_RESULT_SUCCESS; |
| 81 |
} |
| 82 |
return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 83 |
} |
| 84 |
|
| 85 |
bool fileExists(const std::string file) override { |
| 86 |
if ((file.compare(telemetryDeviceEntryForSubdevice0) == 0) || |
| 87 |
(file.compare(telemetryDeviceEntryForSubdevice1) == 0)) { |
| 88 |
return true; |
| 89 |
} |
| 90 |
|
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
ze_result_t getRealPath(const std::string path, std::string &buf) override { |
| 95 |
if (getRealPathResult != ZE_RESULT_SUCCESS) { |
| 96 |
return getRealPathResult; |
| 97 |
} |
| 98 |
|
| 99 |
if (returnInvalidRealPath) { |
| 100 |
buf = invalidRealPath; |
| 101 |
return ZE_RESULT_SUCCESS; |
| 102 |
} |
| 103 |
|
| 104 |
if (path.compare(sysfsPahTelem1) == 0) { |
| 105 |
buf = realPathTelem1; |
| 106 |
} else if (path.compare(sysfsPahTelem2) == 0) { |
| 107 |
buf = realPathTelem2; |
| 108 |
} else if (path.compare(sysfsPahTelem3) == 0) { |
| 109 |
buf = realPathTelem3; |
| 110 |
} else if (path.compare(sysfsPahTelem4) == 0) { |
| 111 |
buf = realPathTelem4; |
| 112 |
} else if (path.compare(sysfsPahTelem5) == 0) { |
| 113 |
buf = realPathTelem5; |
| 114 |
} else { |
| 115 |
return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 116 |
} |
| 117 |
|
| 118 |
return ZE_RESULT_SUCCESS; |
| 119 |
} |
| 120 |
|
| 121 |
ze_result_t listDirectory(const std::string directory, std::vector<std::string> &listOfTelemNodes) override { |
| 122 |
if (listDirectoryResult != ZE_RESULT_SUCCESS) { |
| 123 |
return listDirectoryResult; |
| 124 |
} |
| 125 |
if (directory.compare(baseTelemSysFS) == 0) { |
| 126 |
listOfTelemNodes.push_back("crashlog2"); |
| 127 |
listOfTelemNodes.push_back("crashlog1"); |
| 128 |
if (returnTelemNodes) { |
| 129 |
listOfTelemNodes.push_back("telem3"); |
| 130 |
listOfTelemNodes.push_back("telem2"); |
| 131 |
listOfTelemNodes.push_back("telem1"); |
| 132 |
listOfTelemNodes.push_back("telem4"); |
| 133 |
listOfTelemNodes.push_back("telem5"); |
| 134 |
} |
| 135 |
return ZE_RESULT_SUCCESS; |
| 136 |
} |
| 137 |
return ZE_RESULT_ERROR_NOT_AVAILABLE; |
| 138 |
} |
| 139 |
|
| 140 |
std::string telemetryDeviceEntryForSubdevice0; |
| 141 |
std::string telemetryDeviceEntryForSubdevice1; |
| 142 |
std::string baseTelemSysFSNodeForSubdevice0; |
| 143 |
std::string baseTelemSysFSNodeForSubdevice1; |
| 144 |
}; |
| 145 |
|
| 146 |
class PublicPlatformMonitoringTech : public L0::PlatformMonitoringTech { |
| 147 |
public: |
| 148 |
PublicPlatformMonitoringTech(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} |
| 149 |
using PlatformMonitoringTech::doInitPmtObject; |
| 150 |
using PlatformMonitoringTech::init; |
| 151 |
using PlatformMonitoringTech::keyOffsetMap; |
| 152 |
using PlatformMonitoringTech::preadFunction; |
| 153 |
using PlatformMonitoringTech::telemetryDeviceEntry; |
| 154 |
}; |
| 155 |
|
| 156 |
} // namespace ult |
| 157 |
} // namespace L0 |