Skip to content

Commit 6b64cae

Browse files
committed
Upgrade dscheck to allow testing on OCaml 4 with ocaml-ci
1 parent 8937436 commit 6b64cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+444
-322
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,3 @@ jobs:
4646

4747
- name: Test
4848
run: opam exec -- dune runtest
49-
50-
build-4_x:
51-
strategy:
52-
fail-fast: false
53-
matrix:
54-
os:
55-
- ubuntu-latest
56-
ocaml-compiler:
57-
- 4.13.x
58-
- 4.14.x
59-
60-
runs-on: ${{ matrix.os }}
61-
62-
steps:
63-
- name: Check out code
64-
uses: actions/checkout@v3
65-
66-
- name: Set up OCaml
67-
uses: ocaml/setup-ocaml@v2
68-
with:
69-
opam-pin: false
70-
opam-depext: false
71-
ocaml-compiler: ${{ matrix.ocaml-compiler }}
72-
73-
- name: Install dependencies
74-
run: opam install . --deps-only
75-
76-
- name: Build (release)
77-
run: opam exec -- dune build --release

bench/bench_queue.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ let run_one ~budgetf ?(n_adders = 2) ?(n_takers = 2)
4646
let n = Util.alloc n_msgs_to_take in
4747
if n <> 0 then
4848
let rec loop n =
49-
if 0 < n then
50-
loop (n - Bool.to_int (Option.is_some (Queue.pop_opt t)))
49+
if 0 < n then begin
50+
match Queue.pop_opt t with
51+
| None ->
52+
Domain.cpu_relax ();
53+
loop n
54+
| Some _ -> loop (n - 1)
55+
end
5156
else work ()
5257
in
5358
loop n

bench/bench_relaxed_queue.ml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@ let run_one ~budgetf ~n_adders ~n_takers ?(n_msgs = 50 * Util.iter_factor)
3131
work ()
3232
| `Not_lockfree ->
3333
let rec loop n =
34-
if 0 < n then loop (n - Bool.to_int (Not_lockfree.push t i))
34+
if 0 < n then
35+
if Not_lockfree.push t i then loop (n - 1)
36+
else begin
37+
Domain.cpu_relax ();
38+
loop n
39+
end
3540
else work ()
3641
in
3742
loop n
3843
| `CAS_interface ->
3944
let rec loop n =
40-
if 0 < n then loop (n - Bool.to_int (CAS_interface.push t i))
45+
if 0 < n then
46+
if CAS_interface.push t i then loop (n - 1)
47+
else begin
48+
Domain.cpu_relax ();
49+
loop n
50+
end
4151
else work ()
4252
in
4353
loop n
@@ -56,15 +66,25 @@ let run_one ~budgetf ~n_adders ~n_takers ?(n_msgs = 50 * Util.iter_factor)
5666
work ()
5767
| `Not_lockfree ->
5868
let rec loop n =
59-
if 0 < n then
60-
loop (n - Bool.to_int (Option.is_some (Not_lockfree.pop t)))
69+
if 0 < n then begin
70+
match Not_lockfree.pop t with
71+
| None ->
72+
Domain.cpu_relax ();
73+
loop n
74+
| Some _ -> loop (n - 1)
75+
end
6176
else work ()
6277
in
6378
loop n
6479
| `CAS_interface ->
6580
let rec loop n =
66-
if 0 < n then
67-
loop (n - Bool.to_int (Option.is_some (CAS_interface.pop t)))
81+
if 0 < n then begin
82+
match CAS_interface.pop t with
83+
| None ->
84+
Domain.cpu_relax ();
85+
loop n
86+
| Some _ -> loop (n - 1)
87+
end
6888
else work ()
6989
in
7090
loop n

bench/bench_spsc_queue.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@ let run_one ~budgetf ?(size_exponent = 3) ?(n_msgs = 80 * Util.iter_factor) () =
1717
let work i () =
1818
if i = 0 then
1919
let rec loop n =
20-
if 0 < n then loop (n - Bool.to_int (Queue.try_push t n))
20+
if 0 < n then
21+
if Queue.try_push t n then loop (n - 1)
22+
else begin
23+
Domain.cpu_relax ();
24+
loop n
25+
end
2126
in
2227
loop n_msgs
2328
else
2429
let rec loop n =
2530
if 0 < n then
26-
match Queue.pop_opt t with Some _ -> loop (n - 1) | None -> loop n
31+
match Queue.pop_opt t with
32+
| Some _ -> loop (n - 1)
33+
| None ->
34+
Domain.cpu_relax ();
35+
loop n
2736
in
2837
loop n_msgs
2938
in

bench/bench_ws_deque.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ let run_one ~budgetf ?(n_domains = 1) () =
2929
| work ->
3030
work own;
3131
run own
32-
| exception Exit -> if not !exit then run own
32+
| exception Exit ->
33+
if not !exit then begin
34+
Domain.cpu_relax ();
35+
run own
36+
end
3337
in
3438

3539
let spawn own work =
@@ -42,7 +46,9 @@ let run_one ~budgetf ?(n_domains = 1) () =
4246
let x = !promise in
4347
if x == Obj.magic exit then begin
4448
begin
45-
match try_own own with exception Exit -> () | work -> work own
49+
match try_own own with
50+
| exception Exit -> Domain.cpu_relax ()
51+
| work -> work own
4652
end;
4753
await own promise
4854
end

bench/dune

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
(* -*- tuareg -*- *)
2+
3+
let maybe_domain_shims =
4+
if Jbuild_plugin.V1.ocaml_version < "5" then "domain_shims" else ""
5+
6+
let () =
7+
Jbuild_plugin.V1.send
8+
@@ {|
9+
110
(test
211
(package saturn)
312
(name main)
4-
(libraries saturn multicore-bench multicore-magic))
13+
(libraries saturn multicore-bench multicore-magic |}
14+
^ maybe_domain_shims ^ {| ))
15+
|}

dune-project

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(lang dune 3.2)
1+
(lang dune 3.9)
22
(name saturn)
33
(generate_opam_files true)
44
(implicit_transitive_deps false)
@@ -16,12 +16,13 @@
1616
(saturn_lockfree (= :version))
1717
(multicore-magic (and (>= 2.1.0) :with-test))
1818
(multicore-bench (and (>= 0.1.0) :with-test))
19+
(backoff (and (>= 0.1.0) :with-test))
1920
(alcotest (and (>= 1.7.0) :with-test))
2021
(qcheck (and (>= 0.21.3) :with-test))
2122
(qcheck-stm (and (>= 0.3) :with-test))
2223
(qcheck-alcotest (and (>= 0.21.3) :with-test))
2324
(yojson (and (>= 2.0.2) :with-test))
24-
(dscheck (and (>= 0.2.0) :with-test))))
25+
(dscheck (and (>= 0.4.0) :with-test))))
2526
(package
2627
(name saturn_lockfree)
2728
(synopsis "Collection of lock-free data structures for Multicore OCaml")
@@ -37,4 +38,4 @@
3738
(qcheck-multicoretests-util (and (>= 0.3) :with-test))
3839
(qcheck-alcotest (and (>= 0.21.3) :with-test))
3940
(yojson (and (>= 2.0.2) :with-test))
40-
(dscheck (and (>= 0.2.0) :with-test))))
41+
(dscheck (and (>= 0.4.0) :with-test))))

saturn.opam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ homepage: "https://github.com/ocaml-multicore/saturn"
99
doc: "https://ocaml-multicore.github.io/saturn/"
1010
bug-reports: "https://github.com/ocaml-multicore/saturn/issues"
1111
depends: [
12-
"dune" {>= "3.2"}
12+
"dune" {>= "3.9"}
1313
"ocaml" {>= "4.13"}
1414
"domain_shims" {>= "0.1.0" & with-test}
1515
"saturn_lockfree" {= version}
1616
"multicore-magic" {>= "2.1.0" & with-test}
1717
"multicore-bench" {>= "0.1.0" & with-test}
18+
"backoff" {>= "0.1.0" & with-test}
1819
"alcotest" {>= "1.7.0" & with-test}
1920
"qcheck" {>= "0.21.3" & with-test}
2021
"qcheck-stm" {>= "0.3" & with-test}
2122
"qcheck-alcotest" {>= "0.21.3" & with-test}
2223
"yojson" {>= "2.0.2" & with-test}
23-
"dscheck" {>= "0.2.0" & with-test}
24+
"dscheck" {>= "0.4.0" & with-test}
2425
"odoc" {with-doc}
2526
]
2627
build: [

saturn_lockfree.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ homepage: "https://github.com/ocaml-multicore/saturn"
88
doc: "https://ocaml-multicore.github.io/saturn/"
99
bug-reports: "https://github.com/ocaml-multicore/saturn/issues"
1010
depends: [
11-
"dune" {>= "3.2"}
11+
"dune" {>= "3.9"}
1212
"ocaml" {>= "4.13"}
1313
"domain_shims" {>= "0.1.0" & with-test}
1414
"backoff" {>= "0.1.0"}
@@ -20,7 +20,7 @@ depends: [
2020
"qcheck-multicoretests-util" {>= "0.3" & with-test}
2121
"qcheck-alcotest" {>= "0.21.3" & with-test}
2222
"yojson" {>= "2.0.2" & with-test}
23-
"dscheck" {>= "0.2.0" & with-test}
23+
"dscheck" {>= "0.4.0" & with-test}
2424
"odoc" {with-doc}
2525
]
2626
build: [

src/domain.ocaml4.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let cpu_relax = Thread.yield

0 commit comments

Comments
 (0)