SST/macro
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
sstmac::sw::thread Class Referenceabstract

#include <thread.h>

Inheritance diagram for sstmac::sw::thread:
Inheritance graph
Collaboration diagram for sstmac::sw::thread:
Collaboration graph

Public Types

enum  state {
  PENDING =0, INITIALIZED =1, ACTIVE =2, SUSPENDED =3,
  BLOCKED =4, CANCELED =5, DONE =6
}
 Help resolve deadlock situations. More...
 
typedef spkt_unordered_map< long, thread * > pthread_map_t
 

Public Member Functions

virtual std::string to_string () const
 
void set_api (thread *thr)
 
template<class T >
T * get_api ()
 
virtual appparent_app () const
 
virtual void clear_subthread_from_parent_app ()
 
virtual ~thread ()
 
state get_state () const
 Get current thread state. More...
 
virtual void init_perf_model_params (sprockit::sim_parameters *params)
 
app_id aid () const
 
task_id tid () const
 
void set_sid (software_id sid)
 
void spawn (thread *thr)
 
long init_id ()
 
long thread_id () const
 
void cancel ()
 This thread is not currently active - blocked on something However, some kill event happened and I never want to see this thread again. More...
 
bool is_canceled () const
 
virtual void kill ()
 
operating_systemos () const
 
app_launchenv () const
 
void * stack () const
 
size_t stacksize () const
 
void ** backtrace () const
 
int last_backtrace_nfxn () const
 
int backtrace_nfxn () const
 
void append_backtrace (void *fxn)
 
void pop_backtrace ()
 
void set_backtrace (void **bt)
 
void collect_backtrace (int nfxn)
 
void init_thread (int phyiscal_thread_id, threading_interface *tocopy, void *stack, int stacksize, operating_system *os, threading_interface *yield_to)
 
virtual void run ()=0
 Derived types need to override this method. More...
 
void start_thread (thread *thr)
 A convenience request to start a new thread. More...
 
void join ()
 
process_context get_process_context () const
 
keyschedule_key ()
 key used More...
 
bool is_initialized () const
 Test whether the current task has been initialized (activated) by a scheduler. More...
 
void register_lib (library *lib)
 
void set_affinity (int core)
 
void add_affinity (int core)
 
void zero_affinity ()
 
template<class T >
T & register_perf_ctr_variable (void *ptr)
 
void remove_perf_ctr_variable (void *ptr)
 
perf_counter_modelperf_ctr_model () const
 
void set_cpumask (uint64_t cpumask)
 
uint64_t cpumask () const
 
int active_core () const
 
void set_active_core (int core)
 
void set_pthread_map (pthread_map_t *threadmap)
 
void * get_tls_value (long thekey) const
 
void set_tls_value (long thekey, void *ptr)
 
timestamp now ()
 

Static Public Member Functions

static threadcurrent ()
 

Static Public Attributes

static const int no_core_affinity = -1
 
static const int no_socket_affinity = -1
 
static const int main_thread = -1
 
static const int nic_thread = -2
 
static const int rdma_thread = -3
 
static const app_id main_thread_aid
 
static const task_id main_thread_tid
 

Protected Member Functions

 thread ()
 
virtual api_get_api (const char *name)
 
void unregister_all_libs ()
 

Protected Attributes

spkt_unordered_map< std::string, api * > apis_
 
state state_
 Monitor state for deadlock detection. More...
 
operating_systemos_
 Each thread can only run under one OS/scheduler. More...
 
std::queue< key * > joiners_
 
appparent_app_
 
process_context p_txt_
 

Private Member Functions

void cleanup ()
 This should only ever be invoked by the delete thread event. More...
 

Static Private Member Functions

static void run_routine (void *threadptr)
 Run routine that defines the initial context for this task. More...
 

Private Attributes

bool isInit
 
void ** backtrace_
 
int bt_nfxn_
 
std::map< long, void * > tls_values_
 
pthread_map_tpthread_map_
 
int last_bt_collect_nfxn_
 
void * stack_
 The stack given to this thread. More...
 
size_t stacksize_
 The stacksize. More...
 
software_id sid_
 
long thread_id_
 
perf_counter_modelperf_model_
 
threading_interfacecontext_
 
keyschedule_key_
 This key gets used by the compute scheduler to delay this thread. More...
 
std::list< library * > pending_libs_
 
uint64_t cpumask_
 
int active_core_
 

Friends

class operating_system
 
class app
 
class delete_thread_event
 
apistatic_get_api (const char *name)
 

Detailed Description

Definition at line 42 of file thread.h.

Member Typedef Documentation

typedef spkt_unordered_map<long, thread*> sstmac::sw::thread::pthread_map_t

Definition at line 304 of file thread.h.

Member Enumeration Documentation

Help resolve deadlock situations.

Enumerator
PENDING 
INITIALIZED 
ACTIVE 
SUSPENDED 
BLOCKED 
CANCELED 
DONE 

Definition at line 50 of file thread.h.

Constructor & Destructor Documentation

virtual sstmac::sw::thread::~thread ( )
virtual
sstmac::sw::thread::thread ( )
protected

Referenced by set_pthread_map().

Member Function Documentation

virtual api* sstmac::sw::thread::_get_api ( const char *  name)
protectedvirtual

Reimplemented in sstmac::sw::app.

Referenced by get_api(), and set_pthread_map().

int sstmac::sw::thread::active_core ( ) const
inline

Definition at line 295 of file thread.h.

References active_core_.

void sstmac::sw::thread::add_affinity ( int  core)
inline

Definition at line 253 of file thread.h.

References cpumask_.

Referenced by set_affinity().

app_id sstmac::sw::thread::aid ( ) const
inline

Definition at line 116 of file thread.h.

References sstmac::sw::software_id::app_, and sid_.

void sstmac::sw::thread::append_backtrace ( void *  fxn)

Referenced by backtrace_nfxn().

void** sstmac::sw::thread::backtrace ( ) const
inline

Definition at line 178 of file thread.h.

References backtrace_.

int sstmac::sw::thread::backtrace_nfxn ( ) const
inline

Definition at line 188 of file thread.h.

References append_backtrace(), bt_nfxn_, and pop_backtrace().

Here is the call graph for this function:

void sstmac::sw::thread::cancel ( )
inline

This thread is not currently active - blocked on something However, some kill event happened and I never want to see this thread again.

Make sure the thread doesn't unblock and clean up all resources associated with the thread

Definition at line 147 of file thread.h.

References CANCELED, and state_.

void sstmac::sw::thread::cleanup ( )
private

This should only ever be invoked by the delete thread event.

This ensures that the thread is completely done being operated on It is now safe to free all resources (thread-local vars, etc)

Referenced by set_pthread_map().

virtual void sstmac::sw::thread::clear_subthread_from_parent_app ( )
virtual

Reimplemented in sstmac::sw::app, and sstmac::sw::pthread_runner.

Referenced by parent_app().

void sstmac::sw::thread::collect_backtrace ( int  nfxn)

Referenced by set_backtrace().

uint64_t sstmac::sw::thread::cpumask ( ) const
inline

Definition at line 290 of file thread.h.

References cpumask_.

Referenced by set_cpumask().

static thread* sstmac::sw::thread::current ( )
static

Referenced by set_api().

app_launch* sstmac::sw::thread::env ( ) const

Referenced by os().

template<class T >
T* sstmac::sw::thread::get_api ( )
inline

Definition at line 75 of file thread.h.

References _get_api(), and spkt_throw_printf.

Here is the call graph for this function:

process_context sstmac::sw::thread::get_process_context ( ) const
inline

Definition at line 223 of file thread.h.

References p_txt_.

state sstmac::sw::thread::get_state ( ) const
inline

Get current thread state.

Definition at line 109 of file thread.h.

References init_perf_model_params(), and state_.

Here is the call graph for this function:

void* sstmac::sw::thread::get_tls_value ( long  thekey) const

Referenced by set_pthread_map().

long sstmac::sw::thread::init_id ( )

Referenced by set_sid().

virtual void sstmac::sw::thread::init_perf_model_params ( sprockit::sim_parameters *  params)
virtual

Referenced by get_state().

void sstmac::sw::thread::init_thread ( int  phyiscal_thread_id,
threading_interface tocopy,
void *  stack,
int  stacksize,
operating_system os,
threading_interface yield_to 
)

Referenced by set_backtrace().

bool sstmac::sw::thread::is_canceled ( ) const
inline

Definition at line 152 of file thread.h.

References CANCELED, kill(), and state_.

Here is the call graph for this function:

bool sstmac::sw::thread::is_initialized ( ) const
inline

Test whether the current task has been initialized (activated) by a scheduler.

Definition at line 239 of file thread.h.

References INITIALIZED, register_lib(), and state_.

Here is the call graph for this function:

void sstmac::sw::thread::join ( )

Referenced by set_backtrace().

virtual void sstmac::sw::thread::kill ( )
virtual

Reimplemented in sstmac::sw::app.

Referenced by is_canceled().

int sstmac::sw::thread::last_backtrace_nfxn ( ) const
inline

Definition at line 183 of file thread.h.

References last_bt_collect_nfxn_.

timestamp sstmac::sw::thread::now ( )

Referenced by set_pthread_map().

operating_system* sstmac::sw::thread::os ( ) const
inline

Definition at line 160 of file thread.h.

References env(), and os_.

Referenced by set_backtrace().

Here is the call graph for this function:

virtual app* sstmac::sw::thread::parent_app ( ) const
inlinevirtual

Reimplemented in sstmac::sw::app.

Definition at line 87 of file thread.h.

References clear_subthread_from_parent_app(), and parent_app_.

Here is the call graph for this function:

perf_counter_model* sstmac::sw::thread::perf_ctr_model ( ) const
inline

Definition at line 280 of file thread.h.

References perf_model_.

void sstmac::sw::thread::pop_backtrace ( )

Referenced by backtrace_nfxn().

void sstmac::sw::thread::register_lib ( library lib)

Referenced by is_initialized().

template<class T >
T& sstmac::sw::thread::register_perf_ctr_variable ( void *  ptr)
inline

Definition at line 264 of file thread.h.

References perf_model_, sstmac::sw::perf_counter_model::register_variable(), and spkt_throw.

Here is the call graph for this function:

void sstmac::sw::thread::remove_perf_ctr_variable ( void *  ptr)
inline

Definition at line 275 of file thread.h.

References perf_model_, and sstmac::sw::perf_counter_model::remove_variable().

Referenced by Variable< T >::~Variable(), and VariablePtr< T >::~VariablePtr().

Here is the call graph for this function:

virtual void sstmac::sw::thread::run ( )
pure virtual

Derived types need to override this method.

Implemented in sstmac::sw::app, sstmac::sw::pthread_runner, and sstmac::sumi_thread.

Referenced by set_backtrace().

static void sstmac::sw::thread::run_routine ( void *  threadptr)
staticprivate

Run routine that defines the initial context for this task.

This routine calls the virtual thread::run method.

Referenced by set_pthread_map().

key* sstmac::sw::thread::schedule_key ( )
inline

key used

Returns

Definition at line 232 of file thread.h.

References schedule_key_.

void sstmac::sw::thread::set_active_core ( int  core)
inline

Definition at line 300 of file thread.h.

References active_core_.

void sstmac::sw::thread::set_affinity ( int  core)
inline

Definition at line 247 of file thread.h.

References add_affinity(), and zero_affinity().

Here is the call graph for this function:

void sstmac::sw::thread::set_api ( thread thr)
inline

Definition at line 66 of file thread.h.

References apis_, and current().

Here is the call graph for this function:

void sstmac::sw::thread::set_backtrace ( void **  bt)
inline

Definition at line 199 of file thread.h.

References backtrace_, collect_backtrace(), init_thread(), join(), os(), run(), stack(), stacksize(), and start_thread().

Here is the call graph for this function:

void sstmac::sw::thread::set_cpumask ( uint64_t  cpumask)
inline

Definition at line 285 of file thread.h.

References cpumask(), and cpumask_.

Here is the call graph for this function:

void sstmac::sw::thread::set_pthread_map ( pthread_map_t threadmap)
inline

Definition at line 306 of file thread.h.

References _get_api(), cleanup(), get_tls_value(), now(), pthread_map_, run_routine(), set_tls_value(), static_get_api, thread(), and unregister_all_libs().

Here is the call graph for this function:

void sstmac::sw::thread::set_sid ( software_id  sid)
inline

Definition at line 125 of file thread.h.

References init_id(), sid_, and spawn().

Here is the call graph for this function:

void sstmac::sw::thread::set_tls_value ( long  thekey,
void *  ptr 
)

Referenced by set_pthread_map().

void sstmac::sw::thread::spawn ( thread thr)

Referenced by set_sid().

void* sstmac::sw::thread::stack ( ) const
inline

Definition at line 168 of file thread.h.

References stack_.

Referenced by set_backtrace().

size_t sstmac::sw::thread::stacksize ( ) const
inline

Definition at line 173 of file thread.h.

References stacksize_.

Referenced by set_backtrace().

void sstmac::sw::thread::start_thread ( thread thr)

A convenience request to start a new thread.

The current thread has to be initialized for this to work.

Referenced by set_backtrace().

long sstmac::sw::thread::thread_id ( ) const
inline

Definition at line 136 of file thread.h.

References thread_id_.

task_id sstmac::sw::thread::tid ( ) const
inline

Definition at line 120 of file thread.h.

References sid_, and sstmac::sw::software_id::task_.

virtual std::string sstmac::sw::thread::to_string ( ) const
inlinevirtual

Reimplemented in sumi::parsedumpi.

Definition at line 61 of file thread.h.

void sstmac::sw::thread::unregister_all_libs ( )
protected

Referenced by set_pthread_map().

void sstmac::sw::thread::zero_affinity ( )
inline

Definition at line 258 of file thread.h.

References cpumask_.

Referenced by set_affinity().

Friends And Related Function Documentation

friend class app
friend

Definition at line 46 of file thread.h.

friend class delete_thread_event
friend

Definition at line 47 of file thread.h.

friend class operating_system
friend

Definition at line 45 of file thread.h.

api* static_get_api ( const char *  name)
friend

Referenced by set_pthread_map().

Member Data Documentation

int sstmac::sw::thread::active_core_
private

Definition at line 392 of file thread.h.

Referenced by active_core(), and set_active_core().

spkt_unordered_map<std::string, api*> sstmac::sw::thread::apis_
protected

Definition at line 344 of file thread.h.

Referenced by set_api().

void** sstmac::sw::thread::backtrace_
private

Definition at line 361 of file thread.h.

Referenced by backtrace(), and set_backtrace().

int sstmac::sw::thread::bt_nfxn_
private

Definition at line 363 of file thread.h.

Referenced by backtrace_nfxn().

threading_interface* sstmac::sw::thread::context_
private

Definition at line 382 of file thread.h.

uint64_t sstmac::sw::thread::cpumask_
private

Definition at line 390 of file thread.h.

Referenced by add_affinity(), cpumask(), set_cpumask(), and zero_affinity().

bool sstmac::sw::thread::isInit
private

Definition at line 359 of file thread.h.

std::queue<key*> sstmac::sw::thread::joiners_
protected

Definition at line 352 of file thread.h.

int sstmac::sw::thread::last_bt_collect_nfxn_
private

Definition at line 369 of file thread.h.

Referenced by last_backtrace_nfxn().

const int sstmac::sw::thread::main_thread = -1
static

Definition at line 96 of file thread.h.

const app_id sstmac::sw::thread::main_thread_aid
static

Definition at line 99 of file thread.h.

const task_id sstmac::sw::thread::main_thread_tid
static

Definition at line 100 of file thread.h.

const int sstmac::sw::thread::nic_thread = -2
static

Definition at line 97 of file thread.h.

const int sstmac::sw::thread::no_core_affinity = -1
static

Definition at line 94 of file thread.h.

const int sstmac::sw::thread::no_socket_affinity = -1
static

Definition at line 95 of file thread.h.

operating_system* sstmac::sw::thread::os_
protected

Each thread can only run under one OS/scheduler.

Definition at line 350 of file thread.h.

Referenced by os().

process_context sstmac::sw::thread::p_txt_
protected

Definition at line 356 of file thread.h.

Referenced by get_process_context().

app* sstmac::sw::thread::parent_app_
protected

Definition at line 354 of file thread.h.

Referenced by parent_app().

std::list<library*> sstmac::sw::thread::pending_libs_
private

Definition at line 388 of file thread.h.

perf_counter_model* sstmac::sw::thread::perf_model_
private

Definition at line 380 of file thread.h.

Referenced by perf_ctr_model(), register_perf_ctr_variable(), and remove_perf_ctr_variable().

pthread_map_t* sstmac::sw::thread::pthread_map_
private

Definition at line 367 of file thread.h.

Referenced by set_pthread_map().

const int sstmac::sw::thread::rdma_thread = -3
static

Definition at line 98 of file thread.h.

key* sstmac::sw::thread::schedule_key_
private

This key gets used by the compute scheduler to delay this thread.

Definition at line 386 of file thread.h.

Referenced by schedule_key().

software_id sstmac::sw::thread::sid_
private

Definition at line 376 of file thread.h.

Referenced by aid(), set_sid(), and tid().

void* sstmac::sw::thread::stack_
private

The stack given to this thread.

Definition at line 372 of file thread.h.

Referenced by stack().

size_t sstmac::sw::thread::stacksize_
private

The stacksize.

Definition at line 374 of file thread.h.

Referenced by stacksize().

state sstmac::sw::thread::state_
protected

Monitor state for deadlock detection.

Definition at line 347 of file thread.h.

Referenced by cancel(), get_state(), is_canceled(), and is_initialized().

long sstmac::sw::thread::thread_id_
private

Definition at line 378 of file thread.h.

Referenced by thread_id().

std::map<long, void*> sstmac::sw::thread::tls_values_
private

Definition at line 365 of file thread.h.


The documentation for this class was generated from the following file: