diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index b9abd9a34c..99d4cb824e 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -154,8 +154,8 @@ class MemoryManager { virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy); static HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM); static std::unique_ptr createMemoryManager(ExecutionEnvironment &executionEnvironment); - virtual void *reserveCpuAddressRange(size_t size) = 0; - virtual void releaseReservedCpuAddressRange(void *reserved, size_t size) = 0; + virtual void *reserveCpuAddressRange(size_t size) { return nullptr; }; + virtual void releaseReservedCpuAddressRange(void *reserved, size_t size){}; protected: struct AllocationData { diff --git a/runtime/os_interface/linux/drm_buffer_object.cpp b/runtime/os_interface/linux/drm_buffer_object.cpp index f3364e6c2b..c02c093be3 100644 --- a/runtime/os_interface/linux/drm_buffer_object.cpp +++ b/runtime/os_interface/linux/drm_buffer_object.cpp @@ -29,7 +29,7 @@ namespace NEO { -BufferObject::BufferObject(Drm *drm, int handle, bool isAllocated) : drm(drm), refCount(1), handle(handle), isReused(false), isAllocated(isAllocated) { +BufferObject::BufferObject(Drm *drm, int handle) : drm(drm), refCount(1), handle(handle), isReused(false) { this->tiling_mode = I915_TILING_NONE; this->stride = 0; this->size = 0; diff --git a/runtime/os_interface/linux/drm_buffer_object.h b/runtime/os_interface/linux/drm_buffer_object.h index aac6bce51d..01b16d5861 100644 --- a/runtime/os_interface/linux/drm_buffer_object.h +++ b/runtime/os_interface/linux/drm_buffer_object.h @@ -18,20 +18,11 @@ namespace NEO { class DrmMemoryManager; class Drm; -enum StorageAllocatorType { - MMAP_ALLOCATOR, - BIT32_ALLOCATOR_EXTERNAL, - BIT32_ALLOCATOR_INTERNAL, - MALLOC_ALLOCATOR, - EXTERNAL_ALLOCATOR, - INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, - UNKNOWN_ALLOCATOR -}; - class BufferObject { friend DrmMemoryManager; public: + BufferObject(Drm *drm, int handle); MOCKABLE_VIRTUAL ~BufferObject(){}; bool setTiling(uint32_t mode, uint32_t stride); @@ -48,7 +39,6 @@ class BufferObject { } uint32_t getRefCount() const; - bool peekIsAllocated() const { return isAllocated; } size_t peekSize() const { return size; } int peekHandle() const { return handle; } uint64_t peekAddress() const { return gpuAddress; } @@ -57,13 +47,9 @@ class BufferObject { void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; } void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; } uint64_t peekUnmapSize() const { return unmapSize; } - StorageAllocatorType peekAllocationType() const { return storageAllocatorType; } - void setAllocationType(StorageAllocatorType allocatorType) { this->storageAllocatorType = allocatorType; } bool peekIsReusableAllocation() const { return this->isReused; } protected: - BufferObject(Drm *drm, int handle, bool isAllocated); - Drm *drm; std::atomic refCount; @@ -82,8 +68,6 @@ class BufferObject { uint64_t size; void *lockedAddress; // CPU side virtual address - bool isAllocated = false; uint64_t unmapSize = 0; - StorageAllocatorType storageAllocatorType = UNKNOWN_ALLOCATOR; }; } // namespace NEO diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 882d3ea4be..d966889d1a 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -45,19 +45,18 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, gemCloseWorker.reset(new DrmGemCloseWorker(*this)); } - auto mem = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize); - DEBUG_BREAK_IF(mem == nullptr); + memoryForPinBB = alignedMallocWrapper(MemoryConstants::pageSize, MemoryConstants::pageSize); + DEBUG_BREAK_IF(memoryForPinBB == nullptr); if (forcePinEnabled || validateHostPtrMemory) { - pinBB = allocUserptr(reinterpret_cast(mem), MemoryConstants::pageSize, 0); + pinBB = allocUserptr(reinterpret_cast(memoryForPinBB), MemoryConstants::pageSize, 0); } if (!pinBB) { - alignedFree(mem); + alignedFreeWrapper(memoryForPinBB); + memoryForPinBB = nullptr; DEBUG_BREAK_IF(true); UNRECOVERABLE_IF(validateHostPtrMemory); - } else { - pinBB->isAllocated = true; } } @@ -70,12 +69,15 @@ DrmMemoryManager::~DrmMemoryManager() { unreference(pinBB); pinBB = nullptr; } + if (memoryForPinBB) { + alignedFreeWrapper(memoryForPinBB); + } } void DrmMemoryManager::eraseSharedBufferObject(NEO::BufferObject *bo) { auto it = std::find(sharingBufferObjects.begin(), sharingBufferObjects.end(), bo); - //If an object isReused = true, it must be in the vector DEBUG_BREAK_IF(it == sharingBufferObjects.end()); + releaseGpuRange(reinterpret_cast((*it)->gpuAddress), (*it)->peekUnmapSize()); sharingBufferObjects.erase(it); } @@ -101,10 +103,6 @@ uint32_t DrmMemoryManager::unreference(NEO::BufferObject *bo, bool synchronousDe uint32_t r = bo->refCount.fetch_sub(1); if (r == 1) { - auto unmapSize = bo->peekUnmapSize(); - auto address = bo->isAllocated || unmapSize > 0 ? reinterpret_cast(bo->gpuAddress) : nullptr; - auto allocatorType = bo->peekAllocationType(); - if (bo->isReused) { eraseSharedBufferObject(bo); } @@ -116,38 +114,19 @@ uint32_t DrmMemoryManager::unreference(NEO::BufferObject *bo, bool synchronousDe } delete bo; - if (address) { - if (unmapSize) { - releaseGpuRange(address, unmapSize, allocatorType); - } else { - alignedFreeWrapper(address); - } - } } return r; } -uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, StorageAllocatorType &storageType, bool specificBitness) { +uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, bool specificBitness) { if (specificBitness && this->force32bitAllocations) { - storageType = BIT32_ALLOCATOR_EXTERNAL; return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_EXTERNAL, size)); - } - - if (isLimitedRange()) { - storageType = INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE; + } else { return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD, size)); } - - storageType = MMAP_ALLOCATOR; - return reinterpret_cast(reserveCpuAddressRange(size)); } -void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize, StorageAllocatorType allocatorType) { - if (allocatorType == MMAP_ALLOCATOR) { - releaseReservedCpuAddressRange(address, unmapSize); - return; - } - +void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize) { uint64_t graphicsAddress = static_cast(reinterpret_cast(address)); graphicsAddress = GmmHelper::decanonize(graphicsAddress); gfxPartition->freeGpuAddressRange(graphicsAddress, unmapSize); @@ -163,7 +142,7 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size return nullptr; } - auto res = new (std::nothrow) BufferObject(this->drm, userptr.handle, false); + auto res = new (std::nothrow) BufferObject(this->drm, userptr.handle); if (!res) { DEBUG_BREAK_IF(true); return nullptr; @@ -206,48 +185,37 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc return nullptr; } - bo->isAllocated = true; - // if limitedRangeAlloction is enabled, memory allocation for bo in the limited Range heap is required - if (isLimitedRange()) { - StorageAllocatorType allocType; - bo->gpuAddress = acquireGpuRange(cSize, allocType, false); - if (!bo->gpuAddress) { - bo->close(); - delete bo; - alignedFreeWrapper(res); - return nullptr; - } - - bo->setUnmapSize(cSize); - bo->setAllocationType(allocType); + uint64_t gpuAddress = 0; + size_t alignedSize = cSize; + auto svmCpuAllocation = allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU; + if (svmCpuAllocation) { + //add 2MB padding in case reserved addr is not 2MB aligned + alignedSize = alignUp(cSize, cAlignment) + cAlignment; } - uint64_t reservedGpuAddress = 0; - size_t reserveSizeAligned = 0; - if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) { - //add 2MB padding in case reserved addr is not 2MB aligned - reserveSizeAligned = alignUp(cSize, cAlignment) + cAlignment; - reservedGpuAddress = GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD, reserveSizeAligned)); - if (!reservedGpuAddress) { + if (isLimitedRange() || svmCpuAllocation) { + gpuAddress = acquireGpuRange(alignedSize, false); + if (!gpuAddress) { bo->close(); delete bo; alignedFreeWrapper(res); return nullptr; } - bo->gpuAddress = alignUp(reservedGpuAddress, cAlignment); - bo->isAllocated = false; + + if (svmCpuAllocation) { + bo->gpuAddress = alignUp(gpuAddress, cAlignment); + } else { + bo->gpuAddress = gpuAddress; + } } emitPinningRequest(bo, allocationData); auto allocation = new DrmAllocation(allocationData.type, bo, res, bo->gpuAddress, cSize, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable); - allocation->setDriverAllocatedCpuPtr(isLimitedRange() ? res : nullptr); + allocation->setDriverAllocatedCpuPtr(res); - if (GraphicsAllocation::AllocationType::SVM_CPU == allocationData.type) { - allocation->setDriverAllocatedCpuPtr(res); - allocation->setReservedAddressRange(reinterpret_cast(reservedGpuAddress), reserveSizeAligned); - } + allocation->setReservedAddressRange(reinterpret_cast(gpuAddress), alignedSize); return allocation; } @@ -270,27 +238,25 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al auto realAllocationSize = alignedSize; auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr); - StorageAllocatorType allocType; - auto gpuVirtualAddress = acquireGpuRange(alignedSize, allocType, false); + auto gpuVirtualAddress = acquireGpuRange(alignedSize, false); if (!gpuVirtualAddress) { return nullptr; } BufferObject *bo = allocUserptr(reinterpret_cast(alignedPtr), realAllocationSize, 0); if (!bo) { - releaseGpuRange(reinterpret_cast(gpuVirtualAddress), alignedSize, allocType); + releaseGpuRange(reinterpret_cast(gpuVirtualAddress), alignedSize); return nullptr; } - bo->isAllocated = false; - bo->setUnmapSize(alignedSize); bo->gpuAddress = gpuVirtualAddress; - bo->setAllocationType(allocType); auto allocation = new DrmAllocation(allocationData.type, bo, const_cast(alignedPtr), gpuVirtualAddress, allocationData.size, MemoryPool::System4KBPages, false); allocation->setAllocationOffset(offsetInPage); + allocation->setReservedAddressRange(reinterpret_cast(gpuVirtualAddress), alignedSize); + return allocation; } @@ -307,9 +273,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A return alloc; } - StorageAllocatorType allocatorType = UNKNOWN_ALLOCATOR; - uint64_t gpuRange = acquireGpuRange(allocationData.imgInfo->size, allocatorType, false); - DEBUG_BREAK_IF(gpuRange == reinterpret_cast(MAP_FAILED)); + uint64_t gpuRange = acquireGpuRange(allocationData.imgInfo->size, false); drm_i915_gem_create create = {0, 0, 0}; create.size = allocationData.imgInfo->size; @@ -318,7 +282,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A DEBUG_BREAK_IF(ret != 0); ((void)(ret)); - auto bo = new (std::nothrow) BufferObject(this->drm, create.handle, true); + auto bo = new (std::nothrow) BufferObject(this->drm, create.handle); if (!bo) { return nullptr; } @@ -329,18 +293,17 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A DEBUG_BREAK_IF(ret2 != true); ((void)(ret2)); - bo->setUnmapSize(allocationData.imgInfo->size); - auto allocation = new DrmAllocation(allocationData.type, bo, nullptr, gpuRange, allocationData.imgInfo->size, MemoryPool::SystemCpuInaccessible, false); - bo->setAllocationType(allocatorType); allocation->setDefaultGmm(gmm.release()); + + allocation->setReservedAddressRange(reinterpret_cast(gpuRange), allocationData.imgInfo->size); + return allocation; } DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) { auto internal = useInternal32BitAllocator(allocationData.type); auto allocatorToUse = internal ? internalHeapIndex : HeapIndex::HEAP_EXTERNAL; - auto allocatorType = internal ? BIT32_ALLOCATOR_INTERNAL : BIT32_ALLOCATOR_EXTERNAL; if (allocationData.hostPtr) { uintptr_t inputPtr = reinterpret_cast(allocationData.hostPtr); @@ -359,14 +322,12 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio return nullptr; } - bo->isAllocated = false; - bo->setUnmapSize(realAllocationSize); bo->gpuAddress = GmmHelper::canonize(gpuVirtualAddress); - bo->setAllocationType(allocatorType); auto allocation = new DrmAllocation(allocationData.type, bo, const_cast(allocationData.hostPtr), GmmHelper::canonize(ptrOffset(gpuVirtualAddress, inputPointerOffset)), allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false); allocation->set32BitAllocation(true); allocation->setGpuBaseAddress(GmmHelper::canonize(gfxPartition->getHeapBase(allocatorToUse))); + allocation->setReservedAddressRange(reinterpret_cast(gpuVirtualAddress), realAllocationSize); return allocation; } @@ -393,10 +354,6 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio return nullptr; } - bo->isAllocated = true; - bo->setUnmapSize(allocationSize); - - bo->setAllocationType(allocatorType); bo->gpuAddress = GmmHelper::canonize(res); // softpin to the GPU address, res if it uses limitedRange Allocation @@ -406,6 +363,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio allocation->set32BitAllocation(true); allocation->setGpuBaseAddress(GmmHelper::canonize(gfxPartition->getHeapBase(allocatorToUse))); allocation->setDriverAllocatedCpuPtr(ptrAlloc); + allocation->setReservedAddressRange(reinterpret_cast(res), allocationSize); return allocation; } @@ -424,12 +382,10 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle) BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness) { uint64_t gpuRange = 0llu; - StorageAllocatorType storageType = UNKNOWN_ALLOCATOR; - gpuRange = acquireGpuRange(size, storageType, requireSpecificBitness); - DEBUG_BREAK_IF(gpuRange == reinterpret_cast(MAP_FAILED)); + gpuRange = acquireGpuRange(size, requireSpecificBitness); - auto bo = new (std::nothrow) BufferObject(this->drm, boHandle, true); + auto bo = new (std::nothrow) BufferObject(this->drm, boHandle); if (!bo) { return nullptr; } @@ -437,7 +393,6 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si bo->size = size; bo->gpuAddress = gpuRange; bo->setUnmapSize(size); - bo->setAllocationType(storageType); return bo; } @@ -478,9 +433,9 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (requireSpecificBitness && this->force32bitAllocations) { drmAllocation->set32BitAllocation(true); - drmAllocation->setGpuBaseAddress(getExternalHeapBaseAddress()); - } else if (isLimitedRange()) { - drmAllocation->setGpuBaseAddress(gfxPartition->getHeapBase(HeapIndex::HEAP_STANDARD)); + drmAllocation->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress())); + } else { + drmAllocation->setGpuBaseAddress(GmmHelper::canonize(gfxPartition->getHeapBase(HeapIndex::HEAP_STANDARD))); } if (properties.imgInfo) { @@ -500,9 +455,8 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) { uint64_t gpuRange = 0llu; - StorageAllocatorType storageType = UNKNOWN_ALLOCATOR; - gpuRange = acquireGpuRange(sizeWithPadding, storageType, false); + gpuRange = acquireGpuRange(sizeWithPadding, false); auto srcPtr = inputGraphicsAllocation->getUnderlyingBuffer(); auto srcSize = inputGraphicsAllocation->getUnderlyingBufferSize(); @@ -515,10 +469,11 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation return nullptr; } bo->gpuAddress = gpuRange; - bo->setUnmapSize(sizeWithPadding); - bo->setAllocationType(storageType); - return new DrmAllocation(inputGraphicsAllocation->getAllocationType(), bo, srcPtr, GmmHelper::canonize(ptrOffset(gpuRange, offset)), sizeWithPadding, - inputGraphicsAllocation->getMemoryPool(), false); + auto allocation = new DrmAllocation(inputGraphicsAllocation->getAllocationType(), bo, srcPtr, GmmHelper::canonize(ptrOffset(gpuRange, offset)), sizeWithPadding, + inputGraphicsAllocation->getMemoryPool(), false); + + allocation->setReservedAddressRange(reinterpret_cast(gpuRange), sizeWithPadding); + return allocation; } void DrmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) { @@ -567,11 +522,9 @@ void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) if (gfxAllocation->peekSharedHandle() != Sharing::nonSharedResource) { closeFunction(gfxAllocation->peekSharedHandle()); } - void *reserveAddress = gfxAllocation->getReservedAddressPtr(); - if (reserveAddress) { - auto gpuAddressToFree = GmmHelper::decanonize(reinterpret_cast(reserveAddress)); - gfxPartition->freeGpuAddressRange(gpuAddressToFree, gfxAllocation->getReservedAddressSize()); - } + + releaseGpuRange(gfxAllocation->getReservedAddressPtr(), gfxAllocation->getReservedAddressSize()); + delete gfxAllocation; unreference(search); @@ -724,14 +677,6 @@ void DrmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocation bo->setLockedAddress(nullptr); } -void *DrmMemoryManager::reserveCpuAddressRange(size_t size) { - void *reservePtr = mmapFunction(nullptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); - return reservePtr; -} - -void DrmMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size) { - munmapFunction(reserved, size); -} int DrmMemoryManager::obtainFdFromHandle(int boHandle) { drm_prime_handle openFd = {0, 0, 0}; @@ -747,4 +692,5 @@ uint32_t DrmMemoryManager::getDefaultDrmContextId() const { auto &osContextLinux = static_cast(getDefaultCommandStreamReceiver(0)->getOsContext()); return osContextLinux.getDrmContextIds()[0]; } + } // namespace NEO diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index 438d9258f6..8e3ec0c317 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -52,8 +52,6 @@ class DrmMemoryManager : public MemoryManager { DrmGemCloseWorker *peekGemCloseWorker() const { return this->gemCloseWorker.get(); } bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override; - void *reserveCpuAddressRange(size_t size) override; - void releaseReservedCpuAddressRange(void *reserved, size_t size) override; int obtainFdFromHandle(int boHandle); @@ -64,8 +62,8 @@ class DrmMemoryManager : public MemoryManager { void pushSharedBufferObject(BufferObject *bo); BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags); bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable); - uint64_t acquireGpuRange(size_t &size, StorageAllocatorType &allocType, bool requireSpecificBitness); - void releaseGpuRange(void *address, size_t unmapSize, StorageAllocatorType allocatorType); + uint64_t acquireGpuRange(size_t &size, bool requireSpecificBitness); + void releaseGpuRange(void *address, size_t size); void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const; uint32_t getDefaultDrmContextId() const; @@ -83,14 +81,13 @@ class DrmMemoryManager : public MemoryManager { GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; Drm *drm; - BufferObject *pinBB; + BufferObject *pinBB = nullptr; + void *memoryForPinBB = nullptr; size_t pinThreshold = 8 * 1024 * 1024; bool forcePinEnabled = false; const bool validateHostPtrMemory; std::unique_ptr gemCloseWorker; decltype(&lseek) lseekFunction = lseek; - decltype(&mmap) mmapFunction = mmap; - decltype(&munmap) munmapFunction = munmap; decltype(&close) closeFunction = close; std::vector sharingBufferObjects; std::mutex mtx; diff --git a/unit_tests/mocks/linux/mock_drm_allocation.h b/unit_tests/mocks/linux/mock_drm_allocation.h index 01625076e9..c264a2a7a6 100644 --- a/unit_tests/mocks/linux/mock_drm_allocation.h +++ b/unit_tests/mocks/linux/mock_drm_allocation.h @@ -15,7 +15,7 @@ class MockBufferObject : public BufferObject { public: using BufferObject::handle; - MockBufferObject() : BufferObject(nullptr, 0, false) { + MockBufferObject() : BufferObject(nullptr, 0) { } }; diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index b3d4ca1a97..a679d9bea0 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -17,24 +17,11 @@ namespace NEO { static off_t lseekReturn = 4096u; static std::atomic lseekCalledCount(0); -static std::atomic mmapMockCallCount(0); -static std::atomic munmapMockCallCount(0); inline off_t lseekMock(int fd, off_t offset, int whence) noexcept { lseekCalledCount++; return lseekReturn; } -inline void *mmapMock(void *addr, size_t length, int prot, int flags, - int fd, long offset) noexcept { - mmapMockCallCount++; - return reinterpret_cast(0x1000); -} - -inline int munmapMock(void *addr, size_t length) noexcept { - munmapMockCallCount++; - return 0; -} - inline int closeMock(int) { return 0; } @@ -65,13 +52,9 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { false, executionEnvironment) { this->lseekFunction = &lseekMock; - this->mmapFunction = &mmapMock; - this->munmapFunction = &munmapMock; this->closeFunction = &closeMock; lseekReturn = 4096; lseekCalledCount = 0; - mmapMockCallCount = 0; - munmapMockCallCount = 0; hostPtrManager.reset(new MockHostPtrManager); }; TestedDrmMemoryManager(bool enableLocalMemory, @@ -83,13 +66,9 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { validateHostPtrMemory, executionEnvironment) { this->lseekFunction = &lseekMock; - this->mmapFunction = &mmapMock; - this->munmapFunction = &munmapMock; this->closeFunction = &closeMock; lseekReturn = 4096; lseekCalledCount = 0; - mmapMockCallCount = 0; - munmapMockCallCount = 0; } void unreference(BufferObject *bo) { diff --git a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp index 149ba1d3e8..0b1f674972 100644 --- a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp +++ b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp @@ -17,7 +17,7 @@ using namespace NEO; class TestedBufferObject : public BufferObject { public: - TestedBufferObject(Drm *drm) : BufferObject(drm, 1, true) { + TestedBufferObject(Drm *drm) : BufferObject(drm, 1) { } void tileBy(uint32_t mode) { diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 95db8cc7ba..1163e3c270 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -614,7 +614,7 @@ class DrmCommandStreamEnhancedFixture friend DrmCommandStreamEnhancedFixture; protected: - MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, false) { + MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1) { this->size = alignUp(size, 4096); } }; diff --git a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp index 6dd0eed7f5..ba7303bdfb 100644 --- a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -89,12 +89,6 @@ class DrmGemCloseWorkerFixture { } protected: - class BufferObjectWrapper : public BufferObject { - public: - BufferObjectWrapper(Drm *drm, int handle) - : BufferObject(drm, handle, false) { - } - }; class DrmAllocationWrapper : public DrmAllocation { public: DrmAllocationWrapper(BufferObject *bo) @@ -110,7 +104,7 @@ TEST_F(DrmGemCloseWorkerTests, gemClose) { this->drmMock->gem_close_expected = 1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObjectWrapper(this->drmMock, 1); + auto bo = new BufferObject(this->drmMock, 1); worker->push(bo); @@ -121,7 +115,7 @@ TEST_F(DrmGemCloseWorkerTests, gemCloseExit) { this->drmMock->gem_close_expected = -1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObjectWrapper(this->drmMock, 1); + auto bo = new BufferObject(this->drmMock, 1); worker->push(bo); @@ -141,7 +135,7 @@ TEST_F(DrmGemCloseWorkerTests, close) { this->drmMock->gem_close_expected = -1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObjectWrapper(this->drmMock, 1); + auto bo = new BufferObject(this->drmMock, 1); worker->push(bo); worker->close(false); @@ -159,7 +153,7 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl this->drmMock->gem_close_expected = 1; auto worker = new DrmGemCloseWorker(*mm); - auto bo = new BufferObjectWrapper(this->drmMock, 1); + auto bo = new BufferObject(this->drmMock, 1); bo->reference(); worker->push(bo); 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 c9e4d727db..d2135d754e 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -403,7 +403,6 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr) { auto bo = alloc->getBO(); ASSERT_NE(nullptr, bo); - EXPECT_FALSE(bo->peekIsAllocated()); EXPECT_EQ(ptr, reinterpret_cast(bo->peekAddress())); EXPECT_EQ(Sharing::nonSharedResource, alloc->peekSharedHandle()); memoryManager->freeGraphicsMemory(alloc); @@ -425,7 +424,6 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_Nullptr) { auto bo = alloc->getBO(); ASSERT_NE(nullptr, bo); - EXPECT_FALSE(bo->peekIsAllocated()); EXPECT_EQ(ptr, reinterpret_cast(bo->peekAddress())); memoryManager->freeGraphicsMemory(alloc); @@ -449,7 +447,6 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_MisAligned) { auto bo = alloc->getBO(); ASSERT_NE(nullptr, bo); - EXPECT_FALSE(bo->peekIsAllocated()); EXPECT_EQ(ptrT, reinterpret_cast(bo->peekAddress())); memoryManager->freeGraphicsMemory(alloc); @@ -706,7 +703,6 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked ASSERT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo); EXPECT_EQ(reqs.AllocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekSize()); EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, reinterpret_cast(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress())); - EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekIsAllocated()); } memoryManager->freeGraphicsMemory(graphicsAllocation); EXPECT_EQ(0u, hostPtrManager->getFragmentCount()); @@ -726,14 +722,10 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32 auto address64bit = allocation->getGpuAddressToPatch(); EXPECT_LT(address64bit, MemoryConstants::max32BitAddress); - auto bo = allocation->getBO(); - EXPECT_GE(bo->peekUnmapSize(), 0u); EXPECT_TRUE(allocation->is32BitAllocation()); EXPECT_EQ(GmmHelper::canonize(memoryManager->getExternalHeapBaseAddress()), allocation->getGpuBaseAddress()); - EXPECT_EQ(bo->peekAllocationType(), StorageAllocatorType::BIT32_ALLOCATOR_EXTERNAL); - memoryManager->freeGraphicsMemory(allocation); } @@ -829,7 +821,6 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHos auto bufferObject = drmAllocation->getBO(); - EXPECT_NE(0u, bufferObject->peekUnmapSize()); EXPECT_EQ(drmAllocation->getUnderlyingBuffer(), reinterpret_cast(offsetedPtr)); // Gpu address should be different @@ -838,7 +829,6 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHos EXPECT_EQ(allocationGpuOffset, ptrOffset); EXPECT_EQ(allocationPageOffset, ptrOffset); - EXPECT_FALSE(bufferObject->peekIsAllocated()); auto boAddress = bufferObject->peekAddress(); EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); @@ -889,13 +879,7 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64B auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); auto bufferObject = drmAllocation->getBO(); - EXPECT_NE(0u, bufferObject->peekUnmapSize()); - EXPECT_EQ(allocationPageOffset, ptrOffset); - EXPECT_FALSE(bufferObject->peekIsAllocated()); - - auto totalAllocationSize = alignSizeWholePage(reinterpret_cast(offsetedPtr), size); - EXPECT_EQ(totalAllocationSize, bufferObject->peekUnmapSize()); auto boAddress = bufferObject->peekAddress(); EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); @@ -921,45 +905,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenLimitedRangeAllocatorSetThenH EXPECT_EQ(memoryManager->gfxPartition->getHeapMinimalAddress(internalHeapIndex), gpuInternal32BitAlloc); } -TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignmentThenCorrectAllocatorTypeSelected) { - // if limitedRangeAllocator is enabled by default on the platform, only limitedRangeAllocator case will be tested. - auto limitedRange = memoryManager->isLimitedRange(); - if (limitedRange) { - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - } else { - mock->ioctl_expected.gemUserptr = 2; - mock->ioctl_expected.gemWait = 2; - mock->ioctl_expected.gemClose = 2; - } - - TestedDrmMemoryManager::AllocationData allocationData; - allocationData.size = MemoryConstants::pageSize; - DrmAllocation *allocation = memoryManager->allocateGraphicsMemoryWithAlignment(allocationData); - auto bo = allocation->getBO(); - - // if limitedRangeAllocator is enabled by default on the platform, expect the allocator type - // is always INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE - if (limitedRange) { - EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, bo->peekAllocationType()); - memoryManager->freeGraphicsMemory(allocation); - } else { - //allocation type should be UNKNOWN_ALLOCATOR - EXPECT_EQ(UNKNOWN_ALLOCATOR, bo->peekAllocationType()); - - memoryManager->freeGraphicsMemory(allocation); - - memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); - allocation = memoryManager->allocateGraphicsMemoryWithAlignment(allocationData); - - bo = allocation->getBO(); - //make sure allocation type is set for limitedRangeAllocation - EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, bo->peekAllocationType()); - memoryManager->freeGraphicsMemory(allocation); - } -} - TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignmentAndLimitedRangeAllocatorSetAndAcquireGpuRangeFailsThenNullIsReturned) { mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.gemClose = 1; @@ -1173,15 +1118,6 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); - DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); - EXPECT_EQ(imgInfo.size, drmAllocation->getBO()->peekUnmapSize()); - - if (memoryManager->isLimitedRange()) { - EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); - } else { - EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType()); - } - EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imgInfo.size, this->mock->createParamsSize); __u32 tilingMode = I915_TILING_Y; @@ -1190,11 +1126,6 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag EXPECT_EQ(1u, this->mock->setTilingHandle); memoryManager->freeGraphicsMemory(imageGraphicsAllocation); - - if (!memoryManager->isLimitedRange()) { - EXPECT_EQ(1, mmapMockCallCount); - EXPECT_EQ(1, munmapMockCallCount); - } } TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { @@ -1232,8 +1163,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZero auto imageSize = drmAllocation->getUnderlyingBufferSize(); auto rowPitch = dstImage->getImageDesc().image_row_pitch; - EXPECT_EQ(imageSize, drmAllocation->getBO()->peekUnmapSize()); - EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imageSize, this->mock->createParamsSize); __u32 tilingMode = I915_TILING_Y; @@ -1279,8 +1208,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZ auto imageSize = drmAllocation->getUnderlyingBufferSize(); auto rowPitch = dstImage->getImageDesc().image_row_pitch; - EXPECT_EQ(imageSize, drmAllocation->getBO()->peekUnmapSize()); - EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imageSize, this->mock->createParamsSize); __u32 tilingMode = I915_TILING_Y; @@ -1359,8 +1286,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr auto imageSize = drmAllocation->getUnderlyingBufferSize(); auto rowPitch = dstImage->getImageDesc().image_row_pitch; - EXPECT_EQ(imageSize, drmAllocation->getBO()->peekUnmapSize()); - EXPECT_EQ(1u, this->mock->createParamsHandle); EXPECT_EQ(imageSize, this->mock->createParamsSize); __u32 tilingMode = I915_TILING_Y; @@ -1400,17 +1325,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenMemoryAllocatedForImageThe auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(); ASSERT_NE(nullptr, imageGraphicsAllocation); - DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); - - // if limitedRangeAllocator is enabled, gpuRange is acquired and it should be - // set as unmapsize for freeing in the furture. - auto limitedRange = memoryManager->isLimitedRange(); - if (!limitedRange) { - EXPECT_EQ(0u, drmAllocation->getBO()->peekUnmapSize()); - } else { - EXPECT_NE(0u, drmAllocation->getBO()->peekUnmapSize()); - } - alignedFree(data); } @@ -1600,9 +1514,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT DrmAllocation *drmAllocation = static_cast(graphicsAllocation); auto bo = drmAllocation->getBO(); EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); - EXPECT_EQ(bo->peekUnmapSize(), size); EXPECT_NE(0llu, bo->peekAddress()); - EXPECT_TRUE(bo->peekIsAllocated()); EXPECT_EQ(1u, bo->getRefCount()); EXPECT_EQ(size, bo->peekSize()); @@ -1753,9 +1665,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea drmAllocation = static_cast(graphicsAllocations[i]); bo = drmAllocation->getBO(); EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); - EXPECT_EQ(bo->peekUnmapSize(), size); EXPECT_NE(0llu, bo->peekAddress()); - EXPECT_TRUE(bo->peekIsAllocated()); EXPECT_EQ(expectedRefCount, bo->getRefCount()); EXPECT_EQ(size, bo->peekSize()); @@ -1784,10 +1694,8 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleAndBi auto drmAllocation = static_cast(graphicsAllocation); EXPECT_TRUE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); - EXPECT_EQ(BIT32_ALLOCATOR_EXTERNAL, drmAllocation->getBO()->peekAllocationType()); + EXPECT_EQ(GmmHelper::canonize(memoryManager->getExternalHeapBaseAddress()), drmAllocation->getGpuBaseAddress()); memoryManager->freeGraphicsMemory(graphicsAllocation); - EXPECT_EQ(0, mmapMockCallCount); - EXPECT_EQ(0, munmapMockCallCount); } TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCreatedAndDoesntRequireBitnessThenItIsNot32BitAllocation) { @@ -1805,18 +1713,9 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); - if (memoryManager->isLimitedRange()) { - EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); - } else { - EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType()); - } + EXPECT_EQ(GmmHelper::canonize(memoryManager->gfxPartition->getHeapBase(HeapIndex::HEAP_STANDARD)), drmAllocation->getGpuBaseAddress()); memoryManager->freeGraphicsMemory(graphicsAllocation); - - if (!memoryManager->isLimitedRange()) { - EXPECT_EQ(1, mmapMockCallCount); - EXPECT_EQ(1, munmapMockCallCount); - } } TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenBufferFromSharedHandleIsCreatedThenItIsLimitedRangeAllocation) { @@ -1831,7 +1730,8 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenBufferFromSharedHandl auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); auto drmAllocation = static_cast(graphicsAllocation); - EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); + + EXPECT_EQ(GmmHelper::canonize(memoryManager->gfxPartition->getHeapBase(HeapIndex::HEAP_STANDARD)), drmAllocation->getGpuBaseAddress()); EXPECT_EQ(1, lseekCalledCount); memoryManager->freeGraphicsMemory(graphicsAllocation); } @@ -1849,19 +1749,8 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs auto drmAllocation = static_cast(graphicsAllocation); EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); - - if (memoryManager->isLimitedRange()) { - EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); - } else { - EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType()); - } - + EXPECT_EQ(GmmHelper::canonize(memoryManager->gfxPartition->getHeapBase(HeapIndex::HEAP_STANDARD)), drmAllocation->getGpuBaseAddress()); memoryManager->freeGraphicsMemory(graphicsAllocation); - - if (!memoryManager->isLimitedRange()) { - EXPECT_EQ(1, mmapMockCallCount); - EXPECT_EQ(1, munmapMockCallCount); - } } TEST_F(DrmMemoryManagerTest, givenSharedHandleWhenAllocationIsCreatedAndIoctlPrimeFdToHandleFailsThenNullPtrIsReturned) { @@ -2051,7 +1940,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledButFails DrmMockCustom drmMock; struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, true) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 1) {} }; BufferObjectMock bo(&drmMock); DrmAllocation drmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, 1u, false); @@ -2079,7 +1968,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledButFai DrmMockCustom drmMock; struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, true) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 1) {} }; BufferObjectMock bo(&drmMock); DrmAllocation drmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, 1u, false); @@ -2095,7 +1984,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledOnAllo DrmMockCustom drmMock; struct BufferObjectMock : public BufferObject { - BufferObjectMock(Drm *drm) : BufferObject(drm, 1, true) {} + BufferObjectMock(Drm *drm) : BufferObject(drm, 1) {} }; BufferObjectMock bo(&drmMock); DrmAllocation drmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, 1u, false); @@ -2150,7 +2039,6 @@ TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragm DrmAllocation *graphicsAlloaction = memoryManager->allocate32BitGraphicsMemory(pages3size, host_ptr, GraphicsAllocation::AllocationType::BUFFER); auto bo = graphicsAlloaction->getBO(); - EXPECT_EQ(allocationSize, bo->peekUnmapSize()); EXPECT_EQ(pages3size, bo->peekSize()); EXPECT_EQ(GmmHelper::canonize(ptr), graphicsAlloaction->getGpuAddress()); @@ -2175,9 +2063,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre DrmAllocation *drmAllocation = static_cast(graphicsAllocation); auto bo = drmAllocation->getBO(); EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); - EXPECT_EQ(bo->peekUnmapSize(), realSize); EXPECT_NE(0llu, bo->peekAddress()); - EXPECT_TRUE(bo->peekIsAllocated()); EXPECT_EQ(1u, bo->getRefCount()); EXPECT_EQ(realSize, bo->peekSize()); EXPECT_EQ(1, lseekCalledCount); @@ -2215,9 +2101,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerSupportingVirutalPaddingWhenItIsR auto bo = static_cast(paddedAllocation)->getBO(); EXPECT_NE(nullptr, bo); - EXPECT_EQ(bufferWithPaddingSize, bo->peekUnmapSize()); - - EXPECT_FALSE(bo->peekIsAllocated()); EXPECT_NE(bufferbo->peekHandle(), bo->peekHandle()); memoryManager->freeGraphicsMemory(paddedAllocation); @@ -2249,11 +2132,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit EXPECT_EQ(drmAllocation->getGpuBaseAddress(), heapBase); - auto bo = drmAllocation->getBO(); - EXPECT_TRUE(bo->peekIsAllocated()); - EXPECT_EQ(bo->peekAllocationType(), StorageAllocatorType::BIT32_ALLOCATOR_INTERNAL); - EXPECT_EQ(bo->peekUnmapSize(), bufferSize); - memoryManager->freeGraphicsMemory(drmAllocation); } @@ -2287,11 +2165,6 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc EXPECT_EQ(drmAllocation->getGpuBaseAddress(), heapBase); - auto bo = drmAllocation->getBO(); - EXPECT_TRUE(bo->peekIsAllocated()); - EXPECT_EQ(bo->peekAllocationType(), StorageAllocatorType::BIT32_ALLOCATOR_INTERNAL); - EXPECT_EQ(bo->peekUnmapSize(), bufferSize); - memoryManager->freeGraphicsMemory(drmAllocation); } @@ -2349,11 +2222,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit EXPECT_EQ(drmAllocation->getGpuBaseAddress(), heapBase); - auto bo = drmAllocation->getBO(); - EXPECT_FALSE(bo->peekIsAllocated()); - EXPECT_EQ(bo->peekAllocationType(), StorageAllocatorType::BIT32_ALLOCATOR_INTERNAL); - EXPECT_EQ(bo->peekUnmapSize(), bufferSize); - memoryManager->freeGraphicsMemory(drmAllocation); } @@ -2619,7 +2487,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna class PinBufferObject : public BufferObject { public: - PinBufferObject(Drm *drm) : BufferObject(drm, 1, true) { + PinBufferObject(Drm *drm) : BufferObject(drm, 1) { } int pin(BufferObject *const boToPin[], size_t numberOfBos, uint32_t drmContextId) override { @@ -2797,7 +2665,6 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor allocationData.hostPtr = reinterpret_cast(0x30000000); allocation0 = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData); - EXPECT_EQ((uint64_t)(allocation0->getBO()->peekUnmapSize()), 4 * MB + 16 * 1024); EXPECT_EQ((uint64_t)(allocation0->getBO()->peekSize()), 4 * MB + 12 * 1024); memoryManager->freeGraphicsMemory(allocation0); @@ -3108,7 +2975,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, whenReservingAddressRangeTh auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); ASSERT_NE(nullptr, allocation); void *reserve = memoryManager->reserveCpuAddressRange(size); - EXPECT_NE(nullptr, reserve); + EXPECT_EQ(nullptr, reserve); allocation->setReservedAddressRange(reserve, size); EXPECT_EQ(reserve, allocation->getReservedAddressPtr()); EXPECT_EQ(size, allocation->getReservedAddressSize()); @@ -3189,5 +3056,5 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndReleaseGpuRangeIsCalledThen EXPECT_CALL(*mockGfxPartition.get(), freeGpuAddressRange(gpuAddress, size)); memoryManager->overrideGfxPartition(mockGfxPartition.release()); - memoryManager->releaseGpuRange(reinterpret_cast(gpuAddressCanonized), size, UNKNOWN_ALLOCATOR); + memoryManager->releaseGpuRange(reinterpret_cast(gpuAddressCanonized), size); }