diff options
| author | 2015-04-09 23:05:49 -0400 | |
|---|---|---|
| committer | 2015-04-09 23:05:49 -0400 | |
| commit | 6f1143885bcc02642b707b51355fe4b6cd5375c7 (patch) | |
| tree | fe1307919e7087df41c498b971016ffa931d6594 /src | |
| parent | Merge pull request #690 from Zaneo/sharedmemory (diff) | |
| parent | SVC: Assert on unsupported CreateThread processor ID. (diff) | |
| download | yuzu-6f1143885bcc02642b707b51355fe4b6cd5375c7.tar.gz yuzu-6f1143885bcc02642b707b51355fe4b6cd5375c7.tar.xz yuzu-6f1143885bcc02642b707b51355fe4b6cd5375c7.zip | |
Merge pull request #683 from bunnei/thread-priority
Thread priority and scheduler improvements
Diffstat (limited to '')
| -rw-r--r-- | src/common/thread_queue_list.h | 18 | ||||
| -rw-r--r-- | src/core/hle/function_wrappers.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 50 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 32 | ||||
| -rw-r--r-- | src/core/hle/service/apt/apt.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 52 |
9 files changed, 147 insertions, 41 deletions
diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index 444abf115..4f27fc899 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h | |||
| @@ -40,6 +40,18 @@ struct ThreadQueueList { | |||
| 40 | return -1; | 40 | return -1; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | T get_first() { | ||
| 44 | Queue *cur = first; | ||
| 45 | while (cur != nullptr) { | ||
| 46 | if (!cur->data.empty()) { | ||
| 47 | return cur->data.front(); | ||
| 48 | } | ||
| 49 | cur = cur->next_nonempty; | ||
| 50 | } | ||
| 51 | |||
| 52 | return T(); | ||
| 53 | } | ||
| 54 | |||
| 43 | T pop_first() { | 55 | T pop_first() { |
| 44 | Queue *cur = first; | 56 | Queue *cur = first; |
| 45 | while (cur != nullptr) { | 57 | while (cur != nullptr) { |
| @@ -79,6 +91,12 @@ struct ThreadQueueList { | |||
| 79 | cur->data.push_back(thread_id); | 91 | cur->data.push_back(thread_id); |
| 80 | } | 92 | } |
| 81 | 93 | ||
| 94 | void move(const T& thread_id, Priority old_priority, Priority new_priority) { | ||
| 95 | remove(old_priority, thread_id); | ||
| 96 | prepare(new_priority); | ||
| 97 | push_back(new_priority, thread_id); | ||
| 98 | } | ||
| 99 | |||
| 82 | void remove(Priority priority, const T& thread_id) { | 100 | void remove(Priority priority, const T& thread_id) { |
| 83 | Queue *cur = &queues[priority]; | 101 | Queue *cur = &queues[priority]; |
| 84 | boost::remove_erase(cur->data, thread_id); | 102 | boost::remove_erase(cur->data, thread_id); |
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 0b6b6f518..be2626eef 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h | |||
| @@ -46,6 +46,13 @@ template<ResultCode func(u32*, u32, u32, u32, u32, u32)> void Wrap(){ | |||
| 46 | FuncReturn(retval); | 46 | FuncReturn(retval); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | template<ResultCode func(u32*, s32, u32, u32, u32, s32)> void Wrap() { | ||
| 50 | u32 param_1 = 0; | ||
| 51 | u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; | ||
| 52 | Core::g_app_core->SetReg(1, param_1); | ||
| 53 | FuncReturn(retval); | ||
| 54 | } | ||
| 55 | |||
| 49 | template<ResultCode func(s32*, u32*, s32, bool, s64)> void Wrap() { | 56 | template<ResultCode func(s32*, u32*, s32, bool, s64)> void Wrap() { |
| 50 | s32 param_1 = 0; | 57 | s32 param_1 = 0; |
| 51 | s32 retval = func(¶m_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), | 58 | s32 retval = func(¶m_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), |
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 42f8ce2d9..19135266c 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -46,14 +46,12 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 46 | case ArbitrationType::WaitIfLessThan: | 46 | case ArbitrationType::WaitIfLessThan: |
| 47 | if ((s32)Memory::Read32(address) <= value) { | 47 | if ((s32)Memory::Read32(address) <= value) { |
| 48 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 48 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 49 | HLE::Reschedule(__func__); | ||
| 50 | } | 49 | } |
| 51 | break; | 50 | break; |
| 52 | case ArbitrationType::WaitIfLessThanWithTimeout: | 51 | case ArbitrationType::WaitIfLessThanWithTimeout: |
| 53 | if ((s32)Memory::Read32(address) <= value) { | 52 | if ((s32)Memory::Read32(address) <= value) { |
| 54 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 53 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 55 | GetCurrentThread()->WakeAfterDelay(nanoseconds); | 54 | GetCurrentThread()->WakeAfterDelay(nanoseconds); |
| 56 | HLE::Reschedule(__func__); | ||
| 57 | } | 55 | } |
| 58 | break; | 56 | break; |
| 59 | case ArbitrationType::DecrementAndWaitIfLessThan: | 57 | case ArbitrationType::DecrementAndWaitIfLessThan: |
| @@ -62,7 +60,6 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 62 | Memory::Write32(address, memory_value); | 60 | Memory::Write32(address, memory_value); |
| 63 | if (memory_value <= value) { | 61 | if (memory_value <= value) { |
| 64 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 62 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 65 | HLE::Reschedule(__func__); | ||
| 66 | } | 63 | } |
| 67 | break; | 64 | break; |
| 68 | } | 65 | } |
| @@ -73,7 +70,6 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 73 | if (memory_value <= value) { | 70 | if (memory_value <= value) { |
| 74 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 71 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 75 | GetCurrentThread()->WakeAfterDelay(nanoseconds); | 72 | GetCurrentThread()->WakeAfterDelay(nanoseconds); |
| 76 | HLE::Reschedule(__func__); | ||
| 77 | } | 73 | } |
| 78 | break; | 74 | break; |
| 79 | } | 75 | } |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 498b2ec98..6261b82b6 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -154,7 +154,7 @@ void Shutdown() { | |||
| 154 | */ | 154 | */ |
| 155 | bool LoadExec(u32 entry_point) { | 155 | bool LoadExec(u32 entry_point) { |
| 156 | // 0x30 is the typical main thread priority I've seen used so far | 156 | // 0x30 is the typical main thread priority I've seen used so far |
| 157 | g_main_thread = Kernel::SetupMainThread(Kernel::DEFAULT_STACK_SIZE, entry_point, 0x30); | 157 | g_main_thread = Kernel::SetupMainThread(Kernel::DEFAULT_STACK_SIZE, entry_point, THREADPRIO_DEFAULT); |
| 158 | 158 | ||
| 159 | return true; | 159 | return true; |
| 160 | } | 160 | } |
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index be2c49706..ebc9e79d7 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -56,7 +56,15 @@ SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) { | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | bool Mutex::ShouldWait() { | 58 | bool Mutex::ShouldWait() { |
| 59 | return lock_count > 0 && holding_thread != GetCurrentThread();; | 59 | auto thread = GetCurrentThread(); |
| 60 | bool wait = lock_count > 0 && holding_thread != thread; | ||
| 61 | |||
| 62 | // If the holding thread of the mutex is lower priority than this thread, that thread should | ||
| 63 | // temporarily inherit this thread's priority | ||
| 64 | if (wait && thread->current_priority < holding_thread->current_priority) | ||
| 65 | holding_thread->BoostPriority(thread->current_priority); | ||
| 66 | |||
| 67 | return wait; | ||
| 60 | } | 68 | } |
| 61 | 69 | ||
| 62 | void Mutex::Acquire() { | 70 | void Mutex::Acquire() { |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index be1aed615..33d66b986 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -140,6 +140,28 @@ void ArbitrateAllThreads(u32 address) { | |||
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | /// Boost low priority threads (temporarily) that have been starved | ||
| 144 | static void PriorityBoostStarvedThreads() { | ||
| 145 | u64 current_ticks = CoreTiming::GetTicks(); | ||
| 146 | |||
| 147 | for (auto& thread : thread_list) { | ||
| 148 | // TODO(bunnei): Threads that have been waiting to be scheduled for `boost_ticks` (or | ||
| 149 | // longer) will have their priority temporarily adjusted to 1 higher than the highest | ||
| 150 | // priority thread to prevent thread starvation. This general behavior has been verified | ||
| 151 | // on hardware. However, this is almost certainly not perfect, and the real CTR OS scheduler | ||
| 152 | // should probably be reversed to verify this. | ||
| 153 | |||
| 154 | const u64 boost_timeout = 2000000; // Boost threads that have been ready for > this long | ||
| 155 | |||
| 156 | u64 delta = current_ticks - thread->last_running_ticks; | ||
| 157 | |||
| 158 | if (thread->status == THREADSTATUS_READY && delta > boost_timeout && !thread->idle) { | ||
| 159 | const s32 priority = std::max(ready_queue.get_first()->current_priority - 1, 0); | ||
| 160 | thread->BoostPriority(priority); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 143 | /** | 165 | /** |
| 144 | * Switches the CPU's active thread context to that of the specified thread | 166 | * Switches the CPU's active thread context to that of the specified thread |
| 145 | * @param new_thread The thread to switch to | 167 | * @param new_thread The thread to switch to |
| @@ -151,6 +173,7 @@ static void SwitchContext(Thread* new_thread) { | |||
| 151 | 173 | ||
| 152 | // Save context for previous thread | 174 | // Save context for previous thread |
| 153 | if (previous_thread) { | 175 | if (previous_thread) { |
| 176 | previous_thread->last_running_ticks = CoreTiming::GetTicks(); | ||
| 154 | Core::g_app_core->SaveContext(previous_thread->context); | 177 | Core::g_app_core->SaveContext(previous_thread->context); |
| 155 | 178 | ||
| 156 | if (previous_thread->status == THREADSTATUS_RUNNING) { | 179 | if (previous_thread->status == THREADSTATUS_RUNNING) { |
| @@ -168,6 +191,9 @@ static void SwitchContext(Thread* new_thread) { | |||
| 168 | ready_queue.remove(new_thread->current_priority, new_thread); | 191 | ready_queue.remove(new_thread->current_priority, new_thread); |
| 169 | new_thread->status = THREADSTATUS_RUNNING; | 192 | new_thread->status = THREADSTATUS_RUNNING; |
| 170 | 193 | ||
| 194 | // Restores thread to its nominal priority if it has been temporarily changed | ||
| 195 | new_thread->current_priority = new_thread->nominal_priority; | ||
| 196 | |||
| 171 | Core::g_app_core->LoadContext(new_thread->context); | 197 | Core::g_app_core->LoadContext(new_thread->context); |
| 172 | } else { | 198 | } else { |
| 173 | current_thread = nullptr; | 199 | current_thread = nullptr; |
| @@ -364,7 +390,8 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 364 | thread->status = THREADSTATUS_DORMANT; | 390 | thread->status = THREADSTATUS_DORMANT; |
| 365 | thread->entry_point = entry_point; | 391 | thread->entry_point = entry_point; |
| 366 | thread->stack_top = stack_top; | 392 | thread->stack_top = stack_top; |
| 367 | thread->initial_priority = thread->current_priority = priority; | 393 | thread->nominal_priority = thread->current_priority = priority; |
| 394 | thread->last_running_ticks = CoreTiming::GetTicks(); | ||
| 368 | thread->processor_id = processor_id; | 395 | thread->processor_id = processor_id; |
| 369 | thread->wait_set_output = false; | 396 | thread->wait_set_output = false; |
| 370 | thread->wait_all = false; | 397 | thread->wait_all = false; |
| @@ -400,17 +427,15 @@ static void ClampPriority(const Thread* thread, s32* priority) { | |||
| 400 | void Thread::SetPriority(s32 priority) { | 427 | void Thread::SetPriority(s32 priority) { |
| 401 | ClampPriority(this, &priority); | 428 | ClampPriority(this, &priority); |
| 402 | 429 | ||
| 403 | if (current_priority == priority) { | 430 | // If thread was ready, adjust queues |
| 404 | return; | 431 | if (status == THREADSTATUS_READY) |
| 405 | } | 432 | ready_queue.move(this, current_priority, priority); |
| 406 | 433 | ||
| 407 | if (status == THREADSTATUS_READY) { | 434 | nominal_priority = current_priority = priority; |
| 408 | // If thread was ready, adjust queues | 435 | } |
| 409 | ready_queue.remove(current_priority, this); | 436 | |
| 410 | ready_queue.prepare(priority); | 437 | void Thread::BoostPriority(s32 priority) { |
| 411 | ready_queue.push_back(priority, this); | 438 | ready_queue.move(this, current_priority, priority); |
| 412 | } | ||
| 413 | |||
| 414 | current_priority = priority; | 439 | current_priority = priority; |
| 415 | } | 440 | } |
| 416 | 441 | ||
| @@ -440,6 +465,9 @@ SharedPtr<Thread> SetupMainThread(u32 stack_size, u32 entry_point, s32 priority) | |||
| 440 | 465 | ||
| 441 | void Reschedule() { | 466 | void Reschedule() { |
| 442 | Thread* prev = GetCurrentThread(); | 467 | Thread* prev = GetCurrentThread(); |
| 468 | |||
| 469 | PriorityBoostStarvedThreads(); | ||
| 470 | |||
| 443 | Thread* next = PopNextReadyThread(); | 471 | Thread* next = PopNextReadyThread(); |
| 444 | HLE::g_reschedule = false; | 472 | HLE::g_reschedule = false; |
| 445 | 473 | ||
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index cfd073a70..233bcbdbd 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -17,17 +17,19 @@ | |||
| 17 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/result.h" | 18 | #include "core/hle/result.h" |
| 19 | 19 | ||
| 20 | enum ThreadPriority { | 20 | enum ThreadPriority : s32{ |
| 21 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority | 21 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority |
| 22 | THREADPRIO_DEFAULT = 16, ///< Default thread priority for userland apps | 22 | THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps |
| 23 | THREADPRIO_LOW = 31, ///< Low range of thread priority for userland apps | 23 | THREADPRIO_DEFAULT = 48, ///< Default thread priority for userland apps |
| 24 | THREADPRIO_LOWEST = 63, ///< Thread priority max checked by svcCreateThread | 24 | THREADPRIO_LOWEST = 63, ///< Lowest thread priority |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | enum ThreadProcessorId { | 27 | enum ThreadProcessorId : s32 { |
| 28 | THREADPROCESSORID_0 = 0xFFFFFFFE, ///< Enables core appcode | 28 | THREADPROCESSORID_DEFAULT = -2, ///< Run thread on default core specified by exheader |
| 29 | THREADPROCESSORID_1 = 0xFFFFFFFD, ///< Enables core syscore | 29 | THREADPROCESSORID_ALL = -1, ///< Run thread on either core |
| 30 | THREADPROCESSORID_ALL = 0xFFFFFFFC, ///< Enables both cores | 30 | THREADPROCESSORID_0 = 0, ///< Run thread on core 0 (AppCore) |
| 31 | THREADPROCESSORID_1 = 1, ///< Run thread on core 1 (SysCore) | ||
| 32 | THREADPROCESSORID_MAX = 2, ///< Processor ID must be less than this | ||
| 31 | }; | 33 | }; |
| 32 | 34 | ||
| 33 | enum ThreadStatus { | 35 | enum ThreadStatus { |
| @@ -88,6 +90,12 @@ public: | |||
| 88 | void SetPriority(s32 priority); | 90 | void SetPriority(s32 priority); |
| 89 | 91 | ||
| 90 | /** | 92 | /** |
| 93 | * Temporarily boosts the thread's priority until the next time it is scheduled | ||
| 94 | * @param priority The new priority | ||
| 95 | */ | ||
| 96 | void BoostPriority(s32 priority); | ||
| 97 | |||
| 98 | /** | ||
| 91 | * Gets the thread's thread ID | 99 | * Gets the thread's thread ID |
| 92 | * @return The thread's ID | 100 | * @return The thread's ID |
| 93 | */ | 101 | */ |
| @@ -135,8 +143,10 @@ public: | |||
| 135 | u32 entry_point; | 143 | u32 entry_point; |
| 136 | u32 stack_top; | 144 | u32 stack_top; |
| 137 | 145 | ||
| 138 | s32 initial_priority; | 146 | s32 nominal_priority; ///< Nominal thread priority, as set by the emulated application |
| 139 | s32 current_priority; | 147 | s32 current_priority; ///< Current thread priority, can be temporarily changed |
| 148 | |||
| 149 | u64 last_running_ticks; ///< CPU tick when thread was last running | ||
| 140 | 150 | ||
| 141 | s32 processor_id; | 151 | s32 processor_id; |
| 142 | 152 | ||
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 4861d9e5f..190c5df7a 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp | |||
| @@ -32,7 +32,8 @@ static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem = nullptr; | |||
| 32 | 32 | ||
| 33 | static Kernel::SharedPtr<Kernel::Mutex> lock = nullptr; | 33 | static Kernel::SharedPtr<Kernel::Mutex> lock = nullptr; |
| 34 | static Kernel::SharedPtr<Kernel::Event> notification_event = nullptr; ///< APT notification event | 34 | static Kernel::SharedPtr<Kernel::Event> notification_event = nullptr; ///< APT notification event |
| 35 | static Kernel::SharedPtr<Kernel::Event> pause_event = nullptr; ///< APT pause event | 35 | static Kernel::SharedPtr<Kernel::Event> start_event = nullptr; ///< APT start event |
| 36 | |||
| 36 | static std::vector<u8> shared_font; | 37 | static std::vector<u8> shared_font; |
| 37 | 38 | ||
| 38 | static u32 cpu_percent = 0; ///< CPU time available to the running application | 39 | static u32 cpu_percent = 0; ///< CPU time available to the running application |
| @@ -44,11 +45,11 @@ void Initialize(Service::Interface* self) { | |||
| 44 | 45 | ||
| 45 | cmd_buff[2] = 0x04000000; // According to 3dbrew, this value should be 0x04000000 | 46 | cmd_buff[2] = 0x04000000; // According to 3dbrew, this value should be 0x04000000 |
| 46 | cmd_buff[3] = Kernel::g_handle_table.Create(notification_event).MoveFrom(); | 47 | cmd_buff[3] = Kernel::g_handle_table.Create(notification_event).MoveFrom(); |
| 47 | cmd_buff[4] = Kernel::g_handle_table.Create(pause_event).MoveFrom(); | 48 | cmd_buff[4] = Kernel::g_handle_table.Create(start_event).MoveFrom(); |
| 48 | 49 | ||
| 49 | // TODO(bunnei): Check if these events are cleared/signaled every time Initialize is called. | 50 | // TODO(bunnei): Check if these events are cleared every time Initialize is called. |
| 50 | notification_event->Clear(); | 51 | notification_event->Clear(); |
| 51 | pause_event->Signal(); // Fire start event | 52 | start_event->Clear(); |
| 52 | 53 | ||
| 53 | ASSERT_MSG((nullptr != lock), "Cannot initialize without lock"); | 54 | ASSERT_MSG((nullptr != lock), "Cannot initialize without lock"); |
| 54 | lock->Release(); | 55 | lock->Release(); |
| @@ -81,7 +82,7 @@ void NotifyToWait(Service::Interface* self) { | |||
| 81 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 82 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 82 | u32 app_id = cmd_buff[1]; | 83 | u32 app_id = cmd_buff[1]; |
| 83 | // TODO(Subv): Verify this, it seems to get SWKBD and Home Menu further. | 84 | // TODO(Subv): Verify this, it seems to get SWKBD and Home Menu further. |
| 84 | pause_event->Signal(); | 85 | start_event->Signal(); |
| 85 | 86 | ||
| 86 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 87 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 87 | LOG_WARNING(Service_APT, "(STUBBED) app_id=%u", app_id); | 88 | LOG_WARNING(Service_APT, "(STUBBED) app_id=%u", app_id); |
| @@ -312,7 +313,7 @@ void Init() { | |||
| 312 | 313 | ||
| 313 | // TODO(bunnei): Check if these are created in Initialize or on APT process startup. | 314 | // TODO(bunnei): Check if these are created in Initialize or on APT process startup. |
| 314 | notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification"); | 315 | notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification"); |
| 315 | pause_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Pause"); | 316 | start_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Start"); |
| 316 | } | 317 | } |
| 317 | 318 | ||
| 318 | void Shutdown() { | 319 | void Shutdown() { |
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index bbb4eb9cd..76e9b171a 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -283,8 +283,13 @@ static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 val | |||
| 283 | if (arbiter == nullptr) | 283 | if (arbiter == nullptr) |
| 284 | return ERR_INVALID_HANDLE; | 284 | return ERR_INVALID_HANDLE; |
| 285 | 285 | ||
| 286 | return arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), | 286 | auto res = arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), |
| 287 | address, value, nanoseconds); | 287 | address, value, nanoseconds); |
| 288 | |||
| 289 | if (res == RESULT_SUCCESS) | ||
| 290 | HLE::Reschedule(__func__); | ||
| 291 | |||
| 292 | return res; | ||
| 288 | } | 293 | } |
| 289 | 294 | ||
| 290 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit | 295 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit |
| @@ -312,7 +317,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim | |||
| 312 | } | 317 | } |
| 313 | 318 | ||
| 314 | /// Creates a new thread | 319 | /// Creates a new thread |
| 315 | static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { | 320 | static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { |
| 316 | using Kernel::Thread; | 321 | using Kernel::Thread; |
| 317 | 322 | ||
| 318 | std::string name; | 323 | std::string name; |
| @@ -323,6 +328,27 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u | |||
| 323 | name = Common::StringFromFormat("unknown-%08x", entry_point); | 328 | name = Common::StringFromFormat("unknown-%08x", entry_point); |
| 324 | } | 329 | } |
| 325 | 330 | ||
| 331 | // TODO(bunnei): Implement resource limits to return an error code instead of the below assert. | ||
| 332 | // The error code should be: Description::NotAuthorized, Module::OS, Summary::WrongArgument, | ||
| 333 | // Level::Permanent | ||
| 334 | ASSERT_MSG(priority >= THREADPRIO_USERLAND_MAX, "Unexpected thread priority!"); | ||
| 335 | |||
| 336 | if (priority > THREADPRIO_LOWEST) { | ||
| 337 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, | ||
| 338 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 339 | } | ||
| 340 | |||
| 341 | switch (processor_id) { | ||
| 342 | case THREADPROCESSORID_DEFAULT: | ||
| 343 | case THREADPROCESSORID_0: | ||
| 344 | case THREADPROCESSORID_1: | ||
| 345 | break; | ||
| 346 | default: | ||
| 347 | // TODO(bunnei): Implement support for other processor IDs | ||
| 348 | ASSERT_MSG(false, "Unsupported thread processor ID: %d", processor_id); | ||
| 349 | break; | ||
| 350 | } | ||
| 351 | |||
| 326 | CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create( | 352 | CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create( |
| 327 | name, entry_point, priority, arg, processor_id, stack_top)); | 353 | name, entry_point, priority, arg, processor_id, stack_top)); |
| 328 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); | 354 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); |
| @@ -331,10 +357,7 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u | |||
| 331 | "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, | 357 | "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, |
| 332 | name.c_str(), arg, stack_top, priority, processor_id, *out_handle); | 358 | name.c_str(), arg, stack_top, priority, processor_id, *out_handle); |
| 333 | 359 | ||
| 334 | if (THREADPROCESSORID_1 == processor_id) { | 360 | HLE::Reschedule(__func__); |
| 335 | LOG_WARNING(Kernel_SVC, | ||
| 336 | "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling"); | ||
| 337 | } | ||
| 338 | 361 | ||
| 339 | return RESULT_SUCCESS; | 362 | return RESULT_SUCCESS; |
| 340 | } | 363 | } |
| @@ -374,8 +397,11 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { | |||
| 374 | SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0); | 397 | SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0); |
| 375 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); | 398 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); |
| 376 | 399 | ||
| 400 | HLE::Reschedule(__func__); | ||
| 401 | |||
| 377 | LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", | 402 | LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", |
| 378 | initial_locked ? "true" : "false", *out_handle); | 403 | initial_locked ? "true" : "false", *out_handle); |
| 404 | |||
| 379 | return RESULT_SUCCESS; | 405 | return RESULT_SUCCESS; |
| 380 | } | 406 | } |
| 381 | 407 | ||
| @@ -390,6 +416,9 @@ static ResultCode ReleaseMutex(Handle handle) { | |||
| 390 | return ERR_INVALID_HANDLE; | 416 | return ERR_INVALID_HANDLE; |
| 391 | 417 | ||
| 392 | mutex->Release(); | 418 | mutex->Release(); |
| 419 | |||
| 420 | HLE::Reschedule(__func__); | ||
| 421 | |||
| 393 | return RESULT_SUCCESS; | 422 | return RESULT_SUCCESS; |
| 394 | } | 423 | } |
| 395 | 424 | ||
| @@ -428,6 +457,9 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) | |||
| 428 | return ERR_INVALID_HANDLE; | 457 | return ERR_INVALID_HANDLE; |
| 429 | 458 | ||
| 430 | CASCADE_RESULT(*count, semaphore->Release(release_count)); | 459 | CASCADE_RESULT(*count, semaphore->Release(release_count)); |
| 460 | |||
| 461 | HLE::Reschedule(__func__); | ||
| 462 | |||
| 431 | return RESULT_SUCCESS; | 463 | return RESULT_SUCCESS; |
| 432 | } | 464 | } |
| 433 | 465 | ||
| @@ -520,6 +552,9 @@ static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { | |||
| 520 | return ERR_INVALID_HANDLE; | 552 | return ERR_INVALID_HANDLE; |
| 521 | 553 | ||
| 522 | timer->Set(initial, interval); | 554 | timer->Set(initial, interval); |
| 555 | |||
| 556 | HLE::Reschedule(__func__); | ||
| 557 | |||
| 523 | return RESULT_SUCCESS; | 558 | return RESULT_SUCCESS; |
| 524 | } | 559 | } |
| 525 | 560 | ||
| @@ -534,6 +569,9 @@ static ResultCode CancelTimer(Handle handle) { | |||
| 534 | return ERR_INVALID_HANDLE; | 569 | return ERR_INVALID_HANDLE; |
| 535 | 570 | ||
| 536 | timer->Cancel(); | 571 | timer->Cancel(); |
| 572 | |||
| 573 | HLE::Reschedule(__func__); | ||
| 574 | |||
| 537 | return RESULT_SUCCESS; | 575 | return RESULT_SUCCESS; |
| 538 | } | 576 | } |
| 539 | 577 | ||