diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 4fbac9faa0..7c0317cbee 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1272,11 +1272,11 @@ unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, au } void Drm::waitForBind(uint32_t vmHandleId) { - if (pagingFence[vmHandleId] >= fenceVal[vmHandleId]) { + if (*ioctlHelper->getPagingFenceAddress(vmHandleId, nullptr) >= fenceVal[vmHandleId]) { return; } auto lock = this->lockBindFenceMutex(); - auto fenceAddress = castToUint64(&this->pagingFence[vmHandleId]); + auto fenceAddress = castToUint64(ioctlHelper->getPagingFenceAddress(vmHandleId, nullptr)); auto fenceValue = this->fenceVal[vmHandleId]; lock.unlock(); @@ -1401,10 +1401,10 @@ void programUserFence(Drm *drm, OsContext *osContext, BufferObject *bo, VmBindEx if (drm->isPerContextVMRequired()) { auto osContextLinux = static_cast(osContext); - address = castToUint64(osContextLinux->getFenceAddr(vmHandleId)); + address = castToUint64(ioctlHelper->getPagingFenceAddress(vmHandleId, osContextLinux)); value = osContextLinux->getNextFenceVal(vmHandleId); } else { - address = castToUint64(drm->getFenceAddr(vmHandleId)); + address = castToUint64(ioctlHelper->getPagingFenceAddress(vmHandleId, nullptr)); value = drm->getNextFenceVal(vmHandleId); } diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index 267e387a64..b44808397b 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -13,6 +13,7 @@ #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/drm_wrappers.h" +#include "shared/source/os_interface/linux/os_context_linux.h" #include "shared/source/os_interface/linux/sys_calls.h" #include "drm.h" @@ -79,4 +80,13 @@ std::string IoctlHelper::getIoctlStringBase(DrmIoctl ioctlRequest) const { bool IoctlHelper::checkIfIoctlReinvokeRequired(int error, DrmIoctl ioctlRequest) const { return (error == EINTR || error == EAGAIN || error == EBUSY || error == -EBUSY); } + +uint64_t *IoctlHelper::getPagingFenceAddress(uint32_t vmHandleId, OsContextLinux *osContext) { + if (osContext) { + return osContext->getFenceAddr(vmHandleId); + } else { + return drm.getFenceAddr(vmHandleId); + } +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 08f284540d..9ccd63adcf 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -221,6 +221,8 @@ class IoctlHelper { virtual bool allocateInterrupt(uint32_t &outHandle) { return false; } virtual bool releaseInterrupt(uint32_t handle) { return false; } + virtual uint64_t *getPagingFenceAddress(uint32_t vmHandleId, OsContextLinux *osContext); + protected: Drm &drm; ExternalCtx *externalCtx = nullptr; 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 49ea8889c2..9f98c7a06c 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 @@ -2459,3 +2459,16 @@ TEST(IoctlHelperXeTest, givenL3BankWhenGetTopologyDataAndMapThenResultsAreCorrec // verify topology data EXPECT_EQ(12, topologyData.numL3Banks); } + +TEST(IoctlHelperXeTest, givenIoctlHelperWhenGettingFenceAddressThenReturnCorrectValue) { + MockExecutionEnvironment executionEnvironment{}; + std::unique_ptr drm{Drm::create(std::make_unique(0, ""), *executionEnvironment.rootDeviceEnvironments[0])}; + IoctlHelperXe ioctlHelper{*drm}; + + auto fenceAddr = ioctlHelper.getPagingFenceAddress(0, nullptr); + EXPECT_EQ(drm->getFenceAddr(0), fenceAddr); + + OsContextLinux osContext(*drm, 0, 5u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_CCS, EngineUsage::lowPriority})); + fenceAddr = ioctlHelper.getPagingFenceAddress(0, &osContext); + EXPECT_EQ(osContext.getFenceAddr(0), fenceAddr); +}