Skip to content

Commit 7fefe99

Browse files
committed
Avoid false sharing in Hashtbl benchmark
1 parent c417954 commit 7fefe99

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

dune-project

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
(synopsis "Compositional lock-free data structures and primitives for communication and synchronization")
1717
(depends
1818
(kcas (= :version))
19-
(mdx (and (>= 1.10.0) :with-test))))
19+
(mdx (and (>= 1.10.0) :with-test))
20+
(multicore-magic (and (>= 1.0.0) :with-test))))
2021
(using mdx 0.2)

kcas_data.opam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ depends: [
1111
"dune" {>= "3.3"}
1212
"kcas" {= version}
1313
"mdx" {>= "1.10.0" & with-test}
14+
"multicore-magic" {>= "1.0.0" & with-test}
1415
"odoc" {with-doc}
1516
]
1617
build: [

test/kcas_data/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(test
88
(name hashtbl_bench)
99
(modules hashtbl_bench)
10-
(libraries kcas kcas_data unix)
10+
(libraries kcas kcas_data unix multicore-magic)
1111
(package kcas_data))
1212

1313
(test

test/kcas_data/hashtbl_bench.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ module Int = struct
77
end
88

99
let bench ~n_domains ~n_ops ~n_keys ~percent_read =
10-
let t = Hashtbl.create ~hashed_type:(module Int) () in
10+
let t =
11+
Hashtbl.create ~hashed_type:(module Int) ()
12+
|> Multicore_magic.copy_as_padded
13+
in
1114

1215
for i = 0 to n_keys - 1 do
1316
Hashtbl.replace t i i
1417
done;
1518

1619
let barrier = Atomic.make n_domains in
1720

18-
let n_ops_todo = Atomic.make n_ops in
21+
let n_ops_todo = Atomic.make n_ops |> Multicore_magic.copy_as_padded in
1922
let rec alloc_ops () =
2023
let n = Atomic.get n_ops_todo in
2124
if n = 0 then 0

0 commit comments

Comments
 (0)