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;
43 /** @see ModelChecker::lazy_sync_size */
44 unsigned int lazy_sync_size;
47 /** @brief The central structure for model-checking */
50 ModelChecker(struct model_params params);
53 /** @returns the context for the main model-checking system thread */
54 ucontext_t * get_system_context() { return &system_context; }
56 /** Prints an execution summary with trace information. */
59 void add_thread(Thread *t);
60 void remove_thread(Thread *t);
61 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
63 thread_id_t get_next_id();
64 int get_num_threads();
65 modelclock_t get_next_seq_num();
67 /** @return The currently executing Thread. */
68 Thread * get_current_thread() { return scheduler->get_current_thread(); }
70 int switch_to_master(ModelAction *act);
71 ClockVector * get_cv(thread_id_t tid);
72 ModelAction * get_parent_action(thread_id_t tid);
73 bool next_execution();
75 bool isfinalfeasible();
76 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
77 void get_release_seq_heads(ModelAction *act,
78 std::vector<const ModelAction *> *release_heads);
80 void finish_execution();
81 bool isfeasibleprefix();
82 void set_assert() {asserted=true;}
86 /** The scheduler to use: tracks the running/ready Threads */
89 bool has_asserted() {return asserted;}
90 void reset_asserted() {asserted=false;}
93 const model_params params;
96 * Stores the ModelAction for the current thread action. Call this
97 * immediately before switching from user- to system-context to pass
99 * @param act The ModelAction created by the user-thread action
101 void set_current_action(ModelAction *act) { priv->current_action = act; }
102 Thread * check_current_action(ModelAction *curr);
106 ModelAction * get_last_conflict(ModelAction *act);
107 void set_backtracking(ModelAction *act);
108 Thread * get_next_thread(ModelAction *curr);
109 ModelAction * get_next_backtrack();
110 void reset_to_initial_state();
111 bool resolve_promises(ModelAction *curr);
112 void compute_promises(ModelAction *curr);
114 void add_action_to_lists(ModelAction *act);
115 ModelAction * get_last_action(thread_id_t tid);
116 ModelAction * get_last_seq_cst(const void *location);
117 void build_reads_from_past(ModelAction *curr);
118 ModelAction * process_rmw(ModelAction *curr);
119 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
120 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
121 bool w_modification_order(ModelAction *curr);
122 bool release_seq_head(const ModelAction *rf,
123 std::vector<const ModelAction *> *release_heads) const;
124 bool resolve_release_sequences(void *location);
126 ModelAction *diverge;
128 ucontext_t system_context;
129 action_list_t *action_trace;
130 HashTable<int, Thread *, int> *thread_map;
132 /** Per-object list of actions. Maps an object (i.e., memory location)
133 * to a trace of all actions performed on the object. */
134 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
136 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
137 std::vector<Promise *> *promises;
140 * Collection of lists of objects that might synchronize with one or
141 * more release sequence. Release sequences might be determined lazily
142 * as promises are fulfilled and modification orders are established.
143 * This structure maps its lists by object location. Each ModelAction
144 * in the lists should be an acquire operation.
146 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
149 * Represents the total size of the
150 * ModelChecker::lazy_sync_with_release lists. This count should be
151 * snapshotted, so it is actually a pointer to a location within
154 unsigned int *lazy_sync_size;
156 std::vector<ModelAction *> *thrd_last_action;
157 NodeStack *node_stack;
159 /** Private data members that should be snapshotted. They are grouped
160 * together for efficiency and maintainability. */
161 struct model_snapshot_members *priv;
164 * @brief The modification order graph
166 * A directed acyclic graph recording observations of the modification
167 * order on all the atomic objects in the system. This graph should
168 * never contain any cycles, as that represents a violation of the
169 * memory model (total ordering). This graph really consists of many
170 * disjoint (unconnected) subgraphs, each graph corresponding to a
171 * separate ordering on a distinct object.
173 * The edges in this graph represent the "ordered before" relation,
174 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
177 CycleGraph *mo_graph;
182 extern ModelChecker *model;
184 #endif /* __MODEL_H__ */