mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Read max frequency using pci path
Related-To: NEO-4359 Change-Id: I2dc106cc2d7bc9087fb3925051969fa2a245e6f5 Signed-off-by: Jablonski, Mateusz <mateusz.jablonski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
39ece6481b
commit
719b22ee11
@ -15,7 +15,7 @@ const char *frontEndDllName = FCL_LIBRARY_NAME;
|
||||
const char *igcDllName = IGC_LIBRARY_NAME;
|
||||
const char *libvaDllName = "libva.so.2";
|
||||
|
||||
const char *sysFsPciPath = "/sys/bus/pci/devices/";
|
||||
const char *sysFsPciPathPrefix = "/sys/bus/pci/devices/0000:";
|
||||
const char *pciDevicesDirectory = "/dev/dri/by-path";
|
||||
const char *tbxLibName = "libtbxAccess.so";
|
||||
|
||||
|
@ -104,6 +104,31 @@ TEST(DrmTest, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) {
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenSelectedExistingDeviceWhenOpenDirSuccedsThenHwDeviceIdsHaveProperPciPaths) {
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, false);
|
||||
VariableBackup<decltype(entryIndex)> backupEntryIndex(&entryIndex, 0u);
|
||||
openFull = openWithCounter;
|
||||
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
|
||||
entryIndex = 0;
|
||||
openCounter = 1;
|
||||
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
||||
EXPECT_EQ(1u, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("test1", hwDeviceIds[0]->getPciPath());
|
||||
|
||||
entryIndex = 0;
|
||||
openCounter = 2;
|
||||
hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
||||
EXPECT_EQ(2u, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("test1", hwDeviceIds[0]->getPciPath());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
||||
EXPECT_STREQ("test2", hwDeviceIds[1]->getPciPath());
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenSelectedExistingDeviceWhenOpenDirFailsThenRetryOpeningRenderDevices) {
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, true);
|
||||
@ -115,13 +140,16 @@ TEST(DrmTest, GivenSelectedExistingDeviceWhenOpenDirFailsThenRetryOpeningRenderD
|
||||
EXPECT_STREQ("/dev/dri/renderD128", lastOpenedPath.c_str());
|
||||
EXPECT_EQ(1u, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("00:02.0", hwDeviceIds[0]->getPciPath());
|
||||
|
||||
openCounter = 2;
|
||||
hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
||||
EXPECT_STREQ("/dev/dri/renderD129", lastOpenedPath.c_str());
|
||||
EXPECT_EQ(2u, hwDeviceIds.size());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
||||
EXPECT_STREQ("00:02.0", hwDeviceIds[0]->getPciPath());
|
||||
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
||||
EXPECT_STREQ("00:02.0", hwDeviceIds[1]->getPciPath());
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) {
|
||||
|
@ -48,3 +48,4 @@ extern char providedDrmVersion[5];
|
||||
extern int ioctlSeq[8];
|
||||
extern size_t ioctlCnt;
|
||||
extern bool failOnOpenDir;
|
||||
extern uint32_t entryIndex;
|
||||
|
@ -24,7 +24,7 @@ using namespace NEO;
|
||||
TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFromMultipleThreadsThenSingleBoIsReused) {
|
||||
class MockDrm : public Drm {
|
||||
public:
|
||||
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd), rootDeviceEnvironment) {}
|
||||
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd, ""), rootDeviceEnvironment) {}
|
||||
|
||||
int ioctl(unsigned long request, void *arg) override {
|
||||
if (request == DRM_IOCTL_PRIME_FD_TO_HANDLE) {
|
||||
@ -71,7 +71,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro
|
||||
TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThenPrimeFdToHandleDoesNotRaceWithClose) {
|
||||
class MockDrm : public Drm {
|
||||
public:
|
||||
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd), rootDeviceEnvironment) {
|
||||
MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd, ""), rootDeviceEnvironment) {
|
||||
primeFdHandle = 1;
|
||||
closeHandle = 1;
|
||||
}
|
||||
|
@ -25,32 +25,31 @@
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#define RENDER_DEVICE_NAME_MATCHER ::testing::StrEq("/dev/dri/renderD128")
|
||||
|
||||
using NEO::constructPlatform;
|
||||
using NEO::Drm;
|
||||
using NEO::HwDeviceId;
|
||||
using NEO::RootDeviceEnvironment;
|
||||
|
||||
static const int mockFd = 33;
|
||||
static const char *mockPciPath = "";
|
||||
|
||||
class DrmMockImpl : public Drm {
|
||||
public:
|
||||
DrmMockImpl(int fd) : Drm(std::make_unique<HwDeviceId>(fd), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]){};
|
||||
DrmMockImpl(int fd) : Drm(std::make_unique<HwDeviceId>(fd, mockPciPath), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]){};
|
||||
MOCK_METHOD2(ioctl, int(unsigned long request, void *arg));
|
||||
};
|
||||
|
||||
class DrmMockSuccess : public Drm {
|
||||
public:
|
||||
DrmMockSuccess() : DrmMockSuccess(*constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
|
||||
DrmMockSuccess(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(mockFd), rootDeviceEnvironment) {}
|
||||
DrmMockSuccess(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(mockFd, mockPciPath), rootDeviceEnvironment) {}
|
||||
|
||||
int ioctl(unsigned long request, void *arg) override { return 0; };
|
||||
};
|
||||
|
||||
class DrmMockFail : public Drm {
|
||||
public:
|
||||
DrmMockFail() : Drm(std::make_unique<HwDeviceId>(mockFd), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
|
||||
DrmMockFail() : Drm(std::make_unique<HwDeviceId>(mockFd, mockPciPath), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
|
||||
|
||||
int ioctl(unsigned long request, void *arg) override { return -1; };
|
||||
};
|
||||
@ -335,7 +334,7 @@ class DrmMockCustom : public Drm {
|
||||
ioctl_res_ext = &NONE;
|
||||
}
|
||||
|
||||
DrmMockCustom() : Drm(std::make_unique<HwDeviceId>(mockFd), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
|
||||
DrmMockCustom() : Drm(std::make_unique<HwDeviceId>(mockFd, mockPciPath), *constructPlatform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
|
||||
reset();
|
||||
ioctl_expected.contextCreate = static_cast<int>(NEO::HwHelper::get(NEO::defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*NEO::defaultHwInfo).size());
|
||||
ioctl_expected.contextDestroy = ioctl_expected.contextCreate.load();
|
||||
|
@ -37,7 +37,7 @@ class DrmMockForWorker : public Drm {
|
||||
std::atomic<int> gem_close_cnt;
|
||||
std::atomic<int> gem_close_expected;
|
||||
std::atomic<std::thread::id> ioctl_caller_thread_id;
|
||||
DrmMockForWorker() : Drm(std::make_unique<HwDeviceId>(33), *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
|
||||
DrmMockForWorker() : Drm(std::make_unique<HwDeviceId>(mockFd, mockPciPath), *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {
|
||||
}
|
||||
int ioctl(unsigned long request, void *arg) override {
|
||||
if (_IOC_TYPE(request) == DRM_IOCTL_BASE) {
|
||||
|
@ -34,24 +34,13 @@ class DrmMock : public Drm {
|
||||
using Drm::query;
|
||||
using Drm::sliceCountChangeSupported;
|
||||
|
||||
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(mockFd), rootDeviceEnvironment) {
|
||||
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(mockFd, ""), rootDeviceEnvironment) {
|
||||
sliceCountChangeSupported = true;
|
||||
}
|
||||
DrmMock() : DrmMock(*platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0]) {}
|
||||
|
||||
~DrmMock() override {
|
||||
if (sysFsDefaultGpuPathToRestore != nullptr) {
|
||||
sysFsDefaultGpuPath = sysFsDefaultGpuPathToRestore;
|
||||
}
|
||||
}
|
||||
|
||||
int ioctl(unsigned long request, void *arg) override;
|
||||
|
||||
void setSysFsDefaultGpuPath(const char *path) {
|
||||
sysFsDefaultGpuPathToRestore = sysFsDefaultGpuPath;
|
||||
sysFsDefaultGpuPath = path;
|
||||
}
|
||||
|
||||
void writeConfigFile(const char *name, int deviceID) {
|
||||
std::ofstream tempfile(name, std::ios::binary);
|
||||
if (tempfile.is_open()) {
|
||||
@ -71,7 +60,11 @@ class DrmMock : public Drm {
|
||||
}
|
||||
|
||||
void setFileDescriptor(int fd) {
|
||||
hwDeviceId = std::make_unique<HwDeviceId>(fd);
|
||||
hwDeviceId = std::make_unique<HwDeviceId>(fd, "");
|
||||
}
|
||||
|
||||
void setPciPath(const char *pciPath) {
|
||||
hwDeviceId = std::make_unique<HwDeviceId>(getFileDescriptor(), pciPath);
|
||||
}
|
||||
|
||||
void setDeviceID(int deviceId) { this->deviceId = deviceId; }
|
||||
@ -139,7 +132,4 @@ class DrmMock : public Drm {
|
||||
uint64_t storedParamSseu = ULONG_MAX;
|
||||
|
||||
virtual int handleRemainingRequests(unsigned long request, void *arg) { return -1; }
|
||||
|
||||
private:
|
||||
const char *sysFsDefaultGpuPathToRestore = nullptr;
|
||||
};
|
||||
|
@ -32,71 +32,34 @@ TEST(DrmTest, GetDeviceID) {
|
||||
delete pDrm;
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenConfigFileWithWrongDeviceIDWhenFrequencyIsQueriedThenReturnZero) {
|
||||
DrmMock *pDrm = new DrmMock;
|
||||
EXPECT_NE(nullptr, pDrm);
|
||||
|
||||
pDrm->StoredDeviceID = 0x4321;
|
||||
int maxFrequency = 0;
|
||||
int ret = pDrm->getMaxGpuFrequency(maxFrequency);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
EXPECT_EQ(0, maxFrequency);
|
||||
|
||||
delete pDrm;
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenConfigFileWithWrongDeviceIDFailIoctlWhenFrequencyIsQueriedThenReturnZero) {
|
||||
DrmMock *pDrm = new DrmMock;
|
||||
EXPECT_NE(nullptr, pDrm);
|
||||
|
||||
pDrm->StoredDeviceID = 0x4321;
|
||||
pDrm->StoredRetValForDeviceID = -1;
|
||||
int maxFrequency = 0;
|
||||
int ret = pDrm->getMaxGpuFrequency(maxFrequency);
|
||||
EXPECT_EQ(-1, ret);
|
||||
|
||||
EXPECT_EQ(0, maxFrequency);
|
||||
|
||||
delete pDrm;
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenValidConfigFileWhenFrequencyIsQueriedThenValidValueIsReturned) {
|
||||
|
||||
int expectedMaxFrequency = 1000;
|
||||
|
||||
DrmMock *pDrm = new DrmMock;
|
||||
EXPECT_NE(nullptr, pDrm);
|
||||
DrmMock drm{};
|
||||
|
||||
pDrm->StoredDeviceID = 0x1234;
|
||||
std::string gtMaxFreqFile = "test_files/linux/devices/device/drm/card1/gt_max_freq_mhz";
|
||||
|
||||
std::string gpuFile = "test_files/devices/config";
|
||||
std::string gtMaxFreqFile = "test_files/devices/drm/card0/gt_max_freq_mhz";
|
||||
|
||||
EXPECT_TRUE(fileExists(gpuFile));
|
||||
EXPECT_TRUE(fileExists(gtMaxFreqFile));
|
||||
drm.setPciPath("device");
|
||||
|
||||
int maxFrequency = 0;
|
||||
int ret = pDrm->getMaxGpuFrequency(maxFrequency);
|
||||
int ret = drm.getMaxGpuFrequency(maxFrequency);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
EXPECT_EQ(expectedMaxFrequency, maxFrequency);
|
||||
delete pDrm;
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenNoConfigFileWhenFrequencyIsQueriedThenReturnZero) {
|
||||
DrmMock *pDrm = new DrmMock;
|
||||
EXPECT_NE(nullptr, pDrm);
|
||||
DrmMock drm{};
|
||||
|
||||
pDrm->StoredDeviceID = 0x1234;
|
||||
// change directory
|
||||
pDrm->setSysFsDefaultGpuPath("./");
|
||||
int maxFrequency = 0;
|
||||
int ret = pDrm->getMaxGpuFrequency(maxFrequency);
|
||||
|
||||
drm.setPciPath("invalidPci");
|
||||
int ret = drm.getMaxGpuFrequency(maxFrequency);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
EXPECT_EQ(0, maxFrequency);
|
||||
delete pDrm;
|
||||
}
|
||||
|
||||
TEST(DrmTest, GetRevisionID) {
|
||||
@ -399,7 +362,7 @@ TEST(HwDeviceId, whenHwDeviceIdIsDestroyedThenFileDescriptorIsClosed) {
|
||||
SysCalls::closeFuncCalled = 0;
|
||||
int fileDescriptor = 0x1234;
|
||||
{
|
||||
HwDeviceId hwDeviceId(fileDescriptor);
|
||||
HwDeviceId hwDeviceId(fileDescriptor, "");
|
||||
}
|
||||
EXPECT_EQ(1u, SysCalls::closeFuncCalled);
|
||||
EXPECT_EQ(fileDescriptor, SysCalls::closeFuncArgPassed);
|
||||
|
@ -25,7 +25,7 @@ const char *gmmInitFuncName = "initMockGmm";
|
||||
const char *gmmDestroyFuncName = "destroyMockGmm";
|
||||
const char *metricsLibraryDllName = "";
|
||||
#endif
|
||||
const char *sysFsPciPath = "./test_files";
|
||||
const char *sysFsPciPathPrefix = "./test_files/linux/devices/";
|
||||
const char *pciDevicesDirectory = "./test_files/linux/by-path";
|
||||
} // namespace Os
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
<EFBFBD><EFBFBD>4<12><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
Reference in New Issue
Block a user