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"
19 /* Forward declaration */
27 struct model_snapshot_members;
31 /** @brief Shorthand for a list of release sequence heads */
32 typedef ModelVector<const ModelAction *> rel_heads_list_t;
33 typedef SnapList<ModelAction *> action_list_t;
35 struct PendingFutureValue {
36 PendingFutureValue(ModelAction *writer, ModelAction *reader) :
37 writer(writer), reader(reader)
39 const ModelAction *writer;
43 /** @brief Records information regarding a single pending release sequence */
45 /** @brief The acquire operation */
47 /** @brief The read operation that may read from a release sequence;
48 * may be the same as acquire, or else an earlier action in the same
49 * thread (i.e., when 'acquire' is a fence-acquire) */
50 const ModelAction *read;
51 /** @brief The head of the RMW chain from which 'read' reads; may be
52 * equal to 'release' */
53 const ModelAction *rf;
54 /** @brief The head of the potential longest release sequence chain */
55 const ModelAction *release;
56 /** @brief The write(s) that may break the release sequence */
57 SnapVector<const ModelAction *> writes;
60 /** @brief The central structure for model-checking */
61 class ModelExecution {
63 ModelExecution(ModelChecker *m,
64 const struct model_params *params,
66 NodeStack *node_stack);
69 const struct model_params * get_params() const { return params; }
71 Thread * take_step(ModelAction *curr);
72 void fixup_release_sequences();
74 void print_summary() const;
75 #if SUPPORT_MOD_ORDER_DUMP
76 void dumpGraph(char *filename) const;
79 void add_thread(Thread *t);
80 Thread * get_thread(thread_id_t tid) const;
81 Thread * get_thread(const ModelAction *act) const;
82 int get_promise_number(const Promise *promise) const;
84 bool is_enabled(Thread *t) const;
85 bool is_enabled(thread_id_t tid) const;
87 thread_id_t get_next_id();
88 unsigned int get_num_threads() const;
90 ClockVector * get_cv(thread_id_t tid) const;
91 ModelAction * get_parent_action(thread_id_t tid) const;
92 void check_promises_thread_disabled();
93 bool isfeasibleprefix() const;
95 action_list_t * get_actions_on_obj(void * obj, thread_id_t tid) const;
96 ModelAction * get_last_action(thread_id_t tid) const;
98 bool check_action_enabled(ModelAction *curr);
100 bool assert_bug(const char *msg);
101 bool have_bug_reports() const;
102 SnapVector<bug_message *> * get_bugs() const;
104 bool has_asserted() const;
106 bool is_complete_execution() const;
108 void print_infeasibility(const char *prefix) const;
109 bool is_feasible_prefix_ignore_relseq() const;
110 bool is_infeasible() const;
111 bool is_deadlocked() const;
112 bool is_yieldblocked() const;
113 bool too_many_steps() const;
115 ModelAction * get_next_backtrack();
117 action_list_t * get_action_trace() { return &action_trace; }
119 CycleGraph * const get_mo_graph() { return mo_graph; }
123 int get_execution_number() const;
127 const model_params * const params;
129 /** The scheduler to use: tracks the running/ready Threads */
130 Scheduler * const scheduler;
132 bool sleep_can_read_from(ModelAction *curr, const ModelAction *write);
133 bool thin_air_constraint_may_allow(const ModelAction *writer, const ModelAction *reader) const;
134 bool mo_may_allow(const ModelAction *writer, const ModelAction *reader);
135 bool promises_may_allow(const ModelAction *writer, const ModelAction *reader) const;
136 void set_bad_synchronization();
137 void set_bad_sc_read();
138 bool promises_expired() const;
139 bool should_wake_up(const ModelAction *curr, const Thread *thread) const;
140 void wake_up_sleeping_actions(ModelAction *curr);
141 modelclock_t get_next_seq_num();
143 bool next_execution();
144 ModelAction * check_current_action(ModelAction *curr);
145 bool initialize_curr_action(ModelAction **curr);
146 bool process_read(ModelAction *curr);
147 bool process_write(ModelAction *curr, work_queue_t *work);
148 bool process_fence(ModelAction *curr);
149 bool process_mutex(ModelAction *curr);
150 bool process_thread_action(ModelAction *curr);
151 void process_relseq_fixup(ModelAction *curr, work_queue_t *work_queue);
152 bool read_from(ModelAction *act, const ModelAction *rf);
153 bool synchronize(const ModelAction *first, ModelAction *second);
155 template <typename T>
156 bool check_recency(ModelAction *curr, const T *rf) const;
158 template <typename T, typename U>
159 bool should_read_instead(const ModelAction *curr, const T *rf, const U *other_rf) const;
161 ModelAction * get_last_fence_conflict(ModelAction *act) const;
162 ModelAction * get_last_conflict(ModelAction *act) const;
163 void set_backtracking(ModelAction *act);
164 bool set_latest_backtrack(ModelAction *act);
165 Promise * pop_promise_to_resolve(const ModelAction *curr);
166 bool resolve_promise(ModelAction *curr, Promise *promise,
168 void compute_promises(ModelAction *curr);
169 void compute_relseq_breakwrites(ModelAction *curr);
171 void check_promises(thread_id_t tid, ClockVector *old_cv, ClockVector *merge_cv);
172 void mo_check_promises(const ModelAction *act, bool is_read_check);
173 void thread_blocking_check_promises(Thread *blocker, Thread *waiting);
175 void check_curr_backtracking(ModelAction *curr);
176 void add_action_to_lists(ModelAction *act);
177 ModelAction * get_last_fence_release(thread_id_t tid) const;
178 ModelAction * get_last_seq_cst_write(ModelAction *curr) const;
179 ModelAction * get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const;
180 ModelAction * get_last_unlock(ModelAction *curr) const;
181 void build_may_read_from(ModelAction *curr);
182 ModelAction * process_rmw(ModelAction *curr);
184 template <typename rf_type>
185 bool r_modification_order(ModelAction *curr, const rf_type *rf);
187 bool w_modification_order(ModelAction *curr, ModelVector<ModelAction *> *send_fv);
188 void get_release_seq_heads(ModelAction *acquire, ModelAction *read, rel_heads_list_t *release_heads);
189 bool release_seq_heads(const ModelAction *rf, rel_heads_list_t *release_heads, struct release_seq *pending) const;
190 void propagate_clockvector(ModelAction *acquire, work_queue_t *work);
191 bool resolve_release_sequences(void *location, work_queue_t *work_queue);
192 void add_future_value(const ModelAction *writer, ModelAction *reader);
193 bool check_coherence_promise(const ModelAction *write, const ModelAction *read);
194 ModelAction * get_uninitialized_action(const ModelAction *curr) const;
196 action_list_t action_trace;
197 SnapVector<Thread *> thread_map;
199 /** Per-object list of actions. Maps an object (i.e., memory location)
200 * to a trace of all actions performed on the object. */
201 HashTable<const void *, action_list_t *, uintptr_t, 4> obj_map;
203 /** Per-object list of actions. Maps an object (i.e., memory location)
204 * to a trace of all actions performed on the object. */
205 HashTable<const void *, action_list_t *, uintptr_t, 4> condvar_waiters_map;
207 HashTable<void *, SnapVector<action_list_t> *, uintptr_t, 4> obj_thrd_map;
210 * @brief List of currently-pending promises
212 * Promises are sorted by the execution order of the read(s) which
215 SnapVector<Promise *> promises;
216 SnapVector<struct PendingFutureValue> futurevalues;
219 * List of pending release sequences. Release sequences might be
220 * determined lazily as promises are fulfilled and modification orders
221 * are established. Each entry in the list may only be partially
222 * filled, depending on its pending status.
224 SnapVector<struct release_seq *> pending_rel_seqs;
226 SnapVector<ModelAction *> thrd_last_action;
227 SnapVector<ModelAction *> thrd_last_fence_release;
228 NodeStack * const node_stack;
230 /** A special model-checker Thread; used for associating with
231 * model-checker-related ModelAcitons */
232 Thread *model_thread;
234 /** Private data members that should be snapshotted. They are grouped
235 * together for efficiency and maintainability. */
236 struct model_snapshot_members * const priv;
239 * @brief The modification order graph
241 * A directed acyclic graph recording observations of the modification
242 * order on all the atomic objects in the system. This graph should
243 * never contain any cycles, as that represents a violation of the
244 * memory model (total ordering). This graph really consists of many
245 * disjoint (unconnected) subgraphs, each graph corresponding to a
246 * separate ordering on a distinct object.
248 * The edges in this graph represent the "ordered before" relation,
249 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
252 CycleGraph * const mo_graph;
254 Thread * action_select_next_thread(const ModelAction *curr) const;
257 #endif /* __EXECUTION_H__ */