From b0a6d9131a2c527bdd0f3430d9adfaae4dc83273 Mon Sep 17 00:00:00 2001 From: "Koska, Andrzej" Date: Thu, 12 Apr 2018 10:05:35 +0200 Subject: [PATCH] Making DSH and IOH always resident Change-Id: Ib114b92cb5ee153f213c15c935f8f1d1cfeb46eb --- .../command_stream_receiver.cpp | 6 ++++- .../command_stream_receiver_hw.inl | 2 ++ runtime/memory_manager/graphics_allocation.h | 4 ++++ .../command_stream_receiver_hw_tests.cpp | 23 +++++++++++++++++++ .../windows/device_command_stream_tests.cpp | 19 +++++++++++++-- 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 4320bb739b..51370170cb 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -67,7 +67,11 @@ void CommandStreamReceiver::processEviction() { void CommandStreamReceiver::makeNonResident(GraphicsAllocation &gfxAllocation) { if (gfxAllocation.residencyTaskCount != ObjectNotResident) { makeCoherent(gfxAllocation); - getMemoryManager()->pushAllocationForEviction(&gfxAllocation); + if (gfxAllocation.peekEvictable()) { + getMemoryManager()->pushAllocationForEviction(&gfxAllocation); + } else { + gfxAllocation.setEvictable(true); + } } gfxAllocation.residencyTaskCount = ObjectNotResident; diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index 1e3137129a..c87f09a492 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -299,8 +299,10 @@ CompletionStamp CommandStreamReceiverHw::flushTask( auto sshAllocation = ssh.getGraphicsAllocation(); this->makeResident(*dshAllocation); + dshAllocation->setEvictable(false); this->makeResident(*iohAllocation); this->makeResident(*sshAllocation); + iohAllocation->setEvictable(false); this->makeResident(*tagAllocation); diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 374eb9fb38..572f19ede8 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -50,6 +50,7 @@ class GraphicsAllocation : public IDNode { osHandle sharedHandle; bool locked = false; uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources + bool evictable = true; public: enum AllocationType { @@ -126,6 +127,9 @@ class GraphicsAllocation : public IDNode { int residencyTaskCount = ObjectNotResident; + void setEvictable(bool evictable) { this->evictable = evictable; } + bool peekEvictable() const { return evictable; } + bool isResident() const { return residencyTaskCount != ObjectNotResident; } void setLocked(bool locked) { this->locked = locked; } bool isLocked() const { return locked; } diff --git a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp index 84d0a2bc60..891904b869 100644 --- a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp @@ -315,6 +315,29 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSu EXPECT_EQ(expectedUsedSize, commandStream.getUsed()); } +HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrWhenflushTaskThenDshAndIohNotEvictable) { + auto mockCsr = new MockCsrHw2(*platformDevices[0]); + pDevice->resetCommandStreamReceiver(mockCsr); + DispatchFlags dispatchFlags; + + mockCsr->flushTask(commandStream, + 0, + dsh, + ioh, + ssh, + taskLevel, + dispatchFlags); + + EXPECT_EQ(dsh.getGraphicsAllocation()->peekEvictable(), true); + EXPECT_EQ(ssh.getGraphicsAllocation()->peekEvictable(), true); + EXPECT_EQ(ioh.getGraphicsAllocation()->peekEvictable(), true); + + dsh.getGraphicsAllocation()->setEvictable(false); + EXPECT_EQ(dsh.getGraphicsAllocation()->peekEvictable(), false); + dsh.getGraphicsAllocation()->setEvictable(true); + EXPECT_EQ(dsh.getGraphicsAllocation()->peekEvictable(), true); +} + HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThreadPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) { auto mockCsr = new MockCsrHw2(*platformDevices[0]); pDevice->resetCommandStreamReceiver(mockCsr); diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index e00ff25b59..e9d017048a 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -668,15 +668,21 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); auto commandBuffer = memManager->allocateGraphicsMemory(1024, 4096); + auto dshAlloc = memManager->allocateGraphicsMemory(1024, 4096); + auto iohAlloc = memManager->allocateGraphicsMemory(1024, 4096); + auto sshAlloc = memManager->allocateGraphicsMemory(1024, 4096); mockCsr->setTagAllocation(tagAllocation); LinearStream cs(commandBuffer); + LinearStream dsh(dshAlloc); + LinearStream ioh(iohAlloc); + LinearStream ssh(sshAlloc); DispatchFlags dispatchFlags; dispatchFlags.guardCommandBufferWithPipeControl = true; dispatchFlags.requiresCoherency = true; - mockCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags); + mockCsr->flushTask(cs, 0u, dsh, ioh, ssh, 0u, dispatchFlags); auto &cmdBuffers = mockedSubmissionsAggregator->peekCommandBuffers(); auto storedCommandBuffer = cmdBuffers.peekHead(); @@ -692,11 +698,14 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation(); EXPECT_EQ(reinterpret_cast(csrCommandStream->getUnderlyingBuffer()), mockWddm->submitResult.commandBufferSubmitted); EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)mockWddm->submitResult.commandHeaderSubmitted)->RequiresCoherency); - EXPECT_EQ(3u, mockWddm->makeResidentResult.handleCount); + EXPECT_EQ(6u, mockWddm->makeResidentResult.handleCount); std::vector expectedHandles; expectedHandles.push_back(((WddmAllocation *)tagAllocation)->handle); expectedHandles.push_back(((WddmAllocation *)commandBuffer)->handle); + expectedHandles.push_back(((WddmAllocation *)dshAlloc)->handle); + expectedHandles.push_back(((WddmAllocation *)iohAlloc)->handle); + expectedHandles.push_back(((WddmAllocation *)sshAlloc)->handle); expectedHandles.push_back(((WddmAllocation *)csrCommandStream)->handle); for (auto i = 0u; i < mockWddm->makeResidentResult.handleCount; i++) { @@ -712,8 +721,14 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)tagAllocation)->getTrimCandidateListPosition()); EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)commandBuffer)->getTrimCandidateListPosition()); + EXPECT_EQ(trimListUnusedPosition, ((WddmAllocation *)dshAlloc)->getTrimCandidateListPosition()); + EXPECT_EQ(trimListUnusedPosition, ((WddmAllocation *)iohAlloc)->getTrimCandidateListPosition()); + EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)sshAlloc)->getTrimCandidateListPosition()); EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)csrCommandStream)->getTrimCandidateListPosition()); + memManager->freeGraphicsMemory(dshAlloc); + memManager->freeGraphicsMemory(iohAlloc); + memManager->freeGraphicsMemory(sshAlloc); memManager->freeGraphicsMemory(commandBuffer); }