diff options
| author | 2020-08-02 10:57:08 -0700 | |
|---|---|---|
| committer | 2020-08-05 20:34:49 -0700 | |
| commit | d37f0b29e26b0e6f655f801423ae6ba4f77fa9df (patch) | |
| tree | 20ebd140e8b07c86976e57a2cc2b38bfffacaedd /src | |
| parent | Merge pull request #4489 from lioncash/typesafe (diff) | |
| download | yuzu-d37f0b29e26b0e6f655f801423ae6ba4f77fa9df.tar.gz yuzu-d37f0b29e26b0e6f655f801423ae6ba4f77fa9df.tar.xz yuzu-d37f0b29e26b0e6f655f801423ae6ba4f77fa9df.zip | |
Fix thread naming on Linux, which limits names to 15 bytes.
- In `SetCurrentThreadName`, when on Linux, truncate to 15 bytes, as (at
least on glibc) `pthread_set_name_np` will otherwise return `ERANGE` and
do nothing.
- Also, add logging in case `pthread_set_name_np` returns an error
anyway. This is Linux-specific, as the Apple and BSD versions of
`pthread_set_name_np return `void`.
- Change the name for CPU threads in multi-core mode from
"yuzu:CoreCPUThread_N" (19 bytes) to "yuzu:CPUCore_N" (14 bytes) so it
fits into the Linux limit. Some other thread names are also cut off,
but I didn't bother addressing them as you can guess them from the
truncated versions. For a CPU thread, truncation means you can't see
which core it is!
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/thread.cpp | 12 | ||||
| -rw-r--r-- | src/core/cpu_manager.cpp | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 8e5935e6a..d2c1ac60d 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_funcs.h" | ||
| 6 | #include "common/logging/log.h" | ||
| 5 | #include "common/thread.h" | 7 | #include "common/thread.h" |
| 6 | #ifdef __APPLE__ | 8 | #ifdef __APPLE__ |
| 7 | #include <mach/mach.h> | 9 | #include <mach/mach.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include <unistd.h> | 21 | #include <unistd.h> |
| 20 | #endif | 22 | #endif |
| 21 | 23 | ||
| 24 | #include <string> | ||
| 25 | |||
| 22 | #ifdef __FreeBSD__ | 26 | #ifdef __FreeBSD__ |
| 23 | #define cpu_set_t cpuset_t | 27 | #define cpu_set_t cpuset_t |
| 24 | #endif | 28 | #endif |
| @@ -110,6 +114,14 @@ void SetCurrentThreadName(const char* name) { | |||
| 110 | pthread_set_name_np(pthread_self(), name); | 114 | pthread_set_name_np(pthread_self(), name); |
| 111 | #elif defined(__NetBSD__) | 115 | #elif defined(__NetBSD__) |
| 112 | pthread_setname_np(pthread_self(), "%s", (void*)name); | 116 | pthread_setname_np(pthread_self(), "%s", (void*)name); |
| 117 | #elif defined(__linux__) | ||
| 118 | // Linux limits thread names to 15 characters and will outright reject any | ||
| 119 | // attempt to set a longer name with ERANGE. | ||
| 120 | std::string truncated(name, std::min(strlen(name), static_cast<size_t>(15))); | ||
| 121 | if (int e = pthread_setname_np(pthread_self(), truncated.c_str())) { | ||
| 122 | errno = e; | ||
| 123 | LOG_ERROR(Common, "Failed to set thread name to '{}': {}", truncated, GetLastErrorMsg()); | ||
| 124 | } | ||
| 113 | #else | 125 | #else |
| 114 | pthread_setname_np(pthread_self(), name); | 126 | pthread_setname_np(pthread_self(), name); |
| 115 | #endif | 127 | #endif |
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 358943429..03651e285 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -331,7 +331,7 @@ void CpuManager::RunThread(std::size_t core) { | |||
| 331 | system.RegisterCoreThread(core); | 331 | system.RegisterCoreThread(core); |
| 332 | std::string name; | 332 | std::string name; |
| 333 | if (is_multicore) { | 333 | if (is_multicore) { |
| 334 | name = "yuzu:CoreCPUThread_" + std::to_string(core); | 334 | name = "yuzu:CPUCore_" + std::to_string(core); |
| 335 | } else { | 335 | } else { |
| 336 | name = "yuzu:CPUThread"; | 336 | name = "yuzu:CPUThread"; |
| 337 | } | 337 | } |