summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/thread.cpp12
-rw-r--r--src/common/thread.h1
-rw-r--r--src/common/uint128.h5
-rw-r--r--src/common/x64/native_clock.cpp5
-rw-r--r--src/common/x64/native_clock.h6
5 files changed, 17 insertions, 12 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index f932a7290..919e33af9 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,10 @@ 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<u32>(new_priority) + 1;
+ 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<u32>(new_priority) + 1, 4U);
struct sched_param params;
if (max_prio > min_prio) {
@@ -70,7 +74,7 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) {
params.sched_priority = min_prio - ((min_prio - max_prio) * level) / 4;
}
- pthread_setschedparam(this_thread, SCHED_OTHER, &params);
+ pthread_setschedparam(this_thread, scheduling_type, &params);
}
#endif
diff --git a/src/common/thread.h b/src/common/thread.h
index a63122516..1552f58e0 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -92,6 +92,7 @@ enum class ThreadPriority : u32 {
Normal = 1,
High = 2,
VeryHigh = 3,
+ Critical = 4,
};
void SetCurrentThreadPriority(ThreadPriority new_priority);
diff --git a/src/common/uint128.h b/src/common/uint128.h
index f890ffec2..199d0f55e 100644
--- a/src/common/uint128.h
+++ b/src/common/uint128.h
@@ -31,12 +31,17 @@ namespace Common {
return _udiv128(r[1], r[0], d, &remainder);
#endif
#else
+#ifdef __SIZEOF_INT128__
+ const auto product = static_cast<unsigned __int128>(a) * static_cast<unsigned __int128>(b);
+ return static_cast<u64>(product / d);
+#else
const u64 diva = a / d;
const u64 moda = a % d;
const u64 divb = b / d;
const u64 modb = b % d;
return diva * b + moda * divb + moda * modb / d;
#endif
+#endif
}
// This function multiplies 2 u64 values and produces a u128 value;
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 1b7194503..6aaa8cdf9 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -75,8 +75,8 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequen
}
u64 NativeClock::GetRTSC() {
- TimePoint new_time_point{};
TimePoint current_time_point{};
+ TimePoint new_time_point{};
current_time_point.pack = Common::AtomicLoad128(time_point.pack.data());
do {
@@ -89,8 +89,7 @@ u64 NativeClock::GetRTSC() {
new_time_point.inner.accumulated_ticks = current_time_point.inner.accumulated_ticks + diff;
} while (!Common::AtomicCompareAndSwap(time_point.pack.data(), new_time_point.pack,
current_time_point.pack, current_time_point.pack));
- /// The clock cannot be more precise than the guest timer, remove the lower bits
- return new_time_point.inner.accumulated_ticks & inaccuracy_mask;
+ return new_time_point.inner.accumulated_ticks;
}
void NativeClock::Pause(bool is_paused) {
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h
index 30d2ba2e9..38ae7a462 100644
--- a/src/common/x64/native_clock.h
+++ b/src/common/x64/native_clock.h
@@ -37,12 +37,8 @@ private:
} inner;
};
- /// value used to reduce the native clocks accuracy as some apss rely on
- /// undefined behavior where the level of accuracy in the clock shouldn't
- /// be higher.
- static constexpr u64 inaccuracy_mask = ~(UINT64_C(0x400) - 1);
-
TimePoint time_point;
+
// factors
u64 clock_rtsc_factor{};
u64 cpu_rtsc_factor{};