Change DebugBreak thread implementation to NEO::Thread

Change-Id: Icbb659cf7c86bbd74e6375266d9ec2ee84278597
Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2020-06-17 11:31:08 +02:00
committed by sys_ocldev
parent 3859e13322
commit d42f872d07
3 changed files with 38 additions and 33 deletions

View File

@@ -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<Experimenta
experimentalCmdBuffer = std::move(cmdBuffer);
}
void *CommandStreamReceiver::asyncDebugBreakConfirmation(void *arg) {
auto self = reinterpret_cast<CommandStreamReceiver *>(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<void *>(this));
}
return true;

View File

@@ -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 <cstddef>
#include <cstdint>
@@ -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<Thread> userPauseConfirmation;
std::function<void()> debugConfirmationFunction = []() { std::cin.get(); };
GraphicsAllocation *tagAllocation = nullptr;