diff options
| author | 2021-01-30 20:40:49 +1100 | |
|---|---|---|
| committer | 2021-01-30 20:40:49 +1100 | |
| commit | 3be1a565f895d5399a6c1f6d0997dc528537fe86 (patch) | |
| tree | d5c94d86c78bdcf7a73785b9c28b0c1f5fc0c6af /src/core/hle/kernel/svc.cpp | |
| parent | Merge pull request #5779 from bunnei/kthread-rewrite (diff) | |
| download | yuzu-3be1a565f895d5399a6c1f6d0997dc528537fe86.tar.gz yuzu-3be1a565f895d5399a6c1f6d0997dc528537fe86.tar.xz yuzu-3be1a565f895d5399a6c1f6d0997dc528537fe86.zip | |
kernel: Rewrite resource limit to be more accurate
Matches closer to hardware
Diffstat (limited to 'src/core/hle/kernel/svc.cpp')
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 7fd514e9d..4bae37d10 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "core/hle/kernel/handle_table.h" | 26 | #include "core/hle/kernel/handle_table.h" |
| 27 | #include "core/hle/kernel/k_address_arbiter.h" | 27 | #include "core/hle/kernel/k_address_arbiter.h" |
| 28 | #include "core/hle/kernel/k_condition_variable.h" | 28 | #include "core/hle/kernel/k_condition_variable.h" |
| 29 | #include "core/hle/kernel/k_resource_limit.h" | ||
| 29 | #include "core/hle/kernel/k_scheduler.h" | 30 | #include "core/hle/kernel/k_scheduler.h" |
| 30 | #include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h" | 31 | #include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h" |
| 31 | #include "core/hle/kernel/k_synchronization_object.h" | 32 | #include "core/hle/kernel/k_synchronization_object.h" |
| @@ -37,7 +38,6 @@ | |||
| 37 | #include "core/hle/kernel/physical_core.h" | 38 | #include "core/hle/kernel/physical_core.h" |
| 38 | #include "core/hle/kernel/process.h" | 39 | #include "core/hle/kernel/process.h" |
| 39 | #include "core/hle/kernel/readable_event.h" | 40 | #include "core/hle/kernel/readable_event.h" |
| 40 | #include "core/hle/kernel/resource_limit.h" | ||
| 41 | #include "core/hle/kernel/shared_memory.h" | 41 | #include "core/hle/kernel/shared_memory.h" |
| 42 | #include "core/hle/kernel/svc.h" | 42 | #include "core/hle/kernel/svc.h" |
| 43 | #include "core/hle/kernel/svc_results.h" | 43 | #include "core/hle/kernel/svc_results.h" |
| @@ -141,7 +141,7 @@ enum class ResourceLimitValueType { | |||
| 141 | ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_limit, | 141 | ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_limit, |
| 142 | u32 resource_type, ResourceLimitValueType value_type) { | 142 | u32 resource_type, ResourceLimitValueType value_type) { |
| 143 | std::lock_guard lock{HLE::g_hle_lock}; | 143 | std::lock_guard lock{HLE::g_hle_lock}; |
| 144 | const auto type = static_cast<ResourceType>(resource_type); | 144 | const auto type = static_cast<LimitableResource>(resource_type); |
| 145 | if (!IsValidResourceType(type)) { | 145 | if (!IsValidResourceType(type)) { |
| 146 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | 146 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); |
| 147 | return ERR_INVALID_ENUM_VALUE; | 147 | return ERR_INVALID_ENUM_VALUE; |
| @@ -151,7 +151,7 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_ | |||
| 151 | ASSERT(current_process != nullptr); | 151 | ASSERT(current_process != nullptr); |
| 152 | 152 | ||
| 153 | const auto resource_limit_object = | 153 | const auto resource_limit_object = |
| 154 | current_process->GetHandleTable().Get<ResourceLimit>(resource_limit); | 154 | current_process->GetHandleTable().Get<KResourceLimit>(resource_limit); |
| 155 | if (!resource_limit_object) { | 155 | if (!resource_limit_object) { |
| 156 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | 156 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", |
| 157 | resource_limit); | 157 | resource_limit); |
| @@ -159,10 +159,10 @@ ResultVal<s64> RetrieveResourceLimitValue(Core::System& system, Handle resource_ | |||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | if (value_type == ResourceLimitValueType::CurrentValue) { | 161 | if (value_type == ResourceLimitValueType::CurrentValue) { |
| 162 | return MakeResult(resource_limit_object->GetCurrentResourceValue(type)); | 162 | return MakeResult(resource_limit_object->GetCurrentValue(type)); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | return MakeResult(resource_limit_object->GetMaxResourceValue(type)); | 165 | return MakeResult(resource_limit_object->GetLimitValue(type)); |
| 166 | } | 166 | } |
| 167 | } // Anonymous namespace | 167 | } // Anonymous namespace |
| 168 | 168 | ||
| @@ -312,7 +312,8 @@ static ResultCode ConnectToNamedPort(Core::System& system, Handle* out_handle, | |||
| 312 | return ERR_NOT_FOUND; | 312 | return ERR_NOT_FOUND; |
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(ResourceType::Sessions, 1)); | 315 | ASSERT(kernel.CurrentProcess()->GetResourceLimit()->Reserve(LimitableResource::SessionCountMax, |
| 316 | 1)); | ||
| 316 | 317 | ||
| 317 | auto client_port = it->second; | 318 | auto client_port = it->second; |
| 318 | 319 | ||
| @@ -1450,7 +1451,10 @@ static ResultCode CreateThread(Core::System& system, Handle* out_handle, VAddr e | |||
| 1450 | Svc::ResultInvalidPriority); | 1451 | Svc::ResultInvalidPriority); |
| 1451 | R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority); | 1452 | R_UNLESS(process.CheckThreadPriority(priority), Svc::ResultInvalidPriority); |
| 1452 | 1453 | ||
| 1453 | ASSERT(process.GetResourceLimit()->Reserve(ResourceType::Threads, 1)); | 1454 | ASSERT(process.GetResourceLimit()->Reserve( |
| 1455 | LimitableResource::ThreadCountMax, 1, | ||
| 1456 | system.CoreTiming().GetClockTicks() + | ||
| 1457 | Core::Timing::msToCycles(std::chrono::milliseconds{100}))); | ||
| 1454 | 1458 | ||
| 1455 | std::shared_ptr<KThread> thread; | 1459 | std::shared_ptr<KThread> thread; |
| 1456 | { | 1460 | { |
| @@ -1972,7 +1976,7 @@ static ResultCode CreateResourceLimit(Core::System& system, Handle* out_handle) | |||
| 1972 | LOG_DEBUG(Kernel_SVC, "called"); | 1976 | LOG_DEBUG(Kernel_SVC, "called"); |
| 1973 | 1977 | ||
| 1974 | auto& kernel = system.Kernel(); | 1978 | auto& kernel = system.Kernel(); |
| 1975 | auto resource_limit = ResourceLimit::Create(kernel); | 1979 | auto resource_limit = std::make_shared<KResourceLimit>(kernel, system); |
| 1976 | 1980 | ||
| 1977 | auto* const current_process = kernel.CurrentProcess(); | 1981 | auto* const current_process = kernel.CurrentProcess(); |
| 1978 | ASSERT(current_process != nullptr); | 1982 | ASSERT(current_process != nullptr); |
| @@ -2019,7 +2023,7 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2019 | LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}, Value={}", resource_limit, | 2023 | LOG_DEBUG(Kernel_SVC, "called. Handle={:08X}, Resource type={}, Value={}", resource_limit, |
| 2020 | resource_type, value); | 2024 | resource_type, value); |
| 2021 | 2025 | ||
| 2022 | const auto type = static_cast<ResourceType>(resource_type); | 2026 | const auto type = static_cast<LimitableResource>(resource_type); |
| 2023 | if (!IsValidResourceType(type)) { | 2027 | if (!IsValidResourceType(type)) { |
| 2024 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); | 2028 | LOG_ERROR(Kernel_SVC, "Invalid resource limit type: '{}'", resource_type); |
| 2025 | return ERR_INVALID_ENUM_VALUE; | 2029 | return ERR_INVALID_ENUM_VALUE; |
| @@ -2029,7 +2033,7 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2029 | ASSERT(current_process != nullptr); | 2033 | ASSERT(current_process != nullptr); |
| 2030 | 2034 | ||
| 2031 | auto resource_limit_object = | 2035 | auto resource_limit_object = |
| 2032 | current_process->GetHandleTable().Get<ResourceLimit>(resource_limit); | 2036 | current_process->GetHandleTable().Get<KResourceLimit>(resource_limit); |
| 2033 | if (!resource_limit_object) { | 2037 | if (!resource_limit_object) { |
| 2034 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", | 2038 | LOG_ERROR(Kernel_SVC, "Handle to non-existent resource limit instance used. Handle={:08X}", |
| 2035 | resource_limit); | 2039 | resource_limit); |
| @@ -2041,8 +2045,8 @@ static ResultCode SetResourceLimitLimitValue(Core::System& system, Handle resour | |||
| 2041 | LOG_ERROR( | 2045 | LOG_ERROR( |
| 2042 | Kernel_SVC, | 2046 | Kernel_SVC, |
| 2043 | "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", | 2047 | "Attempted to lower resource limit ({}) for category '{}' below its current value ({})", |
| 2044 | resource_limit_object->GetMaxResourceValue(type), resource_type, | 2048 | resource_limit_object->GetLimitValue(type), resource_type, |
| 2045 | resource_limit_object->GetCurrentResourceValue(type)); | 2049 | resource_limit_object->GetCurrentValue(type)); |
| 2046 | return set_result; | 2050 | return set_result; |
| 2047 | } | 2051 | } |
| 2048 | 2052 | ||