mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 14:33:04 +08:00
Add support for resource lock / unlock on Linux OS
This commit fixes the issue with image contents writes in the configuration of CSR HW with AUB dump. Change-Id: Id0c4f36d4f9eee5175267384d42cb75bf41062f3
This commit is contained in:
committed by
sys_ocldev
parent
bf5170dbeb
commit
f217c9198c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
* Copyright (c) 2017 - 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <iostream>
|
||||
#include "drm/i915_drm.h"
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/os_interface/linux/drm_memory_manager.h"
|
||||
|
||||
#define RENDER_DEVICE_NAME_MATCHER ::testing::StrEq("/dev/dri/renderD128")
|
||||
|
||||
@@ -100,6 +101,17 @@ class DrmMockCustom : public Drm {
|
||||
//DRM_IOCTL_I915_GEM_USERPTR
|
||||
__u32 returnHandle = 0;
|
||||
__u64 gpuMemSize = 3u * MemoryConstants::gigaByte;
|
||||
//DRM_IOCTL_I915_GEM_MMAP
|
||||
__u32 mmapHandle = 0;
|
||||
__u32 mmapPad = 0;
|
||||
__u64 mmapOffset = 0;
|
||||
__u64 mmapSize = 0;
|
||||
__u64 mmapAddrPtr = 0x7F4000001000;
|
||||
__u64 mmapFlags = 0;
|
||||
//DRM_IOCTL_I915_GEM_SET_DOMAIN
|
||||
__u32 setDomainHandle = 0;
|
||||
__u32 setDomainReadDomains = 0;
|
||||
__u32 setDomainWriteDomain = 0;
|
||||
|
||||
int ioctl(unsigned long request, void *arg) override {
|
||||
auto ext = ioctl_res_ext.load();
|
||||
@@ -138,6 +150,21 @@ class DrmMockCustom : public Drm {
|
||||
aperture->aper_available_size = gpuMemSize;
|
||||
aperture->aper_size = gpuMemSize;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_MMAP) {
|
||||
auto mmapParams = (drm_i915_gem_mmap *)arg;
|
||||
mmapHandle = mmapParams->handle;
|
||||
mmapPad = mmapParams->pad;
|
||||
mmapOffset = mmapParams->offset;
|
||||
mmapSize = mmapParams->size;
|
||||
mmapFlags = mmapParams->flags;
|
||||
mmapParams->addr_ptr = mmapAddrPtr;
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_SET_DOMAIN) {
|
||||
auto setDomainParams = (drm_i915_gem_set_domain *)arg;
|
||||
setDomainHandle = setDomainParams->handle;
|
||||
setDomainReadDomains = setDomainParams->read_domains;
|
||||
setDomainWriteDomain = setDomainParams->write_domain;
|
||||
}
|
||||
|
||||
if (ext->no != -1 && ext->no == ioctl_cnt.load()) {
|
||||
ioctl_cnt.fetch_add(1);
|
||||
|
||||
@@ -78,6 +78,9 @@ int closeMock(int) {
|
||||
|
||||
class TestedDrmMemoryManager : public DrmMemoryManager {
|
||||
public:
|
||||
using DrmMemoryManager::allocUserptr;
|
||||
using DrmMemoryManager::setDomainCpu;
|
||||
|
||||
TestedDrmMemoryManager(Drm *drm) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerConsumingCommandBuffers, false) {
|
||||
this->lseekFunction = &lseekMock;
|
||||
this->mmapFunction = &mmapMock;
|
||||
@@ -103,10 +106,8 @@ class TestedDrmMemoryManager : public DrmMemoryManager {
|
||||
DrmMemoryManager::unreference(bo);
|
||||
}
|
||||
|
||||
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, bool softpin) {
|
||||
return DrmMemoryManager::allocUserptr(address, size, flags, softpin);
|
||||
}
|
||||
DrmGemCloseWorker *getgemCloseWorker() { return this->gemCloseWorker.get(); }
|
||||
|
||||
Allocator32bit *getDrmInternal32BitAllocator() { return internal32bitAllocator.get(); }
|
||||
};
|
||||
|
||||
@@ -1001,6 +1002,9 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag
|
||||
queryGmm.release();
|
||||
|
||||
ASSERT_NE(nullptr, imageGraphicsAllocation);
|
||||
EXPECT_NE(0u, imageGraphicsAllocation->getGpuAddress());
|
||||
EXPECT_EQ(nullptr, imageGraphicsAllocation->getUnderlyingBuffer());
|
||||
|
||||
EXPECT_TRUE(imageGraphicsAllocation->gmm->resourceParams.Usage ==
|
||||
GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE);
|
||||
|
||||
@@ -1369,18 +1373,161 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCreateAllocationFromNtHand
|
||||
EXPECT_EQ(nullptr, graphicsAllocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockCalledThenDoNothing) {
|
||||
mock->ioctl_expected = 3;
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledThenReturnPtr) {
|
||||
mock->ioctl_expected = 4;
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(1, 1);
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
|
||||
auto ptr = memoryManager->lockResource(allocation);
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
memoryManager->unlockResource(allocation);
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationWithCpuPtrThenReturnCpuPtrAndSetCpuDomain) {
|
||||
mock->ioctl_expected = 4;
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(1, 1);
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
EXPECT_NE(nullptr, allocation->getUnderlyingBuffer());
|
||||
|
||||
auto ptr = memoryManager->lockResource(allocation);
|
||||
EXPECT_EQ(allocation->getUnderlyingBuffer(), ptr);
|
||||
|
||||
//check DRM_IOCTL_I915_GEM_SET_DOMAIN input params
|
||||
auto drmAllocation = (DrmAllocation *)allocation;
|
||||
EXPECT_EQ((uint32_t)drmAllocation->getBO()->peekHandle(), mock->setDomainHandle);
|
||||
EXPECT_EQ((uint32_t)I915_GEM_DOMAIN_CPU, mock->setDomainReadDomains);
|
||||
EXPECT_EQ(0u, mock->setDomainWriteDomain);
|
||||
|
||||
memoryManager->unlockResource(allocation);
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationWithoutCpuPtrThenReturnLockedPtrAndSetCpuDomain) {
|
||||
mock->ioctl_expected = 6;
|
||||
cl_image_desc imgDesc = {};
|
||||
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imgDesc.image_width = 512;
|
||||
imgDesc.image_height = 512;
|
||||
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
|
||||
imgInfo.imgDesc = &imgDesc;
|
||||
imgInfo.size = 4096u;
|
||||
imgInfo.rowPitch = 512u;
|
||||
|
||||
auto queryGmm = MockGmm::queryImgParams(imgInfo);
|
||||
auto allocation = memoryManager->allocateGraphicsMemoryForImage(imgInfo, queryGmm.get());
|
||||
queryGmm.release();
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
EXPECT_EQ(nullptr, allocation->getUnderlyingBuffer());
|
||||
|
||||
auto ptr = memoryManager->lockResource(allocation);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
|
||||
auto drmAllocation = (DrmAllocation *)allocation;
|
||||
EXPECT_NE(nullptr, drmAllocation->getBO()->peekLockedAddress());
|
||||
|
||||
//check DRM_IOCTL_I915_GEM_MMAP input params
|
||||
EXPECT_EQ((uint32_t)drmAllocation->getBO()->peekHandle(), mock->mmapHandle);
|
||||
EXPECT_EQ(0u, mock->mmapPad);
|
||||
EXPECT_EQ(0u, mock->mmapOffset);
|
||||
EXPECT_EQ(drmAllocation->getBO()->peekSize(), mock->mmapSize);
|
||||
EXPECT_EQ(0u, mock->mmapFlags);
|
||||
|
||||
//check DRM_IOCTL_I915_GEM_SET_DOMAIN input params
|
||||
EXPECT_EQ((uint32_t)drmAllocation->getBO()->peekHandle(), mock->setDomainHandle);
|
||||
EXPECT_EQ((uint32_t)I915_GEM_DOMAIN_CPU, mock->setDomainReadDomains);
|
||||
EXPECT_EQ(0u, mock->setDomainWriteDomain);
|
||||
|
||||
memoryManager->unlockResource(allocation);
|
||||
EXPECT_EQ(nullptr, drmAllocation->getBO()->peekLockedAddress());
|
||||
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnNullAllocationThenReturnNullPtr) {
|
||||
GraphicsAllocation *allocation = nullptr;
|
||||
|
||||
auto ptr = memoryManager->lockResource(allocation);
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
|
||||
memoryManager->unlockResource(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAllocationWithoutBufferObjectThenReturnNullPtr) {
|
||||
DrmAllocation drmAllocation(nullptr, nullptr, 0u, 0u);
|
||||
EXPECT_EQ(nullptr, drmAllocation.getBO());
|
||||
|
||||
auto ptr = memoryManager->lockResource(&drmAllocation);
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
|
||||
memoryManager->unlockResource(&drmAllocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledButFailsOnIoctlMmapThenReturnNullPtr) {
|
||||
mock->ioctl_expected = 1;
|
||||
this->ioctlResExt = {0, -1};
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
|
||||
DrmMockCustom drmMock;
|
||||
struct BufferObjectMock : public BufferObject {
|
||||
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, true) {}
|
||||
};
|
||||
BufferObjectMock bo(&drmMock);
|
||||
DrmAllocation drmAllocation(&bo, nullptr, 0u, 0u);
|
||||
EXPECT_NE(nullptr, drmAllocation.getBO());
|
||||
|
||||
auto ptr = memoryManager->lockResource(&drmAllocation);
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
|
||||
memoryManager->unlockResource(&drmAllocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledOnAllocationWithoutBufferObjectThenReturnFalse) {
|
||||
DrmAllocation drmAllocation(nullptr, nullptr, 0u, 0u);
|
||||
EXPECT_EQ(nullptr, drmAllocation.getBO());
|
||||
|
||||
auto success = memoryManager->setDomainCpu(drmAllocation, false);
|
||||
EXPECT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledButFailsOnIoctlSetDomainThenReturnFalse) {
|
||||
mock->ioctl_expected = 1;
|
||||
this->ioctlResExt = {0, -1};
|
||||
mock->ioctl_res_ext = &ioctlResExt;
|
||||
|
||||
DrmMockCustom drmMock;
|
||||
struct BufferObjectMock : public BufferObject {
|
||||
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, true) {}
|
||||
};
|
||||
BufferObjectMock bo(&drmMock);
|
||||
DrmAllocation drmAllocation(&bo, nullptr, 0u, 0u);
|
||||
EXPECT_NE(nullptr, drmAllocation.getBO());
|
||||
|
||||
auto success = memoryManager->setDomainCpu(drmAllocation, false);
|
||||
EXPECT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledOnAllocationThenReturnSetWriteDomain) {
|
||||
mock->ioctl_expected = 1;
|
||||
|
||||
DrmMockCustom drmMock;
|
||||
struct BufferObjectMock : public BufferObject {
|
||||
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, true) {}
|
||||
};
|
||||
BufferObjectMock bo(&drmMock);
|
||||
DrmAllocation drmAllocation(&bo, nullptr, 0u, 0u);
|
||||
EXPECT_NE(nullptr, drmAllocation.getBO());
|
||||
|
||||
auto success = memoryManager->setDomainCpu(drmAllocation, true);
|
||||
EXPECT_TRUE(success);
|
||||
|
||||
//check DRM_IOCTL_I915_GEM_SET_DOMAIN input params
|
||||
EXPECT_EQ((uint32_t)drmAllocation.getBO()->peekHandle(), mock->setDomainHandle);
|
||||
EXPECT_EQ((uint32_t)I915_GEM_DOMAIN_CPU, mock->setDomainReadDomains);
|
||||
EXPECT_EQ((uint32_t)I915_GEM_DOMAIN_CPU, mock->setDomainWriteDomain);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) {
|
||||
mock->ioctl_expected = 3;
|
||||
auto gmm = Gmm::create(nullptr, 123, false);
|
||||
|
||||
Reference in New Issue
Block a user