2 * @brief Core model checker.
15 #include "libthreads.h"
18 #include "clockvector.h"
19 #include "hashtable.h"
20 #include "workqueue.h"
23 /* Forward declaration */
28 /** @brief Shorthand for a list of release sequence heads */
29 typedef std::vector< const ModelAction *, ModelAlloc<const ModelAction *> > rel_heads_list_t;
32 * Model checker parameter structure. Holds run-time configuration options for
38 unsigned int fairwindow;
39 unsigned int enabledcount;
42 struct PendingFutureValue {
44 modelclock_t expiration;
49 * Structure for holding small ModelChecker members that should be snapshotted
51 struct model_snapshot_members {
52 ModelAction *current_action;
54 modelclock_t used_sequence_numbers;
56 ModelAction *next_backtrack;
59 /** @brief The central structure for model-checking */
62 ModelChecker(struct model_params params);
65 /** @returns the context for the main model-checking system thread */
66 ucontext_t * get_system_context() { return &system_context; }
68 /** Prints an execution summary with trace information. */
70 #if SUPPORT_MOD_ORDER_DUMP
71 void dumpGraph(char *filename);
74 void add_thread(Thread *t);
75 void remove_thread(Thread *t);
76 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
77 Thread * get_thread(ModelAction *act) { return get_thread(act->get_tid()); }
79 thread_id_t get_next_id();
80 int get_num_threads();
82 /** @return The currently executing Thread. */
83 Thread * get_current_thread() { return scheduler->get_current_thread(); }
85 int switch_to_master(ModelAction *act);
86 ClockVector * get_cv(thread_id_t tid);
87 ModelAction * get_parent_action(thread_id_t tid);
88 bool next_execution();
90 bool isfeasibleotherthanRMW();
91 bool isfinalfeasible();
92 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
93 void get_release_seq_heads(ModelAction *act, rel_heads_list_t *release_heads);
94 void finish_execution();
95 bool isfeasibleprefix();
96 void set_assert() {asserted=true;}
98 /** @brief Alert the model-checker that an incorrectly-ordered
99 * synchronization was made */
100 void set_bad_synchronization() { bad_synchronization = true; }
102 const model_params params;
106 /** The scheduler to use: tracks the running/ready Threads */
107 Scheduler *scheduler;
109 bool thin_air_constraint_may_allow(const ModelAction * writer, const ModelAction *reader);
110 bool has_asserted() {return asserted;}
111 void reset_asserted() {asserted=false;}
113 int num_feasible_executions;
114 bool promises_expired();
116 modelclock_t get_next_seq_num();
119 * Stores the ModelAction for the current thread action. Call this
120 * immediately before switching from user- to system-context to pass
122 * @param act The ModelAction created by the user-thread action
124 void set_current_action(ModelAction *act) { priv->current_action = act; }
125 Thread * check_current_action(ModelAction *curr);
126 ModelAction * initialize_curr_action(ModelAction *curr);
127 bool process_read(ModelAction *curr, bool second_part_of_rmw);
128 bool process_write(ModelAction *curr);
129 bool process_mutex(ModelAction *curr);
130 bool process_thread_action(ModelAction *curr);
131 bool check_action_enabled(ModelAction *curr);
135 void check_recency(ModelAction *curr, const ModelAction *rf);
136 ModelAction * get_last_conflict(ModelAction *act);
137 void set_backtracking(ModelAction *act);
138 Thread * get_next_thread(ModelAction *curr);
139 ModelAction * get_next_backtrack();
140 void reset_to_initial_state();
141 bool resolve_promises(ModelAction *curr);
142 void compute_promises(ModelAction *curr);
144 void check_curr_backtracking(ModelAction * curr);
145 void add_action_to_lists(ModelAction *act);
146 ModelAction * get_last_action(thread_id_t tid) const;
147 ModelAction * get_last_seq_cst(ModelAction *curr) const;
148 ModelAction * get_last_unlock(ModelAction *curr) const;
149 void build_reads_from_past(ModelAction *curr);
150 ModelAction * process_rmw(ModelAction *curr);
151 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
152 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
153 bool w_modification_order(ModelAction *curr);
154 bool release_seq_head(const ModelAction *rf, rel_heads_list_t *release_heads) const;
155 bool resolve_release_sequences(void *location, work_queue_t *work_queue);
156 void do_complete_join(ModelAction *join);
158 ModelAction *diverge;
159 ModelAction *earliest_diverge;
161 ucontext_t system_context;
162 action_list_t *action_trace;
163 HashTable<int, Thread *, int> *thread_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> *obj_map;
169 /** Per-object list of actions. Maps an object (i.e., memory location)
170 * to a trace of all actions performed on the object. */
171 HashTable<const void *, action_list_t, uintptr_t, 4> *lock_waiters_map;
173 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
174 std::vector<Promise *> *promises;
175 std::vector<struct PendingFutureValue> *futurevalues;
178 * List of acquire actions that might synchronize with one or more
179 * release sequence. Release sequences might be determined lazily as
180 * promises are fulfilled and modification orders are established. Each
181 * ModelAction in this list must be an acquire operation.
183 std::vector<ModelAction *> *pending_acq_rel_seq;
185 std::vector<ModelAction *> *thrd_last_action;
186 NodeStack *node_stack;
188 /** Private data members that should be snapshotted. They are grouped
189 * together for efficiency and maintainability. */
190 struct model_snapshot_members *priv;
193 * @brief The modification order graph
195 * A directed acyclic graph recording observations of the modification
196 * order on all the atomic objects in the system. This graph should
197 * never contain any cycles, as that represents a violation of the
198 * memory model (total ordering). This graph really consists of many
199 * disjoint (unconnected) subgraphs, each graph corresponding to a
200 * separate ordering on a distinct object.
202 * The edges in this graph represent the "ordered before" relation,
203 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
206 CycleGraph *mo_graph;
210 /** @brief Incorrectly-ordered synchronization was made */
211 bool bad_synchronization;
214 extern ModelChecker *model;
216 #endif /* __MODEL_H__ */