mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Report correct PCI width from API zetSysmanPciGetProperties
If system reports incorrect PCI width, then check width against valid value, and report correct PCI width accordingly. Change-Id: I56f8fe96785ccd22032860d55dd96b81d5fc53f7 Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
87b9c5f4e6
commit
8dff60b6a5
@@ -19,6 +19,8 @@ const std::string LinuxPciImp::resourceFile("device/resource");
|
||||
const std::string LinuxPciImp::maxLinkSpeedFile("device/max_link_speed");
|
||||
const std::string LinuxPciImp::maxLinkWidthFile("device/max_link_width");
|
||||
constexpr uint8_t maxPciBars = 6;
|
||||
// Linux kernel would report 255 link width, as an indication of unknown.
|
||||
constexpr uint32_t unknownPcieLinkWidth = 255u;
|
||||
|
||||
ze_result_t LinuxPciImp::getPciBdf(std::string &bdf) {
|
||||
std::string bdfDir;
|
||||
@@ -50,6 +52,9 @@ ze_result_t LinuxPciImp::getMaxLinkWidth(uint32_t &maxLinkwidth) {
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return result;
|
||||
}
|
||||
if (intVal == static_cast<int>(unknownPcieLinkWidth)) {
|
||||
intVal = 0;
|
||||
}
|
||||
maxLinkwidth = intVal;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ const std::string maxLinkSpeedFile("device/max_link_speed");
|
||||
const std::string maxLinkWidthFile("device/max_link_width");
|
||||
const std::string mockBdf = "0000:00:02.0";
|
||||
constexpr double mockMaxLinkSpeed = 2.5;
|
||||
constexpr int mockMaxLinkWidth = 1;
|
||||
const std::vector<std::string> mockReadBytes =
|
||||
{
|
||||
"0x00000000bf000000 0x00000000bfffffff 0x0000000000140204",
|
||||
@@ -46,6 +45,7 @@ class PciSysfsAccess : public SysfsAccess {};
|
||||
|
||||
template <>
|
||||
struct Mock<PciSysfsAccess> : public SysfsAccess {
|
||||
int 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));
|
||||
@@ -58,6 +58,13 @@ struct Mock<PciSysfsAccess> : public SysfsAccess {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t setValInt(const std::string file, int 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;
|
||||
|
||||
@@ -24,7 +24,15 @@ using ::testing::Return;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
constexpr int mockMaxLinkWidth = 1;
|
||||
constexpr int mockMaxLinkWidthInvalid = 255;
|
||||
constexpr uint32_t expectedBus = 0u;
|
||||
constexpr uint32_t expectedDevice = 2u;
|
||||
constexpr uint32_t expectedFunction = 0u;
|
||||
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 {
|
||||
|
||||
protected:
|
||||
@@ -43,6 +51,7 @@ class SysmanPciFixture : public DeviceFixture, public ::testing::Test {
|
||||
pSysfsAccess = new NiceMock<Mock<PciSysfsAccess>>;
|
||||
linuxPciImp.pSysfsAccess = pSysfsAccess;
|
||||
pOsPci = static_cast<OsPci *>(&linuxPciImp);
|
||||
pSysfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidth);
|
||||
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<std::vector<std::string> &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValVector));
|
||||
@@ -78,12 +87,22 @@ TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropert
|
||||
ze_result_t result = zetSysmanPciGetProperties(hSysman, &properties);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_LT(properties.address.bus, 256u);
|
||||
EXPECT_LT(properties.address.device, 32u);
|
||||
EXPECT_LT(properties.address.function, 8u);
|
||||
EXPECT_LE(properties.maxSpeed.gen, 5u);
|
||||
EXPECT_LE(properties.maxSpeed.width, 32u);
|
||||
EXPECT_LE(properties.maxSpeed.maxBandwidth, std::numeric_limits<uint64_t>::max());
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenGettingPCIWidthThenZeroWidthIsReturnedIfSystemProvidesInvalidValue) {
|
||||
uint32_t width = 0;
|
||||
pSysfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidthInvalid);
|
||||
ON_CALL(*pSysfsAccess, read(_, Matcher<int &>(_)))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess, &Mock<PciSysfsAccess>::getValInt));
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, pciImp.pOsPci->getMaxLinkWidth(width));
|
||||
EXPECT_EQ(width, 0u);
|
||||
}
|
||||
|
||||
TEST_F(SysmanPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceeds) {
|
||||
|
||||
Reference in New Issue
Block a user