Skip to content

Commit eb8cd33

Browse files
Do not flush tag update if already flushed
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 8f8370b commit eb8cd33

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

shared/source/memory_manager/deferrable_allocation_deletion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ bool DeferrableAllocationDeletion::apply() {
2626
graphicsAllocation.releaseUsageInOsContext(contextId);
2727
} else {
2828
isStillUsed = true;
29-
engine.commandStreamReceiver->updateTagFromWait();
29+
if (engine.commandStreamReceiver->peekLatestFlushedTaskCount() < graphicsAllocation.getTaskCount(contextId)) {
30+
engine.commandStreamReceiver->updateTagFromWait();
31+
}
3032
}
3133
}
3234
}

shared/test/unit_test/memory_manager/deferrable_allocation_deletion_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,47 @@ TEST_F(DeferrableAllocationDeletionTest, givenDeferrableAllocationWhenApplyThenW
7979
EXPECT_EQ(1u, memoryManager->freeGraphicsMemoryCalled);
8080
}
8181

82+
HWTEST_F(DeferrableAllocationDeletionTest, givenDeferrableAllocationDeletionWhenTaskCountAlreadyFlushedThenDoNotProgrammTagUpdate) {
83+
struct DeferrableAllocationDeletionApplyCall : public DeferrableAllocationDeletion {
84+
using DeferrableAllocationDeletion::DeferrableAllocationDeletion;
85+
bool apply() override {
86+
auto ret = DeferrableAllocationDeletion::apply();
87+
applyCalled = true;
88+
return ret;
89+
}
90+
bool applyCalled = false;
91+
};
92+
auto &nonDefaultCommandStreamReceiver = static_cast<UltCommandStreamReceiver<FamilyType> &>(*device->commandStreamReceivers[1]);
93+
auto nonDefaultOsContextId = nonDefaultCommandStreamReceiver.getOsContext().getContextId();
94+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize});
95+
*hwTag = 0u;
96+
*nonDefaultCommandStreamReceiver.getTagAddress() = 0u;
97+
nonDefaultCommandStreamReceiver.setLatestFlushedTaskCount(2u);
98+
static_cast<UltCommandStreamReceiver<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver)->setLatestFlushedTaskCount(2u);
99+
nonDefaultCommandStreamReceiver.taskCount = 2u;
100+
static_cast<UltCommandStreamReceiver<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver)->taskCount = 2u;
101+
allocation->updateTaskCount(1u, nonDefaultOsContextId);
102+
allocation->updateTaskCount(1u, defaultOsContextId);
103+
auto used = nonDefaultCommandStreamReceiver.getCS(0u).getUsed();
104+
EXPECT_FALSE(nonDefaultCommandStreamReceiver.flushBatchedSubmissionsCalled);
105+
auto usedDefault = device->getDefaultEngine().commandStreamReceiver->getCS(0u).getUsed();
106+
EXPECT_FALSE(static_cast<UltCommandStreamReceiver<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver)->flushBatchedSubmissionsCalled);
107+
auto deferrableAlloc = new DeferrableAllocationDeletionApplyCall(*memoryManager, *allocation);
108+
EXPECT_FALSE(deferrableAlloc->applyCalled);
109+
asyncDeleter->deferDeletion(deferrableAlloc);
110+
while (!deferrableAlloc->applyCalled)
111+
std::this_thread::yield();
112+
*hwTag = 2u;
113+
*nonDefaultCommandStreamReceiver.getTagAddress() = 2u;
114+
EXPECT_FALSE(nonDefaultCommandStreamReceiver.flushBatchedSubmissionsCalled);
115+
EXPECT_EQ(used, nonDefaultCommandStreamReceiver.getCS(0u).getUsed());
116+
EXPECT_FALSE(static_cast<UltCommandStreamReceiver<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver)->flushBatchedSubmissionsCalled);
117+
EXPECT_EQ(usedDefault, device->getDefaultEngine().commandStreamReceiver->getCS(0u).getUsed());
118+
asyncDeleter->allowExit = true;
119+
*hwTag = 2u;
120+
*nonDefaultCommandStreamReceiver.getTagAddress() = 2u;
121+
}
122+
82123
HWTEST_F(DeferrableAllocationDeletionTest, givenAllocationUsedByTwoOsContextsWhenApplyDeletionThenWaitForBothContextsAndFlushNotReadyCsr) {
83124
auto &nonDefaultCommandStreamReceiver = static_cast<UltCommandStreamReceiver<FamilyType> &>(*device->commandStreamReceivers[1]);
84125
auto nonDefaultOsContextId = nonDefaultCommandStreamReceiver.getOsContext().getContextId();

0 commit comments

Comments
 (0)