diff --git a/base-codezero/src/core/include/platform_thread.h b/base-codezero/src/core/include/platform_thread.h index 710cc3298..243882641 100644 --- a/base-codezero/src/core/include/platform_thread.h +++ b/base-codezero/src/core/include/platform_thread.h @@ -114,9 +114,9 @@ namespace Genode { unsigned long pager_object_badge() const { return _tid; } /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no); + void affinity(unsigned cpu); /** * Get thread name diff --git a/base-codezero/src/core/platform_thread.cc b/base-codezero/src/core/platform_thread.cc index 5aa982277..0ff5d06a0 100644 --- a/base-codezero/src/core/platform_thread.cc +++ b/base-codezero/src/core/platform_thread.cc @@ -27,7 +27,7 @@ using namespace Genode; using namespace Codezero; -void Platform_thread::set_cpu(unsigned int cpu_no) +void Platform_thread::affinity(unsigned int cpu_no) { PDBG("not yet implemented"); } diff --git a/base-fiasco/src/core/include/platform_thread.h b/base-fiasco/src/core/include/platform_thread.h index 62405e26f..7762afea8 100644 --- a/base-fiasco/src/core/include/platform_thread.h +++ b/base-fiasco/src/core/include/platform_thread.h @@ -111,6 +111,13 @@ namespace Genode { */ int state(Genode::Thread_state *state_dst); + /** + * Set the executing CPU for this thread + * + * SMP is not supported on L4/Fiasco. + */ + void affinity(unsigned) { } + /************************ ** Accessor functions ** diff --git a/base-foc/include/foc_cpu_session/client.h b/base-foc/include/foc_cpu_session/client.h index 7c6078e67..f8a19def0 100644 --- a/base-foc/include/foc_cpu_session/client.h +++ b/base-foc/include/foc_cpu_session/client.h @@ -67,6 +67,15 @@ namespace Genode { void exception_handler(Thread_capability thread, Signal_context_capability handler) { call(thread, handler); } + void single_step(Thread_capability thread, bool enable) { + call(thread, enable); } + + unsigned num_cpus() const { + return call(); } + + void affinity(Thread_capability thread, unsigned cpu) { + call(thread, cpu); } + void enable_vcpu(Thread_capability cap, addr_t vcpu_state) { call(cap, vcpu_state); } diff --git a/base-foc/src/core/include/cpu_session_component.h b/base-foc/src/core/include/cpu_session_component.h index 2e48ecd32..e82660c91 100644 --- a/base-foc/src/core/include/cpu_session_component.h +++ b/base-foc/src/core/include/cpu_session_component.h @@ -141,6 +141,8 @@ namespace Genode { int name(Thread_capability, char *, size_t); int state(Thread_capability, Thread_state *); void exception_handler(Thread_capability, Signal_context_capability); + unsigned num_cpus() const; + void affinity(Thread_capability, unsigned); /*********************************** diff --git a/base-foc/src/core/include/platform_thread.h b/base-foc/src/core/include/platform_thread.h index 670cebffe..1fec3e94b 100644 --- a/base-foc/src/core/include/platform_thread.h +++ b/base-foc/src/core/include/platform_thread.h @@ -124,6 +124,11 @@ namespace Genode { */ int state(Genode::Thread_state *state_dst); + /** + * Set the executing CPU for this thread + */ + void affinity(unsigned cpu); + /************************ ** Accessor functions ** diff --git a/base-foc/src/core/platform_thread.cc b/base-foc/src/core/platform_thread.cc index e9511f4b5..e52735917 100644 --- a/base-foc/src/core/platform_thread.cc +++ b/base-foc/src/core/platform_thread.cc @@ -180,6 +180,11 @@ void Platform_thread::cancel_blocking() } +void Platform_thread::affinity(unsigned cpu) +{ +} + + void Platform_thread::_create_thread() { l4_msgtag_t tag = l4_factory_create_thread(L4_BASE_FACTORY_CAP, diff --git a/base-host/src/core/include/platform_thread.h b/base-host/src/core/include/platform_thread.h index 681704503..113b70a94 100644 --- a/base-host/src/core/include/platform_thread.h +++ b/base-host/src/core/include/platform_thread.h @@ -92,9 +92,9 @@ namespace Genode { unsigned long pager_object_badge() const; /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no); + void affinity(unsigned cpu); /** * Get thread name diff --git a/base-host/src/core/platform_thread.cc b/base-host/src/core/platform_thread.cc index 1d1bdd79d..365fe3909 100644 --- a/base-host/src/core/platform_thread.cc +++ b/base-host/src/core/platform_thread.cc @@ -20,7 +20,7 @@ using namespace Genode; -void Platform_thread::set_cpu(unsigned int cpu_no) +void Platform_thread::affinity(unsigned int cpu_no) { PERR("not yet implemented"); } diff --git a/base-hw/src/core/include/platform_thread.h b/base-hw/src/core/include/platform_thread.h index f056e4bcf..e8dfa3360 100644 --- a/base-hw/src/core/include/platform_thread.h +++ b/base-hw/src/core/include/platform_thread.h @@ -139,9 +139,9 @@ namespace Genode { unsigned long pager_object_badge() { return _id; } /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no) + void affinity(unsigned cpu) { kernel_log() << __PRETTY_FUNCTION__ << ": Not implemented\n"; while (1) ; diff --git a/base-linux/src/core/include/platform_thread.h b/base-linux/src/core/include/platform_thread.h index e2e7a28b2..ab9e10e25 100644 --- a/base-linux/src/core/include/platform_thread.h +++ b/base-linux/src/core/include/platform_thread.h @@ -59,6 +59,7 @@ namespace Genode { int start(void *ip, void *sp) { return 0; } int state(Thread_state *state_dst) { return 0; } const char *name() { return _name; } + void affinity(unsigned) { } }; } diff --git a/base-mb/src/core/include/platform_thread.h b/base-mb/src/core/include/platform_thread.h index 13448556e..ad95fe800 100755 --- a/base-mb/src/core/include/platform_thread.h +++ b/base-mb/src/core/include/platform_thread.h @@ -141,9 +141,9 @@ namespace Genode { inline unsigned long pager_object_badge() const { return _tid; } /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no = 0); + void affinity(unsigned cpu); /** * Get thread name diff --git a/base-mb/src/core/platform_thread.cc b/base-mb/src/core/platform_thread.cc index 8e51b1abc..0828116ef 100755 --- a/base-mb/src/core/platform_thread.cc +++ b/base-mb/src/core/platform_thread.cc @@ -81,7 +81,7 @@ Kernel::Utcb* Genode::physical_utcb(Native_thread_id tid) } -void Platform_thread::set_cpu(unsigned int cpu_no) { PERR("not implemented"); } +void Platform_thread::affinity(unsigned int cpu_no) { PERR("not implemented"); } void Platform_thread::cancel_blocking() { PERR("not implemented"); } diff --git a/base-nova/include/cpu_session/client.h b/base-nova/include/cpu_session/client.h index 9985451ce..f0a74476a 100644 --- a/base-nova/include/cpu_session/client.h +++ b/base-nova/include/cpu_session/client.h @@ -80,6 +80,12 @@ namespace Genode { Native_capability native_cap(Thread_capability cap) { return call(cap); } + unsigned num_cpus() const { + return call(); } + + void affinity(Thread_capability thread, unsigned cpu) { + call(thread, cpu); } + private: Native_capability pause_sync(Thread_capability target) { diff --git a/base-nova/src/core/include/cpu_session_component.h b/base-nova/src/core/include/cpu_session_component.h index 9c28cdc76..f78963d11 100644 --- a/base-nova/src/core/include/cpu_session_component.h +++ b/base-nova/src/core/include/cpu_session_component.h @@ -142,6 +142,8 @@ namespace Genode { int name(Thread_capability, char *, size_t); int state(Thread_capability, Thread_state *); void exception_handler(Thread_capability, Signal_context_capability); + unsigned num_cpus() const; + void affinity(Thread_capability, unsigned); /*********************************** diff --git a/base-nova/src/core/include/platform_thread.h b/base-nova/src/core/include/platform_thread.h index f47ccacd1..c97672d3c 100644 --- a/base-nova/src/core/include/platform_thread.h +++ b/base-nova/src/core/include/platform_thread.h @@ -114,9 +114,9 @@ namespace Genode { unsigned long pager_object_badge() const; /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no); + void affinity(unsigned cpu); /** * Get thread name diff --git a/base-nova/src/core/platform_thread.cc b/base-nova/src/core/platform_thread.cc index 1585dd373..65f1837bd 100644 --- a/base-nova/src/core/platform_thread.cc +++ b/base-nova/src/core/platform_thread.cc @@ -35,7 +35,7 @@ using namespace Genode; ** Platform thread ** *********************/ -void Platform_thread::set_cpu(unsigned int cpu_no) +void Platform_thread::affinity(unsigned int cpu_no) { PERR("not yet implemented"); } diff --git a/base-okl4/src/core/include/platform_thread.h b/base-okl4/src/core/include/platform_thread.h index 4fd0e4554..5b18408ad 100644 --- a/base-okl4/src/core/include/platform_thread.h +++ b/base-okl4/src/core/include/platform_thread.h @@ -130,9 +130,9 @@ namespace Genode { unsigned long pager_object_badge() const; /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no); + void affinity(unsigned cpu); /***************************** diff --git a/base-okl4/src/core/platform_thread.cc b/base-okl4/src/core/platform_thread.cc index 02939634d..e88faac56 100644 --- a/base-okl4/src/core/platform_thread.cc +++ b/base-okl4/src/core/platform_thread.cc @@ -36,7 +36,7 @@ using namespace Genode; using namespace Okl4; -void Platform_thread::set_cpu(unsigned int cpu_no) +void Platform_thread::affinity(unsigned int cpu_no) { PERR("not yet implemented"); } diff --git a/base-pistachio/src/core/include/platform_thread.h b/base-pistachio/src/core/include/platform_thread.h index c345672a6..803657f00 100644 --- a/base-pistachio/src/core/include/platform_thread.h +++ b/base-pistachio/src/core/include/platform_thread.h @@ -130,9 +130,9 @@ namespace Genode { return convert_native_thread_id_to_badge(_l4_thread_id); } /** - * Set the executing CPU for this thread. + * Set the executing CPU for this thread */ - void set_cpu(unsigned int cpu_no); + void affinity(unsigned cpu); /********************************** diff --git a/base-pistachio/src/core/platform_thread.cc b/base-pistachio/src/core/platform_thread.cc index 1faae2678..46005155c 100644 --- a/base-pistachio/src/core/platform_thread.cc +++ b/base-pistachio/src/core/platform_thread.cc @@ -39,7 +39,7 @@ static const bool verbose2 = true; #define PT_DBG(args...) if (verbose) PDBG(args); else {} -void Platform_thread::set_cpu(unsigned int cpu_no) +void Platform_thread::affinity(unsigned int cpu_no) { if (cpu_no >= L4_NumProcessors(get_kip())) { PERR("Invalid processor number."); @@ -98,7 +98,7 @@ int Platform_thread::start(void *ip, void *sp, unsigned int cpu_no) } /* get the thread running on the right cpu */ - set_cpu(cpu_no); + affinity(cpu_no); /* assign priority */ if (!L4_Set_Priority(thread, diff --git a/base/include/cpu_session/client.h b/base/include/cpu_session/client.h index 5744325dc..add914c5e 100644 --- a/base/include/cpu_session/client.h +++ b/base/include/cpu_session/client.h @@ -62,6 +62,12 @@ namespace Genode { void single_step(Thread_capability thread, bool enable) { call(thread, enable); } + + unsigned num_cpus() const { + return call(); } + + void affinity(Thread_capability thread, unsigned cpu) { + call(thread, cpu); } }; } diff --git a/base/include/cpu_session/cpu_session.h b/base/include/cpu_session/cpu_session.h index d3d596b17..1475485ad 100644 --- a/base/include/cpu_session/cpu_session.h +++ b/base/include/cpu_session/cpu_session.h @@ -161,6 +161,19 @@ namespace Genode { */ virtual void single_step(Thread_capability thread, bool enable) {} + /** + * Return number of CPUs available via the CPU session + */ + virtual unsigned num_cpus() const = 0; + + /** + * Assign thread to a CPU + * + * The 'cpu' argument is a CPU index starting at 0. It must be + * smaller than the value returned by 'num_cpus()'. + */ + virtual void affinity(Thread_capability thread, unsigned cpu) = 0; + /** * Translate generic priority value to kernel-specific priority levels * @@ -211,6 +224,8 @@ namespace Genode { GENODE_RPC(Rpc_exception_handler, void, exception_handler, Thread_capability, Signal_context_capability); GENODE_RPC(Rpc_single_step, void, single_step, Thread_capability, bool); + GENODE_RPC(Rpc_num_cpus, unsigned, num_cpus); + GENODE_RPC(Rpc_affinity, void, affinity, Thread_capability, unsigned); /* * 'GENODE_RPC_INTERFACE' declaration done manually @@ -233,8 +248,10 @@ namespace Genode { Meta::Type_tuple - > > > > > > > > > > > > Rpc_functions; + > > > > > > > > > > > > > > Rpc_functions; }; } diff --git a/base/src/core/cpu_session_component.cc b/base/src/core/cpu_session_component.cc index 3fecf9d4d..c9b15d252 100644 --- a/base/src/core/cpu_session_component.cc +++ b/base/src/core/cpu_session_component.cc @@ -17,9 +17,10 @@ #include #include -/* Core includes */ +/* core includes */ #include #include +#include using namespace Genode; @@ -162,6 +163,21 @@ void Cpu_session_component::exception_handler(Thread_capability thread_c } +unsigned Cpu_session_component::num_cpus() const +{ + return platform()->num_cpus(); +} + + +void Cpu_session_component::affinity(Thread_capability thread_cap, unsigned cpu) +{ + Cpu_thread_component *thread = _lookup_thread(thread_cap); + if (!thread) return; + + thread->platform_thread()->affinity(cpu); +} + + Cpu_session_component::Cpu_session_component(Rpc_entrypoint *thread_ep, Pager_entrypoint *pager_ep, Allocator *md_alloc, diff --git a/base/src/core/include/cpu_session_component.h b/base/src/core/include/cpu_session_component.h index a521b2f60..00c615bc3 100644 --- a/base/src/core/include/cpu_session_component.h +++ b/base/src/core/include/cpu_session_component.h @@ -134,6 +134,8 @@ namespace Genode { int name(Thread_capability, char *, size_t); int state(Thread_capability, Thread_state *); void exception_handler(Thread_capability, Signal_context_capability); + unsigned num_cpus() const; + void affinity(Thread_capability, unsigned); }; } diff --git a/base/src/core/include/platform_generic.h b/base/src/core/include/platform_generic.h index 486060175..e2e8703bd 100644 --- a/base/src/core/include/platform_generic.h +++ b/base/src/core/include/platform_generic.h @@ -88,6 +88,11 @@ namespace Genode { * Return true if platform supports direct unmap (no mapping db) */ virtual bool supports_direct_unmap() const { return false; } + + /** + * Return number of physical CPUs present in the platform + */ + virtual unsigned num_cpus() const { return 1; } }; diff --git a/ports/src/app/gdb_monitor/cpu_session_component.cc b/ports/src/app/gdb_monitor/cpu_session_component.cc index 1e2976c28..4bee6d608 100644 --- a/ports/src/app/gdb_monitor/cpu_session_component.cc +++ b/ports/src/app/gdb_monitor/cpu_session_component.cc @@ -185,6 +185,18 @@ void Cpu_session_component::single_step(Thread_capability thread_cap, bool enabl } +unsigned Cpu_session_component::num_cpus() const +{ + return _parent_cpu_session.num_cpus(); +} + + +void Cpu_session_component::affinity(Thread_capability thread_cap, unsigned cpu) +{ + _parent_cpu_session.affinity(thread_cap, 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/ports/src/app/gdb_monitor/cpu_session_component.h b/ports/src/app/gdb_monitor/cpu_session_component.h index fb810ce3e..f37ca6125 100644 --- a/ports/src/app/gdb_monitor/cpu_session_component.h +++ b/ports/src/app/gdb_monitor/cpu_session_component.h @@ -69,6 +69,8 @@ class Cpu_session_component : public Rpc_object void exception_handler(Thread_capability thread, Signal_context_capability handler); void single_step(Thread_capability thread, bool enable); + unsigned num_cpus() const; + void affinity(Thread_capability, unsigned); }; #endif /* _CPU_SESSION_COMPONENT_H_ */ diff --git a/ports/src/noux/cpu_session_component.h b/ports/src/noux/cpu_session_component.h index 963ba5ab9..1776b594b 100644 --- a/ports/src/noux/cpu_session_component.h +++ b/ports/src/noux/cpu_session_component.h @@ -131,6 +131,11 @@ namespace Noux { void single_step(Thread_capability thread, bool enable) { _cpu.single_step(thread, enable); } + unsigned num_cpus() const { + return _cpu.num_cpus(); } + + void affinity(Thread_capability thread, unsigned cpu) { + _cpu.affinity(thread, cpu); } }; }