Allow Device creating multiple CSRs [2/n]

Create new OsContext per CSR

Change-Id: I8dad7fc1ab450e560f78eba3152b5913791e59a3
Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz
2018-11-21 09:57:51 +01:00
committed by sys_ocldev
parent 3cb8683fb4
commit 706d9f8070
16 changed files with 104 additions and 80 deletions

View File

@@ -197,7 +197,9 @@ TEST_F(MemoryAllocatorTest, allocateSystemAligned) {
TEST_F(MemoryAllocatorTest, allocateGraphics) {
unsigned int alignment = 4096;
memoryManager->createAndRegisterOsContext();
auto allocation = memoryManager->allocateGraphicsMemory(sizeof(char));
ASSERT_NE(nullptr, allocation);
// initial taskCount must be -1. if not, we may kill allocation before it will be used
EXPECT_EQ((uint32_t)-1, allocation->getTaskCount(0));
@@ -1224,6 +1226,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhenche
}
TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsAddedToTemporaryAllocationList) {
memoryManager->createAndRegisterOsContext();
auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemory(4096);
auto tagAddress = csr->getTagAddress();
@@ -1393,24 +1396,21 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation
}
TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCountIncreases) {
auto osContext = new OsContext(nullptr, 0u);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.registerOsContext(osContext);
MockMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.createAndRegisterOsContext();
EXPECT_EQ(1u, memoryManager.getOsContextCount());
EXPECT_EQ(1, osContext->getRefInternalCount());
EXPECT_EQ(1, memoryManager.registeredOsContexts[0]->getRefInternalCount());
}
TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegistredFromHigherToLowerThenProperSizeIsReturned) {
auto osContext2 = new OsContext(nullptr, 1u);
auto osContext = new OsContext(nullptr, 0u);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.registerOsContext(osContext2);
memoryManager.registerOsContext(osContext);
MockMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.createAndRegisterOsContext();
memoryManager.createAndRegisterOsContext();
EXPECT_EQ(2u, memoryManager.getOsContextCount());
EXPECT_EQ(1, osContext->getRefInternalCount());
EXPECT_EQ(1, osContext2->getRefInternalCount());
EXPECT_EQ(1, memoryManager.registeredOsContexts[0]->getRefInternalCount());
EXPECT_EQ(1, memoryManager.registeredOsContexts[1]->getRefInternalCount());
}
TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) {

View File

@@ -19,7 +19,7 @@ MockDevice::MockDevice(const HardwareInfo &hwInfo)
executionEnvironment->commandStreamReceivers.resize(getDeviceIndex() + 1);
executionEnvironment->commandStreamReceivers[getDeviceIndex()].push_back(std::unique_ptr<CommandStreamReceiver>(commandStreamReceiver));
this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager);
this->commandStreamReceiver.push_back(commandStreamReceiver);
this->engines.emplace_back(commandStreamReceiver, nullptr);
}
MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex)
: Device(hwInfo, executionEnvironment, deviceIndex) {
@@ -49,7 +49,7 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
executionEnvironment->commandStreamReceivers[getDeviceIndex()][0].reset(newCsr);
executionEnvironment->commandStreamReceivers[getDeviceIndex()][0]->initializeTagAllocation();
executionEnvironment->commandStreamReceivers[getDeviceIndex()][0]->setPreemptionCsrAllocation(preemptionAllocation);
this->commandStreamReceiver[0] = newCsr;
this->engines[0].commandStreamReceiver = newCsr;
UNRECOVERABLE_IF(getDeviceIndex() != 0u);
this->tagAddress = executionEnvironment->commandStreamReceivers[getDeviceIndex()][0]->getTagAddress();
}

View File

@@ -99,7 +99,7 @@ class MockDevice : public Device {
size_t alignment = 256 * MemoryConstants::kiloByte;
bool uncacheable = getWaTable()->waCSRUncachable;
this->preemptionAllocation = executionEnvironment->memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable);
this->commandStreamReceiver[0]->setPreemptionCsrAllocation(preemptionAllocation);
this->engines[0].commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
}
}
}

View File

@@ -20,6 +20,7 @@ class MockMemoryManager : public OsAgnosticMemoryManager {
using MemoryManager::allocateGraphicsMemory;
using MemoryManager::allocateGraphicsMemoryInPreferredPool;
using MemoryManager::getAllocationData;
using MemoryManager::registeredOsContexts;
using MemoryManager::timestampPacketAllocator;
using OsAgnosticMemoryManager::OsAgnosticMemoryManager;
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) {

View File

@@ -256,11 +256,9 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf
auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemory(4096);
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
OsContext *osContext = new OsContext(executionEnvironment->osInterface.get(), 0u);
osContext->incRefInternal();
executionEnvironment->memoryManager->registerOsContext(osContext);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
executionEnvironment->commandStreamReceivers[0][0]->flush(batchBuffer, EngineType::ENGINE_RCS,
executionEnvironment->commandStreamReceivers[0][0]->getResidencyAllocations(), *osContext);
auto commandHeader = wddm->submitResult.commandHeaderSubmitted;
@@ -288,7 +286,6 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
OsContext *osContext = new OsContext(executionEnvironment->osInterface.get(), 0u);
osContext->incRefInternal();
executionEnvironment->memoryManager->registerOsContext(osContext);
executionEnvironment->commandStreamReceivers[0][0]->flush(batchBuffer, EngineType::ENGINE_RCS, executionEnvironment->commandStreamReceivers[0][0]->getResidencyAllocations(), *osContext);
auto commandHeader = wddm->submitResult.commandHeaderSubmitted;
COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);

View File

@@ -40,8 +40,8 @@ void WddmMemoryManagerFixture::SetUp() {
constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000;
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
executionEnvironment.osInterface = std::make_unique<OSInterface>();
executionEnvironment.osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, executionEnvironment);
}
@@ -1195,16 +1195,16 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWithNoRegisteredOsContextsWh
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWithRegisteredOsContextWhenCallingIsMemoryBudgetExhaustedThenReturnFalse) {
memoryManager->registerOsContext(new OsContext(osInterface.get(), 0u));
memoryManager->registerOsContext(new OsContext(osInterface.get(), 1u));
memoryManager->registerOsContext(new OsContext(osInterface.get(), 2u));
memoryManager->createAndRegisterOsContext();
memoryManager->createAndRegisterOsContext();
memoryManager->createAndRegisterOsContext();
EXPECT_FALSE(memoryManager->isMemoryBudgetExhausted());
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWithRegisteredOsContextWithExhaustedMemoryBudgetWhenCallingIsMemoryBudgetExhaustedThenReturnTrue) {
memoryManager->registerOsContext(new OsContext(osInterface.get(), 0u));
memoryManager->registerOsContext(new OsContext(osInterface.get(), 1u));
memoryManager->registerOsContext(new OsContext(osInterface.get(), 2u));
memoryManager->createAndRegisterOsContext();
memoryManager->createAndRegisterOsContext();
memoryManager->createAndRegisterOsContext();
memoryManager->getRegisteredOsContext(1)->get()->getResidencyController().setMemoryBudgetExhausted();
EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted());
}

View File

@@ -32,7 +32,7 @@ class WddmMemoryManagerFixture : public GmmEnvironmentFixture, public GdiDllFixt
GdiDllFixture::TearDown();
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm;
};
@@ -52,14 +52,14 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
EXPECT_TRUE(wddm->init());
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
executionEnvironment.osInterface.reset(new OSInterface());
executionEnvironment.osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, executionEnvironment);
memoryManager->registerOsContext(osContext);
memoryManager->createAndRegisterOsContext();
osContext = memoryManager->getRegisteredOsContext(0);
osContext->incRefInternal();
}
void TearDown() {
@@ -67,7 +67,6 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;
OsContext *osContext = nullptr;
@@ -117,13 +116,14 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
ASSERT_NE(nullptr, wddm);
EXPECT_TRUE(wddm->init());
osInterface->get()->setWddm(wddm);
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
wddm->init();
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm, executionEnvironment);
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
memoryManager->registerOsContext(osContext);
memoryManager->createAndRegisterOsContext();
osContext = memoryManager->getRegisteredOsContext(0);
osContext->incRefInternal();
ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm, &GmockWddm::baseCreateAllocationAndMapGpuVa));
}

View File

@@ -80,21 +80,20 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT
};
void SetUp() {
osInterface = std::make_unique<OSInterface>();
executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->initGmm(*platformDevices);
wddm = new ::testing::NiceMock<GmockWddm>();
wddm->gdi = std::make_unique<MockGdi>();
ASSERT_TRUE(wddm->init());
osInterface->get()->setWddm(wddm);
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, *executionEnvironment);
osContext = new OsContext(osInterface.get(), 0u);
memoryManager->createAndRegisterOsContext();
osContext = memoryManager->getRegisteredOsContext(0);
osContext->incRefInternal();
memoryManager->registerOsContext(osContext);
residencyController = &osContext->get()->getResidencyController();
}
@@ -102,7 +101,6 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT
osContext->decRefInternal();
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
::testing::NiceMock<GmockWddm> *wddm = nullptr;
@@ -119,23 +117,23 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test {
gdi = new MockGdi();
wddm->gdi.reset(gdi);
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
osContext = new OsContext(osInterface.get(), osContextId);
osContext->incRefInternal();
residencyController = &osContext->get()->getResidencyController();
executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->osInterface = std::make_unique<OSInterface>();
executionEnvironment->osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm, *executionEnvironment);
memoryManager->registerOsContext(osContext);
memoryManager->createAndRegisterOsContext();
osContext = memoryManager->getRegisteredOsContext(0);
osContext->incRefInternal();
residencyController = &osContext->get()->getResidencyController();
}
void TearDown() {
osContext->decRefInternal();
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<ExecutionEnvironment> executionEnvironment;
std::unique_ptr<MockWddmMemoryManager> memoryManager;