Fix unmap unalignment part at end of mmap allocation

Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2021-01-28 20:58:23 +00:00
committed by Compute-Runtime-Automation
parent 7e9461ffa0
commit 2eaf830aff
5 changed files with 34 additions and 20 deletions

View File

@@ -83,8 +83,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &
cpuPointer = alignUp(cpuPointer, alignment);
auto pointerDiff = ptrDiff(cpuPointer, cpuBasePointer);
auto allocSize = totalSizeToAlloc - pointerDiff;
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(this->createBufferObjectInMemoryRegion(&this->getDrm(allocationData.rootDeviceIndex), reinterpret_cast<uintptr_t>(cpuPointer), allocSize, 0u, maxOsContextCount));
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(this->createBufferObjectInMemoryRegion(&this->getDrm(allocationData.rootDeviceIndex), reinterpret_cast<uintptr_t>(cpuPointer), alignedSize, 0u, maxOsContextCount));
if (!bo) {
this->munmapFunction(cpuBasePointer, totalSizeToAlloc);
@@ -101,20 +100,22 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &
return nullptr;
}
[[maybe_unused]] auto retPtr = this->mmapFunction(cpuPointer, allocSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, getDrm(allocationData.rootDeviceIndex).getFileDescriptor(), static_cast<off_t>(gemMmap.offset));
[[maybe_unused]] auto retPtr = this->mmapFunction(cpuPointer, alignedSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, getDrm(allocationData.rootDeviceIndex).getFileDescriptor(), static_cast<off_t>(gemMmap.offset));
DEBUG_BREAK_IF(retPtr != cpuPointer);
obtainGpuAddress(allocationData, bo.get(), gpuAddress);
emitPinningRequest(bo.get(), allocationData);
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), cpuPointer, bo->gpuAddress, allocSize, MemoryPool::System4KBPages);
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), cpuPointer, bo->gpuAddress, alignedSize, MemoryPool::System4KBPages);
allocation->setMmapPtr(cpuPointer);
allocation->setMmapSize(allocSize);
allocation->setMmapSize(alignedSize);
if (pointerDiff != 0) {
[[maybe_unused]] auto retCode = this->munmapFunction(cpuBasePointer, pointerDiff);
DEBUG_BREAK_IF(retCode != 0);
}
allocation->setReservedAddressRange(reinterpret_cast<void *>(gpuAddress), allocSize);
[[maybe_unused]] auto retCode = this->munmapFunction(ptrOffset(cpuPointer, alignedSize), alignment - pointerDiff);
DEBUG_BREAK_IF(retCode != 0);
allocation->setReservedAddressRange(reinterpret_cast<void *>(gpuAddress), alignedSize);
bo.release();