diff --git a/base-foc/src/core/include/cpu_session_component.h b/base-foc/src/core/include/cpu_session_component.h index 28a650a76..158fb27f0 100644 --- a/base-foc/src/core/include/cpu_session_component.h +++ b/base-foc/src/core/include/cpu_session_component.h @@ -103,6 +103,8 @@ namespace Genode { unsigned _priority; /* priority of threads created with this session */ + Affinity::Location _location; /* CPU affinity of this + session */ /** * Exception handler that will be invoked unless overridden by a @@ -125,9 +127,10 @@ namespace Genode { /** * Constructor */ - Cpu_session_component(Rpc_entrypoint *thread_ep, + Cpu_session_component(Rpc_entrypoint *thread_ep, Pager_entrypoint *pager_ep, - Allocator *md_alloc, const char *args); + Allocator *md_alloc, const char *args, + Affinity const &affinity); /** * Destructor diff --git a/base-hw/include/cpu_session/connection.h b/base-hw/include/cpu_session/connection.h index 4e157e2b4..559804606 100644 --- a/base-hw/include/cpu_session/connection.h +++ b/base-hw/include/cpu_session/connection.h @@ -31,10 +31,11 @@ namespace Genode { * \param priority designated priority of all threads created * with this CPU session */ - Cpu_connection(const char *label = "", long priority = DEFAULT_PRIORITY) + Cpu_connection(const char *label = "", long priority = DEFAULT_PRIORITY, + Affinity const &affinity = Affinity()) : Connection( - session("priority=0x%lx, ram_quota=128K, label=\"%s\"", + session(affinity, "priority=0x%lx, ram_quota=128K, label=\"%s\"", priority, label)), Cpu_session_client(cap()) { } }; diff --git a/base-linux/src/core/include/cpu_session_component.h b/base-linux/src/core/include/cpu_session_component.h index 015ab6d80..c6695f3ff 100644 --- a/base-linux/src/core/include/cpu_session_component.h +++ b/base-linux/src/core/include/cpu_session_component.h @@ -97,6 +97,8 @@ namespace Genode { unsigned _priority; /* priority of threads created with this session */ + Affinity::Location _location; /* CPU affinity of this + session */ /** * Exception handler that will be invoked unless overridden by a @@ -120,8 +122,9 @@ namespace Genode { * Constructor */ Cpu_session_component(Rpc_entrypoint *thread_ep, - Pager_entrypoint *pager_ep, - Allocator *md_alloc, const char *args); + Pager_entrypoint *pager_ep, + Allocator *md_alloc, const char *args, + Affinity const &affinity); /** * Destructor diff --git a/base-nova/src/core/include/cpu_session_component.h b/base-nova/src/core/include/cpu_session_component.h index 8d2f2d9f0..3662c6f0f 100644 --- a/base-nova/src/core/include/cpu_session_component.h +++ b/base-nova/src/core/include/cpu_session_component.h @@ -103,6 +103,8 @@ namespace Genode { unsigned _priority; /* priority of threads created with this session */ + Affinity::Location _location; /* CPU affinity of this + session */ /** * Exception handler that will be invoked unless overridden by a * call of 'Cpu_session::exception_handler'. @@ -125,8 +127,9 @@ namespace Genode { * Constructor */ Cpu_session_component(Rpc_entrypoint *thread_ep, - Pager_entrypoint *pager_ep, - Allocator *md_alloc, const char *args); + Pager_entrypoint *pager_ep, + Allocator *md_alloc, const char *args, + Affinity const &affinity); /** * Destructor diff --git a/base/src/core/cpu_session_component.cc b/base/src/core/cpu_session_component.cc index 94b9e5be9..18233bb95 100644 --- a/base/src/core/cpu_session_component.cc +++ b/base/src/core/cpu_session_component.cc @@ -182,7 +182,11 @@ Cpu_session_component::exception_handler(Thread_capability thread_cap, Affinity::Space Cpu_session_component::affinity_space() const { - return platform()->affinity_space(); + /* + * Return affinity subspace as constrained by the CPU session + * affinity. + */ + return Affinity::Space(_location.width(), _location.height()); } @@ -192,17 +196,35 @@ void Cpu_session_component::affinity(Thread_capability thread_cap, Object_pool::Guard thread(_thread_ep->lookup_and_lock(thread_cap)); if (!thread) return; - thread->platform_thread()->affinity(location); + /* convert session-local location to physical location */ + int const x1 = location.xpos() + _location.xpos(), + y1 = location.ypos() + _location.ypos(), + x2 = location.xpos() + location.width(), + y2 = location.ypos() + location.height(); + + int const clipped_x1 = max(_location.xpos(), x1), + clipped_y1 = max(_location.ypos(), y1), + clipped_x2 = max(_location.xpos() + (int)_location.width() - 1, x2), + clipped_y2 = max(_location.ypos() + (int)_location.height() - 1, y2); + + thread->platform_thread()->affinity(Affinity::Location(clipped_x1, clipped_y1, + clipped_x2 - clipped_x1 + 1, + clipped_y2 - clipped_y1 + 1)); } -Cpu_session_component::Cpu_session_component(Rpc_entrypoint *thread_ep, +Cpu_session_component::Cpu_session_component(Rpc_entrypoint *thread_ep, Pager_entrypoint *pager_ep, - Allocator *md_alloc, - const char *args) -: _thread_ep(thread_ep), _pager_ep(pager_ep), - _md_alloc(md_alloc, Arg_string::find_arg(args, "ram_quota").long_value(0)), - _thread_alloc(&_md_alloc), _priority(0) + Allocator *md_alloc, + char const *args, + Affinity const &affinity) +: + _thread_ep(thread_ep), _pager_ep(pager_ep), + _md_alloc(md_alloc, Arg_string::find_arg(args, "ram_quota").long_value(0)), + _thread_alloc(&_md_alloc), _priority(0), + + /* map affinity to a location within the physical affinity space */ + _location(affinity.scale_to(platform()->affinity_space())) { Arg a = Arg_string::find_arg(args, "priority"); if (a.valid()) { diff --git a/base/src/core/include/cpu_root.h b/base/src/core/include/cpu_root.h index 74954502b..4b687ce2f 100644 --- a/base/src/core/include/cpu_root.h +++ b/base/src/core/include/cpu_root.h @@ -32,9 +32,11 @@ namespace Genode { protected: - Cpu_session_component *_create_session(const char *args) { + Cpu_session_component *_create_session(char const *args, + Affinity const &affinity) { return new (md_alloc()) - Cpu_session_component(_thread_ep, _pager_ep, _md_alloc, args); } + Cpu_session_component(_thread_ep, _pager_ep, _md_alloc, + args, affinity); } void _upgrade_session(Cpu_session_component *cpu, const char *args) { diff --git a/base/src/core/include/cpu_session_component.h b/base/src/core/include/cpu_session_component.h index 3c71103c8..6668aef36 100644 --- a/base/src/core/include/cpu_session_component.h +++ b/base/src/core/include/cpu_session_component.h @@ -96,6 +96,8 @@ namespace Genode { unsigned _priority; /* priority of threads created with this session */ + Affinity::Location _location; /* CPU affinity of this + session */ /** * Exception handler that will be invoked unless overridden by a @@ -119,8 +121,9 @@ namespace Genode { * Constructor */ Cpu_session_component(Rpc_entrypoint *thread_ep, - Pager_entrypoint *pager_ep, - Allocator *md_alloc, const char *args); + Pager_entrypoint *pager_ep, + Allocator *md_alloc, const char *args, + Affinity const &); /** * Destructor