xref: /xnu-11215.81.4/tests/sched/sched_test_utils.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1 #ifndef XNU_SCHED_TEST_UTILS_H
2 #define XNU_SCHED_TEST_UTILS_H
3 
4 #include <stdbool.h>
5 
6 /* -- Meta-controls -- */
7 
8 /* Verbose printing mode is enabled by default */
9 void disable_verbose_sched_utils(void);
10 void reenable_verbose_sched_utils(void);
11 
12 /* -- Time conversions -- */
13 uint64_t nanos_to_abs(uint64_t nanos);
14 uint64_t abs_to_nanos(uint64_t abs);
15 
16 /* -- Thread orchestration -- */
17 void spin_for_duration(uint32_t seconds);
18 
19 /* -- ��️ Platform checks -- */
20 bool platform_is_amp(void);
21 bool platform_is_virtual_machine(void);
22 char *platform_sched_policy(void);
23 
24 /* -- ���� Monitor system performance state -- */
25 
26 /*
27  * Returns true if the system successfully quiesced below the specified threshold
28  * within the specified timeout, and false otherwise.
29  * idle_threshold is given as a ratio between [0.0, 1.0], defaulting to 0.9.
30  */
31 bool wait_for_quiescence(double idle_threshold, int timeout_seconds);
32 bool wait_for_quiescence_default(void);
33 
34 /* Returns true if all cores on the device are recommended */
35 bool check_recommended_core_mask(uint64_t *core_mask);
36 
37 /* -- ��️ Query/control CPU topology -- */
38 
39 /*
40  * Spawns and waits for clpcctrl with the given arguments.
41  * If read_value is true, returns the value assumed to be elicited from clpcctrl.
42  */
43 uint64_t execute_clpcctrl(char *clpcctrl_args[], bool read_value);
44 
45 /* -- ��️ Record traces -- */
46 
47 /*
48  * Tracing requires root privilege.
49  *
50  * Standard usage of this interface would be to call begin_collect_trace()
51  * followed by end_collect_trace() and allow the library to automatically
52  * handle saving/discarding the collected trace upon test end. Traces will
53  * automatically be saved if a failure occurred during the test run and
54  * discarded otherwise.
55  */
56 
57 typedef void *trace_handle_t;
58 
59 /*
60  * Begins trace collection, using the specified name as a prefix for all
61  * generated filenames.
62  *
63  * NOTE: Since scheduler tracing can generate large trace files when left to
64  * run for long durations, take care to begin tracing close to the start of
65  * the period of interest.
66  */
67 trace_handle_t begin_collect_trace(char *filename);
68 trace_handle_t begin_collect_trace_fmt(char *filename_fmt, ...);
69 
70 /*
71  * NOTE: It's possible that tests may induce CPU starvation that can
72  * prevent the trace from ending or cause post-processing to take an extra
73  * long time. This can be avoided by terminating or blocking spawned test
74  * threads before calling end_collect_trace().
75  */
76 void end_collect_trace(trace_handle_t handle);
77 
78 /*
79  * Saves the recorded trace file to a tarball and marks the tarball for
80  * upload in BATS as a debugging artifact.
81  */
82 void save_collected_trace(trace_handle_t handle);
83 
84 /* Deletes the recorded trace */
85 void discard_collected_trace(trace_handle_t handle);
86 
87 #endif /* XNU_SCHED_TEST_UTILS_H */
88