xref: /aosp_15_r20/external/igt-gpu-tools/lib/igt_aux.h (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
1*d83cc019SAndroid Build Coastguard Worker /*
2*d83cc019SAndroid Build Coastguard Worker  * Copyright © 2014, 2015 Intel Corporation
3*d83cc019SAndroid Build Coastguard Worker  *
4*d83cc019SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*d83cc019SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*d83cc019SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*d83cc019SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*d83cc019SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*d83cc019SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*d83cc019SAndroid Build Coastguard Worker  *
11*d83cc019SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*d83cc019SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*d83cc019SAndroid Build Coastguard Worker  * Software.
14*d83cc019SAndroid Build Coastguard Worker  *
15*d83cc019SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*d83cc019SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*d83cc019SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*d83cc019SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*d83cc019SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*d83cc019SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*d83cc019SAndroid Build Coastguard Worker  * IN THE SOFTWARE.
22*d83cc019SAndroid Build Coastguard Worker  *
23*d83cc019SAndroid Build Coastguard Worker  * Authors:
24*d83cc019SAndroid Build Coastguard Worker  *    Daniel Vetter <[email protected]>
25*d83cc019SAndroid Build Coastguard Worker  *
26*d83cc019SAndroid Build Coastguard Worker  */
27*d83cc019SAndroid Build Coastguard Worker 
28*d83cc019SAndroid Build Coastguard Worker #ifndef IGT_AUX_H
29*d83cc019SAndroid Build Coastguard Worker #define IGT_AUX_H
30*d83cc019SAndroid Build Coastguard Worker 
31*d83cc019SAndroid Build Coastguard Worker #include <inttypes.h>
32*d83cc019SAndroid Build Coastguard Worker #include <stdbool.h>
33*d83cc019SAndroid Build Coastguard Worker #include <stddef.h>
34*d83cc019SAndroid Build Coastguard Worker #include <sys/time.h>
35*d83cc019SAndroid Build Coastguard Worker #include <sys/types.h>
36*d83cc019SAndroid Build Coastguard Worker #include <unistd.h>
37*d83cc019SAndroid Build Coastguard Worker #ifdef __linux__
38*d83cc019SAndroid Build Coastguard Worker # include <sys/syscall.h>
39*d83cc019SAndroid Build Coastguard Worker #endif
40*d83cc019SAndroid Build Coastguard Worker 
41*d83cc019SAndroid Build Coastguard Worker #include <i915/gem_submission.h>
42*d83cc019SAndroid Build Coastguard Worker 
43*d83cc019SAndroid Build Coastguard Worker /* signal interrupt helpers */
44*d83cc019SAndroid Build Coastguard Worker #ifdef __linux__
45*d83cc019SAndroid Build Coastguard Worker # ifndef HAVE_GETTID
46*d83cc019SAndroid Build Coastguard Worker #  define gettid() (pid_t)(syscall(__NR_gettid))
47*d83cc019SAndroid Build Coastguard Worker # endif
48*d83cc019SAndroid Build Coastguard Worker #endif
49*d83cc019SAndroid Build Coastguard Worker #define sigev_notify_thread_id _sigev_un._tid
50*d83cc019SAndroid Build Coastguard Worker 
51*d83cc019SAndroid Build Coastguard Worker /* auxialiary igt helpers from igt_aux.c */
52*d83cc019SAndroid Build Coastguard Worker /* generally useful helpers */
53*d83cc019SAndroid Build Coastguard Worker void igt_fork_signal_helper(void);
54*d83cc019SAndroid Build Coastguard Worker void igt_stop_signal_helper(void);
55*d83cc019SAndroid Build Coastguard Worker void igt_suspend_signal_helper(void);
56*d83cc019SAndroid Build Coastguard Worker void igt_resume_signal_helper(void);
57*d83cc019SAndroid Build Coastguard Worker 
58*d83cc019SAndroid Build Coastguard Worker void igt_fork_shrink_helper(int fd);
59*d83cc019SAndroid Build Coastguard Worker void igt_stop_shrink_helper(void);
60*d83cc019SAndroid Build Coastguard Worker 
61*d83cc019SAndroid Build Coastguard Worker void igt_fork_hang_detector(int fd);
62*d83cc019SAndroid Build Coastguard Worker void igt_stop_hang_detector(void);
63*d83cc019SAndroid Build Coastguard Worker 
64*d83cc019SAndroid Build Coastguard Worker struct __igt_sigiter {
65*d83cc019SAndroid Build Coastguard Worker 	unsigned pass;
66*d83cc019SAndroid Build Coastguard Worker };
67*d83cc019SAndroid Build Coastguard Worker 
68*d83cc019SAndroid Build Coastguard Worker bool __igt_sigiter_continue(struct __igt_sigiter *iter, bool interrupt);
69*d83cc019SAndroid Build Coastguard Worker 
70*d83cc019SAndroid Build Coastguard Worker /**
71*d83cc019SAndroid Build Coastguard Worker  * igt_while_interruptible:
72*d83cc019SAndroid Build Coastguard Worker  * @enable: enable igt_ioctl interrupting or not
73*d83cc019SAndroid Build Coastguard Worker  *
74*d83cc019SAndroid Build Coastguard Worker  * Provides control flow such that all drmIoctl() (strictly igt_ioctl())
75*d83cc019SAndroid Build Coastguard Worker  * within the loop are forcibly injected with signals (SIGRTMIN).
76*d83cc019SAndroid Build Coastguard Worker  *
77*d83cc019SAndroid Build Coastguard Worker  * This is useful to exercise ioctl error paths, at least where those can be
78*d83cc019SAndroid Build Coastguard Worker  * exercises by interrupting blocking waits, like stalling for the gpu.
79*d83cc019SAndroid Build Coastguard Worker  *
80*d83cc019SAndroid Build Coastguard Worker  * The code block attached to this macro is run in a loop with doubling the
81*d83cc019SAndroid Build Coastguard Worker  * interrupt timeout on each ioctl for every run, until no ioctl gets
82*d83cc019SAndroid Build Coastguard Worker  * interrupted any more. The starting timeout is taken to be the signal delivery
83*d83cc019SAndroid Build Coastguard Worker  * latency, measured at runtime. This way the any ioctls called from this code
84*d83cc019SAndroid Build Coastguard Worker  * block should be exhaustively tested for all signal interruption paths.
85*d83cc019SAndroid Build Coastguard Worker  *
86*d83cc019SAndroid Build Coastguard Worker  * Note that since this overloads the igt_ioctl(), this method is not useful
87*d83cc019SAndroid Build Coastguard Worker  * for widespread signal injection, for example providing coverage of
88*d83cc019SAndroid Build Coastguard Worker  * pagefaults. To interrupt everything, see igt_fork_signal_helper().
89*d83cc019SAndroid Build Coastguard Worker  */
90*d83cc019SAndroid Build Coastguard Worker #define igt_while_interruptible(enable) \
91*d83cc019SAndroid Build Coastguard Worker 	for (struct __igt_sigiter iter__={}; __igt_sigiter_continue(&iter__, (enable)); )
92*d83cc019SAndroid Build Coastguard Worker 
93*d83cc019SAndroid Build Coastguard Worker /**
94*d83cc019SAndroid Build Coastguard Worker  * igt_until_timeout:
95*d83cc019SAndroid Build Coastguard Worker  * @timeout: timeout in seconds
96*d83cc019SAndroid Build Coastguard Worker  *
97*d83cc019SAndroid Build Coastguard Worker  * Convenience macro loop to run the provided code block in a loop until the
98*d83cc019SAndroid Build Coastguard Worker  * timeout has expired. Of course when an individual execution takes too long,
99*d83cc019SAndroid Build Coastguard Worker  * the actual execution time could be a lot longer.
100*d83cc019SAndroid Build Coastguard Worker  *
101*d83cc019SAndroid Build Coastguard Worker  * The code block will be executed at least once.
102*d83cc019SAndroid Build Coastguard Worker  */
103*d83cc019SAndroid Build Coastguard Worker #define igt_until_timeout(timeout) \
104*d83cc019SAndroid Build Coastguard Worker 	for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (timeout); )
105*d83cc019SAndroid Build Coastguard Worker 
106*d83cc019SAndroid Build Coastguard Worker /**
107*d83cc019SAndroid Build Coastguard Worker  * igt_for_milliseconds:
108*d83cc019SAndroid Build Coastguard Worker  * @time: how long to run the loop in milliseconds
109*d83cc019SAndroid Build Coastguard Worker  *
110*d83cc019SAndroid Build Coastguard Worker  * Convenience macro loop to run the provided code block in a loop until the
111*d83cc019SAndroid Build Coastguard Worker  * target interval has expired. Of course when an individual execution takes
112*d83cc019SAndroid Build Coastguard Worker  * too long, the actual execution time could be a lot longer.
113*d83cc019SAndroid Build Coastguard Worker  *
114*d83cc019SAndroid Build Coastguard Worker  * The code block will be executed at least once.
115*d83cc019SAndroid Build Coastguard Worker  */
116*d83cc019SAndroid Build Coastguard Worker #define igt_for_milliseconds(t) \
117*d83cc019SAndroid Build Coastguard Worker 	for (struct timespec t__={}; igt_nsec_elapsed(&t__)>>20 < (t); )
118*d83cc019SAndroid Build Coastguard Worker 
119*d83cc019SAndroid Build Coastguard Worker void igt_exchange_int(void *array, unsigned i, unsigned j);
120*d83cc019SAndroid Build Coastguard Worker void igt_exchange_int64(void *array, unsigned i, unsigned j);
121*d83cc019SAndroid Build Coastguard Worker void igt_permute_array(void *array, unsigned size,
122*d83cc019SAndroid Build Coastguard Worker 			   void (*exchange_func)(void *array,
123*d83cc019SAndroid Build Coastguard Worker 						 unsigned i,
124*d83cc019SAndroid Build Coastguard Worker 						 unsigned j));
125*d83cc019SAndroid Build Coastguard Worker void igt_progress(const char *header, uint64_t i, uint64_t total);
126*d83cc019SAndroid Build Coastguard Worker void igt_print_activity(void);
127*d83cc019SAndroid Build Coastguard Worker bool igt_check_boolean_env_var(const char *env_var, bool default_value);
128*d83cc019SAndroid Build Coastguard Worker 
129*d83cc019SAndroid Build Coastguard Worker bool igt_aub_dump_enabled(void);
130*d83cc019SAndroid Build Coastguard Worker 
131*d83cc019SAndroid Build Coastguard Worker /* suspend/hibernate and auto-resume system */
132*d83cc019SAndroid Build Coastguard Worker 
133*d83cc019SAndroid Build Coastguard Worker /**
134*d83cc019SAndroid Build Coastguard Worker  *  igt_suspend_state:
135*d83cc019SAndroid Build Coastguard Worker  *  @SUSPEND_STATE_FREEZE: suspend-to-idle target state, aka S0ix or freeze,
136*d83cc019SAndroid Build Coastguard Worker  *			   first non-hibernation state
137*d83cc019SAndroid Build Coastguard Worker  *  @SUSPEND_STATE_STANDBY: standby target state, aka S1, second
138*d83cc019SAndroid Build Coastguard Worker  *			    non-hibernation state
139*d83cc019SAndroid Build Coastguard Worker  *  @SUSPEND_STATE_MEM: suspend-to-mem target state aka S3, third
140*d83cc019SAndroid Build Coastguard Worker  *			non-hibernation state
141*d83cc019SAndroid Build Coastguard Worker  *  @SUSPEND_STATE_DISK: suspend-to-disk target state, aka S4 or hibernation
142*d83cc019SAndroid Build Coastguard Worker  *
143*d83cc019SAndroid Build Coastguard Worker  *  Target suspend states used with igt_system_suspend_autoresume().
144*d83cc019SAndroid Build Coastguard Worker  *  See /sys/power/state for the available states on a given machine.
145*d83cc019SAndroid Build Coastguard Worker  */
146*d83cc019SAndroid Build Coastguard Worker enum igt_suspend_state {
147*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_STATE_FREEZE,
148*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_STATE_STANDBY,
149*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_STATE_MEM,
150*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_STATE_DISK,
151*d83cc019SAndroid Build Coastguard Worker 
152*d83cc019SAndroid Build Coastguard Worker 	/*< private >*/
153*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_STATE_NUM,
154*d83cc019SAndroid Build Coastguard Worker };
155*d83cc019SAndroid Build Coastguard Worker 
156*d83cc019SAndroid Build Coastguard Worker /**
157*d83cc019SAndroid Build Coastguard Worker  * igt_suspend_test:
158*d83cc019SAndroid Build Coastguard Worker  * @SUSPEND_TEST_NONE: no testing, perform a full suspend/resume cycle
159*d83cc019SAndroid Build Coastguard Worker  * @SUSPEND_TEST_FREEZER: complete cycle after freezing all freezable threads
160*d83cc019SAndroid Build Coastguard Worker  * @SUSPEND_TEST_DEVICES: complete cycle after the above step and suspending
161*d83cc019SAndroid Build Coastguard Worker  *			  devices (before calling the drivers' suspend late and
162*d83cc019SAndroid Build Coastguard Worker  *			  no_irq hooks). Platform and system devices are not
163*d83cc019SAndroid Build Coastguard Worker  *			  suspended here, see #SUSPEND_TEST_CORE.
164*d83cc019SAndroid Build Coastguard Worker  * @SUSPEND_TEST_PLATFORM: complete cycle after all the above steps and calling
165*d83cc019SAndroid Build Coastguard Worker  *			   the ACPI platform global control methods (applies
166*d83cc019SAndroid Build Coastguard Worker  *			   only with /sys/power/disk set to platform)
167*d83cc019SAndroid Build Coastguard Worker  * @SUSPEND_TEST_PROCESSORS: complete cycle after all the above steps and
168*d83cc019SAndroid Build Coastguard Worker  *			     disabling non-boot CPUs
169*d83cc019SAndroid Build Coastguard Worker  * @SUSPEND_TEST_CORE: complete cycle after all the above steps and suspending
170*d83cc019SAndroid Build Coastguard Worker  *		       platform and system devices
171*d83cc019SAndroid Build Coastguard Worker  *
172*d83cc019SAndroid Build Coastguard Worker  * Test points used with igt_system_suspend_autoresume(). Specifies if and where
173*d83cc019SAndroid Build Coastguard Worker  * the suspend sequence is to be terminated.
174*d83cc019SAndroid Build Coastguard Worker  */
175*d83cc019SAndroid Build Coastguard Worker enum igt_suspend_test {
176*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_NONE,
177*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_FREEZER,
178*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_DEVICES,
179*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_PLATFORM,
180*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_PROCESSORS,
181*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_CORE,
182*d83cc019SAndroid Build Coastguard Worker 
183*d83cc019SAndroid Build Coastguard Worker 	/*< private >*/
184*d83cc019SAndroid Build Coastguard Worker 	SUSPEND_TEST_NUM,
185*d83cc019SAndroid Build Coastguard Worker };
186*d83cc019SAndroid Build Coastguard Worker 
187*d83cc019SAndroid Build Coastguard Worker void igt_system_suspend_autoresume(enum igt_suspend_state state,
188*d83cc019SAndroid Build Coastguard Worker 				   enum igt_suspend_test test);
189*d83cc019SAndroid Build Coastguard Worker void igt_set_autoresume_delay(int delay_secs);
190*d83cc019SAndroid Build Coastguard Worker int igt_get_autoresume_delay(enum igt_suspend_state state);
191*d83cc019SAndroid Build Coastguard Worker 
192*d83cc019SAndroid Build Coastguard Worker /* dropping priviledges */
193*d83cc019SAndroid Build Coastguard Worker void igt_drop_root(void);
194*d83cc019SAndroid Build Coastguard Worker 
195*d83cc019SAndroid Build Coastguard Worker void igt_debug_wait_for_keypress(const char *var);
196*d83cc019SAndroid Build Coastguard Worker void igt_debug_manual_check(const char *var, const char *expected);
197*d83cc019SAndroid Build Coastguard Worker 
198*d83cc019SAndroid Build Coastguard Worker /* sysinfo cross-arch wrappers from intel_os.c */
199*d83cc019SAndroid Build Coastguard Worker 
200*d83cc019SAndroid Build Coastguard Worker /* These are separate to allow easier testing when porting, see the comment at
201*d83cc019SAndroid Build Coastguard Worker  * the bottom of intel_os.c. */
202*d83cc019SAndroid Build Coastguard Worker void intel_purge_vm_caches(int fd);
203*d83cc019SAndroid Build Coastguard Worker uint64_t intel_get_avail_ram_mb(void);
204*d83cc019SAndroid Build Coastguard Worker uint64_t intel_get_total_ram_mb(void);
205*d83cc019SAndroid Build Coastguard Worker uint64_t intel_get_total_swap_mb(void);
206*d83cc019SAndroid Build Coastguard Worker void *intel_get_total_pinnable_mem(size_t *pinned);
207*d83cc019SAndroid Build Coastguard Worker 
208*d83cc019SAndroid Build Coastguard Worker int __intel_check_memory(uint64_t count, uint64_t size, unsigned mode,
209*d83cc019SAndroid Build Coastguard Worker 			 uint64_t *out_required, uint64_t *out_total);
210*d83cc019SAndroid Build Coastguard Worker void intel_require_memory(uint64_t count, uint64_t size, unsigned mode);
211*d83cc019SAndroid Build Coastguard Worker void intel_require_files(uint64_t count);
212*d83cc019SAndroid Build Coastguard Worker #define CHECK_RAM 0x1
213*d83cc019SAndroid Build Coastguard Worker #define CHECK_SWAP 0x2
214*d83cc019SAndroid Build Coastguard Worker 
215*d83cc019SAndroid Build Coastguard Worker #define min(a, b) ({			\
216*d83cc019SAndroid Build Coastguard Worker 	typeof(a) _a = (a);		\
217*d83cc019SAndroid Build Coastguard Worker 	typeof(b) _b = (b);		\
218*d83cc019SAndroid Build Coastguard Worker 	_a < _b ? _a : _b;		\
219*d83cc019SAndroid Build Coastguard Worker })
220*d83cc019SAndroid Build Coastguard Worker #define max(a, b) ({			\
221*d83cc019SAndroid Build Coastguard Worker 	typeof(a) _a = (a);		\
222*d83cc019SAndroid Build Coastguard Worker 	typeof(b) _b = (b);		\
223*d83cc019SAndroid Build Coastguard Worker 	_a > _b ? _a : _b;		\
224*d83cc019SAndroid Build Coastguard Worker })
225*d83cc019SAndroid Build Coastguard Worker 
226*d83cc019SAndroid Build Coastguard Worker #define clamp(x, min, max) ({		\
227*d83cc019SAndroid Build Coastguard Worker 	typeof(min) _min = (min);	\
228*d83cc019SAndroid Build Coastguard Worker 	typeof(max) _max = (max);	\
229*d83cc019SAndroid Build Coastguard Worker 	typeof(x) _x = (x);		\
230*d83cc019SAndroid Build Coastguard Worker 	_x < _min ? _min : _x > _max ? _max : _x;	\
231*d83cc019SAndroid Build Coastguard Worker })
232*d83cc019SAndroid Build Coastguard Worker 
233*d83cc019SAndroid Build Coastguard Worker #define igt_swap(a, b) do {	\
234*d83cc019SAndroid Build Coastguard Worker 	typeof(a) _tmp = (a);	\
235*d83cc019SAndroid Build Coastguard Worker 	(a) = (b);		\
236*d83cc019SAndroid Build Coastguard Worker 	(b) = _tmp;		\
237*d83cc019SAndroid Build Coastguard Worker } while (0)
238*d83cc019SAndroid Build Coastguard Worker 
239*d83cc019SAndroid Build Coastguard Worker void igt_lock_mem(size_t size);
240*d83cc019SAndroid Build Coastguard Worker void igt_unlock_mem(void);
241*d83cc019SAndroid Build Coastguard Worker 
242*d83cc019SAndroid Build Coastguard Worker /**
243*d83cc019SAndroid Build Coastguard Worker  * igt_wait:
244*d83cc019SAndroid Build Coastguard Worker  * @COND: condition to wait
245*d83cc019SAndroid Build Coastguard Worker  * @timeout_ms: timeout in milliseconds
246*d83cc019SAndroid Build Coastguard Worker  * @interval_ms: amount of time we try to sleep between COND checks
247*d83cc019SAndroid Build Coastguard Worker  *
248*d83cc019SAndroid Build Coastguard Worker  * Waits until COND evaluates to true or the timeout passes.
249*d83cc019SAndroid Build Coastguard Worker  *
250*d83cc019SAndroid Build Coastguard Worker  * It is safe to call this macro if the signal helper is active. The only
251*d83cc019SAndroid Build Coastguard Worker  * problem is that the usleep() calls will return early, making us evaluate COND
252*d83cc019SAndroid Build Coastguard Worker  * too often, possibly eating valuable CPU cycles.
253*d83cc019SAndroid Build Coastguard Worker  *
254*d83cc019SAndroid Build Coastguard Worker  * Returns:
255*d83cc019SAndroid Build Coastguard Worker  * True of COND evaluated to true, false otherwise.
256*d83cc019SAndroid Build Coastguard Worker  */
257*d83cc019SAndroid Build Coastguard Worker #define igt_wait(COND, timeout_ms, interval_ms) ({			\
258*d83cc019SAndroid Build Coastguard Worker 	const unsigned long interval_us__ = 1000 * (interval_ms);	\
259*d83cc019SAndroid Build Coastguard Worker 	const unsigned long timeout_ms__ = (timeout_ms);		\
260*d83cc019SAndroid Build Coastguard Worker 	struct timespec tv__ = {};					\
261*d83cc019SAndroid Build Coastguard Worker 	bool ret__;							\
262*d83cc019SAndroid Build Coastguard Worker 									\
263*d83cc019SAndroid Build Coastguard Worker 	do {								\
264*d83cc019SAndroid Build Coastguard Worker 		uint64_t elapsed__ = igt_nsec_elapsed(&tv__) >> 20;	\
265*d83cc019SAndroid Build Coastguard Worker 									\
266*d83cc019SAndroid Build Coastguard Worker 		if (COND) {						\
267*d83cc019SAndroid Build Coastguard Worker 			igt_debug("%s took %" PRIu64 "ms\n", #COND, elapsed__); \
268*d83cc019SAndroid Build Coastguard Worker 			ret__ = true;					\
269*d83cc019SAndroid Build Coastguard Worker 			break;						\
270*d83cc019SAndroid Build Coastguard Worker 		}							\
271*d83cc019SAndroid Build Coastguard Worker 		if (elapsed__ > timeout_ms__) {				\
272*d83cc019SAndroid Build Coastguard Worker 			ret__ = false;					\
273*d83cc019SAndroid Build Coastguard Worker 			break;						\
274*d83cc019SAndroid Build Coastguard Worker 		}							\
275*d83cc019SAndroid Build Coastguard Worker 									\
276*d83cc019SAndroid Build Coastguard Worker 		usleep(interval_us__);					\
277*d83cc019SAndroid Build Coastguard Worker 	} while (1);							\
278*d83cc019SAndroid Build Coastguard Worker 									\
279*d83cc019SAndroid Build Coastguard Worker 	ret__;								\
280*d83cc019SAndroid Build Coastguard Worker })
281*d83cc019SAndroid Build Coastguard Worker 
282*d83cc019SAndroid Build Coastguard Worker struct igt_mean;
283*d83cc019SAndroid Build Coastguard Worker void igt_start_siglatency(int sig); /* 0 => SIGRTMIN (default) */
284*d83cc019SAndroid Build Coastguard Worker double igt_stop_siglatency(struct igt_mean *result);
285*d83cc019SAndroid Build Coastguard Worker 
286*d83cc019SAndroid Build Coastguard Worker bool igt_allow_unlimited_files(void);
287*d83cc019SAndroid Build Coastguard Worker 
288*d83cc019SAndroid Build Coastguard Worker void igt_set_module_param(const char *name, const char *val);
289*d83cc019SAndroid Build Coastguard Worker void igt_set_module_param_int(const char *name, int val);
290*d83cc019SAndroid Build Coastguard Worker 
291*d83cc019SAndroid Build Coastguard Worker int igt_is_process_running(const char *comm);
292*d83cc019SAndroid Build Coastguard Worker int igt_terminate_process(int sig, const char *comm);
293*d83cc019SAndroid Build Coastguard Worker void igt_lsof(const char *dpath);
294*d83cc019SAndroid Build Coastguard Worker 
295*d83cc019SAndroid Build Coastguard Worker #define igt_hweight(x) \
296*d83cc019SAndroid Build Coastguard Worker 	__builtin_choose_expr(sizeof(x) == 8, \
297*d83cc019SAndroid Build Coastguard Worker 			      __builtin_popcountll(x), \
298*d83cc019SAndroid Build Coastguard Worker 			      __builtin_popcount(x))
299*d83cc019SAndroid Build Coastguard Worker 
300*d83cc019SAndroid Build Coastguard Worker #define is_power_of_two(x)  (((x) & ((x)-1)) == 0)
301*d83cc019SAndroid Build Coastguard Worker 
302*d83cc019SAndroid Build Coastguard Worker #define igt_fls(x) ((x) ? __builtin_choose_expr(sizeof(x) == 8, \
303*d83cc019SAndroid Build Coastguard Worker 						64 - __builtin_clzll(x), \
304*d83cc019SAndroid Build Coastguard Worker 						32 - __builtin_clz(x)) : 0)
305*d83cc019SAndroid Build Coastguard Worker 
306*d83cc019SAndroid Build Coastguard Worker #define roundup_power_of_two(x) ((x) != 0 ? 1 << igt_fls((x) - 1) : 0)
307*d83cc019SAndroid Build Coastguard Worker 
308*d83cc019SAndroid Build Coastguard Worker #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
309*d83cc019SAndroid Build Coastguard Worker 
310*d83cc019SAndroid Build Coastguard Worker uint64_t vfs_file_max(void);
311*d83cc019SAndroid Build Coastguard Worker 
312*d83cc019SAndroid Build Coastguard Worker #endif /* IGT_AUX_H */
313