2018-08-01 20:47:14 +08:00
|
|
|
/*
|
2020-01-07 14:42:40 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-08-01 20:47:14 +08:00
|
|
|
|
2019-03-13 06:24:30 +08:00
|
|
|
#pragma once
|
2019-06-25 22:13:45 +08:00
|
|
|
#include "runtime/os_interface/linux/allocator_helper.h"
|
2018-08-01 20:47:14 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_memory_manager.h"
|
2018-12-21 17:16:27 +08:00
|
|
|
#include "unit_tests/mocks/mock_allocation_properties.h"
|
2018-10-24 14:46:54 +08:00
|
|
|
#include "unit_tests/mocks/mock_host_ptr_manager.h"
|
2019-03-15 17:22:35 +08:00
|
|
|
#include "unit_tests/mocks/mock_memory_manager.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-11-15 22:11:14 +08:00
|
|
|
#include <atomic>
|
2018-08-01 20:47:14 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-08-01 20:47:14 +08:00
|
|
|
static off_t lseekReturn = 4096u;
|
2018-11-15 22:11:14 +08:00
|
|
|
static std::atomic<int> lseekCalledCount(0);
|
2018-08-01 20:47:14 +08:00
|
|
|
|
2019-02-27 04:12:26 +08:00
|
|
|
inline off_t lseekMock(int fd, off_t offset, int whence) noexcept {
|
2018-08-01 20:47:14 +08:00
|
|
|
lseekCalledCount++;
|
|
|
|
return lseekReturn;
|
|
|
|
}
|
2019-02-27 04:12:26 +08:00
|
|
|
inline int closeMock(int) {
|
2018-08-01 20:47:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-15 17:22:35 +08:00
|
|
|
class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
|
2018-08-01 20:47:14 +08:00
|
|
|
public:
|
2018-12-12 01:56:37 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemory;
|
2018-12-06 22:03:06 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemory64kb;
|
2019-01-22 19:40:17 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemoryForImage;
|
2019-03-12 19:00:41 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr;
|
2019-02-08 03:29:30 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemoryWithAlignment;
|
2018-11-30 18:01:33 +08:00
|
|
|
using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr;
|
2019-11-14 17:08:59 +08:00
|
|
|
using DrmMemoryManager::allocateShareableMemory;
|
2018-12-06 22:03:06 +08:00
|
|
|
using DrmMemoryManager::AllocationData;
|
2018-08-01 20:47:14 +08:00
|
|
|
using DrmMemoryManager::allocUserptr;
|
2019-02-25 21:11:34 +08:00
|
|
|
using DrmMemoryManager::createGraphicsAllocation;
|
2019-07-17 21:38:14 +08:00
|
|
|
using DrmMemoryManager::getDefaultDrmContextId;
|
2020-01-07 14:42:40 +08:00
|
|
|
using DrmMemoryManager::getDrm;
|
2019-10-22 16:26:23 +08:00
|
|
|
using DrmMemoryManager::gfxPartitions;
|
2019-09-02 03:36:15 +08:00
|
|
|
using DrmMemoryManager::lockResourceInLocalMemoryImpl;
|
2018-12-21 18:52:46 +08:00
|
|
|
using DrmMemoryManager::pinThreshold;
|
2019-07-29 23:50:46 +08:00
|
|
|
using DrmMemoryManager::releaseGpuRange;
|
2018-08-01 20:47:14 +08:00
|
|
|
using DrmMemoryManager::setDomainCpu;
|
|
|
|
using DrmMemoryManager::sharingBufferObjects;
|
2019-06-06 14:45:14 +08:00
|
|
|
using DrmMemoryManager::supportsMultiStorageResources;
|
2019-09-02 03:36:15 +08:00
|
|
|
using DrmMemoryManager::unlockResourceInLocalMemoryImpl;
|
2019-01-22 19:40:17 +08:00
|
|
|
using MemoryManager::allocateGraphicsMemoryInDevicePool;
|
2019-10-22 19:29:39 +08:00
|
|
|
using MemoryManager::registeredEngines;
|
2019-07-18 05:31:38 +08:00
|
|
|
using MemoryManager::useInternal32BitAllocator;
|
2018-08-01 20:47:14 +08:00
|
|
|
|
2019-03-25 20:12:55 +08:00
|
|
|
TestedDrmMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(gemCloseWorkerMode::gemCloseWorkerInactive,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
executionEnvironment) {
|
2018-08-01 20:47:14 +08:00
|
|
|
this->lseekFunction = &lseekMock;
|
|
|
|
this->closeFunction = &closeMock;
|
|
|
|
lseekReturn = 4096;
|
|
|
|
lseekCalledCount = 0;
|
2018-10-24 14:46:54 +08:00
|
|
|
hostPtrManager.reset(new MockHostPtrManager);
|
2018-08-01 20:47:14 +08:00
|
|
|
};
|
2019-08-27 21:33:58 +08:00
|
|
|
|
2019-03-25 20:12:55 +08:00
|
|
|
TestedDrmMemoryManager(bool enableLocalMemory,
|
2019-03-12 06:06:30 +08:00
|
|
|
bool allowForcePin,
|
|
|
|
bool validateHostPtrMemory,
|
2019-03-25 20:12:55 +08:00
|
|
|
ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, enableLocalMemory,
|
2019-03-15 17:22:35 +08:00
|
|
|
gemCloseWorkerMode::gemCloseWorkerInactive,
|
|
|
|
allowForcePin,
|
|
|
|
validateHostPtrMemory,
|
|
|
|
executionEnvironment) {
|
2018-08-01 20:47:14 +08:00
|
|
|
this->lseekFunction = &lseekMock;
|
|
|
|
this->closeFunction = &closeMock;
|
|
|
|
lseekReturn = 4096;
|
|
|
|
lseekCalledCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void injectPinBB(BufferObject *newPinBB) {
|
|
|
|
BufferObject *currentPinBB = pinBB;
|
|
|
|
pinBB = nullptr;
|
2019-08-27 21:33:58 +08:00
|
|
|
DrmMemoryManager::unreference(currentPinBB, true);
|
2018-08-01 20:47:14 +08:00
|
|
|
pinBB = newPinBB;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmGemCloseWorker *getgemCloseWorker() { return this->gemCloseWorker.get(); }
|
2019-10-22 16:26:23 +08:00
|
|
|
void forceLimitedRangeAllocator(uint64_t range) { getGfxPartition(0)->init(range, getSizeToReserve(), 0); }
|
|
|
|
void overrideGfxPartition(GfxPartition *newGfxPartition) { gfxPartitions[0].reset(newGfxPartition); }
|
2018-08-01 20:47:14 +08:00
|
|
|
|
2019-02-21 23:29:05 +08:00
|
|
|
DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) {
|
2018-12-21 17:16:27 +08:00
|
|
|
bool allocateMemory = ptr == nullptr;
|
|
|
|
AllocationData allocationData;
|
2019-05-10 17:30:07 +08:00
|
|
|
MockAllocationProperties properties(allocateMemory, size, allocationType);
|
|
|
|
getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties));
|
2018-12-21 17:16:27 +08:00
|
|
|
return allocate32BitGraphicsMemoryImpl(allocationData);
|
|
|
|
}
|
2018-08-01 20:47:14 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|