2 * @brief Model-checker core
5 #ifndef __EXECUTION_H__
6 #define __EXECUTION_H__
12 #include "hashtable.h"
14 #include "modeltypes.h"
15 #include "stl-model.h"
17 #include "mypthread.h"
19 #include <condition_variable>
20 #include "classlist.h"
22 typedef SnapList<ModelAction *> action_list_t;
24 struct PendingFutureValue {
25 PendingFutureValue(ModelAction *writer, ModelAction *reader) :
26 writer(writer), reader(reader)
28 const ModelAction *writer;
32 /** @brief The central structure for model-checking */
33 class ModelExecution {
35 ModelExecution(ModelChecker *m, Scheduler *scheduler);
38 struct model_params * get_params() const { return params; }
39 void setParams(struct model_params * _params) {params = _params;}
41 Thread * take_step(ModelAction *curr);
43 void print_summary() const;
44 #if SUPPORT_MOD_ORDER_DUMP
45 void dumpGraph(char *filename) const;
48 void add_thread(Thread *t);
49 Thread * get_thread(thread_id_t tid) const;
50 Thread * get_thread(const ModelAction *act) const;
52 uint32_t get_pthread_counter() { return pthread_counter; }
53 void incr_pthread_counter() { pthread_counter++; }
54 Thread * get_pthread(pthread_t pid);
56 bool is_enabled(Thread *t) const;
57 bool is_enabled(thread_id_t tid) const;
59 thread_id_t get_next_id();
60 unsigned int get_num_threads() const;
62 ClockVector * get_cv(thread_id_t tid) const;
63 ModelAction * get_parent_action(thread_id_t tid) const;
64 bool isfeasibleprefix() const;
66 ModelAction * get_last_action(thread_id_t tid) const;
68 bool check_action_enabled(ModelAction *curr);
70 bool assert_bug(const char *msg);
71 bool have_bug_reports() const;
72 SnapVector<bug_message *> * get_bugs() const;
74 bool has_asserted() const;
76 bool is_complete_execution() const;
78 void print_infeasibility(const char *prefix) const;
79 bool is_infeasible() const;
80 bool is_deadlocked() const;
82 action_list_t * get_action_trace() { return &action_trace; }
84 CycleGraph * const get_mo_graph() { return mo_graph; }
85 HashTable<pthread_cond_t *, cdsc::snapcondition_variable *, uintptr_t, 4> * getCondMap() {return &cond_map;}
86 HashTable<pthread_mutex_t *, cdsc::snapmutex *, uintptr_t, 4> * getMutexMap() {return &mutex_map;}
87 ModelAction * check_current_action(ModelAction *curr);
91 int get_execution_number() const;
95 struct model_params * params;
97 /** The scheduler to use: tracks the running/ready Threads */
98 Scheduler * const scheduler;
100 bool mo_may_allow(const ModelAction *writer, const ModelAction *reader);
101 void set_bad_synchronization();
102 bool should_wake_up(const ModelAction *curr, const Thread *thread) const;
103 void wake_up_sleeping_actions(ModelAction *curr);
104 modelclock_t get_next_seq_num();
106 bool next_execution();
107 bool initialize_curr_action(ModelAction **curr);
108 void process_read(ModelAction *curr, SnapVector<ModelAction *> * rf_set);
109 void process_write(ModelAction *curr);
110 bool process_fence(ModelAction *curr);
111 bool process_mutex(ModelAction *curr);
113 bool process_thread_action(ModelAction *curr);
114 void read_from(ModelAction *act, ModelAction *rf);
115 bool synchronize(const ModelAction *first, ModelAction *second);
117 void add_action_to_lists(ModelAction *act);
118 void add_write_to_lists(ModelAction *act);
119 ModelAction * get_last_fence_release(thread_id_t tid) const;
120 ModelAction * get_last_seq_cst_write(ModelAction *curr) const;
121 ModelAction * get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const;
122 ModelAction * get_last_unlock(ModelAction *curr) const;
123 SnapVector<ModelAction *> * build_may_read_from(ModelAction *curr);
124 ModelAction * process_rmw(ModelAction *curr);
126 bool r_modification_order(ModelAction *curr, const ModelAction *rf, SnapVector<const ModelAction *> *priorset, bool *canprune);
127 void w_modification_order(ModelAction *curr);
128 ClockVector * get_hb_from_write(ModelAction *rf) const;
129 ModelAction * get_uninitialized_action(ModelAction *curr) const;
131 action_list_t action_trace;
132 SnapVector<Thread *> thread_map;
133 SnapVector<Thread *> pthread_map;
134 uint32_t pthread_counter;
136 /** Per-object list of actions. Maps an object (i.e., memory location)
137 * to a trace of all actions performed on the object. */
138 HashTable<const void *, action_list_t *, uintptr_t, 4> obj_map;
140 /** Per-object list of actions. Maps an object (i.e., memory location)
141 * to a trace of all actions performed on the object. */
142 HashTable<const void *, action_list_t *, uintptr_t, 4> condvar_waiters_map;
144 HashTable<const void *, SnapVector<action_list_t> *, uintptr_t, 4> obj_thrd_map;
146 HashTable<const void *, SnapVector<action_list_t> *, uintptr_t, 4> obj_wr_thrd_map;
148 HashTable<const void *, ModelAction *, uintptr_t, 4> obj_last_sc_map;
151 HashTable<pthread_mutex_t *, cdsc::snapmutex *, uintptr_t, 4> mutex_map;
152 HashTable<pthread_cond_t *, cdsc::snapcondition_variable *, uintptr_t, 4> cond_map;
155 * List of pending release sequences. Release sequences might be
156 * determined lazily as promises are fulfilled and modification orders
157 * are established. Each entry in the list may only be partially
158 * filled, depending on its pending status.
161 SnapVector<ModelAction *> thrd_last_action;
162 SnapVector<ModelAction *> thrd_last_fence_release;
164 /** A special model-checker Thread; used for associating with
165 * model-checker-related ModelAcitons */
166 Thread *model_thread;
168 /** Private data members that should be snapshotted. They are grouped
169 * together for efficiency and maintainability. */
170 struct model_snapshot_members * const priv;
173 * @brief The modification order graph
175 * A directed acyclic graph recording observations of the modification
176 * order on all the atomic objects in the system. This graph should
177 * never contain any cycles, as that represents a violation of the
178 * memory model (total ordering). This graph really consists of many
179 * disjoint (unconnected) subgraphs, each graph corresponding to a
180 * separate ordering on a distinct object.
182 * The edges in this graph represent the "ordered before" relation,
183 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
186 CycleGraph * const mo_graph;
190 Thread * action_select_next_thread(const ModelAction *curr) const;
193 #endif /* __EXECUTION_H__ */