diff options
| author | 2021-01-01 02:06:06 -0800 | |
|---|---|---|
| committer | 2021-01-28 21:42:25 -0800 | |
| commit | 1e55498110800623c63e3ef03bfbff6b6de1c522 (patch) | |
| tree | 77437e33162d077c3aa86204b4f47a11d7769a42 /src | |
| parent | hle: kernel: KThread: Fix ThreadType definition. (diff) | |
| download | yuzu-1e55498110800623c63e3ef03bfbff6b6de1c522.tar.gz yuzu-1e55498110800623c63e3ef03bfbff6b6de1c522.tar.xz yuzu-1e55498110800623c63e3ef03bfbff6b6de1c522.zip | |
hle: kernel: KThread: Reorganize thread priority defaults.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/global_scheduler_context.h | 9 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_scheduler.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/kernel/k_thread.h | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc_results.h | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc_types.h | 3 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 4 |
9 files changed, 31 insertions, 31 deletions
diff --git a/src/core/hle/kernel/global_scheduler_context.h b/src/core/hle/kernel/global_scheduler_context.h index a365ffdaf..11592843e 100644 --- a/src/core/hle/kernel/global_scheduler_context.h +++ b/src/core/hle/kernel/global_scheduler_context.h | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "core/hle/kernel/k_priority_queue.h" | 13 | #include "core/hle/kernel/k_priority_queue.h" |
| 14 | #include "core/hle/kernel/k_scheduler_lock.h" | 14 | #include "core/hle/kernel/k_scheduler_lock.h" |
| 15 | #include "core/hle/kernel/k_thread.h" | 15 | #include "core/hle/kernel/k_thread.h" |
| 16 | #include "core/hle/kernel/svc_types.h" | ||
| 16 | 17 | ||
| 17 | namespace Kernel { | 18 | namespace Kernel { |
| 18 | 19 | ||
| @@ -20,8 +21,12 @@ class KernelCore; | |||
| 20 | class SchedulerLock; | 21 | class SchedulerLock; |
| 21 | 22 | ||
| 22 | using KSchedulerPriorityQueue = | 23 | using KSchedulerPriorityQueue = |
| 23 | KPriorityQueue<KThread, Core::Hardware::NUM_CPU_CORES, THREADPRIO_LOWEST, THREADPRIO_HIGHEST>; | 24 | KPriorityQueue<KThread, Core::Hardware::NUM_CPU_CORES, Svc::LowestThreadPriority, |
| 24 | constexpr s32 HighestCoreMigrationAllowedPriority = 2; | 25 | Svc::HighestThreadPriority>; |
| 26 | |||
| 27 | static constexpr s32 HighestCoreMigrationAllowedPriority = 2; | ||
| 28 | static_assert(Svc::LowestThreadPriority >= HighestCoreMigrationAllowedPriority); | ||
| 29 | static_assert(Svc::HighestThreadPriority <= HighestCoreMigrationAllowedPriority); | ||
| 25 | 30 | ||
| 26 | class GlobalSchedulerContext final { | 31 | class GlobalSchedulerContext final { |
| 27 | friend class KScheduler; | 32 | friend class KScheduler; |
diff --git a/src/core/hle/kernel/k_scheduler.cpp b/src/core/hle/kernel/k_scheduler.cpp index 0f34a8a69..0e6300760 100644 --- a/src/core/hle/kernel/k_scheduler.cpp +++ b/src/core/hle/kernel/k_scheduler.cpp | |||
| @@ -763,9 +763,9 @@ void KScheduler::Initialize() { | |||
| 763 | std::string name = "Idle Thread Id:" + std::to_string(core_id); | 763 | std::string name = "Idle Thread Id:" + std::to_string(core_id); |
| 764 | std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); | 764 | std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); |
| 765 | void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); | 765 | void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); |
| 766 | auto thread_res = KThread::Create(system, ThreadType::Kernel, name, 0, THREADPRIO_LOWEST, 0, | 766 | auto thread_res = KThread::Create(system, ThreadType::Kernel, name, 0, |
| 767 | static_cast<u32>(core_id), 0, nullptr, std::move(init_func), | 767 | Svc::LowestThreadPriority, 0, static_cast<u32>(core_id), 0, |
| 768 | init_func_parameter); | 768 | nullptr, std::move(init_func), init_func_parameter); |
| 769 | idle_thread = thread_res.Unwrap().get(); | 769 | idle_thread = thread_res.Unwrap().get(); |
| 770 | 770 | ||
| 771 | { | 771 | { |
diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 0f349dad2..518c5d5df 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | 9 | ||
| 10 | #include "common/assert.h" | 10 | #include "common/assert.h" |
| 11 | #include "common/common_funcs.h" | ||
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 12 | #include "common/fiber.h" | 13 | #include "common/fiber.h" |
| 13 | #include "common/logging/log.h" | 14 | #include "common/logging/log.h" |
| @@ -25,6 +26,7 @@ | |||
| 25 | #include "core/hle/kernel/memory/memory_layout.h" | 26 | #include "core/hle/kernel/memory/memory_layout.h" |
| 26 | #include "core/hle/kernel/object.h" | 27 | #include "core/hle/kernel/object.h" |
| 27 | #include "core/hle/kernel/process.h" | 28 | #include "core/hle/kernel/process.h" |
| 29 | #include "core/hle/kernel/svc_results.h" | ||
| 28 | #include "core/hle/kernel/time_manager.h" | 30 | #include "core/hle/kernel/time_manager.h" |
| 29 | #include "core/hle/result.h" | 31 | #include "core/hle/result.h" |
| 30 | #include "core/memory.h" | 32 | #include "core/memory.h" |
| @@ -124,11 +126,9 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread | |||
| 124 | std::function<void(void*)>&& thread_start_func, | 126 | std::function<void(void*)>&& thread_start_func, |
| 125 | void* thread_start_parameter) { | 127 | void* thread_start_parameter) { |
| 126 | auto& kernel = system.Kernel(); | 128 | auto& kernel = system.Kernel(); |
| 127 | // Check if priority is in ranged. Lowest priority -> highest priority id. | 129 | |
| 128 | if (priority > THREADPRIO_LOWEST) { | 130 | R_UNLESS(Svc::HighestThreadPriority <= priority && priority <= Svc::LowestThreadPriority, |
| 129 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); | 131 | Svc::ResultInvalidPriority); |
| 130 | return ERR_INVALID_THREAD_PRIORITY; | ||
| 131 | } | ||
| 132 | 132 | ||
| 133 | if (processor_id > THREADPROCESSORID_MAX) { | 133 | if (processor_id > THREADPROCESSORID_MAX) { |
| 134 | LOG_ERROR(Kernel_SVC, "Invalid processor id: {}", processor_id); | 134 | LOG_ERROR(Kernel_SVC, "Invalid processor id: {}", processor_id); |
| @@ -186,8 +186,7 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread | |||
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | void KThread::SetBasePriority(u32 priority) { | 188 | void KThread::SetBasePriority(u32 priority) { |
| 189 | ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, | 189 | ASSERT(Svc::HighestThreadPriority <= priority && priority <= Svc::LowestThreadPriority); |
| 190 | "Invalid priority value."); | ||
| 191 | 190 | ||
| 192 | KScopedSchedulerLock lock(kernel); | 191 | KScopedSchedulerLock lock(kernel); |
| 193 | 192 | ||
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index bef480dd7..83a6d36ae 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h | |||
| @@ -39,15 +39,6 @@ class KernelCore; | |||
| 39 | class Process; | 39 | class Process; |
| 40 | class KScheduler; | 40 | class KScheduler; |
| 41 | 41 | ||
| 42 | enum ThreadPriority : u32 { | ||
| 43 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority | ||
| 44 | THREADPRIO_MAX_CORE_MIGRATION = 2, ///< Highest priority for a core migration | ||
| 45 | THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps | ||
| 46 | THREADPRIO_DEFAULT = 44, ///< Default thread priority for userland apps | ||
| 47 | THREADPRIO_LOWEST = 63, ///< Lowest thread priority | ||
| 48 | THREADPRIO_COUNT = 64, ///< Total number of possible thread priorities. | ||
| 49 | }; | ||
| 50 | |||
| 51 | enum class ThreadType : u32 { | 42 | enum class ThreadType : u32 { |
| 52 | Main = 0, | 43 | Main = 0, |
| 53 | Kernel = 1, | 44 | Kernel = 1, |
| @@ -129,6 +120,9 @@ class KThread final : public KSynchronizationObject, public boost::intrusive::li | |||
| 129 | friend class Process; | 120 | friend class Process; |
| 130 | 121 | ||
| 131 | public: | 122 | public: |
| 123 | static constexpr s32 DefaultThreadPriority = 44; | ||
| 124 | static constexpr s32 IdleThreadPriority = 64; | ||
| 125 | |||
| 132 | explicit KThread(KernelCore& kernel); | 126 | explicit KThread(KernelCore& kernel); |
| 133 | ~KThread() override; | 127 | ~KThread() override; |
| 134 | 128 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 711b9d520..70a8ef34b 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1130,11 +1130,9 @@ static ResultCode GetThreadPriority32(Core::System& system, u32* priority, Handl | |||
| 1130 | static ResultCode SetThreadPriority(Core::System& system, Handle handle, u32 priority) { | 1130 | static ResultCode SetThreadPriority(Core::System& system, Handle handle, u32 priority) { |
| 1131 | LOG_TRACE(Kernel_SVC, "called"); | 1131 | LOG_TRACE(Kernel_SVC, "called"); |
| 1132 | 1132 | ||
| 1133 | if (priority > THREADPRIO_LOWEST) { | 1133 | if (priority > Svc::LowestThreadPriority) { |
| 1134 | LOG_ERROR( | 1134 | LOG_ERROR(Kernel_SVC, "An invalid priority was specified {} for thread_handle={:08X}", |
| 1135 | Kernel_SVC, | 1135 | priority, handle); |
| 1136 | "An invalid priority was specified, expected {} but got {} for thread_handle={:08X}", | ||
| 1137 | THREADPRIO_LOWEST, priority, handle); | ||
| 1138 | return ERR_INVALID_THREAD_PRIORITY; | 1136 | return ERR_INVALID_THREAD_PRIORITY; |
| 1139 | } | 1137 | } |
| 1140 | 1138 | ||
| @@ -1472,7 +1470,7 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e | |||
| 1472 | return ERR_INVALID_PROCESSOR_ID; | 1470 | return ERR_INVALID_PROCESSOR_ID; |
| 1473 | } | 1471 | } |
| 1474 | 1472 | ||
| 1475 | if (priority > THREADPRIO_LOWEST) { | 1473 | if (priority > Svc::LowestThreadPriority) { |
| 1476 | LOG_ERROR(Kernel_SVC, | 1474 | LOG_ERROR(Kernel_SVC, |
| 1477 | "Invalid thread priority specified ({}). Must be within the range 0-64", | 1475 | "Invalid thread priority specified ({}). Must be within the range 0-64", |
| 1478 | priority); | 1476 | priority); |
diff --git a/src/core/hle/kernel/svc_results.h b/src/core/hle/kernel/svc_results.h index 78282f021..74adabc11 100644 --- a/src/core/hle/kernel/svc_results.h +++ b/src/core/hle/kernel/svc_results.h | |||
| @@ -11,6 +11,7 @@ namespace Kernel::Svc { | |||
| 11 | constexpr ResultCode ResultTerminationRequested{ErrorModule::Kernel, 59}; | 11 | constexpr ResultCode ResultTerminationRequested{ErrorModule::Kernel, 59}; |
| 12 | constexpr ResultCode ResultInvalidAddress{ErrorModule::Kernel, 102}; | 12 | constexpr ResultCode ResultInvalidAddress{ErrorModule::Kernel, 102}; |
| 13 | constexpr ResultCode ResultInvalidCurrentMemory{ErrorModule::Kernel, 106}; | 13 | constexpr ResultCode ResultInvalidCurrentMemory{ErrorModule::Kernel, 106}; |
| 14 | constexpr ResultCode ResultInvalidPriority{ErrorModule::Kernel, 112}; | ||
| 14 | constexpr ResultCode ResultInvalidHandle{ErrorModule::Kernel, 114}; | 15 | constexpr ResultCode ResultInvalidHandle{ErrorModule::Kernel, 114}; |
| 15 | constexpr ResultCode ResultTimedOut{ErrorModule::Kernel, 117}; | 16 | constexpr ResultCode ResultTimedOut{ErrorModule::Kernel, 117}; |
| 16 | constexpr ResultCode ResultCancelled{ErrorModule::Kernel, 118}; | 17 | constexpr ResultCode ResultCancelled{ErrorModule::Kernel, 118}; |
diff --git a/src/core/hle/kernel/svc_types.h b/src/core/hle/kernel/svc_types.h index d623f7a50..09b858f2a 100644 --- a/src/core/hle/kernel/svc_types.h +++ b/src/core/hle/kernel/svc_types.h | |||
| @@ -77,4 +77,7 @@ enum class ArbitrationType : u32 { | |||
| 77 | WaitIfEqual = 2, | 77 | WaitIfEqual = 2, |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | constexpr inline s32 LowestThreadPriority = 63; | ||
| 81 | constexpr inline s32 HighestThreadPriority = 0; | ||
| 82 | |||
| 80 | } // namespace Kernel::Svc | 83 | } // namespace Kernel::Svc |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 4f55314c7..f976d0a9c 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -219,8 +219,8 @@ AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process, Core::Sy | |||
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | is_loaded = true; | 221 | is_loaded = true; |
| 222 | return {ResultStatus::Success, | 222 | return {ResultStatus::Success, LoadParameters{Kernel::KThread::DefaultThreadPriority, |
| 223 | LoadParameters{Kernel::THREADPRIO_DEFAULT, Core::Memory::DEFAULT_STACK_SIZE}}; | 223 | Core::Memory::DEFAULT_STACK_SIZE}}; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { | 226 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 50e6cd080..ea347ea83 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -179,8 +179,8 @@ AppLoader_NSO::LoadResult AppLoader_NSO::Load(Kernel::Process& process, Core::Sy | |||
| 179 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); | 179 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); |
| 180 | 180 | ||
| 181 | is_loaded = true; | 181 | is_loaded = true; |
| 182 | return {ResultStatus::Success, | 182 | return {ResultStatus::Success, LoadParameters{Kernel::KThread::DefaultThreadPriority, |
| 183 | LoadParameters{Kernel::THREADPRIO_DEFAULT, Core::Memory::DEFAULT_STACK_SIZE}}; | 183 | Core::Memory::DEFAULT_STACK_SIZE}}; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | ResultStatus AppLoader_NSO::ReadNSOModules(Modules& modules) { | 186 | ResultStatus AppLoader_NSO::ReadNSOModules(Modules& modules) { |