Skip to content

Commit c0b7f05

Browse files
Add memory prefetch for kmd migrated shared allocations
This feature is disabled by default, controlled with the knob AppendMemoryPrefetchForKmdMigratedSharedAllocations Related-To: NEO-6740 Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent 10e7b9d commit c0b7f05

File tree

16 files changed

+244
-0
lines changed

16 files changed

+244
-0
lines changed

level_zero/core/source/xe_hpc_core/cmdlist_xe_hpc_core.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ ze_result_t CommandListCoreFamily<IGFX_XE_HPC_CORE>::appendMemoryPrefetch(const
3131
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
3232
}
3333

34+
auto allowPrefetchingKmdMigratedSharedAllocation = false;
35+
if (NEO::DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.get() != -1) {
36+
allowPrefetchingKmdMigratedSharedAllocation = !!NEO::DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.get();
37+
}
38+
39+
if (allowPrefetchingKmdMigratedSharedAllocation) {
40+
auto memoryManager = device->getDriverHandle()->getMemoryManager();
41+
if (memoryManager->isKmdMigrationAvailable(device->getRootDeviceIndex()) &&
42+
(allocData->memoryType == InternalMemoryType::SHARED_UNIFIED_MEMORY)) {
43+
auto alloc = allocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
44+
memoryManager->setMemPrefetch(alloc, device->getRootDeviceIndex());
45+
}
46+
}
47+
3448
if (NEO::DebugManager.flags.AddStatePrefetchCmdToMemoryPrefetchAPI.get() != 1) {
3549
return ZE_RESULT_SUCCESS;
3650
}

level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,137 @@ HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenDebugFlagSetWhenPrefetchApiCal
105105
context->freeMem(ptr);
106106
}
107107

108+
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenUnifiedSharedMemoryWhenPrefetchApiCalledThenDontSetMemPrefetch, IsXeHpcCore) {
109+
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
110+
auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
111+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
112+
113+
size_t size = 10;
114+
size_t alignment = 1u;
115+
void *ptr = nullptr;
116+
117+
ze_device_mem_alloc_desc_t deviceDesc = {};
118+
ze_host_mem_alloc_desc_t hostDesc = {};
119+
auto res = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr);
120+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
121+
EXPECT_NE(nullptr, ptr);
122+
123+
auto ret = pCommandList->appendMemoryPrefetch(ptr, size);
124+
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
125+
126+
auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager());
127+
EXPECT_FALSE(memoryManager->setMemPrefetchCalled);
128+
129+
context->freeMem(ptr);
130+
}
131+
132+
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsWhenPrefetchApiCalledThenDontCallSetMemPrefetchByDefault, IsXeHpcCore) {
133+
DebugManagerStateRestore restore;
134+
DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1);
135+
136+
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
137+
auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
138+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
139+
140+
size_t size = 10;
141+
size_t alignment = 1u;
142+
void *ptr = nullptr;
143+
144+
ze_device_mem_alloc_desc_t deviceDesc = {};
145+
ze_host_mem_alloc_desc_t hostDesc = {};
146+
auto res = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr);
147+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
148+
EXPECT_NE(nullptr, ptr);
149+
150+
auto ret = pCommandList->appendMemoryPrefetch(ptr, size);
151+
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
152+
153+
auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager());
154+
EXPECT_FALSE(memoryManager->setMemPrefetchCalled);
155+
156+
context->freeMem(ptr);
157+
}
158+
159+
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiCalledOnUnifiedSharedMemoryThenCallSetMemPrefetch, IsXeHpcCore) {
160+
DebugManagerStateRestore restore;
161+
DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1);
162+
DebugManager.flags.UseKmdMigration.set(1);
163+
164+
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
165+
auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
166+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
167+
168+
size_t size = 10;
169+
size_t alignment = 1u;
170+
void *ptr = nullptr;
171+
172+
ze_device_mem_alloc_desc_t deviceDesc = {};
173+
ze_host_mem_alloc_desc_t hostDesc = {};
174+
auto res = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr);
175+
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
176+
EXPECT_NE(nullptr, ptr);
177+
178+
auto ret = pCommandList->appendMemoryPrefetch(ptr, size);
179+
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
180+
181+
auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager());
182+
EXPECT_TRUE(memoryManager->setMemPrefetchCalled);
183+
184+
context->freeMem(ptr);
185+
}
186+
187+
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiCalledOnUnifiedDeviceMemoryThenDontCallSetMemPrefetch, IsXeHpcCore) {
188+
DebugManagerStateRestore restore;
189+
DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1);
190+
DebugManager.flags.UseKmdMigration.set(1);
191+
192+
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
193+
auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
194+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
195+
196+
size_t size = 10;
197+
size_t alignment = 1u;
198+
void *ptr = nullptr;
199+
200+
ze_device_mem_alloc_desc_t deviceDesc = {};
201+
context->allocDeviceMem(device->toHandle(), &deviceDesc, size, alignment, &ptr);
202+
EXPECT_NE(nullptr, ptr);
203+
204+
auto ret = pCommandList->appendMemoryPrefetch(ptr, size);
205+
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
206+
207+
auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager());
208+
EXPECT_FALSE(memoryManager->setMemPrefetchCalled);
209+
210+
context->freeMem(ptr);
211+
}
212+
213+
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenAppendMemoryPrefetchForKmdMigratedSharedAllocationsSetWhenPrefetchApiCalledOnUnifiedHostMemoryThenDontCallSetMemPrefetch, IsXeHpcCore) {
214+
DebugManagerStateRestore restore;
215+
DebugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(1);
216+
DebugManager.flags.UseKmdMigration.set(1);
217+
218+
auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
219+
auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u);
220+
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
221+
222+
size_t size = 10;
223+
size_t alignment = 1u;
224+
void *ptr = nullptr;
225+
226+
ze_host_mem_alloc_desc_t hostDesc = {};
227+
context->allocHostMem(&hostDesc, size, alignment, &ptr);
228+
EXPECT_NE(nullptr, ptr);
229+
230+
auto ret = pCommandList->appendMemoryPrefetch(ptr, size);
231+
EXPECT_EQ(ZE_RESULT_SUCCESS, ret);
232+
233+
auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager());
234+
EXPECT_FALSE(memoryManager->setMemPrefetchCalled);
235+
236+
context->freeMem(ptr);
237+
}
238+
108239
HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenCommandBufferIsExhaustedWhenPrefetchApiCalledThenProgramStatePrefetch, IsXeHpcCore) {
109240
using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH;
110241
using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END;

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4941,6 +4941,16 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemAdviseIsCalledThenUp
49414941
}
49424942
}
49434943

4944+
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetMemPrefetchIsCalledThenReturnTrue) {
4945+
TestedDrmMemoryManager memoryManager(false, false, false, *executionEnvironment);
4946+
BufferObject bo(mock, 1, 1024, 0);
4947+
4948+
DrmAllocation drmAllocation(0, AllocationType::UNIFIED_SHARED_MEMORY, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
4949+
EXPECT_EQ(&bo, drmAllocation.getBO());
4950+
4951+
EXPECT_TRUE(memoryManager.setMemPrefetch(&drmAllocation, rootDeviceIndex));
4952+
}
4953+
49444954
TEST_F(DrmMemoryManagerTest, givenPageFaultIsUnSupportedWhenCallingBindBoOnBufferAllocationThenAllocationShouldNotPageFaultAndExplicitResidencyIsNotRequired) {
49454955
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
49464956
executionEnvironment->prepareRootDeviceEnvironments(1);

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ UseDrmVirtualEnginesForBcs = -1
389389
LimitEngineCountForVirtualBcs = -1
390390
LimitEngineCountForVirtualCcs = -1
391391
ForceRunAloneContext = -1
392+
AppendMemoryPrefetchForKmdMigratedSharedAllocations = -1
392393
CreateContextWithAccessCounters = -1
393394
AccessCountersTrigger = -1
394395
AccessCountersGranularity = -1

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, UseDrmVirtualEnginesForBcs, -1, "-1: default, 0:
187187
DECLARE_DEBUG_VARIABLE(int32_t, LimitEngineCountForVirtualBcs, -1, "-1: default, >0 Only use VirtualEngine with limited amount of engines, not max ")
188188
DECLARE_DEBUG_VARIABLE(int32_t, LimitEngineCountForVirtualCcs, -1, "-1: default, >0 Only use VirtualEngine with limited amount of engines, not max ")
189189
DECLARE_DEBUG_VARIABLE(int32_t, CreateContextWithAccessCounters, -1, "-1: default, 0: ignore, 1: create context with Access Counter programming")
190+
DECLARE_DEBUG_VARIABLE(int32_t, AppendMemoryPrefetchForKmdMigratedSharedAllocations, -1, "-1: default, 0: ignore, 1: allow prefetching shared memory to the device associated with the specified command list")
190191
DECLARE_DEBUG_VARIABLE(int32_t, AccessCountersTrigger, -1, "-1: default - disabled, 0: disabled, >= 0: triggering thresholds")
191192
DECLARE_DEBUG_VARIABLE(int32_t, AccessCountersGranularity, -1, "-1: default - ACG_2MB, >= 0: granularites - 0: ACG_128K, 1: ACG_2M, 2: ACG_16M, 3: ACG_16M")
192193
DECLARE_DEBUG_VARIABLE(int32_t, OverridePatIndex, -1, "-1: default, >=0: PatIndex to override")

shared/source/memory_manager/memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class MemoryManager {
219219
virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){};
220220

221221
virtual bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) { return true; }
222+
virtual bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) { return true; }
222223

223224
bool isExternalAllocation(AllocationType allocationType);
224225
LocalMemoryUsageBankSelector *getLocalMemoryUsageBankSelector(AllocationType allocationType, uint32_t rootDeviceIndex);

shared/source/os_interface/linux/drm_allocation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ bool DrmAllocation::setMemAdvise(Drm *drm, MemAdviseFlags flags) {
291291
return success;
292292
}
293293

294+
bool DrmAllocation::setMemPrefetch(Drm *drm) {
295+
bool success = true;
296+
auto ioctlHelper = drm->getIoctlHelper();
297+
298+
for (auto bo : bufferObjects) {
299+
if (bo != nullptr) {
300+
auto region = static_cast<uint32_t>((I915_MEMORY_CLASS_DEVICE << 16u) | 0u);
301+
success &= ioctlHelper->setVmPrefetch(drm, bo->peekAddress(), bo->peekSize(), region);
302+
}
303+
}
304+
305+
return success;
306+
}
307+
294308
void DrmAllocation::registerMemoryToUnmap(void *pointer, size_t size, DrmAllocation::MemoryUnmapFunction unmapFunction) {
295309
this->memoryToUnmap.push_back({pointer, size, unmapFunction});
296310
}

shared/source/os_interface/linux/drm_allocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class DrmAllocation : public GraphicsAllocation {
8585
void setCachePolicy(CachePolicy memType);
8686

8787
bool setMemAdvise(Drm *drm, MemAdviseFlags flags);
88+
bool setMemPrefetch(Drm *drm);
8889

8990
void *getMmapPtr() { return this->mmapPtr; }
9091
void setMmapPtr(void *ptr) { this->mmapPtr = ptr; }

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ bool DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdvise
229229
return drmAllocation->setMemAdvise(&this->getDrm(rootDeviceIndex), flags);
230230
}
231231

232+
bool DrmMemoryManager::setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) {
233+
auto drmAllocation = static_cast<DrmAllocation *>(gfxAllocation);
234+
235+
return drmAllocation->setMemPrefetch(&this->getDrm(rootDeviceIndex));
236+
}
237+
232238
NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex) {
233239
drm_i915_gem_userptr userptr = {};
234240
userptr.user_ptr = address;

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class DrmMemoryManager : public MemoryManager {
6868
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
6969

7070
bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) override;
71+
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) override;
7172

7273
std::unique_lock<std::mutex> acquireAllocLock();
7374
std::vector<GraphicsAllocation *> &getSysMemAllocs();

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class IoctlHelper {
9292
virtual uint32_t getAtomicAdvise(bool isNonAtomic) = 0;
9393
virtual uint32_t getPreferredLocationAdvise() = 0;
9494
virtual bool setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attribute, void *region) = 0;
95+
virtual bool setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) = 0;
9596
virtual uint32_t getDirectSubmissionFlag() = 0;
9697
virtual int32_t getMemRegionsIoctlVal() = 0;
9798
virtual int32_t getEngineInfoIoctlVal() = 0;
@@ -142,6 +143,7 @@ class IoctlHelperUpstream : public IoctlHelper {
142143
uint32_t getAtomicAdvise(bool isNonAtomic) override;
143144
uint32_t getPreferredLocationAdvise() override;
144145
bool setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attribute, void *region) override;
146+
bool setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) override;
145147
uint32_t getDirectSubmissionFlag() override;
146148
int32_t getMemRegionsIoctlVal() override;
147149
int32_t getEngineInfoIoctlVal() override;
@@ -205,6 +207,7 @@ class IoctlHelperPrelim20 : public IoctlHelper {
205207
uint32_t getAtomicAdvise(bool isNonAtomic) override;
206208
uint32_t getPreferredLocationAdvise() override;
207209
bool setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attribute, void *region) override;
210+
bool setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) override;
208211
uint32_t getDirectSubmissionFlag() override;
209212
int32_t getMemRegionsIoctlVal() override;
210213
int32_t getEngineInfoIoctlVal() override;

shared/source/os_interface/linux/ioctl_helper_prelim.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ bool IoctlHelperPrelim20::setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attri
198198
return true;
199199
}
200200

201+
bool IoctlHelperPrelim20::setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) {
202+
prelim_drm_i915_gem_vm_prefetch vmPrefetch{};
203+
204+
vmPrefetch.length = length;
205+
vmPrefetch.region = region;
206+
vmPrefetch.start = start;
207+
208+
int ret = IoctlHelper::ioctl(drm, PRELIM_DRM_IOCTL_I915_GEM_VM_PREFETCH, &vmPrefetch);
209+
if (ret != 0) {
210+
int err = errno;
211+
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(PRELIM_DRM_I915_GEM_VM_PREFETCH) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
212+
DEBUG_BREAK_IF(true);
213+
return false;
214+
}
215+
return true;
216+
}
217+
201218
uint32_t IoctlHelperPrelim20::getDirectSubmissionFlag() {
202219
return PRELIM_I915_CONTEXT_CREATE_FLAGS_ULLS;
203220
}

shared/source/os_interface/linux/ioctl_helper_upstream.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ bool IoctlHelperUpstream::setVmBoAdvise(Drm *drm, int32_t handle, uint32_t attri
101101
return true;
102102
}
103103

104+
bool IoctlHelperUpstream::setVmPrefetch(Drm *drm, uint64_t start, uint64_t length, uint32_t region) {
105+
return true;
106+
}
107+
104108
uint32_t IoctlHelperUpstream::getDirectSubmissionFlag() {
105109
return 0u;
106110
}

shared/test/common/mocks/mock_memory_manager.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
149149
return MemoryManager::setMemAdvise(gfxAllocation, flags, rootDeviceIndex);
150150
}
151151

152+
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t rootDeviceIndex) override {
153+
setMemPrefetchCalled = true;
154+
return MemoryManager::setMemPrefetch(gfxAllocation, rootDeviceIndex);
155+
}
156+
157+
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override {
158+
if (DebugManager.flags.UseKmdMigration.get() != -1) {
159+
return !!DebugManager.flags.UseKmdMigration.get();
160+
}
161+
return false;
162+
}
163+
152164
struct CopyMemoryToAllocationBanksParams {
153165
GraphicsAllocation *graphicsAllocation = nullptr;
154166
size_t destinationOffset = 0u;
@@ -221,6 +233,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
221233
bool failAllocateSystemMemory = false;
222234
bool failAllocate32Bit = false;
223235
bool failSetMemAdvise = false;
236+
bool setMemPrefetchCalled = false;
224237
bool cpuCopyRequired = false;
225238
bool forceCompressed = false;
226239
bool forceFailureInPrimaryAllocation = false;

shared/test/unit_test/os_interface/linux/drm_with_prelim_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemAdviseWithDevicePre
252252
EXPECT_EQ(2u, drm->ioctlCallsCount);
253253
}
254254

255+
TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchSucceedsThenReturnTrue) {
256+
MockBufferObject bo(drm.get(), 0, 0, 1);
257+
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory);
258+
allocation.bufferObjects[0] = &bo;
259+
260+
drm->ioctlRetVal = 0;
261+
EXPECT_TRUE(allocation.setMemPrefetch(drm.get()));
262+
}
263+
264+
TEST_F(IoctlHelperPrelimFixture, givenDrmAllocationWhenSetMemPrefetchFailsThenReturnFalse) {
265+
MockBufferObject bo(drm.get(), 0, 0, 1);
266+
MockDrmAllocation allocation(AllocationType::BUFFER, MemoryPool::LocalMemory);
267+
allocation.bufferObjects[0] = &bo;
268+
269+
drm->ioctlRetVal = EINVAL;
270+
EXPECT_FALSE(allocation.setMemPrefetch(drm.get()));
271+
}
272+
255273
TEST_F(IoctlHelperPrelimFixture, givenVariousDirectSubmissionFlagSettingWhenCreateDrmContextIsCalledThenCorrectFlagsArePassedToIoctl) {
256274
DebugManagerStateRestore stateRestore;
257275
uint32_t vmId = 0u;

shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenSetVmBoAdviseThenReturnTrue) {
169169
EXPECT_TRUE(ioctlHelper->setVmBoAdvise(drm.get(), 0, 0, nullptr));
170170
}
171171

172+
TEST(IoctlHelperTestsUpstream, givenUpstreamWhenSetVmPrefetchThenReturnTrue) {
173+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
174+
executionEnvironment->prepareRootDeviceEnvironments(1);
175+
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
176+
177+
auto ioctlHelper = drm->getIoctlHelper();
178+
EXPECT_TRUE(ioctlHelper->setVmPrefetch(drm.get(), 0, 0, 0));
179+
}
180+
172181
TEST(IoctlHelperTestsUpstream, givenUpstreamWhenDirectSubmissionEnabledThenNoFlagsAdded) {
173182
DebugManagerStateRestore stateRestore;
174183
DebugManager.flags.DirectSubmissionDrmContext.set(1);

0 commit comments

Comments
 (0)