1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <level_zero/zes_api.h>
#include "igfxfmid.h"
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
namespace NEO {
class Drm;
} // namespace NEO
namespace L0 {
namespace Sysman {
class FsAccessInterface;
class ProcFsAccessInterface;
class SysFsAccessInterface;
class PmuInterface;
class LinuxSysmanImp;
class SysmanProductHelper;
typedef std::pair<std::string, std::string> valuePair;
enum EngineClass {
ENGINE_CLASS_RENDER = 0,
ENGINE_CLASS_COPY = 1,
ENGINE_CLASS_VIDEO = 2,
ENGINE_CLASS_VIDEO_ENHANCE = 3,
ENGINE_CLASS_COMPUTE = 4,
ENGINE_CLASS_INVALID = -1
};
const std::multimap<uint16_t, zes_engine_group_t> engineClassToEngineGroup = {
{static_cast<uint16_t>(EngineClass::ENGINE_CLASS_RENDER), ZES_ENGINE_GROUP_RENDER_SINGLE},
{static_cast<uint16_t>(EngineClass::ENGINE_CLASS_VIDEO), ZES_ENGINE_GROUP_MEDIA_DECODE_SINGLE},
{static_cast<uint16_t>(EngineClass::ENGINE_CLASS_VIDEO), ZES_ENGINE_GROUP_MEDIA_ENCODE_SINGLE},
{static_cast<uint16_t>(EngineClass::ENGINE_CLASS_COPY), ZES_ENGINE_GROUP_COPY_SINGLE},
{static_cast<uint16_t>(EngineClass::ENGINE_CLASS_COMPUTE), ZES_ENGINE_GROUP_COMPUTE_SINGLE},
{static_cast<uint16_t>(EngineClass::ENGINE_CLASS_VIDEO_ENHANCE), ZES_ENGINE_GROUP_MEDIA_ENHANCEMENT_SINGLE}};
const std::multimap<zes_engine_group_t, uint16_t> engineGroupToEngineClass = {
{ZES_ENGINE_GROUP_RENDER_SINGLE, static_cast<uint16_t>(EngineClass::ENGINE_CLASS_RENDER)},
{ZES_ENGINE_GROUP_MEDIA_DECODE_SINGLE, static_cast<uint16_t>(EngineClass::ENGINE_CLASS_VIDEO)},
{ZES_ENGINE_GROUP_MEDIA_ENCODE_SINGLE, static_cast<uint16_t>(EngineClass::ENGINE_CLASS_VIDEO)},
{ZES_ENGINE_GROUP_COPY_SINGLE, static_cast<uint16_t>(EngineClass::ENGINE_CLASS_COPY)},
{ZES_ENGINE_GROUP_COMPUTE_SINGLE, static_cast<uint16_t>(EngineClass::ENGINE_CLASS_COMPUTE)},
{ZES_ENGINE_GROUP_MEDIA_ENHANCEMENT_SINGLE, static_cast<uint16_t>(EngineClass::ENGINE_CLASS_VIDEO_ENHANCE)}};
enum class SysfsName {
sysfsNameMinFrequency,
sysfsNameMaxFrequency,
sysfsNameMinDefaultFrequency,
sysfsNameMaxDefaultFrequency,
sysfsNameBoostFrequency,
sysfsNameCurrentFrequency,
sysfsNameTdpFrequency,
sysfsNameActualFrequency,
sysfsNameEfficientFrequency,
sysfsNameMaxValueFrequency,
sysfsNameMinValueFrequency,
sysfsNameThrottleReasonStatus,
sysfsNameThrottleReasonPL1,
sysfsNameThrottleReasonPL2,
sysfsNameThrottleReasonPL4,
sysfsNameThrottleReasonThermal,
sysfsNameSustainedPowerLimit,
sysfsNameSustainedPowerLimitInterval,
sysfsNameEnergyCounterNode,
sysfsNameDefaultPowerLimit,
sysfsNameCriticalPowerLimit,
sysfsNameStandbyModeControl,
sysfsNameMemoryAddressRange,
sysfsNameMaxMemoryFrequency,
sysfsNameMinMemoryFrequency,
sysfsNameSchedulerTimeout,
sysfsNameSchedulerTimeslice,
sysfsNameSchedulerWatchDogTimeout,
sysfsNameSchedulerWatchDogTimeoutMaximum,
sysfsNamePerformanceBaseFrequencyFactor,
sysfsNamePerformanceMediaFrequencyFactor,
sysfsNamePerformanceBaseFrequencyFactorScale,
sysfsNamePerformanceMediaFrequencyFactorScale,
sysfsNamePerformanceSystemPowerBalance,
};
enum class SysfsValueUnit {
milli,
micro,
unAvailable,
};
class SysmanKmdInterface {
public:
SysmanKmdInterface();
virtual ~SysmanKmdInterface();
static std::unique_ptr<SysmanKmdInterface> create(NEO::Drm &drm, SysmanProductHelper *pSysmanProductHelper);
virtual std::string getBasePath(uint32_t subDeviceId) const = 0;
virtual std::string getSysfsFilePath(SysfsName sysfsName, uint32_t subDeviceId, bool baseDirectoryExists) = 0;
virtual std::string getSysfsFilePathForPhysicalMemorySize(uint32_t subDeviceId) = 0;
virtual int64_t getEngineActivityFd(zes_engine_group_t engineGroup, uint32_t engineInstance, uint32_t subDeviceId, PmuInterface *const &pmuInterface) = 0;
virtual std::string getHwmonName(uint32_t subDeviceId, bool isSubdevice) const = 0;
virtual bool isStandbyModeControlAvailable() const = 0;
virtual bool clientInfoAvailableInFdInfo() const = 0;
virtual bool isGroupEngineInterfaceAvailable() const = 0;
ze_result_t initFsAccessInterface(const NEO::Drm &drm);
virtual bool isBaseFrequencyFactorAvailable() const = 0;
virtual bool isMediaFrequencyFactorAvailable() const = 0;
virtual bool isSystemPowerBalanceAvailable() const = 0;
FsAccessInterface *getFsAccess();
ProcFsAccessInterface *getProcFsAccess();
SysFsAccessInterface *getSysFsAccess();
virtual std::string getEngineBasePath(uint32_t subDeviceId) const = 0;
virtual ze_result_t getNumEngineTypeAndInstances(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines,
LinuxSysmanImp *pLinuxSysmanImp,
SysFsAccessInterface *pSysfsAccess,
ze_bool_t onSubdevice,
uint32_t subdeviceId) = 0;
ze_result_t getNumEngineTypeAndInstancesForDevice(std::string engineDir, std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines,
SysFsAccessInterface *pSysfsAccess);
ze_result_t getNumEngineTypeAndInstancesForSubDevices(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines,
NEO::Drm *pDrm,
uint32_t subdeviceId);
SysfsValueUnit getNativeUnit(const SysfsName sysfsName);
void convertSysfsValueUnit(const SysfsValueUnit dstUnit, const SysfsValueUnit srcUnit,
const uint64_t srcValue, uint64_t &dstValue) const;
virtual std::optional<std::string> getEngineClassString(uint16_t engineClass) = 0;
virtual uint32_t getEventType(const bool isIntegratedDevice) = 0;
virtual bool isDefaultFrequencyAvailable() const = 0;
virtual bool isBoostFrequencyAvailable() const = 0;
virtual bool isTdpFrequencyAvailable() const = 0;
virtual bool isPhysicalMemorySizeSupported() const = 0;
virtual void getWedgedStatus(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState) = 0;
virtual bool isSettingTimeoutModeSupported() const = 0;
virtual bool isSettingExclusiveModeSupported() const = 0;
virtual void getDriverVersion(char (&driverVersion)[ZES_STRING_PROPERTY_SIZE]) = 0;
protected:
std::unique_ptr<FsAccessInterface> pFsAccess;
std::unique_ptr<ProcFsAccessInterface> pProcfsAccess;
std::unique_ptr<SysFsAccessInterface> pSysfsAccess;
virtual const std::map<SysfsName, SysfsValueUnit> &getSysfsNameToNativeUnitMap() = 0;
uint32_t getEventTypeImpl(std::string &dirName, const bool isIntegratedDevice);
void getWedgedStatusImpl(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState);
};
class SysmanKmdInterfaceI915 {
protected:
static const std::map<uint16_t, std::string> i915EngineClassToSysfsEngineMap;
static std::string getBasePathI915(uint32_t subDeviceId);
static std::string getHwmonNameI915(uint32_t subDeviceId, bool isSubdevice);
static std::optional<std::string> getEngineClassStringI915(uint16_t engineClass);
static std::string getEngineBasePathI915(uint32_t subDeviceId);
};
class SysmanKmdInterfaceI915Upstream : public SysmanKmdInterface, SysmanKmdInterfaceI915 {
public:
SysmanKmdInterfaceI915Upstream(SysmanProductHelper *pSysmanProductHelper);
~SysmanKmdInterfaceI915Upstream() override;
std::string getBasePath(uint32_t subDeviceId) const override;
std::string getSysfsFilePath(SysfsName sysfsName, uint32_t subDeviceId, bool baseDirectoryExists) override;
std::string getSysfsFilePathForPhysicalMemorySize(uint32_t subDeviceId) override;
int64_t getEngineActivityFd(zes_engine_group_t engineGroup, uint32_t engineInstance, uint32_t subDeviceId, PmuInterface *const &pmuInterface) override;
std::string getHwmonName(uint32_t subDeviceId, bool isSubdevice) const override;
bool isStandbyModeControlAvailable() const override { return true; }
bool clientInfoAvailableInFdInfo() const override { return false; }
bool isGroupEngineInterfaceAvailable() const override { return false; }
std::string getEngineBasePath(uint32_t subDeviceId) const override;
ze_result_t getNumEngineTypeAndInstances(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines,
LinuxSysmanImp *pLinuxSysmanImp,
SysFsAccessInterface *pSysfsAccess,
ze_bool_t onSubdevice,
uint32_t subdeviceId) override;
std::optional<std::string> getEngineClassString(uint16_t engineClass) override;
uint32_t getEventType(const bool isIntegratedDevice) override;
bool isBaseFrequencyFactorAvailable() const override { return false; }
bool isMediaFrequencyFactorAvailable() const override { return true; }
bool isSystemPowerBalanceAvailable() const override { return false; }
bool isDefaultFrequencyAvailable() const override { return true; }
bool isBoostFrequencyAvailable() const override { return true; }
bool isTdpFrequencyAvailable() const override { return true; }
bool isPhysicalMemorySizeSupported() const override { return false; }
void getWedgedStatus(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState) override;
bool isSettingTimeoutModeSupported() const override { return true; }
bool isSettingExclusiveModeSupported() const override { return true; }
void getDriverVersion(char (&driverVersion)[ZES_STRING_PROPERTY_SIZE]) override;
protected:
std::map<SysfsName, valuePair> sysfsNameToFileMap;
std::map<SysfsName, SysfsValueUnit> sysfsNameToNativeUnitMap;
void initSysfsNameToFileMap(SysmanProductHelper *pSysmanProductHelper);
void initSysfsNameToNativeUnitMap(SysmanProductHelper *pSysmanProductHelper);
const std::map<SysfsName, SysfsValueUnit> &getSysfsNameToNativeUnitMap() override {
return sysfsNameToNativeUnitMap;
}
};
class SysmanKmdInterfaceI915Prelim : public SysmanKmdInterface, SysmanKmdInterfaceI915 {
public:
SysmanKmdInterfaceI915Prelim(SysmanProductHelper *pSysmanProductHelper);
~SysmanKmdInterfaceI915Prelim() override;
std::string getBasePath(uint32_t subDeviceId) const override;
std::string getSysfsFilePath(SysfsName sysfsName, uint32_t subDeviceId, bool baseDirectoryExists) override;
std::string getSysfsFilePathForPhysicalMemorySize(uint32_t subDeviceId) override;
int64_t getEngineActivityFd(zes_engine_group_t engineGroup, uint32_t engineInstance, uint32_t subDeviceId, PmuInterface *const &pmuInterface) override;
std::string getHwmonName(uint32_t subDeviceId, bool isSubdevice) const override;
bool isStandbyModeControlAvailable() const override { return true; }
bool clientInfoAvailableInFdInfo() const override { return false; }
bool isGroupEngineInterfaceAvailable() const override { return true; }
std::string getEngineBasePath(uint32_t subDeviceId) const override;
ze_result_t getNumEngineTypeAndInstances(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines,
LinuxSysmanImp *pLinuxSysmanImp,
SysFsAccessInterface *pSysfsAccess,
ze_bool_t onSubdevice,
uint32_t subdeviceId) override;
std::optional<std::string> getEngineClassString(uint16_t engineClass) override;
uint32_t getEventType(const bool isIntegratedDevice) override;
bool isBaseFrequencyFactorAvailable() const override { return true; }
bool isMediaFrequencyFactorAvailable() const override { return true; }
bool isSystemPowerBalanceAvailable() const override { return true; }
bool isDefaultFrequencyAvailable() const override { return true; }
bool isBoostFrequencyAvailable() const override { return true; }
bool isTdpFrequencyAvailable() const override { return true; }
bool isPhysicalMemorySizeSupported() const override { return true; }
void getWedgedStatus(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState) override;
bool isSettingTimeoutModeSupported() const override { return true; }
bool isSettingExclusiveModeSupported() const override { return true; }
void getDriverVersion(char (&driverVersion)[ZES_STRING_PROPERTY_SIZE]) override;
protected:
std::map<SysfsName, valuePair> sysfsNameToFileMap;
std::map<SysfsName, SysfsValueUnit> sysfsNameToNativeUnitMap;
void initSysfsNameToFileMap(SysmanProductHelper *pSysmanProductHelper);
void initSysfsNameToNativeUnitMap(SysmanProductHelper *pSysmanProductHelper);
const std::map<SysfsName, SysfsValueUnit> &getSysfsNameToNativeUnitMap() override {
return sysfsNameToNativeUnitMap;
}
};
class SysmanKmdInterfaceXe : public SysmanKmdInterface {
public:
SysmanKmdInterfaceXe(SysmanProductHelper *pSysmanProductHelper);
~SysmanKmdInterfaceXe() override;
std::string getBasePath(uint32_t subDeviceId) const override;
std::string getSysfsFilePath(SysfsName sysfsName, uint32_t subDeviceId, bool baseDirectoryExists) override;
std::string getSysfsFilePathForPhysicalMemorySize(uint32_t subDeviceId) override;
std::string getEngineBasePath(uint32_t subDeviceId) const override;
int64_t getEngineActivityFd(zes_engine_group_t engineGroup, uint32_t engineInstance, uint32_t subDeviceId, PmuInterface *const &pmuInterface) override;
std::string getHwmonName(uint32_t subDeviceId, bool isSubdevice) const override;
bool isStandbyModeControlAvailable() const override { return false; }
bool clientInfoAvailableInFdInfo() const override { return true; }
bool isGroupEngineInterfaceAvailable() const override { return true; }
ze_result_t getNumEngineTypeAndInstances(std::map<zes_engine_type_flag_t, std::vector<std::string>> &mapOfEngines,
LinuxSysmanImp *pLinuxSysmanImp,
SysFsAccessInterface *pSysfsAccess,
ze_bool_t onSubdevice,
uint32_t subdeviceId) override;
std::optional<std::string> getEngineClassString(uint16_t engineClass) override;
uint32_t getEventType(const bool isIntegratedDevice) override;
bool isBaseFrequencyFactorAvailable() const override { return false; }
bool isMediaFrequencyFactorAvailable() const override { return false; }
bool isSystemPowerBalanceAvailable() const override { return false; }
bool isDefaultFrequencyAvailable() const override { return false; }
bool isBoostFrequencyAvailable() const override { return false; }
bool isTdpFrequencyAvailable() const override { return false; }
bool isPhysicalMemorySizeSupported() const override { return true; }
// Wedged state is not supported in XE.
void getWedgedStatus(LinuxSysmanImp *pLinuxSysmanImp, zes_device_state_t *pState) override{};
bool isSettingTimeoutModeSupported() const override { return false; }
bool isSettingExclusiveModeSupported() const override { return false; }
void getDriverVersion(char (&driverVersion)[ZES_STRING_PROPERTY_SIZE]) override;
protected:
std::map<SysfsName, valuePair> sysfsNameToFileMap;
std::map<SysfsName, SysfsValueUnit> sysfsNameToNativeUnitMap;
void initSysfsNameToFileMap(SysmanProductHelper *pSysmanProductHelper);
void initSysfsNameToNativeUnitMap(SysmanProductHelper *pSysmanProductHelper);
const std::map<SysfsName, SysfsValueUnit> &getSysfsNameToNativeUnitMap() override {
return sysfsNameToNativeUnitMap;
}
static uint64_t getPmuEngineConfig(zes_engine_group_t engineGroup, uint32_t engineInstance, uint32_t subDeviceId);
};
} // namespace Sysman
} // namespace L0
|