diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp index 54c70c3f56..986a6d55db 100644 --- a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp +++ b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp @@ -62,6 +62,14 @@ ze_result_t PlatformMonitoringTech::enumerateRootTelemIndex(FsAccess *pFsAccess, return result; } + // 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" + } + } + // Exmaple: For below directory // # /sys/class/intel_pmt$ ls // telem1 telem2 telem3 @@ -73,12 +81,13 @@ ze_result_t PlatformMonitoringTech::enumerateRootTelemIndex(FsAccess *pFsAccess, if (result != ZE_RESULT_SUCCESS) { return result; } + // Check if Telemetry node(say telem1) and rootPciPathOfGpuDevice share same PCI Root port + // Example: If + // rootPciPathOfGpuDevice = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; + // 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"; + // Thus As realPathOfTelemNode consists of rootPciPathOfGpuDevice, hence both telemNode and GPU device share same PCI Root. if (realPathOfTelemNode.compare(0, rootPciPathOfGpuDevice.size(), rootPciPathOfGpuDevice) == 0) { - // Example: If - // rootPciPathOfGpuDevice = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; - // 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"; - // Thus As realPathOfTelemNode consists of rootPciPathOfGpuDevice, hence both telemNode and GPU device share same PCI Root. auto indexString = telemNode.substr(telem.size(), telemNode.size()); rootDeviceTelemNodeIndex = stoi(indexString); // if telemNode is telemN, then rootDeviceTelemNodeIndex = N return ZE_RESULT_SUCCESS; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h index 5d6b3387c5..518542a979 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/mock_pmt.h @@ -92,9 +92,11 @@ struct Mock : public PmtFsAccess { ze_result_t listDirectorySuccess(const std::string directory, std::vector &listOfTelemNodes) { if (directory.compare(baseTelemSysFS) == 0) { - listOfTelemNodes.push_back("telem1"); - listOfTelemNodes.push_back("telem2"); + listOfTelemNodes.push_back("crashlog2"); + listOfTelemNodes.push_back("crashlog1"); listOfTelemNodes.push_back("telem3"); + listOfTelemNodes.push_back("telem2"); + listOfTelemNodes.push_back("telem1"); listOfTelemNodes.push_back("telem4"); listOfTelemNodes.push_back("telem5"); return ZE_RESULT_SUCCESS; @@ -102,6 +104,15 @@ struct Mock : public PmtFsAccess { return ZE_RESULT_ERROR_NOT_AVAILABLE; } + ze_result_t listDirectoryNoTelemNode(const std::string directory, std::vector &listOfTelemNodes) { + if (directory.compare(baseTelemSysFS) == 0) { + listOfTelemNodes.push_back("crashlog2"); + listOfTelemNodes.push_back("crashlog1"); + return ZE_RESULT_SUCCESS; + } + return ZE_RESULT_ERROR_NOT_AVAILABLE; + } + MOCK_METHOD(ze_result_t, read, (const std::string file, std::string &val), (override)); MOCK_METHOD(ze_result_t, read, (const std::string file, uint64_t &val), (override)); MOCK_METHOD(ze_result_t, getRealPath, (const std::string path, std::string &buf), (override)); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp index 5f47f3263c..ca3bd43d66 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp @@ -74,6 +74,12 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenWhenenumerateRootTelemIndexThenCheckForErr EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), rootPciPathOfGpuDeviceInPmt)); } +TEST_F(ZesPmtFixtureMultiDevice, GivenTelemDirectoryContainNowTelemEntryWhenenumerateRootTelemIndexThenCheckForError) { + ON_CALL(*pTestFsAccess.get(), listDirectory(_, _)) + .WillByDefault(::testing::Invoke(pTestFsAccess.get(), &Mock::listDirectoryNoTelemNode)); + EXPECT_EQ(ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE, PlatformMonitoringTech::enumerateRootTelemIndex(pTestFsAccess.get(), rootPciPathOfGpuDeviceInPmt)); +} + TEST_F(ZesPmtFixtureMultiDevice, GivenValidDeviceHandlesWhenCreatingPMTHandlesThenCheckForErrorThatCouldHappenDuringGUIDRead) { EXPECT_CALL(*pTestFsAccess.get(), read(_, Matcher(_))) .WillOnce(Return(ZE_RESULT_ERROR_NOT_AVAILABLE));