tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
txthread.hpp
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2011
3  * University of Rochester Department of Computer Science
4  * and
5  * Lehigh University Department of Computer Science and Engineering
6  *
7  * License: Modified BSD
8  * Please see the file LICENSE.RSTM for licensing information
9  */
10 
11 /**
12  * Definitions for a common environment for all our STM implementations.
13  * The TxThread object holds all the metadata that a thread needs.
14  *
15  * In addition, this file declares the thread-local pointer that a thread
16  * can use to access its TxThread object.
17  */
18 
19 #ifndef TXTHREAD_HPP__
20 #define TXTHREAD_HPP__
21 
22 #include "alt-license/rand_r_32.h"
23 #include "common/locks.hpp"
24 #include "common/ThreadLocal.hpp"
25 #include "stm/metadata.hpp"
26 #include "stm/WriteSet.hpp"
27 #include "stm/UndoLog.hpp"
28 #include "stm/ValueList.hpp"
29 #include "WBMMPolicy.hpp"
30 
31 namespace stm
32 {
33  /**
34  * The TxThread struct holds all of the metadata that a thread needs in
35  * order to use any of the STM algorithms we support. In the past, this
36  * class also had all global STM metadata as static fields, and had lots
37  * of methods to support the various STM implementations. This proved to
38  * be too cumbersome for some compilers, so we now use this simpler
39  * interface. This file can be included in application code without
40  * pulling in an obscene amount of STM-related function definitions.
41  *
42  * Unfortunately, we still have to pull in metadata.hpp :(
43  *
44  * NB: the order of fields has not been rigorously studied. It is very
45  * likely that a better order would improve performance.
46  */
47  struct TxThread
48  {
49  /*** THESE FIELDS DEAL WITH THE STM IMPLEMENTATIONS ***/
50  uint32_t id; // per thread id
51  uint32_t nesting_depth; // nesting; 0 == not in transaction
52  WBMMPolicy allocator; // buffer malloc/free
53  uint32_t num_commits; // stats counter: commits
54  uint32_t num_aborts; // stats counter: aborts
55  uint32_t num_restarts; // stats counter: restart()s
56  uint32_t num_ro; // stats counter: read-only commits
57  scope_t* volatile scope; // used to roll back; also flag for isTxnl
58  uintptr_t start_time; // start time of transaction
59  uintptr_t end_time; // end time of transaction
60  uintptr_t ts_cache; // last validation time
61  bool tmlHasLock; // is tml thread holding the lock
62  UndoLog undo_log; // etee undo log
63  ValueList vlist; // NOrec read log
64  WriteSet writes; // write set
65  OrecList r_orecs; // read set for orec STMs
66  OrecList locks; // list of all locks held by tx
67  id_version_t my_lock; // lock word for orec STMs
68  filter_t* wf; // write filter
69  filter_t* rf; // read filter
70  volatile uint32_t prio; // for priority
71  uint32_t consec_aborts; // count consec aborts
72  uint32_t seed; // for randomized backoff
73  RRecList myRRecs; // indices of rrecs I set
74  intptr_t order; // for stms that order txns eagerly
75  volatile uint32_t alive; // for STMs that allow remote abort
76  ByteLockList r_bytelocks; // list of all byte locks held for read
77  ByteLockList w_bytelocks; // all byte locks held for write
78  BitLockList r_bitlocks; // list of all bit locks held for read
79  BitLockList w_bitlocks; // list of all bit locks held for write
80  mcs_qnode_t* my_mcslock; // for MCS
81  uintptr_t valid_ts; // the validation timestamp for each tx
82  uintptr_t cm_ts; // the contention manager timestamp
83  filter_t* cf; // conflict filter (RingALA)
84  NanorecList nanorecs; // list of nanorecs held
85  uint32_t consec_commits;// count consec commits
86  toxic_t abort_hist; // for counting poison
87  uint32_t begin_wait; // how long did last tx block at begin
88  bool strong_HG; // for strong hourglass
89  bool irrevocable; // tells begin_blocker that I'm THE ONE
90 
91  /*** PER-THREAD FIELDS FOR ENABLING ADAPTIVITY POLICIES */
92  uint64_t end_txn_time; // end of non-transactional work
93  uint64_t total_nontxn_time; // time on non-transactional work
94 
95  /*** POINTERS TO INSTRUMENTATION */
96 
97  /**
98  * The read/write/commit instrumentation is reached via per-thread
99  * function pointers, which can be exchanged easily during execution.
100  *
101  * The begin function is not a per-thread pointer, and thus we can use
102  * it for synchronization. This necessitates it being volatile.
103  *
104  * The other function pointers can be overwritten by remote threads,
105  * but that the synchronization when using the begin() function avoids
106  * the need for those pointers to be volatile.
107  */
108 
109  /**
110  * The global pointer for starting transactions. The return value should
111  * be true if the transaction was started as irrevocable, the caller can
112  * use this return to execute completely uninstrumented code if it's
113  * available.
114  */
115  static TM_FASTCALL bool(*volatile tmbegin)(TxThread*);
116 
117  /*** Per-thread commit, read, and write pointers */
119  TM_FASTCALL void*(*tmread)(STM_READ_SIG(,,));
121 
122  /**
123  * Some APIs, in particular the itm API at the moment, want to be able
124  * to rollback the top level of nesting without actually unwinding the
125  * stack. Rollback behavior changes per-implementation (some, such as
126  * CGL, can't rollback) so we add it here.
127  */
128  static scope_t* (*tmrollback)(STM_ROLLBACK_SIG(,,,));
129 
130  /**
131  * The function for aborting a transaction. The "tmabort" function is
132  * designed as a configurable function pointer so that an API environment
133  * like the itm shim can override the conflict abort behavior of the
134  * system. tmabort is configured using sys_init.
135  *
136  * Some advanced APIs may not want a NORETURN abort function, but the stm
137  * library at the moment only handles this option.
138  */
139  static NORETURN void (*tmabort)(TxThread*);
140 
141  /*** how to become irrevocable in-flight */
142  static bool(*tmirrevoc)(STM_IRREVOC_SIG(,));
143 
144  /**
145  * for shutting down threads. Currently a no-op.
146  */
147  static void thread_shutdown() { }
148 
149  /**
150  * the init factory. Construction of TxThread objects is only possible
151  * through this function. Note, too, that destruction is forbidden.
152  */
153  static void thread_init();
154  protected:
155  TxThread();
156  ~TxThread() { }
157  }; // class TxThread
158 
159  /*** GLOBAL VARIABLES RELATED TO THREAD MANAGEMENT */
160  extern THREAD_LOCAL_DECL_TYPE(TxThread*) Self; // this thread's TxThread
161 
162 } // namespace stm
163 
164 #endif // TXTHREAD_HPP__
#define STM_WRITE_SIG(tx, addr, val, mask)
Definition: macros.hpp:85
OrecList locks
Definition: txthread.hpp:66
TxThread()
Definition: txthread.cpp:62
bool strong_HG
Definition: txthread.hpp:88
uint32_t begin_wait
Definition: txthread.hpp:87
volatile uint32_t prio
Definition: txthread.hpp:70
static bool(* tmirrevoc)(STM_IRREVOC_SIG(,))
Definition: txthread.hpp:142
NanorecList nanorecs
Definition: txthread.hpp:84
Definition: stm_fraser.c:61
mcs_qnode_t * my_mcslock
Definition: txthread.hpp:80
static void thread_init()
Definition: txthread.cpp:177
uint32_t id
Definition: txthread.hpp:50
THREAD_LOCAL_DECL_TYPE(TxThread *) Self
#define STM_READ_SIG(tx, addr, mask)
Definition: macros.hpp:84
uint32_t seed
Definition: txthread.hpp:72
uintptr_t cm_ts
Definition: txthread.hpp:82
static NORETURN void(* tmabort)(TxThread *)
Definition: txthread.hpp:139
BitLockList r_bitlocks
Definition: txthread.hpp:78
Definition: metadata.hpp:231
#define STM_IRREVOC_SIG(tx, stack)
Definition: macros.hpp:93
ValueList vlist
Definition: txthread.hpp:63
BitLockList w_bitlocks
Definition: txthread.hpp:79
scope_t *volatile scope
Definition: txthread.hpp:57
Definition: ValueList.hpp:118
Definition: UndoLog.hpp:177
RRecList myRRecs
Definition: txthread.hpp:73
uint64_t end_txn_time
Definition: txthread.hpp:92
uint32_t num_ro
Definition: txthread.hpp:56
uint32_t num_aborts
Definition: txthread.hpp:54
TM_FASTCALL void(* tmcommit)(STM_COMMIT_SIG(,))
Definition: txthread.hpp:118
toxic_t abort_hist
Definition: txthread.hpp:86
#define STM_COMMIT_SIG(tx, stack)
Definition: macros.hpp:92
void scope_t
Definition: metadata.hpp:39
WBMMPolicy allocator
Definition: txthread.hpp:52
ByteLockList r_bytelocks
Definition: txthread.hpp:76
Definition: WriteSet.hpp:251
uintptr_t valid_ts
Definition: txthread.hpp:81
Definition: WBMMPolicy.hpp:70
uint64_t total_nontxn_time
Definition: txthread.hpp:93
uint32_t num_commits
Definition: txthread.hpp:53
intptr_t order
Definition: txthread.hpp:74
uint32_t consec_aborts
Definition: txthread.hpp:71
uint32_t nesting_depth
Definition: txthread.hpp:51
filter_t * wf
Definition: txthread.hpp:68
uintptr_t ts_cache
Definition: txthread.hpp:60
Definition: txthread.hpp:47
UndoLog undo_log
Definition: txthread.hpp:62
filter_t * cf
Definition: txthread.hpp:83
OrecList r_orecs
Definition: txthread.hpp:65
uint32_t num_restarts
Definition: txthread.hpp:55
id_version_t my_lock
Definition: txthread.hpp:67
uintptr_t end_time
Definition: txthread.hpp:59
uint32_t consec_commits
Definition: txthread.hpp:85
WriteSet writes
Definition: txthread.hpp:64
#define STM_ROLLBACK_SIG(tx, stack, exception, len)
Definition: macros.hpp:106
Definition: metadata.hpp:51
TM_FASTCALL void(* tmwrite)(STM_WRITE_SIG(,,,))
Definition: txthread.hpp:120
static TM_FASTCALL bool(*volatile tmbegin)(TxThread *)
Definition: txthread.hpp:115
filter_t * rf
Definition: txthread.hpp:69
volatile uint32_t alive
Definition: txthread.hpp:75
~TxThread()
Definition: txthread.hpp:156
uintptr_t start_time
Definition: txthread.hpp:58
bool tmlHasLock
Definition: txthread.hpp:61
ByteLockList w_bytelocks
Definition: txthread.hpp:77
Definition: BitFilter.hpp:36
Definition: locks.hpp:112
static void thread_shutdown()
Definition: txthread.hpp:147
#define NORETURN
Definition: platform.hpp:47
bool irrevocable
Definition: txthread.hpp:89
#define TM_FASTCALL
Definition: platform.hpp:85