Skip to content

Commit bdbdc67

Browse files
committed
By default run an extra (busy) domain when n_domains = 1
The OCaml runtime has a number of special cases when running only a single domain. When benchmarking multicore abstractions we probably don't want to benchmark those special cases except in special cases.
1 parent 7c0a5ae commit bdbdc67

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/multicore_bench.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ module Times : sig
22
type t
33

44
val record :
5-
n_domains:int ->
65
budgetf:float ->
6+
n_domains:int ->
7+
?ensure_multi_domain:bool ->
78
?n_warmups:int ->
89
?n_runs_min:int ->
910
?before:(unit -> unit) ->

lib/times.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type t = { inverted : bool; times_per_domain : float array array; runs : int }
22

3-
let record ~n_domains ~budgetf ?(n_warmups = 3) ?(n_runs_min = 7)
4-
?(before = Fun.id) ~init ~work ?(after = Fun.id) () =
3+
let record ~budgetf ~n_domains ?(ensure_multi_domain = true) ?(n_warmups = 3)
4+
?(n_runs_min = 7) ?(before = Fun.id) ~init ~work ?(after = Fun.id) () =
55
let barrier_init = Barrier.make n_domains in
66
let barrier_before = Barrier.make n_domains in
77
let barrier_after = Barrier.make n_domains in
@@ -11,6 +11,16 @@ let record ~n_domains ~budgetf ?(n_warmups = 3) ?(n_runs_min = 7)
1111
in
1212
let budget_used = ref false |> Multicore_magic.copy_as_padded in
1313
let runs = ref 0 |> Multicore_magic.copy_as_padded in
14+
let exit = ref false in
15+
let extra_domain =
16+
if n_domains = 1 && ensure_multi_domain then
17+
Some
18+
( Domain.spawn @@ fun () ->
19+
while not !exit do
20+
Domain.cpu_relax ()
21+
done )
22+
else None
23+
in
1424
Gc.full_major ();
1525
let budget_start = Mtime_clock.elapsed () in
1626
let prepare_for_await () =
@@ -86,6 +96,8 @@ let record ~n_domains ~budgetf ?(n_warmups = 3) ?(n_runs_min = 7)
8696
in
8797
main 0;
8898
Array.iter Domain.join domains;
99+
exit := true;
100+
Option.iter Domain.join extra_domain;
89101
let times_per_domain =
90102
Array.init (Array.length results) @@ fun i ->
91103
Stack.to_seq results.(i) |> Array.of_seq

0 commit comments

Comments
 (0)