core: evaluate CPU session affinity argument

This commit is contained in:
Norman Feske 2013-08-08 14:44:00 +02:00
parent 5ec07614e8
commit 35723d813d
7 changed files with 57 additions and 20 deletions

View File

@ -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

View File

@ -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<Cpu_session>(
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()) { }
};

View File

@ -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

View File

@ -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

View File

@ -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<Cpu_thread_component>::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()) {

View File

@ -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)
{

View File

@ -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