|
| 1 | +open Bechamel |
| 2 | + |
| 3 | +let test_maybe_thread_yield () = |
| 4 | + Sys.opaque_identity |
| 5 | + (Xapi_timeslice.Timeslice.Runtime.maybe_thread_yield |
| 6 | + ~global_slice_period:10_000_000 |
| 7 | + ) |
| 8 | + |
| 9 | +let test_sched_global_slice () = |
| 10 | + Sys.opaque_identity |
| 11 | + (Xapi_timeslice.Timeslice.Runtime.sched_global_slice |
| 12 | + ~global_slice_period:10_000_000 |
| 13 | + ) |
| 14 | + |
| 15 | +let test_tgroups_on ~name f = |
| 16 | + let allocate () = |
| 17 | + let () = Atomic.set Tgroup.Cgroup.cgroup_dir (Some "") in |
| 18 | + let g_cli = Some "cli" |> Tgroup.of_req_originator |> Option.get in |
| 19 | + let tg_cli = Tgroup.ThreadGroup.create ~tgroup:g_cli in |
| 20 | + let () = tg_cli.thread_count <- Atomic.make 10 in |
| 21 | + let tg_authenticated_root = |
| 22 | + Tgroup.ThreadGroup.create ~tgroup:Tgroup.Group.authenticated_root |
| 23 | + in |
| 24 | + let () = tg_authenticated_root.thread_count <- Atomic.make 5 in |
| 25 | + Tgroup.ThreadGroup.(add tg_cli ; add tg_authenticated_root) |
| 26 | + in |
| 27 | + let free = Tgroup.ThreadGroup.destroy in |
| 28 | + Test.make_with_resource ~name ~allocate ~free Test.uniq f |
| 29 | + |
| 30 | +let test_with_thread_classified ~name f = |
| 31 | + let allocate () = |
| 32 | + let () = Atomic.set Tgroup.Cgroup.cgroup_dir (Some "") in |
| 33 | + let g_cli = Some "cli" |> Tgroup.of_req_originator |> Option.get in |
| 34 | + let tg_cli = Tgroup.ThreadGroup.create ~tgroup:g_cli in |
| 35 | + let () = tg_cli.thread_count <- Atomic.make 10 in |
| 36 | + let tg_authenticated_root = |
| 37 | + Tgroup.ThreadGroup.create ~tgroup:Tgroup.Group.authenticated_root |
| 38 | + in |
| 39 | + let () = tg_authenticated_root.thread_count <- Atomic.make 1 in |
| 40 | + Xapi_stdext_threads.Threadext.ThreadRuntimeContext.( |
| 41 | + let thread_ctx = get () in |
| 42 | + update |
| 43 | + (fun thread_ctx -> |
| 44 | + {thread_ctx with tgroup= Tgroup.Group.authenticated_root} |
| 45 | + ) |
| 46 | + thread_ctx |
| 47 | + ) ; |
| 48 | + Tgroup.ThreadGroup.(add tg_cli ; add tg_authenticated_root) |
| 49 | + in |
| 50 | + let free () = |
| 51 | + Tgroup.ThreadGroup.destroy () ; |
| 52 | + Xapi_stdext_threads.Threadext.ThreadRuntimeContext.remove () |
| 53 | + in |
| 54 | + Test.make_with_resource ~name ~allocate ~free Test.uniq f |
| 55 | + |
| 56 | +let benchmarks = |
| 57 | + Test.make_grouped ~name:"timeslice" |
| 58 | + [ |
| 59 | + test_with_thread_classified ~name:"maybe_thread_yield" |
| 60 | + (Staged.stage test_maybe_thread_yield) |
| 61 | + ; test_tgroups_on ~name:"sched_global_slice" |
| 62 | + (Staged.stage test_sched_global_slice) |
| 63 | + ] |
| 64 | + |
| 65 | +let () = Bechamel_simple_cli.cli benchmarks |
0 commit comments