diff --git a/base-codezero/src/core/include/platform_thread.h b/base-codezero/src/core/include/platform_thread.h index 707bd0b6b..e46554b08 100644 --- a/base-codezero/src/core/include/platform_thread.h +++ b/base-codezero/src/core/include/platform_thread.h @@ -136,6 +136,11 @@ namespace Genode { */ void affinity(unsigned cpu); + /** + * Get the executing CPU for this thread + */ + unsigned affinity(); + /** * Get thread name */ diff --git a/base-codezero/src/core/platform_thread.cc b/base-codezero/src/core/platform_thread.cc index cd77024e3..a09ef3142 100644 --- a/base-codezero/src/core/platform_thread.cc +++ b/base-codezero/src/core/platform_thread.cc @@ -29,7 +29,14 @@ using namespace Codezero; void Platform_thread::affinity(unsigned int cpu_no) { - PDBG("not yet implemented"); + PDBG("'%s' not yet implemented", __PRETTY_FUNCTION__); +} + + +unsigned Platform_thread::affinity() +{ + PDBG("'%s' not yet implemented", __PRETTY_FUNCTION__); + return 0; } diff --git a/base-fiasco/src/core/include/platform_thread.h b/base-fiasco/src/core/include/platform_thread.h index 90af57bdd..742d46a29 100644 --- a/base-fiasco/src/core/include/platform_thread.h +++ b/base-fiasco/src/core/include/platform_thread.h @@ -123,6 +123,11 @@ namespace Genode { */ void affinity(unsigned) { } + /** + * Request the affinity of this thread + */ + unsigned affinity() { return 0; } + /** * Return the address space to which the thread is bound */ diff --git a/base-fiasco/src/core/platform.cc b/base-fiasco/src/core/platform.cc index 4636bd25f..41dfca0e5 100644 --- a/base-fiasco/src/core/platform.cc +++ b/base-fiasco/src/core/platform.cc @@ -130,7 +130,7 @@ static void _core_pager_loop() } -Platform::Sigma0::Sigma0() : Pager_object(0) +Platform::Sigma0::Sigma0() : Pager_object(0, 0) { cap(reinterpret_cap_cast(Native_capability(Fiasco::sigma0_threadid, 0))); } @@ -145,7 +145,7 @@ Platform::Sigma0 *Platform::sigma0() Platform::Core_pager::Core_pager(Platform_pd *core_pd) : - Platform_thread("core.pager"), Pager_object(0) + Platform_thread("core.pager"), Pager_object(0, 0) { Platform_thread::pager(sigma0()); diff --git a/base-foc/src/core/include/platform_thread.h b/base-foc/src/core/include/platform_thread.h index 36564f631..273d4ad00 100644 --- a/base-foc/src/core/include/platform_thread.h +++ b/base-foc/src/core/include/platform_thread.h @@ -138,6 +138,11 @@ namespace Genode { */ void affinity(unsigned cpu); + /** + * Get the executing CPU for this thread + */ + unsigned affinity(); + /** * Return the address space to which the thread is bound */ diff --git a/base-foc/src/core/platform.cc b/base-foc/src/core/platform.cc index 1522f5660..2e2db6d98 100644 --- a/base-foc/src/core/platform.cc +++ b/base-foc/src/core/platform.cc @@ -121,7 +121,7 @@ static void _core_pager_loop() } -Platform::Sigma0::Sigma0(Cap_index* i) : Pager_object(0) +Platform::Sigma0::Sigma0(Cap_index* i) : Pager_object(0, 0) { /* * We use the Pager_object here in a slightly different manner, @@ -132,7 +132,7 @@ Platform::Sigma0::Sigma0(Cap_index* i) : Pager_object(0) Platform::Core_pager::Core_pager(Platform_pd *core_pd, Sigma0 *sigma0) -: Platform_thread("core.pager"), Pager_object(0) +: Platform_thread("core.pager"), Pager_object(0, 0) { Platform_thread::pager(sigma0); diff --git a/base-foc/src/core/platform_thread.cc b/base-foc/src/core/platform_thread.cc index a92620422..6e793b66f 100644 --- a/base-foc/src/core/platform_thread.cc +++ b/base-foc/src/core/platform_thread.cc @@ -209,6 +209,13 @@ void Platform_thread::affinity(unsigned cpu) } +unsigned Platform_thread::affinity() +{ + PERR("'%s' not yet implemented", __PRETTY_FUNCTION__); + return 0; +} + + void Platform_thread::_create_thread() { l4_msgtag_t tag = l4_factory_create_thread(L4_BASE_FACTORY_CAP, diff --git a/base-hw/src/core/include/platform_thread.h b/base-hw/src/core/include/platform_thread.h index 13fcd96a0..a8246052e 100644 --- a/base-hw/src/core/include/platform_thread.h +++ b/base-hw/src/core/include/platform_thread.h @@ -154,6 +154,16 @@ namespace Genode { void affinity(unsigned cpu) { kernel_log() << __PRETTY_FUNCTION__ << ": not implemented\n"; }; + /** + * Get the executing CPU for this thread + */ + unsigned affinity() + { + kernel_log() << __PRETTY_FUNCTION__ << ": not implemented\n"; + return 0; + }; + + /** * Return the address space to which the thread is bound */ diff --git a/base-nova/include/base/pager.h b/base-nova/include/base/pager.h index 1ee6894ff..f589306f3 100644 --- a/base-nova/include/base/pager.h +++ b/base-nova/include/base/pager.h @@ -81,7 +81,7 @@ namespace Genode { static Nova::Utcb * _check_handler(Thread_base *&, Pager_object *&); public: - Pager_object(unsigned long badge); + Pager_object(unsigned long badge, unsigned affinity); virtual ~Pager_object(); diff --git a/base-nova/src/base/pager/pager.cc b/base-nova/src/base/pager/pager.cc index a642e9779..59c486e52 100644 --- a/base-nova/src/base/pager/pager.cc +++ b/base-nova/src/base/pager/pager.cc @@ -257,7 +257,7 @@ static uint8_t create_portal(addr_t pt, addr_t pd, addr_t ec, Mtd mtd, return res; } -Pager_object::Pager_object(unsigned long badge) +Pager_object::Pager_object(unsigned long badge, unsigned affinity) : Thread_base("pager:", PF_HANDLER_STACK_SIZE), _badge(badge) { class Create_exception_pt_failed { }; diff --git a/base-nova/src/core/include/platform_thread.h b/base-nova/src/core/include/platform_thread.h index 9572bf737..5a1212409 100644 --- a/base-nova/src/core/include/platform_thread.h +++ b/base-nova/src/core/include/platform_thread.h @@ -131,6 +131,11 @@ namespace Genode { */ void affinity(unsigned cpu); + /** + * Get the executing CPU for this thread + */ + unsigned affinity(); + /** * Get thread name */ diff --git a/base-nova/src/core/platform_thread.cc b/base-nova/src/core/platform_thread.cc index ac356b470..1f93bc65c 100644 --- a/base-nova/src/core/platform_thread.cc +++ b/base-nova/src/core/platform_thread.cc @@ -46,6 +46,9 @@ void Platform_thread::affinity(unsigned int cpu_no) } +unsigned Platform_thread::affinity() { return _cpu_no; } + + int Platform_thread::start(void *ip, void *sp) { using namespace Nova; @@ -323,7 +326,7 @@ Weak_ptr Platform_thread::address_space() Platform_thread::Platform_thread(const char *name, unsigned, int thread_id) : _pd(0), _pager(0), _id_base(cap_selector_allocator()->alloc(1)), - _sel_exc_base(Native_thread::INVALID_INDEX), _cpu_no(0), + _sel_exc_base(Native_thread::INVALID_INDEX), _cpu_no(0), //XXX find out boot CPU _is_main_thread(false), _is_vcpu(false) { strncpy(_name, name, sizeof(_name)); diff --git a/base-okl4/src/core/include/platform_thread.h b/base-okl4/src/core/include/platform_thread.h index 44404cdbc..971486f03 100644 --- a/base-okl4/src/core/include/platform_thread.h +++ b/base-okl4/src/core/include/platform_thread.h @@ -142,6 +142,11 @@ namespace Genode { */ void affinity(unsigned cpu); + /** + * Request the affinity of this thread + */ + unsigned affinity(); + /***************************** ** OKL4-specific Accessors ** diff --git a/base-okl4/src/core/platform_thread.cc b/base-okl4/src/core/platform_thread.cc index b88e74475..1678a489b 100644 --- a/base-okl4/src/core/platform_thread.cc +++ b/base-okl4/src/core/platform_thread.cc @@ -38,7 +38,14 @@ using namespace Okl4; void Platform_thread::affinity(unsigned int cpu_no) { - PERR("not yet implemented"); + PERR("'%s' not yet implemented", __PRETTY_FUNCTION__); +} + + +unsigned Platform_thread::affinity() +{ + PERR("'%s' not yet implemented", __PRETTY_FUNCTION__); + return 0; } diff --git a/base-pistachio/src/core/include/platform.h b/base-pistachio/src/core/include/platform.h index f96db5e2e..69ef20fba 100644 --- a/base-pistachio/src/core/include/platform.h +++ b/base-pistachio/src/core/include/platform.h @@ -150,6 +150,8 @@ namespace Genode { Rom_fs *rom_fs() { return &_rom_fs; } void wait_for_exit(); + unsigned num_cpus() const { + return L4_NumProcessors(Pistachio::get_kip()); } }; } diff --git a/base-pistachio/src/core/include/platform_thread.h b/base-pistachio/src/core/include/platform_thread.h index c47a06044..91146994e 100644 --- a/base-pistachio/src/core/include/platform_thread.h +++ b/base-pistachio/src/core/include/platform_thread.h @@ -142,6 +142,11 @@ namespace Genode { */ void affinity(unsigned cpu); + /** + * Request the affinity of this thread + */ + unsigned affinity(); + /********************************** ** Pistachio-specific Accessors ** diff --git a/base-pistachio/src/core/platform.cc b/base-pistachio/src/core/platform.cc index 5af8ab1b3..ccb0889d6 100644 --- a/base-pistachio/src/core/platform.cc +++ b/base-pistachio/src/core/platform.cc @@ -199,7 +199,7 @@ static void _core_pager_loop() } -Platform::Sigma0::Sigma0() : Pager_object(0) +Platform::Sigma0::Sigma0() : Pager_object(0, 0) { cap(Native_capability(Pistachio::get_sigma0(), 0)); } @@ -214,7 +214,7 @@ Platform::Sigma0 *Platform::sigma0() Platform::Core_pager::Core_pager(Platform_pd *core_pd) : - Platform_thread("core.pager"), Pager_object(0) + Platform_thread("core.pager"), Pager_object(0, 0) { Platform_thread::pager(sigma0()); diff --git a/base-pistachio/src/core/platform_thread.cc b/base-pistachio/src/core/platform_thread.cc index 5c71107e1..47e69f453 100644 --- a/base-pistachio/src/core/platform_thread.cc +++ b/base-pistachio/src/core/platform_thread.cc @@ -51,6 +51,13 @@ void Platform_thread::affinity(unsigned int cpu_no) } +unsigned Platform_thread::affinity() +{ + PERR("'%s' not yet implemented", __PRETTY_FUNCTION__); + return 0; +} + + int Platform_thread::start(void *ip, void *sp, unsigned int cpu_no) { L4_ThreadId_t thread = _l4_thread_id; diff --git a/base/include/base/pager.h b/base/include/base/pager.h index 187583b4c..c51baebec 100644 --- a/base/include/base/pager.h +++ b/base/include/base/pager.h @@ -58,7 +58,7 @@ namespace Genode { */ Thread_state state; - Pager_object(unsigned long badge) : _badge(badge) { } + Pager_object(unsigned long badge, unsigned affinity) : _badge(badge) { } virtual ~Pager_object() { } unsigned long badge() const { return _badge; } diff --git a/base/src/core/include/rm_session_component.h b/base/src/core/include/rm_session_component.h index c54c358ab..732afd9cf 100644 --- a/base/src/core/include/rm_session_component.h +++ b/base/src/core/include/rm_session_component.h @@ -197,12 +197,14 @@ namespace Genode { * \param session RM session to which the client belongs * \param badge pager-object badge used of identifying the client * when a page-fault occurs + * \param affinity cpu affinity */ Rm_client(Rm_session_component *session, unsigned long badge, - Weak_ptr &address_space) + Weak_ptr &address_space, + unsigned affinity) : - Pager_object(badge), Rm_member(session), Rm_faulter(this), - _address_space(address_space) { } + Pager_object(badge, affinity), Rm_member(session), + Rm_faulter(this), _address_space(address_space) { } int pager(Ipc_pager &pager); diff --git a/base/src/core/rm_session_component.cc b/base/src/core/rm_session_component.cc index 6c0054b0f..a3419a328 100644 --- a/base/src/core/rm_session_component.cc +++ b/base/src/core/rm_session_component.cc @@ -605,6 +605,7 @@ void Rm_session_component::detach(Local_addr local_addr) Pager_capability Rm_session_component::add_client(Thread_capability thread) { unsigned long badge; + unsigned affinity; Weak_ptr address_space; { @@ -615,6 +616,8 @@ Pager_capability Rm_session_component::add_client(Thread_capability thread) /* determine identification of client when faulting */ badge = cpu_thread->platform_thread()->pager_object_badge(); + /* determine cpu affinity of client thread */ + affinity = cpu_thread->platform_thread()->affinity(); address_space = cpu_thread->platform_thread()->address_space(); if (!Locked_ptr(address_space).is_valid()) @@ -625,7 +628,7 @@ Pager_capability Rm_session_component::add_client(Thread_capability thread) Lock::Guard lock_guard(_lock); Rm_client *cl; - try { cl = new(&_client_slab) Rm_client(this, badge, address_space); } + try { cl = new(&_client_slab) Rm_client(this, badge, address_space, affinity); } catch (Allocator::Out_of_memory) { throw Out_of_metadata(); } catch (Cpu_session::Thread_creation_failed) { throw Out_of_metadata(); } catch (Thread_base::Stack_alloc_failed) { throw Out_of_metadata(); }