2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Core-specific instance of the CPU session/thread interfaces
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2006-07-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_
|
|
|
|
#define _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/list.h>
|
|
|
|
#include <base/allocator_guard.h>
|
|
|
|
#include <base/lock.h>
|
|
|
|
#include <base/pager.h>
|
|
|
|
#include <base/rpc_server.h>
|
|
|
|
#include <cpu_session/cpu_session.h>
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
/* core includes */
|
2012-05-28 16:57:09 +02:00
|
|
|
#include <cpu_thread_allocator.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <platform_thread.h>
|
2013-08-10 03:44:55 +02:00
|
|
|
#include <trace/control_area.h>
|
|
|
|
#include <trace/source_registry.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RPC interface of CPU thread
|
|
|
|
*
|
|
|
|
* We make 'Cpu_thread' a RPC object only to be able to lookup CPU threads
|
|
|
|
* from thread capabilities supplied as arguments to CPU-session functions.
|
|
|
|
* A CPU thread does not provide an actual RPC interface.
|
|
|
|
*/
|
|
|
|
struct Cpu_thread
|
|
|
|
{
|
|
|
|
GENODE_RPC_INTERFACE();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Cpu_thread_component : public Rpc_object<Cpu_thread>,
|
|
|
|
public List<Cpu_thread_component>::Element
|
|
|
|
{
|
2013-08-10 03:44:55 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
typedef Trace::Session_label Session_label;
|
|
|
|
typedef Trace::Thread_name Thread_name;
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
private:
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
Thread_name const _name;
|
2013-01-03 20:29:18 +01:00
|
|
|
Platform_thread _platform_thread;
|
|
|
|
bool _bound; /* pd binding flag */
|
|
|
|
Signal_context_capability _sigh; /* exception handler */
|
2013-08-10 03:44:55 +02:00
|
|
|
unsigned const _trace_control_index;
|
|
|
|
Trace::Source _trace_source;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
Cpu_thread_component(Session_label const &label,
|
|
|
|
Thread_name const &name,
|
|
|
|
unsigned priority, addr_t utcb,
|
|
|
|
Signal_context_capability sigh,
|
|
|
|
unsigned trace_control_index,
|
|
|
|
Trace::Control &trace_control)
|
2013-01-03 20:29:18 +01:00
|
|
|
:
|
2013-08-10 03:44:55 +02:00
|
|
|
_name(name),
|
|
|
|
_platform_thread(name.string(), priority, utcb), _bound(false),
|
|
|
|
_sigh(sigh), _trace_control_index(trace_control_index),
|
|
|
|
_trace_source(label, _name, trace_control)
|
2013-01-03 20:29:18 +01:00
|
|
|
{
|
|
|
|
update_exception_sigh();
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
** Accessor functions **
|
|
|
|
************************/
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
Platform_thread *platform_thread() { return &_platform_thread; }
|
|
|
|
bool bound() const { return _bound; }
|
|
|
|
void bound(bool b) { _bound = b; }
|
|
|
|
Trace::Source *trace_source() { return &_trace_source; }
|
2013-01-03 20:29:18 +01:00
|
|
|
|
|
|
|
void sigh(Signal_context_capability sigh)
|
|
|
|
{
|
2013-01-11 22:14:59 +01:00
|
|
|
_sigh = sigh;
|
2013-01-03 20:29:18 +01:00
|
|
|
update_exception_sigh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Propagate exception handler to platform thread
|
|
|
|
*/
|
|
|
|
void update_exception_sigh();
|
2013-08-10 03:44:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return index within the CPU-session's trace control area
|
|
|
|
*/
|
|
|
|
unsigned trace_control_index() const { return _trace_control_index; }
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Cpu_session_component : public Rpc_object<Cpu_session>
|
|
|
|
{
|
2013-08-10 03:44:55 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
typedef Cpu_thread_component::Session_label Session_label;
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
private:
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
Session_label _label;
|
2011-12-22 16:19:25 +01:00
|
|
|
Rpc_entrypoint *_thread_ep;
|
|
|
|
Pager_entrypoint *_pager_ep;
|
|
|
|
Allocator_guard _md_alloc; /* guarded meta-data allocator */
|
2012-05-28 16:57:09 +02:00
|
|
|
Cpu_thread_allocator _thread_alloc; /* meta-data allocator */
|
|
|
|
Lock _thread_alloc_lock; /* protect allocator access */
|
2011-12-22 16:19:25 +01:00
|
|
|
List<Cpu_thread_component> _thread_list;
|
|
|
|
Lock _thread_list_lock; /* protect thread list */
|
|
|
|
unsigned _priority; /* priority of threads
|
|
|
|
created with this
|
|
|
|
session */
|
2013-08-08 14:44:00 +02:00
|
|
|
Affinity::Location _location; /* CPU affinity of this
|
|
|
|
session */
|
2013-08-10 03:44:55 +02:00
|
|
|
Trace::Source_registry &_trace_sources;
|
|
|
|
Trace::Control_area _trace_control_area;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-01-03 20:29:18 +01:00
|
|
|
/**
|
|
|
|
* Exception handler that will be invoked unless overridden by a
|
|
|
|
* call of 'Cpu_session::exception_handler'.
|
|
|
|
*/
|
|
|
|
Signal_context_capability _default_exception_handler;
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/**
|
|
|
|
* Raw thread-killing functionality
|
|
|
|
*
|
|
|
|
* This function is called from the 'kill_thread' function and
|
|
|
|
* the destructor. Each these functions grab the list lock
|
|
|
|
* by themselves and call this function to perform the actual
|
|
|
|
* killing.
|
|
|
|
*/
|
|
|
|
void _unsynchronized_kill_thread(Cpu_thread_component *thread);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2013-08-10 03:44:55 +02:00
|
|
|
Cpu_session_component(Rpc_entrypoint *thread_ep,
|
|
|
|
Pager_entrypoint *pager_ep,
|
|
|
|
Allocator *md_alloc,
|
|
|
|
Trace::Source_registry &trace_sources,
|
|
|
|
const char *args, Affinity const &affinity);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Cpu_session_component();
|
|
|
|
|
2012-11-29 16:48:12 +01:00
|
|
|
/**
|
|
|
|
* Register quota donation at allocator guard
|
|
|
|
*/
|
|
|
|
void upgrade_ram_quota(size_t ram_quota) { _md_alloc.upgrade(ram_quota); }
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/***************************
|
|
|
|
** CPU session interface **
|
|
|
|
***************************/
|
|
|
|
|
2013-08-10 03:44:55 +02:00
|
|
|
Thread_capability create_thread(Name const &, addr_t);
|
2012-05-28 16:57:09 +02:00
|
|
|
Ram_dataspace_capability utcb(Thread_capability thread);
|
2011-12-22 16:19:25 +01:00
|
|
|
void kill_thread(Thread_capability);
|
|
|
|
int set_pager(Thread_capability, Pager_capability);
|
|
|
|
int start(Thread_capability, addr_t, addr_t);
|
|
|
|
void pause(Thread_capability thread_cap);
|
|
|
|
void resume(Thread_capability thread_cap);
|
|
|
|
void cancel_blocking(Thread_capability);
|
|
|
|
int name(Thread_capability, char *, size_t);
|
2012-11-12 17:48:18 +01:00
|
|
|
Thread_state state(Thread_capability);
|
|
|
|
void state(Thread_capability, Thread_state const &);
|
2011-12-22 16:19:25 +01:00
|
|
|
void exception_handler(Thread_capability, Signal_context_capability);
|
2013-08-07 22:16:58 +02:00
|
|
|
Affinity::Space affinity_space() const;
|
|
|
|
void affinity(Thread_capability, Affinity::Location);
|
2013-08-09 11:11:03 +02:00
|
|
|
Dataspace_capability trace_control();
|
|
|
|
unsigned trace_control_index(Thread_capability);
|
|
|
|
Dataspace_capability trace_buffer(Thread_capability);
|
|
|
|
Dataspace_capability trace_policy(Thread_capability);
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__CPU_SESSION_COMPONENT_H_ */
|