From 8029639898cbb6aed223a05d2d2bd5e3e8e331f9 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Fri, 21 Dec 2018 11:52:46 +0100 Subject: [PATCH] Pin allocation with specific DrmContextId at creation time Change-Id: Ic132fb70b1da2cf3b7c70ab899822705adb83edc Signed-off-by: Dunajski, Bartosz --- .../os_interface/linux/drm_buffer_object.cpp | 1 + .../mocks/linux/mock_drm_memory_manager.h | 1 + .../linux/device_command_stream_fixture.h | 3 ++- .../linux/drm_memory_manager_tests.cpp | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/runtime/os_interface/linux/drm_buffer_object.cpp b/runtime/os_interface/linux/drm_buffer_object.cpp index b48636b1a0..e8e3206c67 100644 --- a/runtime/os_interface/linux/drm_buffer_object.cpp +++ b/runtime/os_interface/linux/drm_buffer_object.cpp @@ -171,6 +171,7 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmC execbuf.buffers_ptr = reinterpret_cast(&execObject[0]); execbuf.buffer_count = boIndex + 1; execbuf.batch_len = alignUp(static_cast(sizeof(uint32_t)), 8); + execbuf.rsvd1 = drmContextId; int err = 0; int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf); diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index 05d0e9b1dd..cee89ad59b 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -41,6 +41,7 @@ class TestedDrmMemoryManager : public DrmMemoryManager { using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr; using DrmMemoryManager::AllocationData; using DrmMemoryManager::allocUserptr; + using DrmMemoryManager::pinThreshold; using DrmMemoryManager::setDomainCpu; using DrmMemoryManager::sharingBufferObjects; diff --git a/unit_tests/os_interface/linux/device_command_stream_fixture.h b/unit_tests/os_interface/linux/device_command_stream_fixture.h index f7134f5f9d..e02d4338e4 100644 --- a/unit_tests/os_interface/linux/device_command_stream_fixture.h +++ b/unit_tests/os_interface/linux/device_command_stream_fixture.h @@ -239,7 +239,8 @@ class DrmMockCustom : public Drm { } break; case DRM_IOCTL_I915_GEM_CONTEXT_CREATE: { - ioctl_cnt.contextCreate++; + auto contextCreateParam = reinterpret_cast(arg); + contextCreateParam->ctx_id = ++ioctl_cnt.contextCreate; } break; case DRM_IOCTL_I915_GEM_CONTEXT_DESTROY: { ioctl_cnt.contextDestroy++; diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index f8ff02c34e..89d2a288dd 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -21,6 +21,7 @@ #include "runtime/os_interface/linux/drm_buffer_object.h" #include "runtime/os_interface/linux/drm_command_stream.h" #include "runtime/os_interface/linux/drm_memory_manager.h" +#include "runtime/os_interface/linux/os_context_linux.h" #include "runtime/os_interface/linux/os_interface.h" #include "runtime/os_interface/32bit_memory.h" #include "runtime/os_interface/os_context.h" @@ -219,6 +220,23 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation memoryManager->freeGraphicsMemory(alloc); } +TEST_F(DrmMemoryManagerTest, givenDrmContextIdWhenAllocationIsCreatedThenPinWithPassedDrmContextId) { + mock->ioctl_expected.gemUserptr = 2; + mock->ioctl_expected.execbuffer2 = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 2; + + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); + auto drmContextId = memoryManager->getDefaultCommandStreamReceiver(0)->getOsContext().get()->getDrmContextId(); + ASSERT_NE(nullptr, memoryManager->getPinBB()); + EXPECT_NE(0u, drmContextId); + + auto alloc = memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(memoryManager->pinThreshold, true)); + EXPECT_EQ(drmContextId, mock->execBuffer.rsvd1); + + memoryManager->freeGraphicsMemory(alloc); +} + TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAllocation) { mock->ioctl_expected.gemUserptr = 2; mock->ioctl_expected.gemWait = 1;