Skip to content

Commit

Permalink
Upgrade to ocamlformat 0.27.0; Add exp-grouping=preserve to config
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Dec 17, 2024
1 parent dc7ebbb commit 26bcf69
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
profile = default
version = 0.26.2
version = 0.27.0

exp-grouping=preserve
53 changes: 25 additions & 28 deletions bench/orchestrator.mli
Original file line number Diff line number Diff line change
@@ -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
...
]} *)
20 changes: 12 additions & 8 deletions bench/taslock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/backoff.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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}. *)

Expand Down

0 comments on commit 26bcf69

Please sign in to comment.