Check i915 version at runtime

Related-To: NEO-6510

Check which prelim version is being used.
Select proper IoctlHelper based on that version.
If no version found, switch to upstream instead.

Source of prelim headers:
https://github.com/intel-gpu/drm-uapi-helper


Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2021-12-08 10:10:27 +00:00
committed by Compute-Runtime-Automation
parent abb91a7dae
commit 5a3fd1dc94
28 changed files with 3116 additions and 1133 deletions

View File

@ -34,7 +34,8 @@ set(IGDRCL_SRCS_tests_os_interface_linux
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/linux_create_command_queue_with_properties_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}ioctl_helper_default_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_prelim.cpp
${CMAKE_CURRENT_SOURCE_DIR}/prelim_helper_func.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_os_time_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_linux.h
@ -58,9 +59,9 @@ if(TESTS_DG1 AND "${BRANCH_TYPE}" STREQUAL "")
)
endif()
if(TESTS_XE_HP_SDV AND "${BRANCH_TYPE}" STREQUAL "")
if("${BRANCH_TYPE}" STREQUAL "")
list(APPEND IGDRCL_SRCS_tests_os_interface_linux
${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_xe_hp_sdv.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_upstream.cpp
)
endif()

View File

@ -36,7 +36,11 @@ class DrmTipMock : public DrmMock {
__u64 offset = 0;
int mmapOffsetRetVal = 0;
virtual int handleRemainingRequests(unsigned long request, void *arg) {
void getPrelimVersion(std::string &prelimVersion) override {
prelimVersion = "";
}
virtual int handleRemainingRequests(unsigned long request, void *arg) override {
if ((request == DRM_IOCTL_I915_QUERY) && (arg != nullptr)) {
if (i915QuerySuccessCount == 0) {
return EINVAL;

View File

@ -909,3 +909,32 @@ TEST(DrmTest, whenCheckedIfResourcesCleanupCanBeSkippedThenReturnsFalse) {
EXPECT_FALSE(pDrm->skipResourceCleanup());
delete pDrm;
}
TEST(DrmQueryTest, givenUapiPrelimVersionThenReturnCorrectString) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
std::string prelimVersionFile = "test_files/linux/devices/device/drm/card1/prelim_uapi_version";
EXPECT_TRUE(fileExists(prelimVersionFile));
drm.setPciPath("device");
std::string prelimVersion = "";
drm.getPrelimVersion(prelimVersion);
EXPECT_EQ("2.0", prelimVersion);
}
TEST(DrmQueryTest, givenUapiPrelimVersionWithInvalidPathThenReturnEmptyString) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
drm.setPciPath("invalidPath");
std::string prelimVersion = "2.0";
drm.getPrelimVersion(prelimVersion);
EXPECT_TRUE(prelimVersion.empty());
}

View File

@ -1,40 +0,0 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/source/os_interface/linux/memory_info.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "test.h"
using namespace NEO;
TEST(IoctlHelperTestsDefault, givenUnsupportedPlatformWhenCreateGemExtThenReturnErrorNumber) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]);
drm_i915_memory_region_info regionInfo[2] = {};
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probed_size = 8 * GB;
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probed_size = 16 * GB;
auto ioctlHelper = IoctlHelper::get(IGFX_UNKNOWN);
uint32_t handle = 0;
auto ret = ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);
EXPECT_EQ(-1u, ret);
}
TEST(IoctlHelperTestsDefault, givenUnsupportedPlatformWhenTranslateIfRequiredReturnSameData) {
auto *data = new uint8_t{};
auto ioctlHelper = IoctlHelper::get(IGFX_UNKNOWN);
auto ret = ioctlHelper->translateIfRequired(data, 1);
EXPECT_EQ(ret.get(), data);
}

View File

@ -9,7 +9,6 @@
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include "shared/source/os_interface/linux/memory_info.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock_impl.h"
#include "opencl/test/unit_test/os_interface/linux/drm_mock_prod_dg1.h"
@ -30,7 +29,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtThenReturnCorrectValue) {
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probed_size = 16 * GB;
auto ioctlHelper = IoctlHelper::get(defaultHwInfo->platform.eProductFamily);
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
auto ret = ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);
@ -53,7 +52,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WithDrmTipWhenCreateGemExtWithDebugFlagTh
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
testing::internal::CaptureStdout();
auto ioctlHelper = IoctlHelper::get(defaultHwInfo->platform.eProductFamily);
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
auto ret = ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);
@ -77,7 +76,7 @@ DG1TEST_F(IoctlHelperTestsDg1, givenDg1WhenCreateGemExtWithDebugFlagThenPrintDeb
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
testing::internal::CaptureStdout();
auto ioctlHelper = IoctlHelper::get(defaultHwInfo->platform.eProductFamily);
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
auto ret = ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);

View File

@ -0,0 +1,97 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/os_interface/linux/ioctl_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 "test.h"
using namespace NEO;
extern int handlePrelimRequests(unsigned long request, void *arg);
class DrmPrelimMock : public DrmMock {
public:
DrmPrelimMock(RootDeviceEnvironment &rootDeviceEnvironment) : DrmPrelimMock(rootDeviceEnvironment, defaultHwInfo.get()) {}
DrmPrelimMock(RootDeviceEnvironment &rootDeviceEnvironment, HardwareInfo *inputHwInfo) : DrmMock(rootDeviceEnvironment) {
rootDeviceEnvironment.setHwInfo(inputHwInfo);
rootDeviceEnvironment.getMutableHardwareInfo()->platform.eProductFamily = IGFX_UNKNOWN;
}
void getPrelimVersion(std::string &prelimVersion) override {
prelimVersion = "2.0";
}
int handleRemainingRequests(unsigned long request, void *arg) override {
return handlePrelimRequests(request, arg);
}
};
TEST(IoctlHelperTestsPrelim, givenPrelimsWhenCreateGemExtThenReturnSuccess) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
drm_i915_memory_region_info regionInfo[2] = {};
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[0].probed_size = 8 * GB;
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probed_size = 16 * GB;
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
auto ret = ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);
EXPECT_EQ(1u, handle);
EXPECT_EQ(0u, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
}
TEST(IoctlHelperTestsPrelim, givenPrelimsWhenCreateGemExtWithDebugFlagThenPrintDebugInfo) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.PrintBOCreateDestroyResult.set(true);
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
drm_i915_memory_region_info regionInfo[2] = {};
regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
testing::internal::CaptureStdout();
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);
std::string output = testing::internal::GetCapturedStdout();
std::string expectedOutput("Performing GEM_CREATE_EXT with { size: 1024, param: 0x1000000010001, memory class: 1, memory instance: 0 }\nGEM_CREATE_EXT has returned: 0 BO-1 with size: 1024\n");
EXPECT_EQ(expectedOutput, output);
}
TEST(IoctlHelperTestsPrelim, givenPrelimsWhenTranslateIfRequiredThenReturnSameData) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
auto *data = new uint8_t{};
auto ioctlHelper = IoctlHelper::get(drm.get());
auto ret = ioctlHelper->translateIfRequired(data, 1);
EXPECT_EQ(ret.get(), data);
}
TEST(IoctlHelperTestsDefault, givenPrelimsWhenCallIoctlThenProperIoctlRegistered) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
drm_i915_gem_context_create_ext arg{};
auto ret = IoctlHelper::ioctl(drm.get(), DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT, &arg);
EXPECT_EQ(0u, ret);
EXPECT_EQ(1u, drm->ioctlCallsCount);
}

View File

@ -15,9 +15,7 @@
using namespace NEO;
using IoctlHelperTestsXeHpSdv = ::testing::Test;
XEHPTEST_F(IoctlHelperTestsXeHpSdv, givenXeHpSdvWhenCreateGemExtThenReturnCorrectValue) {
TEST(IoctlHelperTestsUpstream, givenUpstreamWhenCreateGemExtThenReturnCorrectValue) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
@ -28,7 +26,7 @@ XEHPTEST_F(IoctlHelperTestsXeHpSdv, givenXeHpSdvWhenCreateGemExtThenReturnCorrec
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
regionInfo[1].probed_size = 16 * GB;
auto ioctlHelper = IoctlHelper::get(defaultHwInfo->platform.eProductFamily);
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
auto ret = ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);
@ -39,7 +37,7 @@ XEHPTEST_F(IoctlHelperTestsXeHpSdv, givenXeHpSdvWhenCreateGemExtThenReturnCorrec
EXPECT_EQ(I915_MEMORY_CLASS_DEVICE, drm->memRegions.memory_class);
}
XEHPTEST_F(IoctlHelperTestsXeHpSdv, givenXeHpSdvWhenCreateGemExtWithDebugFlagThenPrintDebugInfo) {
TEST(IoctlHelperTestsUpstream, givenUpstreamWhenCreateGemExtWithDebugFlagThenPrintDebugInfo) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.PrintBOCreateDestroyResult.set(true);
@ -52,7 +50,7 @@ XEHPTEST_F(IoctlHelperTestsXeHpSdv, givenXeHpSdvWhenCreateGemExtWithDebugFlagThe
regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0};
testing::internal::CaptureStdout();
auto ioctlHelper = IoctlHelper::get(defaultHwInfo->platform.eProductFamily);
auto ioctlHelper = IoctlHelper::get(drm.get());
uint32_t handle = 0;
ioctlHelper->createGemExt(drm.get(), &regionInfo[1], 1, 1024, handle);

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "test.h"
#include "third_party/uapi/prelim/drm/i915_drm.h"
int handlePrelimRequests(unsigned long request, void *arg) {
if (request == PRELIM_DRM_IOCTL_I915_GEM_CREATE_EXT) {
auto createExtParams = static_cast<prelim_drm_i915_gem_create_ext *>(arg);
if (createExtParams->size == 0) {
return EINVAL;
}
createExtParams->handle = 1u;
auto extensions = reinterpret_cast<prelim_drm_i915_gem_create_ext_setparam *>(createExtParams->extensions);
if (extensions == nullptr) {
return EINVAL;
}
auto setparamRegion = *extensions;
if (setparamRegion.base.name != PRELIM_I915_GEM_CREATE_EXT_SETPARAM) {
return EINVAL;
}
if ((setparamRegion.param.size == 0) ||
(setparamRegion.param.param != (PRELIM_I915_OBJECT_PARAM | PRELIM_I915_PARAM_MEMORY_REGIONS))) {
return EINVAL;
}
auto data = reinterpret_cast<prelim_drm_i915_gem_memory_class_instance *>(setparamRegion.param.data);
if (data == nullptr) {
return EINVAL;
}
if ((data->memory_class != PRELIM_I915_MEMORY_CLASS_SYSTEM) && (data->memory_class != PRELIM_I915_MEMORY_CLASS_DEVICE)) {
return EINVAL;
}
}
return 0;
}