From 2a2596c13b8e389546a022fdd7fd317cb2e97dc5 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Thu, 25 Apr 2024 17:45:21 +0000 Subject: [PATCH] refactor: pass additional data to ioctl helper Signed-off-by: Bartosz Dunajski --- level_zero/core/source/event/event.h | 3 +- .../sources/cmdlist/test_in_order_cmdlist.cpp | 4 +- shared/source/helpers/common_types.h | 4 ++ shared/source/os_interface/linux/drm_neo.cpp | 2 +- .../source/os_interface/linux/ioctl_helper.h | 9 +++-- .../linux/ioctl_helper_prelim.cpp | 3 +- .../linux/ioctl_helper_upstream.cpp | 4 +- .../os_interface/linux/xe/ioctl_helper_xe.cpp | 38 +++++++++++-------- .../os_interface/linux/xe/ioctl_helper_xe.h | 6 ++- .../linux/drm_with_prelim_tests.cpp | 2 +- .../linux/xe/ioctl_helper_xe_tests.h | 3 ++ 11 files changed, 50 insertions(+), 28 deletions(-) diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 0102ee0c93..694c234e4f 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/helpers/common_types.h" #include "shared/source/helpers/timestamp_packet_constants.h" #include "shared/source/helpers/timestamp_packet_container.h" #include "shared/source/memory_manager/multi_graphics_allocation.h" @@ -337,7 +338,7 @@ struct Event : _ze_event_handle_t { uint32_t maxPacketCount = 0; uint32_t totalEventSize = 0; uint32_t counterBasedFlags = 0; - uint32_t externalInterruptId = 0; + uint32_t externalInterruptId = NEO::InterruptId::notUsed; CounterBasedMode counterBasedMode = CounterBasedMode::initiallyDisabled; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp index 5afd175514..d21912a949 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_in_order_cmdlist.cpp @@ -122,7 +122,7 @@ HWTEST2_F(InOrderCmdListTests, givenEventSyncModeDescPassedWhenCreatingEventThen syncModeDesc.syncModeFlags = ZEX_INTEL_EVENT_SYNC_MODE_EXP_FLAG_SIGNAL_INTERRUPT; syncModeDesc.externalInterruptId = 123; auto event4 = DestroyableZeUniquePtr(static_cast(Event::create(eventPool.get(), &eventDesc, device))); - EXPECT_EQ(0u, event4->externalInterruptId); + EXPECT_EQ(NEO::InterruptId::notUsed, event4->externalInterruptId); eventDesc.index = 5; syncModeDesc.syncModeFlags = ZEX_INTEL_EVENT_SYNC_MODE_EXP_FLAG_LOW_POWER_WAIT; @@ -3895,7 +3895,7 @@ HWTEST2_F(InOrderCmdListTests, givenStandaloneCbEventWhenPassingExternalInterrup syncModeDesc.syncModeFlags = ZEX_INTEL_EVENT_SYNC_MODE_EXP_FLAG_SIGNAL_INTERRUPT; auto event1 = createStandaloneCbEvent(reinterpret_cast(&syncModeDesc)); - EXPECT_EQ(0u, event1->externalInterruptId); + EXPECT_EQ(NEO::InterruptId::notUsed, event1->externalInterruptId); syncModeDesc.syncModeFlags = ZEX_INTEL_EVENT_SYNC_MODE_EXP_FLAG_LOW_POWER_WAIT; auto event2 = createStandaloneCbEvent(reinterpret_cast(&syncModeDesc)); diff --git a/shared/source/helpers/common_types.h b/shared/source/helpers/common_types.h index 61b64c90fe..c3ef3c5fd2 100644 --- a/shared/source/helpers/common_types.h +++ b/shared/source/helpers/common_types.h @@ -94,4 +94,8 @@ enum class SynchronizedDispatchMode : uint32_t { limited = 2 }; +namespace InterruptId { +static constexpr uint32_t notUsed = std::numeric_limits::max(); +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 0045de4771..1546925e9f 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -961,7 +961,7 @@ void Drm::getPrelimVersion(std::string &prelimVersion) { } int Drm::waitUserFence(uint32_t ctxId, uint64_t address, uint64_t value, ValueWidth dataWidth, int64_t timeout, uint16_t flags) { - return ioctlHelper->waitUserFence(ctxId, address, value, static_cast(dataWidth), timeout, flags); + return ioctlHelper->waitUserFence(ctxId, address, value, static_cast(dataWidth), timeout, flags, false, NEO::InterruptId::notUsed); } bool Drm::querySystemInfo() { diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 00a91aec8a..7513ae07c2 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -105,7 +105,8 @@ class IoctlHelper { virtual uint16_t closAllocWays(CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) = 0; virtual CacheRegion closFree(CacheRegion closIndex) = 0; virtual int waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) = 0; + uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) = 0; virtual uint32_t getAtomicAdvise(bool isNonAtomic) = 0; virtual uint32_t getAtomicAccess(AtomicAccessMode mode) = 0; virtual uint32_t getPreferredLocationAdvise() = 0; @@ -254,7 +255,8 @@ class IoctlHelperUpstream : public IoctlHelperI915 { uint16_t closAllocWays(CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) override; CacheRegion closFree(CacheRegion closIndex) override; int waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) override; + uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) override; uint32_t getAtomicAdvise(bool isNonAtomic) override; uint32_t getAtomicAccess(AtomicAccessMode mode) override; uint32_t getPreferredLocationAdvise() override; @@ -331,7 +333,8 @@ class IoctlHelperPrelim20 : public IoctlHelperI915 { uint16_t closAllocWays(CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) override; CacheRegion closFree(CacheRegion closIndex) override; int waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) override; + uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) override; uint32_t getAtomicAdvise(bool isNonAtomic) override; uint32_t getAtomicAccess(AtomicAccessMode mode) override; uint32_t getPreferredLocationAdvise() override; diff --git a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp index 83f3e11fab..70f786c977 100644 --- a/shared/source/os_interface/linux/ioctl_helper_prelim.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_prelim.cpp @@ -311,7 +311,8 @@ CacheRegion IoctlHelperPrelim20::closFree(CacheRegion closIndex) { } int IoctlHelperPrelim20::waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) { + uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) { prelim_drm_i915_gem_wait_user_fence wait = {}; wait.ctx_id = ctxId; diff --git a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp index 9ee3896db2..d9ca9d1821 100644 --- a/shared/source/os_interface/linux/ioctl_helper_upstream.cpp +++ b/shared/source/os_interface/linux/ioctl_helper_upstream.cpp @@ -127,8 +127,8 @@ CacheRegion IoctlHelperUpstream::closFree(CacheRegion closIndex) { return CacheRegion::none; } -int IoctlHelperUpstream::waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) { +int IoctlHelperUpstream::waitUserFence(uint32_t ctxId, uint64_t address, uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) { return 0; } 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 2902d0647a..c9091cd17a 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -626,27 +626,34 @@ CacheRegion IoctlHelperXe::closFree(CacheRegion closIndex) { return CacheRegion::none; } -int IoctlHelperXe::xeWaitUserFence(uint32_t ctxId, uint16_t op, uint64_t addr, uint64_t value, - int64_t timeout) { - struct drm_xe_wait_user_fence wait = {}; - wait.addr = addr; - wait.op = op; - wait.value = value; - wait.mask = std::numeric_limits::max(); - wait.timeout = timeout; - wait.exec_queue_id = ctxId; - auto retVal = IoctlHelper::ioctl(DrmIoctl::gemWaitUserFence, &wait); - xeLog(" -> IoctlHelperXe::%s a=0x%llx v=0x%llx T=0x%llx F=0x%x ctx=0x%x retVal=0x%x\n", __FUNCTION__, addr, value, - timeout, wait.flags, ctxId, retVal); +void IoctlHelperXe::setupXeWaitUserFenceStruct(void *arg, uint32_t ctxId, uint16_t op, uint64_t addr, uint64_t value, int64_t timeout) { + auto waitUserFence = reinterpret_cast(arg); + waitUserFence->addr = addr; + waitUserFence->op = op; + waitUserFence->value = value; + waitUserFence->mask = std::numeric_limits::max(); + waitUserFence->timeout = timeout; + waitUserFence->exec_queue_id = ctxId; +} + +int IoctlHelperXe::xeWaitUserFence(uint32_t ctxId, uint16_t op, uint64_t addr, uint64_t value, int64_t timeout, bool userInterrupt, uint32_t externalInterruptId) { + drm_xe_wait_user_fence waitUserFence = {}; + + setupXeWaitUserFenceStruct(&waitUserFence, ctxId, op, addr, value, timeout); + + auto retVal = IoctlHelper::ioctl(DrmIoctl::gemWaitUserFence, &waitUserFence); + xeLog(" -> IoctlHelperXe::%s a=0x%llx v=0x%llx T=0x%llx F=0x%x ctx=0x%x retVal=0x%x\n", __FUNCTION__, + addr, value, timeout, waitUserFence.flags, ctxId, retVal); return retVal; } int IoctlHelperXe::waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) { + uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) { xeLog(" -> IoctlHelperXe::%s a=0x%llx v=0x%llx w=0x%x T=0x%llx F=0x%x ctx=0x%x\n", __FUNCTION__, address, value, dataWidth, timeout, flags, ctxId); UNRECOVERABLE_IF(dataWidth != static_cast(Drm::ValueWidth::u64)); if (address) { - return xeWaitUserFence(ctxId, DRM_XE_UFENCE_WAIT_OP_GTE, address, value, timeout); + return xeWaitUserFence(ctxId, DRM_XE_UFENCE_WAIT_OP_GTE, address, value, timeout, userInterrupt, externalInterruptId); } return 0; } @@ -1290,7 +1297,8 @@ int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) { auto timeout = debuggingEnabled ? infiniteTimeout : oneSecTimeout; return xeWaitUserFence(bind.exec_queue_id, DRM_XE_UFENCE_WAIT_OP_EQ, sync[0].addr, - sync[0].timeline_value, timeout); + sync[0].timeline_value, timeout, + false, NEO::InterruptId::notUsed); } xeLog("error: -> IoctlHelperXe::%s %s index=%d vmid=0x%x h=0x%x s=0x%llx o=0x%llx l=0x%llx f=0x%llx pat=%hu r=%d\n", 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 2216a0eb6c..046b79f619 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -47,7 +47,8 @@ class IoctlHelperXe : public IoctlHelper { uint16_t closAllocWays(CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) override; CacheRegion closFree(CacheRegion closIndex) override; int waitUserFence(uint32_t ctxId, uint64_t address, - uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) override; + uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags, + bool userInterrupt, uint32_t externalInterruptId) override; uint32_t getAtomicAdvise(bool isNonAtomic) override; uint32_t getAtomicAccess(AtomicAccessMode mode) override; uint32_t getPreferredLocationAdvise() override; @@ -139,7 +140,8 @@ class IoctlHelperXe : public IoctlHelper { const char *xeGetengineClassName(uint32_t engineClass); template std::vector queryData(uint32_t queryId); - int xeWaitUserFence(uint32_t ctxId, uint16_t op, uint64_t addr, uint64_t value, int64_t timeout); + virtual int xeWaitUserFence(uint32_t ctxId, uint16_t op, uint64_t addr, uint64_t value, int64_t timeout, bool userInterrupt, uint32_t externalInterruptId); + void setupXeWaitUserFenceStruct(void *arg, uint32_t ctxId, uint16_t op, uint64_t addr, uint64_t value, int64_t timeout); int xeVmBind(const VmBindParams &vmBindParams, bool bindOp); void xeShowBindTable(); void updateBindInfo(uint32_t handle, uint64_t userPtr, uint64_t size); 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 aa01e6602d..c58f8bf375 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 @@ -300,7 +300,7 @@ TEST_F(IoctlHelperPrelimFixture, givenPrelimsWhenWaitUserFenceThenCorrectValueRe uint64_t value = 0x98765ull; auto ioctlHelper = drm->getIoctlHelper(); for (uint32_t i = 0u; i < 4; i++) { - auto ret = ioctlHelper->waitUserFence(10u, gpuAddress, value, i, -1, 0u); + auto ret = ioctlHelper->waitUserFence(10u, gpuAddress, value, i, -1, 0u, false, NEO::InterruptId::notUsed); EXPECT_EQ(0, ret); } } 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/ioctl_helper_xe_tests.h index 80e7e989d3..adcd44eb34 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.h @@ -270,6 +270,7 @@ class DrmMockXe : public DrmMockCustom { ret = waitUserFenceReturn; auto waitUserFenceInput = static_cast(arg); waitUserFenceInputs.push_back(*waitUserFenceInput); + handleUserFenceWaitExtensions(waitUserFenceInput); } break; case DrmIoctl::gemContextCreateExt: { @@ -302,6 +303,8 @@ class DrmMockXe : public DrmMockCustom { return ret; } + virtual void handleUserFenceWaitExtensions(drm_xe_wait_user_fence *userFenceWait) {} + void addMockedQueryTopologyData(uint16_t tileId, uint16_t maskType, uint32_t nBytes, const std::vector &mask) { ASSERT_EQ(nBytes, mask.size());