summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/kernel/kernel.cpp9
-rw-r--r--src/core/hle/kernel/time_manager.cpp20
-rw-r--r--src/core/hle/service/hid/hid.cpp41
-rw-r--r--src/core/hle/service/hid/hidbus.cpp16
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp13
5 files changed, 41 insertions, 58 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 0009193be..7307cf262 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -234,17 +234,18 @@ struct KernelCore::Impl {
234 234
235 void InitializePreemption(KernelCore& kernel) { 235 void InitializePreemption(KernelCore& kernel) {
236 preemption_event = Core::Timing::CreateEvent( 236 preemption_event = Core::Timing::CreateEvent(
237 "PreemptionCallback", [this, &kernel](std::uintptr_t, std::chrono::nanoseconds) { 237 "PreemptionCallback",
238 [this, &kernel](std::uintptr_t, s64 time,
239 std::chrono::nanoseconds) -> std::optional<std::chrono::nanoseconds> {
238 { 240 {
239 KScopedSchedulerLock lock(kernel); 241 KScopedSchedulerLock lock(kernel);
240 global_scheduler_context->PreemptThreads(); 242 global_scheduler_context->PreemptThreads();
241 } 243 }
242 const auto time_interval = std::chrono::nanoseconds{std::chrono::milliseconds(10)}; 244 return std::nullopt;
243 system.CoreTiming().ScheduleEvent(time_interval, preemption_event);
244 }); 245 });
245 246
246 const auto time_interval = std::chrono::nanoseconds{std::chrono::milliseconds(10)}; 247 const auto time_interval = std::chrono::nanoseconds{std::chrono::milliseconds(10)};
247 system.CoreTiming().ScheduleEvent(time_interval, preemption_event); 248 system.CoreTiming().ScheduleLoopingEvent(time_interval, time_interval, preemption_event);
248 } 249 }
249 250
250 void InitializeShutdownThreads() { 251 void InitializeShutdownThreads() {
diff --git a/src/core/hle/kernel/time_manager.cpp b/src/core/hle/kernel/time_manager.cpp
index 2724c3782..5ee72c432 100644
--- a/src/core/hle/kernel/time_manager.cpp
+++ b/src/core/hle/kernel/time_manager.cpp
@@ -11,15 +11,17 @@
11namespace Kernel { 11namespace Kernel {
12 12
13TimeManager::TimeManager(Core::System& system_) : system{system_} { 13TimeManager::TimeManager(Core::System& system_) : system{system_} {
14 time_manager_event_type = 14 time_manager_event_type = Core::Timing::CreateEvent(
15 Core::Timing::CreateEvent("Kernel::TimeManagerCallback", 15 "Kernel::TimeManagerCallback",
16 [this](std::uintptr_t thread_handle, std::chrono::nanoseconds) { 16 [this](std::uintptr_t thread_handle, s64 time,
17 KThread* thread = reinterpret_cast<KThread*>(thread_handle); 17 std::chrono::nanoseconds) -> std::optional<std::chrono::nanoseconds> {
18 { 18 KThread* thread = reinterpret_cast<KThread*>(thread_handle);
19 KScopedSchedulerLock sl(system.Kernel()); 19 {
20 thread->OnTimer(); 20 KScopedSchedulerLock sl(system.Kernel());
21 } 21 thread->OnTimer();
22 }); 22 }
23 return std::nullopt;
24 });
23} 25}
24 26
25void TimeManager::ScheduleTimeEvent(KThread* thread, s64 nanoseconds) { 27void TimeManager::ScheduleTimeEvent(KThread* thread, s64 nanoseconds) {
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 78efffc50..89bb12442 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -74,26 +74,34 @@ IAppletResource::IAppletResource(Core::System& system_,
74 // Register update callbacks 74 // Register update callbacks
75 pad_update_event = Core::Timing::CreateEvent( 75 pad_update_event = Core::Timing::CreateEvent(
76 "HID::UpdatePadCallback", 76 "HID::UpdatePadCallback",
77 [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { 77 [this](std::uintptr_t user_data, s64 time,
78 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
78 const auto guard = LockService(); 79 const auto guard = LockService();
79 UpdateControllers(user_data, ns_late); 80 UpdateControllers(user_data, ns_late);
81 return std::nullopt;
80 }); 82 });
81 mouse_keyboard_update_event = Core::Timing::CreateEvent( 83 mouse_keyboard_update_event = Core::Timing::CreateEvent(
82 "HID::UpdateMouseKeyboardCallback", 84 "HID::UpdateMouseKeyboardCallback",
83 [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { 85 [this](std::uintptr_t user_data, s64 time,
86 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
84 const auto guard = LockService(); 87 const auto guard = LockService();
85 UpdateMouseKeyboard(user_data, ns_late); 88 UpdateMouseKeyboard(user_data, ns_late);
89 return std::nullopt;
86 }); 90 });
87 motion_update_event = Core::Timing::CreateEvent( 91 motion_update_event = Core::Timing::CreateEvent(
88 "HID::UpdateMotionCallback", 92 "HID::UpdateMotionCallback",
89 [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { 93 [this](std::uintptr_t user_data, s64 time,
94 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
90 const auto guard = LockService(); 95 const auto guard = LockService();
91 UpdateMotion(user_data, ns_late); 96 UpdateMotion(user_data, ns_late);
97 return std::nullopt;
92 }); 98 });
93 99
94 system.CoreTiming().ScheduleEvent(pad_update_ns, pad_update_event); 100 system.CoreTiming().ScheduleLoopingEvent(pad_update_ns, pad_update_ns, pad_update_event);
95 system.CoreTiming().ScheduleEvent(mouse_keyboard_update_ns, mouse_keyboard_update_event); 101 system.CoreTiming().ScheduleLoopingEvent(mouse_keyboard_update_ns, mouse_keyboard_update_ns,
96 system.CoreTiming().ScheduleEvent(motion_update_ns, motion_update_event); 102 mouse_keyboard_update_event);
103 system.CoreTiming().ScheduleLoopingEvent(motion_update_ns, motion_update_ns,
104 motion_update_event);
97 105
98 system.HIDCore().ReloadInputDevices(); 106 system.HIDCore().ReloadInputDevices();
99} 107}
@@ -135,13 +143,6 @@ void IAppletResource::UpdateControllers(std::uintptr_t user_data,
135 } 143 }
136 controller->OnUpdate(core_timing); 144 controller->OnUpdate(core_timing);
137 } 145 }
138
139 // If ns_late is higher than the update rate ignore the delay
140 if (ns_late > pad_update_ns) {
141 ns_late = {};
142 }
143
144 core_timing.ScheduleEvent(pad_update_ns - ns_late, pad_update_event);
145} 146}
146 147
147void IAppletResource::UpdateMouseKeyboard(std::uintptr_t user_data, 148void IAppletResource::UpdateMouseKeyboard(std::uintptr_t user_data,
@@ -150,26 +151,12 @@ void IAppletResource::UpdateMouseKeyboard(std::uintptr_t user_data,
150 151
151 controllers[static_cast<size_t>(HidController::Mouse)]->OnUpdate(core_timing); 152 controllers[static_cast<size_t>(HidController::Mouse)]->OnUpdate(core_timing);
152 controllers[static_cast<size_t>(HidController::Keyboard)]->OnUpdate(core_timing); 153 controllers[static_cast<size_t>(HidController::Keyboard)]->OnUpdate(core_timing);
153
154 // If ns_late is higher than the update rate ignore the delay
155 if (ns_late > mouse_keyboard_update_ns) {
156 ns_late = {};
157 }
158
159 core_timing.ScheduleEvent(mouse_keyboard_update_ns - ns_late, mouse_keyboard_update_event);
160} 154}
161 155
162void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { 156void IAppletResource::UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
163 auto& core_timing = system.CoreTiming(); 157 auto& core_timing = system.CoreTiming();
164 158
165 controllers[static_cast<size_t>(HidController::NPad)]->OnMotionUpdate(core_timing); 159 controllers[static_cast<size_t>(HidController::NPad)]->OnMotionUpdate(core_timing);
166
167 // If ns_late is higher than the update rate ignore the delay
168 if (ns_late > motion_update_ns) {
169 ns_late = {};
170 }
171
172 core_timing.ScheduleEvent(motion_update_ns - ns_late, motion_update_event);
173} 160}
174 161
175class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { 162class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> {
diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp
index fa6153b4c..e5e50845f 100644
--- a/src/core/hle/service/hid/hidbus.cpp
+++ b/src/core/hle/service/hid/hidbus.cpp
@@ -50,12 +50,15 @@ HidBus::HidBus(Core::System& system_)
50 // Register update callbacks 50 // Register update callbacks
51 hidbus_update_event = Core::Timing::CreateEvent( 51 hidbus_update_event = Core::Timing::CreateEvent(
52 "Hidbus::UpdateCallback", 52 "Hidbus::UpdateCallback",
53 [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { 53 [this](std::uintptr_t user_data, s64 time,
54 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
54 const auto guard = LockService(); 55 const auto guard = LockService();
55 UpdateHidbus(user_data, ns_late); 56 UpdateHidbus(user_data, ns_late);
57 return std::nullopt;
56 }); 58 });
57 59
58 system_.CoreTiming().ScheduleEvent(hidbus_update_ns, hidbus_update_event); 60 system_.CoreTiming().ScheduleLoopingEvent(hidbus_update_ns, hidbus_update_ns,
61 hidbus_update_event);
59} 62}
60 63
61HidBus::~HidBus() { 64HidBus::~HidBus() {
@@ -63,8 +66,6 @@ HidBus::~HidBus() {
63} 66}
64 67
65void HidBus::UpdateHidbus(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { 68void HidBus::UpdateHidbus(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) {
66 auto& core_timing = system.CoreTiming();
67
68 if (is_hidbus_enabled) { 69 if (is_hidbus_enabled) {
69 for (std::size_t i = 0; i < devices.size(); ++i) { 70 for (std::size_t i = 0; i < devices.size(); ++i) {
70 if (!devices[i].is_device_initializated) { 71 if (!devices[i].is_device_initializated) {
@@ -82,13 +83,6 @@ void HidBus::UpdateHidbus(std::uintptr_t user_data, std::chrono::nanoseconds ns_
82 sizeof(HidbusStatusManagerEntry)); 83 sizeof(HidbusStatusManagerEntry));
83 } 84 }
84 } 85 }
85
86 // If ns_late is higher than the update rate ignore the delay
87 if (ns_late > hidbus_update_ns) {
88 ns_late = {};
89 }
90
91 core_timing.ScheduleEvent(hidbus_update_ns - ns_late, hidbus_update_event);
92} 86}
93 87
94std::optional<std::size_t> HidBus::GetDeviceIndexFromHandle(BusHandle handle) const { 88std::optional<std::size_t> HidBus::GetDeviceIndexFromHandle(BusHandle handle) const {
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index 2b2985a2d..5f69c8c2c 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -67,21 +67,20 @@ NVFlinger::NVFlinger(Core::System& system_, HosBinderDriverServer& hos_binder_dr
67 67
68 // Schedule the screen composition events 68 // Schedule the screen composition events
69 composition_event = Core::Timing::CreateEvent( 69 composition_event = Core::Timing::CreateEvent(
70 "ScreenComposition", [this](std::uintptr_t, std::chrono::nanoseconds ns_late) { 70 "ScreenComposition",
71 [this](std::uintptr_t, s64 time,
72 std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
71 const auto lock_guard = Lock(); 73 const auto lock_guard = Lock();
72 Compose(); 74 Compose();
73 75
74 const auto ticks = std::chrono::nanoseconds{GetNextTicks()}; 76 return std::max(std::chrono::nanoseconds::zero(),
75 const auto ticks_delta = ticks - ns_late; 77 std::chrono::nanoseconds(GetNextTicks()) - ns_late);
76 const auto future_ns = std::max(std::chrono::nanoseconds::zero(), ticks_delta);
77
78 this->system.CoreTiming().ScheduleEvent(future_ns, composition_event);
79 }); 78 });
80 79
81 if (system.IsMulticore()) { 80 if (system.IsMulticore()) {
82 vsync_thread = std::jthread([this](std::stop_token token) { SplitVSync(token); }); 81 vsync_thread = std::jthread([this](std::stop_token token) { SplitVSync(token); });
83 } else { 82 } else {
84 system.CoreTiming().ScheduleEvent(frame_ns, composition_event); 83 system.CoreTiming().ScheduleLoopingEvent(frame_ns, frame_ns, composition_event);
85 } 84 }
86} 85}
87 86