diff options
| author | 2020-04-05 09:48:53 -0400 | |
|---|---|---|
| committer | 2020-06-27 11:36:09 -0400 | |
| commit | 528b19a84287167d7699465e495b196d216b99db (patch) | |
| tree | c3ac61644c1a11fd1cf5ceeb70d1c9f5d4a00aa3 /src | |
| parent | Dynarmic Interface: don't clear cache if JIT has not been created. (diff) | |
| download | yuzu-528b19a84287167d7699465e495b196d216b99db.tar.gz yuzu-528b19a84287167d7699465e495b196d216b99db.tar.xz yuzu-528b19a84287167d7699465e495b196d216b99db.zip | |
General: Tune the priority of main emulation threads so they have higher priority than less important helper threads.
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/thread.cpp | 46 | ||||
| -rw-r--r-- | src/common/thread.h | 9 | ||||
| -rw-r--r-- | src/core/core_timing.cpp | 1 | ||||
| -rw-r--r-- | src/core/cpu_manager.cpp | 1 | ||||
| -rw-r--r-- | src/video_core/gpu_thread.cpp | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_scheduler.cpp | 2 |
6 files changed, 60 insertions, 0 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index c9684aed9..33c8437f5 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -25,6 +25,52 @@ | |||
| 25 | 25 | ||
| 26 | namespace Common { | 26 | namespace Common { |
| 27 | 27 | ||
| 28 | #ifdef _WIN32 | ||
| 29 | |||
| 30 | void SetCurrentThreadPriority(ThreadPriority new_priority) { | ||
| 31 | auto handle = GetCurrentThread(); | ||
| 32 | int windows_priority = 0; | ||
| 33 | switch (new_priority) { | ||
| 34 | case ThreadPriority::Low: | ||
| 35 | windows_priority = THREAD_PRIORITY_BELOW_NORMAL; | ||
| 36 | break; | ||
| 37 | case ThreadPriority::Normal: | ||
| 38 | windows_priority = THREAD_PRIORITY_NORMAL; | ||
| 39 | break; | ||
| 40 | case ThreadPriority::High: | ||
| 41 | windows_priority = THREAD_PRIORITY_ABOVE_NORMAL; | ||
| 42 | break; | ||
| 43 | case ThreadPriority::VeryHigh: | ||
| 44 | windows_priority = THREAD_PRIORITY_HIGHEST; | ||
| 45 | break; | ||
| 46 | default: | ||
| 47 | windows_priority = THREAD_PRIORITY_NORMAL; | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | SetThreadPriority(handle, windows_priority); | ||
| 51 | } | ||
| 52 | |||
| 53 | #else | ||
| 54 | |||
| 55 | void SetCurrentThreadPriority(ThreadPriority new_priority) { | ||
| 56 | pthread_t this_thread = pthread_self(); | ||
| 57 | |||
| 58 | s32 max_prio = sched_get_priority_max(SCHED_OTHER); | ||
| 59 | s32 min_prio = sched_get_priority_min(SCHED_OTHER); | ||
| 60 | u32 level = static_cast<u32>(new_priority) + 1; | ||
| 61 | |||
| 62 | struct sched_param params; | ||
| 63 | if (max_prio > min_prio) { | ||
| 64 | params.sched_priority = min_prio + ((max_prio - min_prio) * level) / 4; | ||
| 65 | } else { | ||
| 66 | params.sched_priority = min_prio - ((min_prio - max_prio) * level) / 4; | ||
| 67 | } | ||
| 68 | |||
| 69 | pthread_setschedparam(this_thread, SCHED_OTHER, ¶ms); | ||
| 70 | } | ||
| 71 | |||
| 72 | #endif | ||
| 73 | |||
| 28 | #ifdef _MSC_VER | 74 | #ifdef _MSC_VER |
| 29 | 75 | ||
| 30 | // Sets the debugger-visible name of the current thread. | 76 | // Sets the debugger-visible name of the current thread. |
diff --git a/src/common/thread.h b/src/common/thread.h index 127cc7e23..52b359413 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -86,6 +86,15 @@ private: | |||
| 86 | std::size_t generation = 0; // Incremented once each time the barrier is used | 86 | std::size_t generation = 0; // Incremented once each time the barrier is used |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | enum class ThreadPriority : u32 { | ||
| 90 | Low = 0, | ||
| 91 | Normal = 1, | ||
| 92 | High = 2, | ||
| 93 | VeryHigh = 3, | ||
| 94 | }; | ||
| 95 | |||
| 96 | void SetCurrentThreadPriority(ThreadPriority new_priority); | ||
| 97 | |||
| 89 | void SetCurrentThreadName(const char* name); | 98 | void SetCurrentThreadName(const char* name); |
| 90 | 99 | ||
| 91 | } // namespace Common | 100 | } // namespace Common |
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index b02119494..032b29e33 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -48,6 +48,7 @@ void CoreTiming::ThreadEntry(CoreTiming& instance) { | |||
| 48 | std::string name = "yuzu:HostTiming"; | 48 | std::string name = "yuzu:HostTiming"; |
| 49 | MicroProfileOnThreadCreate(name.c_str()); | 49 | MicroProfileOnThreadCreate(name.c_str()); |
| 50 | Common::SetCurrentThreadName(name.c_str()); | 50 | Common::SetCurrentThreadName(name.c_str()); |
| 51 | Common::SetCurrentThreadPriority(Common::ThreadPriority::VeryHigh); | ||
| 51 | instance.on_thread_init(); | 52 | instance.on_thread_init(); |
| 52 | instance.ThreadLoop(); | 53 | instance.ThreadLoop(); |
| 53 | } | 54 | } |
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 63c578852..32afcf3ae 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -337,6 +337,7 @@ void CpuManager::RunThread(std::size_t core) { | |||
| 337 | } | 337 | } |
| 338 | MicroProfileOnThreadCreate(name.c_str()); | 338 | MicroProfileOnThreadCreate(name.c_str()); |
| 339 | Common::SetCurrentThreadName(name.c_str()); | 339 | Common::SetCurrentThreadName(name.c_str()); |
| 340 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); | ||
| 340 | auto& data = core_data[core]; | 341 | auto& data = core_data[core]; |
| 341 | data.enter_barrier = std::make_unique<Common::Event>(); | 342 | data.enter_barrier = std::make_unique<Common::Event>(); |
| 342 | data.exit_barrier = std::make_unique<Common::Event>(); | 343 | data.exit_barrier = std::make_unique<Common::Event>(); |
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 323185bfc..738c6f0c1 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp | |||
| @@ -22,6 +22,7 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, | |||
| 22 | std::string name = "yuzu:GPU"; | 22 | std::string name = "yuzu:GPU"; |
| 23 | MicroProfileOnThreadCreate(name.c_str()); | 23 | MicroProfileOnThreadCreate(name.c_str()); |
| 24 | Common::SetCurrentThreadName(name.c_str()); | 24 | Common::SetCurrentThreadName(name.c_str()); |
| 25 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); | ||
| 25 | system.RegisterHostThread(); | 26 | system.RegisterHostThread(); |
| 26 | 27 | ||
| 27 | // Wait for first GPU command before acquiring the window context | 28 | // Wait for first GPU command before acquiring the window context |
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index 82ec9180e..56524e6f3 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <utility> | 9 | #include <utility> |
| 10 | 10 | ||
| 11 | #include "common/microprofile.h" | 11 | #include "common/microprofile.h" |
| 12 | #include "common/thread.h" | ||
| 12 | #include "video_core/renderer_vulkan/vk_device.h" | 13 | #include "video_core/renderer_vulkan/vk_device.h" |
| 13 | #include "video_core/renderer_vulkan/vk_query_cache.h" | 14 | #include "video_core/renderer_vulkan/vk_query_cache.h" |
| 14 | #include "video_core/renderer_vulkan/vk_resource_manager.h" | 15 | #include "video_core/renderer_vulkan/vk_resource_manager.h" |
| @@ -133,6 +134,7 @@ void VKScheduler::BindGraphicsPipeline(VkPipeline pipeline) { | |||
| 133 | } | 134 | } |
| 134 | 135 | ||
| 135 | void VKScheduler::WorkerThread() { | 136 | void VKScheduler::WorkerThread() { |
| 137 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); | ||
| 136 | std::unique_lock lock{mutex}; | 138 | std::unique_lock lock{mutex}; |
| 137 | do { | 139 | do { |
| 138 | cv.wait(lock, [this] { return !chunk_queue.Empty() || quit; }); | 140 | cv.wait(lock, [this] { return !chunk_queue.Empty() || quit; }); |