diff --git a/opencl/test/unit_test/linux/main_linux_dll.cpp b/opencl/test/unit_test/linux/main_linux_dll.cpp index ee31999349..7818aa3870 100644 --- a/opencl/test/unit_test/linux/main_linux_dll.cpp +++ b/opencl/test/unit_test/linux/main_linux_dll.cpp @@ -669,6 +669,7 @@ TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCr MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]); + drm->setupIoctlHelper(defaultHwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment); @@ -687,6 +688,7 @@ TEST(DrmMemoryManagerCreate, givenEnableHostPtrValidationSetToZeroWhenCreateDrmM MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]); + drm->setupIoctlHelper(defaultHwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment); diff --git a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index a82b36ff1a..37ae8e49eb 100644 --- a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -24,6 +24,7 @@ using namespace NEO; TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFromMultipleThreadsThenSingleBoIsReused) { class MockDrm : public Drm { public: + using Drm::setupIoctlHelper; MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(fd, ""), rootDeviceEnvironment) {} int ioctl(unsigned long request, void *arg) override { @@ -37,6 +38,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]); + mock->setupIoctlHelper(defaultHwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); @@ -76,6 +78,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThenPrimeFdToHandleDoesNotRaceWithClose) { class MockDrm : public Drm { public: + using Drm::setupIoctlHelper; MockDrm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(fd, ""), rootDeviceEnvironment) { primeFdHandle = 1; closeHandle = 1; @@ -107,6 +110,7 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]); + mock->setupIoctlHelper(defaultHwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h index a94e2c1ec6..196fc29ca5 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h @@ -33,14 +33,14 @@ class DrmCommandStreamTest : public ::testing::Test { DebugManager.flags.EnableForcePin.set(false); mock = new ::testing::NiceMock(mockFd, *executionEnvironment.rootDeviceEnvironments[0]); + auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo(); + mock->setupIoctlHelper(hwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); - auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo(); mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo)); - mock->setupIoctlHelper(hwInfo->platform.eProductFamily); osContext = std::make_unique(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo))); diff --git a/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp index cf5c251e30..855356e61c 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -34,6 +34,7 @@ using namespace NEO; class DrmMockForWorker : public Drm { public: + using Drm::setupIoctlHelper; std::mutex mutex; std::atomic gem_close_cnt; std::atomic gem_close_expected; @@ -68,6 +69,9 @@ class DrmGemCloseWorkerFixture { void SetUp() { this->drmMock = new DrmMockForWorker(*executionEnvironment.rootDeviceEnvironments[0]); + auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo(); + drmMock->setupIoctlHelper(hwInfo->platform.eProductFamily); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drmMock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drmMock, 0u); diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 6a08868d54..30d630742a 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -67,6 +67,7 @@ class IoctlHelper { virtual std::string getIoctlParamString(int param); virtual IoctlHelper *clone() = 0; + virtual bool isVmBindAvailable(Drm *drm) = 0; virtual uint32_t createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) = 0; virtual std::vector translateToMemoryRegions(const std::vector ®ionInfo) = 0; virtual CacheRegion closAlloc(Drm *drm) = 0; @@ -99,6 +100,7 @@ class IoctlHelperUpstream : public IoctlHelper { public: IoctlHelper *clone() override; + bool isVmBindAvailable(Drm *drm) override; uint32_t createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) override; std::vector translateToMemoryRegions(const std::vector ®ionInfo) override; CacheRegion closAlloc(Drm *drm) override; @@ -146,6 +148,7 @@ class IoctlHelperPrelim20 : public IoctlHelper { std::string getIoctlParamString(int param) override; IoctlHelper *clone() override; + bool isVmBindAvailable(Drm *drm) override; uint32_t createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) override; std::vector translateToMemoryRegions(const std::vector ®ionInfo) override; CacheRegion closAlloc(Drm *drm) override; diff --git a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp index 84d07b1de2..eb7260f3bb 100644 --- a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp @@ -71,6 +71,18 @@ IoctlHelper *IoctlHelperPrelim20::clone() { return new IoctlHelperPrelim20{}; } +bool IoctlHelperPrelim20::isVmBindAvailable(Drm *drm) { + int vmBindSupported = 0; + drm_i915_getparam_t getParam = {}; + getParam.param = PRELIM_I915_PARAM_HAS_VM_BIND; + getParam.value = &vmBindSupported; + int retVal = IoctlHelper::ioctl(drm, DRM_IOCTL_I915_GETPARAM, &getParam); + if (retVal) { + return false; + } + return vmBindSupported; +} + uint32_t IoctlHelperPrelim20::createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) { uint32_t regionsSize = static_cast(memClassInstances.size()); std::vector regions(regionsSize); diff --git a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp index 80813c6bf6..fa1a120001 100644 --- a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp @@ -17,6 +17,10 @@ IoctlHelper *IoctlHelperUpstream::clone() { return new IoctlHelperUpstream{}; } +bool IoctlHelperUpstream::isVmBindAvailable(Drm *drm) { + return false; +} + uint32_t IoctlHelperUpstream::createGemExt(Drm *drm, const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle) { uint32_t regionsSize = static_cast(memClassInstances.size()); std::vector regions(regionsSize); diff --git a/shared/test/common/libult/linux/drm_mock_prelim_context.cpp b/shared/test/common/libult/linux/drm_mock_prelim_context.cpp index be787b16c2..0025d2511e 100644 --- a/shared/test/common/libult/linux/drm_mock_prelim_context.cpp +++ b/shared/test/common/libult/linux/drm_mock_prelim_context.cpp @@ -53,6 +53,10 @@ int DrmMockPrelimContext::handlePrelimRequest(unsigned long request, void *arg) if (gp->param == PRELIM_I915_PARAM_HAS_PAGE_FAULT) { *gp->value = hasPageFaultQueryValue; return hasPageFaultQueryReturn; + } else if (gp->param == PRELIM_I915_PARAM_HAS_VM_BIND) { + vmBindQueryCalled++; + *gp->value = vmBindQueryValue; + return vmBindQueryReturn; } } break; case PRELIM_DRM_IOCTL_I915_GEM_CLOS_RESERVE: { diff --git a/shared/test/common/libult/linux/drm_mock_prelim_context.h b/shared/test/common/libult/linux/drm_mock_prelim_context.h index 84a671bdf4..bdee5d2090 100644 --- a/shared/test/common/libult/linux/drm_mock_prelim_context.h +++ b/shared/test/common/libult/linux/drm_mock_prelim_context.h @@ -22,6 +22,10 @@ struct DrmMockPrelimContext { uint16_t maxNumWays{32}; uint32_t allocNumWays{0}; + size_t vmBindQueryCalled{0}; + int vmBindQueryValue{0}; + int vmBindQueryReturn{0}; + int hasPageFaultQueryValue{0}; int hasPageFaultQueryReturn{0}; diff --git a/shared/test/common/os_interface/linux/device_command_stream_fixture.cpp b/shared/test/common/os_interface/linux/device_command_stream_fixture.cpp index b827bbecef..62139be151 100644 --- a/shared/test/common/os_interface/linux/device_command_stream_fixture.cpp +++ b/shared/test/common/os_interface/linux/device_command_stream_fixture.cpp @@ -201,8 +201,8 @@ DrmMockCustom::DrmMockCustom(RootDeviceEnvironment &rootDeviceEnvironment) ioctl_expected.contextCreate = static_cast(NEO::HwHelper::get(NEO::defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*NEO::defaultHwInfo).size()); ioctl_expected.contextDestroy = ioctl_expected.contextCreate.load(); createVirtualMemoryAddressSpace(NEO::HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo())); - isVmBindAvailable(); setupIoctlHelper(rootDeviceEnvironment.getHardwareInfo()->platform.eProductFamily); + isVmBindAvailable(); reset(); } diff --git a/shared/test/common/os_interface/linux/device_command_stream_fixture.h b/shared/test/common/os_interface/linux/device_command_stream_fixture.h index c4be179ac6..18c770f839 100644 --- a/shared/test/common/os_interface/linux/device_command_stream_fixture.h +++ b/shared/test/common/os_interface/linux/device_command_stream_fixture.h @@ -38,6 +38,7 @@ class DrmMockImpl : public Drm { class DrmMockSuccess : public Drm { public: + using Drm::setupIoctlHelper; DrmMockSuccess(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique(fd, mockPciPath), rootDeviceEnvironment) {} int ioctl(unsigned long request, void *arg) override { return 0; }; diff --git a/shared/test/unit_test/os_interface/linux/drm_command_stream_l0_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_command_stream_l0_tests.cpp index efb597623a..758bd62c2c 100644 --- a/shared/test/unit_test/os_interface/linux/drm_command_stream_l0_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_command_stream_l0_tests.cpp @@ -35,14 +35,15 @@ class DrmCommandStreamTestL0 : public ::testing::Test { //make sure this is disabled, we don't want to test this now DebugManager.flags.EnableForcePin.set(false); + auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo(); mock = new ::testing::NiceMock(mockFd, *executionEnvironment.rootDeviceEnvironments[0]); + mock->setupIoctlHelper(hwInfo->platform.eProductFamily); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(mock)); executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u); - auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo(); mock->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(hwInfo)); osContext = std::make_unique(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], @@ -98,4 +99,4 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTestL0, givenL0ApiConfigWhenCreatingDrmCsrThe VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); MockDrmCsrL0 csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive); EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode); -} \ No newline at end of file +} diff --git a/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp index 2fc7d5bd27..bba4822043 100644 --- a/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp @@ -5,12 +5,13 @@ * */ -#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 "shared/test/common/libult/linux/drm_query_mock.h" #include "shared/test/common/mocks/linux/mock_drm_allocation.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/test_macros/test.h" using namespace NEO; @@ -50,6 +51,28 @@ class IoctlHelperPrelimFixture : public ::testing::Test { std::unique_ptr drm; }; +TEST(IoctlHelperPrelimTest, whenGettingVmBindAvailabilityThenProperValueIsReturnedBasedOnIoctlResult) { + auto executionEnvironment = std::make_unique(); + DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; + + IoctlHelperPrelim20 ioctlHelper{}; + + for (auto &ioctlValue : {0, EINVAL}) { + drm.context.vmBindQueryReturn = ioctlValue; + for (auto &hasVmBind : ::testing::Bool()) { + drm.context.vmBindQueryValue = hasVmBind; + drm.context.vmBindQueryCalled = 0u; + + if (ioctlValue == 0) { + EXPECT_EQ(hasVmBind, ioctlHelper.isVmBindAvailable(&drm)); + } else { + EXPECT_FALSE(ioctlHelper.isVmBindAvailable(&drm)); + } + EXPECT_EQ(1u, drm.context.vmBindQueryCalled); + } + } +} + TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenCreateGemExtThenReturnSuccess) { auto ioctlHelper = drm->getIoctlHelper(); uint32_t handle = 0; diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 7ef7fc9184..7f205a62f1 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -5,7 +5,6 @@ * */ -#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" @@ -17,6 +16,13 @@ using namespace NEO; extern std::map ioctlCodeStringMap; extern std::map ioctlParamCodeStringMap; +TEST(IoctlHelperUpstreamTest, whenGettingVmBindAvailabilityThenFalseIsReturned) { + IoctlHelperUpstream ioctlHelper{}; + auto executionEnvironment = std::make_unique(); + auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + EXPECT_FALSE(ioctlHelper.isVmBindAvailable(drm.get())); +} + TEST(IoctlHelperUpstreamTest, givenIoctlWhenParseToStringThenProperStringIsReturned) { IoctlHelperUpstream ioctlHelper{}; for (auto ioctlCodeString : ioctlCodeStringMap) {