summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2020-04-05 15:48:53 +0200
committerFernando Sahmkow <fsahmkow27@gmail.com>2020-06-27 17:36:09 +0200
commit528b19a84287167d7699465e495b196d216b99db (patch)
treec3ac61644c1a11fd1cf5ceeb70d1c9f5d4a00aa3
parentDynarmic Interface: don't clear cache if JIT has not been created. (diff)
downloadyuzu-528b19a84287167d7699465e495b196d216b99db.tar
yuzu-528b19a84287167d7699465e495b196d216b99db.tar.gz
yuzu-528b19a84287167d7699465e495b196d216b99db.tar.bz2
yuzu-528b19a84287167d7699465e495b196d216b99db.tar.lz
yuzu-528b19a84287167d7699465e495b196d216b99db.tar.xz
yuzu-528b19a84287167d7699465e495b196d216b99db.tar.zst
yuzu-528b19a84287167d7699465e495b196d216b99db.zip
Diffstat (limited to '')
-rw-r--r--src/common/thread.cpp46
-rw-r--r--src/common/thread.h9
-rw-r--r--src/core/core_timing.cpp1
-rw-r--r--src/core/cpu_manager.cpp1
-rw-r--r--src/video_core/gpu_thread.cpp1
-rw-r--r--src/video_core/renderer_vulkan/vk_scheduler.cpp2
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 @@
namespace Common {
+#ifdef _WIN32
+
+void SetCurrentThreadPriority(ThreadPriority new_priority) {
+ auto handle = GetCurrentThread();
+ int windows_priority = 0;
+ switch (new_priority) {
+ case ThreadPriority::Low:
+ windows_priority = THREAD_PRIORITY_BELOW_NORMAL;
+ break;
+ case ThreadPriority::Normal:
+ windows_priority = THREAD_PRIORITY_NORMAL;
+ break;
+ case ThreadPriority::High:
+ windows_priority = THREAD_PRIORITY_ABOVE_NORMAL;
+ break;
+ case ThreadPriority::VeryHigh:
+ windows_priority = THREAD_PRIORITY_HIGHEST;
+ break;
+ default:
+ windows_priority = THREAD_PRIORITY_NORMAL;
+ break;
+ }
+ SetThreadPriority(handle, windows_priority);
+}
+
+#else
+
+void SetCurrentThreadPriority(ThreadPriority new_priority) {
+ pthread_t this_thread = pthread_self();
+
+ s32 max_prio = sched_get_priority_max(SCHED_OTHER);
+ s32 min_prio = sched_get_priority_min(SCHED_OTHER);
+ u32 level = static_cast<u32>(new_priority) + 1;
+
+ struct sched_param params;
+ if (max_prio > min_prio) {
+ params.sched_priority = min_prio + ((max_prio - min_prio) * level) / 4;
+ } else {
+ params.sched_priority = min_prio - ((min_prio - max_prio) * level) / 4;
+ }
+
+ pthread_setschedparam(this_thread, SCHED_OTHER, &params);
+}
+
+#endif
+
#ifdef _MSC_VER
// 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:
std::size_t generation = 0; // Incremented once each time the barrier is used
};
+enum class ThreadPriority : u32 {
+ Low = 0,
+ Normal = 1,
+ High = 2,
+ VeryHigh = 3,
+};
+
+void SetCurrentThreadPriority(ThreadPriority new_priority);
+
void SetCurrentThreadName(const char* name);
} // 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) {
std::string name = "yuzu:HostTiming";
MicroProfileOnThreadCreate(name.c_str());
Common::SetCurrentThreadName(name.c_str());
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::VeryHigh);
instance.on_thread_init();
instance.ThreadLoop();
}
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) {
}
MicroProfileOnThreadCreate(name.c_str());
Common::SetCurrentThreadName(name.c_str());
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
auto& data = core_data[core];
data.enter_barrier = std::make_unique<Common::Event>();
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,
std::string name = "yuzu:GPU";
MicroProfileOnThreadCreate(name.c_str());
Common::SetCurrentThreadName(name.c_str());
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
system.RegisterHostThread();
// 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 @@
#include <utility>
#include "common/microprofile.h"
+#include "common/thread.h"
#include "video_core/renderer_vulkan/vk_device.h"
#include "video_core/renderer_vulkan/vk_query_cache.h"
#include "video_core/renderer_vulkan/vk_resource_manager.h"
@@ -133,6 +134,7 @@ void VKScheduler::BindGraphicsPipeline(VkPipeline pipeline) {
}
void VKScheduler::WorkerThread() {
+ Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
std::unique_lock lock{mutex};
do {
cv.wait(lock, [this] { return !chunk_queue.Empty() || quit; });