summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2021-01-03 01:49:18 -0800
committerGravatar bunnei2021-01-28 21:42:25 -0800
commit4dbf3f4880cac69db21cc8f18582814dc986c854 (patch)
tree16bd5c45c3341e3341d3581e830dbc9f5067784d /src/core/hle/kernel/svc.cpp
parenthle: kernel: KThread: Reorganize thread priority defaults. (diff)
downloadyuzu-4dbf3f4880cac69db21cc8f18582814dc986c854.tar.gz
yuzu-4dbf3f4880cac69db21cc8f18582814dc986c854.tar.xz
yuzu-4dbf3f4880cac69db21cc8f18582814dc986c854.zip
hle: kernel: KThread: Clean up thread priorities.
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
-rw-r--r--src/core/hle/kernel/svc.cpp66
1 files changed, 26 insertions, 40 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 70a8ef34b..2512bfd98 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1443,54 +1443,40 @@ static void ExitProcess32(Core::System& system) {
1443 ExitProcess(system); 1443 ExitProcess(system);
1444} 1444}
1445 1445
1446static constexpr bool IsValidCoreId(int32_t core_id) {
1447 return (0 <= core_id && core_id < static_cast<int32_t>(Core::Hardware::NUM_CPU_CORES));
1448}
1449
1446/// Creates a new thread 1450/// Creates a new thread
1447static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, u64 arg, 1451static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point, u64 arg,
1448 VAddr stack_top, u32 priority, s32 processor_id) { 1452 VAddr stack_bottom, u32 priority, s32 core_id) {
1449 LOG_DEBUG(Kernel_SVC, 1453 LOG_DEBUG(Kernel_SVC,
1450 "called entrypoint=0x{:08X}, arg=0x{:08X}, stacktop=0x{:08X}, " 1454 "called entry_point=0x{:08X}, arg=0x{:08X}, stack_bottom=0x{:08X}, "
1451 "threadpriority=0x{:08X}, processorid=0x{:08X} : created handle=0x{:08X}", 1455 "priority=0x{:08X}, core_id=0x{:08X}",
1452 entry_point, arg, stack_top, priority, processor_id, *out_handle); 1456 entry_point, arg, stack_bottom, priority, core_id);
1453 1457
1454 auto* const current_process = system.Kernel().CurrentProcess(); 1458 // Adjust core id, if it's the default magic.
1455 1459 auto& kernel = system.Kernel();
1456 if (processor_id == THREADPROCESSORID_IDEAL) { 1460 auto& process = *kernel.CurrentProcess();
1457 // Set the target CPU to the one specified by the process. 1461 if (core_id == Svc::IdealCoreUseProcessValue) {
1458 processor_id = current_process->GetIdealCore(); 1462 core_id = process.GetIdealCoreId();
1459 ASSERT(processor_id != THREADPROCESSORID_IDEAL);
1460 }
1461
1462 if (processor_id < THREADPROCESSORID_0 || processor_id > THREADPROCESSORID_3) {
1463 LOG_ERROR(Kernel_SVC, "Invalid thread processor ID: {}", processor_id);
1464 return ERR_INVALID_PROCESSOR_ID;
1465 }
1466
1467 const u64 core_mask = current_process->GetCoreMask();
1468 if ((core_mask | (1ULL << processor_id)) != core_mask) {
1469 LOG_ERROR(Kernel_SVC, "Invalid thread core specified ({})", processor_id);
1470 return ERR_INVALID_PROCESSOR_ID;
1471 }
1472
1473 if (priority > Svc::LowestThreadPriority) {
1474 LOG_ERROR(Kernel_SVC,
1475 "Invalid thread priority specified ({}). Must be within the range 0-64",
1476 priority);
1477 return ERR_INVALID_THREAD_PRIORITY;
1478 } 1463 }
1479 1464
1480 if (((1ULL << priority) & current_process->GetPriorityMask()) == 0) { 1465 // Validate arguments.
1481 LOG_ERROR(Kernel_SVC, "Invalid thread priority specified ({})", priority); 1466 R_UNLESS(IsValidCoreId(core_id), Svc::ResultInvalidCoreId);
1482 return ERR_INVALID_THREAD_PRIORITY; 1467 R_UNLESS(((1ULL << core_id) & process.GetCoreMask()) != 0, Svc::ResultInvalidCoreId);
1483 }
1484 1468
1485 auto& kernel = system.Kernel(); 1469 R_UNLESS(Svc::HighestThreadPriority <= priority && priority <= Svc::LowestThreadPriority,
1470 Svc::ResultInvalidPriority);
1471 R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority);
1486 1472
1487 ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(ResourceType::Threads, 1)); 1473 ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(ResourceType::Threads, 1));
1488 1474
1489 CASCADE_RESULT(std::shared_ptr<KThread> thread, 1475 CASCADE_RESULT(std::shared_ptr<KThread> thread,
1490 KThread::Create(system, ThreadType::User, "", entry_point, priority, arg, 1476 KThread::Create(system, ThreadType::User, "", entry_point, priority, arg,
1491 processor_id, stack_top, current_process)); 1477 core_id, stack_bottom, &process));
1492 1478
1493 const auto new_thread_handle = current_process->GetHandleTable().Create(thread); 1479 const auto new_thread_handle = process.GetHandleTable().Create(thread);
1494 if (new_thread_handle.Failed()) { 1480 if (new_thread_handle.Failed()) {
1495 LOG_ERROR(Kernel_SVC, "Failed to create handle with error=0x{:X}", 1481 LOG_ERROR(Kernel_SVC, "Failed to create handle with error=0x{:X}",
1496 new_thread_handle.Code().raw); 1482 new_thread_handle.Code().raw);
@@ -1872,10 +1858,10 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
1872 1858
1873 const auto* const current_process = system.Kernel().CurrentProcess(); 1859 const auto* const current_process = system.Kernel().CurrentProcess();
1874 1860
1875 if (core == static_cast<u32>(THREADPROCESSORID_IDEAL)) { 1861 if (core == static_cast<u32>(Svc::IdealCoreUseProcessValue)) {
1876 const u8 ideal_cpu_core = current_process->GetIdealCore(); 1862 const u8 ideal_cpu_core = current_process->GetIdealCoreId();
1877 1863
1878 ASSERT(ideal_cpu_core != static_cast<u8>(THREADPROCESSORID_IDEAL)); 1864 ASSERT(ideal_cpu_core != static_cast<u8>(Svc::IdealCoreUseProcessValue));
1879 1865
1880 // Set the target CPU to the ideal core specified by the process. 1866 // Set the target CPU to the ideal core specified by the process.
1881 core = ideal_cpu_core; 1867 core = ideal_cpu_core;
@@ -1903,8 +1889,8 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
1903 affinity_mask); 1889 affinity_mask);
1904 return ERR_INVALID_COMBINATION; 1890 return ERR_INVALID_COMBINATION;
1905 } 1891 }
1906 } else if (core != static_cast<u32>(THREADPROCESSORID_DONT_CARE) && 1892 } else if (core != static_cast<u32>(Svc::IdealCoreDontCare) &&
1907 core != static_cast<u32>(THREADPROCESSORID_DONT_UPDATE)) { 1893 core != static_cast<u32>(Svc::IdealCoreNoUpdate)) {
1908 LOG_ERROR(Kernel_SVC, "Invalid processor ID specified (core={}).", core); 1894 LOG_ERROR(Kernel_SVC, "Invalid processor ID specified (core={}).", core);
1909 return ERR_INVALID_PROCESSOR_ID; 1895 return ERR_INVALID_PROCESSOR_ID;
1910 } 1896 }