Skip to content

Commit a0b3026

Browse files
committed
CP-52911: benchmark Timeslice.Runtime functions
Adds a benchmarking test for functions used in `Timeslice.Runtime` module. This functions are meant to have low overhead and should have a minimum of memory allocations. Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
1 parent c7d8159 commit a0b3026

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

ocaml/tests/bench/dune

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(executables
22
(names
3+
bench_timeslice
34
bench_tracing
45
bench_uuid
56
bench_throttle2
@@ -10,6 +11,7 @@
1011
bechamel
1112
bechamel-notty
1213
notty.unix
14+
tgroup
1315
tracing_export
1416
threads.posix
1517
fmt
@@ -18,4 +20,6 @@
1820
xapi_aux
1921
tests_common
2022
log
21-
xapi_internal))
23+
xapi_internal
24+
xapi_timeslice
25+
xapi-stdext-threads))

0 commit comments

Comments
 (0)