Move waitForTaskCountAndCleanAllocationList to waitUntilComplete

Change-Id: Ia36b43bb2c8e330c1d90d639c06efcad42783e23
This commit is contained in:
Dunajski, Bartosz
2019-07-15 11:01:32 +02:00
committed by sys_ocldev
parent e825dff4a7
commit de381f01e8
5 changed files with 60 additions and 26 deletions

View File

@@ -134,6 +134,9 @@ void CommandQueue::waitUntilComplete(uint32_t taskCountToWait, FlushStamp flushS
DEBUG_BREAK_IF(getHwTag() < taskCountToWait);
latestTaskCountWaited = taskCountToWait;
getCommandStreamReceiver().waitForTaskCountAndCleanAllocationList(taskCountToWait, TEMPORARY_ALLOCATION);
WAIT_LEAVE()
}

View File

@@ -381,7 +381,6 @@ void CommandQueueHw<GfxFamily>::enqueueHandler(Surface **surfacesForResidency,
if (printfHandler) {
printfHandler->printEnqueueOutput();
}
getCommandStreamReceiver().waitForTaskCountAndCleanAllocationList(completionStamp.taskCount, TEMPORARY_ALLOCATION);
}
}
}

View File

@@ -28,8 +28,6 @@ cl_int CommandQueueHw<GfxFamily>::finish(bool dcFlush) {
// Stall until HW reaches CQ taskCount
waitUntilComplete(taskCountToWaitFor, flushStampToWaitFor, false);
getCommandStreamReceiver().waitForTaskCountAndCleanAllocationList(taskCountToWaitFor, TEMPORARY_ALLOCATION);
return CL_SUCCESS;
}
} // namespace NEO

View File

@@ -17,6 +17,7 @@
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_internal_allocation_storage.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_mdi.h"
@@ -488,20 +489,37 @@ HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenSubCaptureIsOnThenActivateSu
mockCmdQ->release();
}
using EnqueueHandlerTestBasic = ::testing::Test;
struct EnqueueHandlerTestBasic : public ::testing::Test {
template <typename FamilyType>
std::unique_ptr<MockCommandQueueHw<FamilyType>> setupFixtureAndCreateMockCommandQueue() {
auto executionEnvironment = platformImpl->peekExecutionEnvironment();
device.reset(MockDevice::createWithExecutionEnvironment<MockDevice>(nullptr, executionEnvironment, 0u));
context = std::make_unique<MockContext>(device.get());
auto mockCmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
auto &ultCsr = static_cast<UltCommandStreamReceiver<FamilyType> &>(mockCmdQ->getCommandStreamReceiver());
ultCsr.taskCount = initialTaskCount;
mockInternalAllocationStorage = new MockInternalAllocationStorage(ultCsr);
ultCsr.internalAllocationStorage.reset(mockInternalAllocationStorage);
return mockCmdQ;
}
MockInternalAllocationStorage *mockInternalAllocationStorage = nullptr;
const uint32_t initialTaskCount = 100;
std::unique_ptr<MockDevice> device;
std::unique_ptr<MockContext> context;
};
HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenCommandIsBlokingThenCompletionStampTaskCountIsPassedToWaitForTaskCountAndCleanAllocationListAsRequiredTaskCount) {
int32_t tag;
auto executionEnvironment = platformImpl->peekExecutionEnvironment();
auto mockCsr = new MockCsrBase<FamilyType>(tag, *executionEnvironment);
executionEnvironment->commandStreamReceivers.resize(1);
std::unique_ptr<MockDevice> pDevice(MockDevice::createWithExecutionEnvironment<MockDevice>(nullptr, executionEnvironment, 0u));
pDevice->resetCommandStreamReceiver(mockCsr);
auto context = std::make_unique<MockContext>(pDevice.get());
MockKernelWithInternals kernelInternals(*pDevice, context.get());
auto mockCmdQ = setupFixtureAndCreateMockCommandQueue<FamilyType>();
MockKernelWithInternals kernelInternals(*device, context.get());
Kernel *kernel = kernelInternals.mockKernel;
MockMultiDispatchInfo multiDispatchInfo(kernel);
auto mockCmdQ = new MockCommandQueueHw<FamilyType>(context.get(), pDevice.get(), 0);
mockCmdQ->deltaTaskCount = 100;
mockCmdQ->template enqueueHandler<CL_COMMAND_WRITE_BUFFER>(nullptr,
0,
true,
@@ -509,6 +527,32 @@ HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenCommandIsBlokingThenCom
0,
nullptr,
nullptr);
EXPECT_EQ(mockCsr->waitForTaskCountRequiredTaskCount, mockCmdQ->completionStampTaskCount);
mockCmdQ->release();
EXPECT_EQ(initialTaskCount + 1, mockInternalAllocationStorage->lastCleanAllocationsTaskCount);
}
HWTEST_F(EnqueueHandlerTestBasic, givenBlockedEnqueueHandlerWhenCommandIsBlokingThenCompletionStampTaskCountIsPassedToWaitForTaskCountAndCleanAllocationListAsRequiredTaskCount) {
auto mockCmdQ = setupFixtureAndCreateMockCommandQueue<FamilyType>();
MockKernelWithInternals kernelInternals(*device, context.get());
Kernel *kernel = kernelInternals.mockKernel;
MockMultiDispatchInfo multiDispatchInfo(kernel);
UserEvent userEvent;
cl_event waitlist[] = {&userEvent};
std::thread t0([&mockCmdQ, &userEvent]() {
while (!mockCmdQ->isQueueBlocked()) {
}
userEvent.setStatus(CL_COMPLETE);
});
mockCmdQ->template enqueueHandler<CL_COMMAND_WRITE_BUFFER>(nullptr,
0,
true,
multiDispatchInfo,
1,
waitlist,
nullptr);
EXPECT_EQ(initialTaskCount + 1, mockInternalAllocationStorage->lastCleanAllocationsTaskCount);
t0.join();
}

View File

@@ -146,19 +146,9 @@ class MockCommandQueueHw : public CommandQueueHw<GfxFamily> {
bool notifyEnqueueReadBufferCalled = false;
bool notifyEnqueueReadImageCalled = false;
bool cpuDataTransferHandlerCalled = false;
uint32_t completionStampTaskCount = 0;
uint32_t deltaTaskCount = 0;
LinearStream *peekCommandStream() {
return this->commandStream;
}
void updateFromCompletionStamp(const CompletionStamp &completionStamp) override {
BaseClass::updateFromCompletionStamp(completionStamp);
const uint32_t &referenceToCompletionStampTaskCount = completionStamp.taskCount;
uint32_t &nonConstReferenceToCompletionStampTaskCount = const_cast<uint32_t &>(referenceToCompletionStampTaskCount);
nonConstReferenceToCompletionStampTaskCount += deltaTaskCount;
completionStampTaskCount = referenceToCompletionStampTaskCount;
}
};
} // namespace NEO