mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-24 18:43:03 +00:00
kern: fix minor assembly bugs, avoid unnecessary function call in KScheduler hotloop
This commit is contained in:
parent
92321ccbc8
commit
d1f3c4904b
6 changed files with 20 additions and 16 deletions
|
@ -19,6 +19,9 @@
|
|||
/* TODO: Different header for this? */
|
||||
#define AMS_KERN_NUM_SUPERVISOR_CALLS 0xC0
|
||||
|
||||
/* ams::kern::KThread, https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp */
|
||||
#define THREAD_THREAD_CONTEXT 0xD0
|
||||
|
||||
/* ams::kern::KThread::StackParameters, https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp */
|
||||
#define THREAD_STACK_PARAMETERS_SIZE 0x30
|
||||
#define THREAD_STACK_PARAMETERS_SVC_PERMISSION 0x00
|
||||
|
|
|
@ -405,8 +405,6 @@ namespace ams::kern {
|
|||
constexpr ThreadState GetState() const { return static_cast<ThreadState>(m_thread_state & ThreadState_Mask); }
|
||||
constexpr ThreadState GetRawState() const { return m_thread_state; }
|
||||
|
||||
NOINLINE KThreadContext *GetContextForSchedulerLoop();
|
||||
|
||||
constexpr uintptr_t GetConditionVariableKey() const { return m_condvar_key; }
|
||||
constexpr uintptr_t GetAddressArbiterKey() const { return m_condvar_key; }
|
||||
|
||||
|
@ -624,9 +622,7 @@ namespace ams::kern {
|
|||
void OnTimer();
|
||||
void DoWorkerTaskImpl();
|
||||
public:
|
||||
static constexpr bool IsConditionVariableThreadTreeValid() {
|
||||
return ConditionVariableThreadTreeTraits::IsValid();
|
||||
}
|
||||
static consteval bool IsKThreadStructurallyValid();
|
||||
|
||||
static KThread *GetThreadFromId(u64 thread_id);
|
||||
static Result GetThreadList(s32 *out_num_threads, ams::kern::svc::KUserPointer<u64 *> out_thread_ids, s32 max_out_count);
|
||||
|
@ -634,7 +630,18 @@ namespace ams::kern {
|
|||
using ConditionVariableThreadTreeType = ConditionVariableThreadTree;
|
||||
};
|
||||
static_assert(alignof(KThread) == 0x10);
|
||||
static_assert(KThread::IsConditionVariableThreadTreeValid());
|
||||
|
||||
consteval bool KThread::IsKThreadStructurallyValid() {
|
||||
/* Check that the condition variable tree is valid. */
|
||||
static_assert(ConditionVariableThreadTreeTraits::IsValid());
|
||||
|
||||
/* Check that the assembly offsets are valid. */
|
||||
static_assert(AMS_OFFSETOF(KThread, m_thread_context) == THREAD_THREAD_CONTEXT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(KThread::IsKThreadStructurallyValid());
|
||||
|
||||
class KScopedDisableDispatch {
|
||||
public:
|
||||
|
|
|
@ -28,7 +28,7 @@ _ZN3ams4kern3svc25CallReturnFromException64Ev:
|
|||
stp x20, x21, [sp, #(EXCEPTION_CONTEXT_X20_X21)]
|
||||
stp x22, x23, [sp, #(EXCEPTION_CONTEXT_X22_X23)]
|
||||
stp x24, x25, [sp, #(EXCEPTION_CONTEXT_X24_X25)]
|
||||
stp x26, x26, [sp, #(EXCEPTION_CONTEXT_X26_X27)]
|
||||
stp x26, x27, [sp, #(EXCEPTION_CONTEXT_X26_X27)]
|
||||
stp x28, x29, [sp, #(EXCEPTION_CONTEXT_X28_X29)]
|
||||
|
||||
/* Call ams::kern::arch::arm64::ReturnFromException(result). */
|
||||
|
|
|
@ -1315,10 +1315,6 @@ namespace ams::kern {
|
|||
}
|
||||
}
|
||||
|
||||
KThreadContext *KThread::GetContextForSchedulerLoop() {
|
||||
return std::addressof(this->GetContext());
|
||||
}
|
||||
|
||||
KThread *KThread::GetThreadFromId(u64 thread_id) {
|
||||
/* Lock the list. */
|
||||
KThread::ListAccessor accessor;
|
||||
|
|
|
@ -376,7 +376,7 @@ _ZN3ams4kern4arch5arm6430EL1SynchronousExceptionHandlerEv:
|
|||
stp x26, x27, [sp, #(EXCEPTION_CONTEXT_X26_X27)]
|
||||
stp x28, x29, [sp, #(EXCEPTION_CONTEXT_X28_X29)]
|
||||
|
||||
mrs x20, sp_el0
|
||||
ldr x20, [sp]
|
||||
mrs x21, elr_el1
|
||||
mrs x22, spsr_el1
|
||||
mrs x23, tpidr_el0
|
||||
|
@ -529,7 +529,7 @@ _ZN3ams4kern4arch5arm6421EL1SystemErrorHandlerEv:
|
|||
stp x26, x27, [sp, #(EXCEPTION_CONTEXT_X26_X27)]
|
||||
stp x28, x29, [sp, #(EXCEPTION_CONTEXT_X28_X29)]
|
||||
|
||||
mrs x20, sp_el0
|
||||
ldr x20, [sp]
|
||||
mrs x21, elr_el1
|
||||
mrs x22, spsr_el1
|
||||
mrs x23, tpidr_el0
|
||||
|
|
|
@ -183,9 +183,7 @@ _ZN3ams4kern10KScheduler12ScheduleImplEv:
|
|||
|
||||
/* Get the highest priority thread's context, and save it. */
|
||||
/* ams::kern::KThread::GetContextForSchedulerLoop() */
|
||||
mov x0, x21
|
||||
bl _ZN3ams4kern7KThread26GetContextForSchedulerLoopEv
|
||||
mov x22, x0
|
||||
add x22, x21, #(THREAD_THREAD_CONTEXT)
|
||||
|
||||
/* Prepare to try to acquire the context lock. */
|
||||
add x1, x22, #(THREAD_CONTEXT_LOCKED)
|
||||
|
|
Loading…
Reference in a new issue