Skip to content

Commit 45a0cee

Browse files
Clean drm interfaces.
- all driver allocations are using SoftPin - remove unneeded methods. - remove unneeded members. - remove unneeded code paths. Change-Id: I3369c0a4d37727210b5a26271d25537ca5218bd4
1 parent c9a8f9b commit 45a0cee

File tree

6 files changed

+33
-58
lines changed

6 files changed

+33
-58
lines changed

runtime/os_interface/linux/drm_buffer_object.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,17 @@
3030
namespace OCLRT {
3131

3232
BufferObject::BufferObject(Drm *drm, int handle, bool isAllocated) : drm(drm), refCount(1), handle(handle), isReused(false), isAllocated(isAllocated) {
33-
this->isSoftpin = false;
34-
3533
this->tiling_mode = I915_TILING_NONE;
3634
this->stride = 0;
37-
3835
execObjectsStorage = nullptr;
39-
4036
this->size = 0;
41-
this->address = nullptr;
4237
this->lockedAddress = nullptr;
43-
this->offset64 = 0;
4438
}
4539

4640
uint32_t BufferObject::getRefCount() const {
4741
return this->refCount.load();
4842
}
4943

50-
bool BufferObject::softPin(uint64_t offset) {
51-
this->isSoftpin = true;
52-
this->offset64 = offset;
53-
54-
return true;
55-
};
56-
5744
bool BufferObject::close() {
5845
drm_gem_close close = {};
5946
close.handle = this->handle;
@@ -111,11 +98,11 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_
11198
execObject.relocation_count = 0; //No relocations, we are SoftPinning
11299
execObject.relocs_ptr = 0ul;
113100
execObject.alignment = 0;
114-
execObject.offset = this->isSoftpin ? this->offset64 : 0;
115-
execObject.flags = this->isSoftpin ? EXEC_OBJECT_PINNED : 0;
101+
execObject.offset = this->gpuAddress;
102+
execObject.flags = EXEC_OBJECT_PINNED;
116103
#ifdef __x86_64__
117104
// set EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag if whole object resides in 32BIT address space boundary
118-
execObject.flags |= (reinterpret_cast<uint64_t>(this->address) + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0;
105+
execObject.flags |= (this->gpuAddress + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0;
119106
#endif
120107
execObject.rsvd1 = drmContextId;
121108
execObject.rsvd2 = 0;
@@ -157,8 +144,8 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmC
157144
drm_i915_gem_execbuffer2 execbuf = {};
158145
StackVec<drm_i915_gem_exec_object2, maxFragmentsCount + 1> execObject;
159146

160-
reinterpret_cast<uint32_t *>(this->address)[0] = 0x05000000;
161-
reinterpret_cast<uint32_t *>(this->address)[1] = 0x00000000;
147+
reinterpret_cast<uint32_t *>(this->gpuAddress)[0] = 0x05000000;
148+
reinterpret_cast<uint32_t *>(this->gpuAddress)[1] = 0x00000000;
162149

163150
execObject.resize(numberOfBos + 1);
164151

runtime/os_interface/linux/drm_buffer_object.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2018 Intel Corporation
2+
* Copyright (C) 2017-2019 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -40,8 +40,6 @@ class BufferObject {
4040
public:
4141
MOCKABLE_VIRTUAL ~BufferObject(){};
4242

43-
bool softPin(uint64_t offset);
44-
4543
bool setTiling(uint32_t mode, uint32_t stride);
4644

4745
MOCKABLE_VIRTUAL int pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmContextId);
@@ -59,8 +57,8 @@ class BufferObject {
5957
bool peekIsAllocated() const { return isAllocated; }
6058
size_t peekSize() const { return size; }
6159
int peekHandle() const { return handle; }
62-
void *peekAddress() const { return address; }
63-
void setAddress(void *address) { this->address = address; }
60+
uint64_t peekAddress() const { return gpuAddress; }
61+
void setAddress(uint64_t address) { this->gpuAddress = address; }
6462
void *peekLockedAddress() const { return lockedAddress; }
6563
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
6664
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
@@ -87,7 +85,6 @@ class BufferObject {
8785
drm_i915_gem_exec_object2 *execObjectsStorage;
8886

8987
int handle; // i915 gem object handle
90-
bool isSoftpin;
9188
bool isReused;
9289

9390
//Tiling
@@ -97,9 +94,9 @@ class BufferObject {
9794
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_t drmContextId);
9895
void processRelocs(int &idx, uint32_t drmContextId);
9996

100-
uint64_t offset64; // last-seen GPU offset
101-
size_t size;
102-
void *address; // GPU side virtual address
97+
uint64_t gpuAddress = 0llu;
98+
99+
uint64_t size;
103100
void *lockedAddress; // CPU side virtual address
104101

105102
bool isAllocated = false;

runtime/os_interface/linux/drm_memory_manager.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ uint32_t DrmMemoryManager::unreference(OCLRT::BufferObject *bo, bool synchronous
128128

129129
if (r == 1) {
130130
auto unmapSize = bo->peekUnmapSize();
131-
auto address = bo->isAllocated || unmapSize > 0 ? bo->address : nullptr;
131+
auto address = bo->isAllocated || unmapSize > 0 ? reinterpret_cast<void *>(bo->gpuAddress) : nullptr;
132132
auto allocatorType = bo->peekAllocationType();
133133

134134
if (bo->isReused) {
@@ -206,8 +206,7 @@ OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t si
206206
return nullptr;
207207
}
208208
res->size = size;
209-
res->address = reinterpret_cast<void *>(address);
210-
res->softPin(address);
209+
res->gpuAddress = address;
211210

212211
return res;
213212
}
@@ -279,8 +278,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(size_t s
279278

280279
bo->isAllocated = false;
281280
bo->setUnmapSize(alignedSize);
282-
bo->address = reinterpret_cast<void *>(gpuVirtualAddress);
283-
bo->softPin((uint64_t)bo->address);
281+
bo->gpuAddress = gpuVirtualAddress;
284282
bo->setAllocationType(allocType);
285283

286284
auto allocation = new DrmAllocation(bo, alignedPtr, gpuVirtualAddress, size, MemoryPool::System4KBPages, false);
@@ -319,8 +317,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
319317
return nullptr;
320318
}
321319
bo->size = allocationData.imgInfo->size;
322-
bo->address = reinterpret_cast<void *>(gpuRange);
323-
bo->softPin(gpuRange);
320+
bo->gpuAddress = gpuRange;
324321

325322
auto ret2 = bo->setTiling(I915_TILING_Y, static_cast<uint32_t>(allocationData.imgInfo->rowPitch));
326323
DEBUG_BREAK_IF(ret2 != true);
@@ -358,9 +355,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
358355

359356
bo->isAllocated = false;
360357
bo->setUnmapSize(realAllocationSize);
361-
bo->address = reinterpret_cast<void *>(gpuVirtualAddress);
362-
uintptr_t offset = (uintptr_t)bo->address;
363-
bo->softPin((uint64_t)offset);
358+
bo->gpuAddress = gpuVirtualAddress;
364359
bo->setAllocationType(allocatorType);
365360
auto drmAllocation = new DrmAllocation(bo, const_cast<void *>(allocationData.hostPtr), static_cast<uint64_t>(ptrOffset(gpuVirtualAddress, inputPointerOffset)),
366361
allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
@@ -409,8 +404,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio
409404
DrmAllocation *drmAllocation = nullptr;
410405
if (limitedRangeAllocation) {
411406
// softpin to the GPU address, res if it uses limitedRangeAllocation
412-
bo->address = reinterpret_cast<void *>(res);
413-
bo->softPin(res);
407+
bo->gpuAddress = res;
414408
drmAllocation = new DrmAllocation(bo, ptrAlloc, res, alignedAllocationSize,
415409
MemoryPool::System4KBPagesWith32BitGpuAddressing, false);
416410
} else {
@@ -451,8 +445,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si
451445
}
452446

453447
bo->size = size;
454-
bo->address = reinterpret_cast<void *>(gpuRange);
455-
bo->softPin(gpuRange);
448+
bo->gpuAddress = gpuRange;
456449
bo->setUnmapSize(size);
457450
bo->setAllocationType(storageType);
458451
return bo;
@@ -490,7 +483,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
490483

491484
lock.unlock();
492485

493-
auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle, MemoryPool::SystemCpuInaccessible, false);
486+
auto drmAllocation = new DrmAllocation(bo, reinterpret_cast<void *>(bo->gpuAddress), bo->size, handle, MemoryPool::SystemCpuInaccessible, false);
494487

495488
if (requireSpecificBitness && this->force32bitAllocations) {
496489
drmAllocation->is32BitAllocation = true;
@@ -517,8 +510,7 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
517510
if (!bo) {
518511
return nullptr;
519512
}
520-
bo->setAddress(reinterpret_cast<void *>(gpuRange));
521-
bo->softPin(gpuRange);
513+
bo->gpuAddress = gpuRange;
522514
bo->setUnmapSize(sizeWithPadding);
523515
bo->setAllocationType(storageType);
524516
return new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding,

unit_tests/os_interface/linux/drm_buffer_object_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedCrosses32BitBoundaryW
102102
drm_i915_gem_exec_object2 execObject;
103103

104104
memset(&execObject, 0, sizeof(execObject));
105-
bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u));
105+
bo->setAddress(((uint64_t)1u << 32) - 0x1000u);
106106
bo->setSize(0x1000);
107107
bo->fillExecObject(execObject, 1);
108108
//base address + size > size of 32bit address space
@@ -113,7 +113,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWh
113113
drm_i915_gem_exec_object2 execObject;
114114

115115
memset(&execObject, 0, sizeof(execObject));
116-
bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u));
116+
bo->setAddress(((uint64_t)1u << 32) - 0x1000u);
117117
bo->setSize(0xFFF);
118118
bo->fillExecObject(execObject, 1);
119119
//base address + size < size of 32bit address space
@@ -130,7 +130,7 @@ TEST_F(DrmBufferObjectTest, onPinIoctlFailed) {
130130
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(this->mock));
131131
ASSERT_NE(nullptr, boToPin.get());
132132

133-
bo->setAddress(buff.get());
133+
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
134134
BufferObject *boArray[1] = {boToPin.get()};
135135
auto ret = bo->pin(boArray, 1, 1);
136136
EXPECT_EQ(EINVAL, ret);
@@ -151,7 +151,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
151151
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(mock.get()));
152152
ASSERT_NE(nullptr, boToPin.get());
153153

154-
bo->setAddress(buff.get());
154+
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
155155
mock->errnoValue = EFAULT;
156156

157157
BufferObject *boArray[1] = {boToPin.get()};
@@ -179,7 +179,7 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
179179

180180
BufferObject *array[3] = {boToPin.get(), boToPin2.get(), boToPin3.get()};
181181

182-
bo->setAddress(buff.get());
182+
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
183183
auto ret = bo->pin(array, 3, 1);
184184
EXPECT_EQ(mock->ioctl_res, ret);
185185
uint32_t bb_end = 0x05000000;
@@ -191,5 +191,5 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
191191
EXPECT_NE(nullptr, boToPin2->execObjectPointerFilled);
192192
EXPECT_NE(nullptr, boToPin3->execObjectPointerFilled);
193193

194-
bo->setAddress(nullptr);
194+
bo->setAddress(0llu);
195195
}

unit_tests/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ class DrmCommandStreamEnhancedFixture
604604

605605
protected:
606606
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, false) {
607-
this->isSoftpin = true;
608607
this->size = alignUp(size, 4096);
609608
}
610609
};

unit_tests/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr) {
468468
auto bo = alloc->getBO();
469469
ASSERT_NE(nullptr, bo);
470470
EXPECT_FALSE(bo->peekIsAllocated());
471-
EXPECT_EQ(ptr, bo->peekAddress());
471+
EXPECT_EQ(ptr, reinterpret_cast<void *>(bo->peekAddress()));
472472
EXPECT_EQ(Sharing::nonSharedResource, alloc->peekSharedHandle());
473473
memoryManager->freeGraphicsMemory(alloc);
474474
::alignedFree(ptr);
@@ -490,7 +490,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_Nullptr) {
490490
auto bo = alloc->getBO();
491491
ASSERT_NE(nullptr, bo);
492492
EXPECT_FALSE(bo->peekIsAllocated());
493-
EXPECT_EQ(ptr, bo->peekAddress());
493+
EXPECT_EQ(ptr, reinterpret_cast<void *>(bo->peekAddress()));
494494

495495
memoryManager->freeGraphicsMemory(alloc);
496496
::alignedFree(ptr);
@@ -514,7 +514,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_MisAligned) {
514514
auto bo = alloc->getBO();
515515
ASSERT_NE(nullptr, bo);
516516
EXPECT_FALSE(bo->peekIsAllocated());
517-
EXPECT_EQ(ptrT, bo->peekAddress());
517+
EXPECT_EQ(ptrT, reinterpret_cast<void *>(bo->peekAddress()));
518518

519519
memoryManager->freeGraphicsMemory(alloc);
520520
::alignedFree(ptrT);
@@ -747,7 +747,7 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked
747747
for (int i = 0; i < maxFragmentsCount; i++) {
748748
ASSERT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo);
749749
EXPECT_EQ(reqs.AllocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekSize());
750-
EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress());
750+
EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, reinterpret_cast<void *>(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress()));
751751
EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekIsAllocated());
752752
}
753753
memoryManager->freeGraphicsMemory(graphicsAllocation);
@@ -1561,7 +1561,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT
15611561
auto bo = drmAllocation->getBO();
15621562
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);
15631563
EXPECT_EQ(bo->peekUnmapSize(), size);
1564-
EXPECT_NE(nullptr, bo->peekAddress());
1564+
EXPECT_NE(0llu, bo->peekAddress());
15651565
EXPECT_TRUE(bo->peekIsAllocated());
15661566
EXPECT_EQ(1u, bo->getRefCount());
15671567
EXPECT_EQ(size, bo->peekSize());
@@ -1625,7 +1625,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea
16251625
bo = drmAllocation->getBO();
16261626
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);
16271627
EXPECT_EQ(bo->peekUnmapSize(), size);
1628-
EXPECT_NE(nullptr, bo->peekAddress());
1628+
EXPECT_NE(0llu, bo->peekAddress());
16291629
EXPECT_TRUE(bo->peekIsAllocated());
16301630
EXPECT_EQ(expectedRefCount, bo->getRefCount());
16311631
EXPECT_EQ(size, bo->peekSize());
@@ -2041,7 +2041,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre
20412041
auto bo = drmAllocation->getBO();
20422042
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);
20432043
EXPECT_EQ(bo->peekUnmapSize(), realSize);
2044-
EXPECT_NE(nullptr, bo->peekAddress());
2044+
EXPECT_NE(0llu, bo->peekAddress());
20452045
EXPECT_TRUE(bo->peekIsAllocated());
20462046
EXPECT_EQ(1u, bo->getRefCount());
20472047
EXPECT_EQ(realSize, bo->peekSize());

0 commit comments

Comments
 (0)