From ee3377b67da3640940d0936f7ebd8472fc1fe31b Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 23 Mar 2015 00:50:38 -0400 Subject: SVC: Reschedule on svcCreateThread. --- src/core/hle/svc.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index bbb4eb9cd..e89e97238 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -336,6 +336,8 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling"); } + HLE::Reschedule(__func__); + return RESULT_SUCCESS; } -- cgit v1.2.3 From 7b9f428b23e1761e7b6c177d2e8eb9219ac6b7f6 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 23 Mar 2015 23:55:21 -0400 Subject: Thread: Implement priority boost for starved threads. SVC: Return correct error code on invalid CreateThread processor ID. SVC: Assert when creating a thread with an invalid userland priority. --- src/core/hle/svc.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index e89e97238..82e187466 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -312,7 +312,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim } /// Creates a new thread -static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { +static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { using Kernel::Thread; std::string name; @@ -323,6 +323,21 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u name = Common::StringFromFormat("unknown-%08x", entry_point); } + // TODO(bunnei): Implement resource limits to return an error code instead of the below assert. + // The error code should be: Description::NotAuthorized, Module::OS, Summary::WrongArgument, + // Level::Permanent + ASSERT_MSG(priority >= THREADPRIO_USERLAND_MAX, "Unexpected thread priority!"); + + if (priority > THREADPRIO_LOWEST) { + return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); + } + + if (processor_id > THREADPROCESSORID_MAX) { + return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Kernel, + ErrorSummary::InvalidArgument, ErrorLevel::Permanent); + } + CASCADE_RESULT(SharedPtr thread, Kernel::Thread::Create( name, entry_point, priority, arg, processor_id, stack_top)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); @@ -331,11 +346,6 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, name.c_str(), arg, stack_top, priority, processor_id, *out_handle); - if (THREADPROCESSORID_1 == processor_id) { - LOG_WARNING(Kernel_SVC, - "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling"); - } - HLE::Reschedule(__func__); return RESULT_SUCCESS; -- cgit v1.2.3 From c077bcefa9e72078ab9df798f41376c0b91abd15 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 6 Apr 2015 21:58:05 -0400 Subject: SVC: Update various SVCs to cause a reschedule. - CreateMutex/ReleaseMutex/ReleaseSemaphore/SetTimer/CancelTimer/ArbitrateAddress --- src/core/hle/svc.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 82e187466..43b7e5cbf 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 if (arbiter == nullptr) return ERR_INVALID_HANDLE; - return arbiter->ArbitrateAddress(static_cast(type), - address, value, nanoseconds); + auto res = arbiter->ArbitrateAddress(static_cast(type), + address, value, nanoseconds); + + if (res == RESULT_SUCCESS) + HLE::Reschedule(__func__); + + return res; } /// Used to output a message on a debug hardware unit - does nothing on a retail unit @@ -386,8 +391,11 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { SharedPtr mutex = Mutex::Create(initial_locked != 0); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); + HLE::Reschedule(__func__); + LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", initial_locked ? "true" : "false", *out_handle); + return RESULT_SUCCESS; } @@ -402,6 +410,9 @@ static ResultCode ReleaseMutex(Handle handle) { return ERR_INVALID_HANDLE; mutex->Release(); + + HLE::Reschedule(__func__); + return RESULT_SUCCESS; } @@ -440,6 +451,9 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) return ERR_INVALID_HANDLE; CASCADE_RESULT(*count, semaphore->Release(release_count)); + + HLE::Reschedule(__func__); + return RESULT_SUCCESS; } @@ -532,6 +546,9 @@ static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { return ERR_INVALID_HANDLE; timer->Set(initial, interval); + + HLE::Reschedule(__func__); + return RESULT_SUCCESS; } @@ -546,6 +563,9 @@ static ResultCode CancelTimer(Handle handle) { return ERR_INVALID_HANDLE; timer->Cancel(); + + HLE::Reschedule(__func__); + return RESULT_SUCCESS; } -- cgit v1.2.3 From db4bd98bac52283ed9bb17456d58ae4e3bc82ec9 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 9 Apr 2015 22:55:18 -0400 Subject: SVC: Assert on unsupported CreateThread processor ID. --- src/core/hle/svc.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 43b7e5cbf..76e9b171a 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -338,9 +338,15 @@ static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point ErrorSummary::InvalidArgument, ErrorLevel::Usage); } - if (processor_id > THREADPROCESSORID_MAX) { - return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Kernel, - ErrorSummary::InvalidArgument, ErrorLevel::Permanent); + switch (processor_id) { + case THREADPROCESSORID_DEFAULT: + case THREADPROCESSORID_0: + case THREADPROCESSORID_1: + break; + default: + // TODO(bunnei): Implement support for other processor IDs + ASSERT_MSG(false, "Unsupported thread processor ID: %d", processor_id); + break; } CASCADE_RESULT(SharedPtr thread, Kernel::Thread::Create( -- cgit v1.2.3