diff options
| author | 2020-02-25 13:22:11 -0400 | |
|---|---|---|
| committer | 2020-06-27 11:35:12 -0400 | |
| commit | 589f9cf108d306e8265ff4856b522cd32fbc121f (patch) | |
| tree | d9e78acb03901cdbbc3f7649b03048f7cd946f06 /src | |
| parent | SVC: Correct CreateThread, StartThread, ExitThread, SleepThread. (diff) | |
| download | yuzu-589f9cf108d306e8265ff4856b522cd32fbc121f.tar.gz yuzu-589f9cf108d306e8265ff4856b522cd32fbc121f.tar.xz yuzu-589f9cf108d306e8265ff4856b522cd32fbc121f.zip | |
SVC: Correct GetThreadPriority, SetThreadPriority, GetThreadCoreMask, SetThreadCoreMask, GetCurrentProcessorNumber
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/core.cpp | 8 | ||||
| -rw-r--r-- | src/core/core.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 17 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 3 |
5 files changed, 26 insertions, 15 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 1d6179a80..5d4ecdce5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -467,6 +467,14 @@ const Kernel::Scheduler& System::CurrentScheduler() const { | |||
| 467 | return impl->CurrentPhysicalCore().Scheduler(); | 467 | return impl->CurrentPhysicalCore().Scheduler(); |
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | Kernel::PhysicalCore& System::CurrentPhysicalCore() { | ||
| 471 | return impl->CurrentPhysicalCore(); | ||
| 472 | } | ||
| 473 | |||
| 474 | const Kernel::PhysicalCore& System::CurrentPhysicalCore() const { | ||
| 475 | return impl->CurrentPhysicalCore(); | ||
| 476 | } | ||
| 477 | |||
| 470 | Kernel::Scheduler& System::Scheduler(std::size_t core_index) { | 478 | Kernel::Scheduler& System::Scheduler(std::size_t core_index) { |
| 471 | return impl->GetPhysicalCore(core_index).Scheduler(); | 479 | return impl->GetPhysicalCore(core_index).Scheduler(); |
| 472 | } | 480 | } |
diff --git a/src/core/core.h b/src/core/core.h index 7f170fc54..9a0dd1075 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -27,6 +27,7 @@ class VfsFilesystem; | |||
| 27 | namespace Kernel { | 27 | namespace Kernel { |
| 28 | class GlobalScheduler; | 28 | class GlobalScheduler; |
| 29 | class KernelCore; | 29 | class KernelCore; |
| 30 | class PhysicalCore; | ||
| 30 | class Process; | 31 | class Process; |
| 31 | class Scheduler; | 32 | class Scheduler; |
| 32 | } // namespace Kernel | 33 | } // namespace Kernel |
| @@ -211,6 +212,12 @@ public: | |||
| 211 | /// Gets the scheduler for the CPU core that is currently running | 212 | /// Gets the scheduler for the CPU core that is currently running |
| 212 | const Kernel::Scheduler& CurrentScheduler() const; | 213 | const Kernel::Scheduler& CurrentScheduler() const; |
| 213 | 214 | ||
| 215 | /// Gets the physical core for the CPU core that is currently running | ||
| 216 | Kernel::PhysicalCore& CurrentPhysicalCore(); | ||
| 217 | |||
| 218 | /// Gets the physical core for the CPU core that is currently running | ||
| 219 | const Kernel::PhysicalCore& CurrentPhysicalCore() const; | ||
| 220 | |||
| 214 | /// Gets a reference to an ARM interface for the CPU core with the specified index | 221 | /// Gets a reference to an ARM interface for the CPU core with the specified index |
| 215 | ARM_Interface& ArmInterface(std::size_t core_index); | 222 | ARM_Interface& ArmInterface(std::size_t core_index); |
| 216 | 223 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index dfb032b4b..2a218e294 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include "core/hle/kernel/memory/memory_block.h" | 27 | #include "core/hle/kernel/memory/memory_block.h" |
| 28 | #include "core/hle/kernel/memory/page_table.h" | 28 | #include "core/hle/kernel/memory/page_table.h" |
| 29 | #include "core/hle/kernel/mutex.h" | 29 | #include "core/hle/kernel/mutex.h" |
| 30 | #include "core/hle/kernel/physical_core.h" | ||
| 30 | #include "core/hle/kernel/process.h" | 31 | #include "core/hle/kernel/process.h" |
| 31 | #include "core/hle/kernel/readable_event.h" | 32 | #include "core/hle/kernel/readable_event.h" |
| 32 | #include "core/hle/kernel/resource_limit.h" | 33 | #include "core/hle/kernel/resource_limit.h" |
| @@ -1071,6 +1072,7 @@ static ResultCode GetThreadPriority(Core::System& system, u32* priority, Handle | |||
| 1071 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 1072 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); |
| 1072 | const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(handle); | 1073 | const std::shared_ptr<Thread> thread = handle_table.Get<Thread>(handle); |
| 1073 | if (!thread) { | 1074 | if (!thread) { |
| 1075 | *priority = 0; | ||
| 1074 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); | 1076 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, handle=0x{:08X}", handle); |
| 1075 | return ERR_INVALID_HANDLE; | 1077 | return ERR_INVALID_HANDLE; |
| 1076 | } | 1078 | } |
| @@ -1105,14 +1107,13 @@ static ResultCode SetThreadPriority(Core::System& system, Handle handle, u32 pri | |||
| 1105 | 1107 | ||
| 1106 | thread->SetPriority(priority); | 1108 | thread->SetPriority(priority); |
| 1107 | 1109 | ||
| 1108 | system.PrepareReschedule(thread->GetProcessorID()); | ||
| 1109 | return RESULT_SUCCESS; | 1110 | return RESULT_SUCCESS; |
| 1110 | } | 1111 | } |
| 1111 | 1112 | ||
| 1112 | /// Get which CPU core is executing the current thread | 1113 | /// Get which CPU core is executing the current thread |
| 1113 | static u32 GetCurrentProcessorNumber(Core::System& system) { | 1114 | static u32 GetCurrentProcessorNumber(Core::System& system) { |
| 1114 | LOG_TRACE(Kernel_SVC, "called"); | 1115 | LOG_TRACE(Kernel_SVC, "called"); |
| 1115 | return system.CurrentScheduler().GetCurrentThread()->GetProcessorID(); | 1116 | return static_cast<u32>(system.CurrentPhysicalCore().CoreIndex()); |
| 1116 | } | 1117 | } |
| 1117 | 1118 | ||
| 1118 | static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_handle, VAddr addr, | 1119 | static ResultCode MapSharedMemory(Core::System& system, Handle shared_memory_handle, VAddr addr, |
| @@ -1430,8 +1431,8 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e | |||
| 1430 | 1431 | ||
| 1431 | ThreadType type = THREADTYPE_USER; | 1432 | ThreadType type = THREADTYPE_USER; |
| 1432 | CASCADE_RESULT(std::shared_ptr<Thread> thread, | 1433 | CASCADE_RESULT(std::shared_ptr<Thread> thread, |
| 1433 | Thread::Create(system, type, "", entry_point, priority, arg, processor_id, stack_top, | 1434 | Thread::Create(system, type, "", entry_point, priority, arg, processor_id, |
| 1434 | current_process)); | 1435 | stack_top, current_process)); |
| 1435 | 1436 | ||
| 1436 | const auto new_thread_handle = current_process->GetHandleTable().Create(thread); | 1437 | const auto new_thread_handle = current_process->GetHandleTable().Create(thread); |
| 1437 | if (new_thread_handle.Failed()) { | 1438 | if (new_thread_handle.Failed()) { |
| @@ -1804,6 +1805,8 @@ static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle, | |||
| 1804 | if (!thread) { | 1805 | if (!thread) { |
| 1805 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", | 1806 | LOG_ERROR(Kernel_SVC, "Thread handle does not exist, thread_handle=0x{:08X}", |
| 1806 | thread_handle); | 1807 | thread_handle); |
| 1808 | *core = 0; | ||
| 1809 | *mask = 0; | ||
| 1807 | return ERR_INVALID_HANDLE; | 1810 | return ERR_INVALID_HANDLE; |
| 1808 | } | 1811 | } |
| 1809 | 1812 | ||
| @@ -1866,11 +1869,7 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle, | |||
| 1866 | return ERR_INVALID_HANDLE; | 1869 | return ERR_INVALID_HANDLE; |
| 1867 | } | 1870 | } |
| 1868 | 1871 | ||
| 1869 | system.PrepareReschedule(thread->GetProcessorID()); | 1872 | return thread->SetCoreAndAffinityMask(core, affinity_mask); |
| 1870 | thread->ChangeCore(core, affinity_mask); | ||
| 1871 | system.PrepareReschedule(thread->GetProcessorID()); | ||
| 1872 | |||
| 1873 | return RESULT_SUCCESS; | ||
| 1874 | } | 1873 | } |
| 1875 | 1874 | ||
| 1876 | static ResultCode CreateEvent(Core::System& system, Handle* write_handle, Handle* read_handle) { | 1875 | static ResultCode CreateEvent(Core::System& system, Handle* write_handle, Handle* read_handle) { |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index d9e610272..e6bb7c666 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -250,6 +250,7 @@ ResultVal<std::shared_ptr<Thread>> Thread::Create(Core::System& system, ThreadTy | |||
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | void Thread::SetPriority(u32 priority) { | 252 | void Thread::SetPriority(u32 priority) { |
| 253 | SchedulerLock lock(kernel); | ||
| 253 | ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, | 254 | ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, |
| 254 | "Invalid priority value."); | 255 | "Invalid priority value."); |
| 255 | nominal_priority = priority; | 256 | nominal_priority = priority; |
| @@ -383,10 +384,6 @@ void Thread::UpdatePriority() { | |||
| 383 | lock_owner->UpdatePriority(); | 384 | lock_owner->UpdatePriority(); |
| 384 | } | 385 | } |
| 385 | 386 | ||
| 386 | void Thread::ChangeCore(u32 core, u64 mask) { | ||
| 387 | SetCoreAndAffinityMask(core, mask); | ||
| 388 | } | ||
| 389 | |||
| 390 | bool Thread::AllSynchronizationObjectsReady() const { | 387 | bool Thread::AllSynchronizationObjectsReady() const { |
| 391 | return std::none_of(wait_objects.begin(), wait_objects.end(), | 388 | return std::none_of(wait_objects.begin(), wait_objects.end(), |
| 392 | [this](const std::shared_ptr<SynchronizationObject>& object) { | 389 | [this](const std::shared_ptr<SynchronizationObject>& object) { |
| @@ -467,6 +464,7 @@ void Thread::SetCurrentPriority(u32 new_priority) { | |||
| 467 | } | 464 | } |
| 468 | 465 | ||
| 469 | ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { | 466 | ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { |
| 467 | SchedulerLock lock(kernel); | ||
| 470 | const auto HighestSetCore = [](u64 mask, u32 max_cores) { | 468 | const auto HighestSetCore = [](u64 mask, u32 max_cores) { |
| 471 | for (s32 core = static_cast<s32>(max_cores - 1); core >= 0; core--) { | 469 | for (s32 core = static_cast<s32>(max_cores - 1); core >= 0; core--) { |
| 472 | if (((mask >> core) & 1) != 0) { | 470 | if (((mask >> core) & 1) != 0) { |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 78a4357b0..29fe5483b 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -221,7 +221,7 @@ public: | |||
| 221 | void UpdatePriority(); | 221 | void UpdatePriority(); |
| 222 | 222 | ||
| 223 | /// Changes the core that the thread is running or scheduled to run on. | 223 | /// Changes the core that the thread is running or scheduled to run on. |
| 224 | void ChangeCore(u32 core, u64 mask); | 224 | ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask); |
| 225 | 225 | ||
| 226 | /** | 226 | /** |
| 227 | * Gets the thread's thread ID | 227 | * Gets the thread's thread ID |
| @@ -522,7 +522,6 @@ private: | |||
| 522 | 522 | ||
| 523 | void SetSchedulingStatus(ThreadSchedStatus new_status); | 523 | void SetSchedulingStatus(ThreadSchedStatus new_status); |
| 524 | void SetCurrentPriority(u32 new_priority); | 524 | void SetCurrentPriority(u32 new_priority); |
| 525 | ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask); | ||
| 526 | 525 | ||
| 527 | void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core); | 526 | void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core); |
| 528 | 527 | ||