From c0d3aef28c0a0c68c18de30228f29e30f0e52533 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 30 Dec 2020 23:01:08 -0800 Subject: core: hle: kernel: Rename Thread to KThread. --- src/core/hle/kernel/k_scheduler.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/core/hle/kernel/k_scheduler.h') diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 783665123..157373934 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h @@ -29,7 +29,7 @@ namespace Kernel { class KernelCore; class Process; class SchedulerLock; -class Thread; +class KThread; class KScheduler final { public: @@ -45,13 +45,13 @@ public: /// The next two are for SingleCore Only. /// Unload current thread before preempting core. - void Unload(Thread* thread); + void Unload(KThread* thread); /// Reload current thread after core preemption. - void Reload(Thread* thread); + void Reload(KThread* thread); /// Gets the current running thread - [[nodiscard]] Thread* GetCurrentThread() const; + [[nodiscard]] KThread* GetCurrentThread() const; /// Gets the timestamp for the last context switch in ticks. [[nodiscard]] u64 GetLastContextSwitchTicks() const; @@ -72,7 +72,7 @@ public: return switch_fiber; } - [[nodiscard]] u64 UpdateHighestPriorityThread(Thread* highest_thread); + [[nodiscard]] u64 UpdateHighestPriorityThread(KThread* highest_thread); /** * Takes a thread and moves it to the back of the it's priority list. @@ -100,13 +100,13 @@ public: void YieldToAnyThread(); /// Notify the scheduler a thread's status has changed. - static void OnThreadStateChanged(KernelCore& kernel, Thread* thread, ThreadState old_state); + static void OnThreadStateChanged(KernelCore& kernel, KThread* thread, ThreadState old_state); /// Notify the scheduler a thread's priority has changed. - static void OnThreadPriorityChanged(KernelCore& kernel, Thread* thread, s32 old_priority); + static void OnThreadPriorityChanged(KernelCore& kernel, KThread* thread, s32 old_priority); /// Notify the scheduler a thread's core and/or affinity mask has changed. - static void OnThreadAffinityMaskChanged(KernelCore& kernel, Thread* thread, + static void OnThreadAffinityMaskChanged(KernelCore& kernel, KThread* thread, const KAffinityMask& old_affinity, s32 old_core); static bool CanSchedule(KernelCore& kernel); @@ -163,13 +163,13 @@ private: * most recent tick count retrieved. No special arithmetic is * applied to it. */ - void UpdateLastContextSwitchTime(Thread* thread, Process* process); + void UpdateLastContextSwitchTime(KThread* thread, Process* process); static void OnSwitch(void* this_scheduler); void SwitchToCurrent(); - Thread* current_thread{}; - Thread* idle_thread{}; + KThread* current_thread{}; + KThread* idle_thread{}; std::shared_ptr switch_fiber{}; @@ -178,7 +178,7 @@ private: bool interrupt_task_thread_runnable{}; bool should_count_idle{}; u64 idle_count{}; - Thread* highest_priority_thread{}; + KThread* highest_priority_thread{}; void* idle_thread_stack{}; }; -- cgit v1.2.3 From cdd14b03e5c8e29bc6cd11bbde0ef726d2f166ce Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 20 Jan 2021 13:42:27 -0800 Subject: hle: kernel: Recode implementation of KThread to be more accurate. --- src/core/hle/kernel/k_scheduler.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/core/hle/kernel/k_scheduler.h') diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 157373934..2308a55be 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h @@ -33,15 +33,14 @@ class KThread; class KScheduler final { public: - explicit KScheduler(Core::System& system, std::size_t core_id); + explicit KScheduler(Core::System& system, s32 core_id); ~KScheduler(); /// Reschedules to the next available thread (call after current thread is suspended) void RescheduleCurrentCore(); /// Reschedules cores pending reschedule, to be called on EnableScheduling. - static void RescheduleCores(KernelCore& kernel, u64 cores_pending_reschedule, - Core::EmuThreadHandle global_thread); + static void RescheduleCores(KernelCore& kernel, u64 cores_pending_reschedule); /// The next two are for SingleCore Only. /// Unload current thread before preempting core. @@ -53,6 +52,11 @@ public: /// Gets the current running thread [[nodiscard]] KThread* GetCurrentThread() const; + /// Returns true if the scheduler is idle + [[nodiscard]] bool IsIdle() const { + return GetCurrentThread() == idle_thread; + } + /// Gets the timestamp for the last context switch in ticks. [[nodiscard]] u64 GetLastContextSwitchTicks() const; @@ -79,7 +83,7 @@ public: * * @note This operation can be redundant and no scheduling is changed if marked as so. */ - void YieldWithoutCoreMigration(); + static void YieldWithoutCoreMigration(KernelCore& kernel); /** * Takes a thread and moves it to the back of the it's priority list. @@ -88,7 +92,7 @@ public: * * @note This operation can be redundant and no scheduling is changed if marked as so. */ - void YieldWithCoreMigration(); + static void YieldWithCoreMigration(KernelCore& kernel); /** * Takes a thread and moves it out of the scheduling queue. @@ -97,7 +101,9 @@ public: * * @note This operation can be redundant and no scheduling is changed if marked as so. */ - void YieldToAnyThread(); + static void YieldToAnyThread(KernelCore& kernel); + + static void ClearPreviousThread(KernelCore& kernel, KThread* thread); /// Notify the scheduler a thread's status has changed. static void OnThreadStateChanged(KernelCore& kernel, KThread* thread, ThreadState old_state); @@ -114,8 +120,7 @@ public: static void SetSchedulerUpdateNeeded(KernelCore& kernel); static void ClearSchedulerUpdateNeeded(KernelCore& kernel); static void DisableScheduling(KernelCore& kernel); - static void EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling, - Core::EmuThreadHandle global_thread); + static void EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduling); [[nodiscard]] static u64 UpdateHighestPriorityThreads(KernelCore& kernel); private: @@ -168,6 +173,7 @@ private: static void OnSwitch(void* this_scheduler); void SwitchToCurrent(); + KThread* prev_thread{}; KThread* current_thread{}; KThread* idle_thread{}; @@ -186,7 +192,7 @@ private: Core::System& system; u64 last_context_switch_time{}; - const std::size_t core_id; + const s32 core_id; Common::SpinLock guard{}; }; -- cgit v1.2.3 From 37f74d87417c8cb491fee1681cc05fb7baa5e516 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 21 Jan 2021 11:26:00 -0800 Subject: hle: kernel: k_scheduler: Use atomics for current_thread, etc. --- src/core/hle/kernel/k_scheduler.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/core/hle/kernel/k_scheduler.h') diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 2308a55be..e0d052593 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h @@ -54,7 +54,7 @@ public: /// Returns true if the scheduler is idle [[nodiscard]] bool IsIdle() const { - return GetCurrentThread() == idle_thread; + return GetCurrentThread() == idle_thread.get(); } /// Gets the timestamp for the last context switch in ticks. @@ -174,8 +174,9 @@ private: void SwitchToCurrent(); KThread* prev_thread{}; - KThread* current_thread{}; - KThread* idle_thread{}; + std::atomic current_thread{}; + + std::shared_ptr idle_thread; std::shared_ptr switch_fiber{}; -- cgit v1.2.3 From 6e953f7f0294d945ba9d6f08350d5dccb0d76075 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 21 Jan 2021 13:00:16 -0800 Subject: hle: kernel: Allocate a dummy KThread for each host thread, and use it for scheduling. --- src/core/hle/kernel/k_scheduler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/hle/kernel/k_scheduler.h') diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index e0d052593..f595b9a5c 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h @@ -54,7 +54,7 @@ public: /// Returns true if the scheduler is idle [[nodiscard]] bool IsIdle() const { - return GetCurrentThread() == idle_thread.get(); + return GetCurrentThread() == idle_thread; } /// Gets the timestamp for the last context switch in ticks. @@ -176,7 +176,7 @@ private: KThread* prev_thread{}; std::atomic current_thread{}; - std::shared_ptr idle_thread; + KThread* idle_thread; std::shared_ptr switch_fiber{}; -- cgit v1.2.3