Fix thread name setting

We utilize `pthread_setname_np` to set the thread names but didn't check for any errors which resulted in the `Skyline-Choreographer` and `ChannelCmdFifo` not having proper names as they exceeded the 16 character limit on thread names for the pthread function.  This has now been fixed by changing the names and introducing error checking to invocations of this function.
This commit is contained in:
PixelyIon 2022-06-09 22:10:44 +05:30
parent 7a0cfb484c
commit 6e09dc5204
No known key found for this signature in database
GPG Key ID: 11BC6C3201BC2C05
4 changed files with 16 additions and 8 deletions

View File

@ -65,7 +65,9 @@ namespace skyline::gpu {
}
void PresentationEngine::ChoreographerThread() {
pthread_setname_np(pthread_self(), "Skyline-Choreographer");
if (int result{pthread_setname_np(pthread_self(), "Sky-Choreo")})
Logger::Warn("Failed to set the thread name: {}", strerror(result));
try {
signal::SetSignalHandler({SIGINT, SIGILL, SIGTRAP, SIGBUS, SIGFPE, SIGSEGV}, signal::ExceptionalSignalHandler);
choreographerLooper = ALooper_prepare(0);

View File

@ -35,9 +35,12 @@ namespace skyline::kernel::type {
}
void KThread::StartThread() {
std::array<char, 16> threadName;
pthread_getname_np(pthread, threadName.data(), threadName.size());
pthread_setname_np(pthread, fmt::format("HOS-{}", id).c_str());
std::array<char, 16> threadName{};
if (int result{pthread_getname_np(pthread, threadName.data(), threadName.size())})
Logger::Warn("Failed to get the thread name: {}", strerror(result));
if (int result{pthread_setname_np(pthread, fmt::format("HOS-{}", id).c_str())})
Logger::Warn("Failed to set the thread name: {}", strerror(result));
Logger::UpdateTag();
if (!ctx.tpidrroEl0)
@ -60,7 +63,8 @@ namespace skyline::kernel::type {
Signal();
if (threadName[0] != 'H' || threadName[1] != 'O' || threadName[2] != 'S' || threadName[3] != '-') {
pthread_setname_np(pthread, threadName.data());
if (int result{pthread_setname_np(pthread, threadName.data())})
Logger::Warn("Failed to set the thread name: {}", strerror(result));
Logger::UpdateTag();
}

View File

@ -340,7 +340,9 @@ namespace skyline::soc::gm20b {
}
void ChannelGpfifo::Run() {
pthread_setname_np(pthread_self(), "GPFIFO");
if (int result{pthread_setname_np(pthread_self(), "GPFIFO")})
Logger::Warn("Failed to set the thread name: {}", strerror(result));
try {
signal::SetSignalHandler({SIGINT, SIGILL, SIGTRAP, SIGBUS, SIGFPE}, signal::ExceptionalSignalHandler);
signal::SetSignalHandler({SIGSEGV}, nce::NCE::HostSignalHandler); // We may access NCE trapped memory

View File

@ -114,8 +114,8 @@ namespace skyline::soc::host1x {
}
void ChannelCommandFifo::Run() {
pthread_setname_np(pthread_self(), "ChannelCommandFifo");
Logger::UpdateTag();
if (int result{pthread_setname_np(pthread_self(), "ChannelCmdFifo")})
Logger::Warn("Failed to set the thread name: {}", strerror(result));
try {
signal::SetSignalHandler({SIGINT, SIGILL, SIGTRAP, SIGBUS, SIGFPE}, signal::ExceptionalSignalHandler);