Move OsContext id setting to constructor.

Change-Id: I1b809befc02536257800e3667307b8deabd5c95d
This commit is contained in:
Mrozek, Michal
2018-09-12 07:47:55 +02:00
committed by sys_ocldev
parent 8e33ec04c5
commit 581805cc88
15 changed files with 39 additions and 27 deletions

View File

@@ -131,7 +131,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
}
executionEnvironment->initializeMemoryManager(outDevice.getEnabled64kbPages(), outDevice.getHardwareCapabilities().localMemorySupported, outDevice.getDeviceIndex());
outDevice.osContext = new OsContext(executionEnvironment->osInterface.get());
outDevice.osContext = new OsContext(executionEnvironment->osInterface.get(), outDevice.getDeviceIndex());
executionEnvironment->memoryManager->registerOsContext(outDevice.osContext);
outDevice.commandStreamReceiver = executionEnvironment->commandStreamReceivers[outDevice.getDeviceIndex()].get();

View File

@@ -387,9 +387,12 @@ RequirementsStatus MemoryManager::checkAllocationsForOverlapping(AllocationRequi
}
void MemoryManager::registerOsContext(OsContext *contextToRegister) {
auto contextId = contextToRegister->getContextId();
if (contextId + 1 > registeredOsContexts.size()) {
registeredOsContexts.resize(contextId + 1);
}
contextToRegister->incRefInternal();
contextToRegister->setContextId(static_cast<uint32_t>(registeredOsContexts.size()));
registeredOsContexts.push_back(contextToRegister);
registeredOsContexts[contextToRegister->getContextId()] = contextToRegister;
}
bool MemoryManager::getAllocationData(AllocationData &allocationData, bool allocateMemory, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) {

View File

@@ -24,7 +24,7 @@
namespace OCLRT {
class OsContext::OsContextImpl {};
OsContext::OsContext(OSInterface *osInterface) {
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId) : contextId(contextId) {
osContextImpl = std::make_unique<OsContext::OsContextImpl>();
}

View File

@@ -29,13 +29,12 @@ class OSInterface;
class OsContext : public ReferenceTrackedObject<OsContext> {
public:
class OsContextImpl;
OsContext(OSInterface *osInterface);
OsContext(OSInterface *osInterface, uint32_t contextId);
~OsContext() override;
OsContextImpl *get() const {
return osContextImpl.get();
};
void setContextId(uint32_t inputContextId) { contextId = inputContextId; }
uint32_t getContextId() { return contextId; }
protected:

View File

@@ -53,7 +53,7 @@ void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cp
monitoredFence.gpuAddress = gpuAddress;
}
OsContext::OsContext(OSInterface *osInterface) {
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId) : contextId(contextId) {
if (osInterface) {
osContextImpl = std::make_unique<OsContextWin>(*osInterface->get()->getWddm());
}

View File

@@ -147,7 +147,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto engineType = OCLRT::ENGINE_RCS;
OsContext osContext(nullptr);
OsContext osContext(nullptr, 0u);
ResidencyContainer allocationsForResidency;
FlushStamp flushStamp = csrWithAubDump->flush(batchBuffer, engineType, &allocationsForResidency, osContext);
@@ -190,7 +190,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub
ASSERT_NE(nullptr, gfxAllocation);
ResidencyContainer allocationsForResidency = {gfxAllocation};
OsContext osContext(nullptr);
OsContext osContext(nullptr, 0u);
csrWithAubDump->processResidency(&allocationsForResidency, osContext);
EXPECT_TRUE(csrWithAubDump->processResidencyParameterization.wasCalled);

View File

@@ -1825,13 +1825,24 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation
}
TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCountIncreases) {
auto osContext = new OsContext(nullptr);
auto osContext = new OsContext(nullptr, 0u);
OsAgnosticMemoryManager memoryManager;
memoryManager.registerOsContext(osContext);
EXPECT_EQ(1u, memoryManager.getOsContextCount());
EXPECT_EQ(1, osContext->getRefInternalCount());
}
TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegistredFromHigherToLowerThenProperSizeIsReturned) {
auto osContext2 = new OsContext(nullptr, 1u);
auto osContext = new OsContext(nullptr, 0u);
OsAgnosticMemoryManager memoryManager;
memoryManager.registerOsContext(osContext2);
memoryManager.registerOsContext(osContext);
EXPECT_EQ(2u, memoryManager.getOsContextCount());
EXPECT_EQ(1, osContext->getRefInternalCount());
EXPECT_EQ(1, osContext2->getRefInternalCount());
}
TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) {
struct mockResidencyData : public ResidencyData {
using ResidencyData::completionData;
@@ -1839,9 +1850,8 @@ TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenIt
mockResidencyData residency;
OsContext osContext(nullptr);
OsContext osContext2(nullptr);
osContext2.setContextId(1u);
OsContext osContext(nullptr, 0u);
OsContext osContext2(nullptr, 1u);
auto lastFenceValue = 45llu;
auto lastFenceValue2 = 23llu;

View File

@@ -57,7 +57,7 @@ class DrmCommandStreamFixture {
const int mockFd = 33;
void SetUp() {
osContext = std::make_unique<OsContext>(nullptr);
osContext = std::make_unique<OsContext>(nullptr, 0u);
this->dbgState = new DebugManagerStateRestore();
//make sure this is disabled, we don't want test this now
DebugManager.flags.EnableForcePin.set(false);

View File

@@ -37,7 +37,7 @@ TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsRetu
TEST(OsContextTest, WhenOsContextIsCreatedThenImplIsAvailable) {
OSInterface osInterface;
auto osContext = std::make_unique<OsContext>(&osInterface);
auto osContext = std::make_unique<OsContext>(&osInterface, 0u);
EXPECT_NE(nullptr, osContext->get());
}
} // namespace OCLRT

View File

@@ -279,7 +279,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get());
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get(), 0u);
osContext->incRefInternal();
executionEnvironment.commandStreamReceivers[0u]->flush(batchBuffer, EngineType::ENGINE_RCS, &executionEnvironment.commandStreamReceivers[0u]->getResidencyAllocations(), *osContext);
auto commandHeader = wddm->submitResult.commandHeaderSubmitted;
@@ -306,7 +306,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get());
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get(), 0u);
osContext->incRefInternal();
executionEnvironment.commandStreamReceivers[0u]->flush(batchBuffer, EngineType::ENGINE_RCS, &executionEnvironment.commandStreamReceivers[0u]->getResidencyAllocations(), *osContext);
auto commandHeader = wddm->submitResult.commandHeaderSubmitted;

View File

@@ -44,7 +44,7 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextBeforeInitWddmThenOsContextIsNot
auto wddm = new WddmMock;
OSInterface osInterface;
osInterface.get()->setWddm(wddm);
EXPECT_THROW(auto osContext = std::make_unique<OsContext>(&osInterface), std::exception);
EXPECT_THROW(auto osContext = std::make_unique<OsContext>(&osInterface, 0u), std::exception);
}
TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitialized) {
@@ -52,13 +52,13 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit
OSInterface osInterface;
osInterface.get()->setWddm(wddm);
wddm->init();
auto osContext = std::make_unique<OsContext>(&osInterface);
auto osContext = std::make_unique<OsContext>(&osInterface, 0u);
EXPECT_NE(nullptr, osContext->get());
EXPECT_TRUE(osContext->get()->isInitialized());
EXPECT_EQ(osContext->get()->getWddm(), wddm);
}
TEST(OsContextTest, whenCreateOsContextWithoutOsInterfaceThenOsContextImplIsNotAvailable) {
auto osContext = std::make_unique<OsContext>(nullptr);
auto osContext = std::make_unique<OsContext>(nullptr, 0u);
EXPECT_EQ(nullptr, osContext->get());
}

View File

@@ -49,7 +49,7 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, publi
void init() {
EXPECT_TRUE(wddm->init());
osContext = std::make_unique<OsContext>(osInterface.get());
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
osContextWin = osContext->get();
}

View File

@@ -41,7 +41,7 @@ struct WddmFixture : public GmmEnvironmentFixture {
gdi = new MockGdi();
wddm->gdi.reset(gdi);
wddm->init();
osContext = std::make_unique<OsContext>(osInterface.get());
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
osContextWin = osContext->get();
ASSERT_TRUE(wddm->isInitialized());
}
@@ -69,7 +69,7 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi
void init() {
EXPECT_TRUE(wddm->init());
osContext = std::make_unique<OsContext>(osInterface.get());
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
osContextWin = osContext->get();
ASSERT_TRUE(wddm->isInitialized());
}

View File

@@ -64,7 +64,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
gdi = new MockGdi();
wddm->gdi.reset(gdi);
EXPECT_TRUE(wddm->init());
osContext = new OsContext(osInterface.get());
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) {
@@ -130,7 +130,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
ASSERT_NE(nullptr, wddm);
EXPECT_TRUE(wddm->init());
osInterface->get()->setWddm(wddm);
osContext = new OsContext(osInterface.get());
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
wddm->init();
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm);

View File

@@ -51,7 +51,7 @@ class WddmPreemptionTests : public Test<WddmFixtureWithMockGdiDll> {
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest);
wddm->setPreemptionMode(preemptionMode);
wddm->init();
osContext = std::make_unique<OsContext>(osInterface.get());
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
osContextWin = osContext->get();
}