diff options
| author | 2020-02-24 22:04:12 -0400 | |
|---|---|---|
| committer | 2020-06-27 11:35:06 -0400 | |
| commit | e31425df3877636c098ec7426ebd2067920715cb (patch) | |
| tree | 5c0fc518a4ebb8413c491b43a9fdd99450c7bd80 /src/core/hle/kernel/thread.h | |
| parent | Merge pull request #3396 from FernandoS27/prometheus-1 (diff) | |
| download | yuzu-e31425df3877636c098ec7426ebd2067920715cb.tar.gz yuzu-e31425df3877636c098ec7426ebd2067920715cb.tar.xz yuzu-e31425df3877636c098ec7426ebd2067920715cb.zip | |
General: Recover Prometheus project from harddrive failure
This commit: Implements CPU Interrupts, Replaces Cycle Timing for Host
Timing, Reworks the Kernel's Scheduler, Introduce Idle State and
Suspended State, Recreates the bootmanager, Initializes Multicore
system.
Diffstat (limited to 'src/core/hle/kernel/thread.h')
| -rw-r--r-- | src/core/hle/kernel/thread.h | 81 |
1 files changed, 67 insertions, 14 deletions
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 23fdef8a4..33d340b47 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -9,23 +9,42 @@ | |||
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | 10 | ||
| 11 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 12 | #include "common/spin_lock.h" | ||
| 12 | #include "core/arm/arm_interface.h" | 13 | #include "core/arm/arm_interface.h" |
| 13 | #include "core/hle/kernel/object.h" | 14 | #include "core/hle/kernel/object.h" |
| 14 | #include "core/hle/kernel/synchronization_object.h" | 15 | #include "core/hle/kernel/synchronization_object.h" |
| 15 | #include "core/hle/result.h" | 16 | #include "core/hle/result.h" |
| 16 | 17 | ||
| 18 | namespace Common { | ||
| 19 | class Fiber; | ||
| 20 | } | ||
| 21 | |||
| 22 | namespace Core { | ||
| 23 | class System; | ||
| 24 | } | ||
| 25 | |||
| 17 | namespace Kernel { | 26 | namespace Kernel { |
| 18 | 27 | ||
| 28 | class GlobalScheduler; | ||
| 19 | class KernelCore; | 29 | class KernelCore; |
| 20 | class Process; | 30 | class Process; |
| 21 | class Scheduler; | 31 | class Scheduler; |
| 22 | 32 | ||
| 23 | enum ThreadPriority : u32 { | 33 | enum ThreadPriority : u32 { |
| 24 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority | 34 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority |
| 25 | THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps | 35 | THREADPRIO_MAX_CORE_MIGRATION = 2, ///< Highest priority for a core migration |
| 26 | THREADPRIO_DEFAULT = 44, ///< Default thread priority for userland apps | 36 | THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps |
| 27 | THREADPRIO_LOWEST = 63, ///< Lowest thread priority | 37 | THREADPRIO_DEFAULT = 44, ///< Default thread priority for userland apps |
| 28 | THREADPRIO_COUNT = 64, ///< Total number of possible thread priorities. | 38 | THREADPRIO_LOWEST = 63, ///< Lowest thread priority |
| 39 | THREADPRIO_COUNT = 64, ///< Total number of possible thread priorities. | ||
| 40 | }; | ||
| 41 | |||
| 42 | enum ThreadType : u32 { | ||
| 43 | THREADTYPE_USER = 0x1, | ||
| 44 | THREADTYPE_KERNEL = 0x2, | ||
| 45 | THREADTYPE_HLE = 0x4, | ||
| 46 | THREADTYPE_IDLE = 0x8, | ||
| 47 | THREADTYPE_SUSPEND = 0x10, | ||
| 29 | }; | 48 | }; |
| 30 | 49 | ||
| 31 | enum ThreadProcessorId : s32 { | 50 | enum ThreadProcessorId : s32 { |
| @@ -111,22 +130,43 @@ public: | |||
| 111 | std::function<bool(ThreadWakeupReason reason, std::shared_ptr<Thread> thread, | 130 | std::function<bool(ThreadWakeupReason reason, std::shared_ptr<Thread> thread, |
| 112 | std::shared_ptr<SynchronizationObject> object, std::size_t index)>; | 131 | std::shared_ptr<SynchronizationObject> object, std::size_t index)>; |
| 113 | 132 | ||
| 133 | /** | ||
| 134 | * Creates and returns a new thread. The new thread is immediately scheduled | ||
| 135 | * @param system The instance of the whole system | ||
| 136 | * @param name The friendly name desired for the thread | ||
| 137 | * @param entry_point The address at which the thread should start execution | ||
| 138 | * @param priority The thread's priority | ||
| 139 | * @param arg User data to pass to the thread | ||
| 140 | * @param processor_id The ID(s) of the processors on which the thread is desired to be run | ||
| 141 | * @param stack_top The address of the thread's stack top | ||
| 142 | * @param owner_process The parent process for the thread, if null, it's a kernel thread | ||
| 143 | * @return A shared pointer to the newly created thread | ||
| 144 | */ | ||
| 145 | static ResultVal<std::shared_ptr<Thread>> Create(Core::System& system, ThreadType type_flags, std::string name, | ||
| 146 | VAddr entry_point, u32 priority, u64 arg, | ||
| 147 | s32 processor_id, VAddr stack_top, | ||
| 148 | Process* owner_process); | ||
| 149 | |||
| 114 | /** | 150 | /** |
| 115 | * Creates and returns a new thread. The new thread is immediately scheduled | 151 | * Creates and returns a new thread. The new thread is immediately scheduled |
| 116 | * @param kernel The kernel instance this thread will be created under. | 152 | * @param system The instance of the whole system |
| 117 | * @param name The friendly name desired for the thread | 153 | * @param name The friendly name desired for the thread |
| 118 | * @param entry_point The address at which the thread should start execution | 154 | * @param entry_point The address at which the thread should start execution |
| 119 | * @param priority The thread's priority | 155 | * @param priority The thread's priority |
| 120 | * @param arg User data to pass to the thread | 156 | * @param arg User data to pass to the thread |
| 121 | * @param processor_id The ID(s) of the processors on which the thread is desired to be run | 157 | * @param processor_id The ID(s) of the processors on which the thread is desired to be run |
| 122 | * @param stack_top The address of the thread's stack top | 158 | * @param stack_top The address of the thread's stack top |
| 123 | * @param owner_process The parent process for the thread | 159 | * @param owner_process The parent process for the thread, if null, it's a kernel thread |
| 160 | * @param thread_start_func The function where the host context will start. | ||
| 161 | * @param thread_start_parameter The parameter which will passed to host context on init | ||
| 124 | * @return A shared pointer to the newly created thread | 162 | * @return A shared pointer to the newly created thread |
| 125 | */ | 163 | */ |
| 126 | static ResultVal<std::shared_ptr<Thread>> Create(KernelCore& kernel, std::string name, | 164 | static ResultVal<std::shared_ptr<Thread>> Create(Core::System& system, ThreadType type_flags, std::string name, |
| 127 | VAddr entry_point, u32 priority, u64 arg, | 165 | VAddr entry_point, u32 priority, u64 arg, |
| 128 | s32 processor_id, VAddr stack_top, | 166 | s32 processor_id, VAddr stack_top, |
| 129 | Process& owner_process); | 167 | Process* owner_process, |
| 168 | std::function<void(void*)>&& thread_start_func, | ||
| 169 | void* thread_start_parameter); | ||
| 130 | 170 | ||
| 131 | std::string GetName() const override { | 171 | std::string GetName() const override { |
| 132 | return name; | 172 | return name; |
| @@ -192,7 +232,9 @@ public: | |||
| 192 | } | 232 | } |
| 193 | 233 | ||
| 194 | /// Resumes a thread from waiting | 234 | /// Resumes a thread from waiting |
| 195 | void ResumeFromWait(); | 235 | void /* deprecated */ ResumeFromWait(); |
| 236 | |||
| 237 | void OnWakeUp(); | ||
| 196 | 238 | ||
| 197 | /// Cancels a waiting operation that this thread may or may not be within. | 239 | /// Cancels a waiting operation that this thread may or may not be within. |
| 198 | /// | 240 | /// |
| @@ -206,10 +248,10 @@ public: | |||
| 206 | * Schedules an event to wake up the specified thread after the specified delay | 248 | * Schedules an event to wake up the specified thread after the specified delay |
| 207 | * @param nanoseconds The time this thread will be allowed to sleep for | 249 | * @param nanoseconds The time this thread will be allowed to sleep for |
| 208 | */ | 250 | */ |
| 209 | void WakeAfterDelay(s64 nanoseconds); | 251 | void /* deprecated */ WakeAfterDelay(s64 nanoseconds); |
| 210 | 252 | ||
| 211 | /// Cancel any outstanding wakeup events for this thread | 253 | /// Cancel any outstanding wakeup events for this thread |
| 212 | void CancelWakeupTimer(); | 254 | void /* deprecated */ CancelWakeupTimer(); |
| 213 | 255 | ||
| 214 | /** | 256 | /** |
| 215 | * Sets the result after the thread awakens (from svcWaitSynchronization) | 257 | * Sets the result after the thread awakens (from svcWaitSynchronization) |
| @@ -290,6 +332,12 @@ public: | |||
| 290 | return context_64; | 332 | return context_64; |
| 291 | } | 333 | } |
| 292 | 334 | ||
| 335 | bool IsHLEThread() const { | ||
| 336 | return (type & THREADTYPE_HLE) != 0; | ||
| 337 | } | ||
| 338 | |||
| 339 | std::shared_ptr<Common::Fiber> GetHostContext() const; | ||
| 340 | |||
| 293 | ThreadStatus GetStatus() const { | 341 | ThreadStatus GetStatus() const { |
| 294 | return status; | 342 | return status; |
| 295 | } | 343 | } |
| @@ -467,16 +515,19 @@ public: | |||
| 467 | } | 515 | } |
| 468 | 516 | ||
| 469 | private: | 517 | private: |
| 518 | friend class GlobalScheduler; | ||
| 519 | friend class Scheduler; | ||
| 520 | |||
| 470 | void SetSchedulingStatus(ThreadSchedStatus new_status); | 521 | void SetSchedulingStatus(ThreadSchedStatus new_status); |
| 471 | void SetCurrentPriority(u32 new_priority); | 522 | void SetCurrentPriority(u32 new_priority); |
| 472 | ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask); | 523 | ResultCode SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask); |
| 473 | 524 | ||
| 474 | void AdjustSchedulingOnStatus(u32 old_flags); | ||
| 475 | void AdjustSchedulingOnPriority(u32 old_priority); | ||
| 476 | void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core); | 525 | void AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core); |
| 477 | 526 | ||
| 478 | ThreadContext32 context_32{}; | 527 | ThreadContext32 context_32{}; |
| 479 | ThreadContext64 context_64{}; | 528 | ThreadContext64 context_64{}; |
| 529 | Common::SpinLock context_guard{}; | ||
| 530 | std::shared_ptr<Common::Fiber> host_context{}; | ||
| 480 | 531 | ||
| 481 | u64 thread_id = 0; | 532 | u64 thread_id = 0; |
| 482 | 533 | ||
| @@ -485,6 +536,8 @@ private: | |||
| 485 | VAddr entry_point = 0; | 536 | VAddr entry_point = 0; |
| 486 | VAddr stack_top = 0; | 537 | VAddr stack_top = 0; |
| 487 | 538 | ||
| 539 | ThreadType type; | ||
| 540 | |||
| 488 | /// Nominal thread priority, as set by the emulated application. | 541 | /// Nominal thread priority, as set by the emulated application. |
| 489 | /// The nominal priority is the thread priority without priority | 542 | /// The nominal priority is the thread priority without priority |
| 490 | /// inheritance taken into account. | 543 | /// inheritance taken into account. |