Add support for IPC handles with implicit scaling

When using implicit scaling, device allocations may have
more than one internal allocation created internally. In that case,
a separate dma-buf handle per internal allocation needs to be
exported.

So introduced two driver experimental extensions to export and
import more than one IPC handle:

- zexMemGetIpcHandles
- zexMemOpenIpcHandles

Related-To: LOCI-2919

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2022-01-31 23:29:01 +00:00
committed by Compute-Runtime-Automation
parent c0de4fd243
commit 3f26f45c10
38 changed files with 1311 additions and 52 deletions

View File

@@ -62,3 +62,41 @@ class MemoryAllocatorMultiDeviceFixture : public MemoryManagementFixture, public
DebugManagerStateRestore restorer;
bool isOsAgnosticMemoryManager;
};
template <uint32_t numRootDevices, uint32_t numSubDevices>
class MemoryAllocatorMultiDeviceAndMultiTileFixture : public MemoryManagementFixture, public MemoryAllocatorMultiDeviceSystemSpecificFixture, public ::testing::TestWithParam<bool> {
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
isOsAgnosticMemoryManager = GetParam();
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
DebugManager.flags.CreateMultipleRootDevices.set(numSubDevices);
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
ultHwConfig.forceOsAgnosticMemoryManager = isOsAgnosticMemoryManager;
executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), true, numRootDevices);
devices = DeviceFactory::createDevices(*executionEnvironment);
memoryManager = executionEnvironment->memoryManager.get();
if (!isOsAgnosticMemoryManager) {
MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(*executionEnvironment);
}
}
void TearDown() override {
if (!isOsAgnosticMemoryManager) {
MemoryAllocatorMultiDeviceSystemSpecificFixture::TearDown(*executionEnvironment);
}
}
uint32_t getNumRootDevices() { return numRootDevices; }
protected:
std::vector<std::unique_ptr<Device>> devices;
ExecutionEnvironment *executionEnvironment = nullptr;
MemoryManager *memoryManager = nullptr;
DebugManagerStateRestore restorer;
bool isOsAgnosticMemoryManager;
};

View File

@@ -53,6 +53,7 @@ TestedDrmMemoryManager::TestedDrmMemoryManager(bool enableLocalMemory,
lseekCalledCount = 0;
closeInputFd = 0;
closeCalledCount = 0;
this->executionEnvironment = &executionEnvironment;
}
void TestedDrmMemoryManager::injectPinBB(BufferObject *newPinBB, uint32_t rootDeviceIndex) {

View File

@@ -8,6 +8,7 @@
#pragma once
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include <atomic>
@@ -112,6 +113,15 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
void forceLimitedRangeAllocator(uint64_t range);
void overrideGfxPartition(GfxPartition *newGfxPartition);
BufferObject *findAndReferenceSharedBufferObject(int boHandle, uint32_t rootDeviceIndex) override {
if (failOnfindAndReferenceSharedBufferObject) {
DrmMockCustom drmMock(*executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]);
auto patIndex = drmMock.getPatIndex(nullptr, AllocationType::BUFFER, CacheRegion::Default, CachePolicy::WriteBack, false);
return new (std::nothrow) BufferObject(&drmMock, patIndex, boHandle, 4096u, 2u);
}
return MemoryManagerCreate<DrmMemoryManager>::findAndReferenceSharedBufferObject(boHandle, rootDeviceIndex);
}
DrmAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, AllocationType allocationType);
~TestedDrmMemoryManager() override;
size_t peekSharedBosSize() {
@@ -153,6 +163,10 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
uint32_t alignedFreeWrapperCalled = 0u;
uint32_t callsToCloseSharedHandle = 0;
bool failOnfindAndReferenceSharedBufferObject = false;
ExecutionEnvironment *executionEnvironment = nullptr;
protected:
std::mutex unreferenceMtx;
std::mutex releaseGpuRangeMtx;

View File

@@ -302,6 +302,10 @@ class FailMemoryManager : public MockMemoryManager {
return nullptr;
}
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
return nullptr;
}
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
return nullptr;
}

View File

@@ -109,6 +109,9 @@ int DrmMockCustom::ioctl(unsigned long request, void *arg) {
primeToHandleParams->handle = outputHandle;
inputFd = primeToHandleParams->fd;
ioctl_cnt.primeFdToHandle++;
if (failOnPrimeFdToHandle == true) {
return -1;
}
} break;
case DRM_IOCTL_PRIME_HANDLE_TO_FD: {
auto *handleToPrimeParams = (drm_prime_handle *)arg;

View File

@@ -212,6 +212,7 @@ class DrmMockCustom : public Drm {
__u64 mmapOffsetExpected = 0;
__u64 mmapOffsetFlags = 0;
bool failOnMmapOffset = false;
bool failOnPrimeFdToHandle = false;
int errnoValue = 0;