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
36 * Structure for holding small ModelChecker members that should be snapshotted
38 struct model_snapshot_members {
39 ModelAction *current_action;
41 modelclock_t used_sequence_numbers;
43 ModelAction *next_backtrack;
45 /** @see ModelChecker::lazy_sync_size */
46 unsigned int lazy_sync_size;
49 /** @brief The central structure for model-checking */
52 ModelChecker(struct model_params params);
55 /** @returns the context for the main model-checking system thread */
56 ucontext_t * get_system_context() { return &system_context; }
58 /** Prints an execution summary with trace information. */
61 void add_thread(Thread *t);
62 void remove_thread(Thread *t);
63 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
64 Thread * get_thread(ModelAction *act) { return get_thread(act->get_tid()); }
66 thread_id_t get_next_id();
67 int get_num_threads();
68 modelclock_t get_next_seq_num();
70 /** @return The currently executing Thread. */
71 Thread * get_current_thread() { return scheduler->get_current_thread(); }
73 int switch_to_master(ModelAction *act);
74 ClockVector * get_cv(thread_id_t tid);
75 ModelAction * get_parent_action(thread_id_t tid);
76 bool next_execution();
78 bool isfeasibleotherthanRMW();
79 bool isfinalfeasible();
80 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
81 void get_release_seq_heads(ModelAction *act,
82 std::vector<const ModelAction *> *release_heads);
83 void finish_execution();
84 bool isfeasibleprefix();
85 void set_assert() {asserted=true;}
89 /** The scheduler to use: tracks the running/ready Threads */
92 bool ensure_rmw_acyclic(const ModelAction * read, const ModelAction *write);
95 bool thin_air_constraint_may_allow(const ModelAction * writer, const ModelAction *reader);
96 bool has_asserted() {return asserted;}
97 void reset_asserted() {asserted=false;}
99 bool promises_expired();
100 const model_params params;
103 * Stores the ModelAction for the current thread action. Call this
104 * immediately before switching from user- to system-context to pass
106 * @param act The ModelAction created by the user-thread action
108 void set_current_action(ModelAction *act) { priv->current_action = act; }
109 Thread * check_current_action(ModelAction *curr);
110 bool process_read(ModelAction *curr, Thread * th, bool second_part_of_rmw);
114 void check_recency(ModelAction *curr, bool already_added);
115 ModelAction * get_last_conflict(ModelAction *act);
116 void set_backtracking(ModelAction *act);
117 Thread * get_next_thread(ModelAction *curr);
118 ModelAction * get_next_backtrack();
119 void reset_to_initial_state();
120 bool resolve_promises(ModelAction *curr);
121 void compute_promises(ModelAction *curr);
124 void check_curr_backtracking(ModelAction * curr);
125 void add_action_to_lists(ModelAction *act);
126 ModelAction * get_last_action(thread_id_t tid);
127 ModelAction * get_last_seq_cst(const void *location);
128 void build_reads_from_past(ModelAction *curr);
129 ModelAction * process_rmw(ModelAction *curr);
130 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
131 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
132 bool w_modification_order(ModelAction *curr);
133 bool release_seq_head(const ModelAction *rf,
134 std::vector<const ModelAction *> *release_heads) const;
135 bool resolve_release_sequences(void *location);
137 ModelAction *diverge;
139 ucontext_t system_context;
140 action_list_t *action_trace;
141 HashTable<int, Thread *, int> *thread_map;
143 /** Per-object list of actions. Maps an object (i.e., memory location)
144 * to a trace of all actions performed on the object. */
145 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
147 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
148 std::vector<Promise *> *promises;
151 * Collection of lists of objects that might synchronize with one or
152 * more release sequence. Release sequences might be determined lazily
153 * as promises are fulfilled and modification orders are established.
154 * This structure maps its lists by object location. Each ModelAction
155 * in the lists should be an acquire operation.
157 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
160 * Represents the total size of the
161 * ModelChecker::lazy_sync_with_release lists. This count should be
162 * snapshotted, so it is actually a pointer to a location within
165 unsigned int *lazy_sync_size;
167 std::vector<ModelAction *> *thrd_last_action;
168 NodeStack *node_stack;
170 /** Private data members that should be snapshotted. They are grouped
171 * together for efficiency and maintainability. */
172 struct model_snapshot_members *priv;
175 * @brief The modification order graph
177 * A directed acyclic graph recording observations of the modification
178 * order on all the atomic objects in the system. This graph should
179 * never contain any cycles, as that represents a violation of the
180 * memory model (total ordering). This graph really consists of many
181 * disjoint (unconnected) subgraphs, each graph corresponding to a
182 * separate ordering on a distinct object.
184 * The edges in this graph represent the "ordered before" relation,
185 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
188 CycleGraph *mo_graph;
195 extern ModelChecker *model;
197 #endif /* __MODEL_H__ */