Skip to content

Commit

Permalink
correctly account for cycle starts
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Richardson committed Nov 13, 2018
1 parent 690d910 commit 0929578
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/execution_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ val create_like
val find_local : t -> 'a Univ_map.Key.t -> 'a option
val with_local : t -> 'a Univ_map.Key.t -> 'a option -> t
val with_tid : t -> int -> t

val record_backtrace : t -> t

4 changes: 3 additions & 1 deletion src/scheduler0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ let events t = t.time_source.events

let set_execution_context t execution_context =
(* Avoid a caml_modify in most cases. *)
(* XXX: see where job_queue also modifies current_execution_context *)
if not (phys_equal t.current_execution_context execution_context)
then (
if t.current_execution_context.tid <> execution_context.tid then (!Tracing.fns).trace_thread_switch execution_context ;
if t.current_execution_context.tid <> execution_context.tid then (!Tracing.fns).trace_thread_switch execution_context
else if t.cycle_started then ((!Tracing.fns).trace_thread_switch execution_context; t.cycle_started <- false) ;
t.current_execution_context <- execution_context )
;;
3 changes: 3 additions & 0 deletions src/scheduler1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type t = Scheduler0.t =
; mutable check_invariants : bool
; mutable max_num_jobs_per_priority_per_cycle : Max_num_jobs_per_priority_per_cycle.t
; mutable record_backtraces : bool
; mutable cycle_started : bool
; mutable on_start_of_cycle : unit -> unit
; mutable on_end_of_cycle : unit -> unit }
[@@deriving fields, sexp_of]
Expand Down Expand Up @@ -172,6 +173,7 @@ let invariant t : unit =
~check_invariants:ignore
~max_num_jobs_per_priority_per_cycle:ignore
~record_backtraces:ignore
~cycle_started:ignore
~on_start_of_cycle:ignore
~on_end_of_cycle:ignore
;
Expand Down Expand Up @@ -243,6 +245,7 @@ let create () =
; check_invariants = Async_kernel_config.check_invariants
; max_num_jobs_per_priority_per_cycle = Async_kernel_config.max_num_jobs_per_priority_per_cycle
; record_backtraces = Async_kernel_config.record_backtraces
; cycle_started = false
; on_start_of_cycle = Fn.id
; on_end_of_cycle = Fn.id }
and events = Timing_wheel_ns.create ~config:Async_kernel_config.timing_wheel_config ~start:now
Expand Down
1 change: 1 addition & 0 deletions src/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ and Scheduler : sig
; mutable check_invariants : bool
; mutable max_num_jobs_per_priority_per_cycle : Max_num_jobs_per_priority_per_cycle.t
; mutable record_backtraces : bool
; mutable cycle_started : bool
; mutable on_start_of_cycle : unit -> unit
; mutable on_end_of_cycle : unit -> unit }
end = Scheduler
Expand Down

0 comments on commit 0929578

Please sign in to comment.