2 * @brief Core model checker.
15 #include "libthreads.h"
18 #include "clockvector.h"
19 #include "hashtable.h"
20 #include "workqueue.h"
22 /* Forward declaration */
27 /** @brief Shorthand for a list of release sequence heads */
28 typedef std::vector< const ModelAction *, MyAlloc<const ModelAction *> > rel_heads_list_t;
31 * Model checker parameter structure. Holds run-time configuration options for
37 unsigned int fairwindow;
38 unsigned int enabledcount;
41 struct PendingFutureValue {
43 modelclock_t expiration;
48 * Structure for holding small ModelChecker members that should be snapshotted
50 struct model_snapshot_members {
51 ModelAction *current_action;
53 modelclock_t used_sequence_numbers;
55 ModelAction *next_backtrack;
58 /** @brief The central structure for model-checking */
61 ModelChecker(struct model_params params);
64 /** @returns the context for the main model-checking system thread */
65 ucontext_t * get_system_context() { return &system_context; }
67 /** Prints an execution summary with trace information. */
70 void add_thread(Thread *t);
71 void remove_thread(Thread *t);
72 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
73 Thread * get_thread(ModelAction *act) { return get_thread(act->get_tid()); }
75 thread_id_t get_next_id();
76 int get_num_threads();
77 modelclock_t get_next_seq_num();
79 /** @return The currently executing Thread. */
80 Thread * get_current_thread() { return scheduler->get_current_thread(); }
82 int switch_to_master(ModelAction *act);
83 ClockVector * get_cv(thread_id_t tid);
84 ModelAction * get_parent_action(thread_id_t tid);
85 bool next_execution();
87 bool isfeasibleotherthanRMW();
88 bool isfinalfeasible();
89 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
90 void get_release_seq_heads(ModelAction *act, rel_heads_list_t *release_heads);
91 void finish_execution();
92 bool isfeasibleprefix();
93 void set_assert() {asserted=true;}
94 const model_params params;
98 /** The scheduler to use: tracks the running/ready Threads */
101 bool thin_air_constraint_may_allow(const ModelAction * writer, const ModelAction *reader);
102 bool has_asserted() {return asserted;}
103 void reset_asserted() {asserted=false;}
105 int num_feasible_executions;
106 bool promises_expired();
109 * Stores the ModelAction for the current thread action. Call this
110 * immediately before switching from user- to system-context to pass
112 * @param act The ModelAction created by the user-thread action
114 void set_current_action(ModelAction *act) { priv->current_action = act; }
115 Thread * check_current_action(ModelAction *curr);
116 ModelAction * initialize_curr_action(ModelAction *curr);
117 bool process_read(ModelAction *curr, bool second_part_of_rmw);
118 bool process_write(ModelAction *curr);
119 void process_mutex(ModelAction *curr);
120 bool check_action_enabled(ModelAction *curr);
124 void check_recency(ModelAction *curr);
125 ModelAction * get_last_conflict(ModelAction *act);
126 void set_backtracking(ModelAction *act);
127 Thread * get_next_thread(ModelAction *curr);
128 ModelAction * get_next_backtrack();
129 void reset_to_initial_state();
130 bool resolve_promises(ModelAction *curr);
131 void compute_promises(ModelAction *curr);
133 void check_curr_backtracking(ModelAction * curr);
134 void add_action_to_lists(ModelAction *act);
135 ModelAction * get_last_action(thread_id_t tid) const;
136 ModelAction * get_last_seq_cst(ModelAction *curr) const;
137 ModelAction * get_last_unlock(ModelAction *curr) const;
138 void build_reads_from_past(ModelAction *curr);
139 ModelAction * process_rmw(ModelAction *curr);
140 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
141 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
142 bool w_modification_order(ModelAction *curr);
143 bool release_seq_head(const ModelAction *rf, rel_heads_list_t *release_heads) const;
144 bool resolve_release_sequences(void *location, work_queue_t *work_queue);
145 void do_complete_join(ModelAction *join);
147 ModelAction *diverge;
149 ucontext_t system_context;
150 action_list_t *action_trace;
151 HashTable<int, Thread *, int> *thread_map;
153 /** Per-object list of actions. Maps an object (i.e., memory location)
154 * to a trace of all actions performed on the object. */
155 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
157 /** Per-object list of actions. Maps an object (i.e., memory location)
158 * to a trace of all actions performed on the object. */
159 HashTable<const void *, action_list_t, uintptr_t, 4> *lock_waiters_map;
161 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
162 std::vector<Promise *> *promises;
163 std::vector<struct PendingFutureValue> *futurevalues;
166 * List of acquire actions that might synchronize with one or more
167 * release sequence. Release sequences might be determined lazily as
168 * promises are fulfilled and modification orders are established. Each
169 * ModelAction in this list must be an acquire operation.
171 std::vector<ModelAction *> *pending_acq_rel_seq;
173 std::vector<ModelAction *> *thrd_last_action;
174 NodeStack *node_stack;
176 /** Private data members that should be snapshotted. They are grouped
177 * together for efficiency and maintainability. */
178 struct model_snapshot_members *priv;
181 * @brief The modification order graph
183 * A directed acyclic graph recording observations of the modification
184 * order on all the atomic objects in the system. This graph should
185 * never contain any cycles, as that represents a violation of the
186 * memory model (total ordering). This graph really consists of many
187 * disjoint (unconnected) subgraphs, each graph corresponding to a
188 * separate ordering on a distinct object.
190 * The edges in this graph represent the "ordered before" relation,
191 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
194 CycleGraph *mo_graph;
200 extern ModelChecker *model;
202 #endif /* __MODEL_H__ */