Skip to content

Commit 49cd8e4

Browse files
committed
Bind bos to proper VM
Change-Id: I536ff342875bba39cf9a9922fcf647af408ae398 Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 038577e commit 49cd8e4

File tree

11 files changed

+46
-34
lines changed

11 files changed

+46
-34
lines changed

opencl/source/os_interface/linux/drm_command_stream.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ template <typename GfxFamily>
116116
void DrmCommandStreamReceiver<GfxFamily>::processResidency(const ResidencyContainer &inputAllocationsForResidency, uint32_t handleId) {
117117
for (auto &alloc : inputAllocationsForResidency) {
118118
auto drmAlloc = static_cast<DrmAllocation *>(alloc);
119-
drmAlloc->makeBOsResident(osContext->getContextId(), 0u, handleId, &this->residency, false);
119+
drmAlloc->makeBOsResident(osContext->getContextId(), handleId, &this->residency, false);
120120
}
121121
}
122122

opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class DrmCommandStreamEnhancedTemplate : public ::testing::Test {
128128

129129
template <typename GfxFamily>
130130
void makeResidentBufferObjects(DrmAllocation *drmAllocation) {
131-
drmAllocation->bindBOs(0u, 0u, &static_cast<TestedDrmCommandStreamReceiver<GfxFamily> *>(csr)->residency, false);
131+
drmAllocation->bindBOs(0u, &static_cast<TestedDrmCommandStreamReceiver<GfxFamily> *>(csr)->residency, false);
132132
}
133133

134134
template <typename GfxFamily>

shared/source/os_interface/linux/drm_allocation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
2828
return static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex));
2929
}
3030

31-
void DrmAllocation::makeBOsResident(uint32_t osContextId, uint32_t drmContextId, uint32_t handleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
31+
void DrmAllocation::makeBOsResident(uint32_t osContextId, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
3232
if (this->fragmentsStorage.fragmentCount) {
3333
for (unsigned int f = 0; f < this->fragmentsStorage.fragmentCount; f++) {
3434
if (!this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId]) {
35-
bindBO(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo, drmContextId, bufferObjects, bind);
35+
bindBO(this->fragmentsStorage.fragmentStorageData[f].osHandleStorage->bo, vmHandleId, bufferObjects, bind);
3636
this->fragmentsStorage.fragmentStorageData[f].residency->resident[osContextId] = true;
3737
}
3838
}
3939
} else {
40-
bindBOs(handleId, drmContextId, bufferObjects, bind);
40+
bindBOs(vmHandleId, bufferObjects, bind);
4141
}
4242
}
4343

44-
void DrmAllocation::bindBO(BufferObject *bo, uint32_t drmContextId, std::vector<BufferObject *> *bufferObjects, bool bind) {
44+
void DrmAllocation::bindBO(BufferObject *bo, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
4545
if (bo) {
4646
if (bufferObjects) {
4747
if (bo->peekIsReusableAllocation()) {
@@ -56,9 +56,9 @@ void DrmAllocation::bindBO(BufferObject *bo, uint32_t drmContextId, std::vector<
5656

5757
} else {
5858
if (bind) {
59-
bo->bind(drmContextId);
59+
bo->bind(vmHandleId);
6060
} else {
61-
bo->unbind(drmContextId);
61+
bo->unbind(vmHandleId);
6262
}
6363
}
6464
}

shared/source/os_interface/linux/drm_allocation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class DrmAllocation : public GraphicsAllocation {
6060

6161
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
6262

63-
void makeBOsResident(uint32_t osContextId, uint32_t drmContextId, uint32_t handleId, std::vector<BufferObject *> *bufferObjects, bool bind);
64-
void bindBO(BufferObject *bo, uint32_t drmContextId, std::vector<BufferObject *> *bufferObjects, bool bind);
65-
void bindBOs(uint32_t handleId, uint32_t drmContextId, std::vector<BufferObject *> *bufferObjects, bool bind);
63+
void makeBOsResident(uint32_t osContextId, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
64+
void bindBO(BufferObject *bo, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
65+
void bindBOs(uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
6666

6767
protected:
6868
BufferObjects bufferObjects{};

shared/source/os_interface/linux/drm_allocation_extended.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace NEO {
1212

13-
void DrmAllocation::bindBOs(uint32_t handleId, uint32_t drmContextId, std::vector<BufferObject *> *bufferObjects, bool bind) {
13+
void DrmAllocation::bindBOs(uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind) {
1414
auto bo = this->getBO();
15-
bindBO(bo, drmContextId, bufferObjects, bind);
15+
bindBO(bo, vmHandleId, bufferObjects, bind);
1616
}
1717

1818
} // namespace NEO

shared/source/os_interface/linux/drm_buffer_object.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace NEO {
3232
BufferObject::BufferObject(Drm *drm, int handle, size_t size) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) {
3333
this->tiling_mode = I915_TILING_NONE;
3434
this->lockedAddress = nullptr;
35+
bindInfo.fill(false);
3536
}
3637

3738
uint32_t BufferObject::getRefCount() const {
@@ -128,18 +129,24 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
128129
return err;
129130
}
130131

131-
void BufferObject::bind(uint32_t drmContextId) {
132-
auto ret = this->drm->bindBufferObject(drmContextId, this);
133-
auto err = this->drm->getErrno();
134-
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "bind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err));
135-
UNRECOVERABLE_IF(ret != 0);
132+
void BufferObject::bind(uint32_t vmHandleId) {
133+
if (!this->bindInfo[vmHandleId]) {
134+
auto ret = this->drm->bindBufferObject(vmHandleId, this);
135+
auto err = this->drm->getErrno();
136+
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "bind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err));
137+
UNRECOVERABLE_IF(ret != 0);
138+
this->bindInfo[vmHandleId] = true;
139+
}
136140
}
137141

138-
void BufferObject::unbind(uint32_t drmContextId) {
139-
auto ret = this->drm->unbindBufferObject(drmContextId, this);
140-
auto err = this->drm->getErrno();
141-
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "unbind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err));
142-
UNRECOVERABLE_IF(ret != 0);
142+
void BufferObject::unbind(uint32_t vmHandleId) {
143+
if (this->bindInfo[vmHandleId]) {
144+
auto ret = this->drm->unbindBufferObject(vmHandleId, this);
145+
auto err = this->drm->getErrno();
146+
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "unbind buffer object returned with %d. errno=%d(%s)\n", ret, err, strerror(err));
147+
UNRECOVERABLE_IF(ret != 0);
148+
this->bindInfo[vmHandleId] = false;
149+
}
143150
}
144151

145152
void BufferObject::printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage) {

shared/source/os_interface/linux/drm_buffer_object.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
*/
77

88
#pragma once
9+
910
#include "drm/i915_drm.h"
11+
#include "engine_limits.h"
1012

13+
#include <array>
1114
#include <atomic>
1215
#include <cstddef>
1316
#include <stdint.h>
@@ -40,8 +43,8 @@ class BufferObject {
4043

4144
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);
4245

43-
void bind(uint32_t drmContextId);
44-
void unbind(uint32_t drmContextId);
46+
void bind(uint32_t vmHandleId);
47+
void unbind(uint32_t vmHandleId);
4548

4649
void printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage);
4750

@@ -82,5 +85,7 @@ class BufferObject {
8285
void *lockedAddress; // CPU side virtual address
8386

8487
uint64_t unmapSize = 0;
88+
89+
std::array<bool, EngineLimits::maxHandleCount> bindInfo;
8590
};
8691
} // namespace NEO

shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::makeResident(Device *devi
3030
auto drmAllocation = static_cast<DrmAllocation *>(*gfxAllocation);
3131
auto &drmContextIds = static_cast<const OsContextLinux *>(engine.osContext)->getDrmContextIds();
3232
for (uint32_t drmIterator = 0u; drmIterator < drmContextIds.size(); drmIterator++) {
33-
drmAllocation->makeBOsResident(engine.osContext->getContextId(), drmContextIds[drmIterator], drmIterator, nullptr, true);
33+
drmAllocation->makeBOsResident(engine.osContext->getContextId(), drmIterator, nullptr, true);
3434
}
3535
drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, engine.osContext->getContextId());
3636
}
@@ -57,7 +57,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evictWithinOsContext(OsCo
5757
auto drmAllocation = static_cast<DrmAllocation *>(&gfxAllocation);
5858
auto &drmContextIds = static_cast<const OsContextLinux *>(osContext)->getDrmContextIds();
5959
for (uint32_t drmIterator = 0u; drmIterator < drmContextIds.size(); drmIterator++) {
60-
drmAllocation->makeBOsResident(osContext->getContextId(), drmContextIds[drmIterator], drmIterator, nullptr, false);
60+
drmAllocation->makeBOsResident(osContext->getContextId(), drmIterator, nullptr, false);
6161
}
6262
drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectNotResident, osContext->getContextId());
6363
}
@@ -87,7 +87,7 @@ void DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osCo
8787
auto drmAllocation = static_cast<DrmAllocation *>(*gfxAllocation);
8888
auto &drmContextIds = static_cast<const OsContextLinux *>(osContext)->getDrmContextIds();
8989
for (uint32_t drmIterator = 0u; drmIterator < drmContextIds.size(); drmIterator++) {
90-
drmAllocation->makeBOsResident(osContext->getContextId(), drmContextIds[drmIterator], drmIterator, nullptr, true);
90+
drmAllocation->makeBOsResident(osContext->getContextId(), drmIterator, nullptr, true);
9191
}
9292
drmAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, osContext->getContextId());
9393
gfxAllocation = residencyContainer.erase(gfxAllocation);

shared/source/os_interface/linux/drm_neo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class Drm {
8787
bool createVirtualMemoryAddressSpace(uint32_t vmCount);
8888
void destroyVirtualMemoryAddressSpace();
8989
uint32_t getVirtualMemoryAddressSpace(uint32_t vmId);
90-
int bindBufferObject(uint32_t drmContextId, BufferObject *bo);
91-
int unbindBufferObject(uint32_t drmContextId, BufferObject *bo);
90+
int bindBufferObject(uint32_t vmHandleId, BufferObject *bo);
91+
int unbindBufferObject(uint32_t vmHandleId, BufferObject *bo);
9292
int setupHardwareInfo(DeviceDescriptor *, bool);
9393

9494
bool areNonPersistentContextsSupported() const { return nonPersistentContextsSupported; }

shared/source/os_interface/linux/drm_query.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, au
4141
return DrmEngineMapper::engineNodeMap(engineType);
4242
}
4343

44-
int Drm::bindBufferObject(uint32_t drmContextId, BufferObject *bo) {
44+
int Drm::bindBufferObject(uint32_t vmHandleId, BufferObject *bo) {
4545
return 0;
4646
}
4747

48-
int Drm::unbindBufferObject(uint32_t drmContextId, BufferObject *bo) {
48+
int Drm::unbindBufferObject(uint32_t vmHandleId, BufferObject *bo) {
4949
return 0;
5050
}
5151

0 commit comments

Comments
 (0)