From 4bc22797bb7a7d3826d2da717f74d55bbbebd9f5 Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 5 Jun 2026 00:58:07 +0000 Subject: [PATCH] [core] move event creation to attached Core::System, remove unused atomics/prevent false share on Core::Timing Signed-off-by: lizzie --- src/audio_core/device/device_session.cpp | 8 ++- src/core/core.cpp | 4 ++ src/core/core.h | 3 + src/core/core_timing.cpp | 59 +++++-------------- src/core/core_timing.h | 44 ++++---------- src/core/hle/kernel/k_hardware_timer.cpp | 9 ++- src/core/hle/kernel/kernel.cpp | 2 +- .../hle/service/glue/time/alarm_worker.cpp | 13 ++-- src/core/hle/service/glue/time/worker.cpp | 29 ++++----- src/core/hle/service/hid/hidbus.cpp | 17 ++---- src/core/hle/service/vi/conductor.cpp | 24 +++----- src/core/memory/cheat_engine.cpp | 12 ++-- src/core/tools/freezer.cpp | 12 ++-- src/core/tools/freezer.h | 12 ++-- src/hid_core/resource_manager.cpp | 55 +++++++---------- src/qt_common/qt_common.cpp | 7 +-- src/tests/core/core_timing.cpp | 22 +++---- src/yuzu_cmd/yuzu.cpp | 1 - 18 files changed, 122 insertions(+), 211 deletions(-) diff --git a/src/audio_core/device/device_session.cpp b/src/audio_core/device/device_session.cpp index 2a1ae1bb3f..b0e91b42ca 100644 --- a/src/audio_core/device/device_session.cpp +++ b/src/audio_core/device/device_session.cpp @@ -19,9 +19,11 @@ using namespace std::literals; constexpr auto INCREMENT_TIME{5ms}; DeviceSession::DeviceSession(Core::System& system_) - : system{system_}, thread_event{Core::Timing::CreateEvent( - "AudioOutSampleTick", - [this](s64 time, std::chrono::nanoseconds) { return ThreadFunc(); })} {} + : system{system_} + , thread_event{system_.CreateEvent("AudioOutSampleTick", [this](s64 time, std::chrono::nanoseconds) { + return ThreadFunc(); + })} +{} DeviceSession::~DeviceSession() { Finalize(); diff --git a/src/core/core.cpp b/src/core/core.cpp index e730b808e0..a6936f3eeb 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -968,4 +968,8 @@ void System::ApplySettings() { } } +std::shared_ptr System::CreateEvent(std::string name, Core::Timing::TimedCallback&& callback) { + return std::make_shared(std::move(callback), std::move(name)); +} + } // namespace Core diff --git a/src/core/core.h b/src/core/core.h index 012533c1fa..af7ae582fa 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -19,6 +19,7 @@ #include "core/file_sys/vfs/vfs_types.h" #include "core/hle/service/os/event.h" #include "core/hle/service/kernel_helpers.h" +#include "core/core_timing.h" namespace Core::Frontend { class EmuWindow; @@ -438,6 +439,8 @@ public: /// Applies any changes to settings to this core instance. void ApplySettings(); + std::shared_ptr CreateEvent(std::string name, Core::Timing::TimedCallback&& callback); + private: struct Impl; std::unique_ptr impl; diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 3e4e7bdc68..4045a2f268 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -23,10 +23,6 @@ namespace Core::Timing { constexpr s64 MAX_SLICE_LENGTH = 10000; -std::shared_ptr CreateEvent(std::string name, TimedCallback&& callback) { - return std::make_shared(std::move(callback), std::move(name)); -} - struct CoreTiming::Event { s64 time; u64 fifo_order; @@ -36,11 +32,10 @@ struct CoreTiming::Event { // Sort by time, unless the times are the same, in which case sort by // the order added to the queue - friend bool operator>(const Event& left, const Event& right) { + friend bool operator>(const Event& left, const Event& right) noexcept { return std::tie(left.time, left.fifo_order) > std::tie(right.time, right.fifo_order); } - - friend bool operator<(const Event& left, const Event& right) { + friend bool operator<(const Event& left, const Event& right) noexcept { return std::tie(left.time, left.fifo_order) < std::tie(right.time, right.fifo_order); } }; @@ -60,8 +55,6 @@ void CoreTiming::Initialize(std::function&& on_thread_init_) { Common::SetCurrentThreadName("HostTiming"); Common::SetCurrentThreadPriority(Common::ThreadPriority::High); on_thread_init(); - has_started = true; - // base frequency in MHz: 1ns (10^-9) = 1GHz (10^9) while (!stop_token.stop_requested()) { while (!paused && !stop_token.stop_requested()) { @@ -77,8 +70,8 @@ void CoreTiming::Initialize(std::function&& on_thread_init_) { // continue. wait_set = true; event.Wait(); + wait_set = false; } - wait_set = false; } paused_set = true; pause_event.Wait(); @@ -144,39 +137,28 @@ void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future, event.Set(); } -void CoreTiming::ScheduleLoopingEvent(std::chrono::nanoseconds start_time, - std::chrono::nanoseconds resched_time, - const std::shared_ptr& event_type, - bool absolute_time) { +void CoreTiming::ScheduleLoopingEvent(std::chrono::nanoseconds start_time, std::chrono::nanoseconds resched_time, const std::shared_ptr& event_type, bool absolute_time) { { std::scoped_lock scope{basic_lock}; const auto next_time{absolute_time ? start_time : GetGlobalTimeNs() + start_time}; - - auto h{event_queue.emplace( - Event{next_time.count(), event_fifo_id++, event_type, resched_time.count()})}; + auto h = event_queue.emplace(Event{next_time.count(), event_fifo_id++, event_type, resched_time.count()}); (*h).handle = h; } - event.Set(); } -void CoreTiming::UnscheduleEvent(const std::shared_ptr& event_type, - UnscheduleEventType type) { +void CoreTiming::UnscheduleEvent(const std::shared_ptr& event_type, UnscheduleEventType type) { { std::scoped_lock lk{basic_lock}; - std::vector to_remove; - for (auto itr = event_queue.begin(); itr != event_queue.end(); itr++) { - const Event& e = *itr; + for (auto it = event_queue.begin(); it != event_queue.end(); it++) { + auto const& e = *it; if (e.type.lock().get() == event_type.get()) { - to_remove.push_back(itr->handle); + to_remove.push_back(it->handle); } } - - for (auto& h : to_remove) { + for (auto& h : to_remove) event_queue.erase(h); - } - event_type->sequence_number++; } @@ -187,16 +169,15 @@ void CoreTiming::UnscheduleEvent(const std::shared_ptr& event_type, } static u64 GetNextTickCount(u64 next_ticks) { - if (Settings::values.use_custom_cpu_ticks.GetValue()) { + if (Settings::values.use_custom_cpu_ticks.GetValue()) return Settings::values.cpu_ticks.GetValue(); - } return next_ticks; } void CoreTiming::AddTicks(u64 ticks_to_add) { const u64 ticks = GetNextTickCount(ticks_to_add); cpu_ticks += ticks; - downcount -= static_cast(ticks); + downcount -= s64(ticks); } void CoreTiming::Idle() { @@ -270,19 +251,14 @@ std::optional CoreTiming::Advance() { next_time = pause_end_time + next_schedule_time; } - event_queue.update(evt.handle, Event{next_time, event_fifo_id++, evt.type, - next_schedule_time, evt.handle}); + event_queue.update(evt.handle, Event{next_time, event_fifo_id++, evt.type, next_schedule_time, evt.handle}); } } global_timer = GetGlobalTimeNs().count(); } - if (!event_queue.empty()) { - return event_queue.top().time; - } else { - return std::nullopt; - } + return event_queue.empty() ? std::optional{} : event_queue.top().time; } void CoreTiming::Reset() { @@ -293,7 +269,6 @@ void CoreTiming::Reset() { timer_thread.request_stop(); timer_thread.join(); } - has_started = false; } /// @brief Returns current time in nanoseconds. @@ -310,10 +285,4 @@ std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const noexcept { : std::chrono::microseconds{Common::WallClock::CPUTickToUS(cpu_ticks)}; } -#ifdef _WIN32 -void CoreTiming::SetTimerResolutionNs(std::chrono::nanoseconds ns) { - timer_resolution_ns = ns.count(); -} -#endif - } // namespace Core::Timing diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 298fc9595d..c03e95d9f7 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h @@ -29,8 +29,7 @@ using TimedCallback = std::function( /// Contains the characteristics of a particular event. struct EventType { - explicit EventType(TimedCallback&& callback_, std::string&& name_) - : callback{std::move(callback_)}, name{std::move(name_)}, sequence_number{0} {} + explicit EventType(TimedCallback&& callback_, std::string&& name_) : callback{std::move(callback_)}, name{std::move(name_)}, sequence_number{0} {} /// The event's callback function. TimedCallback callback; @@ -90,11 +89,6 @@ public: /// Checks if core timing is running. bool IsRunning() const; - /// Checks if the timer thread has started. - bool HasStarted() const { - return has_started; - } - /// Checks if there are any pending time events. bool HasPendingEvents() const; @@ -134,45 +128,29 @@ public: /// Checks for events manually and returns time in nanoseconds for next event, threadsafe. std::optional Advance(); -#ifdef _WIN32 - void SetTimerResolutionNs(std::chrono::nanoseconds ns); -#endif - struct Event; void Reset(); using heap_t = boost::heap::fibonacci_heap>>; + Common::Event event{}; + Common::Event pause_event{}; + + alignas(64) mutable std::mutex basic_lock; + alignas(64) std::mutex advance_lock; + alignas(64) std::atomic paused{}; + alignas(64) std::atomic paused_set{}; + alignas(64) std::atomic wait_set{}; + std::function on_thread_init{}; heap_t event_queue; + std::jthread timer_thread; s64 global_timer = 0; -#ifdef _WIN32 - s64 timer_resolution_ns; -#endif u64 event_fifo_id = 0; s64 pause_end_time{}; /// Cycle timing u64 cpu_ticks{}; s64 downcount{}; - Common::Event event{}; - Common::Event pause_event{}; - std::function on_thread_init{}; - std::jthread timer_thread; - mutable std::mutex basic_lock; - std::mutex advance_lock; - std::atomic paused{}; - std::atomic paused_set{}; - std::atomic wait_set{}; - std::atomic has_started{}; bool is_multicore{}; }; -/// Creates a core timing event with the given name and callback. -/// -/// @param name The name of the core timing event to create. -/// @param callback The callback to execute for the event. -/// -/// @returns An EventType instance representing the created event. -/// -std::shared_ptr CreateEvent(std::string name, TimedCallback&& callback); - } // namespace Core::Timing diff --git a/src/core/hle/kernel/k_hardware_timer.cpp b/src/core/hle/kernel/k_hardware_timer.cpp index 019e709fbe..000589c235 100644 --- a/src/core/hle/kernel/k_hardware_timer.cpp +++ b/src/core/hle/kernel/k_hardware_timer.cpp @@ -13,11 +13,10 @@ namespace Kernel { void KHardwareTimer::Initialize() { // Create the timing callback to register with CoreTiming. - m_event_type = Core::Timing::CreateEvent("KHardwareTimer::Callback", - [this](s64, std::chrono::nanoseconds) { - this->DoTask(); - return std::nullopt; - }); + m_event_type = m_kernel.System().CreateEvent("KHardwareTimer::Callback", [this](s64, std::chrono::nanoseconds) { + this->DoTask(); + return std::nullopt; + }); } void KHardwareTimer::Finalize() { diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 5f88fa498f..4316e748aa 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -256,7 +256,7 @@ struct KernelCore::Impl { } void InitializePreemption(KernelCore& kernel) { - preemption_event = Core::Timing::CreateEvent("PreemptionCallback", [this, &kernel](s64 time, std::chrono::nanoseconds) -> std::optional { + preemption_event = system.CreateEvent("PreemptionCallback", [this, &kernel](s64 time, std::chrono::nanoseconds) -> std::optional { { KScopedSchedulerLock lock(kernel); global_scheduler_context->PreemptThreads(); diff --git a/src/core/hle/service/glue/time/alarm_worker.cpp b/src/core/hle/service/glue/time/alarm_worker.cpp index 3ff071f4a0..4798b067c1 100644 --- a/src/core/hle/service/glue/time/alarm_worker.cpp +++ b/src/core/hle/service/glue/time/alarm_worker.cpp @@ -22,16 +22,11 @@ AlarmWorker::~AlarmWorker() { void AlarmWorker::Initialize(std::shared_ptr time_m) { m_time_m = std::move(time_m); - m_timer_event = m_ctx.CreateEvent("Glue:AlarmWorker:TimerEvent"); - m_timer_timing_event = Core::Timing::CreateEvent( - "Glue:AlarmWorker::AlarmTimer", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - m_timer_event->Signal(); - return std::nullopt; - }); - + m_timer_timing_event = m_system.CreateEvent("Glue:AlarmWorker::AlarmTimer", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + m_timer_event->Signal(); + return std::nullopt; + }); AttachToClosestAlarmEvent(); } diff --git a/src/core/hle/service/glue/time/worker.cpp b/src/core/hle/service/glue/time/worker.cpp index 1dab3e9dcb..1603e28dfe 100644 --- a/src/core/hle/service/glue/time/worker.cpp +++ b/src/core/hle/service/glue/time/worker.cpp @@ -19,28 +19,19 @@ namespace Service::Glue::Time { TimeWorker::TimeWorker(Core::System& system, StandardSteadyClockResource& steady_clock_resource, FileTimestampWorker& file_timestamp_worker) - : m_system{system}, m_ctx{m_system, "Glue:TimeWorker"}, m_event{m_ctx.CreateEvent( - "Glue:TimeWorker:Event")}, + : m_system{system}, m_ctx{m_system, "Glue:TimeWorker"}, m_event{m_ctx.CreateEvent("Glue:TimeWorker:Event")}, m_steady_clock_resource{steady_clock_resource}, - m_file_timestamp_worker{file_timestamp_worker}, m_timer_steady_clock{m_ctx.CreateEvent( - "Glue:TimeWorker:SteadyClockTimerEvent")}, + m_file_timestamp_worker{file_timestamp_worker}, m_timer_steady_clock{m_ctx.CreateEvent("Glue:TimeWorker:SteadyClockTimerEvent")}, m_timer_file_system{m_ctx.CreateEvent("Glue:TimeWorker:FileTimeTimerEvent")}, m_alarm_worker{m_system, m_steady_clock_resource}, m_pm_state_change_handler{m_alarm_worker} { - m_timer_steady_clock_timing_event = Core::Timing::CreateEvent( - "Time::SteadyClockEvent", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - m_timer_steady_clock->Signal(); - return std::nullopt; - }); - - m_timer_file_system_timing_event = Core::Timing::CreateEvent( - "Time::SteadyClockEvent", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - m_timer_file_system->Signal(); - return std::nullopt; - }); + m_timer_steady_clock_timing_event = m_system.CreateEvent("Time::SteadyClockEvent", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + m_timer_steady_clock->Signal(); + return std::nullopt; + }); + m_timer_file_system_timing_event = m_system.CreateEvent("Time::SteadyClockEvent", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + m_timer_file_system->Signal(); + return std::nullopt; + }); } TimeWorker::~TimeWorker() { diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp index ebc66932ab..345deff402 100644 --- a/src/core/hle/service/hid/hidbus.cpp +++ b/src/core/hle/service/hid/hidbus.cpp @@ -51,17 +51,12 @@ Hidbus::Hidbus(Core::System& system_) RegisterHandlers(functions); // Register update callbacks - hidbus_update_event = Core::Timing::CreateEvent( - "Hidbus::UpdateCallback", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - const auto guard = LockService(); - UpdateHidbus(ns_late); - return std::nullopt; - }); - - system_.CoreTiming().ScheduleLoopingEvent(hidbus_update_ns, hidbus_update_ns, - hidbus_update_event); + hidbus_update_event = system_.CreateEvent("Hidbus::UpdateCallback", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + const auto guard = LockService(); + UpdateHidbus(ns_late); + return std::nullopt; + }); + system_.CoreTiming().ScheduleLoopingEvent(hidbus_update_ns, hidbus_update_ns, hidbus_update_event); } Hidbus::~Hidbus() { diff --git a/src/core/hle/service/vi/conductor.cpp b/src/core/hle/service/vi/conductor.cpp index 801a135dd7..b0cb2e0892 100644 --- a/src/core/hle/service/vi/conductor.cpp +++ b/src/core/hle/service/vi/conductor.cpp @@ -23,25 +23,17 @@ Conductor::Conductor(Core::System& system, Container& container, DisplayList& di }); if (system.IsMulticore()) { - m_event = Core::Timing::CreateEvent( - "ScreenComposition", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - m_signal.Set(); - return std::chrono::nanoseconds(this->GetNextTicks()); - }); - + m_event = system.CreateEvent("ScreenComposition", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + m_signal.Set(); + return std::chrono::nanoseconds(this->GetNextTicks()); + }); system.CoreTiming().ScheduleLoopingEvent(FrameNs, FrameNs, m_event); m_thread = std::jthread([this](std::stop_token token) { this->VsyncThread(token); }); } else { - m_event = Core::Timing::CreateEvent( - "ScreenComposition", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - this->ProcessVsync(); - return std::chrono::nanoseconds(this->GetNextTicks()); - }); - + m_event = system.CreateEvent("ScreenComposition", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + this->ProcessVsync(); + return std::chrono::nanoseconds(this->GetNextTicks()); + }); system.CoreTiming().ScheduleLoopingEvent(FrameNs, FrameNs, m_event); } } diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index dcfd23644f..daeec6529b 100644 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp @@ -233,12 +233,12 @@ CheatEngine::~CheatEngine() { } void CheatEngine::Initialize() { - event = Core::Timing::CreateEvent( - "CheatEngine::FrameCallback::" + Common::HexToString(metadata.main_nso_build_id), - [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { - FrameCallback(ns_late); - return std::nullopt; - }); + event = system.CreateEvent( + "CheatEngine::FrameCallback::" + Common::HexToString(metadata.main_nso_build_id), + [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + FrameCallback(ns_late); + return std::nullopt; + }); core_timing.ScheduleLoopingEvent(CHEAT_ENGINE_NS, CHEAT_ENGINE_NS, event); metadata.process_id = system.ApplicationProcess()->GetProcessId(); diff --git a/src/core/tools/freezer.cpp b/src/core/tools/freezer.cpp index 73a86b3c8c..5ab7820392 100644 --- a/src/core/tools/freezer.cpp +++ b/src/core/tools/freezer.cpp @@ -52,14 +52,12 @@ void MemoryWriteWidth(Core::Memory::Memory& memory, u32 width, VAddr addr, u64 v } // Anonymous namespace -Freezer::Freezer(Core::Timing::CoreTiming& core_timing_, Core::Memory::Memory& memory_) +Freezer::Freezer(Core::System& system_, Core::Timing::CoreTiming& core_timing_, Core::Memory::Memory& memory_) : core_timing{core_timing_}, memory{memory_} { - event = Core::Timing::CreateEvent("MemoryFreezer::FrameCallback", - [this](s64 time, std::chrono::nanoseconds ns_late) - -> std::optional { - FrameCallback(ns_late); - return std::nullopt; - }); + event = system_.CreateEvent("MemoryFreezer::FrameCallback", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + FrameCallback(ns_late); + return std::nullopt; + }); core_timing.ScheduleEvent(memory_freezer_ns, event); } diff --git a/src/core/tools/freezer.h b/src/core/tools/freezer.h index 2efbc11f38..d474f74fa0 100644 --- a/src/core/tools/freezer.h +++ b/src/core/tools/freezer.h @@ -11,14 +11,16 @@ #include #include "common/common_types.h" -namespace Core::Timing { +namespace Core { +class System; +namespace Timing { class CoreTiming; struct EventType; } // namespace Core::Timing - -namespace Core::Memory { +namespace Memory { class Memory; -} +} //namespace Core::Memory +} //namespace Core namespace Tools { @@ -38,7 +40,7 @@ public: u64 value; }; - explicit Freezer(Core::Timing::CoreTiming& core_timing_, Core::Memory::Memory& memory_); + explicit Freezer(Core::System& system_, Core::Timing::CoreTiming& core_timing_, Core::Memory::Memory& memory_); ~Freezer(); // Enables or disables the entire memory freezer. diff --git a/src/hid_core/resource_manager.cpp b/src/hid_core/resource_manager.cpp index 0c10d1bec9..420a988d0c 100644 --- a/src/hid_core/resource_manager.cpp +++ b/src/hid_core/resource_manager.cpp @@ -56,33 +56,22 @@ ResourceManager::ResourceManager(Core::System& system_, applet_resource = std::make_shared(system); // Register update callbacks - npad_update_event = Core::Timing::CreateEvent("HID::UpdatePadCallback", - [this](s64 time, std::chrono::nanoseconds ns_late) - -> std::optional { - UpdateNpad(ns_late); - return std::nullopt; - }); - default_update_event = Core::Timing::CreateEvent( - "HID::UpdateDefaultCallback", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - UpdateControllers(ns_late); - return std::nullopt; - }); - mouse_keyboard_update_event = Core::Timing::CreateEvent( - "HID::UpdateMouseKeyboardCallback", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - UpdateMouseKeyboard(ns_late); - return std::nullopt; - }); - motion_update_event = Core::Timing::CreateEvent( - "HID::UpdateMotionCallback", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - UpdateMotion(ns_late); - return std::nullopt; - }); + npad_update_event = system.CreateEvent("HID::UpdatePadCallback", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + UpdateNpad(ns_late); + return std::nullopt; + }); + default_update_event = system.CreateEvent("HID::UpdateDefaultCallback", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + UpdateControllers(ns_late); + return std::nullopt; + }); + mouse_keyboard_update_event = system.CreateEvent("HID::UpdateMouseKeyboardCallback", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + UpdateMouseKeyboard(ns_late); + return std::nullopt; + }); + motion_update_event = system.CreateEvent("HID::UpdateMotionCallback", [this](s64 time, std::chrono::nanoseconds ns_late) -> std::optional { + UpdateMotion(ns_late); + return std::nullopt; + }); } ResourceManager::~ResourceManager() { @@ -267,13 +256,11 @@ void ResourceManager::InitializeTouchScreenSampler() { touch_screen = std::make_shared(touch_resource); gesture = std::make_shared(touch_resource); - touch_update_event = Core::Timing::CreateEvent( - "HID::TouchUpdateCallback", - [this](s64 time, - std::chrono::nanoseconds ns_late) -> std::optional { - touch_resource->OnTouchUpdate(time); - return std::nullopt; - }); + touch_update_event = system.CreateEvent("HID::TouchUpdateCallback", [this](s64 time, + std::chrono::nanoseconds ns_late) -> std::optional { + touch_resource->OnTouchUpdate(time); + return std::nullopt; + }); touch_resource->SetTouchDriver(touch_driver); touch_resource->SetAppletResource(applet_resource, &shared_mutex); diff --git a/src/qt_common/qt_common.cpp b/src/qt_common/qt_common.cpp index b9b8caf6e8..1a64b6184f 100644 --- a/src/qt_common/qt_common.cpp +++ b/src/qt_common/qt_common.cpp @@ -266,12 +266,7 @@ void Init(QWidget* root) { Common::GetMemInfo().TotalPhysicalMemory / f64{1_GiB}); LOG_INFO(Frontend, "Host Swap: {:.2f} GiB", Common::GetMemInfo().TotalSwapMemory / f64{1_GiB}); #ifdef _WIN32 - LOG_INFO(Frontend, "Host Timer Resolution: {:.4f} ms", - std::chrono::duration_cast>( - Common::Windows::SetCurrentTimerResolutionToMaximum()) - .count()); - QtCommon::system->CoreTiming().SetTimerResolutionNs( - Common::Windows::GetCurrentTimerResolution()); + LOG_INFO(Frontend, "Host Timer Resolution: {:.4f} ms", std::chrono::duration_cast>(Common::Windows::SetCurrentTimerResolutionToMaximum()).count()); #endif // Remove cached contents generated during the previous session diff --git a/src/tests/core/core_timing.cpp b/src/tests/core/core_timing.cpp index 81898a1d38..85624952ca 100644 --- a/src/tests/core/core_timing.cpp +++ b/src/tests/core/core_timing.cpp @@ -53,14 +53,15 @@ u64 TestTimerSpeed(Core::Timing::CoreTiming& core_timing) { } // Anonymous namespace TEST_CASE("CoreTiming[BasicOrder]", "[core]") { + Core::System system{}; ScopeInit guard; auto& core_timing = guard.core_timing; std::vector> events{ - Core::Timing::CreateEvent("callbackA", HostCallbackTemplate<0>), - Core::Timing::CreateEvent("callbackB", HostCallbackTemplate<1>), - Core::Timing::CreateEvent("callbackC", HostCallbackTemplate<2>), - Core::Timing::CreateEvent("callbackD", HostCallbackTemplate<3>), - Core::Timing::CreateEvent("callbackE", HostCallbackTemplate<4>), + system.CreateEvent("callbackA", HostCallbackTemplate<0>), + system.CreateEvent("callbackB", HostCallbackTemplate<1>), + system.CreateEvent("callbackC", HostCallbackTemplate<2>), + system.CreateEvent("callbackD", HostCallbackTemplate<3>), + system.CreateEvent("callbackE", HostCallbackTemplate<4>), }; expected_callback = 0; @@ -93,14 +94,15 @@ TEST_CASE("CoreTiming[BasicOrder]", "[core]") { } TEST_CASE("CoreTiming[BasicOrderNoPausing]", "[core]") { + Core::System system{}; ScopeInit guard; auto& core_timing = guard.core_timing; std::vector> events{ - Core::Timing::CreateEvent("callbackA", HostCallbackTemplate<0>), - Core::Timing::CreateEvent("callbackB", HostCallbackTemplate<1>), - Core::Timing::CreateEvent("callbackC", HostCallbackTemplate<2>), - Core::Timing::CreateEvent("callbackD", HostCallbackTemplate<3>), - Core::Timing::CreateEvent("callbackE", HostCallbackTemplate<4>), + system.CreateEvent("callbackA", HostCallbackTemplate<0>), + system.CreateEvent("callbackB", HostCallbackTemplate<1>), + system.CreateEvent("callbackC", HostCallbackTemplate<2>), + system.CreateEvent("callbackD", HostCallbackTemplate<3>), + system.CreateEvent("callbackE", HostCallbackTemplate<4>), }; core_timing.SyncPause(true); diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index d20c126159..e1b8c70056 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -371,7 +371,6 @@ int main(int argc, char** argv) { #ifdef _WIN32 Common::Windows::SetCurrentTimerResolutionToMaximum(); - system.CoreTiming().SetTimerResolutionNs(Common::Windows::GetCurrentTimerResolution()); #endif system.SetContentProvider(std::make_unique());