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);
126 void check_curr_backtracking(ModelAction * curr);
127 void add_action_to_lists(ModelAction *act);
128 ModelAction * get_last_action(thread_id_t tid);
129 ModelAction * get_last_seq_cst(const void *location);
130 void build_reads_from_past(ModelAction *curr);
131 ModelAction * process_rmw(ModelAction *curr);
132 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
133 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
134 bool w_modification_order(ModelAction *curr);
135 bool release_seq_head(const ModelAction *rf,
136 std::vector<const ModelAction *> *release_heads) const;
137 bool resolve_release_sequences(void *location);
139 ModelAction *diverge;
141 ucontext_t system_context;
142 action_list_t *action_trace;
143 HashTable<int, Thread *, int> *thread_map;
145 /** Per-object list of actions. Maps an object (i.e., memory location)
146 * to a trace of all actions performed on the object. */
147 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
149 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
150 std::vector<Promise *> *promises;
151 std::vector<struct PendingFutureValue> *futurevalues;
154 * Collection of lists of objects that might synchronize with one or
155 * more release sequence. Release sequences might be determined lazily
156 * as promises are fulfilled and modification orders are established.
157 * This structure maps its lists by object location. Each ModelAction
158 * in the lists should be an acquire operation.
160 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
163 * Represents the total size of the
164 * ModelChecker::lazy_sync_with_release lists. This count should be
165 * snapshotted, so it is actually a pointer to a location within
168 unsigned int *lazy_sync_size;
170 std::vector<ModelAction *> *thrd_last_action;
171 NodeStack *node_stack;
173 /** Private data members that should be snapshotted. They are grouped
174 * together for efficiency and maintainability. */
175 struct model_snapshot_members *priv;
178 * @brief The modification order graph
180 * A directed acyclic graph recording observations of the modification
181 * order on all the atomic objects in the system. This graph should
182 * never contain any cycles, as that represents a violation of the
183 * memory model (total ordering). This graph really consists of many
184 * disjoint (unconnected) subgraphs, each graph corresponding to a
185 * separate ordering on a distinct object.
187 * The edges in this graph represent the "ordered before" relation,
188 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
191 CycleGraph *mo_graph;
197 extern ModelChecker *model;
199 #endif /* __MODEL_H__ */