2 * @brief Model-checker core
5 #ifndef __EXECUTION_H__
6 #define __EXECUTION_H__
12 #include "hashtable.h"
14 #include "modeltypes.h"
15 #include "stl-model.h"
17 #include "mypthread.h"
19 #include <condition_variable>
20 #include "classlist.h"
22 /** @brief Shorthand for a list of release sequence heads */
23 typedef ModelVector<const ModelAction *> rel_heads_list_t;
24 typedef SnapList<ModelAction *> action_list_t;
26 struct PendingFutureValue {
27 PendingFutureValue(ModelAction *writer, ModelAction *reader) :
28 writer(writer), reader(reader)
30 const ModelAction *writer;
34 /** @brief Records information regarding a single pending release sequence */
36 /** @brief The acquire operation */
38 /** @brief The read operation that may read from a release sequence;
39 * may be the same as acquire, or else an earlier action in the same
40 * thread (i.e., when 'acquire' is a fence-acquire) */
41 const ModelAction *read;
42 /** @brief The head of the RMW chain from which 'read' reads; may be
43 * equal to 'release' */
44 const ModelAction *rf;
45 /** @brief The head of the potential longest release sequence chain */
46 const ModelAction *release;
47 /** @brief The write(s) that may break the release sequence */
48 SnapVector<const ModelAction *> writes;
51 /** @brief The central structure for model-checking */
52 class ModelExecution {
54 ModelExecution(ModelChecker *m,
56 NodeStack *node_stack);
59 struct model_params * get_params() const { return params; }
60 void setParams(struct model_params * _params) {params = _params;}
62 Thread * take_step(ModelAction *curr);
64 void print_summary() const;
65 #if SUPPORT_MOD_ORDER_DUMP
66 void dumpGraph(char *filename) const;
69 void add_thread(Thread *t);
70 Thread * get_thread(thread_id_t tid) const;
71 Thread * get_thread(const ModelAction *act) const;
73 uint32_t get_pthread_counter() { return pthread_counter; }
74 void incr_pthread_counter() { pthread_counter++; }
75 Thread * get_pthread(pthread_t pid);
77 bool is_enabled(Thread *t) const;
78 bool is_enabled(thread_id_t tid) const;
80 thread_id_t get_next_id();
81 unsigned int get_num_threads() const;
83 ClockVector * get_cv(thread_id_t tid) const;
84 ModelAction * get_parent_action(thread_id_t tid) const;
85 bool isfeasibleprefix() const;
87 action_list_t * get_actions_on_obj(void * obj, thread_id_t tid) const;
88 ModelAction * get_last_action(thread_id_t tid) const;
90 bool check_action_enabled(ModelAction *curr);
92 bool assert_bug(const char *msg);
93 bool have_bug_reports() const;
94 SnapVector<bug_message *> * get_bugs() const;
96 bool has_asserted() const;
98 bool is_complete_execution() const;
100 void print_infeasibility(const char *prefix) const;
101 bool is_infeasible() const;
102 bool is_deadlocked() const;
104 action_list_t * get_action_trace() { return &action_trace; }
105 Fuzzer * getFuzzer();
106 CycleGraph * const get_mo_graph() { return mo_graph; }
107 HashTable<pthread_cond_t *, cdsc::condition_variable *, uintptr_t, 4> * getCondMap() {return &cond_map;}
108 HashTable<pthread_mutex_t *, cdsc::mutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
112 int get_execution_number() const;
116 struct model_params * params;
118 /** The scheduler to use: tracks the running/ready Threads */
119 Scheduler * const scheduler;
121 bool mo_may_allow(const ModelAction *writer, const ModelAction *reader);
122 void set_bad_synchronization();
123 void set_bad_sc_read();
124 bool should_wake_up(const ModelAction *curr, const Thread *thread) const;
125 void wake_up_sleeping_actions(ModelAction *curr);
126 modelclock_t get_next_seq_num();
128 bool next_execution();
129 ModelAction * check_current_action(ModelAction *curr);
130 bool initialize_curr_action(ModelAction **curr);
131 bool process_read(ModelAction *curr, ModelVector<ModelAction *> * rf_set);
132 bool process_write(ModelAction *curr);
133 bool process_fence(ModelAction *curr);
134 bool process_mutex(ModelAction *curr);
136 bool process_thread_action(ModelAction *curr);
137 bool read_from(ModelAction *act, const ModelAction *rf);
138 bool synchronize(const ModelAction *first, ModelAction *second);
140 void add_action_to_lists(ModelAction *act);
141 ModelAction * get_last_fence_release(thread_id_t tid) const;
142 ModelAction * get_last_seq_cst_write(ModelAction *curr) const;
143 ModelAction * get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const;
144 ModelAction * get_last_unlock(ModelAction *curr) const;
145 ModelVector<ModelAction *> * build_may_read_from(ModelAction *curr);
146 ModelAction * process_rmw(ModelAction *curr);
148 template <typename rf_type>
149 bool r_modification_order(ModelAction *curr, const rf_type *rf);
151 bool w_modification_order(ModelAction *curr);
152 void get_release_seq_heads(ModelAction *acquire, ModelAction *read, rel_heads_list_t *release_heads);
153 bool release_seq_heads(const ModelAction *rf, rel_heads_list_t *release_heads) const;
154 ModelAction * get_uninitialized_action(const ModelAction *curr) const;
156 action_list_t action_trace;
157 SnapVector<Thread *> thread_map;
158 SnapVector<Thread *> pthread_map;
159 uint32_t pthread_counter;
161 /** Per-object list of actions. Maps an object (i.e., memory location)
162 * to a trace of all actions performed on the object. */
163 HashTable<const void *, action_list_t *, uintptr_t, 4> obj_map;
165 /** Per-object list of actions. Maps an object (i.e., memory location)
166 * to a trace of all actions performed on the object. */
167 HashTable<const void *, action_list_t *, uintptr_t, 4> condvar_waiters_map;
169 HashTable<void *, SnapVector<action_list_t> *, uintptr_t, 4> obj_thrd_map;
171 HashTable<pthread_mutex_t *, cdsc::mutex *, uintptr_t, 4> mutex_map;
172 HashTable<pthread_cond_t *, cdsc::condition_variable *, uintptr_t, 4> cond_map;
175 * List of pending release sequences. Release sequences might be
176 * determined lazily as promises are fulfilled and modification orders
177 * are established. Each entry in the list may only be partially
178 * filled, depending on its pending status.
181 SnapVector<ModelAction *> thrd_last_action;
182 SnapVector<ModelAction *> thrd_last_fence_release;
183 NodeStack * const node_stack;
185 /** A special model-checker Thread; used for associating with
186 * model-checker-related ModelAcitons */
187 Thread *model_thread;
189 /** Private data members that should be snapshotted. They are grouped
190 * together for efficiency and maintainability. */
191 struct model_snapshot_members * const priv;
194 * @brief The modification order graph
196 * A directed acyclic graph recording observations of the modification
197 * order on all the atomic objects in the system. This graph should
198 * never contain any cycles, as that represents a violation of the
199 * memory model (total ordering). This graph really consists of many
200 * disjoint (unconnected) subgraphs, each graph corresponding to a
201 * separate ordering on a distinct object.
203 * The edges in this graph represent the "ordered before" relation,
204 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
207 CycleGraph * const mo_graph;
211 Thread * action_select_next_thread(const ModelAction *curr) const;
214 #endif/* __EXECUTION_H__ */