2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Thread facility
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2009-10-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2009-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__PLATFORM_THREAD_H_
|
|
|
|
#define _CORE__INCLUDE__PLATFORM_THREAD_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread_state.h>
|
|
|
|
#include <base/native_types.h>
|
|
|
|
|
2013-03-08 11:54:12 +01:00
|
|
|
/* core includes */
|
2015-06-19 14:58:18 +02:00
|
|
|
#include <pager.h>
|
2013-03-08 11:54:12 +01:00
|
|
|
#include <address_space.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Platform_pd;
|
|
|
|
class Platform_thread
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend class Platform_pd;
|
|
|
|
|
|
|
|
enum { PD_NAME_MAX_LEN = 64 };
|
|
|
|
|
2013-03-08 11:54:12 +01:00
|
|
|
unsigned _tid; /* global codezero thread ID */
|
|
|
|
unsigned _space_id;
|
|
|
|
Weak_ptr<Address_space> _address_space;
|
|
|
|
addr_t _utcb;
|
|
|
|
char _name[PD_NAME_MAX_LEN];
|
|
|
|
Pager_object *_pager;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign physical thread ID and UTCB address to thread
|
|
|
|
*
|
|
|
|
* This function is called from 'Platform_pd::bind_thread'.
|
|
|
|
*/
|
2013-03-08 11:54:12 +01:00
|
|
|
void _assign_physical_thread(unsigned tid, unsigned space_id,
|
|
|
|
addr_t utcb,
|
|
|
|
Weak_ptr<Address_space> address_space)
|
|
|
|
{
|
|
|
|
_tid = tid; _space_id = space_id; _utcb = utcb;
|
|
|
|
_address_space = address_space;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum { THREAD_INVALID = -1 }; /* invalid thread number */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2014-10-16 11:15:46 +02:00
|
|
|
Platform_thread(size_t, const char *name = 0, unsigned priority = 0,
|
2012-05-28 16:57:09 +02:00
|
|
|
addr_t utcb = 0, int thread_id = THREAD_INVALID);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~Platform_thread();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start thread
|
|
|
|
*
|
|
|
|
* \param ip instruction pointer to start at
|
|
|
|
* \param sp stack pointer to use
|
|
|
|
* \param cpu_no target cpu
|
|
|
|
*
|
|
|
|
* \retval 0 successful
|
|
|
|
* \retval -1 thread could not be started
|
|
|
|
*/
|
|
|
|
int start(void *ip, void *sp, unsigned int cpu_no = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause this thread
|
|
|
|
*/
|
|
|
|
void pause();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resume this thread
|
|
|
|
*/
|
|
|
|
void resume();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel currently blocking operation
|
|
|
|
*/
|
|
|
|
void cancel_blocking();
|
|
|
|
|
|
|
|
/**
|
2012-11-12 17:48:18 +01:00
|
|
|
* Override thread state with 's'
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
2012-11-12 17:48:18 +01:00
|
|
|
* \throw Cpu_session::State_access_failed
|
|
|
|
*/
|
|
|
|
void state(Thread_state s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read thread state
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
2012-11-12 17:48:18 +01:00
|
|
|
* \throw Cpu_session::State_access_failed
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2012-11-12 17:48:18 +01:00
|
|
|
Thread_state state();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-03-08 11:54:12 +01:00
|
|
|
/**
|
|
|
|
* Return the address space to which the thread is bound
|
|
|
|
*/
|
|
|
|
Weak_ptr<Address_space> address_space();
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/************************
|
|
|
|
** Accessor functions **
|
|
|
|
************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set pager capability
|
|
|
|
*/
|
|
|
|
Pager_object *pager(Pager_object *pager) const { return _pager; }
|
|
|
|
void pager(Pager_object *pager) { _pager = pager; }
|
|
|
|
Pager_object *pager() { return _pager; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return identification of thread when faulting
|
|
|
|
*/
|
|
|
|
unsigned long pager_object_badge() const { return _tid; }
|
|
|
|
|
|
|
|
/**
|
2012-09-04 17:32:55 +02:00
|
|
|
* Set the executing CPU for this thread
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2013-08-07 22:16:58 +02:00
|
|
|
void affinity(Affinity::Location) { }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-07-09 15:58:06 +02:00
|
|
|
/**
|
|
|
|
* Get the executing CPU for this thread
|
|
|
|
*/
|
2015-06-11 23:05:02 +02:00
|
|
|
Affinity::Location affinity() const { return Affinity::Location(); }
|
2013-07-09 15:58:06 +02:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/**
|
|
|
|
* Get thread name
|
|
|
|
*/
|
|
|
|
const char *name() const { return "noname"; }
|
|
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
** Codezero specific **
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
addr_t utcb() const { return _utcb; }
|
2015-03-27 14:05:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set CPU quota of the thread to 'quota'
|
|
|
|
*/
|
|
|
|
void quota(size_t const quota) { /* not supported*/ }
|
2015-06-11 23:05:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return execution time consumed by the thread
|
|
|
|
*/
|
|
|
|
unsigned long long execution_time() const { return 0; }
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */
|