Skip to content

Commit 35607e7

Browse files
sysman: add warm reset capability to diagnostics.
Relates-to:LOCI-2507 Signed-off-by: Vilvaraj, T J Vivek <t.j.vivek.vilvaraj@intel.com>
1 parent e857979 commit 35607e7

File tree

3 files changed

+139
-1
lines changed

3 files changed

+139
-1
lines changed

level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "shared/source/helpers/string.h"
1111

1212
namespace L0 {
13+
const std::string LinuxDiagnosticsImp::deviceDir("device");
1314

1415
void OsDiagnostics::getSupportedDiagTests(std::vector<std::string> &supportedDiagTests, OsSysman *pOsSysman) {
1516
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
@@ -20,7 +21,8 @@ void OsDiagnostics::getSupportedDiagTests(std::vector<std::string> &supportedDia
2021
}
2122

2223
void LinuxDiagnosticsImp::osGetDiagProperties(zes_diag_properties_t *pProperties) {
23-
pProperties->onSubdevice = false;
24+
pProperties->onSubdevice = isSubdevice;
25+
pProperties->subdeviceId = subdeviceId;
2426
pProperties->haveTests = 0; // osGetDiagTests is Unsupported
2527
strncpy_s(pProperties->name, ZES_STRING_PROPERTY_SIZE, osDiagType.c_str(), osDiagType.size());
2628
return;
@@ -38,6 +40,8 @@ LinuxDiagnosticsImp::LinuxDiagnosticsImp(OsSysman *pOsSysman, const std::string
3840
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
3941
pFwInterface = pLinuxSysmanImp->getFwUtilInterface();
4042
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
43+
pFsAccess = &pLinuxSysmanImp->getFsAccess();
44+
pProcfsAccess = &pLinuxSysmanImp->getProcfsAccess();
4145
}
4246

4347
std::unique_ptr<OsDiagnostics> OsDiagnostics::create(OsSysman *pOsSysman, const std::string &diagTests, ze_bool_t onSubdevice, uint32_t subdeviceId) {

level_zero/tools/source/sysman/diagnostics/linux/os_diagnostics_imp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class LinuxDiagnosticsImp : public OsDiagnostics, NEO::NonCopyableOrMovableClass
2020
ze_result_t osGetDiagTests(uint32_t *pCount, zes_diag_test_t *pTests) override;
2121
ze_result_t osRunDiagTests(uint32_t start, uint32_t end, zes_diag_result_t *pResult) override;
2222
ze_result_t osRunDiagTestsinFW(zes_diag_result_t *pResult);
23+
ze_result_t osWarmReset();
2324
LinuxDiagnosticsImp() = default;
2425
LinuxDiagnosticsImp(OsSysman *pOsSysman, const std::string &diagTests, ze_bool_t onSubdevice, uint32_t subdeviceId);
2526
~LinuxDiagnosticsImp() override = default;
@@ -28,12 +29,19 @@ class LinuxDiagnosticsImp : public OsDiagnostics, NEO::NonCopyableOrMovableClass
2829
protected:
2930
FirmwareUtil *pFwInterface = nullptr;
3031
SysfsAccess *pSysfsAccess = nullptr;
32+
FsAccess *pFsAccess = nullptr;
33+
ProcfsAccess *pProcfsAccess = nullptr;
34+
decltype(&NEO::SysCalls::open) openFunction = NEO::SysCalls::open;
35+
decltype(&NEO::SysCalls::close) closeFunction = NEO::SysCalls::close;
36+
decltype(&NEO::SysCalls::pread) preadFunction = NEO::SysCalls::pread;
37+
decltype(&NEO::SysCalls::pwrite) pwriteFunction = NEO::SysCalls::pwrite;
3138

3239
private:
3340
static const std::string quiescentGpuFile;
3441
bool isSubdevice = false;
3542
uint32_t subdeviceId = 0;
3643
static const std::string invalidateLmemFile;
44+
static const std::string deviceDir;
3745
};
3846

3947
} // namespace L0

level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/mock_zes_sysman_diagnostics.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ constexpr uint32_t mockDiagHandleCount = 2;
1717
const std::string mockQuiescentGpuFile("quiesce_gpu");
1818
const std::string mockinvalidateLmemFile("invalidate_lmem_mmaps");
1919
const std::vector<std::string> mockSupportedDiagTypes = {"MOCKSUITE1", "MOCKSUITE2"};
20+
const std::string deviceDirDiag("device");
21+
const std::string mockdeviceDirDiag("/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/0000:8c:00.0");
22+
const std::string mockRemove("remove");
23+
const std::string mockRescan("rescan");
24+
const std::string mockRealPathConfig("/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:01.0/config");
25+
const std::string mockDeviceName("/MOCK_DEVICE_NAME");
26+
2027
class DiagnosticsInterface : public FirmwareUtil {};
2128

2229
template <>
@@ -56,6 +63,14 @@ struct Mock<DiagnosticsInterface> : public FirmwareUtil {
5663
class DiagSysfsAccess : public SysfsAccess {};
5764
template <>
5865
struct Mock<DiagSysfsAccess> : public DiagSysfsAccess {
66+
ze_result_t getRealPathVal(const std::string file, std::string &val) {
67+
if (file.compare(deviceDirDiag) == 0) {
68+
val = mockdeviceDirDiag;
69+
} else {
70+
return ZE_RESULT_ERROR_NOT_AVAILABLE;
71+
}
72+
return ZE_RESULT_SUCCESS;
73+
}
5974

6075
ze_result_t mockwrite(const std::string file, const int val) {
6176
if (std::string::npos != file.find(mockQuiescentGpuFile)) {
@@ -70,14 +85,125 @@ struct Mock<DiagSysfsAccess> : public DiagSysfsAccess {
7085
ze_result_t mockwriteFails(const std::string file, const int val) {
7186
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
7287
}
88+
89+
bool mockIsMyDeviceFile(const std::string dev) {
90+
if (dev.compare(mockDeviceName) == 0) {
91+
return true;
92+
}
93+
return false;
94+
}
95+
7396
Mock<DiagSysfsAccess>() = default;
7497

7598
MOCK_METHOD(ze_result_t, write, (const std::string file, const int val), (override));
99+
MOCK_METHOD(ze_result_t, getRealPath, (const std::string path, std::string &val), (override));
100+
MOCK_METHOD(bool, isMyDeviceFile, (const std::string dev), (override));
101+
};
102+
103+
class DiagFsAccess : public FsAccess {};
104+
template <>
105+
struct Mock<DiagFsAccess> : public DiagFsAccess {
106+
ze_result_t mockFsWrite(const std::string file, std::string val) {
107+
if (std::string::npos != file.find(mockRemove)) {
108+
return ZE_RESULT_SUCCESS;
109+
} else if (std::string::npos != file.find(mockRescan)) {
110+
return ZE_RESULT_SUCCESS;
111+
} else {
112+
return ZE_RESULT_ERROR_NOT_AVAILABLE;
113+
}
114+
}
115+
Mock<DiagFsAccess>() = default;
116+
117+
MOCK_METHOD(ze_result_t, write, (const std::string file, const std::string val), (override));
118+
};
119+
120+
class DiagProcfsAccess : public ProcfsAccess {};
121+
122+
template <>
123+
struct Mock<DiagProcfsAccess> : public DiagProcfsAccess {
124+
125+
const ::pid_t extraPid = 4;
126+
const int extraFd = 5;
127+
std::vector<::pid_t> pidList = {1, 2, 3};
128+
std::vector<int> fdList = {0, 1, 2};
129+
::pid_t ourDevicePid = 0;
130+
int ourDeviceFd = 0;
131+
132+
ze_result_t mockProcessListDeviceUnused(std::vector<::pid_t> &list) {
133+
list = pidList;
134+
return ZE_RESULT_SUCCESS;
135+
}
136+
137+
ze_result_t mockProcessListDeviceInUse(std::vector<::pid_t> &list) {
138+
list = pidList;
139+
if (ourDevicePid) {
140+
list.push_back(ourDevicePid);
141+
}
142+
return ZE_RESULT_SUCCESS;
143+
}
144+
145+
::pid_t getMockMyProcessId() {
146+
return ::getpid();
147+
}
148+
149+
ze_result_t getMockFileDescriptors(const ::pid_t pid, std::vector<int> &list) {
150+
// Give every process 3 file descriptors
151+
// Except the device that MOCK has the device open. Give it one extra.
152+
list.clear();
153+
list = fdList;
154+
if (ourDevicePid == pid) {
155+
list.push_back(ourDeviceFd);
156+
}
157+
return ZE_RESULT_SUCCESS;
158+
}
159+
160+
ze_result_t getMockFileDescriptorsFailure(const ::pid_t pid, std::vector<int> &list) {
161+
//return failure to verify the error condition check
162+
list.clear();
163+
return ZE_RESULT_ERROR_UNKNOWN;
164+
}
165+
166+
ze_result_t getMockFileName(const ::pid_t pid, const int fd, std::string &val) {
167+
if (pid == ourDevicePid && fd == ourDeviceFd) {
168+
val = mockDeviceName;
169+
} else {
170+
// return fake filenames for other file descriptors
171+
val = std::string("/FILENAME") + std::to_string(fd);
172+
}
173+
return ZE_RESULT_SUCCESS;
174+
}
175+
176+
bool mockIsAlive(const ::pid_t pid) {
177+
if (pid == ourDevicePid) {
178+
return true;
179+
}
180+
return false;
181+
}
182+
183+
void mockKill(const ::pid_t pid) {
184+
ourDevicePid = 0;
185+
}
186+
187+
Mock<DiagProcfsAccess>() = default;
188+
189+
MOCK_METHOD(ze_result_t, listProcesses, (std::vector<::pid_t> & list), (override));
190+
MOCK_METHOD(::pid_t, myProcessId, (), (override));
191+
MOCK_METHOD(ze_result_t, getFileDescriptors, (const ::pid_t pid, std::vector<int> &list), (override));
192+
MOCK_METHOD(ze_result_t, getFileName, (const ::pid_t pid, const int fd, std::string &val), (override));
193+
MOCK_METHOD(bool, isAlive, (const ::pid_t pid), (override));
194+
MOCK_METHOD(void, kill, (const ::pid_t pid), (override));
76195
};
77196

78197
class PublicLinuxDiagnosticsImp : public L0::LinuxDiagnosticsImp {
79198
public:
199+
using LinuxDiagnosticsImp::closeFunction;
200+
using LinuxDiagnosticsImp::openFunction;
201+
using LinuxDiagnosticsImp::pFsAccess;
80202
using LinuxDiagnosticsImp::pFwInterface;
203+
using LinuxDiagnosticsImp::pProcfsAccess;
204+
using LinuxDiagnosticsImp::preadFunction;
205+
using LinuxDiagnosticsImp::pSysfsAccess;
206+
using LinuxDiagnosticsImp::pwriteFunction;
81207
};
82208
} // namespace ult
83209
} // namespace L0

0 commit comments

Comments
 (0)