Skip to content

Commit 7176e60

Browse files
Do not wait for task count when free empty allocation list
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 7b8820f commit 7176e60

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ void CommandStreamReceiver::waitForTaskCount(uint32_t requiredTaskCount) {
151151
}
152152

153153
void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requiredTaskCount, uint32_t allocationUsage) {
154-
this->CommandStreamReceiver::waitForTaskCount(requiredTaskCount);
154+
auto &list = allocationUsage == TEMPORARY_ALLOCATION ? internalAllocationStorage->getTemporaryAllocations() : internalAllocationStorage->getAllocationsForReuse();
155+
if (!list.peekIsEmpty()) {
156+
this->CommandStreamReceiver::waitForTaskCount(requiredTaskCount);
157+
}
155158
internalAllocationStorage->cleanAllocationList(requiredTaskCount, allocationUsage);
156159
}
157160

shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,15 @@ TEST(CommandStreamReceiverSimpleTest, givenMultipleActivePartitionsWhenWaitingFo
10441044
executionEnvironment.initializeMemoryManager();
10451045
DeviceBitfield deviceBitfield(0b11);
10461046
MockCommandStreamReceiver csr(executionEnvironment, 0, deviceBitfield);
1047+
auto osContext = std::unique_ptr<OsContext>(OsContext::create(nullptr, 0,
1048+
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_BCS, EngineUsage::Regular})));
1049+
csr.setupContext(*osContext);
1050+
1051+
auto hostPtr = reinterpret_cast<void *>(0x1234);
1052+
size_t size = 100;
1053+
auto temporaryAllocation = std::make_unique<MemoryAllocation>(0, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, hostPtr, size, 0, MemoryPool::System4KBPages, MemoryManager::maxOsContextCount);
1054+
temporaryAllocation->updateTaskCount(0u, 0u);
1055+
csr.getInternalAllocationStorage()->storeAllocationWithTaskCount(std::move(temporaryAllocation), TEMPORARY_ALLOCATION, 2u);
10471056

10481057
csr.mockTagAddress[0] = 0u;
10491058
csr.mockTagAddress[2] = 0u;
@@ -1065,6 +1074,30 @@ TEST(CommandStreamReceiverSimpleTest, givenMultipleActivePartitionsWhenWaitingFo
10651074
CpuIntrinsicsTests::pauseAddress = nullptr;
10661075
}
10671076

1077+
TEST(CommandStreamReceiverSimpleTest, givenEmptyTemporaryAllocationListWhenWaitingForTaskCountForCleaningTemporaryAllocationsThenDoNotWait) {
1078+
MockExecutionEnvironment executionEnvironment;
1079+
executionEnvironment.prepareRootDeviceEnvironments(1);
1080+
executionEnvironment.initializeMemoryManager();
1081+
DeviceBitfield deviceBitfield(1);
1082+
MockCommandStreamReceiver csr(executionEnvironment, 0, deviceBitfield);
1083+
1084+
csr.mockTagAddress[0] = 0u;
1085+
csr.taskCount = 3u;
1086+
1087+
VariableBackup<volatile uint32_t *> backupPauseAddress(&CpuIntrinsicsTests::pauseAddress);
1088+
VariableBackup<uint32_t> backupPauseValue(&CpuIntrinsicsTests::pauseValue);
1089+
VariableBackup<uint32_t> backupPauseOffset(&CpuIntrinsicsTests::pauseOffset);
1090+
1091+
CpuIntrinsicsTests::pauseAddress = &csr.mockTagAddress[0];
1092+
CpuIntrinsicsTests::pauseValue = 3u;
1093+
1094+
CpuIntrinsicsTests::pauseCounter = 0;
1095+
csr.waitForTaskCountAndCleanTemporaryAllocationList(3u);
1096+
EXPECT_EQ(0u, CpuIntrinsicsTests::pauseCounter);
1097+
1098+
CpuIntrinsicsTests::pauseAddress = nullptr;
1099+
}
1100+
10681101
TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesAreUsedThenResidencyIsProperlyHandled) {
10691102
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get(), 0u));
10701103

0 commit comments

Comments
 (0)