2 * @brief Model-checker core
5 #ifndef __EXECUTION_H__
6 #define __EXECUTION_H__
12 #include "hashtable.h"
13 #include "workqueue.h"
15 #include "modeltypes.h"
16 #include "stl-model.h"
20 /* Forward declaration */
28 struct model_snapshot_members;
32 /** @brief Shorthand for a list of release sequence heads */
33 typedef ModelVector<const ModelAction *> rel_heads_list_t;
34 typedef SnapList<ModelAction *> action_list_t;
36 struct PendingFutureValue {
37 PendingFutureValue(ModelAction *writer, ModelAction *reader) :
38 writer(writer), reader(reader)
40 const ModelAction *writer;
44 /** @brief Records information regarding a single pending release sequence */
46 /** @brief The acquire operation */
48 /** @brief The read operation that may read from a release sequence;
49 * may be the same as acquire, or else an earlier action in the same
50 * thread (i.e., when 'acquire' is a fence-acquire) */
51 const ModelAction *read;
52 /** @brief The head of the RMW chain from which 'read' reads; may be
53 * equal to 'release' */
54 const ModelAction *rf;
55 /** @brief The head of the potential longest release sequence chain */
56 const ModelAction *release;
57 /** @brief The write(s) that may break the release sequence */
58 SnapVector<const ModelAction *> writes;
61 /** @brief The central structure for model-checking */
62 class ModelExecution {
64 ModelExecution(struct model_params *params, Scheduler *scheduler, NodeStack *node_stack);
67 Thread * take_step(ModelAction *curr);
68 void fixup_release_sequences();
70 void print_summary() const;
71 #if SUPPORT_MOD_ORDER_DUMP
72 void dumpGraph(char *filename) const;
75 void add_thread(Thread *t);
76 Thread * get_thread(thread_id_t tid) const;
77 Thread * get_thread(const ModelAction *act) const;
78 int get_promise_number(const Promise *promise) const;
80 bool is_enabled(Thread *t) const;
81 bool is_enabled(thread_id_t tid) const;
83 thread_id_t get_next_id();
84 unsigned int get_num_threads() const;
86 ClockVector * get_cv(thread_id_t tid) const;
87 ModelAction * get_parent_action(thread_id_t tid) const;
88 void check_promises_thread_disabled();
89 bool isfeasibleprefix() const;
91 action_list_t * get_actions_on_obj(void * obj, thread_id_t tid) const;
92 ModelAction * get_last_action(thread_id_t tid) const;
94 bool check_action_enabled(ModelAction *curr);
96 bool assert_bug(const char *msg);
97 bool have_bug_reports() const;
98 SnapVector<bug_message *> * get_bugs() const;
100 bool has_asserted() const;
102 bool is_complete_execution() const;
104 void print_infeasibility(const char *prefix) const;
105 bool is_feasible_prefix_ignore_relseq() const;
106 bool is_infeasible() const;
107 bool is_deadlocked() const;
108 bool too_many_steps() const;
110 ModelAction * get_next_backtrack();
112 action_list_t * get_action_trace() const { return action_trace; }
114 void increment_execution_number() { execution_number++; }
118 const model_params * const params;
120 /** The scheduler to use: tracks the running/ready Threads */
121 Scheduler * const scheduler;
123 bool sleep_can_read_from(ModelAction *curr, const ModelAction *write);
124 bool thin_air_constraint_may_allow(const ModelAction *writer, const ModelAction *reader) const;
125 bool mo_may_allow(const ModelAction *writer, const ModelAction *reader);
126 bool promises_may_allow(const ModelAction *writer, const ModelAction *reader) const;
127 void set_bad_synchronization();
128 bool promises_expired() const;
129 bool should_wake_up(const ModelAction *curr, const Thread *thread) const;
130 void wake_up_sleeping_actions(ModelAction *curr);
131 modelclock_t get_next_seq_num();
133 bool next_execution();
134 ModelAction * check_current_action(ModelAction *curr);
135 bool initialize_curr_action(ModelAction **curr);
136 bool process_read(ModelAction *curr);
137 bool process_write(ModelAction *curr);
138 bool process_fence(ModelAction *curr);
139 bool process_mutex(ModelAction *curr);
140 bool process_thread_action(ModelAction *curr);
141 void process_relseq_fixup(ModelAction *curr, work_queue_t *work_queue);
142 bool read_from(ModelAction *act, const ModelAction *rf);
143 bool synchronize(const ModelAction *first, ModelAction *second);
145 template <typename T>
146 bool check_recency(ModelAction *curr, const T *rf) const;
148 template <typename T, typename U>
149 bool should_read_instead(const ModelAction *curr, const T *rf, const U *other_rf) const;
151 ModelAction * get_last_fence_conflict(ModelAction *act) const;
152 ModelAction * get_last_conflict(ModelAction *act) const;
153 void set_backtracking(ModelAction *act);
154 bool set_latest_backtrack(ModelAction *act);
155 Promise * pop_promise_to_resolve(const ModelAction *curr);
156 bool resolve_promise(ModelAction *curr, Promise *promise);
157 void compute_promises(ModelAction *curr);
158 void compute_relseq_breakwrites(ModelAction *curr);
160 void check_promises(thread_id_t tid, ClockVector *old_cv, ClockVector *merge_cv);
161 void mo_check_promises(const ModelAction *act, bool is_read_check);
162 void thread_blocking_check_promises(Thread *blocker, Thread *waiting);
164 void check_curr_backtracking(ModelAction *curr);
165 void add_action_to_lists(ModelAction *act);
166 ModelAction * get_last_fence_release(thread_id_t tid) const;
167 ModelAction * get_last_seq_cst_write(ModelAction *curr) const;
168 ModelAction * get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const;
169 ModelAction * get_last_unlock(ModelAction *curr) const;
170 void build_may_read_from(ModelAction *curr);
171 ModelAction * process_rmw(ModelAction *curr);
173 template <typename rf_type>
174 bool r_modification_order(ModelAction *curr, const rf_type *rf);
176 bool w_modification_order(ModelAction *curr, ModelVector<ModelAction *> *send_fv);
177 void get_release_seq_heads(ModelAction *acquire, ModelAction *read, rel_heads_list_t *release_heads);
178 bool release_seq_heads(const ModelAction *rf, rel_heads_list_t *release_heads, struct release_seq *pending) const;
179 bool resolve_release_sequences(void *location, work_queue_t *work_queue);
180 void add_future_value(const ModelAction *writer, ModelAction *reader);
182 ModelAction * get_uninitialized_action(const ModelAction *curr) const;
184 action_list_t * const action_trace;
185 HashTable<int, Thread *, int> * const thread_map;
187 /** Per-object list of actions. Maps an object (i.e., memory location)
188 * to a trace of all actions performed on the object. */
189 HashTable<const void *, action_list_t *, uintptr_t, 4> * const obj_map;
191 /** Per-object list of actions. Maps an object (i.e., memory location)
192 * to a trace of all actions performed on the object. */
193 HashTable<const void *, action_list_t *, uintptr_t, 4> * const condvar_waiters_map;
195 HashTable<void *, SnapVector<action_list_t> *, uintptr_t, 4 > * const obj_thrd_map;
196 SnapVector<Promise *> * const promises;
197 SnapVector<struct PendingFutureValue> * const futurevalues;
200 * List of pending release sequences. Release sequences might be
201 * determined lazily as promises are fulfilled and modification orders
202 * are established. Each entry in the list may only be partially
203 * filled, depending on its pending status.
205 SnapVector<struct release_seq *> * const pending_rel_seqs;
207 SnapVector<ModelAction *> * const thrd_last_action;
208 SnapVector<ModelAction *> * const thrd_last_fence_release;
209 NodeStack * const node_stack;
211 /** A special model-checker Thread; used for associating with
212 * model-checker-related ModelAcitons */
213 Thread *model_thread;
215 /** Private data members that should be snapshotted. They are grouped
216 * together for efficiency and maintainability. */
217 struct model_snapshot_members * const priv;
220 * @brief The modification order graph
222 * A directed acyclic graph recording observations of the modification
223 * order on all the atomic objects in the system. This graph should
224 * never contain any cycles, as that represents a violation of the
225 * memory model (total ordering). This graph really consists of many
226 * disjoint (unconnected) subgraphs, each graph corresponding to a
227 * separate ordering on a distinct object.
229 * The edges in this graph represent the "ordered before" relation,
230 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
233 CycleGraph * const mo_graph;
235 int execution_number;
237 Thread * action_select_next_thread(const ModelAction *curr) const;
240 #endif /* __EXECUTION_H__ */