fix: query drm info to aligned storages

xe topology info to byte aligned storage
xe engine info to 2 byte aligned storage
system info to 4 byte aligned storage

all other info to 8 byte aligned storage

Related-To: NEO-9038
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-10-02 14:26:33 +00:00
committed by Compute-Runtime-Automation
parent fd7c750cf7
commit 85eafc9e61
21 changed files with 105 additions and 76 deletions

View File

@@ -16,6 +16,7 @@
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/resource_info.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/gfx_core_helper.h"
@@ -601,7 +602,8 @@ std::string Drm::getDrmVersion(int fileDescriptor) {
return std::string(name);
}
std::vector<uint8_t> Drm::query(uint32_t queryId, uint32_t queryItemFlags) {
template <typename DataType>
std::vector<DataType> Drm::query(uint32_t queryId, uint32_t queryItemFlags) {
Query query{};
QueryItem queryItem{};
queryItem.queryId = queryId;
@@ -615,7 +617,7 @@ std::vector<uint8_t> Drm::query(uint32_t queryId, uint32_t queryItemFlags) {
return {};
}
auto data = std::vector<uint8_t>(queryItem.length, 0);
auto data = std::vector<DataType>(Math::divideAndRoundUp(queryItem.length, sizeof(DataType)), 0);
queryItem.dataPtr = castToUint64(data.data());
ret = ioctlHelper->ioctl(DrmIoctl::Query, &query);
@@ -932,7 +934,7 @@ int Drm::waitUserFence(uint32_t ctxId, uint64_t address, uint64_t value, ValueWi
bool Drm::querySystemInfo() {
auto request = ioctlHelper->getDrmParamValue(DrmParam::QueryHwconfigTable);
auto deviceBlobQuery = this->query(request, 0);
auto deviceBlobQuery = this->query<uint32_t>(request, 0);
if (deviceBlobQuery.empty()) {
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stdout, "%s", "INFO: System Info query failed!\n");
return false;
@@ -941,9 +943,9 @@ bool Drm::querySystemInfo() {
return true;
}
std::vector<uint8_t> Drm::getMemoryRegions() {
std::vector<uint64_t> Drm::getMemoryRegions() {
auto request = ioctlHelper->getDrmParamValue(DrmParam::QueryMemoryRegions);
return this->query(request, 0);
return this->query<uint64_t>(request, 0);
}
bool Drm::queryMemoryInfo() {
@@ -1522,4 +1524,7 @@ void Drm::waitOnUserFences(const OsContextLinux &osContext, uint64_t address, ui
completionFenceCpuAddress = ptrOffset(completionFenceCpuAddress, postSyncOffset);
}
}
template std::vector<uint16_t> Drm::query<uint16_t>(uint32_t queryId, uint32_t queryItemFlags);
template std::vector<uint32_t> Drm::query<uint32_t>(uint32_t queryId, uint32_t queryItemFlags);
template std::vector<uint64_t> Drm::query<uint64_t>(uint32_t queryId, uint32_t queryItemFlags);
} // namespace NEO

View File

@@ -238,7 +238,7 @@ class Drm : public DriverModel {
pciDomain = domain;
}
MOCKABLE_VIRTUAL std::vector<uint8_t> getMemoryRegions();
MOCKABLE_VIRTUAL std::vector<uint64_t> getMemoryRegions();
MOCKABLE_VIRTUAL bool completionFenceSupport();
@@ -253,7 +253,9 @@ class Drm : public DriverModel {
bool readSysFsAsString(const std::string &relativeFilePath, std::string &readString);
MOCKABLE_VIRTUAL std::string getSysFsPciPath();
std::unique_ptr<HwDeviceIdDrm> &getHwDeviceId() { return hwDeviceId; }
std::vector<uint8_t> query(uint32_t queryId, uint32_t queryItemFlags);
template <typename DataType>
std::vector<DataType> query(uint32_t queryId, uint32_t queryItemFlags);
static std::string getDrmVersion(int fileDescriptor);
protected:

View File

@@ -121,7 +121,7 @@ int IoctlHelper::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_t
return drmContextId;
}
std::vector<EngineCapabilities> IoctlHelper::translateToEngineCaps(const std::vector<uint8_t> &data) {
std::vector<EngineCapabilities> IoctlHelper::translateToEngineCaps(const std::vector<uint64_t> &data) {
auto engineInfo = reinterpret_cast<const drm_i915_query_engine_info *>(data.data());
std::vector<EngineCapabilities> engines;
engines.reserve(engineInfo->num_engines);
@@ -135,7 +135,7 @@ std::vector<EngineCapabilities> IoctlHelper::translateToEngineCaps(const std::ve
return engines;
}
std::vector<MemoryRegion> IoctlHelper::translateToMemoryRegions(const std::vector<uint8_t> &regionInfo) {
std::vector<MemoryRegion> IoctlHelper::translateToMemoryRegions(const std::vector<uint64_t> &regionInfo) {
auto *data = reinterpret_cast<const drm_i915_query_memory_regions *>(regionInfo.data());
auto memRegions = std::vector<MemoryRegion>(data->num_regions);
for (uint32_t i = 0; i < data->num_regions; i++) {
@@ -393,7 +393,7 @@ bool IoctlHelper::checkIfIoctlReinvokeRequired(int error, DrmIoctl ioctlRequest)
std::unique_ptr<MemoryInfo> IoctlHelper::createMemoryInfo() {
auto request = getDrmParamValue(DrmParam::QueryMemoryRegions);
auto dataQuery = drm.query(request, 0);
auto dataQuery = drm.query<uint64_t>(request, 0);
if (!dataQuery.empty()) {
auto memRegions = translateToMemoryRegions(dataQuery);
return std::make_unique<MemoryInfo>(memRegions, drm);
@@ -404,7 +404,7 @@ std::unique_ptr<MemoryInfo> IoctlHelper::createMemoryInfo() {
bool IoctlHelper::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTopologyData &topologyData, TopologyMap &topologyMap) {
auto request = this->getDrmParamValue(DrmParam::QueryTopologyInfo);
auto dataQuery = drm.query(request, 0);
auto dataQuery = drm.query<uint64_t>(request, 0);
if (dataQuery.empty()) {
return false;
}
@@ -489,7 +489,7 @@ bool IoctlHelper::translateTopologyInfo(const QueryTopologyInfo *queryTopologyIn
std::unique_ptr<EngineInfo> IoctlHelper::createEngineInfo(bool isSysmanEnabled) {
auto request = getDrmParamValue(DrmParam::QueryEngineInfo);
auto enginesQuery = drm.query(request, 0);
auto enginesQuery = drm.query<uint64_t>(request, 0);
if (enginesQuery.empty()) {
return {};
}

View File

@@ -131,10 +131,10 @@ class IoctlHelper {
virtual std::string getIoctlString(DrmIoctl ioctlRequest) const = 0;
virtual bool checkIfIoctlReinvokeRequired(int error, DrmIoctl ioctlRequest) const;
virtual std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo);
virtual std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint64_t> &regionInfo);
virtual int createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_t drmVmId, uint32_t deviceIndex);
std::vector<EngineCapabilities> translateToEngineCaps(const std::vector<uint8_t> &data);
std::vector<EngineCapabilities> translateToEngineCaps(const std::vector<uint64_t> &data);
void fillExecObject(ExecObject &execObject, uint32_t handle, uint64_t gpuAddress, uint32_t drmContextId, bool bindInfo, bool isMarkedForCapture);
void logExecObject(const ExecObject &execObject, std::stringstream &logger, size_t size);
@@ -237,7 +237,7 @@ class IoctlHelperImpl : public IoctlHelperUpstream {
}
int createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional<uint32_t> vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks) override;
std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint8_t> &regionInfo) override;
std::vector<MemoryRegion> translateToMemoryRegions(const std::vector<uint64_t> &regionInfo) override;
unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest) const override;
std::string getIoctlString(DrmIoctl ioctlRequest) const override;
};

View File

@@ -95,7 +95,7 @@ bool IoctlHelperPrelim20::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQ
uint32_t flags = classInstance->engineClass;
flags |= (classInstance->engineInstance << 8);
auto dataQuery = drm.query(request, flags);
auto dataQuery = drm.query<uint64_t>(request, flags);
if (dataQuery.empty()) {
success = false;
break;

View File

@@ -12,10 +12,10 @@
namespace NEO {
bool isQueryDrmTip(const std::vector<uint8_t> &queryInfo) {
bool isQueryDrmTip(const std::vector<uint64_t> &queryInfo) {
auto dataOnDrmTip = reinterpret_cast<const drm_i915_query_memory_regions *>(queryInfo.data());
auto lengthOnDrmTip = static_cast<uint32_t>(sizeof(drm_i915_query_memory_regions) + dataOnDrmTip->num_regions * sizeof(drm_i915_memory_region_info));
return static_cast<uint32_t>(queryInfo.size()) == lengthOnDrmTip;
return static_cast<uint32_t>(queryInfo.size() * sizeof(uint64_t)) == lengthOnDrmTip;
}
} // namespace NEO

View File

@@ -18,7 +18,7 @@ using namespace Dg1I915;
constexpr static auto gfxProduct = IGFX_DG1;
extern bool isQueryDrmTip(const std::vector<uint8_t> &queryInfo);
extern bool isQueryDrmTip(const std::vector<uint64_t> &queryInfo);
template <>
int IoctlHelperImpl<gfxProduct>::createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional<uint32_t> vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks) {
@@ -55,7 +55,7 @@ int IoctlHelperImpl<gfxProduct>::createGemExt(const MemRegionsVec &memClassInsta
return ret;
}
std::vector<MemoryRegion> translateDg1RegionInfoToMemoryRegions(const std::vector<uint8_t> &regionInfo) {
std::vector<MemoryRegion> translateDg1RegionInfoToMemoryRegions(const std::vector<uint64_t> &regionInfo) {
auto *data = reinterpret_cast<const drm_i915_query_memory_regions *>(regionInfo.data());
auto memRegions = std::vector<MemoryRegion>(data->num_regions);
for (uint32_t i = 0; i < data->num_regions; i++) {
@@ -68,7 +68,7 @@ std::vector<MemoryRegion> translateDg1RegionInfoToMemoryRegions(const std::vecto
}
template <>
std::vector<MemoryRegion> IoctlHelperImpl<gfxProduct>::translateToMemoryRegions(const std::vector<uint8_t> &regionInfo) {
std::vector<MemoryRegion> IoctlHelperImpl<gfxProduct>::translateToMemoryRegions(const std::vector<uint64_t> &regionInfo) {
if (!isQueryDrmTip(regionInfo)) {
return translateDg1RegionInfoToMemoryRegions(regionInfo);
}

View File

@@ -15,13 +15,13 @@
namespace NEO {
SystemInfo::SystemInfo(const std::vector<uint8_t> &inputData) {
SystemInfo::SystemInfo(const std::vector<uint32_t> &inputData) {
this->parseDeviceBlob(inputData);
}
void SystemInfo::parseDeviceBlob(const std::vector<uint8_t> &inputData) {
auto data = reinterpret_cast<const uint32_t *>(inputData.data());
auto dataSize = inputData.size() / sizeof(uint32_t);
void SystemInfo::parseDeviceBlob(const std::vector<uint32_t> &inputData) {
auto data = inputData.data();
auto dataSize = inputData.size();
uint32_t i = 0;
while (i + 2 < dataSize) {
DEBUG_BREAK_IF(data[i + 1] < 1);

View File

@@ -14,7 +14,7 @@ struct HardwareInfo;
struct SystemInfo {
SystemInfo(const std::vector<uint8_t> &inputData);
SystemInfo(const std::vector<uint32_t> &inputData);
~SystemInfo() = default;
@@ -36,7 +36,7 @@ struct SystemInfo {
void checkSysInfoMismatch(HardwareInfo *hwInfo);
protected:
void parseDeviceBlob(const std::vector<uint8_t> &inputData);
void parseDeviceBlob(const std::vector<uint32_t> &inputData);
uint32_t maxSlicesSupported = 0;
uint32_t maxDualSubSlicesSupported = 0;

View File

@@ -44,8 +44,8 @@ namespace NEO {
int IoctlHelperXe::xeGetQuery(Query *data) {
if (data->numItems == 1) {
QueryItem *queryItem = (QueryItem *)data->itemsPtr;
std::vector<uint8_t> *queryData = nullptr;
QueryItem *queryItem = reinterpret_cast<QueryItem *>(data->itemsPtr);
std::vector<uint64_t> *queryData = nullptr;
switch (queryItem->queryId) {
case static_cast<int>(DrmParam::QueryHwconfigTable):
queryData = &hwconfigFakei915;
@@ -54,19 +54,15 @@ int IoctlHelperXe::xeGetQuery(Query *data) {
xeLog("error: bad query 0x%x\n", queryItem->queryId);
return -1;
}
if (queryData != nullptr) {
if (queryItem->length == 0) {
queryItem->length = static_cast<int32_t>(queryData->size());
return 0;
}
if (queryItem->length != static_cast<int32_t>(queryData->size())) {
xeLog("error: incorrect length 0x%x 0x%lx\n", queryItem->length, queryData->size());
return -1;
}
memcpy_s(reinterpret_cast<void *>(queryItem->dataPtr),
queryItem->length, queryData->data(), queryItem->length);
auto queryDataSize = static_cast<int32_t>(queryData->size() * sizeof(uint64_t));
if (queryItem->length == 0) {
queryItem->length = queryDataSize;
return 0;
}
UNRECOVERABLE_IF(queryItem->length != queryDataSize);
memcpy_s(reinterpret_cast<void *>(queryItem->dataPtr),
queryItem->length, queryData->data(), queryItem->length);
return 0;
}
return -1;
}
@@ -136,7 +132,7 @@ bool IoctlHelperXe::initialize() {
if (retVal != 0 || queryConfig.size == 0) {
return false;
}
auto data = std::vector<uint8_t>(sizeof(drm_xe_query_config) + sizeof(uint64_t) * queryConfig.size, 0);
auto data = std::vector<uint64_t>(Math::divideAndRoundUp(sizeof(drm_xe_query_config) + sizeof(uint64_t) * queryConfig.size, sizeof(uint64_t)), 0);
struct drm_xe_query_config *config = reinterpret_cast<struct drm_xe_query_config *>(data.data());
queryConfig.data = castToUint64(config);
IoctlHelper::ioctl(DrmIoctl::Query, &queryConfig);
@@ -195,13 +191,14 @@ bool IoctlHelperXe::isVmBindAvailable() {
return true;
}
std::vector<uint8_t> IoctlHelperXe::queryData(uint32_t queryId) {
template <typename DataType>
std::vector<DataType> IoctlHelperXe::queryData(uint32_t queryId) {
struct drm_xe_device_query deviceQuery = {};
deviceQuery.query = queryId;
IoctlHelper::ioctl(DrmIoctl::Query, &deviceQuery);
std::vector<uint8_t> retVal(deviceQuery.size);
std::vector<DataType> retVal(Math::divideAndRoundUp(deviceQuery.size, sizeof(DataType)));
deviceQuery.data = castToUint64(retVal.data());
IoctlHelper::ioctl(DrmIoctl::Query, &deviceQuery);
@@ -210,9 +207,9 @@ std::vector<uint8_t> IoctlHelperXe::queryData(uint32_t queryId) {
}
std::unique_ptr<EngineInfo> IoctlHelperXe::createEngineInfo(bool isSysmanEnabled) {
auto enginesData = queryData(DRM_XE_DEVICE_QUERY_ENGINES);
auto enginesData = queryData<uint16_t>(DRM_XE_DEVICE_QUERY_ENGINES);
auto numberHwEngines = enginesData.size() /
auto numberHwEngines = enginesData.size() * sizeof(uint16_t) /
sizeof(struct drm_xe_engine_class_instance);
xeLog("numberHwEngines=%d\n", numberHwEngines);
@@ -268,8 +265,8 @@ inline MemoryRegion createMemoryRegionFromXeMemRegion(const drm_xe_query_mem_reg
}
std::unique_ptr<MemoryInfo> IoctlHelperXe::createMemoryInfo() {
auto memUsageData = queryData(DRM_XE_DEVICE_QUERY_MEM_USAGE);
auto gtsData = queryData(DRM_XE_DEVICE_QUERY_GTS);
auto memUsageData = queryData<uint64_t>(DRM_XE_DEVICE_QUERY_MEM_USAGE);
auto gtsData = queryData<uint64_t>(DRM_XE_DEVICE_QUERY_GTS);
if (memUsageData.empty() || gtsData.empty()) {
return {};
@@ -366,7 +363,7 @@ void IoctlHelperXe::getTopologyMap(uint32_t nTiles, std::vector<std::bitset<8>>
bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTopologyData &topologyData, TopologyMap &topologyMap) {
auto queryGtTopology = queryData(DRM_XE_DEVICE_QUERY_GT_TOPOLOGY);
auto queryGtTopology = queryData<uint8_t>(DRM_XE_DEVICE_QUERY_GT_TOPOLOGY);
auto fillMask = [](std::vector<std::bitset<8>> &vec, drm_xe_query_topology_mask *topo) {
for (uint32_t j = 0; j < topo->num_bytes; j++) {
@@ -378,7 +375,7 @@ bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTo
std::vector<std::bitset<8>> computeDss[2];
std::vector<std::bitset<8>> euDss[2];
auto topologySize = queryGtTopology.size();
uint8_t *dataPtr = reinterpret_cast<uint8_t *>(queryGtTopology.data());
auto dataPtr = queryGtTopology.data();
auto nTiles = 1u;
@@ -406,7 +403,7 @@ bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTo
uint32_t itemSize = sizeof(drm_xe_query_topology_mask) + topo->num_bytes;
topologySize -= itemSize;
dataPtr += itemSize;
dataPtr = ptrOffset(dataPtr, itemSize);
}
bool isComputeDssEmpty = false;

View File

@@ -120,7 +120,8 @@ class IoctlHelperXe : public IoctlHelper {
const char *xeGetClassName(int className);
const char *xeGetBindOpName(int bindOp);
const char *xeGetengineClassName(uint32_t engineClass);
std::vector<uint8_t> queryData(uint32_t queryId);
template <typename DataType>
std::vector<DataType> queryData(uint32_t queryId);
int xeWaitUserFence(uint64_t mask, uint16_t op, uint64_t addr, uint64_t value, int64_t timeout);
int xeVmBind(const VmBindParams &vmBindParams, bool bindOp);
void xeShowBindTable();
@@ -145,7 +146,7 @@ class IoctlHelperXe : public IoctlHelper {
std::vector<BindInfo> bindInfo;
int instance = 0;
uint32_t xeTimestampFrequency = 0;
std::vector<uint8_t> hwconfigFakei915;
std::vector<uint64_t> hwconfigFakei915;
std::vector<drm_xe_engine_class_instance> contextParamEngine;
std::vector<drm_xe_engine_class_instance> allEngines;
};