From 395e955756a763123eb2ff125e5d00de28256149 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 7 Mar 2014 15:15:15 +0100 Subject: [PATCH] hw: set affinity of core threads ref #1076 --- base-hw/include/base/native_types.h | 36 +++++++++++++++++++++++++++++ base-hw/src/core/platform_thread.cc | 3 +++ base-hw/src/core/thread.cc | 8 ++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/base-hw/include/base/native_types.h b/base-hw/include/base/native_types.h index 01f61e3f5..9ab1c645f 100644 --- a/base-hw/include/base/native_types.h +++ b/base-hw/include/base/native_types.h @@ -64,6 +64,11 @@ namespace Genode */ class Start_info; + /** + * Info that a core-thread creator hands out to Platform_thread::start + */ + class Core_start_info; + /** * Memory region that is exclusive to every thread and known by the kernel */ @@ -260,6 +265,32 @@ class Genode::Start_info Native_capability utcb_ds() const { return _utcb_ds; } }; +class Genode::Core_start_info +{ + private: + + unsigned _processor_id; + + public: + + /** + * Set-up valid core startup-message + * + * \param processor_id kernel name of the processor to start on + */ + void init(unsigned const processor_id) + { + _processor_id = processor_id; + } + + + /*************** + ** Accessors ** + ***************/ + + unsigned processor_id() const { return _processor_id; } +}; + class Genode::Native_utcb { private: @@ -279,6 +310,11 @@ class Genode::Native_utcb Start_info * start_info() const { return (Start_info *)_data; } + Core_start_info * core_start_info() const + { + return (Core_start_info *)_data; + } + size_t size() const { return sizeof(_data)/sizeof(_data[0]); } void * base() const { return (void *)_data; } diff --git a/base-hw/src/core/platform_thread.cc b/base-hw/src/core/platform_thread.cc index 9a1dea3fa..071fbeb9f 100644 --- a/base-hw/src/core/platform_thread.cc +++ b/base-hw/src/core/platform_thread.cc @@ -97,6 +97,9 @@ Platform_thread::Platform_thread(size_t const stack_size, } _utcb_virt = _utcb_phys; + /* set-up default start-info */ + _utcb_virt->core_start_info()->init(Processor_driver::primary_id()); + /* create kernel object */ _id = Kernel::new_thread(_kernel_thread, Kernel::Priority::MAX, _label); if (!_id) { diff --git a/base-hw/src/core/thread.cc b/base-hw/src/core/thread.cc index 4a1b1c63b..4b3e63450 100644 --- a/base-hw/src/core/thread.cc +++ b/base-hw/src/core/thread.cc @@ -85,10 +85,16 @@ void Thread_base::start() /* provide thread ident at the aligned base of the stack */ *(Core_thread_id *)base = (Core_thread_id)this; + /* set affinity of thread */ + Platform_thread * const platform_thread = _tid.platform_thread; + unsigned const processor_id = utcb()->core_start_info()->processor_id(); + Affinity::Location location(processor_id, 0, 1, 1); + platform_thread->affinity(location); + /* start thread with stack pointer at the top of stack */ void * sp = (void *)((addr_t)base + size); void * ip = (void *)&_thread_start; - if (_tid.platform_thread->start(ip, sp)) { + if (platform_thread->start(ip, sp)) { PERR("failed to start thread"); alloc->free(base, size); return;