fix: separate ipVersion query and setup

Related-To: NEO-15318

Signed-off-by: Grochowski, Stanislaw <stanislaw.grochowski@intel.com>
This commit is contained in:
Grochowski, Stanislaw
2025-12-05 12:21:28 +00:00
committed by Compute-Runtime-Automation
parent 2c3b6a8760
commit 572932f830
25 changed files with 250 additions and 156 deletions

View File

@@ -17,22 +17,12 @@
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/unified_memory/usm_memory_support.h"
#include "hw_cmds.h"
#include <array>
#include <cstdio>
#include <cstring>
#include <memory>
namespace NEO {
const DeviceDescriptor deviceDescriptorTable[] = {
#define NAMEDDEVICE(devId, gt, devName) {devId, &gt::hwInfo, &gt::setupHardwareInfo, devName},
#define DEVICE(devId, gt) {devId, &gt::hwInfo, &gt::setupHardwareInfo, ""},
#include "devices.inl"
#undef DEVICE
#undef NAMEDDEVICE
{0, nullptr, nullptr, ""}};
Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) {
std::unique_ptr<Drm> drm{new Drm(std::move(hwDeviceId), rootDeviceEnvironment)};
@@ -41,25 +31,12 @@ Drm *Drm::create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironm
}
const auto usDeviceID = rootDeviceEnvironment.getHardwareInfo()->platform.usDeviceID;
const auto usRevId = rootDeviceEnvironment.getHardwareInfo()->platform.usRevId;
if (!DeviceFactory::isAllowedDeviceId(usDeviceID, debugManager.flags.FilterDeviceId.get())) {
return nullptr;
}
const DeviceDescriptor *deviceDescriptor = nullptr;
for (auto &deviceDescriptorEntry : deviceDescriptorTable) {
if (usDeviceID == deviceDescriptorEntry.deviceId) {
deviceDescriptor = &deviceDescriptorEntry;
break;
}
}
if (!deviceDescriptor) {
PRINT_STRING(debugManager.flags.PrintDebugMessages.get(), stderr,
"FATAL: Unknown device: deviceId: %04x, revisionId: %04x\n", usDeviceID, usRevId);
return nullptr;
}
if (drm->setupHardwareInfo(deviceDescriptor, true)) {
if (drm->setupHardwareInfo(usDeviceID, true)) {
return nullptr;
}

View File

@@ -23,6 +23,7 @@
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/gpu_page_fault_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/product_config_helper.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/linux/cache_info.h"
@@ -50,6 +51,8 @@
#include "shared/source/utilities/directory.h"
#include "shared/source/utilities/io_functions.h"
#include "hw_cmds.h"
#include <cstdio>
#include <cstring>
#include <fcntl.h>
@@ -58,6 +61,22 @@
#include <sstream>
namespace NEO {
const DeviceDescriptor deviceDescriptorTable[] = {
#define NAMEDDEVICE(devId, gt, devName) {devId, &gt::hwInfo, &gt::setupHardwareInfo, devName},
#define DEVICE(devId, gt) {devId, &gt::hwInfo, &gt::setupHardwareInfo, ""},
#include "devices.inl"
#undef DEVICE
#undef NAMEDDEVICE
{0, nullptr, nullptr, ""}};
const DeviceDescriptor *Drm::getDeviceDescriptor(uint32_t usDeviceID) {
for (auto &deviceDescriptorEntry : deviceDescriptorTable) {
if (usDeviceID == deviceDescriptorEntry.deviceId) {
return &deviceDescriptorEntry;
}
}
return nullptr;
}
Drm::Drm(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment)
: DriverModel(DriverModelType::drm),
@@ -464,12 +483,20 @@ int Drm::getErrno() {
return errno;
}
int Drm::setupHardwareInfo(const DeviceDescriptor *device, bool setupFeatureTableAndWorkaroundTable) {
int Drm::setupHardwareInfo(uint32_t deviceId, bool setupFeatureTableAndWorkaroundTable) {
const DeviceDescriptor *deviceDescriptor = getDeviceDescriptor(deviceId);
if (!deviceDescriptor) {
PRINT_STRING(debugManager.flags.PrintDebugMessages.get(), stderr,
"FATAL: Unknown device: deviceId: %04x, revisionId: %04x\n", deviceId, rootDeviceEnvironment.getHardwareInfo()->platform.usRevId);
return -1;
}
const auto usDeviceIdOverride = rootDeviceEnvironment.getHardwareInfo()->platform.usDeviceID;
const auto usRevIdOverride = rootDeviceEnvironment.getHardwareInfo()->platform.usRevId;
// reset hwInfo and apply overrides
rootDeviceEnvironment.setHwInfo(device->pHwInfo);
rootDeviceEnvironment.setHwInfo(deviceDescriptor->pHwInfo);
HardwareInfo *hwInfo = rootDeviceEnvironment.getMutableHardwareInfo();
hwInfo->platform.usDeviceID = usDeviceIdOverride;
hwInfo->platform.usRevId = usRevIdOverride;
@@ -489,11 +516,12 @@ int Drm::setupHardwareInfo(const DeviceDescriptor *device, bool setupFeatureTabl
const auto productFamily = hwInfo->platform.eProductFamily;
setupIoctlHelper(productFamily);
hwInfo->ipVersion = ioctlHelper->queryHwIpVersion(productFamily);
ioctlHelper->setupIpVersion();
rootDeviceEnvironment.initReleaseHelper();
auto releaseHelper = rootDeviceEnvironment.getReleaseHelper();
device->setupHardwareInfo(hwInfo, setupFeatureTableAndWorkaroundTable, releaseHelper);
deviceDescriptor->setupHardwareInfo(hwInfo, setupFeatureTableAndWorkaroundTable, releaseHelper);
this->adjustSharedSystemMemCapabilities();
querySystemInfo();
@@ -652,7 +680,7 @@ int Drm::setupHardwareInfo(const DeviceDescriptor *device, bool setupFeatureTabl
rootDeviceEnvironment.setRcsExposure();
setupCacheInfo(*hwInfo);
hwInfo->capabilityTable.deviceName = device->devName;
hwInfo->capabilityTable.deviceName = deviceDescriptor->devName;
rootDeviceEnvironment.initializeGfxCoreHelperFromHwInfo();

View File

@@ -120,7 +120,7 @@ class Drm : public DriverModel {
uint32_t getVirtualMemoryAddressSpace(uint32_t vmId) const;
MOCKABLE_VIRTUAL int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo, const bool forcePagingFence);
MOCKABLE_VIRTUAL int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo);
int setupHardwareInfo(const DeviceDescriptor *, bool);
int setupHardwareInfo(uint32_t deviceId, bool);
void setupSystemInfo(HardwareInfo *hwInfo, SystemInfo *sysInfo);
void setupCacheInfo(const HardwareInfo &hwInfo);
MOCKABLE_VIRTUAL void getPrelimVersion(std::string &prelimVersion);
@@ -288,6 +288,7 @@ class Drm : public DriverModel {
void setupIoctlHelper(const PRODUCT_FAMILY productFamily);
void queryAndSetVmBindPatIndexProgrammingSupport();
bool queryDeviceIdAndRevision();
MOCKABLE_VIRTUAL const DeviceDescriptor *getDeviceDescriptor(uint32_t deviceId);
static uint64_t alignUpGttSize(uint64_t inputGttSize);
#pragma pack(1)

View File

@@ -47,6 +47,9 @@ int IoctlHelper::ioctl(int fd, DrmIoctl request, void *arg) {
void IoctlHelper::setupIpVersion() {
auto &rootDeviceEnvironment = drm.getRootDeviceEnvironment();
auto &hwInfo = *rootDeviceEnvironment.getMutableHardwareInfo();
if (hwInfo.ipVersion.value) {
return;
}
auto &compilerProductHelper = rootDeviceEnvironment.getHelper<CompilerProductHelper>();
hwInfo.ipVersion.value = compilerProductHelper.getHwIpVersion(hwInfo);
}

View File

@@ -11,6 +11,7 @@
#include "shared/source/os_interface/linux/drm_allocation.h"
#include "shared/source/os_interface/linux/drm_buffer_object.h"
#include "shared/source/os_interface/linux/drm_debug.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/drm_wrappers.h"
#include "shared/source/utilities/stackvec.h"
@@ -197,7 +198,7 @@ class IoctlHelper {
virtual bool getFabricLatency(uint32_t fabricId, uint32_t &latency, uint32_t &bandwidth) = 0;
virtual bool requiresUserFenceSetup(bool bind) const = 0;
virtual void *pciBarrierMmap() { return nullptr; };
virtual void setupIpVersion();
void setupIpVersion();
virtual bool isImmediateVmBindRequired() const { return false; }
virtual void configureCcsMode(std::vector<std::string> &files, const std::string expectedFilePrefix, uint32_t ccsMode,
@@ -257,6 +258,7 @@ class IoctlHelper {
virtual bool isSmallBarConfigAllowed() const = 0;
virtual bool overrideMaxSlicesSupported() const { return false; }
virtual bool is2MBSizeAlignmentRequired(AllocationType allocationType) const { return false; }
virtual uint32_t queryHwIpVersion(PRODUCT_FAMILY productFamily) { return 0; }
protected:
Drm &drm;
@@ -447,7 +449,6 @@ class IoctlHelperPrelim20 : public IoctlHelperI915 {
bool getFabricLatency(uint32_t fabricId, uint32_t &latency, uint32_t &bandwidth) override;
bool requiresUserFenceSetup(bool bind) const override;
void *pciBarrierMmap() override;
void setupIpVersion() override;
bool getTopologyDataAndMap(HardwareInfo &hwInfo, DrmQueryTopologyData &topologyData, TopologyMap &topologyMap) override;
uint32_t registerResource(DrmResourceClass classType, const void *data, size_t size) override;
bool registerResourceClasses() override;
@@ -465,9 +466,9 @@ class IoctlHelperPrelim20 : public IoctlHelperI915 {
uint32_t getStatusForResetStats(bool banned) override;
void registerBOBindHandle(Drm *drm, DrmAllocation *drmAllocation) override;
EngineCapabilities::Flags getEngineCapabilitiesFlags(uint64_t capabilities) const override;
uint32_t queryHwIpVersion(PRODUCT_FAMILY productFamily) override;
protected:
bool queryHwIpVersion(EngineClassInstance &engineInfo, HardwareIpVersion &ipVersion, int &ret);
StackVec<uint32_t, size_t(DrmResourceClass::maxSize)> classHandles;
bool handleExecBufferInNonBlockMode = false;
std::string generateUUID();

View File

@@ -1050,23 +1050,33 @@ void *IoctlHelperPrelim20::pciBarrierMmap() {
return SysCalls::mmap(NULL, MemoryConstants::pageSize, PROT_WRITE, MAP_SHARED, drm.getFileDescriptor(), pciBarrierMmapOffset);
}
bool IoctlHelperPrelim20::queryHwIpVersion(EngineClassInstance &engineInfo, HardwareIpVersion &ipVersion, int &ret) {
uint32_t IoctlHelperPrelim20::queryHwIpVersion(PRODUCT_FAMILY productFamily) {
auto productHelper = ProductHelper::create(productFamily);
if (!productHelper || !productHelper->isPlatformQuerySupported()) {
return 0;
}
EngineClassInstance engineInfo = {static_cast<uint16_t>(getDrmParamValue(DrmParam::engineClassRender)), 0};
QueryItem queryItem{};
queryItem.queryId = PRELIM_DRM_I915_QUERY_HW_IP_VERSION;
Query query{};
query.itemsPtr = reinterpret_cast<uint64_t>(&queryItem);
query.numItems = 1u;
ret = ioctl(DrmIoctl::query, &query);
int ret = ioctl(DrmIoctl::query, &query);
if (ret != 0) {
return false;
int err = drm.getErrno();
PRINT_STRING(debugManager.flags.PrintDebugMessages.get(), stderr,
"ioctl(PRELIM_DRM_I915_QUERY_HW_IP_VERSION) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
return 0;
}
if (queryItem.length != sizeof(prelim_drm_i915_query_hw_ip_version)) {
PRINT_STRING(debugManager.flags.PrintDebugMessages.get(), stderr, "%s\n",
"Size got from PRELIM_DRM_I915_QUERY_HW_IP_VERSION query does not match PrelimI915::prelim_drm_i915_query_hw_ip_version size");
return false;
return 0;
}
prelim_drm_i915_query_hw_ip_version queryHwIpVersion{};
@@ -1076,14 +1086,18 @@ bool IoctlHelperPrelim20::queryHwIpVersion(EngineClassInstance &engineInfo, Hard
ret = ioctl(DrmIoctl::query, &query);
if (ret != 0) {
return false;
int err = drm.getErrno();
PRINT_STRING(debugManager.flags.PrintDebugMessages.get(), stderr,
"ioctl(PRELIM_DRM_I915_QUERY_HW_IP_VERSION) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
return 0;
}
HardwareIpVersion ipVersion{};
ipVersion.architecture = queryHwIpVersion.arch;
ipVersion.release = queryHwIpVersion.release;
ipVersion.revision = queryHwIpVersion.stepping;
return true;
return ipVersion.value;
}
bool IoctlHelperPrelim20::initialize() {
@@ -1091,32 +1105,6 @@ bool IoctlHelperPrelim20::initialize() {
return true;
}
void IoctlHelperPrelim20::setupIpVersion() {
auto &rootDeviceEnvironment = drm.getRootDeviceEnvironment();
auto hwInfo = rootDeviceEnvironment.getMutableHardwareInfo();
auto &productHelper = drm.getRootDeviceEnvironment().getHelper<ProductHelper>();
EngineClassInstance engineInfo = {static_cast<uint16_t>(getDrmParamValue(DrmParam::engineClassRender)), 0};
int ret = 0;
auto isPlatformQuerySupported = productHelper.isPlatformQuerySupported();
bool result = false;
if (isPlatformQuerySupported) {
result = queryHwIpVersion(engineInfo, hwInfo->ipVersion, ret);
if (result == false && ret != 0) {
int err = drm.getErrno();
PRINT_STRING(debugManager.flags.PrintDebugMessages.get(), stderr,
"ioctl(PRELIM_DRM_I915_QUERY_HW_IP_VERSION) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
}
}
if (result == false) {
IoctlHelper::setupIpVersion();
}
}
bool IoctlHelperPrelim20::registerResourceClasses() {
for (auto &classNameUUID : classNamesToUuid) {
auto className = classNameUUID.first;

View File

@@ -455,24 +455,10 @@ size_t IoctlHelperXe::getLocalMemoryRegionsSize(const MemoryInfo *memoryInfo, ui
return size;
}
void IoctlHelperXe::setupIpVersion() {
auto &rootDeviceEnvironment = drm.getRootDeviceEnvironment();
auto hwInfo = rootDeviceEnvironment.getMutableHardwareInfo();
if (auto hwIpVersion = GtIpVersion{}; queryHwIpVersion(hwIpVersion)) {
hwInfo->ipVersion.architecture = hwIpVersion.major;
hwInfo->ipVersion.release = hwIpVersion.minor;
hwInfo->ipVersion.revision = hwIpVersion.revision;
} else {
XELOG("No HW IP version received from drm_xe_gt. Falling back to default value.");
IoctlHelper::setupIpVersion();
}
}
bool IoctlHelperXe::queryHwIpVersion(GtIpVersion &gtIpVersion) {
uint32_t IoctlHelperXe::queryHwIpVersion(PRODUCT_FAMILY productFamily) {
auto gtListData = queryData<uint64_t>(DRM_XE_DEVICE_QUERY_GT_LIST);
if (gtListData.empty()) {
return false;
return 0;
}
auto xeGtListData = reinterpret_cast<drm_xe_query_gt_list *>(gtListData.data());
@@ -482,12 +468,14 @@ bool IoctlHelperXe::queryHwIpVersion(GtIpVersion &gtIpVersion) {
if (gtEntry.type == DRM_XE_QUERY_GT_TYPE_MEDIA || gtEntry.ip_ver_major == 0u) {
continue;
}
gtIpVersion.major = gtEntry.ip_ver_major;
gtIpVersion.minor = gtEntry.ip_ver_minor;
gtIpVersion.revision = gtEntry.ip_ver_rev;
return true;
HardwareIpVersion ipVersion{};
ipVersion.architecture = gtEntry.ip_ver_major;
ipVersion.release = gtEntry.ip_ver_minor;
ipVersion.revision = gtEntry.ip_ver_rev;
return ipVersion.value;
}
return false;
return 0;
}
bool IoctlHelperXe::setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) {

View File

@@ -118,7 +118,6 @@ class IoctlHelperXe : public IoctlHelper {
std::unique_ptr<EngineInfo> createEngineInfo(bool isSysmanEnabled) override;
std::unique_ptr<MemoryInfo> createMemoryInfo() override;
size_t getLocalMemoryRegionsSize(const MemoryInfo *memoryInfo, uint32_t subDevicesCount, uint32_t deviceBitfield) const override;
void setupIpVersion() override;
bool setGpuCpuTimes(TimeStampData *pGpuCpuTime, OSTime *osTime) override;
bool getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd) override;
@@ -146,6 +145,7 @@ class IoctlHelperXe : public IoctlHelper {
void *pciBarrierMmap() override;
bool retrieveMmapOffsetForBufferObject(BufferObject &bo, uint64_t flags, uint64_t &offset) override;
bool is2MBSizeAlignmentRequired(AllocationType allocationType) const override;
uint32_t queryHwIpVersion(PRODUCT_FAMILY productFamily) override;
protected:
static constexpr uint32_t maxContextSetProperties = 4;
@@ -192,7 +192,6 @@ class IoctlHelperXe : public IoctlHelper {
uint16_t minor;
uint16_t revision;
};
bool queryHwIpVersion(GtIpVersion &gtIpVersion);
bool isLowLatencyHintAvailable = false;
int maxExecQueuePriority = 0;