2016-05-10 16:05:38 +00:00
|
|
|
/*
|
|
|
|
* \brief CPU thread interface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2016-05-10
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
2016-05-10 16:05:38 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2016-05-10 16:05:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__CPU_THREAD__CPU_THREAD_H_
|
|
|
|
#define _INCLUDE__CPU_THREAD__CPU_THREAD_H_
|
|
|
|
|
|
|
|
#include <base/stdint.h>
|
|
|
|
#include <base/thread_state.h>
|
|
|
|
#include <base/signal.h>
|
|
|
|
#include <base/affinity.h>
|
|
|
|
#include <dataspace/capability.h>
|
|
|
|
|
|
|
|
namespace Genode { struct Cpu_thread; }
|
|
|
|
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
struct Genode::Cpu_thread : Interface
|
2016-05-10 16:05:38 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get dataspace of the thread's user-level thread-control block (UTCB)
|
|
|
|
*/
|
|
|
|
virtual Dataspace_capability utcb() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify instruction and stack pointer of thread - start the thread
|
|
|
|
*
|
|
|
|
* \param thread thread to start
|
|
|
|
* \param ip initial instruction pointer
|
|
|
|
* \param sp initial stack pointer
|
|
|
|
*/
|
|
|
|
virtual void start(addr_t ip, addr_t sp) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause the thread
|
|
|
|
*
|
|
|
|
* After calling this method, the execution of the thread can be
|
|
|
|
* continued by calling 'resume'.
|
|
|
|
*/
|
|
|
|
virtual void pause() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume the thread
|
|
|
|
*/
|
|
|
|
virtual void resume() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current thread state
|
|
|
|
*
|
|
|
|
* \return state of the targeted thread
|
|
|
|
*/
|
|
|
|
virtual Thread_state state() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the current thread state
|
|
|
|
*
|
|
|
|
* \param state state that shall be applied
|
|
|
|
*/
|
|
|
|
virtual void state(Thread_state const &state) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register signal handler for exceptions of the thread
|
|
|
|
*
|
|
|
|
* On Linux, this exception is delivered when the process triggers
|
|
|
|
* a SIGCHLD. On other platforms, this exception is delivered on
|
|
|
|
* the occurrence of CPU exceptions such as division by zero.
|
|
|
|
*/
|
|
|
|
virtual void exception_sigh(Signal_context_capability handler) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/disable single stepping
|
|
|
|
*
|
|
|
|
* Since this method is currently supported by a small number of
|
|
|
|
* platforms, we provide a default implementation
|
|
|
|
*
|
|
|
|
* \param enabled true = enable single-step mode; false = disable
|
|
|
|
*/
|
|
|
|
virtual void single_step(bool enabled) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define affinity of thread to one or multiple CPU nodes
|
|
|
|
*
|
|
|
|
* In the normal case, a thread is assigned to a single CPU. Specifying
|
|
|
|
* more than one CPU node is supposed to principally allow a CPU service to
|
|
|
|
* balance the load of threads among multiple CPUs.
|
|
|
|
*
|
|
|
|
* \param location location within the affinity space of the thread's
|
|
|
|
* CPU session
|
|
|
|
*/
|
|
|
|
virtual void affinity(Affinity::Location location) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request index within the trace control block of the thread's CPU session
|
|
|
|
*
|
|
|
|
* The trace control dataspace contains the control blocks for all threads
|
|
|
|
* of the CPU session. Each thread gets assigned a different index by the
|
|
|
|
* CPU service.
|
|
|
|
*/
|
|
|
|
virtual unsigned trace_control_index() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request trace buffer for the thread
|
|
|
|
*
|
|
|
|
* The trace buffer is not accounted to the CPU session. It is owned by a
|
|
|
|
* TRACE session.
|
|
|
|
*/
|
|
|
|
virtual Dataspace_capability trace_buffer() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request trace policy
|
|
|
|
*
|
|
|
|
* The trace policy buffer is not accounted to the CPU session. It is owned
|
|
|
|
* by a TRACE session.
|
|
|
|
*/
|
|
|
|
virtual Dataspace_capability trace_policy() = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
** RPC declaration **
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
GENODE_RPC(Rpc_utcb, Dataspace_capability, utcb);
|
|
|
|
GENODE_RPC(Rpc_start, void, start, addr_t, addr_t);
|
|
|
|
GENODE_RPC(Rpc_pause, void, pause);
|
|
|
|
GENODE_RPC(Rpc_resume, void, resume);
|
2024-06-17 13:25:28 +00:00
|
|
|
GENODE_RPC(Rpc_get_state, Thread_state, state);
|
|
|
|
GENODE_RPC(Rpc_set_state, void, state, Thread_state const &);
|
2016-05-10 16:05:38 +00:00
|
|
|
GENODE_RPC(Rpc_exception_sigh, void, exception_sigh, Signal_context_capability);
|
|
|
|
GENODE_RPC(Rpc_single_step, void, single_step, bool);
|
|
|
|
GENODE_RPC(Rpc_affinity, void, affinity, Affinity::Location);
|
|
|
|
GENODE_RPC(Rpc_trace_control_index, unsigned, trace_control_index);
|
|
|
|
GENODE_RPC(Rpc_trace_buffer, Dataspace_capability, trace_buffer);
|
|
|
|
GENODE_RPC(Rpc_trace_policy, Dataspace_capability, trace_policy);
|
|
|
|
|
2016-05-11 15:23:51 +00:00
|
|
|
GENODE_RPC_INTERFACE(Rpc_utcb, Rpc_start, Rpc_pause, Rpc_resume,
|
2020-07-06 14:09:44 +00:00
|
|
|
Rpc_set_state, Rpc_get_state,
|
2016-05-11 15:23:51 +00:00
|
|
|
Rpc_exception_sigh, Rpc_single_step, Rpc_affinity,
|
|
|
|
Rpc_trace_control_index, Rpc_trace_buffer,
|
|
|
|
Rpc_trace_policy);
|
2016-05-10 16:05:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__CPU_THREAD__CPU_THREAD_H_ */
|