mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
PCI driver fix for Discrete devices
Change-Id: I91e444c88b5e72463c7f181ece535da4150a2665 Signed-off-by: Vilvaraj, T J Vivek <t.j.vivek.vilvaraj@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
fb7082f0f8
commit
6224db771a
@@ -53,6 +53,39 @@ ze_result_t FsAccess::read(const std::string file, uint64_t &val) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t FsAccess::read(const std::string file, double &val) {
|
||||
// Read a single line from text file without trailing newline
|
||||
std::ifstream fs;
|
||||
|
||||
fs.open(file.c_str());
|
||||
if (fs.fail()) {
|
||||
return getResult(errno);
|
||||
}
|
||||
fs >> val;
|
||||
if (fs.fail()) {
|
||||
fs.close();
|
||||
return getResult(errno);
|
||||
}
|
||||
fs.close();
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t FsAccess::read(const std::string file, uint32_t &val) {
|
||||
// Read a single line from text file without trailing newline
|
||||
std::ifstream fs;
|
||||
|
||||
fs.open(file.c_str());
|
||||
if (fs.fail()) {
|
||||
return getResult(errno);
|
||||
}
|
||||
fs >> val;
|
||||
if (fs.fail()) {
|
||||
fs.close();
|
||||
return getResult(errno);
|
||||
}
|
||||
fs.close();
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
ze_result_t FsAccess::read(const std::string file, std::string &val) {
|
||||
// Read a single line from text file without trailing newline
|
||||
std::ifstream fs;
|
||||
@@ -364,6 +397,24 @@ ze_result_t SysfsAccess::read(const std::string file, int &val) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t SysfsAccess::read(const std::string file, uint32_t &val) {
|
||||
std::string str;
|
||||
ze_result_t result;
|
||||
|
||||
result = FsAccess::read(fullPath(file), str);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::istringstream stream(str);
|
||||
stream >> val;
|
||||
|
||||
if (stream.fail()) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t SysfsAccess::read(const std::string file, double &val) {
|
||||
std::string str;
|
||||
ze_result_t result;
|
||||
|
||||
@@ -35,6 +35,8 @@ class FsAccess {
|
||||
virtual ze_result_t read(const std::string file, uint64_t &val);
|
||||
virtual ze_result_t read(const std::string file, std::string &val);
|
||||
virtual ze_result_t read(const std::string file, std::vector<std::string> &val);
|
||||
virtual ze_result_t read(const std::string file, double &val);
|
||||
virtual ze_result_t read(const std::string file, uint32_t &val);
|
||||
|
||||
virtual ze_result_t write(const std::string file, const std::string val);
|
||||
|
||||
@@ -81,8 +83,9 @@ class SysfsAccess : private FsAccess {
|
||||
|
||||
ze_result_t read(const std::string file, std::string &val) override;
|
||||
MOCKABLE_VIRTUAL ze_result_t read(const std::string file, int &val);
|
||||
ze_result_t read(const std::string file, uint32_t &val) override;
|
||||
ze_result_t read(const std::string file, uint64_t &val) override;
|
||||
MOCKABLE_VIRTUAL ze_result_t read(const std::string file, double &val);
|
||||
ze_result_t read(const std::string file, double &val) override;
|
||||
ze_result_t read(const std::string file, std::vector<std::string> &val) override;
|
||||
|
||||
ze_result_t write(const std::string file, const std::string val) override;
|
||||
|
||||
@@ -22,6 +22,18 @@ constexpr uint8_t maxPciBars = 6;
|
||||
// Linux kernel would report 255 link width, as an indication of unknown.
|
||||
constexpr uint32_t unknownPcieLinkWidth = 255u;
|
||||
|
||||
std::string changeDirNLevelsUp(std::string realRootPath, uint8_t nLevel) {
|
||||
size_t loc;
|
||||
while (nLevel > 0) {
|
||||
loc = realRootPath.find_last_of('/');
|
||||
realRootPath = realRootPath.substr(0, loc);
|
||||
nLevel--;
|
||||
}
|
||||
return realRootPath;
|
||||
}
|
||||
void LinuxPciImp::setLmemSupport(bool val) {
|
||||
isLmemSupported = val;
|
||||
}
|
||||
ze_result_t LinuxPciImp::getPciBdf(std::string &bdf) {
|
||||
std::string bdfDir;
|
||||
ze_result_t result = pSysfsAccess->readSymLink(deviceDir, bdfDir);
|
||||
@@ -34,28 +46,65 @@ ze_result_t LinuxPciImp::getPciBdf(std::string &bdf) {
|
||||
}
|
||||
|
||||
ze_result_t LinuxPciImp::getMaxLinkSpeed(double &maxLinkSpeed) {
|
||||
double val;
|
||||
ze_result_t result = pSysfsAccess->read(maxLinkSpeedFile, val);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
maxLinkSpeed = 0;
|
||||
return result;
|
||||
ze_result_t result;
|
||||
if (isLmemSupported) {
|
||||
std::string rootPortPath;
|
||||
std::string realRootPath;
|
||||
result = pSysfsAccess->getRealPath(deviceDir, realRootPath);
|
||||
// we need to change the absolute path to two levels up to get actual
|
||||
// values of speed and width at the Discrete card's root port.
|
||||
// the root port is always at a fixed distance as defined in HW
|
||||
rootPortPath = changeDirNLevelsUp(realRootPath, 2);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
maxLinkSpeed = 0;
|
||||
return result;
|
||||
}
|
||||
result = pfsAccess->read(rootPortPath + '/' + "max_link_speed", maxLinkSpeed);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
maxLinkSpeed = 0;
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
result = pSysfsAccess->read(maxLinkSpeedFile, maxLinkSpeed);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
maxLinkSpeed = 0;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
maxLinkSpeed = val;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t LinuxPciImp::getMaxLinkWidth(uint32_t &maxLinkwidth) {
|
||||
int intVal;
|
||||
|
||||
ze_result_t result = pSysfsAccess->read(maxLinkWidthFile, intVal);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return result;
|
||||
ze_result_t result;
|
||||
if (isLmemSupported) {
|
||||
std::string rootPortPath;
|
||||
std::string realRootPath;
|
||||
result = pSysfsAccess->getRealPath(deviceDir, realRootPath);
|
||||
// we need to change the absolute path to two levels up to get actual
|
||||
// values of speed and width at the Discrete card's root port.
|
||||
// the root port is always at a fixed distance as defined in HW
|
||||
rootPortPath = changeDirNLevelsUp(realRootPath, 2);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
maxLinkwidth = 0;
|
||||
return result;
|
||||
}
|
||||
result = pfsAccess->read(rootPortPath + '/' + "max_link_width", maxLinkwidth);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
maxLinkwidth = 0;
|
||||
return result;
|
||||
}
|
||||
if (maxLinkwidth == static_cast<uint32_t>(unknownPcieLinkWidth)) {
|
||||
maxLinkwidth = 0;
|
||||
}
|
||||
} else {
|
||||
result = pSysfsAccess->read(maxLinkWidthFile, maxLinkwidth);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return result;
|
||||
}
|
||||
if (maxLinkwidth == static_cast<uint32_t>(unknownPcieLinkWidth)) {
|
||||
maxLinkwidth = 0;
|
||||
}
|
||||
}
|
||||
if (intVal == static_cast<int>(unknownPcieLinkWidth)) {
|
||||
intVal = 0;
|
||||
}
|
||||
maxLinkwidth = intVal;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -129,8 +178,8 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zet_pci_bar_propert
|
||||
|
||||
LinuxPciImp::LinuxPciImp(OsSysman *pOsSysman) {
|
||||
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
|
||||
|
||||
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
|
||||
pfsAccess = &pLinuxSysmanImp->getFsAccess();
|
||||
}
|
||||
|
||||
OsPci *OsPci::create(OsSysman *pOsSysman) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace L0 {
|
||||
|
||||
class SysfsAccess;
|
||||
class FsAccess;
|
||||
|
||||
class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
@@ -20,6 +21,7 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
|
||||
ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) override;
|
||||
ze_result_t getMaxLinkWidth(uint32_t &maxLinkwidth) override;
|
||||
ze_result_t getLinkGen(uint32_t &linkGen) override;
|
||||
void setLmemSupport(bool val) override;
|
||||
ze_result_t initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) override;
|
||||
LinuxPciImp() = default;
|
||||
LinuxPciImp(OsSysman *pOsSysman);
|
||||
@@ -27,12 +29,14 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
|
||||
|
||||
protected:
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
FsAccess *pfsAccess = nullptr;
|
||||
|
||||
private:
|
||||
static const std::string deviceDir;
|
||||
static const std::string resourceFile;
|
||||
static const std::string maxLinkSpeedFile;
|
||||
static const std::string maxLinkWidthFile;
|
||||
bool isLmemSupported = false;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -21,6 +21,7 @@ class OsPci {
|
||||
virtual ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) = 0;
|
||||
virtual ze_result_t getMaxLinkWidth(uint32_t &maxLinkWidth) = 0;
|
||||
virtual ze_result_t getLinkGen(uint32_t &linkGen) = 0;
|
||||
virtual void setLmemSupport(bool val) = 0;
|
||||
virtual ze_result_t initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) = 0;
|
||||
static OsPci *create(OsSysman *pOsSysman);
|
||||
virtual ~OsPci() = default;
|
||||
|
||||
@@ -65,6 +65,8 @@ void PciImp::init() {
|
||||
pOsPci = OsPci::create(pOsSysman);
|
||||
}
|
||||
UNRECOVERABLE_IF(nullptr == pOsPci);
|
||||
Device *device = L0::Device::fromHandle(hCoreDevice);
|
||||
pOsPci->setLmemSupport(device->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(device->getRootDeviceIndex()));
|
||||
std::string bdf;
|
||||
pOsPci->getPciBdf(bdf);
|
||||
if (bdf.empty()) {
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
#include <level_zero/zet_api.h>
|
||||
|
||||
#include "os_pci.h"
|
||||
@@ -24,9 +26,13 @@ class PciImp : public Pci, NEO::NonCopyableOrMovableClass {
|
||||
ze_result_t pciGetInitializedBars(uint32_t *pCount, zet_pci_bar_properties_t *pProperties) override;
|
||||
|
||||
PciImp() = default;
|
||||
PciImp(OsSysman *pOsSysman) : pOsSysman(pOsSysman) { pOsPci = nullptr; };
|
||||
PciImp(OsSysman *pOsSysman, ze_device_handle_t hDevice) : pOsSysman(pOsSysman) {
|
||||
pOsPci = nullptr;
|
||||
hCoreDevice = hDevice;
|
||||
};
|
||||
~PciImp() override;
|
||||
OsPci *pOsPci = nullptr;
|
||||
ze_device_handle_t hCoreDevice = {};
|
||||
|
||||
private:
|
||||
OsSysman *pOsSysman = nullptr;
|
||||
|
||||
@@ -16,6 +16,7 @@ class WddmPciImp : public OsPci {
|
||||
ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) override;
|
||||
ze_result_t getMaxLinkWidth(uint32_t &maxLinkwidth) override;
|
||||
ze_result_t getLinkGen(uint32_t &linkGen) override;
|
||||
void setLmemSupport(bool val) override;
|
||||
ze_result_t initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) override;
|
||||
~WddmPciImp() override = default;
|
||||
};
|
||||
@@ -36,6 +37,8 @@ ze_result_t WddmPciImp::getLinkGen(uint32_t &linkGen) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
void WddmPciImp::setLmemSupport(bool val) {}
|
||||
|
||||
ze_result_t WddmPciImp::initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ SysmanImp::SysmanImp(ze_device_handle_t hDevice) {
|
||||
hCoreDevice = hDevice;
|
||||
pOsSysman = OsSysman::create(this);
|
||||
UNRECOVERABLE_IF(nullptr == pOsSysman);
|
||||
pPci = new PciImp(pOsSysman);
|
||||
pPci = new PciImp(pOsSysman, hCoreDevice);
|
||||
pSched = new SchedulerImp(pOsSysman);
|
||||
pGlobalOperations = new GlobalOperationsImp(pOsSysman, hCoreDevice);
|
||||
pFrequencyHandleContext = new FrequencyHandleContext(pOsSysman);
|
||||
|
||||
@@ -23,7 +23,11 @@ const std::string resourceFile("device/resource");
|
||||
const std::string maxLinkSpeedFile("device/max_link_speed");
|
||||
const std::string maxLinkWidthFile("device/max_link_width");
|
||||
const std::string mockBdf = "0000:00:02.0";
|
||||
const std::string mockRealPath = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/" + mockBdf;
|
||||
const std::string mockRealPath2LevelsUp = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0";
|
||||
|
||||
constexpr double mockMaxLinkSpeed = 2.5;
|
||||
|
||||
const std::vector<std::string> mockReadBytes =
|
||||
{
|
||||
"0x00000000bf000000 0x00000000bfffffff 0x0000000000140204",
|
||||
@@ -42,48 +46,92 @@ const std::vector<std::string> mockReadBytes =
|
||||
};
|
||||
|
||||
class PciSysfsAccess : public SysfsAccess {};
|
||||
class PcifsAccess : public FsAccess {};
|
||||
|
||||
template <>
|
||||
struct Mock<PciSysfsAccess> : public SysfsAccess {
|
||||
int mockMaxLinkWidth = 0;
|
||||
struct Mock<PcifsAccess> : public PcifsAccess {
|
||||
uint32_t mockMaxLinkWidth = 0;
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, double &val), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, int &val), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, std::vector<std::string> &val), (override));
|
||||
MOCK_METHOD(ze_result_t, readSymLink, (const std::string file, std::string &buf), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, uint32_t &val), (override));
|
||||
|
||||
ze_result_t getValDouble(const std::string file, double &val) {
|
||||
if (file.compare(maxLinkSpeedFile) == 0) {
|
||||
if (file.compare(mockRealPath2LevelsUp + '/' + "max_link_speed") == 0) {
|
||||
val = mockMaxLinkSpeed;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t setValInt(const std::string file, int val) {
|
||||
ze_result_t getValInt(const std::string file, uint32_t &val) {
|
||||
if (file.compare(mockRealPath2LevelsUp + '/' + "max_link_width") == 0) {
|
||||
val = mockMaxLinkWidth;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t setValInt(const std::string file, uint32_t val) {
|
||||
if (file.compare(maxLinkWidthFile) == 0) {
|
||||
mockMaxLinkWidth = val;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
};
|
||||
|
||||
ze_result_t getValInt(const std::string file, int &val) {
|
||||
if (file.compare(maxLinkWidthFile) == 0) {
|
||||
val = mockMaxLinkWidth;
|
||||
template <>
|
||||
struct Mock<PciSysfsAccess> : public PciSysfsAccess {
|
||||
uint32_t mockMaxLinkWidth = 0;
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, double &val), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, uint32_t &val), (override));
|
||||
MOCK_METHOD(ze_result_t, read, (const std::string file, std::vector<std::string> &val), (override));
|
||||
MOCK_METHOD(ze_result_t, readSymLink, (const std::string file, std::string &buf), (override));
|
||||
MOCK_METHOD(ze_result_t, getRealPath, (const std::string file, std::string &buf), (override));
|
||||
|
||||
ze_result_t getValDouble(const std::string file, double &val) {
|
||||
if (file.compare(maxLinkSpeedFile) == 0) {
|
||||
val = mockMaxLinkSpeed;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValString(const std::string file, std::string &val) {
|
||||
ze_result_t setValInt(const std::string file, uint32_t val) {
|
||||
if (file.compare(maxLinkWidthFile) == 0) {
|
||||
mockMaxLinkWidth = val;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValInt(const std::string file, uint32_t &val) {
|
||||
if (file.compare(maxLinkWidthFile) == 0) {
|
||||
val = mockMaxLinkWidth;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValStringSymLink(const std::string file, std::string &val) {
|
||||
if (file.compare(deviceDir) == 0) {
|
||||
val = mockBdf;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
ze_result_t getValStringRealPath(const std::string file, std::string &val) {
|
||||
if (file.compare(deviceDir) == 0) {
|
||||
val = mockRealPath;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValVector(const std::string file, std::vector<std::string> &val) {
|
||||
if (file.compare(resourceFile) == 0) {
|
||||
val = mockReadBytes;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_SUCCESS;
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
Mock<PciSysfsAccess>() = default;
|
||||
@@ -91,6 +139,7 @@ struct Mock<PciSysfsAccess> : public SysfsAccess {
|
||||
|
||||
class PublicLinuxPciImp : public L0::LinuxPciImp {
|
||||
public:
|
||||
using LinuxPciImp::pfsAccess;
|
||||
using LinuxPciImp::pSysfsAccess;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h"
|
||||
#include "level_zero/tools/source/sysman/pci/linux/os_pci_imp.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
@@ -33,7 +34,12 @@ constexpr uint32_t expectedWidth = 1u;
|
||||
constexpr uint32_t expectedGen = 1u; // As mockMaxLinkSpeed = 2.5, hence expectedGen should be 1
|
||||
// As mockMaxLinkSpeed = 2.5, hence, pcieSpeedWithEnc = mockMaxLinkWidth * (2.5 * 1000 * 8/10 * 125000) = 250000000
|
||||
constexpr uint64_t expectedBandwidth = 250000000u;
|
||||
class SysmanPciFixture : public DeviceFixture, public ::testing::Test {
|
||||
|
||||
struct MockMemoryManagerPci : public MemoryManagerMock {
|
||||
MockMemoryManagerPci(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
|
||||
};
|
||||
|
||||
class SysmanPciFixture : public ::testing::Test {
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SysmanImp> sysmanImp;
|
||||
@@ -41,30 +47,55 @@ class SysmanPciFixture : public DeviceFixture, public ::testing::Test {
|
||||
|
||||
OsPci *pOsPci = nullptr;
|
||||
Mock<PciSysfsAccess> *pSysfsAccess = nullptr;
|
||||
Mock<PcifsAccess> *pfsAccess = nullptr;
|
||||
L0::Pci *pPciPrev = nullptr;
|
||||
L0::PciImp pciImp;
|
||||
PublicLinuxPciImp linuxPciImp;
|
||||
|
||||
MockMemoryManagerPci *memoryManager = nullptr;
|
||||
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
DeviceFixture::SetUp();
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
memoryManager = new ::testing::NiceMock<MockMemoryManagerPci>(*devices[0].get()->getExecutionEnvironment());
|
||||
devices[0].get()->getExecutionEnvironment()->memoryManager.reset(memoryManager);
|
||||
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
|
||||
sysmanImp = std::make_unique<SysmanImp>(device->toHandle());
|
||||
pSysfsAccess = new NiceMock<Mock<PciSysfsAccess>>;
|
||||
linuxPciImp.pSysfsAccess = pSysfsAccess;
|
||||
pfsAccess = new NiceMock<Mock<PcifsAccess>>;
|
||||
linuxPciImp.pfsAccess = pfsAccess;
|
||||
pOsPci = static_cast<OsPci *>(&linuxPciImp);
|
||||
pSysfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidth);
|
||||
pfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidth);
|
||||
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<std::vector<std::string> &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValVector));
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<int &>(_)))
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<uint32_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValInt));
|
||||
ON_CALL(*pSysfsAccess, readSymLink(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValString));
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValStringSymLink));
|
||||
ON_CALL(*pSysfsAccess, getRealPath(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValStringRealPath));
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<double &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValDouble));
|
||||
ON_CALL(*pfsAccess, read(_, Matcher<double &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pfsAccess, &Mock<PcifsAccess>::getValDouble));
|
||||
ON_CALL(*pfsAccess, read(_, Matcher<uint32_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pfsAccess, &Mock<PcifsAccess>::getValInt));
|
||||
|
||||
pPciPrev = sysmanImp->pPci;
|
||||
sysmanImp->pPci = static_cast<Pci *>(&pciImp);
|
||||
pciImp.pOsPci = pOsPci;
|
||||
pciImp.hCoreDevice = device;
|
||||
memoryManager->localMemorySupported[0] = 0;
|
||||
pciImp.init();
|
||||
hSysman = sysmanImp->toHandle();
|
||||
}
|
||||
@@ -77,13 +108,24 @@ class SysmanPciFixture : public DeviceFixture, public ::testing::Test {
|
||||
delete pSysfsAccess;
|
||||
pSysfsAccess = nullptr;
|
||||
}
|
||||
|
||||
DeviceFixture::TearDown();
|
||||
if (pfsAccess != nullptr) {
|
||||
delete pfsAccess;
|
||||
pfsAccess = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropertiesThenVerifyzetSysmanPciGetPropertiesCallSucceeds) {
|
||||
zet_pci_properties_t properties;
|
||||
zet_pci_properties_t properties, propertiesBefore;
|
||||
|
||||
memset(&properties.address.bus, std::numeric_limits<int>::max(), sizeof(properties.address.bus));
|
||||
memset(&properties.address.device, std::numeric_limits<int>::max(), sizeof(properties.address.device));
|
||||
memset(&properties.address.function, std::numeric_limits<int>::max(), sizeof(properties.address.function));
|
||||
memset(&properties.maxSpeed.gen, std::numeric_limits<int>::max(), sizeof(properties.maxSpeed.gen));
|
||||
memset(&properties.maxSpeed.width, std::numeric_limits<int>::max(), sizeof(properties.maxSpeed.width));
|
||||
memset(&properties.maxSpeed.maxBandwidth, std::numeric_limits<int>::max(), sizeof(properties.maxSpeed.maxBandwidth));
|
||||
propertiesBefore = properties;
|
||||
|
||||
ze_result_t result = zetSysmanPciGetProperties(hSysman, &properties);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
@@ -93,13 +135,54 @@ TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropert
|
||||
EXPECT_EQ(properties.maxSpeed.gen, expectedGen);
|
||||
EXPECT_EQ(properties.maxSpeed.width, expectedWidth);
|
||||
EXPECT_EQ(properties.maxSpeed.maxBandwidth, expectedBandwidth);
|
||||
|
||||
EXPECT_NE(properties.address.bus, propertiesBefore.address.bus);
|
||||
EXPECT_NE(properties.address.device, propertiesBefore.address.device);
|
||||
EXPECT_NE(properties.address.function, propertiesBefore.address.function);
|
||||
EXPECT_NE(properties.maxSpeed.gen, propertiesBefore.maxSpeed.gen);
|
||||
EXPECT_NE(properties.maxSpeed.width, propertiesBefore.maxSpeed.width);
|
||||
EXPECT_NE(properties.maxSpeed.maxBandwidth, propertiesBefore.maxSpeed.maxBandwidth);
|
||||
}
|
||||
|
||||
TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetSysmanPciGetPropertiesThenVerifyzetSysmanPciGetPropertiesCallSucceeds) {
|
||||
zet_pci_properties_t properties, propertiesBefore;
|
||||
memoryManager->localMemorySupported[0] = 1;
|
||||
pciImp.init();
|
||||
|
||||
memset(&properties.address.bus, std::numeric_limits<int>::max(), sizeof(properties.address.bus));
|
||||
memset(&properties.address.device, std::numeric_limits<int>::max(), sizeof(properties.address.device));
|
||||
memset(&properties.address.function, std::numeric_limits<int>::max(), sizeof(properties.address.function));
|
||||
memset(&properties.maxSpeed.gen, std::numeric_limits<int>::max(), sizeof(properties.maxSpeed.gen));
|
||||
memset(&properties.maxSpeed.width, std::numeric_limits<int>::max(), sizeof(properties.maxSpeed.width));
|
||||
memset(&properties.maxSpeed.maxBandwidth, std::numeric_limits<int>::max(), sizeof(properties.maxSpeed.maxBandwidth));
|
||||
propertiesBefore = properties;
|
||||
|
||||
ze_result_t result = zetSysmanPciGetProperties(hSysman, &properties);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(properties.address.bus, expectedBus);
|
||||
EXPECT_EQ(properties.address.device, expectedDevice);
|
||||
EXPECT_EQ(properties.address.function, expectedFunction);
|
||||
EXPECT_EQ(properties.maxSpeed.gen, expectedGen);
|
||||
EXPECT_EQ(properties.maxSpeed.width, expectedWidth);
|
||||
EXPECT_EQ(properties.maxSpeed.maxBandwidth, expectedBandwidth);
|
||||
|
||||
EXPECT_NE(properties.address.bus, propertiesBefore.address.bus);
|
||||
EXPECT_NE(properties.address.device, propertiesBefore.address.device);
|
||||
EXPECT_NE(properties.address.function, propertiesBefore.address.function);
|
||||
EXPECT_NE(properties.maxSpeed.gen, propertiesBefore.maxSpeed.gen);
|
||||
EXPECT_NE(properties.maxSpeed.width, propertiesBefore.maxSpeed.width);
|
||||
EXPECT_NE(properties.maxSpeed.maxBandwidth, propertiesBefore.maxSpeed.maxBandwidth);
|
||||
}
|
||||
|
||||
TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenGettingPCIWidthThenZeroWidthIsReturnedIfSystemProvidesInvalidValue) {
|
||||
uint32_t width = 0;
|
||||
pSysfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidthInvalid);
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<int &>(_)))
|
||||
pfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidthInvalid);
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<uint32_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValInt));
|
||||
ON_CALL(*pfsAccess, read(_, Matcher<uint32_t &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pfsAccess, &Mock<PcifsAccess>::getValInt));
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, pciImp.pOsPci->getMaxLinkWidth(width));
|
||||
EXPECT_EQ(width, 0u);
|
||||
|
||||
Reference in New Issue
Block a user