Fix error returning to user from zetSysmanProcessesGetState API

If after reading clients directory, while actually trying to
access the individual clients file, we receive a error
ZET_RESULT_ERROR_NOT_AVAILABLE, then it means that this process/client
might be killed/removed. Hence dont return error to user.
Instead simply skip that client's traversal further and move on
to next available client.

Change-Id: If86610a89d7b2421fd85560e5a223391b76d78a0
Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2020-06-12 19:55:41 +05:30
committed by sys_ocldev
parent 985bfa158a
commit 1618a25d71
4 changed files with 49 additions and 28 deletions

View File

@@ -22,7 +22,7 @@ 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_UNKNOWN;
return ZE_RESULT_ERROR_NOT_AVAILABLE;
} else {
return ZE_RESULT_ERROR_UNKNOWN;
}
@@ -172,7 +172,7 @@ ze_result_t FsAccess::listDirectory(const std::string path, std::vector<std::str
list.clear();
::DIR *procDir = ::opendir(path.c_str());
if (!procDir) {
return ZE_RESULT_ERROR_UNKNOWN;
return getResult(errno);
}
struct ::dirent *ent;
while (NULL != (ent = ::readdir(procDir))) {
@@ -184,6 +184,11 @@ ze_result_t FsAccess::listDirectory(const std::string path, std::vector<std::str
list.push_back(std::string(ent->d_name));
}
::closedir(procDir);
// Check if in above while loop, readdir encountered any error.
if (errno != 0) {
list.clear();
return getResult(errno);
}
return ZE_RESULT_SUCCESS;
}

View File

@@ -244,7 +244,11 @@ ze_result_t LinuxSysmanDeviceImp::scanProcessesState(std::vector<zet_process_sta
uint64_t pid;
result = pSysfsAccess->read(realClientPidPath, pid);
if (ZE_RESULT_SUCCESS != result) {
return result;
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
continue;
} else {
return result;
}
}
// Traverse the clients/<clientId>/busy directory to get accelerator engines used by process
@@ -252,7 +256,11 @@ ze_result_t LinuxSysmanDeviceImp::scanProcessesState(std::vector<zet_process_sta
std::string busyDirForEngines = clientsDir + "/" + clientId + "/" + "busy";
result = pSysfsAccess->scanDirEntries(busyDirForEngines, engineNums);
if (ZE_RESULT_SUCCESS != result) {
return result;
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
continue;
} else {
return result;
}
}
int64_t engineType = 0;
// Scan all engine files present in /sys/class/drm/card0/clients/<ClientId>/busy and check
@@ -262,7 +270,11 @@ ze_result_t LinuxSysmanDeviceImp::scanProcessesState(std::vector<zet_process_sta
std::string engine = busyDirForEngines + "/" + engineNum;
result = pSysfsAccess->read(engine, timeSpent);
if (ZE_RESULT_SUCCESS != result) {
return result;
if (ZE_RESULT_ERROR_NOT_AVAILABLE == result) {
continue;
} else {
return result;
}
}
if (timeSpent > 0) {
int i915EnginNumber = stoi(engineNum);

View File

@@ -12,11 +12,6 @@
#include "sysman/linux/fs_access.h"
#include "sysman/sysman.h"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
#endif
using ::testing::_;
namespace L0 {
@@ -50,12 +45,12 @@ struct Mock<SysmanDeviceSysfsAccess> : public SysfsAccess {
ze_result_t getValString(const std::string file, std::string &val) {
if (file.compare(subsystemVendorFile) == 0) {
val = "0x8086";
}
if (file.compare(deviceFile) == 0) {
} else if (file.compare(deviceFile) == 0) {
val = "0x3ea5";
}
if (file.compare(vendorFile) == 0) {
} else if (file.compare(vendorFile) == 0) {
val = "0x8086";
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
@@ -63,12 +58,18 @@ struct Mock<SysmanDeviceSysfsAccess> : public SysfsAccess {
ze_result_t getValUnsignedLong(const std::string file, uint64_t &val) {
if ((file.compare("clients/4/pid") == 0) || (file.compare("clients/5/pid") == 0)) {
val = pid1;
}
if (file.compare("clients/6/pid") == 0) {
} else if (file.compare("clients/6/pid") == 0) {
val = pid2;
}
if ((file.compare("clients/4/busy/0") == 0) || (file.compare("clients/4/busy/3") == 0) || (file.compare("clients/5/busy/1") == 0) || (file.compare("clients/6/busy/0") == 0)) {
} else if ((file.compare("clients/4/busy/0") == 0) || (file.compare("clients/4/busy/3") == 0) ||
(file.compare("clients/5/busy/1") == 0) || (file.compare("clients/6/busy/0") == 0)) {
val = engineTimeSpent;
} else if ((file.compare("clients/4/busy/1") == 0) || (file.compare("clients/4/busy/2") == 0) ||
(file.compare("clients/5/busy/0") == 0) || (file.compare("clients/5/busy/2") == 0) ||
(file.compare("clients/5/busy/3") == 0) || (file.compare("clients/6/busy/1") == 0) ||
(file.compare("clients/6/busy/2") == 0) || (file.compare("clients/6/busy/3") == 0)) {
val = 0;
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
@@ -78,12 +79,14 @@ struct Mock<SysmanDeviceSysfsAccess> : public SysfsAccess {
list.push_back(clientId1);
list.push_back(clientId2);
list.push_back(clientId3);
}
if ((path.compare("clients/4/busy") == 0) || (path.compare("clients/5/busy") == 0) || (path.compare("clients/6/busy") == 0)) {
} else if ((path.compare("clients/4/busy") == 0) || (path.compare("clients/5/busy") == 0) ||
(path.compare("clients/6/busy") == 0)) {
list.push_back(engine0);
list.push_back(engine1);
list.push_back(engine2);
list.push_back(engine3);
} else {
return ZE_RESULT_ERROR_NOT_AVAILABLE;
}
return ZE_RESULT_SUCCESS;
}
@@ -91,9 +94,9 @@ struct Mock<SysmanDeviceSysfsAccess> : public SysfsAccess {
Mock() = default;
~Mock() override = default;
MOCK_METHOD2(read, ze_result_t(const std::string file, std::string &val));
MOCK_METHOD2(read, ze_result_t(const std::string file, uint64_t &val));
MOCK_METHOD2(scanDirEntries, ze_result_t(const std::string path, std::vector<std::string> &list));
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, scanDirEntries, (const std::string path, std::vector<std::string> &list), (override));
};
class PublicLinuxSysmanDeviceImp : public L0::LinuxSysmanDeviceImp {
@@ -103,8 +106,4 @@ class PublicLinuxSysmanDeviceImp : public L0::LinuxSysmanDeviceImp {
};
} // namespace ult
} // namespace L0
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
} // namespace L0

View File

@@ -109,5 +109,10 @@ TEST_F(SysmanSysmanDeviceFixture, GivenValidSysmanHandleWhileRetrievingInformati
EXPECT_EQ(processes[1].memSize, memSize2);
}
TEST_F(SysmanSysmanDeviceFixture, GivenValidSysmanHandleWhileReadingNonExistingFileThenErrorIsReturned) {
std::vector<std::string> engineEntries;
EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pSysfsAccess->scanDirEntries("clients/7/busy", engineEntries));
}
} // namespace ult
} // namespace L0