From 49cd8e4e1b1193a9e8ed15fa2078ec9913e888b0 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Tue, 28 Jul 2020 07:48:41 +0200 Subject: [PATCH] Bind bos to proper VM Change-Id: I536ff342875bba39cf9a9922fcf647af408ae398 Signed-off-by: Lukasz Jobczyk --- .../os_interface/linux/drm_command_stream.inl | 2 +- .../linux/drm_command_stream_fixture.h | 2 +- .../os_interface/linux/drm_allocation.cpp | 12 ++++----- .../os_interface/linux/drm_allocation.h | 6 ++--- .../linux/drm_allocation_extended.cpp | 4 +-- .../os_interface/linux/drm_buffer_object.cpp | 27 ++++++++++++------- .../os_interface/linux/drm_buffer_object.h | 11 +++++--- .../drm_memory_operations_handler_bind.cpp | 6 ++--- shared/source/os_interface/linux/drm_neo.h | 4 +-- .../source/os_interface/linux/drm_query.cpp | 4 +-- .../os_interface/linux/drm_query_dg1.cpp | 4 +-- 11 files changed, 47 insertions(+), 35 deletions(-) diff --git a/opencl/source/os_interface/linux/drm_command_stream.inl b/opencl/source/os_interface/linux/drm_command_stream.inl index 86bfa48aaf..631efacbca 100644 --- a/opencl/source/os_interface/linux/drm_command_stream.inl +++ b/opencl/source/os_interface/linux/drm_command_stream.inl @@ -116,7 +116,7 @@ template void DrmCommandStreamReceiver::processResidency(const ResidencyContainer &inputAllocationsForResidency, uint32_t handleId) { for (auto &alloc : inputAllocationsForResidency) { auto drmAlloc = static_cast(alloc); - drmAlloc->makeBOsResident(osContext->getContextId(), 0u, handleId, &this->residency, false); + drmAlloc->makeBOsResident(osContext->getContextId(), handleId, &this->residency, false); } } diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h index 0d106632d0..b774f5566e 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h @@ -128,7 +128,7 @@ class DrmCommandStreamEnhancedTemplate : public ::testing::Test { template void makeResidentBufferObjects(DrmAllocation *drmAllocation) { - drmAllocation->bindBOs(0u, 0u, &static_cast *>(csr)->residency, false); + drmAllocation->bindBOs(0u, &static_cast *>(csr)->residency, false); } template diff --git a/shared/source/os_interface/linux/drm_allocation.cpp b/shared/source/os_interface/linux/drm_allocation.cpp index e78e9f90c0..8adf307d3e 100644 --- a/shared/source/os_interface/linux/drm_allocation.cpp +++ b/shared/source/os_interface/linux/drm_allocation.cpp @@ -28,20 +28,20 @@ uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) { return static_cast((static_cast(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex)); } -void DrmAllocation::makeBOsResident(uint32_t osContextId, uint32_t drmContextId, uint32_t handleId, std::vector *bufferObjects, bool bind) { +void DrmAllocation::makeBOsResident(uint32_t osContextId, uint32_t vmHandleId, std::vector *bufferObjects, bool bind) { if (this->fragmentsStorage.fragmentCount) { for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) { if (!this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId]) { - bindBO(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo, drmContextId, bufferObjects, bind); + bindBO(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo, vmHandleId, bufferObjects, bind); this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId] = true; } } } else { - bindBOs(handleId, drmContextId, bufferObjects, bind); + bindBOs(vmHandleId, bufferObjects, bind); } } -void DrmAllocation::bindBO(BufferObject *bo, uint32_t drmContextId, std::vector *bufferObjects, bool bind) { +void DrmAllocation::bindBO(BufferObject *bo, uint32_t vmHandleId, std::vector *bufferObjects, bool bind) { if (bo) { if (bufferObjects) { if (bo->peekIsReusableAllocation()) { @@ -56,9 +56,9 @@ void DrmAllocation::bindBO(BufferObject *bo, uint32_t drmContextId, std::vector< } else { if (bind) { - bo->bind(drmContextId); + bo->bind(vmHandleId); } else { - bo->unbind(drmContextId); + bo->unbind(vmHandleId); } } } diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index 583eb6c315..2901b302dc 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -60,9 +60,9 @@ class DrmAllocation : public GraphicsAllocation { uint64_t peekInternalHandle(MemoryManager *memoryManager) override; - void makeBOsResident(uint32_t osContextId, uint32_t drmContextId, uint32_t handleId, std::vector *bufferObjects, bool bind); - void bindBO(BufferObject *bo, uint32_t drmContextId, std::vector *bufferObjects, bool bind); - void bindBOs(uint32_t handleId, uint32_t drmContextId, std::vector *bufferObjects, bool bind); + void makeBOsResident(uint32_t osContextId, uint32_t vmHandleId, std::vector *bufferObjects, bool bind); + void bindBO(BufferObject *bo, uint32_t vmHandleId, std::vector *bufferObjects, bool bind); + void bindBOs(uint32_t vmHandleId, std::vector *bufferObjects, bool bind); protected: BufferObjects bufferObjects{}; diff --git a/shared/source/os_interface/linux/drm_allocation_extended.cpp b/shared/source/os_interface/linux/drm_allocation_extended.cpp index 01d064fa9a..9e8840f82b 100644 --- a/shared/source/os_interface/linux/drm_allocation_extended.cpp +++ b/shared/source/os_interface/linux/drm_allocation_extended.cpp @@ -10,9 +10,9 @@ namespace NEO { -void DrmAllocation::bindBOs(uint32_t handleId, uint32_t drmContextId, std::vector *bufferObjects, bool bind) { +void DrmAllocation::bindBOs(uint32_t vmHandleId, std::vector *bufferObjects, bool bind) { auto bo = this->getBO(); - bindBO(bo, drmContextId, bufferObjects, bind); + bindBO(bo, vmHandleId, bufferObjects, bind); } } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_buffer_object.cpp b/shared/source/os_interface/linux/drm_buffer_object.cpp index 725dd17697..718a0e5512 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.cpp +++ b/shared/source/os_interface/linux/drm_buffer_object.cpp @@ -32,6 +32,7 @@ namespace NEO { BufferObject::BufferObject(Drm *drm, int handle, size_t size) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) { this->tiling_mode = I915_TILING_NONE; this->lockedAddress = nullptr; + bindInfo.fill(false); } uint32_t BufferObject::getRefCount() const { @@ -128,18 +129,24 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo return err; } -void BufferObject::bind(uint32_t drmContextId) { - auto ret = this->drm->bindBufferObject(drmContextId, this); - auto err = this->drm->getErrno(); - printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "bind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err)); - UNRECOVERABLE_IF(ret != 0); +void BufferObject::bind(uint32_t vmHandleId) { + if (!this->bindInfo[vmHandleId]) { + auto ret = this->drm->bindBufferObject(vmHandleId, this); + auto err = this->drm->getErrno(); + printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "bind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err)); + UNRECOVERABLE_IF(ret != 0); + this->bindInfo[vmHandleId] = true; + } } -void BufferObject::unbind(uint32_t drmContextId) { - auto ret = this->drm->unbindBufferObject(drmContextId, this); - auto err = this->drm->getErrno(); - printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "unbind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err)); - UNRECOVERABLE_IF(ret != 0); +void BufferObject::unbind(uint32_t vmHandleId) { + if (this->bindInfo[vmHandleId]) { + auto ret = this->drm->unbindBufferObject(vmHandleId, this); + auto err = this->drm->getErrno(); + printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "unbind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err)); + UNRECOVERABLE_IF(ret != 0); + this->bindInfo[vmHandleId] = false; + } } void BufferObject::printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage) { diff --git a/shared/source/os_interface/linux/drm_buffer_object.h b/shared/source/os_interface/linux/drm_buffer_object.h index aa99eddc1c..239b216279 100644 --- a/shared/source/os_interface/linux/drm_buffer_object.h +++ b/shared/source/os_interface/linux/drm_buffer_object.h @@ -6,8 +6,11 @@ */ #pragma once -#include "drm/i915_drm.h" +#include "drm/i915_drm.h" +#include "engine_limits.h" + +#include #include #include #include @@ -40,8 +43,8 @@ class BufferObject { int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, uint32_t drmContextId, BufferObject *const residency[], size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage); - void bind(uint32_t drmContextId); - void unbind(uint32_t drmContextId); + void bind(uint32_t vmHandleId); + void unbind(uint32_t vmHandleId); void printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage); @@ -82,5 +85,7 @@ class BufferObject { void *lockedAddress; // CPU side virtual address uint64_t unmapSize = 0; + + std::array bindInfo; }; } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp index 6058c831fb..2152220670 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp @@ -30,7 +30,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *devi auto drmAllocation = static_cast(*gfxAllocation); auto &drmContextIds = static_cast(engine.osContext)->getDrmContextIds(); for (uint32_t drmIterator = 0u; drmIterator < drmContextIds.size(); drmIterator++) { - drmAllocation->makeBOsResident(engine.osContext->getContextId(), drmContextIds[drmIterator], drmIterator, nullptr, true); + drmAllocation->makeBOsResident(engine.osContext->getContextId(), drmIterator, nullptr, true); } drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, engine.osContext->getContextId()); } @@ -57,7 +57,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evictWithinOsContext(OsCo auto drmAllocation = static_cast(&gfxAllocation); auto &drmContextIds = static_cast(osContext)->getDrmContextIds(); for (uint32_t drmIterator = 0u; drmIterator < drmContextIds.size(); drmIterator++) { - drmAllocation->makeBOsResident(osContext->getContextId(), drmContextIds[drmIterator], drmIterator, nullptr, false); + drmAllocation->makeBOsResident(osContext->getContextId(), drmIterator, nullptr, false); } drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectNotResident, osContext->getContextId()); } @@ -87,7 +87,7 @@ void DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osCo auto drmAllocation = static_cast(*gfxAllocation); auto &drmContextIds = static_cast(osContext)->getDrmContextIds(); for (uint32_t drmIterator = 0u; drmIterator < drmContextIds.size(); drmIterator++) { - drmAllocation->makeBOsResident(osContext->getContextId(), drmContextIds[drmIterator], drmIterator, nullptr, true); + drmAllocation->makeBOsResident(osContext->getContextId(), drmIterator, nullptr, true); } drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId()); gfxAllocation = residencyContainer.erase(gfxAllocation); diff --git a/shared/source/os_interface/linux/drm_neo.h b/shared/source/os_interface/linux/drm_neo.h index 4bce3aa464..9fe201eb63 100644 --- a/shared/source/os_interface/linux/drm_neo.h +++ b/shared/source/os_interface/linux/drm_neo.h @@ -87,8 +87,8 @@ class Drm { bool createVirtualMemoryAddressSpace(uint32_t vmCount); void destroyVirtualMemoryAddressSpace(); uint32_t getVirtualMemoryAddressSpace(uint32_t vmId); - int bindBufferObject(uint32_t drmContextId, BufferObject *bo); - int unbindBufferObject(uint32_t drmContextId, BufferObject *bo); + int bindBufferObject(uint32_t vmHandleId, BufferObject *bo); + int unbindBufferObject(uint32_t vmHandleId, BufferObject *bo); int setupHardwareInfo(DeviceDescriptor *, bool); bool areNonPersistentContextsSupported() const { return nonPersistentContextsSupported; } diff --git a/shared/source/os_interface/linux/drm_query.cpp b/shared/source/os_interface/linux/drm_query.cpp index d38ac2c7aa..4ea94e90b1 100644 --- a/shared/source/os_interface/linux/drm_query.cpp +++ b/shared/source/os_interface/linux/drm_query.cpp @@ -41,11 +41,11 @@ unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, au return DrmEngineMapper::engineNodeMap(engineType); } -int Drm::bindBufferObject(uint32_t drmContextId, BufferObject *bo) { +int Drm::bindBufferObject(uint32_t vmHandleId, BufferObject *bo) { return 0; } -int Drm::unbindBufferObject(uint32_t drmContextId, BufferObject *bo) { +int Drm::unbindBufferObject(uint32_t vmHandleId, BufferObject *bo) { return 0; } diff --git a/shared/source/os_interface/linux/drm_query_dg1.cpp b/shared/source/os_interface/linux/drm_query_dg1.cpp index bc75a2cc36..982856676f 100644 --- a/shared/source/os_interface/linux/drm_query_dg1.cpp +++ b/shared/source/os_interface/linux/drm_query_dg1.cpp @@ -49,11 +49,11 @@ unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, au return DrmEngineMapper::engineNodeMap(engineType); } -int Drm::bindBufferObject(uint32_t drmContextId, BufferObject *bo) { +int Drm::bindBufferObject(uint32_t vmHandleId, BufferObject *bo) { return 0; } -int Drm::unbindBufferObject(uint32_t drmContextId, BufferObject *bo) { +int Drm::unbindBufferObject(uint32_t vmHandleId, BufferObject *bo) { return 0; }