Added DeviceId filtering under Linux

Change-Id: Ie4b91d139beb8f31d50737d829e9d8fe801dcfa1
Signed-off-by: Koska <andrzej.koska@intel.com>
Related-To: NEO-3239
This commit is contained in:
Andrzej Koska
2019-10-14 18:05:30 +02:00
committed by sys_ocldev
parent 68d152a3d9
commit 1f6dde3f02
5 changed files with 90 additions and 20 deletions

View File

@@ -23,6 +23,8 @@
namespace NEO {
bool (*Drm::pIsi915Version)(int fd) = Drm::isi915Version;
int (*Drm::pClose)(int fd) = ::close;
const DeviceDescriptor deviceDescriptorTable[] = {
#define DEVICE(devId, gt, gtType) {devId, &gt::hwInfo, &gt::setupHardwareInfo, gtType},
#include "devices.inl"
@@ -71,7 +73,7 @@ int Drm::getDeviceFd(const int devType) {
const char *pathPrefix;
unsigned int startNum;
const unsigned int maxDrmDevices = 64;
if (DebugManager.flags.ForceDeviceId.get() == "unk") {
switch (devType) {
case 0:
startNum = 128;
@@ -82,7 +84,6 @@ int Drm::getDeviceFd(const int devType) {
pathPrefix = "/dev/dri/card";
break;
}
for (unsigned int i = 0; i < maxDrmDevices; i++) {
snprintf(fullPath, PATH_MAX, "%s%u", pathPrefix, i + startNum);
int fd = ::open(fullPath, O_RDWR);
@@ -93,6 +94,19 @@ int Drm::getDeviceFd(const int devType) {
::close(fd);
}
}
} else {
const char *cardType[] = {"-render", "-card"};
for (auto param : cardType) {
snprintf(fullPath, PATH_MAX, "/dev/dri/by-path/pci-0000:%s%s", DebugManager.flags.ForceDeviceId.get().c_str(), param);
int fd = ::open(fullPath, O_RDWR);
if (fd >= 0) {
if (pIsi915Version(fd)) {
return fd;
}
pClose(fd);
}
}
}
return -1;
}

View File

@@ -83,6 +83,9 @@ class Drm {
MemoryInfo *getMemoryInfo() const {
return memoryInfo.get();
}
static bool (*pIsi915Version)(int fd);
static bool isi915Version(int fd);
static int (*pClose)(int fd);
protected:
int getQueueSliceCount(drm_i915_gem_context_param_sseu *sseu);
@@ -97,7 +100,6 @@ class Drm {
std::unique_ptr<EngineInfo> engineInfo;
std::unique_ptr<MemoryInfo> memoryInfo;
static bool isi915Version(int fd);
static int getDeviceFd(const int devType);
static int openDevice();
static Drm *create(int32_t deviceOrdinal);

View File

@@ -48,6 +48,55 @@ void initializeTestedDevice() {
}
}
int openRetVal = 0;
int testOpen(const char *fullPath, int, ...) {
return openRetVal;
};
TEST(DrmTest, GivenSelectedNotExistingDeviceWhenGetDeviceFdThenFail) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.ForceDeviceId.set("1234");
struct DrmTest : public NEO::Drm {
using NEO::Drm::getDeviceFd;
};
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
openFull = testOpen;
openRetVal = -1;
int fd = DrmTest::getDeviceFd(0);
EXPECT_EQ(fd, -1);
}
TEST(DrmTest, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.ForceDeviceId.set("1234");
struct DrmTest : public NEO::Drm {
using NEO::Drm::getDeviceFd;
};
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
openRetVal = 1023; // fakeFd
openFull = testOpen;
int fd = DrmTest::getDeviceFd(0);
EXPECT_NE(fd, -1);
}
TEST(DrmTest, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.ForceDeviceId.set("1234");
struct DrmTest : public NEO::Drm {
using NEO::Drm::getDeviceFd;
};
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
VariableBackup<decltype(Drm::pIsi915Version)> backupIsi915Version(&Drm::pIsi915Version);
VariableBackup<decltype(Drm::pClose)> backupClose(&Drm::pClose);
openFull = testOpen;
openRetVal = 1023;
Drm::pIsi915Version = [](int x) -> bool { return false; };
Drm::pClose = [](int x) -> int { return 0; };
int fd = DrmTest::getDeviceFd(0);
EXPECT_EQ(fd, -1);
}
TEST_F(DrmTests, getReturnsNull) {
auto drm = Drm::get(0);
EXPECT_EQ(drm, nullptr);

View File

@@ -11,6 +11,7 @@
#include <iostream>
int (*c_open)(const char *pathname, int flags, ...) = nullptr;
int (*openFull)(const char *pathname, int flags, ...) = nullptr;
int (*c_ioctl)(int fd, unsigned long int request, ...) = nullptr;
int fakeFd = 1023;
@@ -36,6 +37,9 @@ int ioctlSeq[8] = {0, 0, 0, 0, 0, 0, 0, 0};
size_t ioctlCnt = 0;
int open(const char *pathname, int flags, ...) {
if (openFull != nullptr) {
return openFull(pathname, flags);
}
if (c_open == nullptr) {
c_open = (int (*)(const char *, int, ...))dlsym(RTLD_NEXT, "open");
}

View File

@@ -24,6 +24,7 @@ int ioctl(int fd, unsigned long int request, ...) throw();
}
extern int (*c_open)(const char *pathname, int flags, ...);
extern int (*openFull)(const char *pathname, int flags, ...);
extern int (*c_ioctl)(int __fd, unsigned long int __request, ...);
extern int fakeFd;