From 0b46fb9f0d1b461f93b84c1e9349a2b0d6c788c3 Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Wed, 21 May 2025 13:12:14 +0000 Subject: [PATCH] refactor: Add allocation type parameter to ioctl helper functions Related-To: NEO-12952 Signed-off-by: Slawomir Milczarek --- .../os_interface/linux/drm_memory_manager.cpp | 24 +++++++++---------- .../os_interface/linux/ioctl_helper.cpp | 4 ++-- .../source/os_interface/linux/ioctl_helper.h | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 595a746740..a0bccef499 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1462,7 +1462,7 @@ void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, } ioctlHelper->syncUserptrAlloc(*this, *gfxAllocation); - ioctlHelper->releaseGpuRange(*this, gfxAllocation->getReservedAddressPtr(), gfxAllocation->getReservedAddressSize(), gfxAllocation->getRootDeviceIndex()); + ioctlHelper->releaseGpuRange(*this, gfxAllocation->getReservedAddressPtr(), gfxAllocation->getReservedAddressSize(), gfxAllocation->getRootDeviceIndex(), gfxAllocation->getAllocationType()); alignedFreeWrapper(gfxAllocation->getDriverAllocatedCpuPtr()); drmAlloc->freeRegisteredBOBindExtHandles(&getDrm(drmAlloc->getRootDeviceIndex())); @@ -2604,15 +2604,15 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & auto gfxPartition = getGfxPartition(allocationData.rootDeviceIndex); auto canAllocateInHeapExtended = debugManager.flags.AllocateHostAllocationsInHeapExtendedHost.get(); if (canAllocateInHeapExtended && allocationData.flags.isUSMHostAllocation && gfxPartition->getHeapLimit(HeapIndex::heapExtendedHost) > 0u) { - preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, HeapIndex::heapExtendedHost); + preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type, HeapIndex::heapExtendedHost); } if (0 == preferredAddress) { - preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, HeapIndex::totalHeaps); + preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type, HeapIndex::totalHeaps); } auto cpuPointer = ioctlHelper->mmapFunction(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (castToUint64(cpuPointer) != preferredAddress) { - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); preferredAddress = 0; } @@ -2626,7 +2626,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & MemoryPoolHelper::isSystemMemoryPool(memoryPool), allocationData.flags.isUSMHostAllocation)); if (!bo) { - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); ioctlHelper->munmapFunction(*this, cpuBasePointer, totalSizeToAlloc); return nullptr; } @@ -2634,7 +2634,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & uint64_t offset = 0; uint64_t mmapOffsetWb = ioctlHelper->getDrmParamValue(DrmParam::mmapOffsetWb); if (!retrieveMmapOffsetForBufferObject(allocationData.rootDeviceIndex, *bo, mmapOffsetWb, offset)) { - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); ioctlHelper->munmapFunction(*this, cpuPointer, size); return nullptr; } @@ -2761,15 +2761,15 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const auto gfxPartition = getGfxPartition(allocationData.rootDeviceIndex); auto canAllocateInHeapExtended = debugManager.flags.AllocateSharedAllocationsInHeapExtendedHost.get(); if (canAllocateInHeapExtended && gfxPartition->getHeapLimit(HeapIndex::heapExtendedHost) > 0u && !allocationData.flags.resource48Bit) { - preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, HeapIndex::heapExtendedHost); + preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type, HeapIndex::heapExtendedHost); } if (0 == preferredAddress) { - preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, HeapIndex::totalHeaps); + preferredAddress = ioctlHelper->acquireGpuRange(*this, totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type, HeapIndex::totalHeaps); } auto cpuPointer = ioctlHelper->mmapFunction(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, PROT_NONE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (castToUint64(cpuPointer) != preferredAddress) { - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); preferredAddress = 0; } @@ -2821,7 +2821,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const if (ret) { ioctlHelper->munmapFunction(*this, cpuPointer, totalSizeToAlloc); - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); return nullptr; } @@ -2829,7 +2829,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const if (vmAdviseAttribute.has_value() && !ioctlHelper->setVmBoAdvise(bo->peekHandle(), vmAdviseAttribute.value(), nullptr)) { ioctlHelper->munmapFunction(*this, cpuBasePointer, totalSizeToAlloc); - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); return nullptr; } @@ -2838,7 +2838,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const bo->setBOType(getBOTypeFromPatIndex(patIndex, productHelper.isVmBindPatIndexProgrammingSupported())); if (!retrieveMmapOffsetForBufferObject(allocationData.rootDeviceIndex, *bo, mmapOffsetWb, offset)) { ioctlHelper->munmapFunction(*this, cpuBasePointer, totalSizeToAlloc); - ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex); + ioctlHelper->releaseGpuRange(*this, reinterpret_cast(preferredAddress), totalSizeToAlloc, allocationData.rootDeviceIndex, allocationData.type); return nullptr; } diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index 02d2551a42..367de3d03f 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -138,14 +138,14 @@ uint64_t *IoctlHelper::getPagingFenceAddress(uint32_t vmHandleId, OsContextLinux } } -uint64_t IoctlHelper::acquireGpuRange(DrmMemoryManager &memoryManager, size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex) { +uint64_t IoctlHelper::acquireGpuRange(DrmMemoryManager &memoryManager, size_t &size, uint32_t rootDeviceIndex, AllocationType allocType, HeapIndex heapIndex) { if (heapIndex >= HeapIndex::totalHeaps) { return 0; } return memoryManager.acquireGpuRange(size, rootDeviceIndex, heapIndex); } -void IoctlHelper::releaseGpuRange(DrmMemoryManager &memoryManager, void *address, size_t size, uint32_t rootDeviceIndex) { +void IoctlHelper::releaseGpuRange(DrmMemoryManager &memoryManager, void *address, size_t size, uint32_t rootDeviceIndex, AllocationType allocType) { memoryManager.releaseGpuRange(address, size, rootDeviceIndex); } diff --git a/shared/source/os_interface/linux/ioctl_helper.h b/shared/source/os_interface/linux/ioctl_helper.h index 1fa785689f..29fc29ace9 100644 --- a/shared/source/os_interface/linux/ioctl_helper.h +++ b/shared/source/os_interface/linux/ioctl_helper.h @@ -232,8 +232,8 @@ class IoctlHelper { virtual bool releaseInterrupt(uint32_t handle) { return false; } virtual uint64_t *getPagingFenceAddress(uint32_t vmHandleId, OsContextLinux *osContext); - virtual uint64_t acquireGpuRange(DrmMemoryManager &memoryManager, size_t &size, uint32_t rootDeviceIndex, HeapIndex heapIndex); - virtual void releaseGpuRange(DrmMemoryManager &memoryManager, void *address, size_t size, uint32_t rootDeviceIndex); + virtual uint64_t acquireGpuRange(DrmMemoryManager &memoryManager, size_t &size, uint32_t rootDeviceIndex, AllocationType allocType, HeapIndex heapIndex); + virtual void releaseGpuRange(DrmMemoryManager &memoryManager, void *address, size_t size, uint32_t rootDeviceIndex, AllocationType allocType); virtual void *mmapFunction(DrmMemoryManager &memoryManager, void *ptr, size_t size, int prot, int flags, int fd, off_t offset); virtual int munmapFunction(DrmMemoryManager &memoryManager, void *ptr, size_t size); virtual void registerMemoryToUnmap(DrmAllocation &allocation, void *pointer, size_t size, DrmAllocation::MemoryUnmapFunction unmapFunction);