Pass maxOsContextCount to BufferObject

Change-Id: I9e64718a5a64096c8fdc50f3b84d3843701ff602
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-08-20 13:20:20 +02:00
committed by sys_ocldev
parent 53cb6a127d
commit 739c1c6c99
10 changed files with 39 additions and 38 deletions

View File

@ -14,9 +14,10 @@ namespace NEO {
class MockBufferObject : public BufferObject {
public:
using BufferObject::bindInfo;
using BufferObject::BufferObject;
using BufferObject::handle;
MockBufferObject(Drm *drm) : BufferObject(drm, 0, 0) {
MockBufferObject(Drm *drm) : BufferObject(drm, 0, 0, 1) {
}
};

View File

@ -25,7 +25,7 @@ using namespace NEO;
class TestedBufferObject : public BufferObject {
public:
TestedBufferObject(Drm *drm) : BufferObject(drm, 1, 0) {
TestedBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) {
}
void tileBy(uint32_t mode) {
@ -188,7 +188,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
TEST(DrmBufferObjectSimpleTest, givenBufferObjectWhenConstructedWithASizeThenTheSizeIsInitialized) {
std::unique_ptr<DrmMockCustom> drmMock(new DrmMockCustom);
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000));
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 1, 0x1000, 1));
EXPECT_EQ(0x1000u, bo->peekSize());
}
@ -231,7 +231,7 @@ TEST_F(DrmBufferObjectTest, givenDeleterWhenBufferObjectIsCreatedAndDeletedThenC
mock->ioctl_expected.reset();
{
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(mock.get(), 1, 0x1000));
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(mock.get(), 1, 0x1000, 1));
}
EXPECT_EQ(1, mock->ioctl_cnt.gemClose);
@ -245,9 +245,9 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoCreatedThenBindInfoIsInitia
device->getExecutionEnvironment()->calculateMaxOsContextCount();
DrmMock drm(*(device->getExecutionEnvironment()->rootDeviceEnvironments[0].get()));
EXPECT_TRUE(drm.isPerContextVMRequired());
MockBufferObject bo(&drm);
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(&drm, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
for (auto &iter : bo.bindInfo) {
@ -273,9 +273,9 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectB
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
MockBufferObject bo(drm);
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;

View File

@ -147,7 +147,7 @@ class DrmCommandStreamEnhancedTemplate : public ::testing::Test {
friend DrmCommandStreamEnhancedTemplate<T>;
protected:
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0) {
MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, 0, 16u) {
this->size = alignUp(size, 4096);
}
};

View File

@ -104,7 +104,7 @@ TEST_F(DrmGemCloseWorkerTests, gemClose) {
this->drmMock->gem_close_expected = 1;
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObject(this->drmMock, 1, 0);
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
worker->push(bo);
@ -115,7 +115,7 @@ TEST_F(DrmGemCloseWorkerTests, gemCloseExit) {
this->drmMock->gem_close_expected = -1;
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObject(this->drmMock, 1, 0);
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
worker->push(bo);
@ -135,7 +135,7 @@ TEST_F(DrmGemCloseWorkerTests, close) {
this->drmMock->gem_close_expected = -1;
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObject(this->drmMock, 1, 0);
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
worker->push(bo);
worker->close(false);
@ -153,7 +153,7 @@ TEST_F(DrmGemCloseWorkerTests, givenAllocationWhenAskedForUnreferenceWithForceFl
this->drmMock->gem_close_expected = 1;
auto worker = new DrmGemCloseWorker(*mm);
auto bo = new BufferObject(this->drmMock, 1, 0);
auto bo = new BufferObject(this->drmMock, 1, 0, 1);
bo->reference();
worker->push(bo);

View File

@ -104,7 +104,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThen
namespace NEO {
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks);
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount);
class DrmMemoryManagerLocalMemoryTest : public ::testing::Test {
public:
@ -166,7 +166,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
auto gpuAddress = 0x1234u;
auto size = MemoryConstants::pageSize64k;
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, (1 << (MemoryBanks::Bank0 - 1))));
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, (1 << (MemoryBanks::Bank0 - 1)), 1));
ASSERT_NE(nullptr, bo);
EXPECT_EQ(1u, mock->ioctlCallsCount);
@ -195,7 +195,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
auto gpuAddress = 0x1234u;
auto size = MemoryConstants::pageSize;
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank));
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1));
EXPECT_EQ(nullptr, bo);
}
@ -207,7 +207,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
auto gpuAddress = 0x1234u;
auto size = MemoryConstants::pageSize;
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank));
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1));
EXPECT_EQ(nullptr, bo);
}
@ -217,7 +217,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWhenCreateBufferObj
auto gpuAddress = 0x1234u;
auto size = 0u;
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank));
auto bo = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(&memoryManager->getDrm(0), gpuAddress, size, MemoryBanks::MainBank, 1));
EXPECT_EQ(nullptr, bo);
}
@ -643,7 +643,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhen
}
TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnBufferObjectThenReturnPtr) {
BufferObject bo(mock, 1, 1024);
BufferObject bo(mock, 1, 1024, 0);
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
EXPECT_EQ(&bo, drmAllocation.getBO());
@ -657,7 +657,7 @@ TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithL
}
TEST_F(DrmMemoryManagerLocalMemoryWithCustomMockTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnWriteCombinedAllocationThenReturnPtrAlignedTo64Kb) {
BufferObject bo(mock, 1, 1024);
BufferObject bo(mock, 1, 1024, 0);
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::WRITE_COMBINED, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
EXPECT_EQ(&bo, drmAllocation.getBO());
@ -851,7 +851,7 @@ TEST_F(DrmMemoryManagerTestDg1, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAll
this->ioctlResExt = {mockDg1->ioctl_cnt.total, -1};
mockDg1->ioctl_res_ext = &ioctlResExt;
BufferObject bo(mockDg1, 1, 0);
BufferObject bo(mockDg1, 1, 0, 0);
DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, 0u, MemoryPool::LocalMemory);
EXPECT_NE(nullptr, drmAllocation.getBO());

View File

@ -2383,7 +2383,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledButFails
DrmMockCustom drmMock;
struct BufferObjectMock : public BufferObject {
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
};
BufferObjectMock bo(&drmMock);
DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, (osHandle)0u, MemoryPool::MemoryNull);
@ -2416,7 +2416,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenUnlockResourceIsCalledOnAl
DrmMockCustom drmMock;
struct BufferObjectMock : public BufferObject {
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
};
auto bo = new BufferObjectMock(&drmMock);
auto drmAllocation = new DrmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, bo, nullptr, 0u, (osHandle)0u, MemoryPool::LocalMemory);
@ -2443,7 +2443,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledButFai
DrmMockCustom drmMock;
struct BufferObjectMock : public BufferObject {
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
};
BufferObjectMock bo(&drmMock);
DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, (osHandle)0u, MemoryPool::MemoryNull);
@ -2459,7 +2459,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSetDomainCpuIsCalledOnAllo
DrmMockCustom drmMock;
struct BufferObjectMock : public BufferObject {
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0) {}
BufferObjectMock(Drm *drm) : BufferObject(drm, 1, 0, 1) {}
};
BufferObjectMock bo(&drmMock);
DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, &bo, nullptr, 0u, (osHandle)0u, MemoryPool::MemoryNull);
@ -2981,7 +2981,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
class PinBufferObject : public BufferObject {
public:
PinBufferObject(Drm *drm) : BufferObject(drm, 1, 0) {
PinBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) {
}
int pin(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) override {

View File

@ -30,14 +30,14 @@
namespace NEO {
BufferObject::BufferObject(Drm *drm, int handle, size_t size) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) {
BufferObject::BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount) : drm(drm), refCount(1), handle(handle), size(size), isReused(false) {
this->tiling_mode = I915_TILING_NONE;
this->lockedAddress = nullptr;
perContextVmsUsed = drm->isPerContextVMRequired();
if (perContextVmsUsed) {
bindInfo.resize(MemoryManager::maxOsContextCount);
bindInfo.resize(maxOsContextCount);
for (auto &iter : bindInfo) {
iter.fill(false);
}

View File

@ -29,7 +29,7 @@ class BufferObject {
friend DrmMemoryManager;
public:
BufferObject(Drm *drm, int handle, size_t size);
BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount);
MOCKABLE_VIRTUAL ~BufferObject(){};
struct Deleter {

View File

@ -175,7 +175,7 @@ NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size
return nullptr;
}
auto res = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), userptr.handle, size);
auto res = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), userptr.handle, size, maxOsContextCount);
if (!res) {
DEBUG_BREAK_IF(true);
return nullptr;
@ -349,7 +349,7 @@ GraphicsAllocation *DrmMemoryManager::allocateShareableMemory(const AllocationDa
DEBUG_BREAK_IF(ret != 0);
((void)(ret));
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, bufferSize));
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, bufferSize, maxOsContextCount));
bo->gpuAddress = gpuRange;
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo.get(), nullptr, gpuRange, bufferSize, MemoryPool::SystemCpuInaccessible);
@ -378,7 +378,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
DEBUG_BREAK_IF(ret != 0);
UNUSED_VARIABLE(ret);
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new (std::nothrow) BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.imgInfo->size));
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new (std::nothrow) BufferObject(&getDrm(allocationData.rootDeviceIndex), create.handle, allocationData.imgInfo->size, maxOsContextCount));
if (!bo) {
return nullptr;
}
@ -484,7 +484,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si
gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex, isLocalMemorySupported(rootDeviceIndex));
auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, size);
auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, size, maxOsContextCount);
if (!bo) {
return nullptr;
}

View File

@ -18,7 +18,7 @@
namespace NEO {
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks) {
BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount) {
auto memoryInfo = static_cast<MemoryInfoImpl *>(drm->getMemoryInfo());
if (!memoryInfo) {
return nullptr;
@ -50,7 +50,7 @@ BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, si
return nullptr;
}
auto bo = new (std::nothrow) BufferObject(drm, createExt.handle, size);
auto bo = new (std::nothrow) BufferObject(drm, createExt.handle, size, maxOsContextCount);
if (!bo) {
return nullptr;
}
@ -85,7 +85,7 @@ uint64_t getGpuAddress(GraphicsAllocation::AllocationType allocType, GfxPartitio
return gpuAddress;
}
bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress) {
bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
auto &storageInfo = allocation->storageInfo;
auto boAddress = gpuAddress;
@ -95,7 +95,7 @@ bool createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddres
memoryBanks &= 1u << handleId;
}
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks));
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
if (nullptr == bos[handleId]) {
return false;
}
@ -148,7 +148,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
allocation->setFlushL3Required(allocationData.flags.flushL3);
allocation->setReservedAddressRange(reinterpret_cast<void *>(gpuAddress), sizeAllocated);
if (!createDrmAllocation(&getDrm(allocationData.rootDeviceIndex), allocation.get(), gpuAddress)) {
if (!createDrmAllocation(&getDrm(allocationData.rootDeviceIndex), allocation.get(), gpuAddress, maxOsContextCount)) {
for (auto handleId = 0u; handleId < allocationData.storageInfo.getNumBanks(); handleId++) {
delete allocation->getGmm(handleId);
}