mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 04:12:57 +08:00
Add support for multiple buffer objects in drm allocation
Resolves: NEO-3364 Change-Id: I05e8b9a05328298dcc578d62b2aa7b56ffbf4ddc Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.inl"
|
||||
#include "runtime/os_interface/linux/device_command_stream.inl"
|
||||
#include "runtime/os_interface/linux/drm_command_stream.inl"
|
||||
#include "runtime/os_interface/linux/drm_command_stream_bdw_plus.inl"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.inl"
|
||||
#include "runtime/os_interface/linux/device_command_stream.inl"
|
||||
#include "runtime/os_interface/linux/drm_command_stream.inl"
|
||||
#include "runtime/os_interface/linux/drm_command_stream_bdw_plus.inl"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.inl"
|
||||
#include "runtime/os_interface/linux/device_command_stream.inl"
|
||||
#include "runtime/os_interface/linux/drm_command_stream.inl"
|
||||
#include "runtime/os_interface/linux/drm_command_stream_bdw_plus.inl"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_bdw_plus.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_engine_mapper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_engine_mapper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker.cpp
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
namespace NEO {
|
||||
std::string DrmAllocation::getAllocationInfoString() const {
|
||||
std::stringstream ss;
|
||||
for (auto bo : bufferObjects) {
|
||||
if (bo != nullptr) {
|
||||
ss << " Handle: " << bo->peekHandle();
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,23 @@ struct OsHandle {
|
||||
BufferObject *bo = nullptr;
|
||||
};
|
||||
|
||||
using BufferObjects = std::array<BufferObject *, maxHandleCount>;
|
||||
|
||||
class DrmAllocation : public GraphicsAllocation {
|
||||
public:
|
||||
DrmAllocation(AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable)
|
||||
: GraphicsAllocation(allocationType, ptrIn, sizeIn, sharedHandle, pool, multiOsContextCapable),
|
||||
bo(bo) {
|
||||
bufferObjects({bo}) {
|
||||
}
|
||||
|
||||
DrmAllocation(AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable)
|
||||
: GraphicsAllocation(allocationType, ptrIn, gpuAddress, 0, sizeIn, pool, multiOsContextCapable),
|
||||
bo(bo) {
|
||||
bufferObjects({bo}) {
|
||||
}
|
||||
|
||||
DrmAllocation(AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool, bool multiOsContextCapable)
|
||||
: GraphicsAllocation(allocationType, ptrIn, gpuAddress, 0, sizeIn, pool, multiOsContextCapable),
|
||||
bufferObjects(bos) {
|
||||
}
|
||||
|
||||
std::string getAllocationInfoString() const override;
|
||||
@@ -33,11 +40,18 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
if (fragmentsStorage.fragmentCount) {
|
||||
return fragmentsStorage.fragmentStorageData[0].osHandleStorage->bo;
|
||||
}
|
||||
return this->bo;
|
||||
return this->bufferObjects[0];
|
||||
}
|
||||
const BufferObjects &getBOs() const {
|
||||
return this->bufferObjects;
|
||||
}
|
||||
BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
||||
return bufferObjects[handleIndex];
|
||||
}
|
||||
|
||||
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
|
||||
|
||||
protected:
|
||||
BufferObject *bo;
|
||||
BufferObjects bufferObjects{};
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -35,6 +35,10 @@ BufferObject::BufferObject(Drm *drm, int handle) : drm(drm), refCount(1), handle
|
||||
this->lockedAddress = nullptr;
|
||||
}
|
||||
|
||||
BufferObject::BufferObject(Drm *drm, int handle, size_t size) : BufferObject(drm, handle) {
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
uint32_t BufferObject::getRefCount() const {
|
||||
return this->refCount.load();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class BufferObject {
|
||||
|
||||
public:
|
||||
BufferObject(Drm *drm, int handle);
|
||||
BufferObject(Drm *drm, int handle, size_t size);
|
||||
MOCKABLE_VIRTUAL ~BufferObject(){};
|
||||
|
||||
bool setTiling(uint32_t mode, uint32_t stride);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
namespace NEO {
|
||||
class BufferObject;
|
||||
class Drm;
|
||||
class DrmAllocation;
|
||||
class DrmMemoryManager;
|
||||
|
||||
template <typename GfxFamily>
|
||||
@@ -49,6 +50,7 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver<GfxFamily> {
|
||||
}
|
||||
|
||||
protected:
|
||||
void makeResidentBufferObjects(const DrmAllocation *drmAllocation);
|
||||
void makeResident(BufferObject *bo);
|
||||
|
||||
std::vector<BufferObject *> residency;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "runtime/gmm_helper/gmm_helper.h"
|
||||
#include "runtime/helpers/preamble.h"
|
||||
#include "runtime/mem_obj/buffer.h"
|
||||
#include "runtime/os_interface/linux/drm_allocation.h"
|
||||
#include "runtime/os_interface/linux/drm_buffer_object.h"
|
||||
#include "runtime/os_interface/linux/drm_command_stream.h"
|
||||
#include "runtime/os_interface/linux/drm_engine_mapper.h"
|
||||
@@ -120,8 +121,7 @@ void DrmCommandStreamReceiver<GfxFamily>::processResidency(const ResidencyContai
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BufferObject *bo = drmAlloc->getBO();
|
||||
makeResident(bo);
|
||||
makeResidentBufferObjects(drmAlloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
runtime/os_interface/linux/drm_command_stream_bdw_plus.inl
Normal file
17
runtime/os_interface/linux/drm_command_stream_bdw_plus.inl
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/linux/drm_allocation.h"
|
||||
#include "runtime/os_interface/linux/drm_command_stream.h"
|
||||
|
||||
namespace NEO {
|
||||
template <typename GfxFamily>
|
||||
void DrmCommandStreamReceiver<GfxFamily>::makeResidentBufferObjects(const DrmAllocation *drmAllocation) {
|
||||
auto bo = drmAllocation->getBO();
|
||||
makeResident(bo);
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -510,8 +510,10 @@ void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation)
|
||||
if (gfxAllocation->fragmentsStorage.fragmentCount) {
|
||||
cleanGraphicsMemoryCreatedFromHostPtr(gfxAllocation);
|
||||
} else {
|
||||
auto bo = static_cast<DrmAllocation *>(gfxAllocation)->getBO();
|
||||
unreference(bo, bo->isReused ? false : true);
|
||||
auto &bos = static_cast<DrmAllocation *>(gfxAllocation)->getBOs();
|
||||
for (auto bo : bos) {
|
||||
unreference(bo, bo && bo->isReused ? false : true);
|
||||
}
|
||||
if (gfxAllocation->peekSharedHandle() != Sharing::nonSharedResource) {
|
||||
closeFunction(gfxAllocation->peekSharedHandle());
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ class DrmMemoryManager : public MemoryManager {
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
void *lockResourceInLocalMemoryImpl(GraphicsAllocation &graphicsAllocation);
|
||||
MOCKABLE_VIRTUAL void *lockResourceInLocalMemoryImpl(BufferObject *bo);
|
||||
MOCKABLE_VIRTUAL void unlockResourceInLocalMemoryImpl(BufferObject *bo);
|
||||
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
|
||||
@@ -18,6 +18,13 @@ void *DrmMemoryManager::lockResourceInLocalMemoryImpl(GraphicsAllocation &graphi
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::unlockResourceInLocalMemoryImpl(BufferObject *bo) {
|
||||
}
|
||||
|
||||
bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) {
|
||||
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, memoryToCopy, sizeToCopy);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/os_interface/os_context.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -21,7 +21,7 @@ class MockBufferObject : public BufferObject {
|
||||
|
||||
class MockDrmAllocation : public DrmAllocation {
|
||||
public:
|
||||
using DrmAllocation::bo;
|
||||
using DrmAllocation::bufferObjects;
|
||||
using DrmAllocation::memoryPool;
|
||||
|
||||
MockDrmAllocation(AllocationType allocationType, MemoryPool::Type pool) : DrmAllocation(allocationType, nullptr, nullptr, 0, static_cast<size_t>(0), pool, false) {
|
||||
|
||||
@@ -5,10 +5,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
template <typename GfxFamily>
|
||||
class TestedDrmCommandStreamReceiver : public DrmCommandStreamReceiver<GfxFamily> {
|
||||
public:
|
||||
using CommandStreamReceiver::commandStream;
|
||||
using DrmCommandStreamReceiver<GfxFamily>::makeResidentBufferObjects;
|
||||
using DrmCommandStreamReceiver<GfxFamily>::residency;
|
||||
|
||||
TestedDrmCommandStreamReceiver(gemCloseWorkerMode mode, ExecutionEnvironment &executionEnvironment)
|
||||
|
||||
@@ -37,13 +37,16 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
|
||||
using DrmMemoryManager::AllocationData;
|
||||
using DrmMemoryManager::allocUserptr;
|
||||
using DrmMemoryManager::createGraphicsAllocation;
|
||||
using DrmMemoryManager::drm;
|
||||
using DrmMemoryManager::getDefaultDrmContextId;
|
||||
using DrmMemoryManager::gfxPartition;
|
||||
using DrmMemoryManager::lockResourceInLocalMemoryImpl;
|
||||
using DrmMemoryManager::pinThreshold;
|
||||
using DrmMemoryManager::releaseGpuRange;
|
||||
using DrmMemoryManager::setDomainCpu;
|
||||
using DrmMemoryManager::sharingBufferObjects;
|
||||
using DrmMemoryManager::supportsMultiStorageResources;
|
||||
using DrmMemoryManager::unlockResourceInLocalMemoryImpl;
|
||||
using MemoryManager::allocateGraphicsMemoryInDevicePool;
|
||||
using MemoryManager::useInternal32BitAllocator;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ TEST(DebugSettingsManager, GivenDebugSettingsManagerWithLogAllocationsThenLogsCo
|
||||
MockBufferObject bo;
|
||||
bo.handle = 4;
|
||||
|
||||
allocation.bo = &bo;
|
||||
allocation.bufferObjects[0] = &bo;
|
||||
|
||||
debugManager.logAllocation(&allocation);
|
||||
|
||||
|
||||
@@ -159,6 +159,13 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
|
||||
EXPECT_EQ(EFAULT, ret);
|
||||
}
|
||||
|
||||
TEST(DrmBufferObjectSimpleTest, givenBufferObjectWhenConstructedWithASizeThenTheSizeIsInitialized) {
|
||||
std::unique_ptr<DrmMockCustom> drmMock(new DrmMockCustom);
|
||||
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000));
|
||||
|
||||
EXPECT_EQ(0x1000u, bo->peekSize());
|
||||
}
|
||||
|
||||
TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
|
||||
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom);
|
||||
|
||||
145
unit_tests/os_interface/linux/drm_command_stream_fixture.h
Normal file
145
unit_tests/os_interface/linux/drm_command_stream_fixture.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
|
||||
#include "runtime/command_stream/preemption.h"
|
||||
#include "runtime/os_interface/linux/drm_command_stream.h"
|
||||
#include "runtime/os_interface/linux/os_context_linux.h"
|
||||
#include "runtime/os_interface/linux/os_interface.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "unit_tests/mocks/linux/mock_drm_command_stream_receiver.h"
|
||||
#include "unit_tests/os_interface/linux/device_command_stream_fixture.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
class DrmCommandStreamFixture {
|
||||
public:
|
||||
void SetUp() {
|
||||
|
||||
//make sure this is disabled, we don't want to test this now
|
||||
DebugManager.flags.EnableForcePin.set(false);
|
||||
|
||||
mock = std::make_unique<::testing::NiceMock<DrmMockImpl>>(mockFd);
|
||||
|
||||
executionEnvironment.setHwInfo(*platformDevices);
|
||||
executionEnvironment.osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment.osInterface->get()->setDrm(mock.get());
|
||||
|
||||
osContext = std::make_unique<OsContextLinux>(*mock, 0u, 1, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0],
|
||||
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
|
||||
|
||||
csr = new DrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(executionEnvironment, gemCloseWorkerMode::gemCloseWorkerActive);
|
||||
ASSERT_NE(nullptr, csr);
|
||||
executionEnvironment.commandStreamReceivers.resize(1);
|
||||
executionEnvironment.commandStreamReceivers[0].push_back(std::unique_ptr<CommandStreamReceiver>(csr));
|
||||
csr->setupContext(*osContext);
|
||||
|
||||
// Memory manager creates pinBB with ioctl, expect one call
|
||||
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
|
||||
.Times(1);
|
||||
memoryManager = new DrmMemoryManager(gemCloseWorkerActive,
|
||||
DebugManager.flags.EnableForcePin.get(),
|
||||
true,
|
||||
executionEnvironment);
|
||||
executionEnvironment.memoryManager.reset(memoryManager);
|
||||
::testing::Mock::VerifyAndClearExpectations(mock.get());
|
||||
|
||||
//assert we have memory manager
|
||||
ASSERT_NE(nullptr, memoryManager);
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
memoryManager->waitForDeletions();
|
||||
memoryManager->peekGemCloseWorker()->close(true);
|
||||
executionEnvironment.commandStreamReceivers.clear();
|
||||
::testing::Mock::VerifyAndClearExpectations(mock.get());
|
||||
// Memory manager closes pinBB with ioctl, expect one call
|
||||
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
|
||||
.Times(::testing::AtLeast(1));
|
||||
}
|
||||
|
||||
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
|
||||
DrmMemoryManager *memoryManager = nullptr;
|
||||
std::unique_ptr<::testing::NiceMock<DrmMockImpl>> mock;
|
||||
const int mockFd = 33;
|
||||
static const uint64_t alignment = MemoryConstants::allocationAlignment;
|
||||
DebugManagerStateRestore dbgState;
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
std::unique_ptr<OsContextLinux> osContext;
|
||||
};
|
||||
|
||||
class DrmCommandStreamEnhancedFixture {
|
||||
public:
|
||||
std::unique_ptr<DebugManagerStateRestore> dbgState;
|
||||
ExecutionEnvironment *executionEnvironment;
|
||||
std::unique_ptr<DrmMockCustom> mock;
|
||||
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
|
||||
|
||||
DrmMemoryManager *mm = nullptr;
|
||||
std::unique_ptr<MockDevice> device;
|
||||
|
||||
virtual void SetUp() {
|
||||
executionEnvironment = new ExecutionEnvironment;
|
||||
executionEnvironment->incRefInternal();
|
||||
executionEnvironment->setHwInfo(*platformDevices);
|
||||
executionEnvironment->initGmm();
|
||||
this->dbgState = std::make_unique<DebugManagerStateRestore>();
|
||||
//make sure this is disabled, we don't want to test this now
|
||||
DebugManager.flags.EnableForcePin.set(false);
|
||||
|
||||
mock = std::make_unique<DrmMockCustom>();
|
||||
executionEnvironment->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->osInterface->get()->setDrm(mock.get());
|
||||
|
||||
tCsr = new TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
|
||||
csr = tCsr;
|
||||
ASSERT_NE(nullptr, csr);
|
||||
mm = new DrmMemoryManager(gemCloseWorkerInactive,
|
||||
DebugManager.flags.EnableForcePin.get(),
|
||||
true,
|
||||
*executionEnvironment);
|
||||
ASSERT_NE(nullptr, mm);
|
||||
executionEnvironment->memoryManager.reset(mm);
|
||||
device.reset(MockDevice::create<MockDevice>(executionEnvironment, 0u));
|
||||
device->resetCommandStreamReceiver(tCsr);
|
||||
ASSERT_NE(nullptr, device);
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
executionEnvironment->decRefInternal();
|
||||
}
|
||||
|
||||
void makeResidentBufferObjects(const DrmAllocation *drmAllocation) {
|
||||
tCsr->makeResidentBufferObjects(drmAllocation);
|
||||
}
|
||||
|
||||
bool isResident(BufferObject *bo) {
|
||||
return tCsr->isResident(bo);
|
||||
}
|
||||
|
||||
const BufferObject *getResident(BufferObject *bo) {
|
||||
return tCsr->getResident(bo);
|
||||
}
|
||||
|
||||
protected:
|
||||
TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *tCsr = nullptr;
|
||||
|
||||
class MockBufferObject : public BufferObject {
|
||||
friend DrmCommandStreamEnhancedFixture;
|
||||
|
||||
protected:
|
||||
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1) {
|
||||
this->size = alignUp(size, 4096);
|
||||
}
|
||||
};
|
||||
|
||||
MockBufferObject *createBO(size_t size) {
|
||||
return new MockBufferObject(this->mock.get(), size);
|
||||
}
|
||||
};
|
||||
@@ -24,70 +24,13 @@
|
||||
#include "unit_tests/mocks/mock_host_ptr_manager.h"
|
||||
#include "unit_tests/mocks/mock_program.h"
|
||||
#include "unit_tests/mocks/mock_submissions_aggregator.h"
|
||||
#include "unit_tests/os_interface/linux/device_command_stream_fixture.h"
|
||||
#include "unit_tests/os_interface/linux/drm_command_stream_fixture.h"
|
||||
|
||||
#include "drm/i915_drm.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
class DrmCommandStreamFixture {
|
||||
public:
|
||||
void SetUp() {
|
||||
|
||||
//make sure this is disabled, we don't want test this now
|
||||
DebugManager.flags.EnableForcePin.set(false);
|
||||
|
||||
mock = std::make_unique<::testing::NiceMock<DrmMockImpl>>(mockFd);
|
||||
|
||||
executionEnvironment.setHwInfo(*platformDevices);
|
||||
executionEnvironment.osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment.osInterface->get()->setDrm(mock.get());
|
||||
executionEnvironment.memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandler>();
|
||||
|
||||
osContext = std::make_unique<OsContextLinux>(*mock, 0u, 1, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0],
|
||||
PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false);
|
||||
|
||||
csr = new DrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(executionEnvironment, gemCloseWorkerMode::gemCloseWorkerActive);
|
||||
ASSERT_NE(nullptr, csr);
|
||||
executionEnvironment.commandStreamReceivers.resize(1);
|
||||
executionEnvironment.commandStreamReceivers[0].push_back(std::unique_ptr<CommandStreamReceiver>(csr));
|
||||
csr->setupContext(*osContext);
|
||||
|
||||
// Memory manager creates pinBB with ioctl, expect one call
|
||||
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
|
||||
.Times(1);
|
||||
memoryManager = new DrmMemoryManager(gemCloseWorkerActive,
|
||||
DebugManager.flags.EnableForcePin.get(),
|
||||
true,
|
||||
executionEnvironment);
|
||||
executionEnvironment.memoryManager.reset(memoryManager);
|
||||
::testing::Mock::VerifyAndClearExpectations(mock.get());
|
||||
|
||||
//assert we have memory manager
|
||||
ASSERT_NE(nullptr, memoryManager);
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
memoryManager->waitForDeletions();
|
||||
memoryManager->peekGemCloseWorker()->close(true);
|
||||
executionEnvironment.commandStreamReceivers.clear();
|
||||
::testing::Mock::VerifyAndClearExpectations(mock.get());
|
||||
// Memory manager closes pinBB with ioctl, expect one call
|
||||
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
|
||||
.Times(::testing::AtLeast(1));
|
||||
}
|
||||
|
||||
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
|
||||
DrmMemoryManager *memoryManager = nullptr;
|
||||
std::unique_ptr<::testing::NiceMock<DrmMockImpl>> mock;
|
||||
const int mockFd = 33;
|
||||
static const uint64_t alignment = MemoryConstants::allocationAlignment;
|
||||
DebugManagerStateRestore dbgState;
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
std::unique_ptr<OsContextLinux> osContext;
|
||||
};
|
||||
|
||||
typedef Test<DrmCommandStreamFixture> DrmCommandStreamTest;
|
||||
|
||||
ACTION_P(copyIoctlParam, dstValue) {
|
||||
@@ -550,77 +493,6 @@ TEST_F(DrmCommandStreamTest, CheckDrmFreeCloseFailed) {
|
||||
csr->flush(batchBuffer, csr->getResidencyAllocations());
|
||||
}
|
||||
|
||||
/* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
|
||||
* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
|
||||
* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
|
||||
class DrmCommandStreamEnhancedFixture
|
||||
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<DebugManagerStateRestore> dbgState;
|
||||
ExecutionEnvironment *executionEnvironment;
|
||||
std::unique_ptr<DrmMockCustom> mock;
|
||||
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
|
||||
|
||||
DrmMemoryManager *mm = nullptr;
|
||||
std::unique_ptr<MockDevice> device;
|
||||
|
||||
virtual void SetUp() {
|
||||
executionEnvironment = new ExecutionEnvironment;
|
||||
executionEnvironment->incRefInternal();
|
||||
executionEnvironment->setHwInfo(*platformDevices);
|
||||
executionEnvironment->initGmm();
|
||||
this->dbgState = std::make_unique<DebugManagerStateRestore>();
|
||||
//make sure this is disabled, we don't want test this now
|
||||
DebugManager.flags.EnableForcePin.set(false);
|
||||
|
||||
mock = std::make_unique<DrmMockCustom>();
|
||||
executionEnvironment->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->osInterface->get()->setDrm(mock.get());
|
||||
|
||||
tCsr = new TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
|
||||
csr = tCsr;
|
||||
ASSERT_NE(nullptr, csr);
|
||||
mm = new DrmMemoryManager(gemCloseWorkerInactive,
|
||||
DebugManager.flags.EnableForcePin.get(),
|
||||
true,
|
||||
*executionEnvironment);
|
||||
ASSERT_NE(nullptr, mm);
|
||||
executionEnvironment->memoryManager.reset(mm);
|
||||
device.reset(MockDevice::create<MockDevice>(executionEnvironment, 0u));
|
||||
device->resetCommandStreamReceiver(tCsr);
|
||||
ASSERT_NE(nullptr, device);
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
executionEnvironment->decRefInternal();
|
||||
}
|
||||
|
||||
bool isResident(BufferObject *bo) {
|
||||
return tCsr->isResident(bo);
|
||||
}
|
||||
|
||||
const BufferObject *getResident(BufferObject *bo) {
|
||||
return tCsr->getResident(bo);
|
||||
}
|
||||
|
||||
protected:
|
||||
TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *tCsr = nullptr;
|
||||
|
||||
class MockBufferObject : public BufferObject {
|
||||
friend DrmCommandStreamEnhancedFixture;
|
||||
|
||||
protected:
|
||||
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1) {
|
||||
this->size = alignUp(size, 4096);
|
||||
}
|
||||
};
|
||||
|
||||
MockBufferObject *createBO(size_t size) {
|
||||
return new MockBufferObject(this->mock.get(), size);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Test<DrmCommandStreamEnhancedFixture> DrmCommandStreamGemWorkerTests;
|
||||
|
||||
TEST_F(DrmCommandStreamGemWorkerTests, givenDefaultDrmCSRWhenItIsCreatedThenGemCloseWorkerModeIsInactive) {
|
||||
@@ -933,6 +805,26 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte
|
||||
|
||||
typedef Test<DrmCommandStreamEnhancedFixture> DrmCommandStreamLeaksTest;
|
||||
|
||||
TEST_F(DrmCommandStreamLeaksTest, givenDrmAllocationWhenGetBufferObjectToModifyIsCalledForAGivenHandleIdThenTheCorrespondingBufferObjectGetsModified) {
|
||||
auto size = 1024u;
|
||||
auto allocation = new DrmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, size, MemoryPool::MemoryNull, 1u, false);
|
||||
|
||||
auto &bos = allocation->getBOs();
|
||||
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) {
|
||||
EXPECT_EQ(nullptr, bos[handleId]);
|
||||
}
|
||||
|
||||
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) {
|
||||
allocation->getBufferObjectToModify(handleId) = this->createBO(size);
|
||||
}
|
||||
|
||||
for (auto handleId = 0u; handleId < maxHandleCount; handleId++) {
|
||||
EXPECT_NE(nullptr, bos[handleId]);
|
||||
}
|
||||
|
||||
mm->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmCommandStreamLeaksTest, makeResident) {
|
||||
auto buffer = this->createBO(1024);
|
||||
auto allocation = new DrmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, buffer, nullptr, buffer->peekSize(), MemoryPool::MemoryNull, 1u, false);
|
||||
@@ -1541,3 +1433,20 @@ TEST_F(DrmCommandStreamTest, givenDrmCommandStreamWhenGettingMocsThenProperValue
|
||||
expectedMocs = GmmHelper::cacheEnabledIndex;
|
||||
EXPECT_EQ(mocs, expectedMocs);
|
||||
}
|
||||
|
||||
typedef Test<DrmCommandStreamEnhancedFixture> DrmCommandStreamHwTest;
|
||||
|
||||
HWTEST_F(DrmCommandStreamHwTest, givenAllocationWithSingleBufferObjectWhenMakeResidentBufferObjectsIsCalledThenTheBufferObjectIsMadeResident) {
|
||||
TestedDrmCommandStreamReceiver<FamilyType> csrHw(gemCloseWorkerMode::gemCloseWorkerInactive, *executionEnvironment);
|
||||
|
||||
auto size = 1024u;
|
||||
auto bo = this->createBO(size);
|
||||
BufferObjects bos{bo};
|
||||
auto allocation = new DrmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, bos, nullptr, 0u, size, MemoryPool::LocalMemory, false);
|
||||
EXPECT_EQ(bo, allocation->getBO());
|
||||
|
||||
csrHw.makeResidentBufferObjects(allocation);
|
||||
EXPECT_TRUE(csrHw.isResident(bo));
|
||||
|
||||
mm->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,29 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIs
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status);
|
||||
}
|
||||
|
||||
TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) {
|
||||
MockExecutionEnvironment executionEnvironment(*platformDevices);
|
||||
executionEnvironment.osInterface = std::make_unique<OSInterface>();
|
||||
TestedDrmMemoryManager memoryManager(executionEnvironment);
|
||||
DrmAllocation drmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory, false);
|
||||
|
||||
auto ptr = memoryManager.lockResourceInLocalMemoryImpl(drmAllocation.getBO());
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
|
||||
memoryManager.unlockResourceInLocalMemoryImpl(drmAllocation.getBO());
|
||||
}
|
||||
|
||||
TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) {
|
||||
MockExecutionEnvironment executionEnvironment(*platformDevices);
|
||||
executionEnvironment.osInterface = std::make_unique<OSInterface>();
|
||||
TestedDrmMemoryManager memoryManager(executionEnvironment);
|
||||
|
||||
auto drmAllocation = new DrmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory, false);
|
||||
EXPECT_NE(nullptr, drmAllocation);
|
||||
|
||||
memoryManager.freeGraphicsMemoryImpl(drmAllocation);
|
||||
}
|
||||
|
||||
using DrmMemoryManagerWithLocalMemoryTest = Test<DrmMemoryManagerWithLocalMemoryFixture>;
|
||||
|
||||
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnAllocationInLocalMemoryThenReturnNullPtr) {
|
||||
|
||||
@@ -3090,9 +3090,9 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn
|
||||
|
||||
{
|
||||
::testing::InSequence inSequence;
|
||||
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true));
|
||||
EXPECT_CALL(gmockDrmMemoryManager, releaseGpuRange(::testing::_, ::testing::_));
|
||||
EXPECT_CALL(gmockDrmMemoryManager, alignedFreeWrapper(::testing::_));
|
||||
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true)).Times(maxHandleCount);
|
||||
EXPECT_CALL(gmockDrmMemoryManager, releaseGpuRange(::testing::_, ::testing::_)).Times(1);
|
||||
EXPECT_CALL(gmockDrmMemoryManager, alignedFreeWrapper(::testing::_)).Times(1);
|
||||
}
|
||||
|
||||
gmockDrmMemoryManager.freeGraphicsMemory(allocation);
|
||||
@@ -3109,7 +3109,8 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd
|
||||
auto allocation = gmockDrmMemoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, false);
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
|
||||
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, false));
|
||||
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, false)).Times(1);
|
||||
EXPECT_CALL(gmockDrmMemoryManager, unreference(::testing::_, true)).Times(maxHandleCount - 1);
|
||||
|
||||
gmockDrmMemoryManager.freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user