2 * @brief Core model checker.
15 #include "libthreads.h"
18 #include "clockvector.h"
19 #include "hashtable.h"
21 /* Forward declaration */
27 * Model checker parameter structure. Holds run-time configuration options for
35 struct PendingFutureValue {
37 modelclock_t expiration;
42 * Structure for holding small ModelChecker members that should be snapshotted
44 struct model_snapshot_members {
45 ModelAction *current_action;
47 modelclock_t used_sequence_numbers;
49 ModelAction *next_backtrack;
51 /** @see ModelChecker::lazy_sync_size */
52 unsigned int lazy_sync_size;
55 /** @brief The central structure for model-checking */
58 ModelChecker(struct model_params params);
61 /** @returns the context for the main model-checking system thread */
62 ucontext_t * get_system_context() { return &system_context; }
64 /** Prints an execution summary with trace information. */
67 void add_thread(Thread *t);
68 void remove_thread(Thread *t);
69 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
70 Thread * get_thread(ModelAction *act) { return get_thread(act->get_tid()); }
72 thread_id_t get_next_id();
73 int get_num_threads();
74 modelclock_t get_next_seq_num();
76 /** @return The currently executing Thread. */
77 Thread * get_current_thread() { return scheduler->get_current_thread(); }
79 int switch_to_master(ModelAction *act);
80 ClockVector * get_cv(thread_id_t tid);
81 ModelAction * get_parent_action(thread_id_t tid);
82 bool next_execution();
84 bool isfeasibleotherthanRMW();
85 bool isfinalfeasible();
86 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
87 void get_release_seq_heads(ModelAction *act,
88 std::vector<const ModelAction *> *release_heads);
89 void finish_execution();
90 bool isfeasibleprefix();
91 void set_assert() {asserted=true;}
95 /** The scheduler to use: tracks the running/ready Threads */
98 bool thin_air_constraint_may_allow(const ModelAction * writer, const ModelAction *reader);
99 bool has_asserted() {return asserted;}
100 void reset_asserted() {asserted=false;}
102 bool promises_expired();
103 const model_params params;
106 * Stores the ModelAction for the current thread action. Call this
107 * immediately before switching from user- to system-context to pass
109 * @param act The ModelAction created by the user-thread action
111 void set_current_action(ModelAction *act) { priv->current_action = act; }
112 Thread * check_current_action(ModelAction *curr);
113 bool process_read(ModelAction *curr, Thread * th, bool second_part_of_rmw);
117 void check_recency(ModelAction *curr, bool already_added);
118 ModelAction * get_last_conflict(ModelAction *act);
119 void set_backtracking(ModelAction *act);
120 Thread * get_next_thread(ModelAction *curr);
121 ModelAction * get_next_backtrack();
122 void reset_to_initial_state();
123 bool resolve_promises(ModelAction *curr);
124 void compute_promises(ModelAction *curr);
127 void check_curr_backtracking(ModelAction * curr);
128 void add_action_to_lists(ModelAction *act);
129 ModelAction * get_last_action(thread_id_t tid);
130 ModelAction * get_last_seq_cst(const void *location);
131 void build_reads_from_past(ModelAction *curr);
132 ModelAction * process_rmw(ModelAction *curr);
133 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
134 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
135 bool w_modification_order(ModelAction *curr);
136 bool release_seq_head(const ModelAction *rf,
137 std::vector<const ModelAction *> *release_heads) const;
138 bool resolve_release_sequences(void *location);
140 ModelAction *diverge;
142 ucontext_t system_context;
143 action_list_t *action_trace;
144 HashTable<int, Thread *, int> *thread_map;
146 /** Per-object list of actions. Maps an object (i.e., memory location)
147 * to a trace of all actions performed on the object. */
148 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
150 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
151 std::vector<Promise *> *promises;
152 std::vector<struct PendingFutureValue> *futurevalues;
155 * Collection of lists of objects that might synchronize with one or
156 * more release sequence. Release sequences might be determined lazily
157 * as promises are fulfilled and modification orders are established.
158 * This structure maps its lists by object location. Each ModelAction
159 * in the lists should be an acquire operation.
161 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
164 * Represents the total size of the
165 * ModelChecker::lazy_sync_with_release lists. This count should be
166 * snapshotted, so it is actually a pointer to a location within
169 unsigned int *lazy_sync_size;
171 std::vector<ModelAction *> *thrd_last_action;
172 NodeStack *node_stack;
174 /** Private data members that should be snapshotted. They are grouped
175 * together for efficiency and maintainability. */
176 struct model_snapshot_members *priv;
179 * @brief The modification order graph
181 * A directed acyclic graph recording observations of the modification
182 * order on all the atomic objects in the system. This graph should
183 * never contain any cycles, as that represents a violation of the
184 * memory model (total ordering). This graph really consists of many
185 * disjoint (unconnected) subgraphs, each graph corresponding to a
186 * separate ordering on a distinct object.
188 * The edges in this graph represent the "ordered before" relation,
189 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
192 CycleGraph *mo_graph;
198 extern ModelChecker *model;
200 #endif /* __MODEL_H__ */