From 59cd0a9c7ffc7d4e6b03b1f4efc2d63f8aa40dc4 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 1 Nov 2017 01:49:54 +0300 Subject: [PATCH] Implement set_native_priority (posix) --- Utilities/Thread.cpp | 32 ++++++++++++++++++---------- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 6 ++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 9a3034c49e..6fca5cc54c 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1884,20 +1884,30 @@ void thread_ctrl::set_native_priority(int priority) HANDLE _this_thread = GetCurrentThread(); INT native_priority = THREAD_PRIORITY_NORMAL; - switch (priority) - { - default: - case 0: - break; - case 1: + if (priority > 0) native_priority = THREAD_PRIORITY_ABOVE_NORMAL; - break; - case -1: + if (priority < 0) native_priority = THREAD_PRIORITY_BELOW_NORMAL; - break; - } - SetThreadPriority(_this_thread, native_priority); + if (!SetThreadPriority(_this_thread, native_priority)) + { + LOG_ERROR(GENERAL, "SetThreadPriority() failed: 0x%x", GetLastError()); + } +#else + int policy; + struct sched_param param; + + pthread_getschedparam(pthread_self(), &policy, ¶m); + + if (priority > 0) + param.sched_priority = sched_get_priority_max(policy); + if (priority < 0) + param.sched_priority = sched_get_priority_min(policy); + + if (int err = pthread_setschedparam(pthread_self(), policy, ¶m)) + { + LOG_ERROR(GENERAL, "pthraed_setschedparam() failed: %d", err); + } #endif } diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 10eff03b31..732fe985bb 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -57,6 +57,8 @@ void audio_config::on_init(const std::shared_ptr& _this) void audio_config::on_task() { + thread_ctrl::set_native_priority(1); + AudioDumper m_dump(g_cfg.audio.dump_to_file ? 2 : 0); // Init AudioDumper for 2 channels if enabled float buf2ch[2 * BUFFER_SIZE]{}; // intermediate buffer for 2 channels @@ -337,8 +339,8 @@ void audio_config::on_task() case 8: m_dump.WriteData(&buf8ch, sizeof(buf8ch)); break; // write file data (8 ch) } - cellAudio.trace("Audio perf: start=%d (access=%d, AddData=%d, events=%d, dump=%d)", - time_pos, stamp1 - stamp0, stamp2 - stamp1, stamp3 - stamp2, get_system_time() - stamp3); + cellAudio.trace("Audio perf: (access=%d, AddData=%d, events=%d, dump=%d)", + stamp1 - stamp0, stamp2 - stamp1, stamp3 - stamp2, get_system_time() - stamp3); } }