|
| 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 () = Tgroup.add g_cli in |
| 20 | + let tg_cli = Tgroup.group_of_description g_cli |> Option.get in |
| 21 | + let _ = Atomic.fetch_and_add tg_cli.thread_count 10 in |
| 22 | + let () = Tgroup.add Tgroup.Description.authenticated_root in |
| 23 | + let tg_authenticated_root = |
| 24 | + Tgroup.group_of_description Tgroup.Description.authenticated_root |
| 25 | + |> Option.get |
| 26 | + in |
| 27 | + let _ = Atomic.fetch_and_add tg_authenticated_root.thread_count 5 in |
| 28 | + () |
| 29 | + in |
| 30 | + let free = Tgroup.destroy in |
| 31 | + Test.make_with_resource ~name ~allocate ~free Test.uniq f |
| 32 | + |
| 33 | +let test_with_thread_classified ~name f = |
| 34 | + let allocate () = |
| 35 | + let () = Atomic.set Tgroup.Cgroup.cgroup_dir (Some "") in |
| 36 | + let g_cli = Some "cli" |> Tgroup.of_req_originator |> Option.get in |
| 37 | + let () = Tgroup.add g_cli in |
| 38 | + let tg_cli = Tgroup.group_of_description g_cli |> Option.get in |
| 39 | + let _ = Atomic.fetch_and_add tg_cli.thread_count 10 in |
| 40 | + let () = Tgroup.add Tgroup.Description.authenticated_root in |
| 41 | + let tg_authenticated_root = |
| 42 | + Tgroup.group_of_description Tgroup.Description.authenticated_root |
| 43 | + |> Option.get |
| 44 | + in |
| 45 | + let () = Atomic.incr tg_authenticated_root.thread_count in |
| 46 | + Xapi_stdext_threads.Threadext.ThreadRuntimeContext.( |
| 47 | + let thread_ctx = get () in |
| 48 | + update |
| 49 | + (fun thread_ctx -> |
| 50 | + {thread_ctx with tgroup= Tgroup.Description.authenticated_root} |
| 51 | + ) |
| 52 | + thread_ctx |
| 53 | + ) |
| 54 | + in |
| 55 | + let free () = |
| 56 | + Tgroup.destroy () ; |
| 57 | + Xapi_stdext_threads.Threadext.ThreadRuntimeContext.remove () |
| 58 | + in |
| 59 | + Test.make_with_resource ~name ~allocate ~free Test.uniq f |
| 60 | + |
| 61 | +let benchmarks = |
| 62 | + Test.make_grouped ~name:"timeslice" |
| 63 | + [ |
| 64 | + test_with_thread_classified ~name:"maybe_thread_yield" |
| 65 | + (Staged.stage test_maybe_thread_yield) |
| 66 | + ; test_tgroups_on ~name:"sched_global_slice" |
| 67 | + (Staged.stage test_sched_global_slice) |
| 68 | + ] |
| 69 | + |
| 70 | +let () = Bechamel_simple_cli.cli benchmarks |
0 commit comments