From 6e09dc5204e6670312b93aed16418ce7d8c2ddfc Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Thu, 9 Jun 2022 22:10:44 +0530 Subject: [PATCH] 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. --- app/src/main/cpp/skyline/gpu/presentation_engine.cpp | 4 +++- app/src/main/cpp/skyline/kernel/types/KThread.cpp | 12 ++++++++---- app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp | 4 +++- app/src/main/cpp/skyline/soc/host1x/command_fifo.cpp | 4 ++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index b6d8858d..87643ecb 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -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); diff --git a/app/src/main/cpp/skyline/kernel/types/KThread.cpp b/app/src/main/cpp/skyline/kernel/types/KThread.cpp index 8cb39ade..1ecc5e65 100644 --- a/app/src/main/cpp/skyline/kernel/types/KThread.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KThread.cpp @@ -35,9 +35,12 @@ namespace skyline::kernel::type { } void KThread::StartThread() { - std::array threadName; - pthread_getname_np(pthread, threadName.data(), threadName.size()); - pthread_setname_np(pthread, fmt::format("HOS-{}", id).c_str()); + std::array 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(); } diff --git a/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp b/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp index c9d5b996..189d04e2 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp @@ -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 diff --git a/app/src/main/cpp/skyline/soc/host1x/command_fifo.cpp b/app/src/main/cpp/skyline/soc/host1x/command_fifo.cpp index 6c9b132a..ff67e7a6 100644 --- a/app/src/main/cpp/skyline/soc/host1x/command_fifo.cpp +++ b/app/src/main/cpp/skyline/soc/host1x/command_fifo.cpp @@ -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);