diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp index f6340ef0ea..bc5ac2cf60 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -701,8 +701,6 @@ HWTEST_F(CommandStreamReceiverTest, givenDebugPauseThreadWhenSettingFlagProgress while (*mockCSR->debugPauseStateAddress != DebugPauseState::hasUserEndConfirmation) ; - mockCSR->userPauseConfirmation.join(); - EXPECT_EQ(2u, confirmationCounter); auto output = testing::internal::GetCapturedStdout(); @@ -726,7 +724,6 @@ HWTEST_F(CommandStreamReceiverTest, givenDebugPauseThreadWhenTerminatingAtFirstS pDevice->resetCommandStreamReceiver(mockCSR); *mockCSR->debugPauseStateAddress = DebugPauseState::terminate; - mockCSR->userPauseConfirmation.join(); EXPECT_EQ(0u, confirmationCounter); auto output = testing::internal::GetCapturedStdout(); @@ -754,7 +751,6 @@ HWTEST_F(CommandStreamReceiverTest, givenDebugPauseThreadWhenTerminatingAtSecond ; *mockCSR->debugPauseStateAddress = DebugPauseState::terminate; - mockCSR->userPauseConfirmation.join(); auto output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr(std::string("Debug break: Press enter to start workload"))); diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index daa52b2699..672c33994d 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -49,9 +49,9 @@ CommandStreamReceiver::CommandStreamReceiver(ExecutionEnvironment &executionEnvi } CommandStreamReceiver::~CommandStreamReceiver() { - if (userPauseConfirmation.joinable()) { + if (userPauseConfirmation) { *debugPauseStateAddress = DebugPauseState::terminate; - userPauseConfirmation.join(); + userPauseConfirmation->join(); } for (int i = 0; i < IndirectHeap::NUM_TYPES; ++i) { @@ -389,6 +389,38 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptr(arg); + + auto debugPauseStateAddress = self->debugPauseStateAddress; + + while (*debugPauseStateAddress != DebugPauseState::waitingForUserStartConfirmation) { + if (*debugPauseStateAddress == DebugPauseState::terminate) { + return nullptr; + } + std::this_thread::yield(); + } + + std::cout << "Debug break: Press enter to start workload" << std::endl; + self->debugConfirmationFunction(); + + *debugPauseStateAddress = DebugPauseState::hasUserStartConfirmation; + + while (*debugPauseStateAddress != DebugPauseState::waitingForUserEndConfirmation) { + if (*debugPauseStateAddress == DebugPauseState::terminate) { + return nullptr; + } + std::this_thread::yield(); + } + + std::cout << "Debug break: Workload ended, press enter to continue" << std::endl; + self->debugConfirmationFunction(); + + *debugPauseStateAddress = DebugPauseState::hasUserEndConfirmation; + + return nullptr; +} + bool CommandStreamReceiver::initializeTagAllocation() { auto tagAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::TAG_BUFFER}); if (!tagAllocation) { @@ -400,32 +432,7 @@ bool CommandStreamReceiver::initializeTagAllocation() { *this->debugPauseStateAddress = DebugManager.flags.EnableNullHardware.get() ? DebugPauseState::disabled : DebugPauseState::waitingForFirstSemaphore; if (DebugManager.flags.PauseOnEnqueue.get() != -1) { - userPauseConfirmation = std::thread( - [this]() { - while (*debugPauseStateAddress != DebugPauseState::waitingForUserStartConfirmation) { - if (*debugPauseStateAddress == DebugPauseState::terminate) { - return; - } - std::this_thread::yield(); - } - - std::cout << "Debug break: Press enter to start workload" << std::endl; - debugConfirmationFunction(); - - *debugPauseStateAddress = DebugPauseState::hasUserStartConfirmation; - - while (*debugPauseStateAddress != DebugPauseState::waitingForUserEndConfirmation) { - if (*debugPauseStateAddress == DebugPauseState::terminate) { - return; - } - std::this_thread::yield(); - } - - std::cout << "Debug break: Workload ended, press enter to continue" << std::endl; - debugConfirmationFunction(); - - *debugPauseStateAddress = DebugPauseState::hasUserEndConfirmation; - }); + userPauseConfirmation = Thread::create(CommandStreamReceiver::asyncDebugBreakConfirmation, reinterpret_cast(this)); } return true; diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index d7a8e17a50..7c505dc609 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -18,6 +18,7 @@ #include "shared/source/helpers/options.h" #include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/kernel/grf_config.h" +#include "shared/source/os_interface/os_thread.h" #include #include @@ -251,7 +252,8 @@ class CommandStreamReceiver { // offset for debug state must be 8 bytes, if only 4 bytes are used tag writes overwrite it const uint64_t debugPauseStateAddressOffset = 8; - std::thread userPauseConfirmation; + static void *asyncDebugBreakConfirmation(void *arg); + std::unique_ptr userPauseConfirmation; std::function debugConfirmationFunction = []() { std::cin.get(); }; GraphicsAllocation *tagAllocation = nullptr;