diff options
| author | 2018-10-25 18:42:50 -0400 | |
|---|---|---|
| committer | 2018-10-26 12:49:11 -0400 | |
| commit | 6594853eb112f265fe2354723160c0d4e1cb761a (patch) | |
| tree | 60e67d4d7f38d8f1fe5bebe01f3ef0d87881c570 /src/core/hle/kernel/scheduler.cpp | |
| parent | Merge pull request #1533 from FernandoS27/lmem (diff) | |
| download | yuzu-6594853eb112f265fe2354723160c0d4e1cb761a.tar.gz yuzu-6594853eb112f265fe2354723160c0d4e1cb761a.tar.xz yuzu-6594853eb112f265fe2354723160c0d4e1cb761a.zip | |
svc: Implement svcGetInfo command 0xF0000002
This retrieves:
if (curr_thread == handle_thread) {
result = total_thread_ticks + (hardware_tick_count - last_context_switch_ticks);
} else if (curr_thread == handle_thread && sub_id == current_core_index) {
result = hardware_tick_count - last_context_switch_ticks;
}
Diffstat (limited to 'src/core/hle/kernel/scheduler.cpp')
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 1342c597e..5a5f4cef1 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "core/arm/arm_interface.h" | 10 | #include "core/arm/arm_interface.h" |
| 11 | #include "core/core.h" | 11 | #include "core/core.h" |
| 12 | #include "core/core_timing.h" | ||
| 12 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| 13 | #include "core/hle/kernel/process.h" | 14 | #include "core/hle/kernel/process.h" |
| 14 | #include "core/hle/kernel/scheduler.h" | 15 | #include "core/hle/kernel/scheduler.h" |
| @@ -34,6 +35,10 @@ Thread* Scheduler::GetCurrentThread() const { | |||
| 34 | return current_thread.get(); | 35 | return current_thread.get(); |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 38 | u64 Scheduler::GetLastContextSwitchTicks() const { | ||
| 39 | return last_context_switch_time; | ||
| 40 | } | ||
| 41 | |||
| 37 | Thread* Scheduler::PopNextReadyThread() { | 42 | Thread* Scheduler::PopNextReadyThread() { |
| 38 | Thread* next = nullptr; | 43 | Thread* next = nullptr; |
| 39 | Thread* thread = GetCurrentThread(); | 44 | Thread* thread = GetCurrentThread(); |
| @@ -54,7 +59,10 @@ Thread* Scheduler::PopNextReadyThread() { | |||
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | void Scheduler::SwitchContext(Thread* new_thread) { | 61 | void Scheduler::SwitchContext(Thread* new_thread) { |
| 57 | Thread* previous_thread = GetCurrentThread(); | 62 | Thread* const previous_thread = GetCurrentThread(); |
| 63 | Process* const previous_process = Core::CurrentProcess(); | ||
| 64 | |||
| 65 | UpdateLastContextSwitchTime(previous_thread, previous_process); | ||
| 58 | 66 | ||
| 59 | // Save context for previous thread | 67 | // Save context for previous thread |
| 60 | if (previous_thread) { | 68 | if (previous_thread) { |
| @@ -78,8 +86,6 @@ void Scheduler::SwitchContext(Thread* new_thread) { | |||
| 78 | // Cancel any outstanding wakeup events for this thread | 86 | // Cancel any outstanding wakeup events for this thread |
| 79 | new_thread->CancelWakeupTimer(); | 87 | new_thread->CancelWakeupTimer(); |
| 80 | 88 | ||
| 81 | auto* const previous_process = Core::CurrentProcess(); | ||
| 82 | |||
| 83 | current_thread = new_thread; | 89 | current_thread = new_thread; |
| 84 | 90 | ||
| 85 | ready_queue.remove(new_thread->GetPriority(), new_thread); | 91 | ready_queue.remove(new_thread->GetPriority(), new_thread); |
| @@ -102,6 +108,22 @@ void Scheduler::SwitchContext(Thread* new_thread) { | |||
| 102 | } | 108 | } |
| 103 | } | 109 | } |
| 104 | 110 | ||
| 111 | void Scheduler::UpdateLastContextSwitchTime(Thread* thread, Process* process) { | ||
| 112 | const u64 prev_switch_ticks = last_context_switch_time; | ||
| 113 | const u64 most_recent_switch_ticks = CoreTiming::GetTicks(); | ||
| 114 | const u64 update_ticks = most_recent_switch_ticks - prev_switch_ticks; | ||
| 115 | |||
| 116 | if (thread != nullptr) { | ||
| 117 | thread->UpdateCPUTimeTicks(update_ticks); | ||
| 118 | } | ||
| 119 | |||
| 120 | if (process != nullptr) { | ||
| 121 | process->UpdateCPUTimeTicks(update_ticks); | ||
| 122 | } | ||
| 123 | |||
| 124 | last_context_switch_time = most_recent_switch_ticks; | ||
| 125 | } | ||
| 126 | |||
| 105 | void Scheduler::Reschedule() { | 127 | void Scheduler::Reschedule() { |
| 106 | std::lock_guard<std::mutex> lock(scheduler_mutex); | 128 | std::lock_guard<std::mutex> lock(scheduler_mutex); |
| 107 | 129 | ||