From 5cfb9e3e9ddee672d9a8d99ce11f6c181bf4ae3d Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Tue, 14 Jun 2022 11:22:50 +0200 Subject: [PATCH] base-hw: distinguish core, idle, user threads Do not only distinguish core and user threads, but the idle threads too. Instead of a boolean value, introduce a new thread type. Ref genodelabs/genode#4527 --- repos/base-hw/src/core/kernel/cpu.cc | 3 ++- repos/base-hw/src/core/kernel/thread.cc | 14 +++++++------- repos/base-hw/src/core/kernel/thread.h | 11 ++++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/repos/base-hw/src/core/kernel/cpu.cc b/repos/base-hw/src/core/kernel/cpu.cc index 7840d39acb..02e190d63e 100644 --- a/repos/base-hw/src/core/kernel/cpu.cc +++ b/repos/base-hw/src/core/kernel/cpu.cc @@ -109,7 +109,8 @@ Cpu::Idle_thread::Idle_thread(Board::Address_space_id_allocator &addr_space_id_a Cpu &cpu, Pd &core_pd) : - Thread { addr_space_id_alloc, user_irq_pool, cpu_pool, core_pd, "idle" } + Thread { addr_space_id_alloc, user_irq_pool, cpu_pool, core_pd, + Cpu_priority::min(), 0, "idle", Thread::IDLE } { regs->ip = (addr_t)&idle_thread_main; diff --git a/repos/base-hw/src/core/kernel/thread.cc b/repos/base-hw/src/core/kernel/thread.cc index 0d2e9227e7..5d17a3a559 100644 --- a/repos/base-hw/src/core/kernel/thread.cc +++ b/repos/base-hw/src/core/kernel/thread.cc @@ -369,7 +369,7 @@ void Thread::_call_restart_thread() Thread &thread = *thread_ptr; - if (!_core && (&pd() != &thread.pd())) { + if (_type == USER && (&pd() != &thread.pd())) { raw(*this, ": failed to lookup thread ", (unsigned)user_arg_1(), " to restart it"); _die(); @@ -793,7 +793,7 @@ void Thread::_call() case call_id_pause_vm(): _call_pause_vm(); return; default: /* check wether this is a core thread */ - if (!_core) { + if (_type != CORE) { Genode::raw(*this, ": not entitled to do kernel call"); _die(); return; @@ -805,7 +805,7 @@ void Thread::_call() _call_new(_addr_space_id_alloc, _user_irq_pool, _cpu_pool, _core_pd, (unsigned) user_arg_2(), (unsigned) _core_to_kernel_quota(user_arg_3()), - (char const *) user_arg_4()); + (char const *) user_arg_4(), USER); return; case call_id_new_core_thread(): _call_new(_addr_space_id_alloc, _user_irq_pool, _cpu_pool, @@ -857,7 +857,7 @@ void Thread::_mmu_exception() return; } - if (_core) + if (_type != USER) Genode::raw(*this, " raised a fault, which should never happen ", _fault); @@ -874,7 +874,7 @@ Thread::Thread(Board::Address_space_id_allocator &addr_space_id_alloc, unsigned const priority, unsigned const quota, char const *const label, - bool core) + Type type) : Kernel::Object { *this }, Cpu_job { priority, quota }, @@ -885,8 +885,8 @@ Thread::Thread(Board::Address_space_id_allocator &addr_space_id_alloc, _ipc_node { *this }, _state { AWAITS_START }, _label { label }, - _core { core }, - regs { core } + _type { type }, + regs { type != USER } { } diff --git a/repos/base-hw/src/core/kernel/thread.h b/repos/base-hw/src/core/kernel/thread.h index f7516a6ba9..30f774163d 100644 --- a/repos/base-hw/src/core/kernel/thread.h +++ b/repos/base-hw/src/core/kernel/thread.h @@ -57,6 +57,10 @@ struct Kernel::Thread_fault */ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout { + public: + + enum Type { USER, CORE, IDLE }; + private: /* @@ -149,7 +153,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout capid_t _timeout_sigid { 0 }; bool _paused { false }; bool _cancel_next_await_signal { false }; - bool const _core { false }; + Type const _type; Genode::Constructible _tlb_invalidation {}; Genode::Constructible _destroy {}; @@ -301,7 +305,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout unsigned const priority, unsigned const quota, char const *const label, - bool core = false); + Type const type); /** * Constructor for core/kernel thread @@ -315,7 +319,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout char const *const label) : Thread(addr_space_id_alloc, user_irq_pool, cpu_pool, core_pd, - Cpu_priority::min(), 0, label, true) + Cpu_priority::min(), 0, label, CORE) { } ~Thread(); @@ -432,6 +436,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout char const * label() const { return _label; } Thread_fault fault() const { return _fault; } Genode::Native_utcb *utcb() { return _utcb; } + Type type() const { return _type; } Pd &pd() const {