Skip to content

Commit 8029639

Browse files
Pin allocation with specific DrmContextId at creation time
Change-Id: Ic132fb70b1da2cf3b7c70ab899822705adb83edc Signed-off-by: Dunajski, Bartosz <[email protected]>
1 parent ebd0889 commit 8029639

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

runtime/os_interface/linux/drm_buffer_object.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmC
171171
execbuf.buffers_ptr = reinterpret_cast<uintptr_t>(&execObject[0]);
172172
execbuf.buffer_count = boIndex + 1;
173173
execbuf.batch_len = alignUp(static_cast<uint32_t>(sizeof(uint32_t)), 8);
174+
execbuf.rsvd1 = drmContextId;
174175

175176
int err = 0;
176177
int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);

unit_tests/mocks/linux/mock_drm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TestedDrmMemoryManager : public DrmMemoryManager {
4141
using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr;
4242
using DrmMemoryManager::AllocationData;
4343
using DrmMemoryManager::allocUserptr;
44+
using DrmMemoryManager::pinThreshold;
4445
using DrmMemoryManager::setDomainCpu;
4546
using DrmMemoryManager::sharingBufferObjects;
4647

unit_tests/os_interface/linux/device_command_stream_fixture.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ class DrmMockCustom : public Drm {
239239
} break;
240240

241241
case DRM_IOCTL_I915_GEM_CONTEXT_CREATE: {
242-
ioctl_cnt.contextCreate++;
242+
auto contextCreateParam = reinterpret_cast<drm_i915_gem_context_create *>(arg);
243+
contextCreateParam->ctx_id = ++ioctl_cnt.contextCreate;
243244
} break;
244245
case DRM_IOCTL_I915_GEM_CONTEXT_DESTROY: {
245246
ioctl_cnt.contextDestroy++;

unit_tests/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "runtime/os_interface/linux/drm_buffer_object.h"
2222
#include "runtime/os_interface/linux/drm_command_stream.h"
2323
#include "runtime/os_interface/linux/drm_memory_manager.h"
24+
#include "runtime/os_interface/linux/os_context_linux.h"
2425
#include "runtime/os_interface/linux/os_interface.h"
2526
#include "runtime/os_interface/32bit_memory.h"
2627
#include "runtime/os_interface/os_context.h"
@@ -219,6 +220,23 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
219220
memoryManager->freeGraphicsMemory(alloc);
220221
}
221222

223+
TEST_F(DrmMemoryManagerTest, givenDrmContextIdWhenAllocationIsCreatedThenPinWithPassedDrmContextId) {
224+
mock->ioctl_expected.gemUserptr = 2;
225+
mock->ioctl_expected.execbuffer2 = 1;
226+
mock->ioctl_expected.gemWait = 1;
227+
mock->ioctl_expected.gemClose = 2;
228+
229+
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(this->mock, true, false, *executionEnvironment);
230+
auto drmContextId = memoryManager->getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId();
231+
ASSERT_NE(nullptr, memoryManager->getPinBB());
232+
EXPECT_NE(0u, drmContextId);
233+
234+
auto alloc = memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(memoryManager->pinThreshold, true));
235+
EXPECT_EQ(drmContextId, mock->execBuffer.rsvd1);
236+
237+
memoryManager->freeGraphicsMemory(alloc);
238+
}
239+
222240
TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAllocation) {
223241
mock->ioctl_expected.gemUserptr = 2;
224242
mock->ioctl_expected.gemWait = 1;

0 commit comments

Comments
 (0)