summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2020-01-30 18:13:59 -0500
committerGravatar GitHub2020-01-30 18:13:59 -0500
commit985d0f35e55f0752c6e147d0140b367708499cb4 (patch)
tree119249aee3acc2cc2ee6a5d391288b52c126765b /src/core/hle/kernel
parentMerge pull request #3151 from FearlessTobi/fix-korean (diff)
parentSystem: Address Feedback (diff)
downloadyuzu-985d0f35e55f0752c6e147d0140b367708499cb4.tar.gz
yuzu-985d0f35e55f0752c6e147d0140b367708499cb4.tar.xz
yuzu-985d0f35e55f0752c6e147d0140b367708499cb4.zip
Merge pull request #3353 from FernandoS27/aries
System: Refactor CPU Core management and move ARMInterface and Schedulers to Kernel
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp1
-rw-r--r--src/core/hle/kernel/kernel.cpp52
-rw-r--r--src/core/hle/kernel/kernel.h19
-rw-r--r--src/core/hle/kernel/physical_core.cpp52
-rw-r--r--src/core/hle/kernel/physical_core.h74
-rw-r--r--src/core/hle/kernel/scheduler.cpp1
-rw-r--r--src/core/hle/kernel/svc.cpp2
-rw-r--r--src/core/hle/kernel/thread.cpp3
-rw-r--r--src/core/hle/kernel/wait_object.cpp3
9 files changed, 198 insertions, 9 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index db189c8e3..2ea3dcb61 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -8,7 +8,6 @@
8#include "common/assert.h" 8#include "common/assert.h"
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/core.h" 10#include "core/core.h"
11#include "core/core_cpu.h"
12#include "core/hle/kernel/address_arbiter.h" 11#include "core/hle/kernel/address_arbiter.h"
13#include "core/hle/kernel/errors.h" 12#include "core/hle/kernel/errors.h"
14#include "core/hle/kernel/scheduler.h" 13#include "core/hle/kernel/scheduler.h"
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 1d0783bd3..0cf3c8f70 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -3,13 +3,15 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <atomic> 5#include <atomic>
6#include <functional>
6#include <memory> 7#include <memory>
7#include <mutex> 8#include <mutex>
8#include <utility> 9#include <utility>
9 10
10#include "common/assert.h" 11#include "common/assert.h"
11#include "common/logging/log.h" 12#include "common/logging/log.h"
12 13#include "core/arm/arm_interface.h"
14#include "core/arm/exclusive_monitor.h"
13#include "core/core.h" 15#include "core/core.h"
14#include "core/core_timing.h" 16#include "core/core_timing.h"
15#include "core/core_timing_util.h" 17#include "core/core_timing_util.h"
@@ -17,6 +19,7 @@
17#include "core/hle/kernel/errors.h" 19#include "core/hle/kernel/errors.h"
18#include "core/hle/kernel/handle_table.h" 20#include "core/hle/kernel/handle_table.h"
19#include "core/hle/kernel/kernel.h" 21#include "core/hle/kernel/kernel.h"
22#include "core/hle/kernel/physical_core.h"
20#include "core/hle/kernel/process.h" 23#include "core/hle/kernel/process.h"
21#include "core/hle/kernel/resource_limit.h" 24#include "core/hle/kernel/resource_limit.h"
22#include "core/hle/kernel/scheduler.h" 25#include "core/hle/kernel/scheduler.h"
@@ -98,6 +101,7 @@ struct KernelCore::Impl {
98 void Initialize(KernelCore& kernel) { 101 void Initialize(KernelCore& kernel) {
99 Shutdown(); 102 Shutdown();
100 103
104 InitializePhysicalCores(kernel);
101 InitializeSystemResourceLimit(kernel); 105 InitializeSystemResourceLimit(kernel);
102 InitializeThreads(); 106 InitializeThreads();
103 InitializePreemption(); 107 InitializePreemption();
@@ -121,6 +125,21 @@ struct KernelCore::Impl {
121 global_scheduler.Shutdown(); 125 global_scheduler.Shutdown();
122 126
123 named_ports.clear(); 127 named_ports.clear();
128
129 for (auto& core : cores) {
130 core.Shutdown();
131 }
132 cores.clear();
133
134 exclusive_monitor.reset(nullptr);
135 }
136
137 void InitializePhysicalCores(KernelCore& kernel) {
138 exclusive_monitor =
139 Core::MakeExclusiveMonitor(system.Memory(), global_scheduler.CpuCoresCount());
140 for (std::size_t i = 0; i < global_scheduler.CpuCoresCount(); i++) {
141 cores.emplace_back(system, kernel, i, *exclusive_monitor);
142 }
124 } 143 }
125 144
126 // Creates the default system resource limit 145 // Creates the default system resource limit
@@ -186,6 +205,9 @@ struct KernelCore::Impl {
186 /// the ConnectToPort SVC. 205 /// the ConnectToPort SVC.
187 NamedPortTable named_ports; 206 NamedPortTable named_ports;
188 207
208 std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor;
209 std::vector<Kernel::PhysicalCore> cores;
210
189 // System context 211 // System context
190 Core::System& system; 212 Core::System& system;
191}; 213};
@@ -240,6 +262,34 @@ const Kernel::GlobalScheduler& KernelCore::GlobalScheduler() const {
240 return impl->global_scheduler; 262 return impl->global_scheduler;
241} 263}
242 264
265Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) {
266 return impl->cores[id];
267}
268
269const Kernel::PhysicalCore& KernelCore::PhysicalCore(std::size_t id) const {
270 return impl->cores[id];
271}
272
273Core::ExclusiveMonitor& KernelCore::GetExclusiveMonitor() {
274 return *impl->exclusive_monitor;
275}
276
277const Core::ExclusiveMonitor& KernelCore::GetExclusiveMonitor() const {
278 return *impl->exclusive_monitor;
279}
280
281void KernelCore::InvalidateAllInstructionCaches() {
282 for (std::size_t i = 0; i < impl->global_scheduler.CpuCoresCount(); i++) {
283 PhysicalCore(i).ArmInterface().ClearInstructionCache();
284 }
285}
286
287void KernelCore::PrepareReschedule(std::size_t id) {
288 if (id < impl->global_scheduler.CpuCoresCount()) {
289 impl->cores[id].Stop();
290 }
291}
292
243void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) { 293void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) {
244 impl->named_ports.emplace(std::move(name), std::move(port)); 294 impl->named_ports.emplace(std::move(name), std::move(port));
245} 295}
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 3bf0068ed..fccffaf3a 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -11,8 +11,9 @@
11#include "core/hle/kernel/object.h" 11#include "core/hle/kernel/object.h"
12 12
13namespace Core { 13namespace Core {
14class ExclusiveMonitor;
14class System; 15class System;
15} 16} // namespace Core
16 17
17namespace Core::Timing { 18namespace Core::Timing {
18class CoreTiming; 19class CoreTiming;
@@ -25,6 +26,7 @@ class AddressArbiter;
25class ClientPort; 26class ClientPort;
26class GlobalScheduler; 27class GlobalScheduler;
27class HandleTable; 28class HandleTable;
29class PhysicalCore;
28class Process; 30class Process;
29class ResourceLimit; 31class ResourceLimit;
30class Thread; 32class Thread;
@@ -84,6 +86,21 @@ public:
84 /// Gets the sole instance of the global scheduler 86 /// Gets the sole instance of the global scheduler
85 const Kernel::GlobalScheduler& GlobalScheduler() const; 87 const Kernel::GlobalScheduler& GlobalScheduler() const;
86 88
89 /// Gets the an instance of the respective physical CPU core.
90 Kernel::PhysicalCore& PhysicalCore(std::size_t id);
91
92 /// Gets the an instance of the respective physical CPU core.
93 const Kernel::PhysicalCore& PhysicalCore(std::size_t id) const;
94
95 /// Stops execution of 'id' core, in order to reschedule a new thread.
96 void PrepareReschedule(std::size_t id);
97
98 Core::ExclusiveMonitor& GetExclusiveMonitor();
99
100 const Core::ExclusiveMonitor& GetExclusiveMonitor() const;
101
102 void InvalidateAllInstructionCaches();
103
87 /// Adds a port to the named port table 104 /// Adds a port to the named port table
88 void AddNamedPort(std::string name, std::shared_ptr<ClientPort> port); 105 void AddNamedPort(std::string name, std::shared_ptr<ClientPort> port);
89 106
diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp
new file mode 100644
index 000000000..896a1a87a
--- /dev/null
+++ b/src/core/hle/kernel/physical_core.cpp
@@ -0,0 +1,52 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "common/logging/log.h"
6#include "core/arm/arm_interface.h"
7#ifdef ARCHITECTURE_x86_64
8#include "core/arm/dynarmic/arm_dynarmic.h"
9#endif
10#include "core/arm/exclusive_monitor.h"
11#include "core/arm/unicorn/arm_unicorn.h"
12#include "core/core.h"
13#include "core/hle/kernel/kernel.h"
14#include "core/hle/kernel/physical_core.h"
15#include "core/hle/kernel/scheduler.h"
16#include "core/hle/kernel/thread.h"
17
18namespace Kernel {
19
20PhysicalCore::PhysicalCore(Core::System& system, KernelCore& kernel, std::size_t id,
21 Core::ExclusiveMonitor& exclusive_monitor)
22 : core_index{id}, kernel{kernel} {
23#ifdef ARCHITECTURE_x86_64
24 arm_interface = std::make_shared<Core::ARM_Dynarmic>(system, exclusive_monitor, core_index);
25#else
26 arm_interface = std::make_shared<Core::ARM_Unicorn>(system);
27 LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
28#endif
29
30 scheduler = std::make_shared<Kernel::Scheduler>(system, *arm_interface, core_index);
31}
32
33PhysicalCore::~PhysicalCore() = default;
34
35void PhysicalCore::Run() {
36 arm_interface->Run();
37 arm_interface->ClearExclusiveState();
38}
39
40void PhysicalCore::Step() {
41 arm_interface->Step();
42}
43
44void PhysicalCore::Stop() {
45 arm_interface->PrepareReschedule();
46}
47
48void PhysicalCore::Shutdown() {
49 scheduler->Shutdown();
50}
51
52} // namespace Kernel
diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.h
new file mode 100644
index 000000000..fbef0801f
--- /dev/null
+++ b/src/core/hle/kernel/physical_core.h
@@ -0,0 +1,74 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <cstddef>
8#include <memory>
9
10namespace Kernel {
11class Scheduler;
12} // namespace Kernel
13
14namespace Core {
15class ARM_Interface;
16class ExclusiveMonitor;
17class System;
18} // namespace Core
19
20namespace Kernel {
21
22class PhysicalCore {
23public:
24 PhysicalCore(Core::System& system, KernelCore& kernel, std::size_t id,
25 Core::ExclusiveMonitor& exclusive_monitor);
26
27 ~PhysicalCore();
28
29 /// Execute current jit state
30 void Run();
31 /// Execute a single instruction in current jit.
32 void Step();
33 /// Stop JIT execution/exit
34 void Stop();
35
36 // Shutdown this physical core.
37 void Shutdown();
38
39 Core::ARM_Interface& ArmInterface() {
40 return *arm_interface;
41 }
42
43 const Core::ARM_Interface& ArmInterface() const {
44 return *arm_interface;
45 }
46
47 bool IsMainCore() const {
48 return core_index == 0;
49 }
50
51 bool IsSystemCore() const {
52 return core_index == 3;
53 }
54
55 std::size_t CoreIndex() const {
56 return core_index;
57 }
58
59 Kernel::Scheduler& Scheduler() {
60 return *scheduler;
61 }
62
63 const Kernel::Scheduler& Scheduler() const {
64 return *scheduler;
65 }
66
67private:
68 std::size_t core_index;
69 KernelCore& kernel;
70 std::shared_ptr<Core::ARM_Interface> arm_interface;
71 std::shared_ptr<Kernel::Scheduler> scheduler;
72};
73
74} // namespace Kernel
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index d36fcd7d9..eb196a690 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -14,7 +14,6 @@
14#include "common/logging/log.h" 14#include "common/logging/log.h"
15#include "core/arm/arm_interface.h" 15#include "core/arm/arm_interface.h"
16#include "core/core.h" 16#include "core/core.h"
17#include "core/core_cpu.h"
18#include "core/core_timing.h" 17#include "core/core_timing.h"
19#include "core/hle/kernel/kernel.h" 18#include "core/hle/kernel/kernel.h"
20#include "core/hle/kernel/process.h" 19#include "core/hle/kernel/process.h"
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index dbcdb0b88..1d99bf7a2 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -15,7 +15,7 @@
15#include "common/string_util.h" 15#include "common/string_util.h"
16#include "core/arm/exclusive_monitor.h" 16#include "core/arm/exclusive_monitor.h"
17#include "core/core.h" 17#include "core/core.h"
18#include "core/core_cpu.h" 18#include "core/core_manager.h"
19#include "core/core_timing.h" 19#include "core/core_timing.h"
20#include "core/core_timing_util.h" 20#include "core/core_timing_util.h"
21#include "core/hle/kernel/address_arbiter.h" 21#include "core/hle/kernel/address_arbiter.h"
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index e84e5ce0d..e965b5b04 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -13,7 +13,6 @@
13#include "common/thread_queue_list.h" 13#include "common/thread_queue_list.h"
14#include "core/arm/arm_interface.h" 14#include "core/arm/arm_interface.h"
15#include "core/core.h" 15#include "core/core.h"
16#include "core/core_cpu.h"
17#include "core/core_timing.h" 16#include "core/core_timing.h"
18#include "core/core_timing_util.h" 17#include "core/core_timing_util.h"
19#include "core/hle/kernel/errors.h" 18#include "core/hle/kernel/errors.h"
@@ -356,7 +355,7 @@ void Thread::SetActivity(ThreadActivity value) {
356 // Set status if not waiting 355 // Set status if not waiting
357 if (status == ThreadStatus::Ready || status == ThreadStatus::Running) { 356 if (status == ThreadStatus::Ready || status == ThreadStatus::Running) {
358 SetStatus(ThreadStatus::Paused); 357 SetStatus(ThreadStatus::Paused);
359 Core::System::GetInstance().CpuCore(processor_id).PrepareReschedule(); 358 kernel.PrepareReschedule(processor_id);
360 } 359 }
361 } else if (status == ThreadStatus::Paused) { 360 } else if (status == ThreadStatus::Paused) {
362 // Ready to reschedule 361 // Ready to reschedule
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp
index 745f2c4e8..a0c806e8f 100644
--- a/src/core/hle/kernel/wait_object.cpp
+++ b/src/core/hle/kernel/wait_object.cpp
@@ -7,7 +7,6 @@
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/core.h" 9#include "core/core.h"
10#include "core/core_cpu.h"
11#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
12#include "core/hle/kernel/object.h" 11#include "core/hle/kernel/object.h"
13#include "core/hle/kernel/process.h" 12#include "core/hle/kernel/process.h"
@@ -96,7 +95,7 @@ void WaitObject::WakeupWaitingThread(std::shared_ptr<Thread> thread) {
96 } 95 }
97 if (resume) { 96 if (resume) {
98 thread->ResumeFromWait(); 97 thread->ResumeFromWait();
99 Core::System::GetInstance().PrepareReschedule(thread->GetProcessorID()); 98 kernel.PrepareReschedule(thread->GetProcessorID());
100 } 99 }
101} 100}
102 101