Skip to content

Commit 64ff54e

Browse files
committed
full replay only when necessary
1 parent 5a6c2f8 commit 64ff54e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/tracedAtomic.ml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ let num_runs = ref 0
165165
(* we stash the current state in case a check fails and we need to log it *)
166166
let schedule_for_checks = ref []
167167

168-
let do_run init_func init_schedule =
169-
init_func (); (*set up run *)
170-
tracing := true;
168+
let setup_run func init_schedule =
169+
atomics_counter := 1;
170+
CCVector.clear processes;
171171
schedule_for_checks := init_schedule;
172+
func () ;
173+
num_runs := !num_runs + 1;
174+
finished_processes := 0
175+
176+
let do_run init_schedule =
172177
(* cache the number of processes in case it's expensive*)
173178
let num_processes = CCVector.length processes in
174179
(* current number of ops we are through the current run *)
@@ -197,9 +202,7 @@ let do_run init_func init_schedule =
197202
in
198203
tracing := true;
199204
run_trace init_schedule ();
200-
finished_processes := 0;
201205
tracing := false;
202-
num_runs := !num_runs + 1;
203206
if !num_runs mod 1000 == 0 then
204207
Printf.printf "run: %d\n" !num_runs;
205208
let procs = CCVector.mapi (fun i p -> { proc_id = i; op = p.next_op; obj_ptr = p.next_repr }) processes |> CCVector.to_list in
@@ -208,8 +211,6 @@ let do_run init_func init_schedule =
208211
|> Seq.filter (fun (_,proc) -> not proc.finished)
209212
|> Seq.map (fun (id,_) -> id)
210213
|> IntSet.of_seq in
211-
CCVector.clear processes;
212-
atomics_counter := 1;
213214
match last_element init_schedule with
214215
| (run_proc, run_op, run_ptr) ->
215216
{ procs; enabled = current_enabled; run_proc; run_op; run_ptr; backtrack = IntSet.empty }
@@ -231,12 +232,26 @@ let rec explore func state clock last_access =
231232
let p = IntSet.min_elt s.enabled in
232233
let dones = ref IntSet.empty in
233234
s.backtrack <- IntSet.singleton p;
235+
let is_backtracking = ref false in
234236
while IntSet.(cardinal (diff s.backtrack !dones)) > 0 do
235237
let j = IntSet.min_elt (IntSet.diff s.backtrack !dones) in
236238
dones := IntSet.add j !dones;
237239
let j_proc = List.nth s.procs j in
238-
let schedule = (List.map (fun s -> (s.run_proc, s.run_op, s.run_ptr)) state) @ [(j, j_proc.op, j_proc.obj_ptr)] in
239-
let statedash = state @ [do_run func schedule] in
240+
let new_step = [(j, j_proc.op, j_proc.obj_ptr)] in
241+
let full_schedule = List.map (fun s -> (s.run_proc, s.run_op, s.run_ptr)) state @ new_step in
242+
let schedule =
243+
if !is_backtracking
244+
then begin
245+
setup_run func full_schedule ;
246+
full_schedule
247+
end
248+
else begin
249+
is_backtracking := true ;
250+
schedule_for_checks := full_schedule;
251+
new_step
252+
end
253+
in
254+
let statedash = state @ [do_run schedule] in
240255
let state_time = (List.length statedash)-1 in
241256
let new_last_access = match j_proc.obj_ptr with Some(ptr) -> IntMap.add ptr state_time last_access | None -> last_access in
242257
let new_clock = IntMap.add j state_time clock in
@@ -269,7 +284,10 @@ let check f =
269284

270285

271286
let trace func =
272-
let empty_state = do_run func [(0, Start, None)] :: [] in
287+
let schedule = [(0, Start, None)] in
288+
setup_run func schedule ;
289+
let empty_state = do_run schedule :: [] in
273290
let empty_clock = IntMap.empty in
274291
let empty_last_access = IntMap.empty in
275-
explore func empty_state empty_clock empty_last_access
292+
explore func empty_state empty_clock empty_last_access ;
293+
Printf.printf "Finished after %i runs.\n%!" !num_runs

0 commit comments

Comments
 (0)