From ff65d0ab59b157d3561cacdbd3b6d4b5d4b69601 Mon Sep 17 00:00:00 2001 From: Szymon Morek Date: Fri, 13 Dec 2024 16:51:38 +0000 Subject: [PATCH] performance: don't wait on fence immediately after bind Related-To: NEO-13456 Signed-off-by: Szymon Morek --- .../os_interface/linux/xe/ioctl_helper_xe.cpp | 12 +------ .../xe/ioctl_helper_xe_debugger_tests.cpp | 31 ------------------- .../linux/xe/ioctl_helper_xe_tests.cpp | 26 ++++++++++------ 3 files changed, 18 insertions(+), 51 deletions(-) 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 6787dee91e..e7951866cb 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -1379,17 +1379,7 @@ int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) { return ret; } - constexpr auto oneSecTimeout = 1000000000ll; - constexpr auto infiniteTimeout = -1; - bool debuggingEnabled = drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled(); - uint64_t timeout = debuggingEnabled ? infiniteTimeout : oneSecTimeout; - if (debugManager.flags.VmBindWaitUserFenceTimeout.get() != -1) { - timeout = debugManager.flags.VmBindWaitUserFenceTimeout.get(); - } - return xeWaitUserFence(bind.exec_queue_id, DRM_XE_UFENCE_WAIT_OP_EQ, - sync[0].addr, - sync[0].timeline_value, timeout, - false, NEO::InterruptId::notUsed, nullptr); + return ret; } std::string IoctlHelperXe::getDrmParamString(DrmParam drmParam) const { diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp index 4f756c548b..9f0c433070 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp @@ -349,34 +349,3 @@ TEST(IoctlHelperXeTest, givenResourceRegistrationEnabledWhenAllocationTypeShould } EXPECT_EQ(DrmResourceClass::maxSize, drm.registeredClass); } - -TEST(IoctlHelperXeTest, givenDebuggingEnabledWhenCallingVmBindThenWaitUserFenceIsCalledWithCorrectTimeout) { - - DebugManagerStateRestore restorer; - auto executionEnvironment = std::make_unique(); - executionEnvironment->setDebuggingMode(DebuggingMode::online); - auto drm = DrmMockXeDebug::create(*executionEnvironment->rootDeviceEnvironments[0]); - auto xeIoctlHelper = std::make_unique(*drm); - - auto expectedTimeout = -1; - - uint64_t fenceAddress = 0x4321; - uint64_t fenceValue = 0x789; - - auto handle = 0x1234u; - - VmBindExtUserFenceT vmBindExtUserFence{}; - xeIoctlHelper->fillVmBindExtUserFence(vmBindExtUserFence, fenceAddress, fenceValue, 0u); - - VmBindParams vmBindParams{}; - vmBindParams.handle = handle; - xeIoctlHelper->setVmBindUserFence(vmBindParams, vmBindExtUserFence); - - EXPECT_EQ(0, xeIoctlHelper->vmBind(vmBindParams)); - auto &waitUserFence = drm->waitUserFenceInputs[0]; - EXPECT_EQ(expectedTimeout, waitUserFence.timeout); - drm->waitUserFenceInputs.clear(); - EXPECT_EQ(0, xeIoctlHelper->vmUnbind(vmBindParams)); - waitUserFence = drm->waitUserFenceInputs[0]; - EXPECT_EQ(expectedTimeout, waitUserFence.timeout); -} 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 fb623a2121..14d8480a83 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 @@ -1504,7 +1504,7 @@ TEST(IoctlHelperXeTest, givenDisabledFtrMultiTileArchWhenCreatingEngineInfoThenM using IoctlHelperXeFenceWaitTest = ::testing::Test; -TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenWaitUserFenceIsCalled) { +TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenSyncObjectAdded) { DebugManagerStateRestore restorer; auto executionEnvironment = std::make_unique(); auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]); @@ -1531,9 +1531,11 @@ TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenWaitUserFenceIsCalled) { EXPECT_EQ(0, xeIoctlHelper->vmBind(vmBindParams)); EXPECT_EQ(1u, drm->vmBindInputs.size()); EXPECT_EQ(1u, drm->syncInputs.size()); - EXPECT_EQ(1u, drm->waitUserFenceInputs.size()); + EXPECT_EQ(0u, drm->waitUserFenceInputs.size()); auto expectedMask = std::numeric_limits::max(); auto expectedTimeout = 1000000000ll; + xeIoctlHelper->waitUserFence(0u, fenceAddress, fenceValue, static_cast(Drm::ValueWidth::u64), expectedTimeout, 0, false, NEO::InterruptId::notUsed, nullptr); + EXPECT_EQ(1u, drm->waitUserFenceInputs.size()); { auto &sync = drm->syncInputs[0]; @@ -1543,7 +1545,7 @@ TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenWaitUserFenceIsCalled) { auto &waitUserFence = drm->waitUserFenceInputs[0]; EXPECT_EQ(fenceAddress, waitUserFence.addr); - EXPECT_EQ(static_cast(DRM_XE_UFENCE_WAIT_OP_EQ), waitUserFence.op); + EXPECT_EQ(static_cast(DRM_XE_UFENCE_WAIT_OP_GTE), waitUserFence.op); EXPECT_EQ(0u, waitUserFence.flags); EXPECT_EQ(fenceValue, waitUserFence.value); EXPECT_EQ(expectedMask, waitUserFence.mask); @@ -1558,6 +1560,8 @@ TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenWaitUserFenceIsCalled) { EXPECT_EQ(0, xeIoctlHelper->vmUnbind(vmBindParams)); EXPECT_EQ(1u, drm->vmBindInputs.size()); EXPECT_EQ(1u, drm->syncInputs.size()); + EXPECT_EQ(0u, drm->waitUserFenceInputs.size()); + xeIoctlHelper->waitUserFence(0u, fenceAddress, fenceValue, static_cast(Drm::ValueWidth::u64), expectedTimeout, 0, false, NEO::InterruptId::notUsed, nullptr); EXPECT_EQ(1u, drm->waitUserFenceInputs.size()); { auto &sync = drm->syncInputs[0]; @@ -1568,7 +1572,7 @@ TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenWaitUserFenceIsCalled) { auto &waitUserFence = drm->waitUserFenceInputs[0]; EXPECT_EQ(fenceAddress, waitUserFence.addr); - EXPECT_EQ(static_cast(DRM_XE_UFENCE_WAIT_OP_EQ), waitUserFence.op); + EXPECT_EQ(static_cast(DRM_XE_UFENCE_WAIT_OP_GTE), waitUserFence.op); EXPECT_EQ(0u, waitUserFence.flags); EXPECT_EQ(fenceValue, waitUserFence.value); EXPECT_EQ(expectedMask, waitUserFence.mask); @@ -1579,7 +1583,7 @@ TEST_F(IoctlHelperXeFenceWaitTest, whenCallingVmBindThenWaitUserFenceIsCalled) { } } -TEST(IoctlHelperXeTest, givenVmBindWaitUserFenceTimeoutWhenCallingVmBindThenWaitUserFenceIsCalledWithSpecificTimeout) { +TEST(IoctlHelperXeTest, givenVmBindWaitUserFenceTimeoutCalledThenWaitUserFenceIsCalledWithSpecificTimeout) { DebugManagerStateRestore restorer; debugManager.flags.VmBindWaitUserFenceTimeout.set(5000000000ll); auto executionEnvironment = std::make_unique(); @@ -1608,9 +1612,12 @@ TEST(IoctlHelperXeTest, givenVmBindWaitUserFenceTimeoutWhenCallingVmBindThenWait EXPECT_EQ(0, xeIoctlHelper->vmBind(vmBindParams)); EXPECT_EQ(1u, drm->vmBindInputs.size()); EXPECT_EQ(1u, drm->syncInputs.size()); - EXPECT_EQ(1u, drm->waitUserFenceInputs.size()); + EXPECT_EQ(0u, drm->waitUserFenceInputs.size()); + auto expectedMask = std::numeric_limits::max(); auto expectedTimeout = 5000000000ll; + xeIoctlHelper->waitUserFence(0u, fenceAddress, fenceValue, static_cast(Drm::ValueWidth::u64), expectedTimeout, 0, false, NEO::InterruptId::notUsed, nullptr); + EXPECT_EQ(1u, drm->waitUserFenceInputs.size()); { auto &sync = drm->syncInputs[0]; @@ -1620,7 +1627,7 @@ TEST(IoctlHelperXeTest, givenVmBindWaitUserFenceTimeoutWhenCallingVmBindThenWait auto &waitUserFence = drm->waitUserFenceInputs[0]; EXPECT_EQ(fenceAddress, waitUserFence.addr); - EXPECT_EQ(static_cast(DRM_XE_UFENCE_WAIT_OP_EQ), waitUserFence.op); + EXPECT_EQ(static_cast(DRM_XE_UFENCE_WAIT_OP_GTE), waitUserFence.op); EXPECT_EQ(0u, waitUserFence.flags); EXPECT_EQ(fenceValue, waitUserFence.value); EXPECT_EQ(expectedMask, waitUserFence.mask); @@ -1681,8 +1688,9 @@ TEST(IoctlHelperXeTest, whenUserFenceFailsThenErrorIsPropagated) { int errorValue = -1; drm->waitUserFenceReturn = errorValue; - EXPECT_EQ(errorValue, xeIoctlHelper->vmBind(vmBindParams)); - EXPECT_EQ(errorValue, xeIoctlHelper->vmUnbind(vmBindParams)); + auto expectedTimeout = 1000000000ll; + auto ret = xeIoctlHelper->waitUserFence(0u, fenceAddress, fenceValue, static_cast(Drm::ValueWidth::u64), expectedTimeout, 0, false, NEO::InterruptId::notUsed, nullptr); + EXPECT_EQ(errorValue, ret); } TEST(IoctlHelperXeTest, WhenSetupIpVersionIsCalledThenIpVersionIsCorrect) {