feature: Add ioctl helper function to synchronize userptr allocations

Related-To: NEO-12846

Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek 2024-11-22 17:02:47 +00:00 committed by Compute-Runtime-Automation
parent 5862cbcb9f
commit edaac6ce43
4 changed files with 7 additions and 5 deletions

View File

@ -456,7 +456,7 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignmentFromUserptr(const Alloc
} }
auto ioctlHelper = getDrm(allocationData.rootDeviceIndex).getIoctlHelper(); auto ioctlHelper = getDrm(allocationData.rootDeviceIndex).getIoctlHelper();
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(ioctlHelper->allocUserptr(*this, reinterpret_cast<uintptr_t>(res), size, allocationData.rootDeviceIndex)); std::unique_ptr<BufferObject, BufferObject::Deleter> bo(ioctlHelper->allocUserptr(*this, allocationData, reinterpret_cast<uintptr_t>(res), size, allocationData.rootDeviceIndex));
if (!bo) { if (!bo) {
alignedFreeWrapper(res); alignedFreeWrapper(res);
return nullptr; return nullptr;
@ -605,7 +605,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(con
return nullptr; return nullptr;
} }
auto ioctlHelper = getDrm(rootDeviceIndex).getIoctlHelper(); auto ioctlHelper = getDrm(rootDeviceIndex).getIoctlHelper();
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(ioctlHelper->allocUserptr(*this, reinterpret_cast<uintptr_t>(alignedPtr), realAllocationSize, rootDeviceIndex)); std::unique_ptr<BufferObject, BufferObject::Deleter> bo(ioctlHelper->allocUserptr(*this, allocationData, reinterpret_cast<uintptr_t>(alignedPtr), realAllocationSize, rootDeviceIndex));
if (!bo) { if (!bo) {
releaseGpuRange(reinterpret_cast<void *>(gpuVirtualAddress), alignedSize, rootDeviceIndex); releaseGpuRange(reinterpret_cast<void *>(gpuVirtualAddress), alignedSize, rootDeviceIndex);
return nullptr; return nullptr;
@ -1386,6 +1386,7 @@ void DrmMemoryManager::handleFenceCompletion(GraphicsAllocation *allocation) {
} else { } else {
static_cast<DrmAllocation *>(allocation)->getBO()->wait(-1); static_cast<DrmAllocation *>(allocation)->getBO()->wait(-1);
} }
drm.getIoctlHelper()->syncUserptrAllocs(*this);
} }
GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) { GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) {

View File

@ -126,6 +126,7 @@ class DrmMemoryManager : public MemoryManager {
MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex); MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex);
BufferObject *allocUserptr(uintptr_t address, size_t size, uint32_t rootDeviceIndex); BufferObject *allocUserptr(uintptr_t address, size_t size, uint32_t rootDeviceIndex);
size_t getUserptrAlignment();
decltype(&mmap) mmapFunction = mmap; decltype(&mmap) mmapFunction = mmap;
decltype(&munmap) munmapFunction = munmap; decltype(&munmap) munmapFunction = munmap;
@ -143,7 +144,6 @@ class DrmMemoryManager : public MemoryManager {
void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const; void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const;
uint32_t getDefaultDrmContextId(uint32_t rootDeviceIndex) const; uint32_t getDefaultDrmContextId(uint32_t rootDeviceIndex) const;
OsContextLinux *getDefaultOsContext(uint32_t rootDeviceIndex) const; OsContextLinux *getDefaultOsContext(uint32_t rootDeviceIndex) const;
size_t getUserptrAlignment();
StorageInfo createStorageInfoFromProperties(const AllocationProperties &properties) override; StorageInfo createStorageInfoFromProperties(const AllocationProperties &properties) override;
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override; GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;

View File

@ -115,7 +115,7 @@ void IoctlHelper::registerMemoryToUnmap(DrmAllocation &allocation, void *pointer
return allocation.registerMemoryToUnmap(pointer, size, unmapFunction); return allocation.registerMemoryToUnmap(pointer, size, unmapFunction);
} }
BufferObject *IoctlHelper::allocUserptr(DrmMemoryManager &memoryManager, uintptr_t address, size_t size, uint32_t rootDeviceIndex) { BufferObject *IoctlHelper::allocUserptr(DrmMemoryManager &memoryManager, const AllocationData &allocData, uintptr_t address, size_t size, uint32_t rootDeviceIndex) {
return memoryManager.allocUserptr(address, size, rootDeviceIndex); return memoryManager.allocUserptr(address, size, rootDeviceIndex);
} }

View File

@ -229,7 +229,8 @@ class IoctlHelper {
virtual void *mmapFunction(DrmMemoryManager &memoryManager, void *ptr, size_t size, int prot, int flags, int fd, off_t offset); 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 int munmapFunction(DrmMemoryManager &memoryManager, void *ptr, size_t size);
virtual void registerMemoryToUnmap(DrmAllocation &allocation, void *pointer, size_t size, DrmAllocation::MemoryUnmapFunction unmapFunction); virtual void registerMemoryToUnmap(DrmAllocation &allocation, void *pointer, size_t size, DrmAllocation::MemoryUnmapFunction unmapFunction);
virtual BufferObject *allocUserptr(DrmMemoryManager &memoryManager, uintptr_t address, size_t size, uint32_t rootDeviceIndex); virtual BufferObject *allocUserptr(DrmMemoryManager &memoryManager, const AllocationData &allocData, uintptr_t address, size_t size, uint32_t rootDeviceIndex);
virtual void syncUserptrAllocs(DrmMemoryManager &memoryManager) { return; };
virtual bool queryDeviceParams(uint32_t *moduleId, uint16_t *serverType) { return false; } virtual bool queryDeviceParams(uint32_t *moduleId, uint16_t *serverType) { return false; }