From 07a11e640f8a279f3832918a1d59f4f9229b4f29 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 1 Aug 2024 09:59:15 +0000 Subject: [PATCH] refactor: include xe header in dedicated namespace avoid redefinition issue in case of integrating multiple xe drm versions define mock drm xe in inl file to provide xe definitions for mock members Signed-off-by: Mateusz Jablonski --- .../kmd_interface/sysman_kmd_interface_xe.cpp | 3 +- .../scheduler/linux/mock_sysfs_scheduler.h | 3 +- .../os_interface/linux/xe/ioctl_helper_xe.cpp | 8 ++- .../os_interface/linux/xe/ioctl_helper_xe.h | 14 ++-- .../linux/xe/ioctl_helper_xe_perf.cpp | 5 +- shared/source/os_interface/linux/xe/xedrm.h | 20 ++++++ .../os_interface/linux/xe/CMakeLists.txt | 1 - .../linux/xe/ioctl_helper_xe_perf_tests.cpp | 3 +- .../linux/xe/ioctl_helper_xe_tests.cpp | 9 ++- .../os_interface/linux/xe/mock_drm_xe.h | 18 +++++ ...octl_helper_xe_tests.h => mock_drm_xe.inl} | 68 +------------------ .../linux/xe/mock_ioctl_helper_xe.h | 59 ++++++++++++++++ 12 files changed, 124 insertions(+), 87 deletions(-) create mode 100644 shared/source/os_interface/linux/xe/xedrm.h create mode 100644 shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.h rename shared/test/unit_test/os_interface/linux/xe/{ioctl_helper_xe_tests.h => mock_drm_xe.inl} (86%) create mode 100644 shared/test/unit_test/os_interface/linux/xe/mock_ioctl_helper_xe.h diff --git a/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_xe.cpp b/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_xe.cpp index 0a7856e555..c13160fa0f 100644 --- a/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_xe.cpp +++ b/level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface_xe.cpp @@ -7,14 +7,13 @@ #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/engine_info.h" +#include "shared/source/os_interface/linux/xe/xedrm.h" #include "level_zero/sysman/source/shared/linux/kmd_interface/sysman_kmd_interface.h" #include "level_zero/sysman/source/shared/linux/pmu/sysman_pmu_imp.h" #include "level_zero/sysman/source/shared/linux/product_helper/sysman_product_helper.h" #include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" -#include "xe_drm.h" - namespace L0 { namespace Sysman { diff --git a/level_zero/sysman/test/unit_tests/sources/scheduler/linux/mock_sysfs_scheduler.h b/level_zero/sysman/test/unit_tests/sources/scheduler/linux/mock_sysfs_scheduler.h index 42c5272001..a5df3094d6 100644 --- a/level_zero/sysman/test/unit_tests/sources/scheduler/linux/mock_sysfs_scheduler.h +++ b/level_zero/sysman/test/unit_tests/sources/scheduler/linux/mock_sysfs_scheduler.h @@ -8,13 +8,12 @@ #pragma once #include "shared/source/os_interface/linux/engine_info.h" +#include "shared/source/os_interface/linux/xe/xedrm.h" #include "level_zero/sysman/source/api/scheduler/linux/sysman_os_scheduler_imp.h" #include "level_zero/sysman/source/shared/linux/sysman_fs_access_interface.h" #include "level_zero/sysman/test/unit_tests/sources/linux/mock_sysman_hw_device_id.h" -#include "xe_drm.h" - namespace L0 { namespace Sysman { namespace ult { diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index ab920aebc5..7b130f3f27 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -26,10 +26,9 @@ #include "shared/source/os_interface/linux/memory_info.h" #include "shared/source/os_interface/linux/os_context_linux.h" #include "shared/source/os_interface/linux/sys_calls.h" +#include "shared/source/os_interface/linux/xe/xedrm.h" #include "shared/source/os_interface/os_time.h" -#include "xe_drm.h" - #include #include #include @@ -178,7 +177,10 @@ bool IoctlHelperXe::initialize() { hwInfo->platform.usRevId = static_cast((config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID] >> 16) & 0xff); hwInfo->capabilityTable.gpuAddressSpace = (1ull << config->info[DRM_XE_QUERY_CONFIG_VA_BITS]) - 1; - hwInfo->capabilityTable.cxlType = getCxlType(config); + hwInfo->capabilityTable.cxlType = 0; + if (getCxlType() && config->num_params > *getCxlType()) { + hwInfo->capabilityTable.cxlType = static_cast(config->info[*getCxlType()]); + } queryGtListData = queryData(DRM_XE_DEVICE_QUERY_GT_LIST); diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 2a90948507..76a93cc2f8 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -15,11 +15,13 @@ #include #include +namespace NEO { + +namespace XeDrm { struct drm_xe_engine_class_instance; struct drm_xe_query_gt_list; struct drm_xe_query_config; - -namespace NEO { +} // namespace XeDrm enum class EngineClass : uint16_t; @@ -151,7 +153,7 @@ class IoctlHelperXe : public IoctlHelper { int debuggerMetadataDestroyIoctl(DrmIoctl request, void *arg); int getRunaloneExtProperty(); virtual bool isExtraEngineClassAllowed(uint16_t engineClass) const { return false; } - virtual uint32_t getCxlType(struct drm_xe_query_config *config) { return 0u; } + virtual std::optional getCxlType() { return {}; } struct UserFenceExtension { static constexpr uint32_t tagValue = 0x123987; @@ -176,15 +178,15 @@ class IoctlHelperXe : public IoctlHelper { std::mutex xeLock; std::vector bindInfo; std::vector hwconfig; - std::vector contextParamEngine; + std::vector contextParamEngine; std::vector queryGtListData; constexpr static int invalidIndex = -1; StackVec gtIdToTileId; StackVec tileIdToGtId; - drm_xe_query_gt_list *xeGtListData = nullptr; + XeDrm::drm_xe_query_gt_list *xeGtListData = nullptr; - std::unique_ptr defaultEngine; + std::unique_ptr defaultEngine; struct DebugMetadata { DrmResourceClass type; uint64_t offset; diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp index efe04bb965..8fb7d34e9d 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe_perf.cpp @@ -7,8 +7,7 @@ #include "shared/source/os_interface/linux/sys_calls.h" #include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" - -#include "xe_drm.h" +#include "shared/source/os_interface/linux/xe/xedrm.h" namespace NEO { @@ -36,4 +35,4 @@ bool IoctlHelperXe::isEuStallSupported() { return false; } -} // namespace NEO \ No newline at end of file +} // namespace NEO diff --git a/shared/source/os_interface/linux/xe/xedrm.h b/shared/source/os_interface/linux/xe/xedrm.h new file mode 100644 index 0000000000..6475695014 --- /dev/null +++ b/shared/source/os_interface/linux/xe/xedrm.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#ifndef _XE_DRM_H_ +#include +#include +namespace NEO { +namespace XeDrm { +#include "xe_drm.h" +} +} // namespace NEO +using namespace NEO::XeDrm; + +#endif diff --git a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt index 4ed9936794..6ddfa510cf 100644 --- a/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/xe/CMakeLists.txt @@ -8,7 +8,6 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/ioctl_helper_xe_perf_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_xe_tests.h ) if(NEO_ENABLE_XE_EU_DEBUG_SUPPORT) list(APPEND NEO_CORE_OS_INTERFACE_TESTS_LINUX_XE diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp index 3a1c3f0867..636594e1f1 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_perf_tests.cpp @@ -9,7 +9,8 @@ #include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" #include "shared/test/common/mocks/linux/mock_os_context_linux.h" -#include "shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h" +#include "shared/test/common/test_macros/test.h" +#include "shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.h" using namespace NEO; diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp index bff0671614..686538d6a7 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp @@ -5,12 +5,17 @@ * */ -#include "shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h" - +#include "shared/source/helpers/compiler_product_helper.h" +#include "shared/source/os_interface/linux/memory_info.h" #include "shared/source/os_interface/linux/os_context_linux.h" +#include "shared/source/os_interface/product_helper.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" #include "shared/test/common/mocks/linux/mock_os_context_linux.h" +#include "shared/test/common/mocks/linux/mock_os_time_linux.h" +#include "shared/test/common/test_macros/test.h" +#include "shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.h" using namespace NEO; diff --git a/shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.h b/shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.h new file mode 100644 index 0000000000..c4844f99fa --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/os_interface/linux/xe/xedrm.h" +#include "shared/test/common/libult/linux/drm_mock.h" +#include "shared/test/unit_test/os_interface/linux/xe/mock_ioctl_helper_xe.h" +namespace NEO { +namespace XeDrm { +#include "shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.inl" +} +} // namespace NEO +using NEO::XeDrm::DrmMockXe; diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h b/shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.inl similarity index 86% rename from shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h rename to shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.inl index a605a41fc6..677d3fd2f5 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h +++ b/shared/test/unit_test/os_interface/linux/xe/mock_drm_xe.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,72 +7,6 @@ #pragma once -#include "shared/source/helpers/common_types.h" -#include "shared/source/helpers/compiler_product_helper.h" -#include "shared/source/helpers/register_offsets.h" -#include "shared/source/os_interface/linux/engine_info.h" -#include "shared/source/os_interface/linux/ioctl_helper.h" -#include "shared/source/os_interface/linux/memory_info.h" -#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" -#include "shared/source/os_interface/product_helper.h" -#include "shared/test/common/helpers/debug_manager_state_restore.h" -#include "shared/test/common/helpers/default_hw_info.h" -#include "shared/test/common/libult/linux/drm_mock.h" -#include "shared/test/common/mocks/linux/mock_os_time_linux.h" -#include "shared/test/common/mocks/mock_execution_environment.h" -#include "shared/test/common/test_macros/test.h" - -#include "xe_drm.h" - -using namespace NEO; - -struct MockIoctlHelperXe : IoctlHelperXe { - using IoctlHelperXe::bindInfo; - using IoctlHelperXe::contextParamEngine; - using IoctlHelperXe::defaultEngine; - using IoctlHelperXe::getDefaultEngineClass; - using IoctlHelperXe::getFdFromVmExport; - using IoctlHelperXe::ioctl; - using IoctlHelperXe::IoctlHelperXe; - using IoctlHelperXe::maxContextSetProperties; - using IoctlHelperXe::maxExecQueuePriority; - using IoctlHelperXe::queryGtListData; - using IoctlHelperXe::setContextProperties; - using IoctlHelperXe::supportedFeatures; - using IoctlHelperXe::tileIdToGtId; - using IoctlHelperXe::UserFenceExtension; - using IoctlHelperXe::xeGetBindFlagNames; - using IoctlHelperXe::xeGetBindOperationName; - using IoctlHelperXe::xeGetClassName; - using IoctlHelperXe::xeGetengineClassName; - using IoctlHelperXe::xeGtListData; - using IoctlHelperXe::xeShowBindTable; - - int perfOpenIoctl(DrmIoctl request, void *arg) override { - if (failPerfOpen) { - return -1; - } - return IoctlHelperXe::perfOpenIoctl(request, arg); - } - - int ioctl(int fd, DrmIoctl request, void *arg) override { - if (request == DrmIoctl::perfDisable) { - if (failPerfDisable) { - return -1; - } - } - if (request == DrmIoctl::perfEnable) { - if (failPerfEnable) { - return -1; - } - } - return IoctlHelperXe::ioctl(fd, request, arg); - } - bool failPerfDisable = false; - bool failPerfEnable = false; - bool failPerfOpen = false; -}; - inline constexpr int testValueVmId = 0x5764; inline constexpr int testValueMapOff = 0x7788; inline constexpr int testValuePrime = 0x4321; diff --git a/shared/test/unit_test/os_interface/linux/xe/mock_ioctl_helper_xe.h b/shared/test/unit_test/os_interface/linux/xe/mock_ioctl_helper_xe.h new file mode 100644 index 0000000000..029d6b8ff6 --- /dev/null +++ b/shared/test/unit_test/os_interface/linux/xe/mock_ioctl_helper_xe.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/os_interface/linux/xe/ioctl_helper_xe.h" + +using namespace NEO; + +struct MockIoctlHelperXe : IoctlHelperXe { + using IoctlHelperXe::bindInfo; + using IoctlHelperXe::contextParamEngine; + using IoctlHelperXe::defaultEngine; + using IoctlHelperXe::getDefaultEngineClass; + using IoctlHelperXe::getFdFromVmExport; + using IoctlHelperXe::ioctl; + using IoctlHelperXe::IoctlHelperXe; + using IoctlHelperXe::maxContextSetProperties; + using IoctlHelperXe::maxExecQueuePriority; + using IoctlHelperXe::queryGtListData; + using IoctlHelperXe::setContextProperties; + using IoctlHelperXe::supportedFeatures; + using IoctlHelperXe::tileIdToGtId; + using IoctlHelperXe::UserFenceExtension; + using IoctlHelperXe::xeGetBindFlagNames; + using IoctlHelperXe::xeGetBindOperationName; + using IoctlHelperXe::xeGetClassName; + using IoctlHelperXe::xeGetengineClassName; + using IoctlHelperXe::xeGtListData; + using IoctlHelperXe::xeShowBindTable; + + int perfOpenIoctl(DrmIoctl request, void *arg) override { + if (failPerfOpen) { + return -1; + } + return IoctlHelperXe::perfOpenIoctl(request, arg); + } + + int ioctl(int fd, DrmIoctl request, void *arg) override { + if (request == DrmIoctl::perfDisable) { + if (failPerfDisable) { + return -1; + } + } + if (request == DrmIoctl::perfEnable) { + if (failPerfEnable) { + return -1; + } + } + return IoctlHelperXe::ioctl(fd, request, arg); + } + bool failPerfDisable = false; + bool failPerfEnable = false; + bool failPerfOpen = false; +};