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
34 * Structure for holding small ModelChecker members that should be snapshotted
36 struct model_snapshot_members {
37 ModelAction *current_action;
39 modelclock_t used_sequence_numbers;
41 ModelAction *next_backtrack;
44 /** @brief The central structure for model-checking */
47 ModelChecker(struct model_params params);
50 /** @returns the context for the main model-checking system thread */
51 ucontext_t * get_system_context() { return &system_context; }
53 /** Prints an execution summary with trace information. */
56 void add_thread(Thread *t);
57 void remove_thread(Thread *t);
58 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
60 thread_id_t get_next_id();
61 int get_num_threads();
62 modelclock_t get_next_seq_num();
64 /** @return The currently executing Thread. */
65 Thread * get_current_thread() { return scheduler->get_current_thread(); }
67 int switch_to_master(ModelAction *act);
68 ClockVector * get_cv(thread_id_t tid);
69 ModelAction * get_parent_action(thread_id_t tid);
70 bool next_execution();
72 bool isfinalfeasible();
73 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
74 void get_release_seq_heads(ModelAction *act,
75 std::vector<const ModelAction *> *release_heads);
77 void finish_execution();
78 bool isfeasibleprefix();
79 void set_assert() {asserted=true;}
83 /** The scheduler to use: tracks the running/ready Threads */
86 bool has_asserted() {return asserted;}
87 void reset_asserted() {asserted=false;}
90 const model_params params;
93 * Stores the ModelAction for the current thread action. Call this
94 * immediately before switching from user- to system-context to pass
96 * @param act The ModelAction created by the user-thread action
98 void set_current_action(ModelAction *act) { priv->current_action = act; }
99 Thread * check_current_action(ModelAction *curr);
103 ModelAction * get_last_conflict(ModelAction *act);
104 void set_backtracking(ModelAction *act);
105 Thread * get_next_replay_thread();
106 ModelAction * get_next_backtrack();
107 void reset_to_initial_state();
108 bool resolve_promises(ModelAction *curr);
109 void compute_promises(ModelAction *curr);
111 void add_action_to_lists(ModelAction *act);
112 ModelAction * get_last_action(thread_id_t tid);
113 ModelAction * get_last_seq_cst(const void *location);
114 void build_reads_from_past(ModelAction *curr);
115 ModelAction * process_rmw(ModelAction *curr);
116 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
117 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
118 bool w_modification_order(ModelAction *curr);
119 bool release_seq_head(const ModelAction *rf,
120 std::vector<const ModelAction *> *release_heads) const;
121 bool resolve_release_sequences(void *location);
123 ModelAction *diverge;
125 ucontext_t system_context;
126 action_list_t *action_trace;
127 HashTable<int, Thread *, int> *thread_map;
129 /** Per-object list of actions. Maps an object (i.e., memory location)
130 * to a trace of all actions performed on the object. */
131 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
133 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
134 std::vector<Promise *> *promises;
137 * Collection of lists of objects that might synchronize with one or
138 * more release sequence. Release sequences might be determined lazily
139 * as promises are fulfilled and modification orders are established.
140 * This structure maps its lists by object location. Each ModelAction
141 * in the lists should be an acquire operation.
143 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
145 std::vector<ModelAction *> *thrd_last_action;
146 NodeStack *node_stack;
148 /** Private data members that should be snapshotted. They are grouped
149 * together for efficiency and maintainability. */
150 struct model_snapshot_members *priv;
153 * @brief The modification order graph
155 * A directed acyclic graph recording observations of the modification
156 * order on all the atomic objects in the system. This graph should
157 * never contain any cycles, as that represents a violation of the
158 * memory model (total ordering). This graph really consists of many
159 * disjoint (unconnected) subgraphs, each graph corresponding to a
160 * separate ordering on a distinct object.
162 * The edges in this graph represent the "ordered before" relation,
163 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
166 CycleGraph *mo_graph;
171 extern ModelChecker *model;
173 #endif /* __MODEL_H__ */