From 1541f198ebd12e977569b1d822e3f0ded9d98387 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 27 Nov 2021 20:31:46 +0100 Subject: Core/Common: Corrections to core timing and add critical priority. --- src/common/thread.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/common/thread.cpp') diff --git a/src/common/thread.cpp b/src/common/thread.cpp index f932a72909..924f0df1b3 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -47,6 +47,9 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { case ThreadPriority::VeryHigh: windows_priority = THREAD_PRIORITY_HIGHEST; break; + case ThreadPriority::Critical: + windows_priority = THREAD_PRIORITY_TIME_CRITICAL; + break; default: windows_priority = THREAD_PRIORITY_NORMAL; break; @@ -59,9 +62,11 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { 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(new_priority) + 1; + const auto scheduling_type = + new_priority != ThreadPriority::Critical ? SCHED_OTHER : SCHED_FIFO; + s32 max_prio = sched_get_priority_max(scheduling_type); + s32 min_prio = sched_get_priority_min(scheduling_type); + u32 level = std::max(static_cast(new_priority) + 1, 4U); struct sched_param params; if (max_prio > min_prio) { @@ -70,7 +75,7 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { params.sched_priority = min_prio - ((min_prio - max_prio) * level) / 4; } - pthread_setschedparam(this_thread, SCHED_OTHER, ¶ms); + pthread_setschedparam(this_thread, scheduling_type, ¶ms); } #endif -- cgit v1.2.3 From d3becee4c0baa6034c8a211ea912296f0c8c0c85 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 28 Nov 2021 12:21:45 +0100 Subject: Core: Fix tests. --- src/common/thread.cpp | 3 +-- src/common/x64/native_clock.cpp | 1 + src/tests/core/core_timing.cpp | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/common/thread.cpp') diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 924f0df1b3..919e33af92 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -62,8 +62,7 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { void SetCurrentThreadPriority(ThreadPriority new_priority) { pthread_t this_thread = pthread_self(); - const auto scheduling_type = - new_priority != ThreadPriority::Critical ? SCHED_OTHER : SCHED_FIFO; + const auto scheduling_type = SCHED_OTHER; s32 max_prio = sched_get_priority_max(scheduling_type); s32 min_prio = sched_get_priority_min(scheduling_type); u32 level = std::max(static_cast(new_priority) + 1, 4U); diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp index 427a382cdf..0b89f9ed2e 100644 --- a/src/common/x64/native_clock.cpp +++ b/src/common/x64/native_clock.cpp @@ -5,6 +5,7 @@ #include #include +#include "common/atomic_ops.h" #include "common/uint128.h" #include "common/x64/native_clock.h" diff --git a/src/tests/core/core_timing.cpp b/src/tests/core/core_timing.cpp index 62eb437538..e687416a81 100644 --- a/src/tests/core/core_timing.cpp +++ b/src/tests/core/core_timing.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "core/core.h" @@ -21,9 +22,11 @@ std::array delays{}; std::bitset callbacks_ran_flags; u64 expected_callback = 0; +std::mutex control_mutex; template void HostCallbackTemplate(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { + std::unique_lock lk(control_mutex); static_assert(IDX < CB_IDS.size(), "IDX out of range"); callbacks_ran_flags.set(IDX); REQUIRE(CB_IDS[IDX] == user_data); -- cgit v1.2.3