refactor(sysman): Wrapper function to fetch PMU configs w.r.t Xe driver

A new wrapper function is introduced which fetches the PMU configs for
the Active Ticks and Total Ticks.

Related-To: NEO-14594

Signed-off-by: Pratik Bari <pratik.bari@intel.com>
This commit is contained in:
Pratik Bari
2025-04-09 12:37:23 +00:00
committed by Compute-Runtime-Automation
parent e4196b3029
commit ff7bfc8b6e
6 changed files with 44 additions and 31 deletions

View File

@@ -112,36 +112,14 @@ ze_result_t SysmanKmdInterfaceXe::getEngineActivityFdList(zes_engine_group_t eng
return result;
}
const std::string activeTicksEventFile = std::string(sysDevicesDir) + sysmanDeviceDirName + "/events/engine-active-ticks";
const std::string sysmanDeviceDir = std::string(sysDevicesDir) + sysmanDeviceDirName;
uint64_t activeTicksConfig = UINT64_MAX;
auto ret = pPmuInterface->getConfigFromEventFile(activeTicksEventFile, activeTicksConfig);
if (ret < 0) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get config for the active ticks from event file and returning error:0x%x\n", __FUNCTION__, result);
return result;
}
const std::string totalTicksEventFile = std::string(sysDevicesDir) + "/" + sysmanDeviceDirName + "/events/engine-total-ticks";
uint64_t totalTicksConfig = UINT64_MAX;
ret = pPmuInterface->getConfigFromEventFile(totalTicksEventFile, totalTicksConfig);
if (ret < 0) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get config for the total ticks from event file and returning error:0x%x\n", __FUNCTION__, result);
return result;
}
const std::string formatDir = std::string(sysDevicesDir) + sysmanDeviceDirName + "/format/";
ret = pPmuInterface->getConfigAfterFormat(formatDir, activeTicksConfig, engineClass->second, engineInstance, gtId);
auto ret = pPmuInterface->getPmuConfigs(sysmanDeviceDir, engineClass->second, engineInstance, gtId, activeTicksConfig, totalTicksConfig);
if (ret < 0) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get config for the active ticks after format and returning error:0x%x\n", __FUNCTION__, result);
return result;
}
ret = pPmuInterface->getConfigAfterFormat(formatDir, totalTicksConfig, engineClass->second, engineInstance, gtId);
if (ret < 0) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get config for the total ticks after format and returning error:0x%x\n", __FUNCTION__, result);
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to get configs and returning error:0x%x\n", __FUNCTION__, result);
return result;
}

View File

@@ -18,8 +18,7 @@ class PmuInterface {
virtual ~PmuInterface() = default;
virtual int64_t pmuInterfaceOpen(uint64_t config, int group, uint32_t format) = 0;
virtual int32_t pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) = 0;
virtual int32_t getConfigFromEventFile(const std::string_view &eventFile, uint64_t &config) = 0;
virtual int32_t getConfigAfterFormat(const std::string_view &formatDir, uint64_t &config, uint64_t engineClass, uint64_t engineInstance, uint64_t gt) = 0;
virtual int32_t getPmuConfigs(const std::string_view &sysmanDeviceDir, uint64_t engineClass, uint64_t engineInstance, uint64_t gtId, uint64_t &activeTicksConfig, uint64_t &totalTicksConfig) = 0;
static PmuInterface *create(LinuxSysmanImp *pLinuxSysmanImp);
};

View File

@@ -155,6 +155,37 @@ int32_t PmuInterfaceImp::getConfigAfterFormat(const std::string_view &formatDir,
return 0;
}
int32_t PmuInterfaceImp::getPmuConfigs(const std::string_view &sysmanDeviceDir, uint64_t engineClass, uint64_t engineInstance, uint64_t gtId, uint64_t &activeTicksConfig, uint64_t &totalTicksConfig) {
// The PMU configs are first fetched by reading the corresponding values from the event file in /sys/devices/xe_<bdf>/events/ directory and then bitwise ORed with the values obtained by
// shifting the parameters gt, engineClass and engineInstance with the shift value fetched from the corresponding file in /sys/devices/xe_<bdf>/format/ directory.
const std::string activeTicksEventFile = std::string(sysmanDeviceDir) + "/events/engine-active-ticks";
auto ret = getConfigFromEventFile(activeTicksEventFile, activeTicksConfig);
if (ret < 0) {
return ret;
}
const std::string totalTicksEventFile = std::string(sysmanDeviceDir) + "/events/engine-total-ticks";
ret = getConfigFromEventFile(totalTicksEventFile, totalTicksConfig);
if (ret < 0) {
return ret;
}
const std::string formatDir = std::string(sysmanDeviceDir) + "/format/";
ret = getConfigAfterFormat(formatDir, activeTicksConfig, engineClass, engineInstance, gtId);
if (ret < 0) {
return ret;
}
ret = getConfigAfterFormat(formatDir, totalTicksConfig, engineClass, engineInstance, gtId);
if (ret < 0) {
return ret;
}
return 0;
}
PmuInterfaceImp::PmuInterfaceImp(LinuxSysmanImp *pLinuxSysmanImp) {
pSysmanKmdInterface = pLinuxSysmanImp->getSysmanKmdInterface();
}

View File

@@ -25,12 +25,13 @@ class PmuInterfaceImp : public PmuInterface, NEO::NonCopyableAndNonMovableClass
~PmuInterfaceImp() override = default;
int64_t pmuInterfaceOpen(uint64_t config, int group, uint32_t format) override;
int32_t pmuRead(int fd, uint64_t *data, ssize_t sizeOfdata) override;
int32_t getConfigFromEventFile(const std::string_view &eventFile, uint64_t &config) override;
int32_t getConfigAfterFormat(const std::string_view &formatDir, uint64_t &config, uint64_t engineClass, uint64_t engineInstance, uint64_t gt) override;
int32_t getPmuConfigs(const std::string_view &sysmanDeviceDir, uint64_t engineClass, uint64_t engineInstance, uint64_t gtId, uint64_t &activeTicksConfig, uint64_t &totalTicksConfig) override;
protected:
virtual int32_t getErrorNo();
virtual int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags);
MOCKABLE_VIRTUAL int32_t getErrorNo();
MOCKABLE_VIRTUAL int64_t perfEventOpen(perf_event_attr *attr, pid_t pid, int cpu, int groupFd, uint64_t flags);
MOCKABLE_VIRTUAL int32_t getConfigFromEventFile(const std::string_view &eventFile, uint64_t &config);
MOCKABLE_VIRTUAL int32_t getConfigAfterFormat(const std::string_view &formatDir, uint64_t &config, uint64_t engineClass, uint64_t engineInstance, uint64_t gt);
decltype(&read) readFunction = read;
decltype(&syscall) syscallFunction = syscall;
SysmanKmdInterface *pSysmanKmdInterface = nullptr;

View File

@@ -23,6 +23,8 @@ constexpr uint64_t mockEvent1Val = 100u;
constexpr uint64_t mockEvent2Val = 150u;
class MockPmuInterfaceImpForSysman : public L0::Sysman::PmuInterfaceImp {
public:
using L0::Sysman::PmuInterfaceImp::getConfigAfterFormat;
using L0::Sysman::PmuInterfaceImp::getConfigFromEventFile;
using L0::Sysman::PmuInterfaceImp::getErrorNo;
using L0::Sysman::PmuInterfaceImp::perfEventOpen;
using L0::Sysman::PmuInterfaceImp::pSysmanKmdInterface;

View File

@@ -15,6 +15,8 @@ namespace ult {
class MockPmuInterfaceImp : public L0::Sysman::PmuInterfaceImp {
public:
using PmuInterfaceImp::getConfigAfterFormat;
using PmuInterfaceImp::getConfigFromEventFile;
using PmuInterfaceImp::perfEventOpen;
using PmuInterfaceImp::pSysmanKmdInterface;
int64_t mockPmuFd = -1;