diff --git a/.ocamlformat b/.ocamlformat index 0b457a3..ffb06fc 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,2 +1,4 @@ profile = default -version = 0.26.2 +version = 0.27.0 + +exp-grouping=preserve diff --git a/bench/orchestrator.mli b/bench/orchestrator.mli index 074f57b..e848766 100644 --- a/bench/orchestrator.mli +++ b/bench/orchestrator.mli @@ -1,37 +1,34 @@ -(** Helper library that ensures all workers have started before any - starts making progress on the benchmark. *) +(** Helper library that ensures all workers have started before any starts + making progress on the benchmark. *) type t -(** An orchestrator is similar to a counter that ensures each domain - has started and complete each round simultanously. All domains - wait for the other before beginning the next round. *) +(** An orchestrator is similar to a counter that ensures each domain has started + and complete each round simultanously. All domains wait for the other before + beginning the next round. *) val init : total_domains:int -> rounds:int -> t -(** [init ~total_domains:nd ~rounds:nr] create an orchestrator that - will run [nr] rounds for a test that uses exactly [nd] worker - domains *) +(** [init ~total_domains:nd ~rounds:nr] create an orchestrator that will run + [nr] rounds for a test that uses exactly [nd] worker domains *) val worker : t -> (unit -> unit) -> unit -(** [worker t f] builds the function to pass to [Domain.spawn] while - using the orchestrator [t]. Doing [Domain.spawn (fun () -> worker - t f)] is similar to [Domain.spawn f] except that the orchestrator - is used to synchronize all domains progress. - *) +(** [worker t f] builds the function to pass to [Domain.spawn] while using the + orchestrator [t]. Doing [Domain.spawn (fun () -> worker t f)] is similar to + [Domain.spawn f] except that the orchestrator is used to synchronize all + domains progress. *) val run : ?drop_first:bool -> t -> float List.t -(** [run t] is launching the benchmark by enabling domains to progress. Benchmarks code should have the following structure : +(** [run t] is launching the benchmark by enabling domains to progress. + Benchmarks code should have the following structure : -{[ - (* Initialize the orchestrator, with [nd] the number of domains we want. *) - let orchestrator = init ~total_domain:nd ~round:100 in - (* Spawn domains with [worker] *) - let domains = - List.init nd (fun _ -> - Domain.spawn (fun () -> - worker orchestrator (fun () -> some_function ()))) in - (* Run the benchmarks by freeing domains round by round. *) - let times = run orchestrator in - ... -]} - -*) + {[ + (* Initialize the orchestrator, with [nd] the number of domains we want. *) + let orchestrator = init ~total_domain:nd ~round:100 in + (* Spawn domains with [worker] *) + let domains = + List.init nd (fun _ -> + Domain.spawn (fun () -> + worker orchestrator (fun () -> some_function ()))) in + (* Run the benchmarks by freeing domains round by round. *) + let times = run orchestrator in + ... + ]} *) diff --git a/bench/taslock.ml b/bench/taslock.ml index f5769d1..469ab27 100644 --- a/bench/taslock.ml +++ b/bench/taslock.ml @@ -15,9 +15,10 @@ module TASlock : LOCK = struct let create () = Atomic.make false let rec acquire t = - if not @@ Atomic.compare_and_set t false true then ( + if not @@ Atomic.compare_and_set t false true then begin Domain.cpu_relax (); - acquire t) + acquire t + end let release t = Atomic.set t false end @@ -28,12 +29,14 @@ module TTASlock : LOCK = struct let create () = Atomic.make false let rec acquire t = - if Atomic.get t then ( + if Atomic.get t then begin Domain.cpu_relax (); - acquire t) - else if not (Atomic.compare_and_set t false true) then ( + acquire t + end + else if not (Atomic.compare_and_set t false true) then begin Domain.cpu_relax (); - acquire t) + acquire t + end let release t = Atomic.set t false end @@ -44,9 +47,10 @@ module TTASlock_boff : LOCK = struct let create () = Atomic.make false let rec acquire_ ?(backoff = Backoff.default) t = - if Atomic.get t then ( + if Atomic.get t then begin Domain.cpu_relax (); - acquire_ ~backoff t) + acquire_ ~backoff t + end else if not (Atomic.compare_and_set t false true) then acquire_ ~backoff:(Backoff.once backoff) t diff --git a/src/backoff.mli b/src/backoff.mli index f032c4b..b00b5f3 100644 --- a/src/backoff.mli +++ b/src/backoff.mli @@ -25,7 +25,7 @@ val max_wait_log : int (** Logarithm of the maximum allowed value for wait. *) val create : ?lower_wait_log:int -> ?upper_wait_log:int -> unit -> t -(** [create] creates a backoff value. [upper_wait_log], [lower_wait_log] +(** [create] creates a backoff value. [upper_wait_log], [lower_wait_log] override the logarithmic upper and lower bound on the number of spins executed by {!once}. *)