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 9b683986db..88161feaae 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -435,6 +435,12 @@ bool IoctlHelperXe::getTopologyDataAndMap(const HardwareInfo &hwInfo, DrmQueryTo return true; } +void IoctlHelperXe::updateBindInfo(uint32_t handle, uint64_t userPtr, uint64_t size) { + std::unique_lock lock(xeLock); + BindInfo b = {handle, userPtr, 0, size}; + bindInfo.push_back(b); +} + int IoctlHelperXe::createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks) { struct drm_xe_gem_create create = {}; uint32_t regionsSize = static_cast(memClassInstances.size()); @@ -462,13 +468,7 @@ int IoctlHelperXe::createGemExt(const MemRegionsVec &memClassInstances, size_t a xeLog(" -> IoctlHelperXe::%s [%d,%d] vmid=0x%x s=0x%lx f=0x%x h=0x%x r=%d\n", __FUNCTION__, mem.memoryClass, mem.memoryInstance, create.vm_id, create.size, create.flags, handle, ret); - - { - std::unique_lock lock(xeLock); - BindInfo b = {create.handle, 0, 0, create.size}; - bindInfo.push_back(b); - } - + updateBindInfo(create.handle, 0u, create.size); return ret; } @@ -496,6 +496,7 @@ uint32_t IoctlHelperXe::createGem(uint64_t size, uint32_t memoryBanks) { create.flags = static_cast(memoryInstances.to_ulong()); [[maybe_unused]] auto ret = ioctl(DrmIoctl::GemCreate, &create); DEBUG_BREAK_IF(ret != 0); + updateBindInfo(create.handle, 0u, create.size); return create.handle; } @@ -984,11 +985,7 @@ int IoctlHelperXe::ioctl(DrmIoctl request, void *arg) { case DrmIoctl::GemUserptr: { GemUserPtr *d = static_cast(arg); d->handle = userPtrHandle++ | XE_USERPTR_FAKE_FLAG; - { - std::unique_lock lock(xeLock); - BindInfo b = {d->handle, d->userPtr, 0, d->userSize}; - bindInfo.push_back(b); - } + updateBindInfo(d->handle, d->userPtr, d->userSize); ret = 0; xeLog(" -> IoctlHelperXe::ioctl GemUserptrGemUserptr p=0x%llx s=0x%llx f=0x%x h=0x%x r=%d\n", d->userPtr, d->userSize, d->flags, d->handle, ret); 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 280b4d1337..dfbec0d9b4 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -111,7 +111,6 @@ class IoctlHelperXe : public IoctlHelper { uint32_t xeSyncObjCreate(uint32_t flags); bool xeSyncObjWait(uint32_t *handles, uint32_t count, uint64_t absTimeoutNsec, uint32_t flags, uint32_t *firstSignaled); void xeSyncObjDestroy(uint32_t handle); - int xeGetQuery(Query *data); struct drm_xe_engine_class_instance *xeFindMatchingEngine(uint16_t engineClass, uint16_t engineInstance); @@ -123,6 +122,7 @@ class IoctlHelperXe : public IoctlHelper { int xeWaitUserFence(uint64_t mask, 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); struct UserFenceExtension { static constexpr uint32_t tagValue = 0x123987; 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 10f87b116f..bd5a15fcd7 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 @@ -65,7 +65,7 @@ TEST(IoctlHelperXeTest, whenChangingBufferBindingThenWaitIsNeededAlways) { TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsThenDummyValueIsReturned) { auto executionEnvironment = std::make_unique(); DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - auto xeIoctlHelper = std::make_unique(drm); + auto xeIoctlHelper = std::make_unique(drm); ASSERT_NE(nullptr, xeIoctlHelper); std::vector regionInfo(2); @@ -77,13 +77,16 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsThen uint32_t handle = 0u; uint32_t numOfChunks = 0; + + EXPECT_TRUE(xeIoctlHelper->bindInfo.empty()); EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, {}, -1, false, numOfChunks)); + EXPECT_FALSE(xeIoctlHelper->bindInfo.empty()); } TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsAndVmIdThenDummyValueIsReturned) { auto executionEnvironment = std::make_unique(); DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]}; - auto xeIoctlHelper = std::make_unique(drm); + auto xeIoctlHelper = std::make_unique(drm); ASSERT_NE(nullptr, xeIoctlHelper); std::vector regionInfo(2); @@ -95,8 +98,11 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallingGemCreateExtWithRegionsAndV uint32_t handle = 0u; uint32_t numOfChunks = 0; + GemVmControl test = {}; + EXPECT_TRUE(xeIoctlHelper->bindInfo.empty()); EXPECT_NE(0, xeIoctlHelper->createGemExt(memRegions, 0u, handle, 0, test.vmId, -1, false, numOfChunks)); + EXPECT_FALSE(xeIoctlHelper->bindInfo.empty()); } inline constexpr int testValueVmId = 0x5764; @@ -329,7 +335,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndNoLocalMemoryThenP auto executionEnvironment = std::make_unique(); DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; - auto xeIoctlHelper = std::make_unique(drm); + auto xeIoctlHelper = std::make_unique(drm); drm.memoryInfo.reset(xeIoctlHelper->createMemoryInfo().release()); ASSERT_NE(nullptr, xeIoctlHelper); @@ -337,8 +343,10 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndNoLocalMemoryThenP uint32_t memoryBanks = 3u; EXPECT_EQ(0, drm.ioctlCnt.gemCreate); + EXPECT_TRUE(xeIoctlHelper->bindInfo.empty()); uint32_t handle = xeIoctlHelper->createGem(size, memoryBanks); EXPECT_EQ(1, drm.ioctlCnt.gemCreate); + EXPECT_FALSE(xeIoctlHelper->bindInfo.empty()); EXPECT_EQ(size, drm.createParamsSize); EXPECT_EQ(1u, drm.createParamsFlags); @@ -354,7 +362,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateWhenMemoryBanksZeroTh auto executionEnvironment = std::make_unique(); DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; - auto xeIoctlHelper = std::make_unique(drm); + auto xeIoctlHelper = std::make_unique(drm); drm.memoryInfo.reset(xeIoctlHelper->createMemoryInfo().release()); ASSERT_NE(nullptr, xeIoctlHelper); @@ -362,8 +370,10 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateWhenMemoryBanksZeroTh uint32_t memoryBanks = 0u; EXPECT_EQ(0, drm.ioctlCnt.gemCreate); + EXPECT_TRUE(xeIoctlHelper->bindInfo.empty()); uint32_t handle = xeIoctlHelper->createGem(size, memoryBanks); EXPECT_EQ(1, drm.ioctlCnt.gemCreate); + EXPECT_FALSE(xeIoctlHelper->bindInfo.empty()); EXPECT_EQ(size, drm.createParamsSize); EXPECT_EQ(1u, drm.createParamsFlags); @@ -379,7 +389,7 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndLocalMemoryThenPro auto executionEnvironment = std::make_unique(); DrmMockXe drm{*executionEnvironment->rootDeviceEnvironments[0]}; - auto xeIoctlHelper = std::make_unique(drm); + auto xeIoctlHelper = std::make_unique(drm); drm.memoryInfo.reset(xeIoctlHelper->createMemoryInfo().release()); ASSERT_NE(nullptr, xeIoctlHelper); @@ -387,8 +397,10 @@ TEST(IoctlHelperXeTest, givenIoctlHelperXeWhenCallGemCreateAndLocalMemoryThenPro uint32_t memoryBanks = 3u; EXPECT_EQ(0, drm.ioctlCnt.gemCreate); + EXPECT_TRUE(xeIoctlHelper->bindInfo.empty()); uint32_t handle = xeIoctlHelper->createGem(size, memoryBanks); EXPECT_EQ(1, drm.ioctlCnt.gemCreate); + EXPECT_FALSE(xeIoctlHelper->bindInfo.empty()); EXPECT_EQ(size, drm.createParamsSize); EXPECT_EQ(6u, drm.createParamsFlags);