summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/host_memory.cpp4
-rw-r--r--src/common/logging/filter.cpp1
-rw-r--r--src/common/logging/types.h1
-rw-r--r--src/common/thread.h2
-rw-r--r--src/common/threadsafe_queue.h4
-rw-r--r--src/common/x64/native_clock.cpp49
6 files changed, 42 insertions, 19 deletions
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index e829af1ac..802943eb7 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -149,7 +149,7 @@ public:
149 } 149 }
150 150
151 void Unmap(size_t virtual_offset, size_t length) { 151 void Unmap(size_t virtual_offset, size_t length) {
152 std::lock_guard lock{placeholder_mutex}; 152 std::scoped_lock lock{placeholder_mutex};
153 153
154 // Unmap until there are no more placeholders 154 // Unmap until there are no more placeholders
155 while (UnmapOnePlaceholder(virtual_offset, length)) { 155 while (UnmapOnePlaceholder(virtual_offset, length)) {
@@ -169,7 +169,7 @@ public:
169 } 169 }
170 const size_t virtual_end = virtual_offset + length; 170 const size_t virtual_end = virtual_offset + length;
171 171
172 std::lock_guard lock{placeholder_mutex}; 172 std::scoped_lock lock{placeholder_mutex};
173 auto [it, end] = placeholders.equal_range({virtual_offset, virtual_end}); 173 auto [it, end] = placeholders.equal_range({virtual_offset, virtual_end});
174 while (it != end) { 174 while (it != end) {
175 const size_t offset = std::max(it->lower(), virtual_offset); 175 const size_t offset = std::max(it->lower(), virtual_offset);
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
index 9120cc178..4acbff649 100644
--- a/src/common/logging/filter.cpp
+++ b/src/common/logging/filter.cpp
@@ -101,6 +101,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
101 SUB(Service, GRC) \ 101 SUB(Service, GRC) \
102 SUB(Service, HID) \ 102 SUB(Service, HID) \
103 SUB(Service, IRS) \ 103 SUB(Service, IRS) \
104 SUB(Service, JIT) \
104 SUB(Service, LBL) \ 105 SUB(Service, LBL) \
105 SUB(Service, LDN) \ 106 SUB(Service, LDN) \
106 SUB(Service, LDR) \ 107 SUB(Service, LDR) \
diff --git a/src/common/logging/types.h b/src/common/logging/types.h
index f803ab796..99c15fa96 100644
--- a/src/common/logging/types.h
+++ b/src/common/logging/types.h
@@ -69,6 +69,7 @@ enum class Class : u8 {
69 Service_GRC, ///< The game recording service 69 Service_GRC, ///< The game recording service
70 Service_HID, ///< The HID (Human interface device) service 70 Service_HID, ///< The HID (Human interface device) service
71 Service_IRS, ///< The IRS service 71 Service_IRS, ///< The IRS service
72 Service_JIT, ///< The JIT service
72 Service_LBL, ///< The LBL (LCD backlight) service 73 Service_LBL, ///< The LBL (LCD backlight) service
73 Service_LDN, ///< The LDN (Local domain network) service 74 Service_LDN, ///< The LDN (Local domain network) service
74 Service_LDR, ///< The loader service 75 Service_LDR, ///< The loader service
diff --git a/src/common/thread.h b/src/common/thread.h
index a8c17c71a..626609372 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -17,7 +17,7 @@ namespace Common {
17class Event { 17class Event {
18public: 18public:
19 void Set() { 19 void Set() {
20 std::lock_guard lk{mutex}; 20 std::scoped_lock lk{mutex};
21 if (!is_set) { 21 if (!is_set) {
22 is_set = true; 22 is_set = true;
23 condvar.notify_one(); 23 condvar.notify_one();
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h
index 2c8c2b90e..7272ac6e8 100644
--- a/src/common/threadsafe_queue.h
+++ b/src/common/threadsafe_queue.h
@@ -52,7 +52,7 @@ public:
52 // line before cv.wait 52 // line before cv.wait
53 // TODO(bunnei): This can be replaced with C++20 waitable atomics when properly supported. 53 // TODO(bunnei): This can be replaced with C++20 waitable atomics when properly supported.
54 // See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details. 54 // See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details.
55 std::lock_guard lock{cv_mutex}; 55 std::scoped_lock lock{cv_mutex};
56 cv.notify_one(); 56 cv.notify_one();
57 } 57 }
58 58
@@ -159,7 +159,7 @@ public:
159 159
160 template <typename Arg> 160 template <typename Arg>
161 void Push(Arg&& t) { 161 void Push(Arg&& t) {
162 std::lock_guard lock{write_lock}; 162 std::scoped_lock lock{write_lock};
163 spsc_queue.Push(t); 163 spsc_queue.Push(t);
164 } 164 }
165 165
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 7a3f21dcf..7fd9d22f8 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -10,25 +10,49 @@
10#include "common/uint128.h" 10#include "common/uint128.h"
11#include "common/x64/native_clock.h" 11#include "common/x64/native_clock.h"
12 12
13#ifdef _MSC_VER
14#include <intrin.h>
15#endif
16
13namespace Common { 17namespace Common {
14 18
19#ifdef _MSC_VER
20__forceinline static u64 FencedRDTSC() {
21 _mm_lfence();
22 _ReadWriteBarrier();
23 const u64 result = __rdtsc();
24 _mm_lfence();
25 _ReadWriteBarrier();
26 return result;
27}
28#else
29static u64 FencedRDTSC() {
30 u64 result;
31 asm volatile("lfence\n\t"
32 "rdtsc\n\t"
33 "shl $32, %%rdx\n\t"
34 "or %%rdx, %0\n\t"
35 "lfence"
36 : "=a"(result)
37 :
38 : "rdx", "memory", "cc");
39 return result;
40}
41#endif
42
15u64 EstimateRDTSCFrequency() { 43u64 EstimateRDTSCFrequency() {
16 // Discard the first result measuring the rdtsc. 44 // Discard the first result measuring the rdtsc.
17 _mm_mfence(); 45 FencedRDTSC();
18 __rdtsc();
19 std::this_thread::sleep_for(std::chrono::milliseconds{1}); 46 std::this_thread::sleep_for(std::chrono::milliseconds{1});
20 _mm_mfence(); 47 FencedRDTSC();
21 __rdtsc();
22 48
23 // Get the current time. 49 // Get the current time.
24 const auto start_time = std::chrono::steady_clock::now(); 50 const auto start_time = std::chrono::steady_clock::now();
25 _mm_mfence(); 51 const u64 tsc_start = FencedRDTSC();
26 const u64 tsc_start = __rdtsc();
27 // Wait for 200 milliseconds. 52 // Wait for 200 milliseconds.
28 std::this_thread::sleep_for(std::chrono::milliseconds{200}); 53 std::this_thread::sleep_for(std::chrono::milliseconds{200});
29 const auto end_time = std::chrono::steady_clock::now(); 54 const auto end_time = std::chrono::steady_clock::now();
30 _mm_mfence(); 55 const u64 tsc_end = FencedRDTSC();
31 const u64 tsc_end = __rdtsc();
32 // Calculate differences. 56 // Calculate differences.
33 const u64 timer_diff = static_cast<u64>( 57 const u64 timer_diff = static_cast<u64>(
34 std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count()); 58 std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count());
@@ -42,8 +66,7 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequen
42 u64 rtsc_frequency_) 66 u64 rtsc_frequency_)
43 : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, true), rtsc_frequency{ 67 : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, true), rtsc_frequency{
44 rtsc_frequency_} { 68 rtsc_frequency_} {
45 _mm_mfence(); 69 time_point.inner.last_measure = FencedRDTSC();
46 time_point.inner.last_measure = __rdtsc();
47 time_point.inner.accumulated_ticks = 0U; 70 time_point.inner.accumulated_ticks = 0U;
48 ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency); 71 ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency);
49 us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency); 72 us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency);
@@ -58,8 +81,7 @@ u64 NativeClock::GetRTSC() {
58 81
59 current_time_point.pack = Common::AtomicLoad128(time_point.pack.data()); 82 current_time_point.pack = Common::AtomicLoad128(time_point.pack.data());
60 do { 83 do {
61 _mm_mfence(); 84 const u64 current_measure = FencedRDTSC();
62 const u64 current_measure = __rdtsc();
63 u64 diff = current_measure - current_time_point.inner.last_measure; 85 u64 diff = current_measure - current_time_point.inner.last_measure;
64 diff = diff & ~static_cast<u64>(static_cast<s64>(diff) >> 63); // max(diff, 0) 86 diff = diff & ~static_cast<u64>(static_cast<s64>(diff) >> 63); // max(diff, 0)
65 new_time_point.inner.last_measure = current_measure > current_time_point.inner.last_measure 87 new_time_point.inner.last_measure = current_measure > current_time_point.inner.last_measure
@@ -80,8 +102,7 @@ void NativeClock::Pause(bool is_paused) {
80 current_time_point.pack = Common::AtomicLoad128(time_point.pack.data()); 102 current_time_point.pack = Common::AtomicLoad128(time_point.pack.data());
81 do { 103 do {
82 new_time_point.pack = current_time_point.pack; 104 new_time_point.pack = current_time_point.pack;
83 _mm_mfence(); 105 new_time_point.inner.last_measure = FencedRDTSC();
84 new_time_point.inner.last_measure = __rdtsc();
85 } while (!Common::AtomicCompareAndSwap(time_point.pack.data(), new_time_point.pack, 106 } while (!Common::AtomicCompareAndSwap(time_point.pack.data(), new_time_point.pack,
86 current_time_point.pack, current_time_point.pack)); 107 current_time_point.pack, current_time_point.pack));
87 } 108 }