From fffa22b17da9dc4f0969f9acfdf9e9158e6ee5a0 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Wed, 30 Jun 2021 09:10:41 +0000 Subject: [PATCH] Enhance wait method in L0 command queue Signed-off-by: Lukasz Jobczyk --- level_zero/core/source/cmdqueue/cmdqueue.cpp | 12 ++++---- .../core/source/cmdqueue/cmdqueue_imp.h | 6 ++-- .../sources/cmdqueue/test_cmdqueue.cpp | 28 +++++++++++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/level_zero/core/source/cmdqueue/cmdqueue.cpp b/level_zero/core/source/cmdqueue/cmdqueue.cpp index 4e5feffd84..574c183ce7 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue.cpp +++ b/level_zero/core/source/cmdqueue/cmdqueue.cpp @@ -66,7 +66,7 @@ void CommandQueueImp::submitBatchBuffer(size_t offset, NEO::ResidencyContainer & commandStream->getGraphicsAllocation()->updateResidencyTaskCount(csr->peekTaskCount() + 1, csr->getOsContext().getContextId()); csr->submitBatchBuffer(batchBuffer, csr->getResidencyAllocations()); - buffers.setCurrentFlushStamp(csr->obtainCurrentFlushStamp()); + buffers.setCurrentFlushStamp(csr->peekTaskCount(), csr->obtainCurrentFlushStamp()); } ze_result_t CommandQueueImp::synchronize(uint64_t timeout) { @@ -151,8 +151,8 @@ ze_result_t CommandQueueImp::CommandBufferManager::initialize(Device *device, si memset(buffers[BUFFER_ALLOCATION::FIRST]->getUnderlyingBuffer(), 0, buffers[BUFFER_ALLOCATION::FIRST]->getUnderlyingBufferSize()); memset(buffers[BUFFER_ALLOCATION::SECOND]->getUnderlyingBuffer(), 0, buffers[BUFFER_ALLOCATION::SECOND]->getUnderlyingBufferSize()); - flushId[BUFFER_ALLOCATION::FIRST] = 0u; - flushId[BUFFER_ALLOCATION::SECOND] = 0u; + flushId[BUFFER_ALLOCATION::FIRST] = std::make_pair(0u, 0u); + flushId[BUFFER_ALLOCATION::SECOND] = std::make_pair(0u, 0u); return ZE_RESULT_SUCCESS; } @@ -174,10 +174,10 @@ void CommandQueueImp::CommandBufferManager::switchBuffers(NEO::CommandStreamRece bufferUse = BUFFER_ALLOCATION::FIRST; } - NEO::FlushStamp completionId = flushId[bufferUse]; - if (completionId != 0u) { + auto completionId = flushId[bufferUse]; + if (completionId.second != 0u) { UNRECOVERABLE_IF(csr == nullptr); - csr->waitForFlushStamp(completionId); + csr->waitForTaskCountWithKmdNotifyFallback(completionId.first, completionId.second, false, false); } } diff --git a/level_zero/core/source/cmdqueue/cmdqueue_imp.h b/level_zero/core/source/cmdqueue/cmdqueue_imp.h index 35fd7bec36..c328e0235f 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_imp.h +++ b/level_zero/core/source/cmdqueue/cmdqueue_imp.h @@ -43,13 +43,13 @@ struct CommandQueueImp : public CommandQueue { return buffers[bufferUse]; } - void setCurrentFlushStamp(NEO::FlushStamp flushStamp) { - flushId[bufferUse] = flushStamp; + void setCurrentFlushStamp(uint32_t taskCount, NEO::FlushStamp flushStamp) { + flushId[bufferUse] = std::make_pair(taskCount, flushStamp); } private: NEO::GraphicsAllocation *buffers[BUFFER_ALLOCATION::COUNT]; - NEO::FlushStamp flushId[BUFFER_ALLOCATION::COUNT]; + std::pair flushId[BUFFER_ALLOCATION::COUNT]; BUFFER_ALLOCATION bufferUse = BUFFER_ALLOCATION::FIRST; }; static constexpr size_t defaultQueueCmdBufferSize = 128 * MemoryConstants::kiloByte; diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp index 8a00b0d3ed..ffd80bda2b 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp @@ -98,7 +98,7 @@ TEST_F(CommandQueueCreate, whenSynchronizeByPollingTaskCountThenCallsPrintOutput commandQueue->destroy(); } -TEST_F(CommandQueueCreate, whenReserveLinearStreamThenBufferAllocationSwitched) { +HWTEST_F(CommandQueueCreate, whenReserveLinearStreamThenBufferAllocationSwitched) { const ze_command_queue_desc_t desc{}; ze_result_t returnValue; @@ -115,14 +115,38 @@ TEST_F(CommandQueueCreate, whenReserveLinearStreamThenBufferAllocationSwitched) auto firstAllocation = commandQueue->commandStream->getGraphicsAllocation(); EXPECT_EQ(firstAllocation, commandQueue->buffers.getCurrentBufferAllocation()); + uint32_t currentTaskCount = 33u; + auto &csr = neoDevice->getUltCommandStreamReceiver(); + csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount; + commandQueue->commandStream->getSpace(maxSize - 16u); + commandQueue->buffers.setCurrentFlushStamp(121u, 121u); size_t nextSize = 16u + 16u; commandQueue->reserveLinearStreamSize(nextSize); auto secondAllocation = commandQueue->commandStream->getGraphicsAllocation(); EXPECT_EQ(secondAllocation, commandQueue->buffers.getCurrentBufferAllocation()); - EXPECT_NE(firstAllocation, secondAllocation); + EXPECT_EQ(csr.latestWaitForCompletionWithTimeoutTaskCount, currentTaskCount); + + commandQueue->commandStream->getSpace(maxSize - 16u); + commandQueue->buffers.setCurrentFlushStamp(244u, 244u); + commandQueue->reserveLinearStreamSize(nextSize); + + auto thirdAllocation = commandQueue->commandStream->getGraphicsAllocation(); + EXPECT_EQ(thirdAllocation, commandQueue->buffers.getCurrentBufferAllocation()); + EXPECT_EQ(thirdAllocation, firstAllocation); + EXPECT_NE(thirdAllocation, secondAllocation); + EXPECT_EQ(csr.latestWaitForCompletionWithTimeoutTaskCount, 121u); + + commandQueue->commandStream->getSpace(maxSize - 16u); + commandQueue->reserveLinearStreamSize(nextSize); + + auto fourthAllocation = commandQueue->commandStream->getGraphicsAllocation(); + EXPECT_EQ(fourthAllocation, commandQueue->buffers.getCurrentBufferAllocation()); + EXPECT_EQ(fourthAllocation, secondAllocation); + EXPECT_NE(fourthAllocation, firstAllocation); + EXPECT_EQ(csr.latestWaitForCompletionWithTimeoutTaskCount, 244u); commandQueue->destroy(); }