|
1 | 1 | open Kcas |
2 | 2 | open Bench |
3 | 3 |
|
4 | | -let run_one ?(factor = 1) ?(n_iter = 10 * factor * Util.iter_factor) () = |
| 4 | +let run_one ~n_domains ?(factor = 1) ?(n_ops = 50 * factor * Util.iter_factor) |
| 5 | + () = |
| 6 | + let n_ops = n_ops * n_domains in |
| 7 | + |
5 | 8 | let a = Loc.make ~padded:true 10 in |
6 | 9 | let b = Loc.make ~padded:true 52 in |
| 10 | + let xs = Loc.make_array ~padded:true n_domains 0 in |
| 11 | + |
| 12 | + let n_ops_todo = Atomic.make n_ops |> Multicore_magic.copy_as_padded in |
| 13 | + |
| 14 | + let init i = Array.unsafe_get xs i in |
7 | 15 |
|
8 | | - let init _ = Loc.make ~padded:true 0 in |
9 | | - let work i x = |
10 | | - if i land 1 = 0 then begin |
11 | | - let tx1 ~xt = |
12 | | - let a = Xt.get ~xt a in |
13 | | - let b = Xt.get ~xt b in |
14 | | - Xt.set ~xt x (b - a) |
15 | | - and tx2 ~xt = |
16 | | - let a = Xt.get ~xt a in |
17 | | - let b = Xt.get ~xt b in |
18 | | - Xt.set ~xt x (a + b) |
19 | | - in |
20 | | - let tx1 = { Xt.tx = tx1 } and tx2 = { Xt.tx = tx2 } in |
21 | | - for _ = 1 to n_iter asr 1 do |
22 | | - Xt.commit tx1; |
23 | | - Xt.commit tx2 |
24 | | - done |
25 | | - end |
26 | | - else begin |
27 | | - let tx1 ~xt = |
28 | | - let a = Xt.get ~xt a in |
29 | | - let b = Xt.get ~xt b in |
30 | | - Xt.set ~xt x (b - a) |
31 | | - and tx2 ~xt = |
32 | | - let a = Xt.get ~xt a in |
33 | | - let b = Xt.get ~xt b in |
34 | | - Xt.set ~xt x (a + b) |
35 | | - in |
36 | | - let tx1 = { Xt.tx = tx1 } and tx2 = { Xt.tx = tx2 } in |
37 | | - for _ = 1 to n_iter asr 1 do |
38 | | - Xt.commit tx1; |
39 | | - Xt.commit tx2 |
40 | | - done |
41 | | - end |
| 16 | + let work _ x = |
| 17 | + let tx1 ~xt = |
| 18 | + let a = Xt.get ~xt a in |
| 19 | + let b = Xt.get ~xt b in |
| 20 | + Xt.set ~xt x (b - a) |
| 21 | + and tx2 ~xt = |
| 22 | + let a = Xt.get ~xt a in |
| 23 | + let b = Xt.get ~xt b in |
| 24 | + Xt.set ~xt x (a + b) |
| 25 | + in |
| 26 | + let rec work () = |
| 27 | + let n = Util.alloc n_ops_todo in |
| 28 | + if n <> 0 then begin |
| 29 | + for _ = 1 to n asr 1 do |
| 30 | + Xt.commit { tx = tx1 }; |
| 31 | + Xt.commit { tx = tx2 } |
| 32 | + done; |
| 33 | + work () |
| 34 | + end |
| 35 | + in |
| 36 | + work () |
42 | 37 | in |
43 | 38 |
|
44 | | - let times = Times.record ~n_domains:2 ~init ~work () in |
| 39 | + let after () = Atomic.set n_ops_todo n_ops in |
| 40 | + |
| 41 | + let times = Times.record ~n_domains ~init ~work ~after () in |
| 42 | + |
| 43 | + let name metric = |
| 44 | + Printf.sprintf "%s/%d worker%s" metric n_domains |
| 45 | + (if n_domains = 1 then "" else "s") |
| 46 | + in |
45 | 47 |
|
46 | 48 | List.concat |
47 | 49 | [ |
48 | 50 | Stats.of_times times |
49 | | - |> Stats.scale (1_000_000_000.0 /. Float.of_int n_iter) |
50 | | - |> Stats.to_json ~name:"time per transaction" |
| 51 | + |> Stats.scale (1_000_000_000.0 /. Float.of_int n_ops) |
| 52 | + |> Stats.to_json |
| 53 | + ~name:(name "time per transaction") |
51 | 54 | ~description:"Time to perform a single transaction" ~units:"ns"; |
52 | 55 | Times.invert times |> Stats.of_times |
53 | | - |> Stats.scale (Float.of_int (n_iter * 2) /. 1_000_000.0) |
54 | | - |> Stats.to_json ~name:"transactions over time" |
| 56 | + |> Stats.scale (Float.of_int (n_ops * n_domains) /. 1_000_000.0) |
| 57 | + |> Stats.to_json |
| 58 | + ~name:(name "transactions over time") |
55 | 59 | ~description: |
56 | 60 | "Number of transactions performed over time using 2 domains" |
57 | 61 | ~units:"M/s"; |
58 | 62 | ] |
59 | 63 |
|
60 | | -let run_suite ~factor = run_one ~factor () |
| 64 | +let run_suite ~factor = |
| 65 | + [ 1; 2; 4 ] |
| 66 | + |> List.concat_map @@ fun n_domains -> run_one ~n_domains ~factor () |
0 commit comments