From 2dc469cebac90462fcc48edcf5c1b77148825957 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 27 Oct 2019 22:01:45 -0400 Subject: scheduler: Amend documentation comments Adjusts the formatting of a few of the comments an ensures they get recognized as proper Doxygen comments. --- src/core/hle/kernel/scheduler.cpp | 29 ----------- src/core/hle/kernel/scheduler.h | 105 +++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 75 deletions(-) diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index e6dcb9639..53281cc6c 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -35,24 +35,11 @@ void GlobalScheduler::RemoveThread(const Thread* thread) { thread_list.end()); } -/* - * UnloadThread selects a core and forces it to unload its current thread's context - */ void GlobalScheduler::UnloadThread(s32 core) { Scheduler& sched = system.Scheduler(core); sched.UnloadThread(); } -/* - * SelectThread takes care of selecting the new scheduled thread. - * It does it in 3 steps: - * - First a thread is selected from the top of the priority queue. If no thread - * is obtained then we move to step two, else we are done. - * - Second we try to get a suggested thread that's not assigned to any core or - * that is not the top thread in that core. - * - Third is no suggested thread is found, we do a second pass and pick a running - * thread in another core and swap it with its current thread. - */ void GlobalScheduler::SelectThread(u32 core) { const auto update_thread = [](Thread* thread, Scheduler& sched) { if (thread != sched.selected_thread) { @@ -114,10 +101,6 @@ void GlobalScheduler::SelectThread(u32 core) { update_thread(current_thread, sched); } -/* - * YieldThread takes a thread and moves it to the back of the it's priority list - * This operation can be redundant and no scheduling is changed if marked as so. - */ bool GlobalScheduler::YieldThread(Thread* yielding_thread) { // Note: caller should use critical section, etc. const u32 core_id = static_cast(yielding_thread->GetProcessorID()); @@ -132,12 +115,6 @@ bool GlobalScheduler::YieldThread(Thread* yielding_thread) { return AskForReselectionOrMarkRedundant(yielding_thread, winner); } -/* - * YieldThreadAndBalanceLoad takes a thread and moves it to the back of the it's priority list. - * Afterwards, tries to pick a suggested thread from the suggested queue that has worse time or - * a better priority than the next thread in the core. - * This operation can be redundant and no scheduling is changed if marked as so. - */ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, // etc. @@ -189,12 +166,6 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { return AskForReselectionOrMarkRedundant(yielding_thread, winner); } -/* - * YieldThreadAndWaitForLoadBalancing takes a thread and moves it out of the scheduling queue - * and into the suggested queue. If no thread can be squeduled afterwards in that core, - * a suggested thread is obtained instead. - * This operation can be redundant and no scheduling is changed if marked as so. - */ bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread) { // Note: caller should check if !thread.IsSchedulerOperationRedundant and use critical section, // etc. diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h index fcae28e0a..8f1f39c59 100644 --- a/src/core/hle/kernel/scheduler.h +++ b/src/core/hle/kernel/scheduler.h @@ -26,6 +26,7 @@ public: explicit GlobalScheduler(Core::System& system); ~GlobalScheduler(); + /// Adds a new thread to the scheduler void AddThread(SharedPtr thread); @@ -37,47 +38,57 @@ public: return thread_list; } - // Add a thread to the suggested queue of a cpu core. Suggested threads may be - // picked if no thread is scheduled to run on the core. + /** + * Add a thread to the suggested queue of a cpu core. Suggested threads may be + * picked if no thread is scheduled to run on the core. + */ void Suggest(u32 priority, u32 core, Thread* thread); - // Remove a thread to the suggested queue of a cpu core. Suggested threads may be - // picked if no thread is scheduled to run on the core. + /** + * Remove a thread to the suggested queue of a cpu core. Suggested threads may be + * picked if no thread is scheduled to run on the core. + */ void Unsuggest(u32 priority, u32 core, Thread* thread); - // Add a thread to the scheduling queue of a cpu core. The thread is added at the - // back the queue in its priority level + /** + * Add a thread to the scheduling queue of a cpu core. The thread is added at the + * back the queue in its priority level. + */ void Schedule(u32 priority, u32 core, Thread* thread); - // Add a thread to the scheduling queue of a cpu core. The thread is added at the - // front the queue in its priority level + /** + * Add a thread to the scheduling queue of a cpu core. The thread is added at the + * front the queue in its priority level. + */ void SchedulePrepend(u32 priority, u32 core, Thread* thread); - // Reschedule an already scheduled thread based on a new priority + /// Reschedule an already scheduled thread based on a new priority void Reschedule(u32 priority, u32 core, Thread* thread); - // Unschedule a thread. + /// Unschedules a thread. void Unschedule(u32 priority, u32 core, Thread* thread); - // Transfers a thread into an specific core. If the destination_core is -1 - // it will be unscheduled from its source code and added into its suggested - // queue. + /** + * Transfers a thread into an specific core. If the destination_core is -1 + * it will be unscheduled from its source code and added into its suggested + * queue. + */ void TransferToCore(u32 priority, s32 destination_core, Thread* thread); - /* - * UnloadThread selects a core and forces it to unload its current thread's context - */ + /// Selects a core and forces it to unload its current thread's context void UnloadThread(s32 core); - /* - * SelectThread takes care of selecting the new scheduled thread. - * It does it in 3 steps: - * - First a thread is selected from the top of the priority queue. If no thread - * is obtained then we move to step two, else we are done. - * - Second we try to get a suggested thread that's not assigned to any core or - * that is not the top thread in that core. - * - Third is no suggested thread is found, we do a second pass and pick a running - * thread in another core and swap it with its current thread. + /** + * Takes care of selecting the new scheduled thread in three steps: + * + * 1. First a thread is selected from the top of the priority queue. If no thread + * is obtained then we move to step two, else we are done. + * + * 2. Second we try to get a suggested thread that's not assigned to any core or + * that is not the top thread in that core. + * + * 3. Third is no suggested thread is found, we do a second pass and pick a running + * thread in another core and swap it with its current thread. */ void SelectThread(u32 core); @@ -85,33 +96,37 @@ public: return !scheduled_queue[core_id].empty(); } - /* - * YieldThread takes a thread and moves it to the back of the it's priority list - * This operation can be redundant and no scheduling is changed if marked as so. + /** + * Takes a thread and moves it to the back of the it's priority list. + * + * @note This operation can be redundant and no scheduling is changed if marked as so. */ bool YieldThread(Thread* thread); - /* - * YieldThreadAndBalanceLoad takes a thread and moves it to the back of the it's priority list. + /** + * Takes a thread and moves it to the back of the it's priority list. * Afterwards, tries to pick a suggested thread from the suggested queue that has worse time or * a better priority than the next thread in the core. - * This operation can be redundant and no scheduling is changed if marked as so. + * + * @note This operation can be redundant and no scheduling is changed if marked as so. */ bool YieldThreadAndBalanceLoad(Thread* thread); - /* - * YieldThreadAndWaitForLoadBalancing takes a thread and moves it out of the scheduling queue - * and into the suggested queue. If no thread can be squeduled afterwards in that core, + /** + * Takes a thread and moves it out of the scheduling queue. + * and into the suggested queue. If no thread can be scheduled afterwards in that core, * a suggested thread is obtained instead. - * This operation can be redundant and no scheduling is changed if marked as so. + * + * @note This operation can be redundant and no scheduling is changed if marked as so. */ bool YieldThreadAndWaitForLoadBalancing(Thread* thread); - /* - * PreemptThreads this operation rotates the scheduling queues of threads at - * a preemption priority and then does some core rebalancing. Preemption priorities - * can be found in the array 'preemption_priorities'. This operation happens - * every 10ms. + /** + * Rotates the scheduling queues of threads at a preemption priority and then does + * some core rebalancing. Preemption priorities can be found in the array + * 'preemption_priorities'. + * + * @note This operation happens every 10ms. */ void PreemptThreads(); @@ -137,8 +152,8 @@ private: std::array, NUM_CPU_CORES> suggested_queue; std::atomic is_reselection_pending; - // `preemption_priorities` are the priority levels at which the global scheduler - // preempts threads every 10 ms. They are ordered from Core 0 to Core 3 + // The priority levels at which the global scheduler preempts threads every 10 ms. They are + // ordered from Core 0 to Core 3. std::array preemption_priorities = {59, 59, 59, 62}; /// Lists all thread ids that aren't deleted/etc. @@ -181,10 +196,8 @@ public: private: friend class GlobalScheduler; - /** - * Switches the CPU's active thread context to that of the specified thread - * @param new_thread The thread to switch to - */ + + /// Switches the CPU's active thread context to that of the specified thread void SwitchContext(); /** -- cgit v1.2.3 From 2fb0bbff29cc2f1330b773db2f57b09bf1476036 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 27 Oct 2019 22:13:51 -0400 Subject: scheduler: Initialize class members directly where applicable Reduces the overall amount of code. --- src/core/hle/kernel/scheduler.cpp | 8 +++----- src/core/hle/kernel/scheduler.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 53281cc6c..8353308aa 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -22,9 +22,9 @@ namespace Kernel { -GlobalScheduler::GlobalScheduler(Core::System& system) : system{system} { - is_reselection_pending = false; -} +GlobalScheduler::GlobalScheduler(Core::System& system) : system{system} {} + +GlobalScheduler::~GlobalScheduler() = default; void GlobalScheduler::AddThread(SharedPtr thread) { thread_list.push_back(std::move(thread)); @@ -357,8 +357,6 @@ void GlobalScheduler::Shutdown() { thread_list.clear(); } -GlobalScheduler::~GlobalScheduler() = default; - Scheduler::Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, u32 core_id) : system(system), cpu_core(cpu_core), core_id(core_id) {} diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h index 8f1f39c59..74feecc06 100644 --- a/src/core/hle/kernel/scheduler.h +++ b/src/core/hle/kernel/scheduler.h @@ -150,7 +150,7 @@ private: static constexpr u32 min_regular_priority = 2; std::array, NUM_CPU_CORES> scheduled_queue; std::array, NUM_CPU_CORES> suggested_queue; - std::atomic is_reselection_pending; + std::atomic is_reselection_pending{false}; // The priority levels at which the global scheduler preempts threads every 10 ms. They are // ordered from Core 0 to Core 3. -- cgit v1.2.3 From f19c1a7cda321c96f6314acf8a9b5137bc3fe1ea Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 27 Oct 2019 22:34:28 -0400 Subject: scheduler: Silence sign conversion warnings --- src/core/hle/kernel/scheduler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 8353308aa..9a38fa50c 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -251,7 +251,7 @@ void GlobalScheduler::PreemptThreads() { if (winner->IsRunning()) { UnloadThread(winner->GetProcessorID()); } - TransferToCore(winner->GetPriority(), core_id, winner); + TransferToCore(winner->GetPriority(), s32(core_id), winner); current_thread = winner->GetPriority() <= current_thread->GetPriority() ? winner : current_thread; } @@ -284,7 +284,7 @@ void GlobalScheduler::PreemptThreads() { if (winner->IsRunning()) { UnloadThread(winner->GetProcessorID()); } - TransferToCore(winner->GetPriority(), core_id, winner); + TransferToCore(winner->GetPriority(), s32(core_id), winner); current_thread = winner; } } @@ -302,12 +302,12 @@ void GlobalScheduler::Unsuggest(u32 priority, u32 core, Thread* thread) { } void GlobalScheduler::Schedule(u32 priority, u32 core, Thread* thread) { - ASSERT_MSG(thread->GetProcessorID() == core, "Thread must be assigned to this core."); + ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core."); scheduled_queue[core].add(thread, priority); } void GlobalScheduler::SchedulePrepend(u32 priority, u32 core, Thread* thread) { - ASSERT_MSG(thread->GetProcessorID() == core, "Thread must be assigned to this core."); + ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core."); scheduled_queue[core].add(thread, priority, false); } @@ -439,7 +439,7 @@ void Scheduler::SwitchContext() { // Load context of new thread if (new_thread) { - ASSERT_MSG(new_thread->GetProcessorID() == this->core_id, + ASSERT_MSG(new_thread->GetProcessorID() == s32(this->core_id), "Thread must be assigned to this core."); ASSERT_MSG(new_thread->GetStatus() == ThreadStatus::Ready, "Thread must be ready to become running."); -- cgit v1.2.3 From 6c8f28813c5ad9c3636638851a752ff5d33155f3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 27 Oct 2019 22:39:20 -0400 Subject: scheduler: Mark parameter of AskForReselectionOrMarkRedundant() as const This is only compared against, so it can be made const. --- src/core/hle/kernel/scheduler.cpp | 8 ++++---- src/core/hle/kernel/scheduler.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 9a38fa50c..0e2dbf13e 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -107,11 +107,10 @@ bool GlobalScheduler::YieldThread(Thread* yielding_thread) { const u32 priority = yielding_thread->GetPriority(); // Yield the thread - ASSERT_MSG(yielding_thread == scheduled_queue[core_id].front(priority), - "Thread yielding without being in front"); + const Thread* const winner = scheduled_queue[core_id].front(priority); + ASSERT_MSG(yielding_thread == winner, "Thread yielding without being in front"); scheduled_queue[core_id].yield(priority); - Thread* winner = scheduled_queue[core_id].front(priority); return AskForReselectionOrMarkRedundant(yielding_thread, winner); } @@ -339,7 +338,8 @@ void GlobalScheduler::TransferToCore(u32 priority, s32 destination_core, Thread* } } -bool GlobalScheduler::AskForReselectionOrMarkRedundant(Thread* current_thread, Thread* winner) { +bool GlobalScheduler::AskForReselectionOrMarkRedundant(Thread* current_thread, + const Thread* winner) { if (current_thread == winner) { current_thread->IncrementYieldCount(); return true; diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h index 74feecc06..f2d6311b8 100644 --- a/src/core/hle/kernel/scheduler.h +++ b/src/core/hle/kernel/scheduler.h @@ -145,7 +145,7 @@ public: void Shutdown(); private: - bool AskForReselectionOrMarkRedundant(Thread* current_thread, Thread* winner); + bool AskForReselectionOrMarkRedundant(Thread* current_thread, const Thread* winner); static constexpr u32 min_regular_priority = 2; std::array, NUM_CPU_CORES> scheduled_queue; -- cgit v1.2.3