hle: kernel: KThread: Remove thread types that do not exist.

This commit is contained in:
bunnei 2020-12-31 00:46:09 -08:00
parent 9a4e148f9e
commit eea346ba8e
6 changed files with 30 additions and 53 deletions

View file

@ -279,7 +279,7 @@ void CpuManager::PreemptSingleCore(bool from_running_enviroment) {
auto& scheduler = system.Kernel().Scheduler(current_core); auto& scheduler = system.Kernel().Scheduler(current_core);
scheduler.Reload(scheduler.GetCurrentThread()); scheduler.Reload(scheduler.GetCurrentThread());
auto* currrent_thread2 = scheduler.GetCurrentThread(); auto* currrent_thread2 = scheduler.GetCurrentThread();
if (!currrent_thread2->IsIdleThread()) { if (!currrent_thread2->IsKernelThread()) {
idle_count = 0; idle_count = 0;
} }
} }

View file

@ -627,11 +627,11 @@ void KScheduler::OnThreadStart() {
void KScheduler::Unload(KThread* thread) { void KScheduler::Unload(KThread* thread) {
if (thread) { if (thread) {
thread->SetIsRunning(false); thread->SetIsRunning(false);
if (thread->IsContinuousOnSVC() && !thread->IsHLEThread()) { if (thread->IsContinuousOnSVC()) {
system.ArmInterface(core_id).ExceptionalExit(); system.ArmInterface(core_id).ExceptionalExit();
thread->SetContinuousOnSVC(false); thread->SetContinuousOnSVC(false);
} }
if (!thread->IsHLEThread() && !thread->HasExited()) { if (!thread->HasExited()) {
Core::ARM_Interface& cpu_core = system.ArmInterface(core_id); Core::ARM_Interface& cpu_core = system.ArmInterface(core_id);
cpu_core.SaveContext(thread->GetContext32()); cpu_core.SaveContext(thread->GetContext32());
cpu_core.SaveContext(thread->GetContext64()); cpu_core.SaveContext(thread->GetContext64());
@ -655,14 +655,13 @@ void KScheduler::Reload(KThread* thread) {
if (thread_owner_process != nullptr) { if (thread_owner_process != nullptr) {
system.Kernel().MakeCurrentProcess(thread_owner_process); system.Kernel().MakeCurrentProcess(thread_owner_process);
} }
if (!thread->IsHLEThread()) {
Core::ARM_Interface& cpu_core = system.ArmInterface(core_id); Core::ARM_Interface& cpu_core = system.ArmInterface(core_id);
cpu_core.LoadContext(thread->GetContext32()); cpu_core.LoadContext(thread->GetContext32());
cpu_core.LoadContext(thread->GetContext64()); cpu_core.LoadContext(thread->GetContext64());
cpu_core.SetTlsAddress(thread->GetTLSAddress()); cpu_core.SetTlsAddress(thread->GetTLSAddress());
cpu_core.SetTPIDR_EL0(thread->GetTPIDR_EL0()); cpu_core.SetTPIDR_EL0(thread->GetTPIDR_EL0());
cpu_core.ClearExclusiveState(); cpu_core.ClearExclusiveState();
}
} }
} }
@ -722,7 +721,7 @@ void KScheduler::SwitchToCurrent() {
return state.needs_scheduling.load(std::memory_order_relaxed); return state.needs_scheduling.load(std::memory_order_relaxed);
}; };
do { do {
if (current_thread != nullptr && !current_thread->IsHLEThread()) { if (current_thread != nullptr) {
current_thread->context_guard.lock(); current_thread->context_guard.lock();
if (current_thread->GetRawState() != ThreadState::Runnable) { if (current_thread->GetRawState() != ThreadState::Runnable) {
current_thread->context_guard.unlock(); current_thread->context_guard.unlock();
@ -764,9 +763,9 @@ void KScheduler::Initialize() {
std::string name = "Idle Thread Id:" + std::to_string(core_id); std::string name = "Idle Thread Id:" + std::to_string(core_id);
std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc();
void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
ThreadType type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE); auto thread_res = KThread::Create(system, THREADTYPE_KERNEL, name, 0, THREADPRIO_LOWEST, 0,
auto thread_res = KThread::Create(system, type, name, 0, 64, 0, static_cast<u32>(core_id), 0, static_cast<u32>(core_id), 0, nullptr, std::move(init_func),
nullptr, std::move(init_func), init_func_parameter); init_func_parameter);
idle_thread = thread_res.Unwrap().get(); idle_thread = thread_res.Unwrap().get();
{ {

View file

@ -125,7 +125,7 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread
void* thread_start_parameter) { void* thread_start_parameter) {
auto& kernel = system.Kernel(); auto& kernel = system.Kernel();
// Check if priority is in ranged. Lowest priority -> highest priority id. // Check if priority is in ranged. Lowest priority -> highest priority id.
if (priority > THREADPRIO_LOWEST && ((type_flags & THREADTYPE_IDLE) == 0)) { if (priority > THREADPRIO_LOWEST) {
LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority);
return ERR_INVALID_THREAD_PRIORITY; return ERR_INVALID_THREAD_PRIORITY;
} }
@ -164,10 +164,10 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread
thread->owner_process = owner_process; thread->owner_process = owner_process;
thread->type = type_flags; thread->type = type_flags;
thread->signaled = false; thread->signaled = false;
if ((type_flags & THREADTYPE_IDLE) == 0) {
auto& scheduler = kernel.GlobalSchedulerContext(); auto& scheduler = kernel.GlobalSchedulerContext();
scheduler.AddThread(thread); scheduler.AddThread(thread);
}
if (owner_process) { if (owner_process) {
thread->tls_address = thread->owner_process->CreateTLSRegion(); thread->tls_address = thread->owner_process->CreateTLSRegion();
thread->owner_process->RegisterThread(thread.get()); thread->owner_process->RegisterThread(thread.get());
@ -175,13 +175,10 @@ ResultVal<std::shared_ptr<KThread>> KThread::Create(Core::System& system, Thread
thread->tls_address = 0; thread->tls_address = 0;
} }
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used ResetThreadContext32(thread->context_32, static_cast<u32>(stack_top),
// to initialize the context static_cast<u32>(entry_point), static_cast<u32>(arg));
if ((type_flags & THREADTYPE_HLE) == 0) { ResetThreadContext64(thread->context_64, stack_top, entry_point, arg);
ResetThreadContext32(thread->context_32, static_cast<u32>(stack_top),
static_cast<u32>(entry_point), static_cast<u32>(arg));
ResetThreadContext64(thread->context_64, stack_top, entry_point, arg);
}
thread->host_context = thread->host_context =
std::make_shared<Common::Fiber>(std::move(thread_start_func), thread_start_parameter); std::make_shared<Common::Fiber>(std::move(thread_start_func), thread_start_parameter);

View file

@ -51,9 +51,6 @@ enum ThreadPriority : u32 {
enum ThreadType : u32 { enum ThreadType : u32 {
THREADTYPE_USER = 0x1, THREADTYPE_USER = 0x1,
THREADTYPE_KERNEL = 0x2, THREADTYPE_KERNEL = 0x2,
THREADTYPE_HLE = 0x4,
THREADTYPE_IDLE = 0x8,
THREADTYPE_SUSPEND = 0x10,
}; };
enum ThreadProcessorId : s32 { enum ThreadProcessorId : s32 {
@ -309,16 +306,8 @@ public:
return context_64; return context_64;
} }
bool IsHLEThread() const { bool IsKernelThread() const {
return (type & THREADTYPE_HLE) != 0; return (type & THREADTYPE_KERNEL) != 0;
}
bool IsSuspendThread() const {
return (type & THREADTYPE_SUSPEND) != 0;
}
bool IsIdleThread() const {
return (type & THREADTYPE_IDLE) != 0;
} }
bool WasRunning() const { bool WasRunning() const {

View file

@ -168,11 +168,9 @@ struct KernelCore::Impl {
std::string name = "Suspend Thread Id:" + std::to_string(i); std::string name = "Suspend Thread Id:" + std::to_string(i);
std::function<void(void*)> init_func = Core::CpuManager::GetSuspendThreadStartFunc(); std::function<void(void*)> init_func = Core::CpuManager::GetSuspendThreadStartFunc();
void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
const auto type = auto thread_res = KThread::Create(system, THREADTYPE_KERNEL, std::move(name), 0, 0, 0,
static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND); static_cast<u32>(i), 0, nullptr, std::move(init_func),
auto thread_res = init_func_parameter);
KThread::Create(system, type, std::move(name), 0, 0, 0, static_cast<u32>(i), 0,
nullptr, std::move(init_func), init_func_parameter);
suspend_threads[i] = std::move(thread_res).Unwrap(); suspend_threads[i] = std::move(thread_res).Unwrap();
} }

View file

@ -92,10 +92,8 @@ std::vector<std::unique_ptr<WaitTreeThread>> WaitTreeItem::MakeThreadItemList()
std::size_t row = 0; std::size_t row = 0;
auto add_threads = [&](const std::vector<std::shared_ptr<Kernel::KThread>>& threads) { auto add_threads = [&](const std::vector<std::shared_ptr<Kernel::KThread>>& threads) {
for (std::size_t i = 0; i < threads.size(); ++i) { for (std::size_t i = 0; i < threads.size(); ++i) {
if (!threads[i]->IsHLEThread()) { item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i]));
item_list.push_back(std::make_unique<WaitTreeThread>(*threads[i])); item_list.back()->row = row;
item_list.back()->row = row;
}
++row; ++row;
} }
}; };
@ -149,10 +147,6 @@ QString WaitTreeCallstack::GetText() const {
std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeCallstack::GetChildren() const { std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeCallstack::GetChildren() const {
std::vector<std::unique_ptr<WaitTreeItem>> list; std::vector<std::unique_ptr<WaitTreeItem>> list;
if (thread.IsHLEThread()) {
return list;
}
if (thread.GetOwnerProcess() == nullptr || !thread.GetOwnerProcess()->Is64BitProcess()) { if (thread.GetOwnerProcess() == nullptr || !thread.GetOwnerProcess()->Is64BitProcess()) {
return list; return list;
} }