diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl index becd154d2c..48503fc11a 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl @@ -424,7 +424,7 @@ inline ze_result_t CommandListCoreFamilyImmediate::executeCommand size_t commandStreamStart = this->cmdListCurrentStartOffset; auto csr = static_cast(cmdQ)->getCsr(); - auto lockCSR = csr->obtainUniqueOwnership(); + auto lockCSR = outerLock != nullptr ? std::move(*outerLock) : csr->obtainUniqueOwnership(); if (NEO::ApiSpecificConfig::isSharedAllocPrefetchEnabled()) { auto svmAllocMgr = this->device->getDriverHandle()->getSvmAllocsManager(); @@ -1685,8 +1685,8 @@ ze_result_t CommandListCoreFamilyImmediate::appendCommandLists(ui return ret; } - auto cmdQueue = this->cmdQImmediate; - ret = cmdQueue->executeCommandLists(numCommandLists, phCommandLists, nullptr, true, this->commandContainer.getCommandStream()); + auto mainAppendLock = static_cast(this->cmdQImmediate)->getCsr()->obtainUniqueOwnership(); + ret = this->cmdQImmediate->executeCommandLists(numCommandLists, phCommandLists, nullptr, true, this->commandContainer.getCommandStream()); if (ret != ZE_RESULT_SUCCESS) { return ret; } @@ -1701,7 +1701,7 @@ ze_result_t CommandListCoreFamilyImmediate::appendCommandLists(ui } bool hasStallingCmds = true; - return flushImmediate(ret, true, hasStallingCmds, relaxedOrderingDispatch, NEO::AppendOperations::kernel, false, hSignalEvent, true, nullptr); + return flushImmediate(ret, true, hasStallingCmds, relaxedOrderingDispatch, NEO::AppendOperations::kernel, false, hSignalEvent, true, &mainAppendLock); } } // namespace L0 diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index 29846659f4..58e759fd26 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -73,11 +73,12 @@ ze_result_t CommandQueueHw::executeCommandLists( this->csr->ensurePrimaryCsrInitialized(*this->device->getNEODevice()); } - auto lockCSR = this->csr->obtainUniqueOwnership(); + std::unique_lock lockCSR; if (parentImmediateCommandlistLinearStream != nullptr) { this->startingCmdBuffer = parentImmediateCommandlistLinearStream; } else { + lockCSR = this->csr->obtainUniqueOwnership(); this->startingCmdBuffer = &this->commandStream; } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp index 1cd8b2771d..a03b34e34c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp @@ -1567,12 +1567,19 @@ HWTEST2_F(ImmediateCommandListTest, givenImmediateCmdListWhenAppendingRegularThe commandList->close(); auto cmdListHandle = commandList->toHandle(); + auto &ultCsr = neoDevice->getUltCommandStreamReceiver(); + ultCsr.recursiveLockCounter = 0; + // first append can carry preamble commandListImmediate->appendCommandLists(1, &cmdListHandle, nullptr, 0, nullptr); + EXPECT_EQ(1u, ultCsr.recursiveLockCounter); + // regular append can dispatch bb_start to secondary regular or primary directly regular commandListImmediate->appendCommandLists(1, &cmdListHandle, nullptr, 0, nullptr); + EXPECT_EQ(2u, ultCsr.recursiveLockCounter); + auto startStream = static_cast(commandListImmediate->cmdQImmediate)->getStartingCmdBuffer(); if (commandListImmediate->getCmdListBatchBufferFlag()) { diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp index 4e092cda42..a7d59b6bbf 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp @@ -1379,9 +1379,14 @@ HWTEST2_F(ExecuteCommandListTests, givenSuccessfulSubmitBatchBufferThenExecuteCo auto commandListHandle = commandList->toHandle(); commandList->close(); + auto &ultCsr = neoDevice->getUltCommandStreamReceiver(); + ultCsr.recursiveLockCounter = 0; + auto res = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(1u, ultCsr.recursiveLockCounter); + commandQueue->destroy(); commandList->destroy(); }