Skip to content

Commit 2b7e92b

Browse files
refactor: Set the sysman device directory name in SysmanKmdInterface
The name of the Sysman Device Directory is added as a parameter in SysmanKmdInterface as the name depends on either i915 or xe driver Related-To: NEO-14070 Signed-off-by: Pratik Bari <pratik.bari@intel.com>
1 parent 6ee39ed commit 2b7e92b

17 files changed

+100
-86
lines changed

level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,10 @@ void SysmanKmdInterface::convertSysfsValueUnit(const SysfsValueUnit dstUnit, con
173173
}
174174
}
175175

176-
uint32_t SysmanKmdInterface::getEventTypeImpl(std::string &dirName, const bool isIntegratedDevice) {
177-
auto pSysFsAccess = getSysFsAccess();
178-
auto pFsAccess = getFsAccess();
176+
uint32_t SysmanKmdInterface::getEventType() {
179177

180-
if (!isIntegratedDevice) {
181-
std::string bdfDir;
182-
ze_result_t result = pSysFsAccess->readSymLink(deviceDir, bdfDir);
183-
if (ZE_RESULT_SUCCESS != result) {
184-
return 0;
185-
}
186-
const auto loc = bdfDir.find_last_of('/');
187-
auto bdf = bdfDir.substr(loc + 1);
188-
std::replace(bdf.begin(), bdf.end(), ':', '_');
189-
dirName = dirName + "_" + bdf;
190-
}
191-
192-
const std::string eventTypeSysfsNode = sysDevicesDir + dirName + "/" + "type";
178+
auto pFsAccess = getFsAccess();
179+
const std::string eventTypeSysfsNode = sysDevicesDir + sysmanDeviceDirName + "/" + "type";
193180
auto eventTypeVal = 0u;
194181
if (ZE_RESULT_SUCCESS != pFsAccess->read(eventTypeSysfsNode, eventTypeVal)) {
195182
return 0;
@@ -221,6 +208,24 @@ ze_result_t SysmanKmdInterface::checkErrorNumberAndReturnStatus() {
221208
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
222209
}
223210

211+
ze_result_t SysmanKmdInterface::getDeviceDirName(std::string &dirName, const bool isIntegratedDevice) {
212+
213+
ze_result_t result = ZE_RESULT_SUCCESS;
214+
if (!isIntegratedDevice) {
215+
auto pSysFsAccess = getSysFsAccess();
216+
std::string bdfDir;
217+
result = pSysFsAccess->readSymLink(deviceDir, bdfDir);
218+
if (ZE_RESULT_SUCCESS != result) {
219+
return result;
220+
}
221+
const auto loc = bdfDir.find_last_of('/');
222+
auto bdf = bdfDir.substr(loc + 1);
223+
std::replace(bdf.begin(), bdf.end(), ':', '_');
224+
dirName = dirName + "_" + bdf;
225+
}
226+
return result;
227+
}
228+
224229
std::string SysmanKmdInterfaceI915::getBasePathI915(uint32_t subDeviceId) {
225230
return "gt/gt" + std::to_string(subDeviceId) + "/";
226231
}

level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class SysmanKmdInterface {
140140
void convertSysfsValueUnit(const SysfsValueUnit dstUnit, const SysfsValueUnit srcUnit,
141141
const uint64_t srcValue, uint64_t &dstValue) const;
142142
virtual std::optional<std::string> getEngineClassString(uint16_t engineClass) = 0;
143-
virtual uint32_t getEventType(const bool isIntegratedDevice) = 0;
143+
uint32_t getEventType();
144144
virtual bool isDefaultFrequencyAvailable() const = 0;
145145
virtual bool isBoostFrequencyAvailable() const = 0;
146146
virtual bool isTdpFrequencyAvailable() const = 0;
@@ -154,14 +154,16 @@ class SysmanKmdInterface {
154154
virtual std::string getGpuBindEntry() const = 0;
155155
virtual std::string getGpuUnBindEntry() const = 0;
156156
virtual std::vector<zes_power_domain_t> getPowerDomains() const = 0;
157+
virtual void setSysmanDeviceDirName(const bool isIntegratedDevice) = 0;
157158
ze_result_t checkErrorNumberAndReturnStatus();
158159

159160
protected:
160161
std::unique_ptr<FsAccessInterface> pFsAccess;
161162
std::unique_ptr<ProcFsAccessInterface> pProcfsAccess;
162163
std::unique_ptr<SysFsAccessInterface> pSysfsAccess;
164+
std::string sysmanDeviceDirName = "";
163165
virtual const std::map<SysfsName, SysfsValueUnit> &getSysfsNameToNativeUnitMap() = 0;
164-
uint32_t getEventTypeImpl(std::string &dirName, const bool isIntegratedDevice);
166+
ze_result_t getDeviceDirName(std::string &dirName, const bool isIntegratedDevice);
165167
void getWedgedStatusImpl(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState);
166168
};
167169

@@ -199,7 +201,6 @@ class SysmanKmdInterfaceI915Upstream : public SysmanKmdInterface, SysmanKmdInter
199201
ze_bool_t onSubdevice,
200202
uint32_t subdeviceId) override;
201203
std::optional<std::string> getEngineClassString(uint16_t engineClass) override;
202-
uint32_t getEventType(const bool isIntegratedDevice) override;
203204
bool isBaseFrequencyFactorAvailable() const override { return false; }
204205
bool isMediaFrequencyFactorAvailable() const override { return true; }
205206
bool isSystemPowerBalanceAvailable() const override { return false; }
@@ -216,6 +217,7 @@ class SysmanKmdInterfaceI915Upstream : public SysmanKmdInterface, SysmanKmdInter
216217
std::string getGpuBindEntry() const override;
217218
std::string getGpuUnBindEntry() const override;
218219
std::vector<zes_power_domain_t> getPowerDomains() const override { return {ZES_POWER_DOMAIN_PACKAGE}; }
220+
void setSysmanDeviceDirName(const bool isIntegratedDevice) override;
219221

220222
protected:
221223
std::map<SysfsName, valuePair> sysfsNameToFileMap;
@@ -249,7 +251,6 @@ class SysmanKmdInterfaceI915Prelim : public SysmanKmdInterface, SysmanKmdInterfa
249251
ze_bool_t onSubdevice,
250252
uint32_t subdeviceId) override;
251253
std::optional<std::string> getEngineClassString(uint16_t engineClass) override;
252-
uint32_t getEventType(const bool isIntegratedDevice) override;
253254
bool isBaseFrequencyFactorAvailable() const override { return true; }
254255
bool isMediaFrequencyFactorAvailable() const override { return true; }
255256
bool isSystemPowerBalanceAvailable() const override { return true; }
@@ -266,6 +267,7 @@ class SysmanKmdInterfaceI915Prelim : public SysmanKmdInterface, SysmanKmdInterfa
266267
std::string getGpuBindEntry() const override;
267268
std::string getGpuUnBindEntry() const override;
268269
std::vector<zes_power_domain_t> getPowerDomains() const override { return {ZES_POWER_DOMAIN_PACKAGE}; }
270+
void setSysmanDeviceDirName(const bool isIntegratedDevice) override;
269271

270272
protected:
271273
std::map<SysfsName, valuePair> sysfsNameToFileMap;
@@ -299,7 +301,6 @@ class SysmanKmdInterfaceXe : public SysmanKmdInterface {
299301
ze_bool_t onSubdevice,
300302
uint32_t subdeviceId) override;
301303
std::optional<std::string> getEngineClassString(uint16_t engineClass) override;
302-
uint32_t getEventType(const bool isIntegratedDevice) override;
303304
bool isBaseFrequencyFactorAvailable() const override { return false; }
304305
bool isMediaFrequencyFactorAvailable() const override { return false; }
305306
bool isSystemPowerBalanceAvailable() const override { return false; }
@@ -318,6 +319,7 @@ class SysmanKmdInterfaceXe : public SysmanKmdInterface {
318319
ze_result_t getBusyAndTotalTicksConfigs(uint64_t fnNumber, uint64_t engineInstance, uint64_t engineClass, std::pair<uint64_t, uint64_t> &configPair) override;
319320
std::string getGpuBindEntry() const override;
320321
std::string getGpuUnBindEntry() const override;
322+
void setSysmanDeviceDirName(const bool isIntegratedDevice) override;
321323

322324
protected:
323325
std::map<SysfsName, valuePair> sysfsNameToFileMap;

level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_i915_prelim.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ std::optional<std::string> SysmanKmdInterfaceI915Prelim::getEngineClassString(ui
188188
return sysfEngineString->second;
189189
}
190190

191-
uint32_t SysmanKmdInterfaceI915Prelim::getEventType(const bool isIntegratedDevice) {
192-
std::string i915DirName = "i915";
193-
return getEventTypeImpl(i915DirName, isIntegratedDevice);
194-
}
195-
196191
void SysmanKmdInterfaceI915Prelim::getWedgedStatus(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState) {
197192
getWedgedStatusImpl(pLinuxSysmanImp, pState);
198193
}
@@ -227,5 +222,11 @@ std::string SysmanKmdInterfaceI915Prelim::getGpuUnBindEntry() const {
227222
return getGpuUnBindEntryI915();
228223
}
229224

225+
void SysmanKmdInterfaceI915Prelim::setSysmanDeviceDirName(const bool isIntegratedDevice) {
226+
227+
sysmanDeviceDirName = "i915";
228+
getDeviceDirName(sysmanDeviceDirName, isIntegratedDevice);
229+
}
230+
230231
} // namespace Sysman
231232
} // namespace L0

level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_i915_upstream.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ ze_result_t SysmanKmdInterfaceI915Upstream::getNumEngineTypeAndInstances(std::ma
144144
return getNumEngineTypeAndInstancesForDevice(getEngineBasePath(subdeviceId), mapOfEngines, pSysfsAccess);
145145
}
146146

147-
uint32_t SysmanKmdInterfaceI915Upstream::getEventType(const bool isIntegratedDevice) {
148-
std::string i915DirName = "i915";
149-
return getEventTypeImpl(i915DirName, isIntegratedDevice);
150-
}
151-
152147
void SysmanKmdInterfaceI915Upstream::getWedgedStatus(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState) {
153148
getWedgedStatusImpl(pLinuxSysmanImp, pState);
154149
}
@@ -180,5 +175,11 @@ std::string SysmanKmdInterfaceI915Upstream::getGpuUnBindEntry() const {
180175
return getGpuUnBindEntryI915();
181176
}
182177

178+
void SysmanKmdInterfaceI915Upstream::setSysmanDeviceDirName(const bool isIntegratedDevice) {
179+
180+
sysmanDeviceDirName = "i915";
181+
getDeviceDirName(sysmanDeviceDirName, isIntegratedDevice);
182+
}
183+
183184
} // namespace Sysman
184185
} // namespace L0

level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_xe.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ ze_result_t SysmanKmdInterfaceXe::getNumEngineTypeAndInstances(std::map<zes_engi
138138
return getNumEngineTypeAndInstancesForDevice(getEngineBasePath(subdeviceId), mapOfEngines, pSysfsAccess);
139139
}
140140

141-
uint32_t SysmanKmdInterfaceXe::getEventType(const bool isIntegratedDevice) {
142-
std::string xeDirName = "xe";
143-
return getEventTypeImpl(xeDirName, isIntegratedDevice);
144-
}
145-
146141
void SysmanKmdInterfaceXe::getDriverVersion(char (&driverVersion)[ZES_STRING_PROPERTY_SIZE]) {
147142

148143
auto pFsAccess = getFsAccess();
@@ -170,5 +165,11 @@ std::string SysmanKmdInterfaceXe::getGpuUnBindEntry() const {
170165
return "/sys/bus/pci/drivers/xe/unbind";
171166
}
172167

168+
void SysmanKmdInterfaceXe::setSysmanDeviceDirName(const bool isIntegratedDevice) {
169+
170+
sysmanDeviceDirName = "xe";
171+
getDeviceDirName(sysmanDeviceDirName, isIntegratedDevice);
172+
}
173+
173174
} // namespace Sysman
174175
} // namespace L0

level_zero/sysman/source/shared/linux/pmu/sysman_pmu_imp.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -28,13 +28,12 @@ inline int64_t PmuInterfaceImp::perfEventOpen(perf_event_attr *attr, pid_t pid,
2828
}
2929

3030
int64_t PmuInterfaceImp::pmuInterfaceOpen(uint64_t config, int group, uint32_t format) {
31-
const bool isIntegratedDevice = pDevice->getRootDeviceEnvironment().getHardwareInfo()->capabilityTable.isIntegratedDevice;
3231
struct perf_event_attr attr = {};
3332
int nrCpus = get_nprocs_conf();
3433
int cpu = 0;
3534
int64_t ret = 0;
3635

37-
attr.type = pSysmanKmdInterface->getEventType(isIntegratedDevice);
36+
attr.type = pSysmanKmdInterface->getEventType();
3837
if (attr.type == 0) {
3938
return -ENOENT;
4039
}
@@ -63,7 +62,6 @@ int PmuInterfaceImp::pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) {
6362
}
6463

6564
PmuInterfaceImp::PmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) {
66-
pDevice = pLinuxSysmanImp->getSysmanDeviceImp();
6765
pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface();
6866
}
6967

level_zero/sysman/source/shared/linux/pmu/sysman_pmu_imp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class PmuInterfaceImp : public PmuInterface, NEO::NonCopyableAndNonMovableClass
3535
SysmanKmdInterface *pSysmanKmdInterface = nullptr;
3636

3737
private:
38-
SysmanDeviceImp *pDevice = nullptr;
3938
static const std::string deviceDir;
4039
static const std::string sysDevicesDir;
4140
};

level_zero/sysman/source/shared/linux/zes_os_sysman_imp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ze_result_t LinuxSysmanImp::init() {
6161
if (result != ZE_RESULT_SUCCESS) {
6262
return result;
6363
}
64+
pSysmanKmdInterface->setSysmanDeviceDirName(getSysmanDeviceImp()->getRootDeviceEnvironment().getHardwareInfo()->capabilityTable.isIntegratedDevice);
6465
pFsAccess = pSysmanKmdInterface->getFsAccess();
6566
pProcfsAccess = pSysmanKmdInterface->getProcFsAccess();
6667
pSysfsAccess = pSysmanKmdInterface->getSysFsAccess();

level_zero/sysman/test/unit_tests/sources/engine/linux/test_zes_engine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class ZesEngineFixtureI915 : public ZesEngineFixture {
5353
pLinuxSysmanImp->pPmuInterface = pPmuInterface.get();
5454

5555
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
56-
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true;
56+
bool isIntegratedDevice = true;
57+
pLinuxSysmanImp->pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
5758
device = pSysmanDevice;
5859
getEngineHandles(0);
5960
}
@@ -138,7 +139,8 @@ TEST_F(ZesEngineFixtureI915, GivenValidEngineHandleAndIntegratedDeviceWhenCallin
138139
}
139140

140141
TEST_F(ZesEngineFixtureI915, GivenValidEngineHandleAndDiscreteDeviceWhenCallingZesEngineGetActivityThenVerifyCallReturnsSuccess) {
141-
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false;
142+
bool isIntegratedDevice = false;
143+
pLinuxSysmanImp->pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
142144
zes_engine_stats_t stats = {};
143145
auto handles = getEngineHandles(handleComponentCount);
144146
EXPECT_EQ(handleComponentCount, handles.size());

level_zero/sysman/test/unit_tests/sources/engine/linux/test_zes_engine_prelim.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class ZesEngineFixturePrelim : public SysmanDeviceFixture {
4949
pLinuxSysmanImp->pPmuInterface = pPmuInterface.get();
5050

5151
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
52-
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true;
52+
bool isIntegratedDevice = true;
53+
pLinuxSysmanImp->pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
5354
device = pSysmanDevice;
5455
getEngineHandles(0);
5556
}
@@ -85,7 +86,6 @@ TEST_F(SysmanDeviceFixture, GivenComponentCountZeroAndOpenCallFailsWhenCallingZe
8586
osInterface->setDriverModel(std::unique_ptr<MockEngineNeoDrmPrelim>(pDrm));
8687

8788
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
88-
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true;
8989
L0::Sysman::SysmanDevice *device = pSysmanDevice;
9090

9191
uint32_t count = 0;
@@ -199,7 +199,8 @@ TEST_F(ZesEngineFixturePrelim, GivenValidEngineHandleAndPmuTimeStampIsZeroWhenCa
199199

200200
TEST_F(ZesEngineFixturePrelim, GivenValidEngineHandleAndDiscreteDeviceWhenCallingZesEngineGetActivityThenVerifyCallReturnsSuccess) {
201201

202-
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false;
202+
bool isIntegratedDevice = false;
203+
pLinuxSysmanImp->pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
203204
zes_engine_stats_t stats = {};
204205
auto handles = getEngineHandles(handleComponentCount);
205206
EXPECT_EQ(handleComponentCount, handles.size());
@@ -404,7 +405,8 @@ class ZesEngineMultiFixturePrelim : public SysmanMultiDeviceFixture {
404405
pDrm->mockReadSysmanQueryEngineInfoMultiDevice = true;
405406

406407
pSysmanDeviceImp->pEngineHandleContext->handleList.clear();
407-
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true;
408+
bool isIntegratedDevice = true;
409+
pLinuxSysmanImp->pSysmanKmdInterface->setSysmanDeviceDirName(isIntegratedDevice);
408410
device = pSysmanDevice;
409411
getEngineHandles(0);
410412
}

0 commit comments

Comments
 (0)