From 0c299c5e08b8ff4d19697283307446ca0f0e2644 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 30 Mar 2016 15:34:37 +0200 Subject: [PATCH] base: separate native CPU from CPU session This patch unifies the CPU session interface across all platforms. The former differences are moved to respective "native-CPU" interfaces. NOVA is not covered by the patch and still relies on a custom version of the core-internal 'cpu_session_component.h'. However, this will soon be removed once the ongoing rework of pause/single-step on NOVA is completed. Fixes #1922 --- .../src/core/include/platform_thread.h | 5 + repos/base-fiasco/src/core/target.inc | 1 + .../base-foc/include/foc_cpu_session/client.h | 108 ------- .../include/foc_cpu_session/connection.h | 41 --- .../include/foc_cpu_session/foc_cpu_session.h | 46 --- .../base-foc/include/foc_native_cpu/client.h | 39 +++ .../include/foc_native_cpu/foc_native_cpu.h | 42 +++ .../src/core/include/cpu_session_component.h | 298 ------------------ .../src/core/include/cpu_session_irqs.h | 66 ++++ .../src/core/include/native_cpu_component.h | 48 +++ .../src/core/include/platform_thread.h | 7 +- ...n_extension.cc => native_cpu_component.cc} | 48 ++- repos/base-foc/src/core/platform_thread.cc | 13 +- repos/base-foc/src/core/target.inc | 4 +- .../src/core/include/platform_thread.h | 5 + repos/base-linux/src/base/env/platform_env.cc | 21 +- repos/base-linux/src/base/ipc/ipc.cc | 2 +- .../src/base/thread/thread_linux.cc | 7 +- .../src/core/cpu_session_extension.cc | 48 --- .../src/core/cpu_session_support.cc | 30 -- .../src/core/include/cpu_session_component.h | 249 --------------- .../src/core/include/native_cpu_component.h | 47 +++ .../src/core/include/platform_thread.h | 7 +- .../src/core/native_cpu_component.cc | 68 ++++ repos/base-linux/src/core/platform_thread.cc | 2 +- repos/base-linux/src/core/target.mk | 3 +- .../src/include/base/internal/platform_env.h | 14 +- .../src/include/linux_cpu_session/client.h | 104 ------ .../linux_cpu_session/linux_cpu_session.h | 70 ---- .../src/include/linux_native_cpu/client.h | 37 +++ .../linux_native_cpu/linux_native_cpu.h | 68 ++++ .../base-linux/src/lib/lx_hybrid/lx_hybrid.cc | 27 +- repos/base-nova/include/cpu_session/client.h | 2 + .../src/core/cpu_session_extension.cc | 5 +- .../base-nova/src/core/cpu_session_support.cc | 30 -- .../src/core/include/cpu_session_component.h | 6 + .../src/core/include/platform_thread.h | 7 +- repos/base-nova/src/core/platform_thread.cc | 2 +- repos/base-nova/src/core/target.inc | 1 + .../base-okl4/src/core/cpu_session_support.cc | 30 -- .../src/core/include/platform_thread.h | 5 + repos/base-okl4/src/core/target.inc | 1 + .../src/core/include/platform_thread.h | 5 + repos/base-pistachio/src/core/target.inc | 1 + repos/base-sel4/lib/mk/core.mk | 1 + .../base-sel4/src/core/cpu_session_support.cc | 30 -- .../src/core/include/platform_thread.h | 5 + repos/base/include/cpu_session/client.h | 2 + repos/base/include/cpu_session/cpu_session.h | 20 +- repos/base/src/core/cpu_session_component.cc | 14 +- .../src/core/cpu_session_support.cc | 2 +- .../src/core/include/cpu_session_component.h | 16 +- .../src/core/include/native_cpu_component.h | 42 +++ repos/ports-foc/src/lib/l4lx/genode_block.cc | 10 +- repos/ports-foc/src/lib/l4lx/genode_net.cc | 4 +- .../ports-foc/src/lib/l4lx/genode_terminal.cc | 6 +- repos/ports-foc/src/lib/l4lx/include/vcpu.h | 15 +- repos/ports-foc/src/lib/l4lx/l4lx_thread.cc | 15 +- repos/ports-foc/src/lib/l4lx/l4x_pagefault.cc | 3 +- repos/ports-foc/src/lib/l4lx/startup.cc | 10 +- .../app/gdb_monitor/cpu_session_component.cc | 6 + .../app/gdb_monitor/cpu_session_component.h | 1 + repos/ports/src/noux/cpu_session_component.h | 3 + 63 files changed, 668 insertions(+), 1207 deletions(-) delete mode 100644 repos/base-foc/include/foc_cpu_session/client.h delete mode 100644 repos/base-foc/include/foc_cpu_session/connection.h delete mode 100644 repos/base-foc/include/foc_cpu_session/foc_cpu_session.h create mode 100644 repos/base-foc/include/foc_native_cpu/client.h create mode 100644 repos/base-foc/include/foc_native_cpu/foc_native_cpu.h delete mode 100644 repos/base-foc/src/core/include/cpu_session_component.h create mode 100644 repos/base-foc/src/core/include/cpu_session_irqs.h create mode 100644 repos/base-foc/src/core/include/native_cpu_component.h rename repos/base-foc/src/core/{cpu_session_extension.cc => native_cpu_component.cc} (61%) delete mode 100644 repos/base-linux/src/core/cpu_session_extension.cc delete mode 100644 repos/base-linux/src/core/cpu_session_support.cc delete mode 100644 repos/base-linux/src/core/include/cpu_session_component.h create mode 100644 repos/base-linux/src/core/include/native_cpu_component.h create mode 100644 repos/base-linux/src/core/native_cpu_component.cc delete mode 100644 repos/base-linux/src/include/linux_cpu_session/client.h delete mode 100644 repos/base-linux/src/include/linux_cpu_session/linux_cpu_session.h create mode 100644 repos/base-linux/src/include/linux_native_cpu/client.h create mode 100644 repos/base-linux/src/include/linux_native_cpu/linux_native_cpu.h delete mode 100644 repos/base-nova/src/core/cpu_session_support.cc delete mode 100644 repos/base-okl4/src/core/cpu_session_support.cc delete mode 100644 repos/base-sel4/src/core/cpu_session_support.cc rename repos/{base-fiasco => base}/src/core/cpu_session_support.cc (91%) create mode 100644 repos/base/src/core/include/native_cpu_component.h diff --git a/repos/base-fiasco/src/core/include/platform_thread.h b/repos/base-fiasco/src/core/include/platform_thread.h index 7c741a88b..52330036e 100644 --- a/repos/base-fiasco/src/core/include/platform_thread.h +++ b/repos/base-fiasco/src/core/include/platform_thread.h @@ -77,6 +77,11 @@ namespace Genode { */ void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ diff --git a/repos/base-fiasco/src/core/target.inc b/repos/base-fiasco/src/core/target.inc index 1a3f7348e..4fcc7096b 100644 --- a/repos/base-fiasco/src/core/target.inc +++ b/repos/base-fiasco/src/core/target.inc @@ -50,6 +50,7 @@ vpath ram_session_component.cc $(GEN_CORE_DIR) vpath rom_session_component.cc $(GEN_CORE_DIR) vpath cap_session_component.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath pd_session_component.cc $(GEN_CORE_DIR) vpath rpc_cap_factory.cc $(GEN_CORE_DIR) vpath core_rpc_cap_alloc.cc $(GEN_CORE_DIR) diff --git a/repos/base-foc/include/foc_cpu_session/client.h b/repos/base-foc/include/foc_cpu_session/client.h deleted file mode 100644 index ad520c19c..000000000 --- a/repos/base-foc/include/foc_cpu_session/client.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * \brief Client-side cpu session Fiasco.OC extension - * \author Stefan Kalkowski - * \date 2011-04-04 - */ - -/* - * Copyright (C) 2011-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _INCLUDE__FOC_CPU_SESSION__CLIENT_H_ -#define _INCLUDE__FOC_CPU_SESSION__CLIENT_H_ - -#include -#include -#include - -namespace Genode { - - struct Foc_cpu_session_client : Rpc_client - { - explicit Foc_cpu_session_client(Cpu_session_capability session) - : Rpc_client(static_cap_cast(session)) { } - - Thread_capability create_thread(size_t weight, Name const &name, addr_t utcb = 0) { - return call(weight, name, utcb); } - - Ram_dataspace_capability utcb(Thread_capability thread) { - return call(thread); } - - void kill_thread(Thread_capability thread) { - call(thread); } - - int set_pager(Thread_capability thread, Pager_capability pager) { - return call(thread, pager); } - - int start(Thread_capability thread, addr_t ip, addr_t sp) { - return call(thread, ip, sp); } - - void pause(Thread_capability thread) { - call(thread); } - - void resume(Thread_capability thread) { - call(thread); } - - void cancel_blocking(Thread_capability thread) { - call(thread); } - - int name(Thread_capability thread, char *name_dst, size_t name_len) - { - PWRN("name called, this function is deprecated"); - return -1; - } - - Thread_state state(Thread_capability thread) { - return call(thread); } - - void state(Thread_capability thread, Thread_state const &state) { - call(thread, state); } - - void exception_handler(Thread_capability thread, Signal_context_capability handler) { - call(thread, handler); } - - void single_step(Thread_capability thread, bool enable) { - call(thread, enable); } - - Affinity::Space affinity_space() const { - return call(); } - - void affinity(Thread_capability thread, Affinity::Location location) { - call(thread, location); } - - Dataspace_capability trace_control() { - return call(); } - - unsigned trace_control_index(Thread_capability thread) { - return call(thread); } - - Dataspace_capability trace_buffer(Thread_capability thread) { - return call(thread); } - - Dataspace_capability trace_policy(Thread_capability thread) { - return call(thread); } - - void enable_vcpu(Thread_capability cap, addr_t vcpu_state) { - call(cap, vcpu_state); } - - Native_capability native_cap(Thread_capability cap) { - return call(cap); } - - Native_capability alloc_irq() { - return call(); } - - int ref_account(Cpu_session_capability session) { - return call(session); } - - int transfer_quota(Cpu_session_capability session, size_t amount) { - return call(session, amount); } - - Quota quota() override { return call(); } - }; - -} - -#endif /* _INCLUDE__FOC_CPU_SESSION__CLIENT_H_ */ diff --git a/repos/base-foc/include/foc_cpu_session/connection.h b/repos/base-foc/include/foc_cpu_session/connection.h deleted file mode 100644 index 89f3d42de..000000000 --- a/repos/base-foc/include/foc_cpu_session/connection.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * \brief Connection to Fiasco.OC specific cpu service - * \author Stefan Kalkowski - * \date 2011-04-04 - */ - -/* - * Copyright (C) 2011-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _INCLUDE__FOC_CPU_SESSION__CONNECTION_H_ -#define _INCLUDE__FOC_CPU_SESSION__CONNECTION_H_ - -#include -#include - -namespace Genode { - - struct Foc_cpu_connection : Connection, Foc_cpu_session_client - { - /** - * Constructor - * - * \param label initial session label - * \param priority designated priority of all threads created - * with this CPU session - */ - Foc_cpu_connection(const char *label = "", - long priority = DEFAULT_PRIORITY) - : - Connection( - session("priority=0x%lx, ram_quota=32K, label=\"%s\"", - priority, label)), - Foc_cpu_session_client(cap()) { } - }; -} - -#endif /* _INCLUDE__FOC_CPU_SESSION__CONNECTION_H_ */ diff --git a/repos/base-foc/include/foc_cpu_session/foc_cpu_session.h b/repos/base-foc/include/foc_cpu_session/foc_cpu_session.h deleted file mode 100644 index 9ea5fca10..000000000 --- a/repos/base-foc/include/foc_cpu_session/foc_cpu_session.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * \brief Cpu session interface extension for Fiasco.OC - * \author Stefan Kalkowski - * \date 2011-04-04 - */ - -/* - * Copyright (C) 2011-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _INCLUDE__FOC_CPU_SESSION__FOC_CPU_SESSION_H_ -#define _INCLUDE__FOC_CPU_SESSION__FOC_CPU_SESSION_H_ - -#include -#include - -namespace Genode { - - struct Foc_cpu_session : Cpu_session - { - virtual ~Foc_cpu_session() { } - - virtual void enable_vcpu(Thread_capability cap, addr_t vcpu_state) = 0; - - virtual Native_capability native_cap(Thread_capability cap) = 0; - - virtual Native_capability alloc_irq() = 0; - - - /********************* - ** RPC declaration ** - *********************/ - - GENODE_RPC(Rpc_enable_vcpu, void, enable_vcpu, Thread_capability, addr_t); - GENODE_RPC(Rpc_native_cap, Native_capability, native_cap, Thread_capability); - GENODE_RPC(Rpc_alloc_irq, Native_capability, alloc_irq); - - GENODE_RPC_INTERFACE_INHERIT(Cpu_session, - Rpc_enable_vcpu, Rpc_native_cap, Rpc_alloc_irq); - }; -} - -#endif /* _INCLUDE__FOC_CPU_SESSION__FOC_CPU_SESSION_H_ */ diff --git a/repos/base-foc/include/foc_native_cpu/client.h b/repos/base-foc/include/foc_native_cpu/client.h new file mode 100644 index 000000000..c001c93d2 --- /dev/null +++ b/repos/base-foc/include/foc_native_cpu/client.h @@ -0,0 +1,39 @@ +/* + * \brief Client-side Fiasco.OC specific CPU session interface + * \author Stefan Kalkowski + * \author Norman Feske + * \date 2011-04-14 + */ + +/* + * Copyright (C) 2011-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__FOC_NATIVE_CPU__CLIENT_H_ +#define _INCLUDE__FOC_NATIVE_CPU__CLIENT_H_ + +#include +#include + +namespace Genode { struct Foc_native_cpu_client; } + + +struct Genode::Foc_native_cpu_client : Rpc_client +{ + explicit Foc_native_cpu_client(Capability cap) + : Rpc_client(static_cap_cast(cap)) { } + + void enable_vcpu(Thread_capability cap, addr_t vcpu_state) { + call(cap, vcpu_state); } + + Native_capability native_cap(Thread_capability cap) { + return call(cap); } + + Native_capability alloc_irq() { + return call(); } +}; + +#endif /* _INCLUDE__FOC_NATIVE_CPU__CLIENT_H_ */ diff --git a/repos/base-foc/include/foc_native_cpu/foc_native_cpu.h b/repos/base-foc/include/foc_native_cpu/foc_native_cpu.h new file mode 100644 index 000000000..9dd8cd05d --- /dev/null +++ b/repos/base-foc/include/foc_native_cpu/foc_native_cpu.h @@ -0,0 +1,42 @@ +/* + * \brief Fiasco.OC-specific part of the CPU session interface + * \author Stefan Kalkowski + * \author Norman Feske + * \date 2011-04-14 + */ + +/* + * Copyright (C) 2011-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__FOC_NATIVE_CPU__FOC_NATIVE_CPU_H_ +#define _INCLUDE__FOC_NATIVE_CPU__FOC_NATIVE_CPU_H_ + +#include +#include + +namespace Genode { struct Foc_native_cpu; } + + +struct Genode::Foc_native_cpu : Cpu_session::Native_cpu +{ + virtual void enable_vcpu(Thread_capability cap, addr_t vcpu_state) = 0; + virtual Native_capability native_cap(Thread_capability cap) = 0; + virtual Native_capability alloc_irq() = 0; + + + /********************* + ** RPC declaration ** + *********************/ + + GENODE_RPC(Rpc_enable_vcpu, void, enable_vcpu, Thread_capability, addr_t); + GENODE_RPC(Rpc_native_cap, Native_capability, native_cap, Thread_capability); + GENODE_RPC(Rpc_alloc_irq, Native_capability, alloc_irq); + + GENODE_RPC_INTERFACE(Rpc_enable_vcpu, Rpc_native_cap, Rpc_alloc_irq); +}; + +#endif /* _INCLUDE__FOC_NATIVE_CPU__FOC_NATIVE_CPU_H_ */ diff --git a/repos/base-foc/src/core/include/cpu_session_component.h b/repos/base-foc/src/core/include/cpu_session_component.h deleted file mode 100644 index 9c3ceda0b..000000000 --- a/repos/base-foc/src/core/include/cpu_session_component.h +++ /dev/null @@ -1,298 +0,0 @@ -/* - * \brief Core-specific instance of the CPU session/thread interfaces - * \author Christian Helmuth - * \author Norman Feske - * \author Stefan Kalkowski - * \date 2006-07-17 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ -#define _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ - -/* Genode includes */ -#include -#include -#include -#include -#include -#include - -/* core includes */ -#include -#include -#include -#include - -namespace Genode { - - /** - * RPC interface of CPU thread - * - * We make 'Cpu_thread' a RPC object only to be able to lookup CPU threads - * from thread capabilities supplied as arguments to CPU-session functions. - * A CPU thread does not provide an actual RPC interface. - */ - struct Cpu_thread - { - GENODE_RPC_INTERFACE(); - }; - - - class Cpu_thread_component : public Rpc_object, - public List::Element, - public Trace::Source::Info_accessor - { - public: - - typedef Trace::Session_label Session_label; - typedef Trace::Thread_name Thread_name; - - private: - - Session_label const _session_label; - Thread_name const _name; - Platform_thread _platform_thread; - bool _bound; /* pd binding flag */ - Signal_context_capability _sigh; /* exception handler */ - unsigned const _trace_control_index; - Trace::Source _trace_source; - - public: - - Cpu_thread_component(size_t const weight, - size_t const quota, - Session_label const &label, - Thread_name const &name, - unsigned priority, addr_t utcb, - Signal_context_capability sigh, - unsigned trace_control_index, - Trace::Control &trace_control) - : - _session_label(label), _name(name), - _platform_thread(name.string(), priority, utcb), _bound(false), - _sigh(sigh), _trace_control_index(trace_control_index), - _trace_source(*this, trace_control) - { - update_exception_sigh(); - } - - - /******************************************** - ** Trace::Source::Info_accessor interface ** - ********************************************/ - - Trace::Source::Info trace_source_info() const - { - return { _session_label, _name, - _platform_thread.execution_time(), - _platform_thread.affinity() }; - } - - - /************************ - ** Accessor functions ** - ************************/ - - Platform_thread *platform_thread() { return &_platform_thread; } - bool bound() const { return _bound; } - void bound(bool b) { _bound = b; } - Trace::Source *trace_source() { return &_trace_source; } - - size_t weight() const { return Cpu_session::DEFAULT_WEIGHT; } - - void sigh(Signal_context_capability sigh) - { - _sigh = sigh; - update_exception_sigh(); - } - - /** - * Propagate exception handler to platform thread - */ - void update_exception_sigh(); - - /** - * Return index within the CPU-session's trace control area - */ - unsigned trace_control_index() const { return _trace_control_index; } - }; - - - class Cpu_session_component : public Rpc_object - { - public: - - typedef Cpu_thread_component::Session_label Session_label; - - private: - - /** - * Allocator used for managing the CPU threads associated with the - * CPU session - */ - typedef Tslab Cpu_thread_allocator; - - Session_label _label; - Rpc_entrypoint *_session_ep; - Rpc_entrypoint *_thread_ep; - Pager_entrypoint *_pager_ep; - Allocator_guard _md_alloc; /* guarded meta-data allocator */ - Cpu_thread_allocator _thread_alloc; /* meta-data allocator */ - Lock _thread_alloc_lock; /* protect allocator access */ - List _thread_list; - Lock _thread_list_lock; /* protect thread list */ - unsigned _priority; /* priority of threads - created with this - session */ - Affinity::Location _location; /* CPU affinity of this - session */ - Trace::Source_registry &_trace_sources; - Trace::Control_area _trace_control_area; - - size_t _weight; - size_t _quota; - Cpu_session_component * _ref; - List _ref_members; - Lock _ref_members_lock; - - void _incr_weight(size_t); - void _decr_weight(size_t); - size_t _weight_to_quota(size_t) const; - void _decr_quota(size_t); - void _incr_quota(size_t); - void _update_thread_quota(Cpu_thread_component *) const; - void _update_each_thread_quota(); - void _transfer_quota(Cpu_session_component *, size_t); - void _insert_ref_member(Cpu_session_component *) { } - void _unsync_remove_ref_member(Cpu_session_component *) { } - void _remove_ref_member(Cpu_session_component *) { } - void _deinit_ref_account(); - void _deinit_threads(); - - /** - * Exception handler that will be invoked unless overridden by a - * call of 'Cpu_session::exception_handler'. - */ - Signal_context_capability _default_exception_handler; - - /** - * Raw thread-killing functionality - * - * This function is called from the 'kill_thread' function and - * the destructor. Each these functions grab the list lock - * by themselves and call this function to perform the actual - * killing. - */ - void _unsynchronized_kill_thread(Thread_capability cap); - - public: - - /** - * Constructor - */ - Cpu_session_component(Rpc_entrypoint *session_ep, - Rpc_entrypoint *thread_ep, - Pager_entrypoint *pager_ep, - Allocator *md_alloc, - Trace::Source_registry &trace_sources, - const char *args, Affinity const &affinity, - size_t quota); - - /** - * Destructor - */ - ~Cpu_session_component(); - - /** - * Register quota donation at allocator guard - */ - void upgrade_ram_quota(size_t ram_quota) { _md_alloc.upgrade(ram_quota); } - - - /*************************** - ** CPU session interface ** - ***************************/ - - Thread_capability create_thread(size_t, Name const &, addr_t); - Ram_dataspace_capability utcb(Thread_capability thread); - void kill_thread(Thread_capability); - Thread_capability first(); - Thread_capability next(Thread_capability); - int set_pager(Thread_capability, Pager_capability); - int start(Thread_capability, addr_t, addr_t); - void pause(Thread_capability thread_cap); - void resume(Thread_capability thread_cap); - void single_step(Thread_capability thread_cap, bool enable); - void cancel_blocking(Thread_capability); - int name(Thread_capability, char *, size_t); - Thread_state state(Thread_capability); - void state(Thread_capability, Thread_state const &); - void exception_handler(Thread_capability, Signal_context_capability); - Affinity::Space affinity_space() const; - void affinity(Thread_capability, Affinity::Location); - Dataspace_capability trace_control(); - unsigned trace_control_index(Thread_capability); - Dataspace_capability trace_buffer(Thread_capability); - Dataspace_capability trace_policy(Thread_capability); - int ref_account(Cpu_session_capability c); - int transfer_quota(Cpu_session_capability, size_t); - Quota quota() override; - - - /*********************************** - ** Fiasco.OC specific extensions ** - ***********************************/ - - void enable_vcpu(Thread_capability, addr_t); - Native_capability native_cap(Thread_capability); - Native_capability alloc_irq(); - }; - - - class Cpu_session_irqs : public Avl_node - { - private: - - enum { IRQ_MAX = 20 }; - - Cpu_session_component* _owner; - Native_capability _irqs[IRQ_MAX]; - unsigned _cnt; - - public: - - Cpu_session_irqs(Cpu_session_component *owner) - : _owner(owner), _cnt(0) {} - - bool add(Native_capability irq) - { - if (_cnt >= (IRQ_MAX - 1)) - return false; - _irqs[_cnt++] = irq; - return true; - } - - /************************ - ** Avl node interface ** - ************************/ - - bool higher(Cpu_session_irqs *c) { return (c->_owner > _owner); } - - Cpu_session_irqs *find_by_session(Cpu_session_component *o) - { - if (o == _owner) return this; - - Cpu_session_irqs *c = Avl_node::child(o > _owner); - return c ? c->find_by_session(o) : 0; - } - }; -} - -#endif /* _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ */ diff --git a/repos/base-foc/src/core/include/cpu_session_irqs.h b/repos/base-foc/src/core/include/cpu_session_irqs.h new file mode 100644 index 000000000..e8a98d385 --- /dev/null +++ b/repos/base-foc/src/core/include/cpu_session_irqs.h @@ -0,0 +1,66 @@ +/* + * \brief Fiasco.OC-specific implementation of core's CPU service + * \author Christian Helmuth + * \author Norman Feske + * \author Stefan Kalkowski + * \date 2006-07-17 + */ + +/* + * Copyright (C) 2006-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _CORE__INCLUDE__CPU_SESSION_IRQS_H_ +#define _CORE__INCLUDE__CPU_SESSION_IRQS_H_ + +/* Genode includes */ +#include + +/* core includes */ +#include + +namespace Genode { class Cpu_session_irqs; } + + +class Genode::Cpu_session_irqs : public Avl_node +{ + private: + + enum { IRQ_MAX = 20 }; + + Cpu_session_component* _owner; + Native_capability _irqs[IRQ_MAX]; + unsigned _cnt; + + public: + + Cpu_session_irqs(Cpu_session_component *owner) + : _owner(owner), _cnt(0) {} + + bool add(Native_capability irq) + { + if (_cnt >= (IRQ_MAX - 1)) + return false; + _irqs[_cnt++] = irq; + return true; + } + + /************************ + ** Avl node interface ** + ************************/ + + bool higher(Cpu_session_irqs *c) { return (c->_owner > _owner); } + + Cpu_session_irqs *find_by_session(Cpu_session_component *o) + { + if (o == _owner) return this; + + Cpu_session_irqs *c = Avl_node::child(o > _owner); + return c ? c->find_by_session(o) : 0; + } +}; + +#endif /* _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ */ diff --git a/repos/base-foc/src/core/include/native_cpu_component.h b/repos/base-foc/src/core/include/native_cpu_component.h new file mode 100644 index 000000000..bf1fd037b --- /dev/null +++ b/repos/base-foc/src/core/include/native_cpu_component.h @@ -0,0 +1,48 @@ +/* + * \brief Kernel-specific part of the CPU-session interface + * \author Norman Feske + * \date 2016-01-19 + * + * This definition is used on platforms with no kernel-specific PD functions + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ +#define _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ + +/* Genode includes */ +#include +#include + +namespace Genode { + + class Cpu_session_component; + class Native_cpu_component; +} + + +class Genode::Native_cpu_component : public Rpc_object +{ + private: + + Cpu_session_component &_cpu_session; + Rpc_entrypoint &_thread_ep; + + public: + + Native_cpu_component(Cpu_session_component &, char const *); + ~Native_cpu_component(); + + void enable_vcpu(Thread_capability, addr_t) override; + Native_capability native_cap(Thread_capability) override; + Native_capability alloc_irq() override; +}; + +#endif /* _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ */ diff --git a/repos/base-foc/src/core/include/platform_thread.h b/repos/base-foc/src/core/include/platform_thread.h index 0cc5897c5..b200b0362 100644 --- a/repos/base-foc/src/core/include/platform_thread.h +++ b/repos/base-foc/src/core/include/platform_thread.h @@ -64,7 +64,7 @@ namespace Genode { /** * Constructor for non-core threads */ - Platform_thread(const char *name, unsigned priority, addr_t); + Platform_thread(size_t, const char *name, unsigned priority, addr_t); /** * Constructor for core main-thread @@ -98,6 +98,11 @@ namespace Genode { */ void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool); + /** * Resume this thread */ diff --git a/repos/base-foc/src/core/cpu_session_extension.cc b/repos/base-foc/src/core/native_cpu_component.cc similarity index 61% rename from repos/base-foc/src/core/cpu_session_extension.cc rename to repos/base-foc/src/core/native_cpu_component.cc index e796c8253..ad8df5986 100644 --- a/repos/base-foc/src/core/cpu_session_extension.cc +++ b/repos/base-foc/src/core/native_cpu_component.cc @@ -14,8 +14,9 @@ /* Genode includes */ #include -/* Core includes */ -#include +/* core includes */ +#include +#include #include /* Fiasco.OC includes */ @@ -26,15 +27,9 @@ namespace Fiasco { static Genode::Avl_tree _irq_tree; -Genode::Ram_dataspace_capability Genode::Cpu_session_component::utcb(Genode::Thread_capability thread_cap) -{ - using namespace Genode; - PERR("%s: Not implemented", __PRETTY_FUNCTION__); - return Ram_dataspace_capability(); -} -void Genode::Cpu_session_component::enable_vcpu(Genode::Thread_capability thread_cap, +void Genode::Native_cpu_component::enable_vcpu(Genode::Thread_capability thread_cap, Genode::addr_t vcpu_state) { using namespace Genode; @@ -49,12 +44,12 @@ void Genode::Cpu_session_component::enable_vcpu(Genode::Thread_capability thread if (l4_msgtag_has_error(tag)) PWRN("l4_thread_vcpu_control failed"); }; - _thread_ep->apply(thread_cap, lambda); + _thread_ep.apply(thread_cap, lambda); } Genode::Native_capability -Genode::Cpu_session_component::native_cap(Genode::Thread_capability cap) +Genode::Native_cpu_component::native_cap(Genode::Thread_capability cap) { using namespace Genode; @@ -62,11 +57,11 @@ Genode::Cpu_session_component::native_cap(Genode::Thread_capability cap) return (!thread) ? Native_capability() : thread->platform_thread()->thread().local; }; - return _thread_ep->apply(cap, lambda); + return _thread_ep.apply(cap, lambda); } -Genode::Native_capability Genode::Cpu_session_component::alloc_irq() +Genode::Native_capability Genode::Native_cpu_component::alloc_irq() { using namespace Fiasco; using namespace Genode; @@ -74,11 +69,11 @@ Genode::Native_capability Genode::Cpu_session_component::alloc_irq() /* find irq object container of this cpu-session */ Cpu_session_irqs* node = _irq_tree.first(); if (node) - node = node->find_by_session(this); + node = node->find_by_session(&_cpu_session); /* if not found, we've to create one */ if (!node) { - node = new (&_md_alloc) Cpu_session_irqs(this); + node = new (&_cpu_session._md_alloc) Cpu_session_irqs(&_cpu_session); _irq_tree.insert(node); } @@ -96,22 +91,15 @@ Genode::Native_capability Genode::Cpu_session_component::alloc_irq() } -void Genode::Cpu_session_component::single_step(Genode::Thread_capability thread_cap, bool enable) +Genode::Native_cpu_component::Native_cpu_component(Cpu_session_component &cpu_session, char const *) +: + _cpu_session(cpu_session), _thread_ep(*_cpu_session._thread_ep) { - using namespace Genode; - - auto lambda = [&] (Cpu_thread_component *thread) { - if (!thread) return; - - Fiasco::l4_cap_idx_t tid = thread->platform_thread()->thread().local.dst(); - - enum { THREAD_SINGLE_STEP = 0x40000 }; - int flags = enable ? THREAD_SINGLE_STEP : 0; - - Fiasco::l4_thread_ex_regs(tid, ~0UL, ~0UL, flags); - }; - _thread_ep->apply(thread_cap, lambda); + _thread_ep.manage(this); } -Genode::Cpu_session::Quota Genode::Cpu_session_component::quota() { return Quota(); } +Genode::Native_cpu_component::~Native_cpu_component() +{ + _thread_ep.dissolve(this); +} diff --git a/repos/base-foc/src/core/platform_thread.cc b/repos/base-foc/src/core/platform_thread.cc index 8f7b93b3d..a023386f9 100644 --- a/repos/base-foc/src/core/platform_thread.cc +++ b/repos/base-foc/src/core/platform_thread.cc @@ -116,6 +116,17 @@ void Platform_thread::pause() } +void Platform_thread::single_step(bool enabled) +{ + Fiasco::l4_cap_idx_t const tid = thread().local.dst(); + + enum { THREAD_SINGLE_STEP = 0x40000 }; + int const flags = enabled ? THREAD_SINGLE_STEP : 0; + + Fiasco::l4_thread_ex_regs(tid, ~0UL, ~0UL, flags); +} + + void Platform_thread::resume() { if (!_pager_obj) @@ -268,7 +279,7 @@ Weak_ptr Platform_thread::address_space() } -Platform_thread::Platform_thread(const char *name, unsigned prio, addr_t) +Platform_thread::Platform_thread(size_t, const char *name, unsigned prio, addr_t) : _state(DEAD), _core_thread(false), _thread(true), diff --git a/repos/base-foc/src/core/target.inc b/repos/base-foc/src/core/target.inc index 0462f117c..a082af024 100644 --- a/repos/base-foc/src/core/target.inc +++ b/repos/base-foc/src/core/target.inc @@ -9,7 +9,7 @@ SRC_CC += stack_area.cc \ core_printf.cc \ core_rpc_cap_alloc.cc \ cpu_session_component.cc \ - cpu_session_extension.cc \ + cpu_session_support.cc \ dataspace_component.cc \ dump_alloc.cc \ io_mem_session_component.cc \ @@ -24,6 +24,7 @@ SRC_CC += stack_area.cc \ pd_assign_pci.cc \ pd_upgrade_ram_quota.cc \ native_pd_component.cc \ + native_cpu_component.cc \ rpc_cap_factory.cc \ platform.cc \ platform_pd.cc \ @@ -47,6 +48,7 @@ include $(GEN_CORE_DIR)/version.inc vpath stack_area.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath dataspace_component.cc $(GEN_CORE_DIR) vpath dump_alloc.cc $(GEN_CORE_DIR) vpath io_mem_session_component.cc $(GEN_CORE_DIR) diff --git a/repos/base-hw/src/core/include/platform_thread.h b/repos/base-hw/src/core/include/platform_thread.h index 657e60a1a..875c303e1 100644 --- a/repos/base-hw/src/core/include/platform_thread.h +++ b/repos/base-hw/src/core/include/platform_thread.h @@ -134,6 +134,11 @@ namespace Genode { */ void pause() { Kernel::pause_thread(kernel_object()); } + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ diff --git a/repos/base-linux/src/base/env/platform_env.cc b/repos/base-linux/src/base/env/platform_env.cc index 1eef3716e..8a9aeadc4 100644 --- a/repos/base-linux/src/base/env/platform_env.cc +++ b/repos/base-linux/src/base/env/platform_env.cc @@ -169,8 +169,8 @@ Platform_env::Platform_env() env_stack_area_rm_session = &_stack_area; /* register TID and PID of the main thread at core */ - cpu_session()->thread_id(parent()->main_thread_cap(), - lx_getpid(), lx_gettid()); + Linux_native_cpu_client native_cpu(cpu_session()->native_cpu()); + native_cpu.thread_id(parent()->main_thread_cap(), lx_getpid(), lx_gettid()); } @@ -182,25 +182,14 @@ namespace Genode { Native_connection_state server_socket_pair() { - /* - * Obtain access to Linux-specific extension of the CPU session - * interface. We can cast to the specific type because the Linux - * version of 'Platform_env' is hosting a 'Linux_cpu_client' object. - */ - Linux_cpu_session *cpu = dynamic_cast(env()->cpu_session()); - - if (!cpu) { - PERR("could not obtain Linux extension to CPU session interface"); - struct Could_not_access_linux_cpu_session { }; - throw Could_not_access_linux_cpu_session(); - } + Linux_native_cpu_client native_cpu(env()->cpu_session()->native_cpu()); Native_connection_state ncs; Thread_base *thread = Thread_base::myself(); if (thread) { - ncs.server_sd = cpu->server_sd(thread->cap()).dst().socket; - ncs.client_sd = cpu->client_sd(thread->cap()).dst().socket; + ncs.server_sd = native_cpu.server_sd(thread->cap()).dst().socket; + ncs.client_sd = native_cpu.client_sd(thread->cap()).dst().socket; } return ncs; } diff --git a/repos/base-linux/src/base/ipc/ipc.cc b/repos/base-linux/src/base/ipc/ipc.cc index 94797908f..69ea15707 100644 --- a/repos/base-linux/src/base/ipc/ipc.cc +++ b/repos/base-linux/src/base/ipc/ipc.cc @@ -17,7 +17,7 @@ #include #include #include -#include +#include /* base-internal includes */ #include diff --git a/repos/base-linux/src/base/thread/thread_linux.cc b/repos/base-linux/src/base/thread/thread_linux.cc index d2184f2ab..96bcd8194 100644 --- a/repos/base-linux/src/base/thread/thread_linux.cc +++ b/repos/base-linux/src/base/thread/thread_linux.cc @@ -17,7 +17,7 @@ #include #include #include -#include +#include /* base-internal includes */ #include @@ -60,9 +60,8 @@ void Thread_base::_thread_start() Thread_base * const thread = Thread_base::myself(); /* inform core about the new thread and process ID of the new thread */ - Linux_cpu_session *cpu = dynamic_cast(thread->_cpu_session); - if (cpu) - cpu->thread_id(thread->cap(), thread->native_thread().pid, thread->native_thread().tid); + Linux_native_cpu_client native_cpu(thread->_cpu_session->native_cpu()); + native_cpu.thread_id(thread->cap(), thread->native_thread().pid, thread->native_thread().tid); /* wakeup 'start' function */ startup_lock().unlock(); diff --git a/repos/base-linux/src/core/cpu_session_extension.cc b/repos/base-linux/src/core/cpu_session_extension.cc deleted file mode 100644 index ac71a1bc1..000000000 --- a/repos/base-linux/src/core/cpu_session_extension.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* - * \brief Linux-specific extension of the CPU session implementation - * \author Norman Feske - * \date 2012-08-09 - */ - -/* core includes */ -#include - -/* Linux includes */ -#include - -using namespace Genode; - - -void Cpu_session_component::thread_id(Thread_capability thread_cap, int pid, int tid) -{ - _thread_ep->apply(thread_cap, [&] (Cpu_thread_component *thread) { - if (thread) thread->platform_thread()->thread_id(pid, tid); }); -} - - -Untyped_capability Cpu_session_component::server_sd(Thread_capability thread_cap) -{ - auto lambda = [] (Cpu_thread_component *thread) { - if (!thread) return Untyped_capability(); - - enum { DUMMY_LOCAL_NAME = 0 }; - typedef Native_capability::Dst Dst; - return Untyped_capability(Dst(thread->platform_thread()->server_sd()), - DUMMY_LOCAL_NAME); - }; - return _thread_ep->apply(thread_cap, lambda); -} - - -Untyped_capability Cpu_session_component::client_sd(Thread_capability thread_cap) -{ - auto lambda = [] (Cpu_thread_component *thread) { - if (!thread) return Untyped_capability(); - - enum { DUMMY_LOCAL_NAME = 0 }; - typedef Native_capability::Dst Dst; - return Untyped_capability(Dst(thread->platform_thread()->client_sd()), - DUMMY_LOCAL_NAME); - }; - return _thread_ep->apply(thread_cap, lambda); -} diff --git a/repos/base-linux/src/core/cpu_session_support.cc b/repos/base-linux/src/core/cpu_session_support.cc deleted file mode 100644 index 38bc99bd6..000000000 --- a/repos/base-linux/src/core/cpu_session_support.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * \brief Platform-specific parts of cores CPU-service - * \author Martin Stein - * \date 2012-04-17 - */ - -/* - * Copyright (C) 2009-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include - -/* Core includes */ -#include - -using namespace Genode; - - -Ram_dataspace_capability Cpu_session_component::utcb(Thread_capability thread_cap) -{ - PERR("%s: Not implemented", __PRETTY_FUNCTION__); - return Ram_dataspace_capability(); -} - - -Cpu_session::Quota Cpu_session_component::quota() { return Quota(); } diff --git a/repos/base-linux/src/core/include/cpu_session_component.h b/repos/base-linux/src/core/include/cpu_session_component.h deleted file mode 100644 index 99854c9fd..000000000 --- a/repos/base-linux/src/core/include/cpu_session_component.h +++ /dev/null @@ -1,249 +0,0 @@ -/* - * \brief Core-specific instance of the CPU session/thread interfaces - * \author Christian Helmuth - * \author Norman Feske - * \date 2006-07-17 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ -#define _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ - -/* Genode includes */ -#include -#include -#include -#include -#include - -/* core includes */ -#include -#include -#include -#include -#include - -namespace Genode { - - /** - * RPC interface of CPU thread - * - * We make 'Cpu_thread' a RPC object only to be able to lookup CPU threads - * from thread capabilities supplied as arguments to CPU-session functions. - * A CPU thread does not provide an actual RPC interface. - */ - struct Cpu_thread - { - GENODE_RPC_INTERFACE(); - }; - - - class Cpu_thread_component : public Rpc_object, - public List::Element, - public Trace::Source::Info_accessor - { - public: - - typedef Trace::Session_label Session_label; - typedef Trace::Thread_name Thread_name; - - private: - - Session_label const _session_label; - Thread_name const _name; - Platform_thread _platform_thread; - bool _bound; /* pd binding flag */ - Signal_context_capability _sigh; /* exception handler */ - unsigned const _trace_control_index; - Trace::Source _trace_source; - - public: - - Cpu_thread_component(size_t const weight, - size_t const quota, - Session_label const &label, - Thread_name const &name, - unsigned priority, addr_t utcb, - Signal_context_capability sigh, - unsigned trace_control_index, - Trace::Control &trace_control) - : - _session_label(label), _name(name), - _platform_thread(name.string(), priority, utcb), _bound(false), - _sigh(sigh), _trace_control_index(trace_control_index), - _trace_source(*this, trace_control) - { - update_exception_sigh(); - } - - - /******************************************** - ** Trace::Source::Info_accessor interface ** - ********************************************/ - - Trace::Source::Info trace_source_info() const - { - return { _session_label, _name, - _platform_thread.execution_time(), - _platform_thread.affinity() }; - } - - - /************************ - ** Accessor functions ** - ************************/ - - Platform_thread *platform_thread() { return &_platform_thread; } - bool bound() const { return _bound; } - void bound(bool b) { _bound = b; } - Trace::Source *trace_source() { return &_trace_source; } - - size_t weight() const { return Cpu_session::DEFAULT_WEIGHT; } - - void sigh(Signal_context_capability sigh) - { - _sigh = sigh; - update_exception_sigh(); - } - - /** - * Propagate exception handler to platform thread - */ - void update_exception_sigh(); - - /** - * Return index within the CPU-session's trace control area - */ - unsigned trace_control_index() const { return _trace_control_index; } - }; - - - class Cpu_session_component : public Rpc_object - { - public: - - typedef Cpu_thread_component::Session_label Session_label; - - private: - - Session_label _label; - Rpc_entrypoint *_session_ep; - Rpc_entrypoint *_thread_ep; - Pager_entrypoint *_pager_ep; - Allocator_guard _md_alloc; /* guarded meta-data allocator */ - Cpu_thread_allocator _thread_alloc; /* meta-data allocator */ - Lock _thread_alloc_lock; /* protect allocator access */ - List _thread_list; - Lock _thread_list_lock; /* protect thread list */ - unsigned _priority; /* priority of threads - created with this - session */ - Affinity::Location _location; /* CPU affinity of this - session */ - Trace::Source_registry &_trace_sources; - Trace::Control_area _trace_control_area; - - size_t _weight; - size_t _quota; - Cpu_session_component * _ref; - List _ref_members; - Lock _ref_members_lock; - - void _incr_weight(size_t); - void _decr_weight(size_t); - size_t _weight_to_quota(size_t) const; - void _decr_quota(size_t); - void _incr_quota(size_t); - void _update_thread_quota(Cpu_thread_component *) const; - void _update_each_thread_quota(); - void _transfer_quota(Cpu_session_component *, size_t); - void _insert_ref_member(Cpu_session_component *) { } - void _unsync_remove_ref_member(Cpu_session_component *) { } - void _remove_ref_member(Cpu_session_component *) { } - void _deinit_ref_account(); - void _deinit_threads(); - - /** - * Exception handler that will be invoked unless overridden by a - * call of 'Cpu_session::exception_handler'. - */ - Signal_context_capability _default_exception_handler; - - /** - * Raw thread-killing functionality - * - * This function is called from the 'kill_thread' function and - * the destructor. Each these functions grab the list lock - * by themselves and call this function to perform the actual - * killing. - */ - void _unsynchronized_kill_thread(Thread_capability cap); - - public: - - /** - * Constructor - */ - Cpu_session_component(Rpc_entrypoint *session_ep, - Rpc_entrypoint *thread_ep, - Pager_entrypoint *pager_ep, - Allocator *md_alloc, - Trace::Source_registry &trace_sources, - const char *args, Affinity const &affinity, - size_t quota); - - /** - * Destructor - */ - ~Cpu_session_component(); - - /** - * Register quota donation at allocator guard - */ - void upgrade_ram_quota(size_t ram_quota) { _md_alloc.upgrade(ram_quota); } - - - /*************************** - ** CPU session interface ** - ***************************/ - - Thread_capability create_thread(size_t, Name const &, addr_t); - Ram_dataspace_capability utcb(Thread_capability thread); - void kill_thread(Thread_capability); - int set_pager(Thread_capability, Pager_capability); - int start(Thread_capability, addr_t, addr_t); - void pause(Thread_capability thread_cap); - void resume(Thread_capability thread_cap); - void cancel_blocking(Thread_capability); - int name(Thread_capability, char *, size_t); - Thread_state state(Thread_capability); - void state(Thread_capability, Thread_state const &); - void exception_handler(Thread_capability, Signal_context_capability); - Affinity::Space affinity_space() const; - void affinity(Thread_capability, Affinity::Location); - Dataspace_capability trace_control(); - unsigned trace_control_index(Thread_capability); - Dataspace_capability trace_buffer(Thread_capability); - Dataspace_capability trace_policy(Thread_capability); - int ref_account(Cpu_session_capability c); - int transfer_quota(Cpu_session_capability, size_t); - Quota quota() override; - - - /******************************* - ** Linux-specific extensions ** - *******************************/ - - void thread_id(Thread_capability, int, int); - Untyped_capability server_sd(Thread_capability); - Untyped_capability client_sd(Thread_capability); - }; -} - -#endif /* _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ */ diff --git a/repos/base-linux/src/core/include/native_cpu_component.h b/repos/base-linux/src/core/include/native_cpu_component.h new file mode 100644 index 000000000..0174519ca --- /dev/null +++ b/repos/base-linux/src/core/include/native_cpu_component.h @@ -0,0 +1,47 @@ +/* + * \brief Kernel-specific part of the CPU-session interface + * \author Norman Feske + * \date 2016-01-19 + * + * This definition is used on platforms with no kernel-specific PD functions + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ +#define _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ + +/* Genode includes */ +#include + +namespace Genode { + + class Cpu_session_component; + class Native_cpu_component; +} + + +class Genode::Native_cpu_component : public Rpc_object +{ + private: + + Cpu_session_component &_cpu_session; + Rpc_entrypoint &_thread_ep; + + public: + + Native_cpu_component(Cpu_session_component &, char const *); + ~Native_cpu_component(); + + void thread_id(Thread_capability, int, int) override; + Untyped_capability server_sd(Thread_capability) override; + Untyped_capability client_sd(Thread_capability) override; +}; + +#endif /* _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ */ diff --git a/repos/base-linux/src/core/include/platform_thread.h b/repos/base-linux/src/core/include/platform_thread.h index ac165a0c9..1a7d46461 100644 --- a/repos/base-linux/src/core/include/platform_thread.h +++ b/repos/base-linux/src/core/include/platform_thread.h @@ -81,7 +81,7 @@ namespace Genode { /** * Constructor */ - Platform_thread(const char *name, unsigned priority, addr_t); + Platform_thread(size_t, const char *name, unsigned priority, addr_t); ~Platform_thread(); @@ -95,6 +95,11 @@ namespace Genode { */ void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ diff --git a/repos/base-linux/src/core/native_cpu_component.cc b/repos/base-linux/src/core/native_cpu_component.cc new file mode 100644 index 000000000..dc0b7b416 --- /dev/null +++ b/repos/base-linux/src/core/native_cpu_component.cc @@ -0,0 +1,68 @@ +/* + * \brief Core implementation of the CPU session interface + * \author Norman Feske + * \date 2012-08-15 + */ + +/* + * Copyright (C) 2012-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* core-local includes */ +#include +#include + +using namespace Genode; + + +void Native_cpu_component::thread_id(Thread_capability thread_cap, int pid, int tid) +{ + _thread_ep.apply(thread_cap, [&] (Cpu_thread_component *thread) { + if (thread) thread->platform_thread()->thread_id(pid, tid); }); +} + + +Untyped_capability Native_cpu_component::server_sd(Thread_capability thread_cap) +{ + auto lambda = [] (Cpu_thread_component *thread) { + if (!thread) return Untyped_capability(); + + enum { DUMMY_LOCAL_NAME = 0 }; + typedef Native_capability::Dst Dst; + return Untyped_capability(Dst(thread->platform_thread()->server_sd()), + DUMMY_LOCAL_NAME); + }; + return _thread_ep.apply(thread_cap, lambda); +} + + +Untyped_capability Native_cpu_component::client_sd(Thread_capability thread_cap) +{ + auto lambda = [] (Cpu_thread_component *thread) { + if (!thread) return Untyped_capability(); + + enum { DUMMY_LOCAL_NAME = 0 }; + typedef Native_capability::Dst Dst; + return Untyped_capability(Dst(thread->platform_thread()->client_sd()), + DUMMY_LOCAL_NAME); + }; + return _thread_ep.apply(thread_cap, lambda); +} + + +Native_cpu_component::Native_cpu_component(Cpu_session_component &cpu_session, char const *) +: + _cpu_session(cpu_session), _thread_ep(*_cpu_session._thread_ep) +{ + _thread_ep.manage(this); +} + + +Native_cpu_component::~Native_cpu_component() +{ + _thread_ep.dissolve(this); +} + diff --git a/repos/base-linux/src/core/platform_thread.cc b/repos/base-linux/src/core/platform_thread.cc index 42767873b..060ca43df 100644 --- a/repos/base-linux/src/core/platform_thread.cc +++ b/repos/base-linux/src/core/platform_thread.cc @@ -74,7 +74,7 @@ Platform_thread::Registry *Platform_thread::_registry() ** Platform_thread ** *********************/ -Platform_thread::Platform_thread(const char *name, unsigned, addr_t) +Platform_thread::Platform_thread(size_t, const char *name, unsigned, addr_t) : _tid(-1), _pid(-1) { strncpy(_name, name, min(sizeof(_name), strlen(name) + 1)); diff --git a/repos/base-linux/src/core/target.mk b/repos/base-linux/src/core/target.mk index 64adaff21..bdc8b4fcf 100644 --- a/repos/base-linux/src/core/target.mk +++ b/repos/base-linux/src/core/target.mk @@ -12,12 +12,12 @@ SRC_CC = main.cc \ ram_session_support.cc \ rom_session_component.cc \ cpu_session_component.cc \ - cpu_session_extension.cc \ cpu_session_support.cc \ pd_session_component.cc \ pd_upgrade_ram_quota.cc \ dataspace_component.cc \ native_pd_component.cc \ + native_cpu_component.cc \ rpc_cap_factory.cc \ core_rpc_cap_alloc.cc \ io_mem_session_component.cc \ @@ -41,6 +41,7 @@ include $(GEN_CORE_DIR)/version.inc vpath main.cc $(GEN_CORE_DIR) vpath ram_session_component.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath pd_upgrade_ram_quota.cc $(GEN_CORE_DIR) vpath rpc_cap_factory.cc $(GEN_CORE_DIR) vpath platform_services.cc $(GEN_CORE_DIR) diff --git a/repos/base-linux/src/include/base/internal/platform_env.h b/repos/base-linux/src/include/base/internal/platform_env.h index bc3abb2cf..7b3892fc6 100644 --- a/repos/base-linux/src/include/base/internal/platform_env.h +++ b/repos/base-linux/src/include/base/internal/platform_env.h @@ -24,7 +24,7 @@ /* Genode includes */ #include #include -#include +#include /* base-internal includes */ #include @@ -39,15 +39,15 @@ namespace Genode { struct Genode::Expanding_cpu_session_client : - Upgradeable_client + Upgradeable_client { - Expanding_cpu_session_client(Genode::Capability cap) - : Upgradeable_client(cap) { } + Expanding_cpu_session_client(Genode::Capability cap) + : Upgradeable_client(cap) { } Thread_capability create_thread(size_t weight, Name const &name, addr_t utcb) { return retry( - [&] () { return Linux_cpu_session_client::create_thread(weight, name, utcb); }, + [&] () { return Cpu_session_client::create_thread(weight, name, utcb); }, [&] () { upgrade_ram(8*1024); }); } }; @@ -334,7 +334,7 @@ namespace Genode { _ram_session_cap(ram_cap), _ram_session_client(_ram_session_cap), _cpu_session_cap(cpu_cap), - _cpu_session_client(static_cap_cast(cpu_cap)), + _cpu_session_client(cpu_cap), _rm_session_mmap(false), _pd_session_cap(pd_cap), _pd_session_client(_pd_session_cap) @@ -348,7 +348,7 @@ namespace Genode { Ram_session *ram_session() override { return &_ram_session_client; } Ram_session_capability ram_session_cap() override { return _ram_session_cap; } Rm_session *rm_session() override { return &_rm_session_mmap; } - Linux_cpu_session *cpu_session() override { return &_cpu_session_client; } + Cpu_session *cpu_session() override { return &_cpu_session_client; } Cpu_session_capability cpu_session_cap() override { return _cpu_session_cap; } Pd_session *pd_session() override { return &_pd_session_client; } Pd_session_capability pd_session_cap() override { return _pd_session_cap; } diff --git a/repos/base-linux/src/include/linux_cpu_session/client.h b/repos/base-linux/src/include/linux_cpu_session/client.h deleted file mode 100644 index df153cd83..000000000 --- a/repos/base-linux/src/include/linux_cpu_session/client.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * \brief Client-side CPU session interface - * \author Norman Feske - * \date 2012-08-09 - */ - -/* - * Copyright (C) 2006-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _INCLUDE__LINUX_CPU_SESSION__CLIENT_H_ -#define _INCLUDE__LINUX_CPU_SESSION__CLIENT_H_ - -#include -#include - -namespace Genode { - - struct Linux_cpu_session_client : Rpc_client - { - explicit Linux_cpu_session_client(Capability session) - : Rpc_client(session) { } - - Thread_capability create_thread(size_t weight, Name const &name, addr_t utcb = 0) { - return call(weight, name, utcb); } - - Ram_dataspace_capability utcb(Thread_capability thread) { - return call(thread); } - - void kill_thread(Thread_capability thread) { - call(thread); } - - int set_pager(Thread_capability thread, Pager_capability pager) { - return call(thread, pager); } - - int start(Thread_capability thread, addr_t ip, addr_t sp) { - return call(thread, ip, sp); } - - void pause(Thread_capability thread) { - call(thread); } - - void resume(Thread_capability thread) { - call(thread); } - - void cancel_blocking(Thread_capability thread) { - call(thread); } - - Thread_state state(Thread_capability thread) { - return call(thread); } - - void state(Thread_capability thread, Thread_state const &state) { - call(thread, state); } - - void exception_handler(Thread_capability thread, Signal_context_capability handler) { - call(thread, handler); } - - void single_step(Thread_capability thread, bool enable) { - call(thread, enable); } - - Affinity::Space affinity_space() const { - return call(); } - - void affinity(Thread_capability thread, Affinity::Location location) { - call(thread, location); } - - Dataspace_capability trace_control() { - return call(); } - - unsigned trace_control_index(Thread_capability thread) { - return call(thread); } - - Dataspace_capability trace_buffer(Thread_capability thread) { - return call(thread); } - - Dataspace_capability trace_policy(Thread_capability thread) { - return call(thread); } - - int ref_account(Cpu_session_capability session) { - return call(session); } - - int transfer_quota(Cpu_session_capability session, size_t amount) { - return call(session, amount); } - - Quota quota() override { return call(); } - - /***************************** - * Linux-specific extension ** - *****************************/ - - void thread_id(Thread_capability thread, int pid, int tid) { - call(thread, pid, tid); } - - Untyped_capability server_sd(Thread_capability thread) { - return call(thread); } - - Untyped_capability client_sd(Thread_capability thread) { - return call(thread); } - }; -} - -#endif /* _INCLUDE__LINUX_CPU_SESSION__CLIENT_H_ */ diff --git a/repos/base-linux/src/include/linux_cpu_session/linux_cpu_session.h b/repos/base-linux/src/include/linux_cpu_session/linux_cpu_session.h deleted file mode 100644 index 8fc46c299..000000000 --- a/repos/base-linux/src/include/linux_cpu_session/linux_cpu_session.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * \brief Linux-specific extension of the CPU session interface - * \author Norman Feske - * \date 2012-08-09 - */ - -/* - * Copyright (C) 2012-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -#ifndef _INCLUDE__LINUX_CPU_SESSION__LINUX_CPU_SESSION_H_ -#define _INCLUDE__LINUX_CPU_SESSION__LINUX_CPU_SESSION_H_ - -#include - -namespace Genode { - - struct Linux_cpu_session : Cpu_session - { - virtual ~Linux_cpu_session() { } - - /** - * Register Linux PID and TID of the specified thread - */ - virtual void thread_id(Thread_capability, int pid, int tid) = 0; - - /* - * If a thread plays the role of an entrypoint, core creates a bound - * socket pair for the thread and passes both makes the socket - * descriptors of both ends available to the owner of the thread's - * CPU session via the 'server_sd' and 'client_sd' function. - */ - - /** - * Request server-side socket descriptor - * - * The socket descriptor returned by this function is meant to be used - * exclusively by the server for receiving incoming requests. It should - * never leave the server process. - */ - virtual Untyped_capability server_sd(Thread_capability thread) = 0; - - /** - * Request client-side socket descriptor - * - * The returned socket descriptor enables a client to send messages to - * the thread. It is already connected to the 'server_sd' descriptor. - * In contrast to 'server_sd', the 'client_sd' is expected to be passed - * around via capability delegations. - */ - virtual Untyped_capability client_sd(Thread_capability thread) = 0; - - - /********************* - ** RPC declaration ** - *********************/ - - GENODE_RPC(Rpc_thread_id, void, thread_id, Thread_capability, int, int); - GENODE_RPC(Rpc_server_sd, Untyped_capability, server_sd, Thread_capability); - GENODE_RPC(Rpc_client_sd, Untyped_capability, client_sd, Thread_capability); - - GENODE_RPC_INTERFACE_INHERIT(Cpu_session, - Rpc_thread_id, Rpc_server_sd, Rpc_client_sd); - }; -} - -#endif /* _INCLUDE__LINUX_CPU_SESSION__LINUX_CPU_SESSION_H_ */ diff --git a/repos/base-linux/src/include/linux_native_cpu/client.h b/repos/base-linux/src/include/linux_native_cpu/client.h new file mode 100644 index 000000000..2c2891c2c --- /dev/null +++ b/repos/base-linux/src/include/linux_native_cpu/client.h @@ -0,0 +1,37 @@ +/* + * \brief Client-side of the Linux-specific CPU session interface + * \author Norman Feske + * \date 2012-08-15 + */ + +/* + * Copyright (C) 2012-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__LINUX_NATIVE_CPU__CLIENT_H_ +#define _INCLUDE__LINUX_NATIVE_CPU__CLIENT_H_ + +#include +#include + +namespace Genode { struct Linux_native_cpu_client; } + +struct Genode::Linux_native_cpu_client : Rpc_client +{ + explicit Linux_native_cpu_client(Capability cap) + : Rpc_client(static_cap_cast(cap)) { } + + void thread_id(Thread_capability thread, int pid, int tid) { + call(thread, pid, tid); } + + Untyped_capability server_sd(Thread_capability thread) { + return call(thread); } + + Untyped_capability client_sd(Thread_capability thread) { + return call(thread); } +}; + +#endif /* _INCLUDE__LINUX_NATIVE_CPU__CLIENT_H_ */ diff --git a/repos/base-linux/src/include/linux_native_cpu/linux_native_cpu.h b/repos/base-linux/src/include/linux_native_cpu/linux_native_cpu.h new file mode 100644 index 000000000..644f0ca4e --- /dev/null +++ b/repos/base-linux/src/include/linux_native_cpu/linux_native_cpu.h @@ -0,0 +1,68 @@ +/* + * \brief Linux-specific extension of the CPU session interface + * \author Norman Feske + * \date 2012-08-15 + */ + +/* + * Copyright (C) 2012-2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__LINUX_NATIVE_CPU__LINUX_NATIVE_CPU_H_ +#define _INCLUDE__LINUX_NATIVE_CPU__LINUX_NATIVE_CPU_H_ + +#include +#include + +namespace Genode { struct Linux_native_cpu; } + + +struct Genode::Linux_native_cpu : Cpu_session::Native_cpu +{ + /** + * Register Linux PID and TID of the specified thread + */ + virtual void thread_id(Thread_capability, int pid, int tid) = 0; + + /* + * If a thread plays the role of an entrypoint, core creates a bound + * socket pair for the thread and passes both makes the socket + * descriptors of both ends available to the owner of the thread's + * CPU session via the 'server_sd' and 'client_sd' function. + */ + + /** + * Request server-side socket descriptor + * + * The socket descriptor returned by this function is meant to be used + * exclusively by the server for receiving incoming requests. It should + * never leave the server process. + */ + virtual Untyped_capability server_sd(Thread_capability thread) = 0; + + /** + * Request client-side socket descriptor + * + * The returned socket descriptor enables a client to send messages to + * the thread. It is already connected to the 'server_sd' descriptor. + * In contrast to 'server_sd', the 'client_sd' is expected to be passed + * around via capability delegations. + */ + virtual Untyped_capability client_sd(Thread_capability thread) = 0; + + + /********************* + ** RPC declaration ** + *********************/ + + GENODE_RPC(Rpc_thread_id, void, thread_id, Thread_capability, int, int); + GENODE_RPC(Rpc_server_sd, Untyped_capability, server_sd, Thread_capability); + GENODE_RPC(Rpc_client_sd, Untyped_capability, client_sd, Thread_capability); + + GENODE_RPC_INTERFACE(Rpc_thread_id, Rpc_server_sd, Rpc_client_sd); +}; + +#endif /* _INCLUDE__LINUX_NATIVE_CPU__LINUX_NATIVE_CPU_H_ */ diff --git a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc index 482265b2d..90e5c5204 100644 --- a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc +++ b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc @@ -15,7 +15,7 @@ #include #include #include -#include +#include /* base-internal includes */ #include @@ -336,23 +336,6 @@ namespace Genode { } -/** - * Return Linux-specific extension of the Env::CPU session interface - */ -Linux_cpu_session *cpu_session(Cpu_session * cpu_session) -{ - Linux_cpu_session *cpu = dynamic_cast(cpu_session); - - if (!cpu) { - PERR("could not obtain Linux extension to CPU session interface"); - struct Could_not_access_linux_cpu_session { }; - throw Could_not_access_linux_cpu_session(); - } - - return cpu; -} - - static void adopt_thread(Native_thread::Meta_data *meta_data) { lx_sigaltstack(signal_stack, sizeof(signal_stack)); @@ -487,10 +470,10 @@ Thread_base::Thread_base(size_t weight, const char *name, size_t stack_size, native_thread().meta_data->wait_for_construction(); - Linux_cpu_session *cpu = cpu_session(_cpu_session); + _thread_cap = _cpu_session->create_thread(weight, name); - _thread_cap = cpu->create_thread(weight, name); - cpu->thread_id(_thread_cap, native_thread().pid, native_thread().tid); + Linux_native_cpu_client native_cpu(_cpu_session->native_cpu()); + native_cpu.thread_id(_thread_cap, native_thread().pid, native_thread().tid); } @@ -526,5 +509,5 @@ Thread_base::~Thread_base() _native_thread = nullptr; /* inform core about the killed thread */ - cpu_session(_cpu_session)->kill_thread(_thread_cap); + _cpu_session->kill_thread(_thread_cap); } diff --git a/repos/base-nova/include/cpu_session/client.h b/repos/base-nova/include/cpu_session/client.h index 64fae6202..1faa05628 100644 --- a/repos/base-nova/include/cpu_session/client.h +++ b/repos/base-nova/include/cpu_session/client.h @@ -102,6 +102,8 @@ namespace Genode { Quota quota() override { return call(); } + Capability native_cpu() override { return call(); } + private: Native_capability pause_sync(Thread_capability) { diff --git a/repos/base-nova/src/core/cpu_session_extension.cc b/repos/base-nova/src/core/cpu_session_extension.cc index 1fe4ffc93..68269d2c5 100644 --- a/repos/base-nova/src/core/cpu_session_extension.cc +++ b/repos/base-nova/src/core/cpu_session_extension.cc @@ -42,10 +42,7 @@ Cpu_session_component::single_step_sync(Thread_capability thread_cap, bool enabl if (!thread || !thread->platform_thread()) return Native_capability(); - return thread->platform_thread()->single_step(enable); + return thread->platform_thread()->single_step_sync(enable); }; return _thread_ep->apply(thread_cap, lambda); } - - -void Cpu_session_component::single_step(Thread_capability, bool) { return; } diff --git a/repos/base-nova/src/core/cpu_session_support.cc b/repos/base-nova/src/core/cpu_session_support.cc deleted file mode 100644 index 43809899b..000000000 --- a/repos/base-nova/src/core/cpu_session_support.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * \brief Platform-specific parts of cores CPU-service - * \author Martin Stein - * \date 2012-04-17 - */ - -/* - * Copyright (C) 2009-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include - -/* core includes */ -#include - -using namespace Genode; - - -Ram_dataspace_capability Cpu_session_component::utcb(Thread_capability thread_cap) -{ - PERR("%s: Not implemented", __PRETTY_FUNCTION__); - return Ram_dataspace_capability(); -} - - -Cpu_session::Quota Cpu_session_component::quota() { return Quota(); } diff --git a/repos/base-nova/src/core/include/cpu_session_component.h b/repos/base-nova/src/core/include/cpu_session_component.h index 47dae9a80..709b7b357 100644 --- a/repos/base-nova/src/core/include/cpu_session_component.h +++ b/repos/base-nova/src/core/include/cpu_session_component.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace Genode { @@ -166,6 +167,10 @@ namespace Genode { List _ref_members; Lock _ref_members_lock; + Native_cpu_component _native_cpu; + + friend class Native_cpu_component; + void _incr_weight(size_t); void _decr_weight(size_t); size_t _weight_to_quota(size_t) const; @@ -246,6 +251,7 @@ namespace Genode { int ref_account(Cpu_session_capability c); int transfer_quota(Cpu_session_capability, size_t); Quota quota() override; + Capability native_cpu() { return Capability(); } /****************************** diff --git a/repos/base-nova/src/core/include/platform_thread.h b/repos/base-nova/src/core/include/platform_thread.h index 9674b37a9..820d7c869 100644 --- a/repos/base-nova/src/core/include/platform_thread.h +++ b/repos/base-nova/src/core/include/platform_thread.h @@ -93,6 +93,11 @@ namespace Genode { */ Native_capability pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ @@ -167,7 +172,7 @@ namespace Genode { if (main_thread) _features |= MAIN_THREAD; } - Native_capability single_step(bool on); + Native_capability single_step_sync(bool on); /** * Set CPU quota of the thread to 'quota' diff --git a/repos/base-nova/src/core/platform_thread.cc b/repos/base-nova/src/core/platform_thread.cc index 064eb6c12..4ff9746ad 100644 --- a/repos/base-nova/src/core/platform_thread.cc +++ b/repos/base-nova/src/core/platform_thread.cc @@ -303,7 +303,7 @@ void Platform_thread::cancel_blocking() } -Native_capability Platform_thread::single_step(bool on) +Native_capability Platform_thread::single_step_sync(bool on) { if (!_pager) return Native_capability(); diff --git a/repos/base-nova/src/core/target.inc b/repos/base-nova/src/core/target.inc index 6d8c0ee31..8d06bb0ec 100644 --- a/repos/base-nova/src/core/target.inc +++ b/repos/base-nova/src/core/target.inc @@ -50,6 +50,7 @@ vpath main.cc $(GEN_CORE_DIR) vpath ram_session_component.cc $(GEN_CORE_DIR) vpath rom_session_component.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath pd_session_component.cc $(GEN_CORE_DIR) vpath pd_upgrade_ram_quota.cc $(GEN_CORE_DIR) vpath rm_session_component.cc $(GEN_CORE_DIR) diff --git a/repos/base-okl4/src/core/cpu_session_support.cc b/repos/base-okl4/src/core/cpu_session_support.cc deleted file mode 100644 index 38bc99bd6..000000000 --- a/repos/base-okl4/src/core/cpu_session_support.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * \brief Platform-specific parts of cores CPU-service - * \author Martin Stein - * \date 2012-04-17 - */ - -/* - * Copyright (C) 2009-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include - -/* Core includes */ -#include - -using namespace Genode; - - -Ram_dataspace_capability Cpu_session_component::utcb(Thread_capability thread_cap) -{ - PERR("%s: Not implemented", __PRETTY_FUNCTION__); - return Ram_dataspace_capability(); -} - - -Cpu_session::Quota Cpu_session_component::quota() { return Quota(); } diff --git a/repos/base-okl4/src/core/include/platform_thread.h b/repos/base-okl4/src/core/include/platform_thread.h index 1e930820b..4b1ff0de9 100644 --- a/repos/base-okl4/src/core/include/platform_thread.h +++ b/repos/base-okl4/src/core/include/platform_thread.h @@ -74,6 +74,11 @@ namespace Genode { */ void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ diff --git a/repos/base-okl4/src/core/target.inc b/repos/base-okl4/src/core/target.inc index e18197cc2..a5f40be42 100644 --- a/repos/base-okl4/src/core/target.inc +++ b/repos/base-okl4/src/core/target.inc @@ -46,6 +46,7 @@ vpath main.cc $(GEN_CORE_DIR) vpath ram_session_component.cc $(GEN_CORE_DIR) vpath rom_session_component.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath pd_session_component.cc $(GEN_CORE_DIR) vpath pd_upgrade_ram_quota.cc $(GEN_CORE_DIR) vpath pd_assign_pci.cc $(GEN_CORE_DIR) diff --git a/repos/base-pistachio/src/core/include/platform_thread.h b/repos/base-pistachio/src/core/include/platform_thread.h index a47fc9fd9..a7e622d99 100644 --- a/repos/base-pistachio/src/core/include/platform_thread.h +++ b/repos/base-pistachio/src/core/include/platform_thread.h @@ -90,6 +90,11 @@ namespace Genode { */ void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ diff --git a/repos/base-pistachio/src/core/target.inc b/repos/base-pistachio/src/core/target.inc index aae5c7d4d..69fd7d9f6 100644 --- a/repos/base-pistachio/src/core/target.inc +++ b/repos/base-pistachio/src/core/target.inc @@ -46,6 +46,7 @@ vpath main.cc $(GEN_CORE_DIR) vpath ram_session_component.cc $(GEN_CORE_DIR) vpath rom_session_component.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath pd_session_component.cc $(GEN_CORE_DIR) vpath rpc_cap_factory.cc $(GEN_CORE_DIR) vpath pd_assign_pci.cc $(GEN_CORE_DIR) diff --git a/repos/base-sel4/lib/mk/core.mk b/repos/base-sel4/lib/mk/core.mk index f1f123a5b..004b095e3 100644 --- a/repos/base-sel4/lib/mk/core.mk +++ b/repos/base-sel4/lib/mk/core.mk @@ -46,6 +46,7 @@ vpath main.cc $(GEN_CORE_DIR) vpath ram_session_component.cc $(GEN_CORE_DIR) vpath rom_session_component.cc $(GEN_CORE_DIR) vpath cpu_session_component.cc $(GEN_CORE_DIR) +vpath cpu_session_support.cc $(GEN_CORE_DIR) vpath pd_session_component.cc $(GEN_CORE_DIR) vpath pd_assign_pci.cc $(GEN_CORE_DIR) vpath pd_upgrade_ram_quota.cc $(GEN_CORE_DIR) diff --git a/repos/base-sel4/src/core/cpu_session_support.cc b/repos/base-sel4/src/core/cpu_session_support.cc deleted file mode 100644 index 9a7f732e2..000000000 --- a/repos/base-sel4/src/core/cpu_session_support.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * \brief Platform-specific parts of cores CPU-service - * \author Martin Stein - * \date 2012-04-17 - */ - -/* - * Copyright (C) 2009-2013 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU General Public License version 2. - */ - -/* Genode includes */ -#include - -/* Core includes */ -#include - -using namespace Genode; - - -Ram_dataspace_capability Cpu_session_component::utcb(Thread_capability) -{ - PDBG("not implemented"); - return Ram_dataspace_capability(); -} - - -Cpu_session::Quota Cpu_session_component::quota() { return Quota(); } diff --git a/repos/base-sel4/src/core/include/platform_thread.h b/repos/base-sel4/src/core/include/platform_thread.h index 8b2cced22..ee62c294e 100644 --- a/repos/base-sel4/src/core/include/platform_thread.h +++ b/repos/base-sel4/src/core/include/platform_thread.h @@ -97,6 +97,11 @@ class Genode::Platform_thread : public List::Element */ void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } + /** * Resume this thread */ diff --git a/repos/base/include/cpu_session/client.h b/repos/base/include/cpu_session/client.h index 9331e201c..8f6e1a64b 100644 --- a/repos/base/include/cpu_session/client.h +++ b/repos/base/include/cpu_session/client.h @@ -87,6 +87,8 @@ struct Genode::Cpu_session_client : Rpc_client return call(session, amount); } Quota quota() override { return call(); } + + Capability native_cpu() override { return call(); } }; #endif /* _INCLUDE__CPU_SESSION__CLIENT_H_ */ diff --git a/repos/base/include/cpu_session/cpu_session.h b/repos/base/include/cpu_session/cpu_session.h index 15496e0f3..d799acaf9 100644 --- a/repos/base/include/cpu_session/cpu_session.h +++ b/repos/base/include/cpu_session/cpu_session.h @@ -299,6 +299,22 @@ struct Genode::Cpu_session : Session static size_t quota_lim_downscale(size_t const value, size_t const limit) { return ((T)value * limit) >> Cpu_session::QUOTA_LIMIT_LOG2; } + + /***************************************** + ** Access to kernel-specific interface ** + *****************************************/ + + /** + * Common base class of kernel-specific CPU interfaces + */ + struct Native_cpu { }; + + /** + * Return capability to kernel-specific CPU operations + */ + virtual Capability native_cpu() = 0; + + /********************* ** RPC declaration ** *********************/ @@ -331,6 +347,7 @@ struct Genode::Cpu_session : Session GENODE_RPC(Rpc_ref_account, int, ref_account, Cpu_session_capability); GENODE_RPC(Rpc_transfer_quota, int, transfer_quota, Cpu_session_capability, size_t); GENODE_RPC(Rpc_quota, Quota, quota); + GENODE_RPC(Rpc_native_cpu, Capability, native_cpu); /* * 'GENODE_RPC_INTERFACE' declaration done manually @@ -361,8 +378,9 @@ struct Genode::Cpu_session : Session Meta::Type_tuple - > > > > > > > > > > > > > > > > > > > > Rpc_functions; + > > > > > > > > > > > > > > > > > > > > > Rpc_functions; }; struct Genode::Cpu_session::Quota diff --git a/repos/base/src/core/cpu_session_component.cc b/repos/base/src/core/cpu_session_component.cc index 4f25a9fbc..8e8da6fc8 100644 --- a/repos/base/src/core/cpu_session_component.cc +++ b/repos/base/src/core/cpu_session_component.cc @@ -166,6 +166,17 @@ void Cpu_session_component::pause(Thread_capability thread_cap) } +void Cpu_session_component::single_step(Thread_capability thread_cap, bool enabled) +{ + auto lambda = [this, enabled] (Cpu_thread_component *thread) { + if (!thread) return; + + thread->platform_thread()->single_step(enabled); + }; + _thread_ep->apply(thread_cap, lambda); +} + + void Cpu_session_component::resume(Thread_capability thread_cap) { auto lambda = [this] (Cpu_thread_component *thread) { @@ -416,7 +427,8 @@ Cpu_session_component::Cpu_session_component(Rpc_entrypoint *session_ep, /* map affinity to a location within the physical affinity space */ _location(affinity.scale_to(platform()->affinity_space())), - _trace_sources(trace_sources), _quota(quota), _ref(0) + _trace_sources(trace_sources), _quota(quota), _ref(0), + _native_cpu(*this, args) { /* remember session label */ char buf[Session_label::size()]; diff --git a/repos/base-fiasco/src/core/cpu_session_support.cc b/repos/base/src/core/cpu_session_support.cc similarity index 91% rename from repos/base-fiasco/src/core/cpu_session_support.cc rename to repos/base/src/core/cpu_session_support.cc index 38bc99bd6..a5ad4ba19 100644 --- a/repos/base-fiasco/src/core/cpu_session_support.cc +++ b/repos/base/src/core/cpu_session_support.cc @@ -1,5 +1,5 @@ /* - * \brief Platform-specific parts of cores CPU-service + * \brief Platform-specific parts of core's CPU-service * \author Martin Stein * \date 2012-04-17 */ diff --git a/repos/base/src/core/include/cpu_session_component.h b/repos/base/src/core/include/cpu_session_component.h index 7e4ea6364..f1d1df73b 100644 --- a/repos/base/src/core/include/cpu_session_component.h +++ b/repos/base/src/core/include/cpu_session_component.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace Genode { @@ -172,24 +173,21 @@ namespace Genode { List _ref_members; Lock _ref_members_lock; + Native_cpu_component _native_cpu; + + friend class Native_cpu_component; + /* * Utilities for quota accounting */ void _incr_weight(size_t const weight); - void _decr_weight(size_t const weight); - size_t _weight_to_quota(size_t const weight) const; - void _decr_quota(size_t const quota); - void _incr_quota(size_t const quota); - void _update_thread_quota(Cpu_thread_component *) const; - void _update_each_thread_quota(); - void _transfer_quota(Cpu_session_component * const dst, size_t const quota); @@ -213,7 +211,6 @@ namespace Genode { } void _deinit_ref_account(); - void _deinit_threads(); /** @@ -267,6 +264,7 @@ namespace Genode { int start(Thread_capability, addr_t, addr_t); void pause(Thread_capability thread_cap); void resume(Thread_capability thread_cap); + void single_step(Thread_capability thread_cap, bool enable); void cancel_blocking(Thread_capability); int name(Thread_capability, char *, size_t); Thread_state state(Thread_capability); @@ -281,6 +279,8 @@ namespace Genode { int ref_account(Cpu_session_capability c); int transfer_quota(Cpu_session_capability, size_t); Quota quota() override; + + Capability native_cpu() { return _native_cpu.cap(); } }; } diff --git a/repos/base/src/core/include/native_cpu_component.h b/repos/base/src/core/include/native_cpu_component.h new file mode 100644 index 000000000..2a503ffe0 --- /dev/null +++ b/repos/base/src/core/include/native_cpu_component.h @@ -0,0 +1,42 @@ +/* + * \brief Kernel-specific part of the CPU-session interface + * \author Norman Feske + * \date 2016-01-19 + * + * This definition is used on platforms with no kernel-specific PD functions + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ +#define _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ + +/* Genode includes */ +#include + +/* core-local includes */ +#include + +namespace Genode { + + class Cpu_session_component; + class Native_cpu_component; +} + + +struct Genode::Native_cpu_component +{ + Native_cpu_component(Cpu_session_component &, char const *) { } + + Capability cap() + { + return Capability(); + } +}; + +#endif /* _CORE__INCLUDE__NATIVE_CPU_COMPONENT_H_ */ diff --git a/repos/ports-foc/src/lib/l4lx/genode_block.cc b/repos/ports-foc/src/lib/l4lx/genode_block.cc index 0351f57e2..335886510 100644 --- a/repos/ports-foc/src/lib/l4lx/genode_block.cc +++ b/repos/ports-foc/src/lib/l4lx/genode_block.cc @@ -97,12 +97,20 @@ namespace { Genode::Signal_context _tx; char _name[32]; + Genode::Native_capability _alloc_irq() + { + Genode::Foc_native_cpu_client + native_cpu(L4lx::cpu_connection()->native_cpu()); + + return native_cpu.alloc_irq(); + } + public: Block_device(const char *label) : _alloc(Genode::env()->heap()), _session(&_alloc, TX_BUF_SIZE, label), - _irq_cap(L4lx::vcpu_connection()->alloc_irq()) + _irq_cap(_alloc_irq()) { _session.info(&_blk_cnt, &_blk_size, &_blk_ops); Genode::strncpy(_name, label, sizeof(_name)); diff --git a/repos/ports-foc/src/lib/l4lx/genode_net.cc b/repos/ports-foc/src/lib/l4lx/genode_net.cc index db54f740f..d35f92c9a 100644 --- a/repos/ports-foc/src/lib/l4lx/genode_net.cc +++ b/repos/ports-foc/src/lib/l4lx/genode_net.cc @@ -149,7 +149,9 @@ extern "C" { l4_cap_idx_t genode_net_irq_cap() { Linux::Irq_guard guard; - static Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); + Genode::Foc_native_cpu_client + native_cpu(L4lx::cpu_connection()->native_cpu()); + static Genode::Native_capability cap = native_cpu.alloc_irq(); static Genode::Lock lock(Genode::Lock::LOCKED); static Signal_thread th(cap.dst(), &lock); lock.lock(); diff --git a/repos/ports-foc/src/lib/l4lx/genode_terminal.cc b/repos/ports-foc/src/lib/l4lx/genode_terminal.cc index 741926895..8865f5cb6 100644 --- a/repos/ports-foc/src/lib/l4lx/genode_terminal.cc +++ b/repos/ports-foc/src/lib/l4lx/genode_terminal.cc @@ -95,7 +95,11 @@ extern "C" { l4_cap_idx_t genode_terminal_irq(unsigned idx) { - static Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); + + Genode::Foc_native_cpu_client + native_cpu(L4lx::cpu_connection()->native_cpu()); + + static Genode::Native_capability cap = native_cpu.alloc_irq(); if (!signal_thread) signal_thread = new (Genode::env()->heap()) Signal_thread(cap.dst()); return cap.dst(); diff --git a/repos/ports-foc/src/lib/l4lx/include/vcpu.h b/repos/ports-foc/src/lib/l4lx/include/vcpu.h index 0f805a2ab..7fc4e4550 100644 --- a/repos/ports-foc/src/lib/l4lx/include/vcpu.h +++ b/repos/ports-foc/src/lib/l4lx/include/vcpu.h @@ -19,7 +19,8 @@ #include #include #include -#include +#include +#include #include #include @@ -29,7 +30,7 @@ namespace Fiasco { namespace L4lx { - extern Genode::Foc_cpu_session_client *vcpu_connection(); + extern Genode::Cpu_session *cpu_connection(); class Vcpu : public Genode::Thread_base @@ -68,8 +69,10 @@ namespace L4lx { l4_utcb_tcr_u(_utcb)->user[0] = native_thread().kcap; /* enable vcpu functionality respectively */ - if (_vcpu_state) - vcpu_connection()->enable_vcpu(_thread_cap, _vcpu_state); + if (_vcpu_state) { + Genode::Foc_native_cpu_client native_cpu(cpu_connection()->native_cpu()); + native_cpu.enable_vcpu(_thread_cap, _vcpu_state); + } /* set cpu affinity */ set_affinity(_cpu_nr); @@ -94,8 +97,8 @@ namespace L4lx { void set_affinity(unsigned i) { - vcpu_connection()->affinity(_thread_cap, - Genode::Affinity::Location(i, 0)); + cpu_connection()->affinity(_thread_cap, + Genode::Affinity::Location(i, 0)); } }; diff --git a/repos/ports-foc/src/lib/l4lx/l4lx_thread.cc b/repos/ports-foc/src/lib/l4lx/l4lx_thread.cc index 7bd0361da..4682635da 100644 --- a/repos/ports-foc/src/lib/l4lx/l4lx_thread.cc +++ b/repos/ports-foc/src/lib/l4lx/l4lx_thread.cc @@ -13,7 +13,7 @@ /* Genode includes */ #include -#include +#include #include #include @@ -48,12 +48,9 @@ static l4_addr_t utcb_base_addr() return _addr; } -Genode::Foc_cpu_session_client* L4lx::vcpu_connection() +Genode::Cpu_session* L4lx::cpu_connection() { - using namespace Genode; - - static Foc_cpu_session_client _client(Genode::env()->cpu_session_cap()); - return &_client; + return Genode::env()->cpu_session(); } @@ -102,7 +99,11 @@ void l4lx_thread_alloc_irq(l4_cap_idx_t c) { Linux::Irq_guard guard; - Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); + Genode::Foc_native_cpu_client + native_cpu(L4lx::cpu_connection()->native_cpu()); + + Genode::Native_capability cap = native_cpu.alloc_irq(); + l4_task_map(L4_BASE_TASK_CAP, L4_BASE_TASK_CAP, l4_obj_fpage(cap.dst(), 0, L4_FPAGE_RWX), c | L4_ITEM_MAP); } diff --git a/repos/ports-foc/src/lib/l4lx/l4x_pagefault.cc b/repos/ports-foc/src/lib/l4lx/l4x_pagefault.cc index 142322aa3..a6fe44b02 100644 --- a/repos/ports-foc/src/lib/l4lx/l4x_pagefault.cc +++ b/repos/ports-foc/src/lib/l4lx/l4x_pagefault.cc @@ -91,7 +91,8 @@ Fiasco::l4_cap_idx_t genode_balloon_irq_cap() { Linux::Irq_guard guard; - static Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); + static Genode::Foc_native_cpu_client native_cpu(L4lx::cpu_connection()->native_cpu()); + static Genode::Native_capability cap = native_cpu.alloc_irq(); static Genode::Lock lock(Genode::Lock::LOCKED); static Signal_thread th(cap.dst(), &lock); lock.lock(); diff --git a/repos/ports-foc/src/lib/l4lx/startup.cc b/repos/ports-foc/src/lib/l4lx/startup.cc index 3a6913ad6..2ef0efddb 100644 --- a/repos/ports-foc/src/lib/l4lx/startup.cc +++ b/repos/ports-foc/src/lib/l4lx/startup.cc @@ -17,9 +17,10 @@ #include #include #include -#include +#include #include #include +#include /* L4lx includes */ #include @@ -102,10 +103,13 @@ static void prepare_l4re_env() { using namespace Fiasco; - Genode::Foc_cpu_session_client cpu(Genode::env()->cpu_session_cap()); + Genode::Cpu_session &cpu = *Genode::env()->cpu_session(); + + Genode::Foc_native_cpu_client native_cpu(cpu.native_cpu()); Genode::Thread_capability main_thread = Genode::Thread_base::myself()->cap(); - static Genode::Native_capability main_thread_cap = cpu.native_cap(main_thread); + + static Genode::Native_capability main_thread_cap = native_cpu.native_cap(main_thread); l4re_env_t *env = l4re_env(); env->first_free_utcb = (l4_addr_t)l4_utcb() + L4_UTCB_OFFSET; diff --git a/repos/ports/src/app/gdb_monitor/cpu_session_component.cc b/repos/ports/src/app/gdb_monitor/cpu_session_component.cc index 093d52d5f..50320ee66 100644 --- a/repos/ports/src/app/gdb_monitor/cpu_session_component.cc +++ b/repos/ports/src/app/gdb_monitor/cpu_session_component.cc @@ -230,6 +230,12 @@ Dataspace_capability Cpu_session_component::trace_policy(Thread_capability threa } +Capability Cpu_session_component::native_cpu() +{ + return _parent_cpu_session.native_cpu(); +} + + Cpu_session_component::Cpu_session_component(Signal_receiver *exception_signal_receiver, const char *args) : _parent_cpu_session(env()->parent()->session(args)), _exception_signal_receiver(exception_signal_receiver) diff --git a/repos/ports/src/app/gdb_monitor/cpu_session_component.h b/repos/ports/src/app/gdb_monitor/cpu_session_component.h index 15d66fd1d..977e4c0c1 100644 --- a/repos/ports/src/app/gdb_monitor/cpu_session_component.h +++ b/repos/ports/src/app/gdb_monitor/cpu_session_component.h @@ -79,6 +79,7 @@ class Cpu_session_component : public Rpc_object int ref_account(Cpu_session_capability c); int transfer_quota(Cpu_session_capability c, size_t q); Quota quota() override; + Capability native_cpu() override; }; #endif /* _CPU_SESSION_COMPONENT_H_ */ diff --git a/repos/ports/src/noux/cpu_session_component.h b/repos/ports/src/noux/cpu_session_component.h index d8e6bccf5..80eb7548f 100644 --- a/repos/ports/src/noux/cpu_session_component.h +++ b/repos/ports/src/noux/cpu_session_component.h @@ -149,6 +149,9 @@ namespace Noux { int transfer_quota(Cpu_session_capability c, size_t q) override { return _cpu.transfer_quota(c, q); } + + Capability native_cpu() override { + return _cpu.native_cpu(); } }; }