| 
 | 1 | +open Multicore_bench  | 
 | 2 | +open Picos_std_sync  | 
 | 3 | + | 
 | 4 | +let run_one_domain ~budgetf ?(n_msgs = 50 * Util.iter_factor) () =  | 
 | 5 | +  let t = Stack.create ~padded:true () in  | 
 | 6 | + | 
 | 7 | +  let op push =  | 
 | 8 | +    if push then Stack.push t 101  | 
 | 9 | +    else match Stack.pop_exn t with _ -> () | exception Stack.Empty -> ()  | 
 | 10 | +  in  | 
 | 11 | + | 
 | 12 | +  let init _ =  | 
 | 13 | +    assert (  | 
 | 14 | +      match Stack.pop_exn t with _ -> false | exception Stack.Empty -> true);  | 
 | 15 | +    Util.generate_push_and_pop_sequence n_msgs  | 
 | 16 | +  in  | 
 | 17 | +  let work _ bits = Util.Bits.iter op bits in  | 
 | 18 | + | 
 | 19 | +  Times.record ~budgetf ~n_domains:1 ~init ~work ()  | 
 | 20 | +  |> Times.to_thruput_metrics ~n:n_msgs ~singular:"message" ~config:"one domain"  | 
 | 21 | + | 
 | 22 | +let run_one ~budgetf ~n_adders ~n_takers () =  | 
 | 23 | +  let n_domains = n_adders + n_takers in  | 
 | 24 | + | 
 | 25 | +  let n_msgs = 50 * Util.iter_factor in  | 
 | 26 | + | 
 | 27 | +  let t = Stack.create ~padded:true () in  | 
 | 28 | + | 
 | 29 | +  let n_msgs_to_add = Countdown.create ~n_domains:n_adders () in  | 
 | 30 | +  let n_msgs_to_take = Countdown.create ~n_domains:n_takers () in  | 
 | 31 | + | 
 | 32 | +  let init _ =  | 
 | 33 | +    assert (  | 
 | 34 | +      match Stack.pop_exn t with _ -> false | exception Stack.Empty -> true);  | 
 | 35 | +    Countdown.non_atomic_set n_msgs_to_add n_msgs;  | 
 | 36 | +    Countdown.non_atomic_set n_msgs_to_take n_msgs  | 
 | 37 | +  in  | 
 | 38 | +  let work i () =  | 
 | 39 | +    if i < n_adders then  | 
 | 40 | +      let rec work () =  | 
 | 41 | +        let n = Countdown.alloc n_msgs_to_add ~domain_index:i ~batch:1000 in  | 
 | 42 | +        if 0 < n then begin  | 
 | 43 | +          for i = 1 to n do  | 
 | 44 | +            Stack.push t i  | 
 | 45 | +          done;  | 
 | 46 | +          work ()  | 
 | 47 | +        end  | 
 | 48 | +      in  | 
 | 49 | +      work ()  | 
 | 50 | +    else  | 
 | 51 | +      let i = i - n_adders in  | 
 | 52 | +      let rec work () =  | 
 | 53 | +        let n = Countdown.alloc n_msgs_to_take ~domain_index:i ~batch:1000 in  | 
 | 54 | +        if 0 < n then  | 
 | 55 | +          let rec loop n =  | 
 | 56 | +            if 0 < n then begin  | 
 | 57 | +              match Stack.pop_exn t with  | 
 | 58 | +              | _ -> loop (n - 1)  | 
 | 59 | +              | exception Stack.Empty ->  | 
 | 60 | +                  Backoff.once Backoff.default |> ignore;  | 
 | 61 | +                  loop n  | 
 | 62 | +            end  | 
 | 63 | +            else work ()  | 
 | 64 | +          in  | 
 | 65 | +          loop n  | 
 | 66 | +      in  | 
 | 67 | +      work ()  | 
 | 68 | +  in  | 
 | 69 | + | 
 | 70 | +  let config =  | 
 | 71 | +    let format role n =  | 
 | 72 | +      Printf.sprintf "%d %s%s" n role (if n = 1 then "" else "s")  | 
 | 73 | +    in  | 
 | 74 | +    Printf.sprintf "%s, %s"  | 
 | 75 | +      (format "nb adder" n_adders)  | 
 | 76 | +      (format "nb taker" n_takers)  | 
 | 77 | +  in  | 
 | 78 | +  Times.record ~budgetf ~n_domains ~init ~work ()  | 
 | 79 | +  |> Times.to_thruput_metrics ~n:n_msgs ~singular:"message" ~config  | 
 | 80 | + | 
 | 81 | +let run_suite ~budgetf =  | 
 | 82 | +  run_one_domain ~budgetf ()  | 
 | 83 | +  @ (Util.cross [ 1; 2; 4 ] [ 1; 2; 4 ]  | 
 | 84 | +    |> List.concat_map @@ fun (n_adders, n_takers) ->  | 
 | 85 | +       if Picos_domain.recommended_domain_count () < n_adders + n_takers then []  | 
 | 86 | +       else run_one ~budgetf ~n_adders ~n_takers ())  | 
0 commit comments