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 * Structure for holding small ModelChecker members that should be snapshotted
37 struct model_snapshot_members {
38 ModelAction *current_action;
40 modelclock_t used_sequence_numbers;
42 ModelAction *next_backtrack;
44 /** @see ModelChecker::lazy_sync_size */
45 unsigned int lazy_sync_size;
48 /** @brief The central structure for model-checking */
51 ModelChecker(struct model_params params);
54 /** @returns the context for the main model-checking system thread */
55 ucontext_t * get_system_context() { return &system_context; }
57 /** Prints an execution summary with trace information. */
60 void add_thread(Thread *t);
61 void remove_thread(Thread *t);
62 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
64 thread_id_t get_next_id();
65 int get_num_threads();
66 modelclock_t get_next_seq_num();
68 /** @return The currently executing Thread. */
69 Thread * get_current_thread() { return scheduler->get_current_thread(); }
71 int switch_to_master(ModelAction *act);
72 ClockVector * get_cv(thread_id_t tid);
73 ModelAction * get_parent_action(thread_id_t tid);
74 bool next_execution();
76 bool isfinalfeasible();
77 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
78 void get_release_seq_heads(ModelAction *act,
79 std::vector<const ModelAction *> *release_heads);
81 void finish_execution();
82 bool isfeasibleprefix();
83 void set_assert() {asserted=true;}
87 /** The scheduler to use: tracks the running/ready Threads */
90 bool has_asserted() {return asserted;}
91 void reset_asserted() {asserted=false;}
94 const model_params params;
97 * Stores the ModelAction for the current thread action. Call this
98 * immediately before switching from user- to system-context to pass
100 * @param act The ModelAction created by the user-thread action
102 void set_current_action(ModelAction *act) { priv->current_action = act; }
103 Thread * check_current_action(ModelAction *curr);
104 bool process_read(ModelAction *curr, Thread * th, bool second_part_of_rmw);
108 void check_recency(ModelAction *curr, bool already_added);
109 ModelAction * get_last_conflict(ModelAction *act);
110 void set_backtracking(ModelAction *act);
111 Thread * get_next_replay_thread();
112 ModelAction * get_next_backtrack();
113 void reset_to_initial_state();
114 bool resolve_promises(ModelAction *curr);
115 void compute_promises(ModelAction *curr);
117 void add_action_to_lists(ModelAction *act);
118 ModelAction * get_last_action(thread_id_t tid);
119 ModelAction * get_last_seq_cst(const void *location);
120 void build_reads_from_past(ModelAction *curr);
121 ModelAction * process_rmw(ModelAction *curr);
122 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
123 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
124 bool w_modification_order(ModelAction *curr);
125 bool release_seq_head(const ModelAction *rf,
126 std::vector<const ModelAction *> *release_heads) const;
127 bool resolve_release_sequences(void *location);
129 ModelAction *diverge;
131 ucontext_t system_context;
132 action_list_t *action_trace;
133 HashTable<int, Thread *, int> *thread_map;
135 /** Per-object list of actions. Maps an object (i.e., memory location)
136 * to a trace of all actions performed on the object. */
137 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
139 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
140 std::vector<Promise *> *promises;
143 * Collection of lists of objects that might synchronize with one or
144 * more release sequence. Release sequences might be determined lazily
145 * as promises are fulfilled and modification orders are established.
146 * This structure maps its lists by object location. Each ModelAction
147 * in the lists should be an acquire operation.
149 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
152 * Represents the total size of the
153 * ModelChecker::lazy_sync_with_release lists. This count should be
154 * snapshotted, so it is actually a pointer to a location within
157 unsigned int *lazy_sync_size;
159 std::vector<ModelAction *> *thrd_last_action;
160 NodeStack *node_stack;
162 /** Private data members that should be snapshotted. They are grouped
163 * together for efficiency and maintainability. */
164 struct model_snapshot_members *priv;
167 * @brief The modification order graph
169 * A directed acyclic graph recording observations of the modification
170 * order on all the atomic objects in the system. This graph should
171 * never contain any cycles, as that represents a violation of the
172 * memory model (total ordering). This graph really consists of many
173 * disjoint (unconnected) subgraphs, each graph corresponding to a
174 * separate ordering on a distinct object.
176 * The edges in this graph represent the "ordered before" relation,
177 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
180 CycleGraph *mo_graph;
186 extern ModelChecker *model;
188 #endif /* __MODEL_H__ */