kern: update scheduler for new switch count tracking logic

This commit is contained in:
Michael Scire 2023-02-21 03:12:17 -07:00
parent 8176f085f1
commit 3a5f406c5f
6 changed files with 39 additions and 18 deletions

View file

@ -263,7 +263,7 @@
/* NOTE: Due to constraints on ldarb relative offsets, KSCHEDULER_NEEDS_SCHEDULING cannot trivially be changed, and will require assembly edits. */
#define KSCHEDULER_NEEDS_SCHEDULING 0x00
#define KSCHEDULER_INTERRUPT_TASK_RUNNABLE 0x01
#define KSCHEDULER_HIGHEST_PRIORITY_THREAD 0x10
#define KSCHEDULER_IDLE_THREAD_STACK 0x18
#define KSCHEDULER_PREVIOUS_THREAD 0x20
#define KSCHEDULER_INTERRUPT_TASK_MANAGER 0x28
#define KSCHEDULER_HIGHEST_PRIORITY_THREAD 0x18
#define KSCHEDULER_IDLE_THREAD_STACK 0x20
#define KSCHEDULER_PREVIOUS_THREAD 0x28
#define KSCHEDULER_INTERRUPT_TASK_MANAGER 0x30

View file

@ -108,6 +108,7 @@ namespace ams::kern {
KWaitObject m_wait_object;
KThread *m_running_threads[cpu::NumCores];
u64 m_running_thread_idle_counts[cpu::NumCores];
u64 m_running_thread_switch_counts[cpu::NumCores];
KThread *m_pinned_threads[cpu::NumCores];
util::Atomic<s64> m_cpu_time;
util::Atomic<s64> m_num_process_switches;
@ -285,9 +286,10 @@ namespace ams::kern {
return m_system_resource->IsSecureResource() ? static_cast<KSecureSystemResource *>(m_system_resource)->GetUsedSize() : 0;
}
void SetRunningThread(s32 core, KThread *thread, u64 idle_count) {
m_running_threads[core] = thread;
m_running_thread_idle_counts[core] = idle_count;
void SetRunningThread(s32 core, KThread *thread, u64 idle_count, u64 switch_count) {
m_running_threads[core] = thread;
m_running_thread_idle_counts[core] = idle_count;
m_running_thread_switch_counts[core] = switch_count;
}
void ClearRunningThread(KThread *thread) {
@ -306,6 +308,7 @@ namespace ams::kern {
constexpr KThread *GetRunningThread(s32 core) const { return m_running_threads[core]; }
constexpr u64 GetRunningThreadIdleCount(s32 core) const { return m_running_thread_idle_counts[core]; }
constexpr u64 GetRunningThreadSwitchCount(s32 core) const { return m_running_thread_switch_counts[core]; }
void RegisterThread(KThread *thread);
void UnregisterThread(KThread *thread);

View file

@ -43,6 +43,7 @@ namespace ams::kern {
bool interrupt_task_runnable{false};
bool should_count_idle{false};
u64 idle_count{0};
u64 switch_count{0};
KThread *highest_priority_thread{nullptr};
void *idle_thread_stack{nullptr};
KThread *prev_thread{nullptr};
@ -67,6 +68,7 @@ namespace ams::kern {
m_state.interrupt_task_runnable = false;
m_state.should_count_idle = false;
m_state.idle_count = 0;
m_state.switch_count = 0;
m_state.idle_thread_stack = nullptr;
m_state.highest_priority_thread = nullptr;
m_state.prev_thread = nullptr;
@ -93,6 +95,10 @@ namespace ams::kern {
return m_state.idle_count;
}
ALWAYS_INLINE u64 GetSwitchCount() const {
return m_state.switch_count;
}
ALWAYS_INLINE KThread *GetIdleThread() const {
return m_idle_thread;
}