fix(sysman): Fix device name for the integrated device w.r.t Xe driver

Related-To: NEO-15290

Signed-off-by: Pratik Bari <pratik.bari@intel.com>
This commit is contained in:
Pratik Bari
2025-06-25 10:35:18 +00:00
committed by Compute-Runtime-Automation
parent 7ea975ed45
commit 3e024eccb4
8 changed files with 97 additions and 26 deletions

View File

@@ -205,22 +205,23 @@ ze_result_t SysmanKmdInterface::checkErrorNumberAndReturnStatus() {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
ze_result_t SysmanKmdInterface::getDeviceDirName(std::string &dirName, const bool isIntegratedDevice) {
void SysmanKmdInterface::updateSysmanDeviceDirName(std::string &dirName) {
ze_result_t result = ZE_RESULT_SUCCESS;
if (!isIntegratedDevice) {
auto pSysFsAccess = getSysFsAccess();
std::string bdfDir;
result = pSysFsAccess->readSymLink(std::string(deviceDir), bdfDir);
if (ZE_RESULT_SUCCESS != result) {
return result;
}
const auto loc = bdfDir.find_last_of('/');
auto bdf = bdfDir.substr(loc + 1);
std::replace(bdf.begin(), bdf.end(), ':', '_');
dirName = dirName + "_" + bdf;
std::string bdfDir = "";
auto pSysfsAccess = getSysFsAccess();
auto result = pSysfsAccess->readSymLink(std::string(deviceDir), bdfDir);
if (ZE_RESULT_SUCCESS != result) {
dirName = "";
return;
}
return result;
const auto loc = bdfDir.find_last_of('/'); // Gives the location of the last occurence of '/' in the bdfDir path. Eg: bdfDir = ../../../0000:03:00.0
auto bdf = bdfDir.substr(loc + 1); // The bdf will start after the last location of '/'. Eg: bdf = 0000:03:00.0
std::replace(bdf.begin(), bdf.end(), ':', '_'); // The ':' is replaced by '_'. Eg: bdf = 0000_03_00.0
dirName = dirName + "_" + bdf; // The final dirName has bdf name appended to the dirName. Eg: i915_0000_03_00.0 or xe_0000_03_00.0
}
const std::string SysmanKmdInterface::getSysmanDeviceDirName() const {
return sysmanDeviceDirName;
}
std::string SysmanKmdInterfaceI915::getBasePathI915(uint32_t subDeviceId) {

View File

@@ -177,6 +177,7 @@ class SysmanKmdInterface {
virtual std::string getGpuUnBindEntry() const = 0;
virtual std::vector<zes_power_domain_t> getPowerDomains() const = 0;
virtual void setSysmanDeviceDirName(const bool isIntegratedDevice) = 0;
const std::string getSysmanDeviceDirName() const;
ze_result_t checkErrorNumberAndReturnStatus();
protected:
@@ -185,8 +186,8 @@ class SysmanKmdInterface {
std::unique_ptr<SysFsAccessInterface> pSysfsAccess;
std::string sysmanDeviceDirName = "";
virtual const std::map<SysfsName, SysfsValueUnit> &getSysfsNameToNativeUnitMap() = 0;
ze_result_t getDeviceDirName(std::string &dirName, const bool isIntegratedDevice);
void getWedgedStatusImpl(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState);
void updateSysmanDeviceDirName(std::string &dirName);
};
class SysmanKmdInterfaceI915 {

View File

@@ -240,9 +240,10 @@ std::string SysmanKmdInterfaceI915Prelim::getGpuUnBindEntry() const {
}
void SysmanKmdInterfaceI915Prelim::setSysmanDeviceDirName(const bool isIntegratedDevice) {
sysmanDeviceDirName = "i915";
getDeviceDirName(sysmanDeviceDirName, isIntegratedDevice);
if (!isIntegratedDevice) {
updateSysmanDeviceDirName(sysmanDeviceDirName);
}
}
} // namespace Sysman

View File

@@ -187,9 +187,10 @@ std::string SysmanKmdInterfaceI915Upstream::getGpuUnBindEntry() const {
}
void SysmanKmdInterfaceI915Upstream::setSysmanDeviceDirName(const bool isIntegratedDevice) {
sysmanDeviceDirName = "i915";
getDeviceDirName(sysmanDeviceDirName, isIntegratedDevice);
if (!isIntegratedDevice) {
updateSysmanDeviceDirName(sysmanDeviceDirName);
}
}
} // namespace Sysman

View File

@@ -157,7 +157,7 @@ ze_result_t SysmanKmdInterfaceXe::getEngineActivityFdListAndConfigPair(zes_engin
return result;
}
const std::string sysmanDeviceDir = std::string(sysDevicesDir) + sysmanDeviceDirName;
const std::string sysmanDeviceDir = std::string(sysDevicesDir) + getSysmanDeviceDirName();
uint64_t activeTicksConfig = UINT64_MAX;
uint64_t totalTicksConfig = UINT64_MAX;
@@ -255,7 +255,7 @@ ze_result_t SysmanKmdInterfaceXe::getBusyAndTotalTicksConfigsForVf(PmuInterface
std::pair<uint64_t, uint64_t> &configPair) {
ze_result_t result = ZE_RESULT_SUCCESS;
const std::string sysmanDeviceDir = std::string(sysDevicesDir) + sysmanDeviceDirName;
const std::string sysmanDeviceDir = std::string(sysDevicesDir) + getSysmanDeviceDirName();
auto ret = pPmuInterface->getPmuConfigs(sysmanDeviceDir, engineClass, engineInstance, gtId, configPair.first, configPair.second);
if (ret < 0) {
@@ -283,9 +283,8 @@ std::string SysmanKmdInterfaceXe::getGpuUnBindEntry() const {
}
void SysmanKmdInterfaceXe::setSysmanDeviceDirName(const bool isIntegratedDevice) {
sysmanDeviceDirName = "xe";
getDeviceDirName(sysmanDeviceDirName, isIntegratedDevice);
updateSysmanDeviceDirName(sysmanDeviceDirName);
}
} // namespace Sysman

View File

@@ -59,6 +59,7 @@ class SysmanFixtureDeviceI915Prelim : public SysmanDeviceFixture {
std::unique_ptr<MockPmuInterfaceImp> pPmuInterface;
void SetUp() override {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
SysmanDeviceFixture::SetUp();
device = pSysmanDevice;
pLinuxSysmanImp->pSysmanKmdInterface.reset(new SysmanKmdInterfaceI915Prelim(pLinuxSysmanImp->getSysmanProductHelper()));
@@ -72,7 +73,6 @@ class SysmanFixtureDeviceI915Prelim : public SysmanDeviceFixture {
}
void mockInitFsAccess() {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
pLinuxSysmanImp->pSysmanKmdInterface->initFsAccessInterface(*pLinuxSysmanImp->getDrm());
}
@@ -97,6 +97,29 @@ TEST_F(SysmanFixtureDeviceI915Prelim, GivenSysmanKmdInterfaceInstanceWhenCalling
EXPECT_STREQ("engine", pSysmanKmdInterface->getEngineBasePath(0).c_str());
}
TEST_F(SysmanFixtureDeviceI915Prelim, GivenSysmanKmdInterfaceWhenCallingGetSysmanDeviceDirNameForDiscreteDeviceThenCorrectNameIsReturned) {
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
EXPECT_STREQ("i915_0000_03_00.0", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceI915Prelim, GivenSysmanKmdInterfaceAndReadSymLinkFailsWhenCallingGetSysmanDeviceDirNameForDiscreteDeviceThenEmptyStringIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
bool isIntegratedDevice = false;
pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
EXPECT_STREQ("", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceI915Prelim, GivenSysmanKmdInterfaceWhenCallingGetSysmanDeviceDirNameForIntegratedDeviceThenCorrectNameIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
auto pSysmanKmdInterface = std::make_unique<SysmanKmdInterfaceI915Prelim>(pLinuxSysmanImp->getSysmanProductHelper());
mockInitFsAccess();
bool isIntegratedDevice = true;
pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
EXPECT_STREQ("i915", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceI915Prelim, GivenSysmanKmdInterfaceWhenGettingSysfsFileNamesThenProperPathsAreReturned) {
auto pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface();
bool baseDirectoryExists = true;

View File

@@ -56,7 +56,7 @@ class SysmanFixtureDeviceI915Upstream : public SysmanDeviceFixture {
std::unique_ptr<MockPmuInterfaceImp> pPmuInterface;
void SetUp() override {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
SysmanDeviceFixture::SetUp();
device = pSysmanDevice;
pPmuInterface = std::make_unique<MockPmuInterfaceImp>(pLinuxSysmanImp);
@@ -67,6 +67,10 @@ class SysmanFixtureDeviceI915Upstream : public SysmanDeviceFixture {
pLinuxSysmanImp->pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
}
void mockInitFsAccess() {
pLinuxSysmanImp->pSysmanKmdInterface->initFsAccessInterface(*pLinuxSysmanImp->getDrm());
}
void TearDown() override {
SysmanDeviceFixture::TearDown();
}
@@ -130,6 +134,29 @@ TEST_F(SysmanFixtureDeviceI915Upstream, GivenSysmanKmdInterfaceWhenGettingEngine
EXPECT_STREQ("engine", pSysmanKmdInterface->getEngineBasePath(0).c_str());
}
TEST_F(SysmanFixtureDeviceI915Upstream, GivenSysmanKmdInterfaceWhenCallingGetSysmanDeviceDirNameForDiscreteDeviceThenCorrectNameIsReturned) {
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
EXPECT_STREQ("i915_0000_03_00.0", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceI915Upstream, GivenSysmanKmdInterfaceAndReadSymLinkFailsWhenCallingGetSysmanDeviceDirNameForDiscreteDeviceThenEmptyStringIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
bool isIntegratedDevice = false;
pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
EXPECT_STREQ("", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceI915Upstream, GivenSysmanKmdInterfaceWhenCallingGetSysmanDeviceDirNameForIntegratedDeviceThenCorrectNameIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
auto pSysmanKmdInterface = std::make_unique<SysmanKmdInterfaceI915Upstream>(pLinuxSysmanImp->getSysmanProductHelper());
mockInitFsAccess();
bool isIntegratedDevice = true;
pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
EXPECT_STREQ("i915", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceI915Upstream, GivenSysmanKmdInterfaceWhenCallingGetEngineClassStringThenCorrectPathIsReturned) {
auto pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface();
EXPECT_STREQ("rcs", pSysmanKmdInterface->getEngineClassString(EngineClass::ENGINE_CLASS_RENDER).value().c_str());

View File

@@ -40,11 +40,17 @@ static ssize_t mockReadSuccess(int fd, void *buf, size_t count, off_t offset) {
return count;
}
static int mockReadLinkFailure(const char *path, char *buf, size_t bufsize) {
errno = ENOENT;
return -1;
}
class SysmanFixtureDeviceXe : public SysmanDeviceFixture {
protected:
std::unique_ptr<MockPmuInterfaceImp> pPmuInterface;
void SetUp() override {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
SysmanDeviceFixture::SetUp();
pPmuInterface = std::make_unique<MockPmuInterfaceImp>(pLinuxSysmanImp);
pLinuxSysmanImp->pSysmanKmdInterface.reset(new SysmanKmdInterfaceXe(pLinuxSysmanImp->getSysmanProductHelper()));
@@ -55,7 +61,6 @@ class SysmanFixtureDeviceXe : public SysmanDeviceFixture {
}
void mockInitFsAccess() {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess);
pLinuxSysmanImp->pSysmanKmdInterface->initFsAccessInterface(*pLinuxSysmanImp->getDrm());
}
@@ -64,6 +69,19 @@ class SysmanFixtureDeviceXe : public SysmanDeviceFixture {
}
};
TEST_F(SysmanFixtureDeviceXe, GivenSysmanKmdInterfaceWhenCallingGetSysmanDeviceDirNameThenCorrectNameIsReturned) {
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
EXPECT_STREQ("xe_0000_03_00.0", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceXe, GivenSysmanKmdInterfaceAndReadSymLinkFailsWhenCallingGetSysmanDeviceDirNameThenEmptyStringIsReturned) {
VariableBackup<decltype(NEO::SysCalls::sysCallsReadlink)> mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkFailure);
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
bool isIntegratedDevice = false;
pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
EXPECT_STREQ("", pSysmanKmdInterface->getSysmanDeviceDirName().c_str());
}
TEST_F(SysmanFixtureDeviceXe, GivenSysmanKmdInterfaceWhenGettingSysfsFileNamesThenProperPathsAreReturned) {
auto pSysmanKmdInterface = pLinuxSysmanImp->pSysmanKmdInterface.get();
bool baseDirectoryExists = true;