xref: /aosp_15_r20/external/ltp/include/tst_timer.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (C) 2015-2020 Cyril Hrubis <[email protected]>
3*49cdfc7eSAndroid Build Coastguard Worker  */
4*49cdfc7eSAndroid Build Coastguard Worker 
5*49cdfc7eSAndroid Build Coastguard Worker  /*
6*49cdfc7eSAndroid Build Coastguard Worker 
7*49cdfc7eSAndroid Build Coastguard Worker    Timer - struct timespec conversion runtimes and easy to use functions to
8*49cdfc7eSAndroid Build Coastguard Worker            measure elapsed time.
9*49cdfc7eSAndroid Build Coastguard Worker 
10*49cdfc7eSAndroid Build Coastguard Worker   */
11*49cdfc7eSAndroid Build Coastguard Worker 
12*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_TIMER
13*49cdfc7eSAndroid Build Coastguard Worker #define TST_TIMER
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker #include <linux/time_types.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <linux/types.h>
17*49cdfc7eSAndroid Build Coastguard Worker #include <sched.h>
18*49cdfc7eSAndroid Build Coastguard Worker #include <sys/time.h>
19*49cdfc7eSAndroid Build Coastguard Worker #include <mqueue.h>
20*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
21*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
22*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/common_timers.h"
23*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/posix_types.h"
24*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker /*
27*49cdfc7eSAndroid Build Coastguard Worker  * Converts timeval to microseconds.
28*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timeval_to_us(struct timeval t)29*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timeval_to_us(struct timeval t)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker 	return ((long long)t.tv_sec) * 1000000 + t.tv_usec;
32*49cdfc7eSAndroid Build Coastguard Worker }
33*49cdfc7eSAndroid Build Coastguard Worker 
34*49cdfc7eSAndroid Build Coastguard Worker /*
35*49cdfc7eSAndroid Build Coastguard Worker  * Converts timeval to milliseconds.
36*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timeval_to_ms(struct timeval t)37*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timeval_to_ms(struct timeval t)
38*49cdfc7eSAndroid Build Coastguard Worker {
39*49cdfc7eSAndroid Build Coastguard Worker 	return ((long long)t.tv_sec) * 1000 + (t.tv_usec + 500) / 1000;
40*49cdfc7eSAndroid Build Coastguard Worker }
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker /*
43*49cdfc7eSAndroid Build Coastguard Worker  * Converts milliseconds to struct timeval
44*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ms_to_timeval(long long ms)45*49cdfc7eSAndroid Build Coastguard Worker static inline struct timeval tst_ms_to_timeval(long long ms)
46*49cdfc7eSAndroid Build Coastguard Worker {
47*49cdfc7eSAndroid Build Coastguard Worker 	struct timeval ret;
48*49cdfc7eSAndroid Build Coastguard Worker 
49*49cdfc7eSAndroid Build Coastguard Worker 	ret.tv_sec = ms / 1000;
50*49cdfc7eSAndroid Build Coastguard Worker 	ret.tv_usec = (ms % 1000) * 1000;
51*49cdfc7eSAndroid Build Coastguard Worker 
52*49cdfc7eSAndroid Build Coastguard Worker 	return ret;
53*49cdfc7eSAndroid Build Coastguard Worker }
54*49cdfc7eSAndroid Build Coastguard Worker 
55*49cdfc7eSAndroid Build Coastguard Worker /*
56*49cdfc7eSAndroid Build Coastguard Worker  * Converts microseconds to struct timeval
57*49cdfc7eSAndroid Build Coastguard Worker  */
tst_us_to_timeval(long long us)58*49cdfc7eSAndroid Build Coastguard Worker static inline struct timeval tst_us_to_timeval(long long us)
59*49cdfc7eSAndroid Build Coastguard Worker {
60*49cdfc7eSAndroid Build Coastguard Worker 	struct timeval ret;
61*49cdfc7eSAndroid Build Coastguard Worker 
62*49cdfc7eSAndroid Build Coastguard Worker 	ret.tv_sec = us / 1000000;
63*49cdfc7eSAndroid Build Coastguard Worker 	ret.tv_usec = us % 1000000;
64*49cdfc7eSAndroid Build Coastguard Worker 
65*49cdfc7eSAndroid Build Coastguard Worker 	return ret;
66*49cdfc7eSAndroid Build Coastguard Worker }
67*49cdfc7eSAndroid Build Coastguard Worker 
68*49cdfc7eSAndroid Build Coastguard Worker /*
69*49cdfc7eSAndroid Build Coastguard Worker  * Returns difference between two timeval structures.
70*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timeval_diff(struct timeval t1,struct timeval t2)71*49cdfc7eSAndroid Build Coastguard Worker static inline struct timeval tst_timeval_diff(struct timeval t1,
72*49cdfc7eSAndroid Build Coastguard Worker                                               struct timeval t2)
73*49cdfc7eSAndroid Build Coastguard Worker {
74*49cdfc7eSAndroid Build Coastguard Worker 	struct timeval res;
75*49cdfc7eSAndroid Build Coastguard Worker 
76*49cdfc7eSAndroid Build Coastguard Worker 	res.tv_sec = t1.tv_sec - t2.tv_sec;
77*49cdfc7eSAndroid Build Coastguard Worker 
78*49cdfc7eSAndroid Build Coastguard Worker 	if (t1.tv_usec < t2.tv_usec) {
79*49cdfc7eSAndroid Build Coastguard Worker 		res.tv_sec--;
80*49cdfc7eSAndroid Build Coastguard Worker 		res.tv_usec = 1000000 - (t2.tv_usec - t1.tv_usec);
81*49cdfc7eSAndroid Build Coastguard Worker 	} else {
82*49cdfc7eSAndroid Build Coastguard Worker 		res.tv_usec = t1.tv_usec - t2.tv_usec;
83*49cdfc7eSAndroid Build Coastguard Worker 	}
84*49cdfc7eSAndroid Build Coastguard Worker 
85*49cdfc7eSAndroid Build Coastguard Worker 	return res;
86*49cdfc7eSAndroid Build Coastguard Worker }
87*49cdfc7eSAndroid Build Coastguard Worker 
tst_timeval_diff_us(struct timeval t1,struct timeval t2)88*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timeval_diff_us(struct timeval t1,
89*49cdfc7eSAndroid Build Coastguard Worker                                             struct timeval t2)
90*49cdfc7eSAndroid Build Coastguard Worker {
91*49cdfc7eSAndroid Build Coastguard Worker 	return tst_timeval_to_us(tst_timeval_diff(t1, t2));
92*49cdfc7eSAndroid Build Coastguard Worker }
93*49cdfc7eSAndroid Build Coastguard Worker 
tst_timeval_diff_ms(struct timeval t1,struct timeval t2)94*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timeval_diff_ms(struct timeval t1,
95*49cdfc7eSAndroid Build Coastguard Worker                                             struct timeval t2)
96*49cdfc7eSAndroid Build Coastguard Worker {
97*49cdfc7eSAndroid Build Coastguard Worker 	return tst_timeval_to_ms(tst_timeval_diff(t1, t2));
98*49cdfc7eSAndroid Build Coastguard Worker }
99*49cdfc7eSAndroid Build Coastguard Worker 
100*49cdfc7eSAndroid Build Coastguard Worker #ifndef __kernel_timespec
101*49cdfc7eSAndroid Build Coastguard Worker 
102*49cdfc7eSAndroid Build Coastguard Worker typedef __kernel_long_t	__kernel_old_time_t;
103*49cdfc7eSAndroid Build Coastguard Worker 
104*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT___KERNEL_OLD_TIMEVAL
105*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_old_timeval {
106*49cdfc7eSAndroid Build Coastguard Worker 	__kernel_old_time_t	tv_sec;		/* seconds */
107*49cdfc7eSAndroid Build Coastguard Worker 	__kernel_suseconds_t	tv_usec;	/* microseconds */
108*49cdfc7eSAndroid Build Coastguard Worker };
109*49cdfc7eSAndroid Build Coastguard Worker #endif
110*49cdfc7eSAndroid Build Coastguard Worker 
111*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT___KERNEL_OLD_TIMESPEC
112*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_old_timespec {
113*49cdfc7eSAndroid Build Coastguard Worker 	__kernel_old_time_t	tv_sec;		/* seconds */
114*49cdfc7eSAndroid Build Coastguard Worker 	__kernel_old_time_t	tv_nsec;	/* nanoseconds */
115*49cdfc7eSAndroid Build Coastguard Worker };
116*49cdfc7eSAndroid Build Coastguard Worker #endif
117*49cdfc7eSAndroid Build Coastguard Worker 
118*49cdfc7eSAndroid Build Coastguard Worker typedef long long __kernel_time64_t;
119*49cdfc7eSAndroid Build Coastguard Worker 
120*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT___KERNEL_TIMESPEC
121*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_timespec {
122*49cdfc7eSAndroid Build Coastguard Worker 	__kernel_time64_t       tv_sec;                 /* seconds */
123*49cdfc7eSAndroid Build Coastguard Worker 	long long               tv_nsec;                /* nanoseconds */
124*49cdfc7eSAndroid Build Coastguard Worker };
125*49cdfc7eSAndroid Build Coastguard Worker #endif
126*49cdfc7eSAndroid Build Coastguard Worker 
127*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT___KERNEL_OLD_ITIMERSPEC
128*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_old_itimerspec {
129*49cdfc7eSAndroid Build Coastguard Worker 	struct __kernel_old_timespec it_interval;    /* timer period */
130*49cdfc7eSAndroid Build Coastguard Worker 	struct __kernel_old_timespec it_value;       /* timer expiration */
131*49cdfc7eSAndroid Build Coastguard Worker };
132*49cdfc7eSAndroid Build Coastguard Worker #endif
133*49cdfc7eSAndroid Build Coastguard Worker 
134*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT___KERNEL_ITIMERSPEC
135*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_itimerspec {
136*49cdfc7eSAndroid Build Coastguard Worker 	struct __kernel_timespec it_interval;    /* timer period */
137*49cdfc7eSAndroid Build Coastguard Worker 	struct __kernel_timespec it_value;       /* timer expiration */
138*49cdfc7eSAndroid Build Coastguard Worker };
139*49cdfc7eSAndroid Build Coastguard Worker #endif
140*49cdfc7eSAndroid Build Coastguard Worker 
141*49cdfc7eSAndroid Build Coastguard Worker #ifndef HAVE_STRUCT___KERNEL_OLD_ITIMERVAL
142*49cdfc7eSAndroid Build Coastguard Worker struct __kernel_old_itimerval {
143*49cdfc7eSAndroid Build Coastguard Worker 	struct __kernel_old_timeval it_interval;	/* timer interval */
144*49cdfc7eSAndroid Build Coastguard Worker 	struct __kernel_old_timeval it_value;		/* current value */
145*49cdfc7eSAndroid Build Coastguard Worker };
146*49cdfc7eSAndroid Build Coastguard Worker #endif
147*49cdfc7eSAndroid Build Coastguard Worker #endif
148*49cdfc7eSAndroid Build Coastguard Worker 
149*49cdfc7eSAndroid Build Coastguard Worker enum tst_ts_type {
150*49cdfc7eSAndroid Build Coastguard Worker 	TST_LIBC_TIMESPEC,
151*49cdfc7eSAndroid Build Coastguard Worker 	TST_KERN_OLD_TIMESPEC,
152*49cdfc7eSAndroid Build Coastguard Worker 	TST_KERN_TIMESPEC
153*49cdfc7eSAndroid Build Coastguard Worker };
154*49cdfc7eSAndroid Build Coastguard Worker 
155*49cdfc7eSAndroid Build Coastguard Worker struct tst_ts {
156*49cdfc7eSAndroid Build Coastguard Worker 	enum tst_ts_type type;
157*49cdfc7eSAndroid Build Coastguard Worker 	union ts {
158*49cdfc7eSAndroid Build Coastguard Worker 		struct timespec libc_ts;
159*49cdfc7eSAndroid Build Coastguard Worker 		struct __kernel_old_timespec kern_old_ts;
160*49cdfc7eSAndroid Build Coastguard Worker 		struct __kernel_timespec kern_ts;
161*49cdfc7eSAndroid Build Coastguard Worker 	} ts;
162*49cdfc7eSAndroid Build Coastguard Worker };
163*49cdfc7eSAndroid Build Coastguard Worker 
164*49cdfc7eSAndroid Build Coastguard Worker struct tst_its {
165*49cdfc7eSAndroid Build Coastguard Worker 	enum tst_ts_type type;
166*49cdfc7eSAndroid Build Coastguard Worker 	union {
167*49cdfc7eSAndroid Build Coastguard Worker 		struct __kernel_old_itimerspec kern_old_its;
168*49cdfc7eSAndroid Build Coastguard Worker 		struct __kernel_itimerspec kern_its;
169*49cdfc7eSAndroid Build Coastguard Worker 	} ts;
170*49cdfc7eSAndroid Build Coastguard Worker };
171*49cdfc7eSAndroid Build Coastguard Worker 
tst_ts_get(struct tst_ts * t)172*49cdfc7eSAndroid Build Coastguard Worker static inline void *tst_ts_get(struct tst_ts *t)
173*49cdfc7eSAndroid Build Coastguard Worker {
174*49cdfc7eSAndroid Build Coastguard Worker 	if (!t)
175*49cdfc7eSAndroid Build Coastguard Worker 		return NULL;
176*49cdfc7eSAndroid Build Coastguard Worker 
177*49cdfc7eSAndroid Build Coastguard Worker 	switch (t->type) {
178*49cdfc7eSAndroid Build Coastguard Worker 	case TST_LIBC_TIMESPEC:
179*49cdfc7eSAndroid Build Coastguard Worker 		return &t->ts.libc_ts;
180*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
181*49cdfc7eSAndroid Build Coastguard Worker 		return &t->ts.kern_old_ts;
182*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
183*49cdfc7eSAndroid Build Coastguard Worker 		return &t->ts.kern_ts;
184*49cdfc7eSAndroid Build Coastguard Worker 	default:
185*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", t->type);
186*49cdfc7eSAndroid Build Coastguard Worker 		return NULL;
187*49cdfc7eSAndroid Build Coastguard Worker 	}
188*49cdfc7eSAndroid Build Coastguard Worker }
189*49cdfc7eSAndroid Build Coastguard Worker 
tst_its_get(struct tst_its * t)190*49cdfc7eSAndroid Build Coastguard Worker static inline void *tst_its_get(struct tst_its *t)
191*49cdfc7eSAndroid Build Coastguard Worker {
192*49cdfc7eSAndroid Build Coastguard Worker 	if (!t)
193*49cdfc7eSAndroid Build Coastguard Worker 		return NULL;
194*49cdfc7eSAndroid Build Coastguard Worker 
195*49cdfc7eSAndroid Build Coastguard Worker 	switch (t->type) {
196*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
197*49cdfc7eSAndroid Build Coastguard Worker 		return &t->ts.kern_old_its;
198*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
199*49cdfc7eSAndroid Build Coastguard Worker 		return &t->ts.kern_its;
200*49cdfc7eSAndroid Build Coastguard Worker 	default:
201*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", t->type);
202*49cdfc7eSAndroid Build Coastguard Worker 		return NULL;
203*49cdfc7eSAndroid Build Coastguard Worker 	}
204*49cdfc7eSAndroid Build Coastguard Worker }
205*49cdfc7eSAndroid Build Coastguard Worker 
libc_clock_getres(clockid_t clk_id,void * ts)206*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_clock_getres(clockid_t clk_id, void *ts)
207*49cdfc7eSAndroid Build Coastguard Worker {
208*49cdfc7eSAndroid Build Coastguard Worker 	return clock_getres(clk_id, ts);
209*49cdfc7eSAndroid Build Coastguard Worker }
210*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_getres(clockid_t clk_id,void * ts)211*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_getres(clockid_t clk_id, void *ts)
212*49cdfc7eSAndroid Build Coastguard Worker {
213*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_getres, clk_id, ts);
214*49cdfc7eSAndroid Build Coastguard Worker }
215*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_getres64(clockid_t clk_id,void * ts)216*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_getres64(clockid_t clk_id, void *ts)
217*49cdfc7eSAndroid Build Coastguard Worker {
218*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_getres_time64, clk_id, ts);
219*49cdfc7eSAndroid Build Coastguard Worker }
220*49cdfc7eSAndroid Build Coastguard Worker 
libc_clock_gettime(clockid_t clk_id,void * ts)221*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_clock_gettime(clockid_t clk_id, void *ts)
222*49cdfc7eSAndroid Build Coastguard Worker {
223*49cdfc7eSAndroid Build Coastguard Worker 	return clock_gettime(clk_id, ts);
224*49cdfc7eSAndroid Build Coastguard Worker }
225*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_gettime(clockid_t clk_id,void * ts)226*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_gettime(clockid_t clk_id, void *ts)
227*49cdfc7eSAndroid Build Coastguard Worker {
228*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_gettime, clk_id, ts);
229*49cdfc7eSAndroid Build Coastguard Worker }
230*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_gettime64(clockid_t clk_id,void * ts)231*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_gettime64(clockid_t clk_id, void *ts)
232*49cdfc7eSAndroid Build Coastguard Worker {
233*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_gettime64, clk_id, ts);
234*49cdfc7eSAndroid Build Coastguard Worker }
235*49cdfc7eSAndroid Build Coastguard Worker 
libc_clock_settime(clockid_t clk_id,void * ts)236*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_clock_settime(clockid_t clk_id, void *ts)
237*49cdfc7eSAndroid Build Coastguard Worker {
238*49cdfc7eSAndroid Build Coastguard Worker 	return clock_settime(clk_id, ts);
239*49cdfc7eSAndroid Build Coastguard Worker }
240*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_settime(clockid_t clk_id,void * ts)241*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_settime(clockid_t clk_id, void *ts)
242*49cdfc7eSAndroid Build Coastguard Worker {
243*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_settime, clk_id, ts);
244*49cdfc7eSAndroid Build Coastguard Worker }
245*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_settime64(clockid_t clk_id,void * ts)246*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_settime64(clockid_t clk_id, void *ts)
247*49cdfc7eSAndroid Build Coastguard Worker {
248*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_settime64, clk_id, ts);
249*49cdfc7eSAndroid Build Coastguard Worker }
250*49cdfc7eSAndroid Build Coastguard Worker 
libc_clock_nanosleep(clockid_t clk_id,int flags,void * request,void * remain)251*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_clock_nanosleep(clockid_t clk_id, int flags,
252*49cdfc7eSAndroid Build Coastguard Worker 				       void *request, void *remain)
253*49cdfc7eSAndroid Build Coastguard Worker {
254*49cdfc7eSAndroid Build Coastguard Worker 	return clock_nanosleep(clk_id, flags, request, remain);
255*49cdfc7eSAndroid Build Coastguard Worker }
256*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_nanosleep(clockid_t clk_id,int flags,void * request,void * remain)257*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_nanosleep(clockid_t clk_id, int flags,
258*49cdfc7eSAndroid Build Coastguard Worker 				      void *request, void *remain)
259*49cdfc7eSAndroid Build Coastguard Worker {
260*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_nanosleep, clk_id, flags,
261*49cdfc7eSAndroid Build Coastguard Worker 			   request, remain);
262*49cdfc7eSAndroid Build Coastguard Worker }
263*49cdfc7eSAndroid Build Coastguard Worker 
sys_clock_nanosleep64(clockid_t clk_id,int flags,void * request,void * remain)264*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
265*49cdfc7eSAndroid Build Coastguard Worker 				        void *request, void *remain)
266*49cdfc7eSAndroid Build Coastguard Worker {
267*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_clock_nanosleep_time64, clk_id, flags,
268*49cdfc7eSAndroid Build Coastguard Worker 			   request, remain);
269*49cdfc7eSAndroid Build Coastguard Worker }
270*49cdfc7eSAndroid Build Coastguard Worker 
sys_futex(int * uaddr,int futex_op,int val,void * to,int * uaddr2,int val3)271*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_futex(int *uaddr, int futex_op, int val, void *to,
272*49cdfc7eSAndroid Build Coastguard Worker 			    int *uaddr2, int val3)
273*49cdfc7eSAndroid Build Coastguard Worker {
274*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_futex, uaddr, futex_op, val, to, uaddr2, val3);
275*49cdfc7eSAndroid Build Coastguard Worker }
276*49cdfc7eSAndroid Build Coastguard Worker 
sys_futex_time64(int * uaddr,int futex_op,int val,void * to,int * uaddr2,int val3)277*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_futex_time64(int *uaddr, int futex_op, int val, void *to,
278*49cdfc7eSAndroid Build Coastguard Worker 				   int *uaddr2, int val3)
279*49cdfc7eSAndroid Build Coastguard Worker {
280*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_futex_time64, uaddr, futex_op, val, to, uaddr2, val3);
281*49cdfc7eSAndroid Build Coastguard Worker }
282*49cdfc7eSAndroid Build Coastguard Worker 
libc_mq_timedsend(mqd_t mqdes,const char * msg_ptr,size_t msg_len,unsigned int msg_prio,void * abs_timeout)283*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_mq_timedsend(mqd_t mqdes, const char *msg_ptr,
284*49cdfc7eSAndroid Build Coastguard Worker 		size_t msg_len, unsigned int msg_prio, void *abs_timeout)
285*49cdfc7eSAndroid Build Coastguard Worker {
286*49cdfc7eSAndroid Build Coastguard Worker 	return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout);
287*49cdfc7eSAndroid Build Coastguard Worker }
288*49cdfc7eSAndroid Build Coastguard Worker 
sys_mq_timedsend(mqd_t mqdes,const char * msg_ptr,size_t msg_len,unsigned int msg_prio,void * abs_timeout)289*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_mq_timedsend(mqd_t mqdes, const char *msg_ptr,
290*49cdfc7eSAndroid Build Coastguard Worker 		size_t msg_len, unsigned int msg_prio, void *abs_timeout)
291*49cdfc7eSAndroid Build Coastguard Worker {
292*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio,
293*49cdfc7eSAndroid Build Coastguard Worker 			   abs_timeout);
294*49cdfc7eSAndroid Build Coastguard Worker }
295*49cdfc7eSAndroid Build Coastguard Worker 
sys_mq_timedsend64(mqd_t mqdes,const char * msg_ptr,size_t msg_len,unsigned int msg_prio,void * abs_timeout)296*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_mq_timedsend64(mqd_t mqdes, const char *msg_ptr,
297*49cdfc7eSAndroid Build Coastguard Worker 		size_t msg_len, unsigned int msg_prio, void *abs_timeout)
298*49cdfc7eSAndroid Build Coastguard Worker {
299*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_mq_timedsend_time64, mqdes, msg_ptr, msg_len,
300*49cdfc7eSAndroid Build Coastguard Worker 			   msg_prio, abs_timeout);
301*49cdfc7eSAndroid Build Coastguard Worker }
302*49cdfc7eSAndroid Build Coastguard Worker 
libc_mq_timedreceive(mqd_t mqdes,char * msg_ptr,size_t msg_len,unsigned int * msg_prio,void * abs_timeout)303*49cdfc7eSAndroid Build Coastguard Worker static inline ssize_t libc_mq_timedreceive(mqd_t mqdes, char *msg_ptr,
304*49cdfc7eSAndroid Build Coastguard Worker 		size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
305*49cdfc7eSAndroid Build Coastguard Worker {
306*49cdfc7eSAndroid Build Coastguard Worker 	return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout);
307*49cdfc7eSAndroid Build Coastguard Worker }
308*49cdfc7eSAndroid Build Coastguard Worker 
sys_mq_timedreceive(mqd_t mqdes,char * msg_ptr,size_t msg_len,unsigned int * msg_prio,void * abs_timeout)309*49cdfc7eSAndroid Build Coastguard Worker static inline ssize_t sys_mq_timedreceive(mqd_t mqdes, char *msg_ptr,
310*49cdfc7eSAndroid Build Coastguard Worker 		size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
311*49cdfc7eSAndroid Build Coastguard Worker {
312*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_mq_timedreceive, mqdes, msg_ptr, msg_len,
313*49cdfc7eSAndroid Build Coastguard Worker 			   msg_prio, abs_timeout);
314*49cdfc7eSAndroid Build Coastguard Worker }
315*49cdfc7eSAndroid Build Coastguard Worker 
sys_mq_timedreceive64(mqd_t mqdes,char * msg_ptr,size_t msg_len,unsigned int * msg_prio,void * abs_timeout)316*49cdfc7eSAndroid Build Coastguard Worker static inline ssize_t sys_mq_timedreceive64(mqd_t mqdes, char *msg_ptr,
317*49cdfc7eSAndroid Build Coastguard Worker 		size_t msg_len, unsigned int *msg_prio, void *abs_timeout)
318*49cdfc7eSAndroid Build Coastguard Worker {
319*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
320*49cdfc7eSAndroid Build Coastguard Worker 			   msg_prio, abs_timeout);
321*49cdfc7eSAndroid Build Coastguard Worker }
322*49cdfc7eSAndroid Build Coastguard Worker 
libc_sched_rr_get_interval(pid_t pid,void * ts)323*49cdfc7eSAndroid Build Coastguard Worker static inline int libc_sched_rr_get_interval(pid_t pid, void *ts)
324*49cdfc7eSAndroid Build Coastguard Worker {
325*49cdfc7eSAndroid Build Coastguard Worker 	return sched_rr_get_interval(pid, ts);
326*49cdfc7eSAndroid Build Coastguard Worker }
327*49cdfc7eSAndroid Build Coastguard Worker 
sys_sched_rr_get_interval(pid_t pid,void * ts)328*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_sched_rr_get_interval(pid_t pid, void *ts)
329*49cdfc7eSAndroid Build Coastguard Worker {
330*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_sched_rr_get_interval, pid, ts);
331*49cdfc7eSAndroid Build Coastguard Worker }
332*49cdfc7eSAndroid Build Coastguard Worker 
sys_sched_rr_get_interval64(pid_t pid,void * ts)333*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_sched_rr_get_interval64(pid_t pid, void *ts)
334*49cdfc7eSAndroid Build Coastguard Worker {
335*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_sched_rr_get_interval_time64, pid, ts);
336*49cdfc7eSAndroid Build Coastguard Worker }
337*49cdfc7eSAndroid Build Coastguard Worker 
sys_timer_gettime(kernel_timer_t timerid,void * its)338*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timer_gettime(kernel_timer_t timerid, void *its)
339*49cdfc7eSAndroid Build Coastguard Worker {
340*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timer_gettime, timerid, its);
341*49cdfc7eSAndroid Build Coastguard Worker }
342*49cdfc7eSAndroid Build Coastguard Worker 
sys_timer_gettime64(kernel_timer_t timerid,void * its)343*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timer_gettime64(kernel_timer_t timerid, void *its)
344*49cdfc7eSAndroid Build Coastguard Worker {
345*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timer_gettime64, timerid, its);
346*49cdfc7eSAndroid Build Coastguard Worker }
347*49cdfc7eSAndroid Build Coastguard Worker 
sys_timer_settime(kernel_timer_t timerid,int flags,void * its,void * old_its)348*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timer_settime(kernel_timer_t timerid, int flags, void *its,
349*49cdfc7eSAndroid Build Coastguard Worker 				    void *old_its)
350*49cdfc7eSAndroid Build Coastguard Worker {
351*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timer_settime, timerid, flags, its, old_its);
352*49cdfc7eSAndroid Build Coastguard Worker }
353*49cdfc7eSAndroid Build Coastguard Worker 
sys_timer_settime64(kernel_timer_t timerid,int flags,void * its,void * old_its)354*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timer_settime64(kernel_timer_t timerid, int flags, void *its,
355*49cdfc7eSAndroid Build Coastguard Worker 				      void *old_its)
356*49cdfc7eSAndroid Build Coastguard Worker {
357*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timer_settime64, timerid, flags, its, old_its);
358*49cdfc7eSAndroid Build Coastguard Worker }
359*49cdfc7eSAndroid Build Coastguard Worker 
sys_timerfd_gettime(int fd,void * its)360*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timerfd_gettime(int fd, void *its)
361*49cdfc7eSAndroid Build Coastguard Worker {
362*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timerfd_gettime, fd, its);
363*49cdfc7eSAndroid Build Coastguard Worker }
364*49cdfc7eSAndroid Build Coastguard Worker 
sys_timerfd_gettime64(int fd,void * its)365*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timerfd_gettime64(int fd, void *its)
366*49cdfc7eSAndroid Build Coastguard Worker {
367*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timerfd_gettime64, fd, its);
368*49cdfc7eSAndroid Build Coastguard Worker }
369*49cdfc7eSAndroid Build Coastguard Worker 
sys_timerfd_settime(int fd,int flags,void * its,void * old_its)370*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timerfd_settime(int fd, int flags, void *its,
371*49cdfc7eSAndroid Build Coastguard Worker 				      void *old_its)
372*49cdfc7eSAndroid Build Coastguard Worker {
373*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timerfd_settime, fd, flags, its, old_its);
374*49cdfc7eSAndroid Build Coastguard Worker }
375*49cdfc7eSAndroid Build Coastguard Worker 
sys_timerfd_settime64(int fd,int flags,void * its,void * old_its)376*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_timerfd_settime64(int fd, int flags, void *its,
377*49cdfc7eSAndroid Build Coastguard Worker 				      void *old_its)
378*49cdfc7eSAndroid Build Coastguard Worker {
379*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_timerfd_settime64, fd, flags, its, old_its);
380*49cdfc7eSAndroid Build Coastguard Worker }
381*49cdfc7eSAndroid Build Coastguard Worker 
sys_setitimer(int which,void * new_value,void * old_value)382*49cdfc7eSAndroid Build Coastguard Worker static inline int sys_setitimer(int which, void *new_value, void *old_value)
383*49cdfc7eSAndroid Build Coastguard Worker {
384*49cdfc7eSAndroid Build Coastguard Worker 	return tst_syscall(__NR_setitimer, which, new_value, old_value);
385*49cdfc7eSAndroid Build Coastguard Worker }
386*49cdfc7eSAndroid Build Coastguard Worker 
387*49cdfc7eSAndroid Build Coastguard Worker /*
388*49cdfc7eSAndroid Build Coastguard Worker  * Returns tst_ts seconds.
389*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_get_sec(struct tst_ts ts)390*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_ts_get_sec(struct tst_ts ts)
391*49cdfc7eSAndroid Build Coastguard Worker {
392*49cdfc7eSAndroid Build Coastguard Worker 	switch (ts.type) {
393*49cdfc7eSAndroid Build Coastguard Worker 	case TST_LIBC_TIMESPEC:
394*49cdfc7eSAndroid Build Coastguard Worker 		return ts.ts.libc_ts.tv_sec;
395*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
396*49cdfc7eSAndroid Build Coastguard Worker 		return ts.ts.kern_old_ts.tv_sec;
397*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
398*49cdfc7eSAndroid Build Coastguard Worker 		return ts.ts.kern_ts.tv_sec;
399*49cdfc7eSAndroid Build Coastguard Worker 	default:
400*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", ts.type);
401*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
402*49cdfc7eSAndroid Build Coastguard Worker 	}
403*49cdfc7eSAndroid Build Coastguard Worker }
404*49cdfc7eSAndroid Build Coastguard Worker 
405*49cdfc7eSAndroid Build Coastguard Worker /*
406*49cdfc7eSAndroid Build Coastguard Worker  * Returns tst_ts nanoseconds.
407*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_get_nsec(struct tst_ts ts)408*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_ts_get_nsec(struct tst_ts ts)
409*49cdfc7eSAndroid Build Coastguard Worker {
410*49cdfc7eSAndroid Build Coastguard Worker 	switch (ts.type) {
411*49cdfc7eSAndroid Build Coastguard Worker 	case TST_LIBC_TIMESPEC:
412*49cdfc7eSAndroid Build Coastguard Worker 		return ts.ts.libc_ts.tv_nsec;
413*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
414*49cdfc7eSAndroid Build Coastguard Worker 		return ts.ts.kern_old_ts.tv_nsec;
415*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
416*49cdfc7eSAndroid Build Coastguard Worker 		return ts.ts.kern_ts.tv_nsec;
417*49cdfc7eSAndroid Build Coastguard Worker 	default:
418*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", ts.type);
419*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
420*49cdfc7eSAndroid Build Coastguard Worker 	}
421*49cdfc7eSAndroid Build Coastguard Worker }
422*49cdfc7eSAndroid Build Coastguard Worker 
423*49cdfc7eSAndroid Build Coastguard Worker /*
424*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_ts seconds.
425*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_set_sec(struct tst_ts * ts,long long sec)426*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_ts_set_sec(struct tst_ts *ts, long long sec)
427*49cdfc7eSAndroid Build Coastguard Worker {
428*49cdfc7eSAndroid Build Coastguard Worker 	switch (ts->type) {
429*49cdfc7eSAndroid Build Coastguard Worker 	case TST_LIBC_TIMESPEC:
430*49cdfc7eSAndroid Build Coastguard Worker 		ts->ts.libc_ts.tv_sec = sec;
431*49cdfc7eSAndroid Build Coastguard Worker 	break;
432*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
433*49cdfc7eSAndroid Build Coastguard Worker 		ts->ts.kern_old_ts.tv_sec = sec;
434*49cdfc7eSAndroid Build Coastguard Worker 	break;
435*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
436*49cdfc7eSAndroid Build Coastguard Worker 		ts->ts.kern_ts.tv_sec = sec;
437*49cdfc7eSAndroid Build Coastguard Worker 	break;
438*49cdfc7eSAndroid Build Coastguard Worker 	default:
439*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", ts->type);
440*49cdfc7eSAndroid Build Coastguard Worker 	}
441*49cdfc7eSAndroid Build Coastguard Worker }
442*49cdfc7eSAndroid Build Coastguard Worker 
443*49cdfc7eSAndroid Build Coastguard Worker /*
444*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_ts nanoseconds.
445*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_set_nsec(struct tst_ts * ts,long long nsec)446*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_ts_set_nsec(struct tst_ts *ts, long long nsec)
447*49cdfc7eSAndroid Build Coastguard Worker {
448*49cdfc7eSAndroid Build Coastguard Worker 	switch (ts->type) {
449*49cdfc7eSAndroid Build Coastguard Worker 	case TST_LIBC_TIMESPEC:
450*49cdfc7eSAndroid Build Coastguard Worker 		ts->ts.libc_ts.tv_nsec = nsec;
451*49cdfc7eSAndroid Build Coastguard Worker 	break;
452*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
453*49cdfc7eSAndroid Build Coastguard Worker 		ts->ts.kern_old_ts.tv_nsec = nsec;
454*49cdfc7eSAndroid Build Coastguard Worker 	break;
455*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
456*49cdfc7eSAndroid Build Coastguard Worker 		ts->ts.kern_ts.tv_nsec = nsec;
457*49cdfc7eSAndroid Build Coastguard Worker 	break;
458*49cdfc7eSAndroid Build Coastguard Worker 	default:
459*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", ts->type);
460*49cdfc7eSAndroid Build Coastguard Worker 	}
461*49cdfc7eSAndroid Build Coastguard Worker }
462*49cdfc7eSAndroid Build Coastguard Worker 
463*49cdfc7eSAndroid Build Coastguard Worker /*
464*49cdfc7eSAndroid Build Coastguard Worker  * Returns tst_its it_interval seconds.
465*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_get_interval_sec(struct tst_its its)466*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_its_get_interval_sec(struct tst_its its)
467*49cdfc7eSAndroid Build Coastguard Worker {
468*49cdfc7eSAndroid Build Coastguard Worker 	switch (its.type) {
469*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
470*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_old_its.it_interval.tv_sec;
471*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
472*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_its.it_interval.tv_sec;
473*49cdfc7eSAndroid Build Coastguard Worker 	default:
474*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its.type);
475*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
476*49cdfc7eSAndroid Build Coastguard Worker 	}
477*49cdfc7eSAndroid Build Coastguard Worker }
478*49cdfc7eSAndroid Build Coastguard Worker 
479*49cdfc7eSAndroid Build Coastguard Worker /*
480*49cdfc7eSAndroid Build Coastguard Worker  * Returns tst_its it_interval nanoseconds.
481*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_get_interval_nsec(struct tst_its its)482*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_its_get_interval_nsec(struct tst_its its)
483*49cdfc7eSAndroid Build Coastguard Worker {
484*49cdfc7eSAndroid Build Coastguard Worker 	switch (its.type) {
485*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
486*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_old_its.it_interval.tv_nsec;
487*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
488*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_its.it_interval.tv_nsec;
489*49cdfc7eSAndroid Build Coastguard Worker 	default:
490*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its.type);
491*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
492*49cdfc7eSAndroid Build Coastguard Worker 	}
493*49cdfc7eSAndroid Build Coastguard Worker }
494*49cdfc7eSAndroid Build Coastguard Worker 
495*49cdfc7eSAndroid Build Coastguard Worker /*
496*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_interval seconds.
497*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_interval_sec(struct tst_its * its,long long sec)498*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_interval_sec(struct tst_its *its, long long sec)
499*49cdfc7eSAndroid Build Coastguard Worker {
500*49cdfc7eSAndroid Build Coastguard Worker 	switch (its->type) {
501*49cdfc7eSAndroid Build Coastguard Worker 	break;
502*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
503*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_old_its.it_interval.tv_sec = sec;
504*49cdfc7eSAndroid Build Coastguard Worker 	break;
505*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
506*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_its.it_interval.tv_sec = sec;
507*49cdfc7eSAndroid Build Coastguard Worker 	break;
508*49cdfc7eSAndroid Build Coastguard Worker 	default:
509*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its->type);
510*49cdfc7eSAndroid Build Coastguard Worker 	}
511*49cdfc7eSAndroid Build Coastguard Worker }
512*49cdfc7eSAndroid Build Coastguard Worker 
513*49cdfc7eSAndroid Build Coastguard Worker /*
514*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_interval nanoseconds.
515*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_interval_nsec(struct tst_its * its,long long nsec)516*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_interval_nsec(struct tst_its *its, long long nsec)
517*49cdfc7eSAndroid Build Coastguard Worker {
518*49cdfc7eSAndroid Build Coastguard Worker 	switch (its->type) {
519*49cdfc7eSAndroid Build Coastguard Worker 	break;
520*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
521*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_old_its.it_interval.tv_nsec = nsec;
522*49cdfc7eSAndroid Build Coastguard Worker 	break;
523*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
524*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_its.it_interval.tv_nsec = nsec;
525*49cdfc7eSAndroid Build Coastguard Worker 	break;
526*49cdfc7eSAndroid Build Coastguard Worker 	default:
527*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its->type);
528*49cdfc7eSAndroid Build Coastguard Worker 	}
529*49cdfc7eSAndroid Build Coastguard Worker }
530*49cdfc7eSAndroid Build Coastguard Worker 
531*49cdfc7eSAndroid Build Coastguard Worker /*
532*49cdfc7eSAndroid Build Coastguard Worker  * Returns tst_its it_value seconds.
533*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_get_value_sec(struct tst_its its)534*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_its_get_value_sec(struct tst_its its)
535*49cdfc7eSAndroid Build Coastguard Worker {
536*49cdfc7eSAndroid Build Coastguard Worker 	switch (its.type) {
537*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
538*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_old_its.it_value.tv_sec;
539*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
540*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_its.it_value.tv_sec;
541*49cdfc7eSAndroid Build Coastguard Worker 	default:
542*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its.type);
543*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
544*49cdfc7eSAndroid Build Coastguard Worker 	}
545*49cdfc7eSAndroid Build Coastguard Worker }
546*49cdfc7eSAndroid Build Coastguard Worker 
547*49cdfc7eSAndroid Build Coastguard Worker /*
548*49cdfc7eSAndroid Build Coastguard Worker  * Returns tst_its it_value nanoseconds.
549*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_get_value_nsec(struct tst_its its)550*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_its_get_value_nsec(struct tst_its its)
551*49cdfc7eSAndroid Build Coastguard Worker {
552*49cdfc7eSAndroid Build Coastguard Worker 	switch (its.type) {
553*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
554*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_old_its.it_value.tv_nsec;
555*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
556*49cdfc7eSAndroid Build Coastguard Worker 		return its.ts.kern_its.it_value.tv_nsec;
557*49cdfc7eSAndroid Build Coastguard Worker 	default:
558*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its.type);
559*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
560*49cdfc7eSAndroid Build Coastguard Worker 	}
561*49cdfc7eSAndroid Build Coastguard Worker }
562*49cdfc7eSAndroid Build Coastguard Worker 
563*49cdfc7eSAndroid Build Coastguard Worker /*
564*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_value seconds.
565*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_value_sec(struct tst_its * its,long long sec)566*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_value_sec(struct tst_its *its, long long sec)
567*49cdfc7eSAndroid Build Coastguard Worker {
568*49cdfc7eSAndroid Build Coastguard Worker 	switch (its->type) {
569*49cdfc7eSAndroid Build Coastguard Worker 	break;
570*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
571*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_old_its.it_value.tv_sec = sec;
572*49cdfc7eSAndroid Build Coastguard Worker 	break;
573*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
574*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_its.it_value.tv_sec = sec;
575*49cdfc7eSAndroid Build Coastguard Worker 	break;
576*49cdfc7eSAndroid Build Coastguard Worker 	default:
577*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its->type);
578*49cdfc7eSAndroid Build Coastguard Worker 	}
579*49cdfc7eSAndroid Build Coastguard Worker }
580*49cdfc7eSAndroid Build Coastguard Worker 
581*49cdfc7eSAndroid Build Coastguard Worker /*
582*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_value nanoseconds.
583*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_value_nsec(struct tst_its * its,long long nsec)584*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_value_nsec(struct tst_its *its, long long nsec)
585*49cdfc7eSAndroid Build Coastguard Worker {
586*49cdfc7eSAndroid Build Coastguard Worker 	switch (its->type) {
587*49cdfc7eSAndroid Build Coastguard Worker 	break;
588*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_OLD_TIMESPEC:
589*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_old_its.it_value.tv_nsec = nsec;
590*49cdfc7eSAndroid Build Coastguard Worker 	break;
591*49cdfc7eSAndroid Build Coastguard Worker 	case TST_KERN_TIMESPEC:
592*49cdfc7eSAndroid Build Coastguard Worker 		its->ts.kern_its.it_value.tv_nsec = nsec;
593*49cdfc7eSAndroid Build Coastguard Worker 	break;
594*49cdfc7eSAndroid Build Coastguard Worker 	default:
595*49cdfc7eSAndroid Build Coastguard Worker 		tst_brk(TBROK, "Invalid type: %d", its->type);
596*49cdfc7eSAndroid Build Coastguard Worker 	}
597*49cdfc7eSAndroid Build Coastguard Worker }
598*49cdfc7eSAndroid Build Coastguard Worker 
599*49cdfc7eSAndroid Build Coastguard Worker /*
600*49cdfc7eSAndroid Build Coastguard Worker  * Checks that timespec is valid, i.e. that the timestamp is not zero and that
601*49cdfc7eSAndroid Build Coastguard Worker  * the nanoseconds are normalized i.e. in <0, 1s) interval.
602*49cdfc7eSAndroid Build Coastguard Worker  *
603*49cdfc7eSAndroid Build Coastguard Worker  *  0: On success, i.e. timespec updated correctly.
604*49cdfc7eSAndroid Build Coastguard Worker  * -1: Error, timespec not updated.
605*49cdfc7eSAndroid Build Coastguard Worker  * -2: Error, tv_nsec is corrupted.
606*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_valid(struct tst_ts * t)607*49cdfc7eSAndroid Build Coastguard Worker static inline int tst_ts_valid(struct tst_ts *t)
608*49cdfc7eSAndroid Build Coastguard Worker {
609*49cdfc7eSAndroid Build Coastguard Worker 	long long nsec = tst_ts_get_nsec(*t);
610*49cdfc7eSAndroid Build Coastguard Worker 
611*49cdfc7eSAndroid Build Coastguard Worker 	if (nsec < 0 || nsec >= 1000000000)
612*49cdfc7eSAndroid Build Coastguard Worker 		return -2;
613*49cdfc7eSAndroid Build Coastguard Worker 
614*49cdfc7eSAndroid Build Coastguard Worker 	if (tst_ts_get_sec(*t) == 0 && tst_ts_get_nsec(*t) == 0)
615*49cdfc7eSAndroid Build Coastguard Worker 		return -1;
616*49cdfc7eSAndroid Build Coastguard Worker 
617*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
618*49cdfc7eSAndroid Build Coastguard Worker }
619*49cdfc7eSAndroid Build Coastguard Worker 
620*49cdfc7eSAndroid Build Coastguard Worker /*
621*49cdfc7eSAndroid Build Coastguard Worker  * Converts timespec to tst_ts.
622*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_from_timespec(struct timespec ts)623*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts tst_ts_from_timespec(struct timespec ts)
624*49cdfc7eSAndroid Build Coastguard Worker {
625*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts t = {
626*49cdfc7eSAndroid Build Coastguard Worker 		.type = TST_LIBC_TIMESPEC,
627*49cdfc7eSAndroid Build Coastguard Worker 		.ts.libc_ts.tv_sec = ts.tv_sec,
628*49cdfc7eSAndroid Build Coastguard Worker 		.ts.libc_ts.tv_nsec = ts.tv_nsec,
629*49cdfc7eSAndroid Build Coastguard Worker 	};
630*49cdfc7eSAndroid Build Coastguard Worker 
631*49cdfc7eSAndroid Build Coastguard Worker 	return t;
632*49cdfc7eSAndroid Build Coastguard Worker }
633*49cdfc7eSAndroid Build Coastguard Worker 
634*49cdfc7eSAndroid Build Coastguard Worker /*
635*49cdfc7eSAndroid Build Coastguard Worker  * Converst tst_ts into timespec.
636*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_to_timespec(struct tst_ts t)637*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec tst_ts_to_timespec(struct tst_ts t)
638*49cdfc7eSAndroid Build Coastguard Worker {
639*49cdfc7eSAndroid Build Coastguard Worker 	return t.ts.libc_ts;
640*49cdfc7eSAndroid Build Coastguard Worker }
641*49cdfc7eSAndroid Build Coastguard Worker 
642*49cdfc7eSAndroid Build Coastguard Worker /*
643*49cdfc7eSAndroid Build Coastguard Worker  * Converts tst_ts to nanoseconds.
644*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_to_ns(struct tst_ts t)645*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_ts_to_ns(struct tst_ts t)
646*49cdfc7eSAndroid Build Coastguard Worker {
647*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_get_sec(t) * 1000000000 + tst_ts_get_nsec(t);
648*49cdfc7eSAndroid Build Coastguard Worker }
649*49cdfc7eSAndroid Build Coastguard Worker 
650*49cdfc7eSAndroid Build Coastguard Worker /*
651*49cdfc7eSAndroid Build Coastguard Worker  * Converts tst_ts to microseconds and rounds the value.
652*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_to_us(struct tst_ts t)653*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_ts_to_us(struct tst_ts t)
654*49cdfc7eSAndroid Build Coastguard Worker {
655*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_get_sec(t) * 1000000 +
656*49cdfc7eSAndroid Build Coastguard Worker 	       (tst_ts_get_nsec(t) + 500) / 1000;
657*49cdfc7eSAndroid Build Coastguard Worker }
658*49cdfc7eSAndroid Build Coastguard Worker 
659*49cdfc7eSAndroid Build Coastguard Worker /*
660*49cdfc7eSAndroid Build Coastguard Worker  * Converts timespec to microseconds and rounds the value.
661*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timespec_to_us(struct timespec ts)662*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timespec_to_us(struct timespec ts)
663*49cdfc7eSAndroid Build Coastguard Worker {
664*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_us(tst_ts_from_timespec(ts));
665*49cdfc7eSAndroid Build Coastguard Worker }
666*49cdfc7eSAndroid Build Coastguard Worker 
667*49cdfc7eSAndroid Build Coastguard Worker /*
668*49cdfc7eSAndroid Build Coastguard Worker  * Converts tst_ts to milliseconds and rounds the value.
669*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_to_ms(struct tst_ts t)670*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_ts_to_ms(struct tst_ts t)
671*49cdfc7eSAndroid Build Coastguard Worker {
672*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_get_sec(t) * 1000 +
673*49cdfc7eSAndroid Build Coastguard Worker 	       (tst_ts_get_nsec(t) + 500000) / 1000000;
674*49cdfc7eSAndroid Build Coastguard Worker }
675*49cdfc7eSAndroid Build Coastguard Worker 
676*49cdfc7eSAndroid Build Coastguard Worker /*
677*49cdfc7eSAndroid Build Coastguard Worker  * Converts timespec to milliseconds and rounds the value.
678*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timespec_to_ms(struct timespec ts)679*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timespec_to_ms(struct timespec ts)
680*49cdfc7eSAndroid Build Coastguard Worker {
681*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_ms(tst_ts_from_timespec(ts));
682*49cdfc7eSAndroid Build Coastguard Worker }
683*49cdfc7eSAndroid Build Coastguard Worker 
684*49cdfc7eSAndroid Build Coastguard Worker /*
685*49cdfc7eSAndroid Build Coastguard Worker  * Converts nanoseconds to tst_ts
686*49cdfc7eSAndroid Build Coastguard Worker  */
687*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_from_ns(enum tst_ts_type type,long long ns)688*49cdfc7eSAndroid Build Coastguard Worker tst_ts_from_ns(enum tst_ts_type type, long long ns)
689*49cdfc7eSAndroid Build Coastguard Worker {
690*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts ret = {.type = type};
691*49cdfc7eSAndroid Build Coastguard Worker 
692*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&ret, ns / 1000000000);
693*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&ret, ns % 1000000000);
694*49cdfc7eSAndroid Build Coastguard Worker 
695*49cdfc7eSAndroid Build Coastguard Worker 	return ret;
696*49cdfc7eSAndroid Build Coastguard Worker }
697*49cdfc7eSAndroid Build Coastguard Worker 
698*49cdfc7eSAndroid Build Coastguard Worker /*
699*49cdfc7eSAndroid Build Coastguard Worker  * Converts microseconds to tst_ts
700*49cdfc7eSAndroid Build Coastguard Worker  */
701*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_from_us(enum tst_ts_type type,long long us)702*49cdfc7eSAndroid Build Coastguard Worker tst_ts_from_us(enum tst_ts_type type, long long us)
703*49cdfc7eSAndroid Build Coastguard Worker {
704*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts ret = {.type = type};
705*49cdfc7eSAndroid Build Coastguard Worker 
706*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&ret, us / 1000000);
707*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&ret, (us % 1000000) * 1000);
708*49cdfc7eSAndroid Build Coastguard Worker 
709*49cdfc7eSAndroid Build Coastguard Worker 	return ret;
710*49cdfc7eSAndroid Build Coastguard Worker }
711*49cdfc7eSAndroid Build Coastguard Worker 
712*49cdfc7eSAndroid Build Coastguard Worker /*
713*49cdfc7eSAndroid Build Coastguard Worker  * Converts microseconds to timespec
714*49cdfc7eSAndroid Build Coastguard Worker  */
715*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec
tst_timespec_from_us(long long us)716*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_from_us(long long us)
717*49cdfc7eSAndroid Build Coastguard Worker {
718*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_timespec(tst_ts_from_us(TST_LIBC_TIMESPEC, us));
719*49cdfc7eSAndroid Build Coastguard Worker }
720*49cdfc7eSAndroid Build Coastguard Worker 
721*49cdfc7eSAndroid Build Coastguard Worker /*
722*49cdfc7eSAndroid Build Coastguard Worker  * Converts miliseconds to tst_ts
723*49cdfc7eSAndroid Build Coastguard Worker  */
724*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_from_ms(enum tst_ts_type type,long long ms)725*49cdfc7eSAndroid Build Coastguard Worker tst_ts_from_ms(enum tst_ts_type type, long long ms)
726*49cdfc7eSAndroid Build Coastguard Worker {
727*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts ret = {.type = type};
728*49cdfc7eSAndroid Build Coastguard Worker 
729*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&ret, ms / 1000);
730*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&ret, (ms % 1000) * 1000000);
731*49cdfc7eSAndroid Build Coastguard Worker 
732*49cdfc7eSAndroid Build Coastguard Worker 	return ret;
733*49cdfc7eSAndroid Build Coastguard Worker }
734*49cdfc7eSAndroid Build Coastguard Worker 
735*49cdfc7eSAndroid Build Coastguard Worker /*
736*49cdfc7eSAndroid Build Coastguard Worker  * Converts miliseconds to timespec
737*49cdfc7eSAndroid Build Coastguard Worker  */
738*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec
tst_timespec_from_ms(long long ms)739*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_from_ms(long long ms)
740*49cdfc7eSAndroid Build Coastguard Worker {
741*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_timespec(tst_ts_from_ms(TST_LIBC_TIMESPEC, ms));
742*49cdfc7eSAndroid Build Coastguard Worker }
743*49cdfc7eSAndroid Build Coastguard Worker 
744*49cdfc7eSAndroid Build Coastguard Worker /*
745*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_value from microseconds.
746*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_interval_from_us(struct tst_its * its,long long usec)747*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_interval_from_us(struct tst_its *its, long long usec)
748*49cdfc7eSAndroid Build Coastguard Worker {
749*49cdfc7eSAndroid Build Coastguard Worker 	struct timespec tp = tst_timespec_from_us(usec);
750*49cdfc7eSAndroid Build Coastguard Worker 
751*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_interval_sec(its, tp.tv_sec);
752*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_interval_nsec(its, tp.tv_nsec);
753*49cdfc7eSAndroid Build Coastguard Worker }
754*49cdfc7eSAndroid Build Coastguard Worker 
755*49cdfc7eSAndroid Build Coastguard Worker /*
756*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_value from microseconds.
757*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_value_from_us(struct tst_its * its,long long usec)758*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_value_from_us(struct tst_its *its, long long usec)
759*49cdfc7eSAndroid Build Coastguard Worker {
760*49cdfc7eSAndroid Build Coastguard Worker 	struct timespec tp = tst_timespec_from_us(usec);
761*49cdfc7eSAndroid Build Coastguard Worker 
762*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_value_sec(its, tp.tv_sec);
763*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_value_nsec(its, tp.tv_nsec);
764*49cdfc7eSAndroid Build Coastguard Worker }
765*49cdfc7eSAndroid Build Coastguard Worker 
766*49cdfc7eSAndroid Build Coastguard Worker /*
767*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_interval from tst_ts.
768*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_interval_from_ts(struct tst_its * its,struct tst_ts ts)769*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_interval_from_ts(struct tst_its *its, struct tst_ts ts)
770*49cdfc7eSAndroid Build Coastguard Worker {
771*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_interval_sec(its, tst_ts_get_sec(ts));
772*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_interval_nsec(its, tst_ts_get_nsec(ts));
773*49cdfc7eSAndroid Build Coastguard Worker }
774*49cdfc7eSAndroid Build Coastguard Worker 
775*49cdfc7eSAndroid Build Coastguard Worker /*
776*49cdfc7eSAndroid Build Coastguard Worker  * Sets tst_its it_value from tst_ts.
777*49cdfc7eSAndroid Build Coastguard Worker  */
tst_its_set_value_from_ts(struct tst_its * its,struct tst_ts ts)778*49cdfc7eSAndroid Build Coastguard Worker static inline void tst_its_set_value_from_ts(struct tst_its *its, struct tst_ts ts)
779*49cdfc7eSAndroid Build Coastguard Worker {
780*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_value_sec(its, tst_ts_get_sec(ts));
781*49cdfc7eSAndroid Build Coastguard Worker 	tst_its_set_value_nsec(its, tst_ts_get_nsec(ts));
782*49cdfc7eSAndroid Build Coastguard Worker }
783*49cdfc7eSAndroid Build Coastguard Worker 
784*49cdfc7eSAndroid Build Coastguard Worker /*
785*49cdfc7eSAndroid Build Coastguard Worker  * Returns if t1 less than t2. Both t1 and t2 must be normalized.
786*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_lt(struct tst_ts t1,struct tst_ts t2)787*49cdfc7eSAndroid Build Coastguard Worker static inline int tst_ts_lt(struct tst_ts t1, struct tst_ts t2)
788*49cdfc7eSAndroid Build Coastguard Worker {
789*49cdfc7eSAndroid Build Coastguard Worker 	if (tst_ts_get_sec(t1) == tst_ts_get_sec(t2))
790*49cdfc7eSAndroid Build Coastguard Worker 		return tst_ts_get_nsec(t1) < tst_ts_get_nsec(t2);
791*49cdfc7eSAndroid Build Coastguard Worker 
792*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_get_sec(t1) < tst_ts_get_sec(t2);
793*49cdfc7eSAndroid Build Coastguard Worker }
794*49cdfc7eSAndroid Build Coastguard Worker 
795*49cdfc7eSAndroid Build Coastguard Worker /*
796*49cdfc7eSAndroid Build Coastguard Worker  * Returns if ts1 less than ts2. Both ts1 and ts2 must be normalized.
797*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timespec_lt(struct timespec ts1,struct timespec ts2)798*49cdfc7eSAndroid Build Coastguard Worker static inline int tst_timespec_lt(struct timespec ts1, struct timespec ts2)
799*49cdfc7eSAndroid Build Coastguard Worker {
800*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_lt(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
801*49cdfc7eSAndroid Build Coastguard Worker }
802*49cdfc7eSAndroid Build Coastguard Worker 
803*49cdfc7eSAndroid Build Coastguard Worker /*
804*49cdfc7eSAndroid Build Coastguard Worker  * Returns normalized tst_ts, i.e. 0 <= nsec < 1000000000.
805*49cdfc7eSAndroid Build Coastguard Worker  */
tst_ts_normalize(struct tst_ts t)806*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts tst_ts_normalize(struct tst_ts t)
807*49cdfc7eSAndroid Build Coastguard Worker {
808*49cdfc7eSAndroid Build Coastguard Worker 	long long sec = tst_ts_get_sec(t);
809*49cdfc7eSAndroid Build Coastguard Worker 	long long nsec = tst_ts_get_nsec(t);
810*49cdfc7eSAndroid Build Coastguard Worker 
811*49cdfc7eSAndroid Build Coastguard Worker 	if (nsec >= 1000000000) {
812*49cdfc7eSAndroid Build Coastguard Worker 		tst_ts_set_sec(&t, sec + 1);
813*49cdfc7eSAndroid Build Coastguard Worker 		tst_ts_set_nsec(&t, nsec - 1000000000);
814*49cdfc7eSAndroid Build Coastguard Worker 	}
815*49cdfc7eSAndroid Build Coastguard Worker 
816*49cdfc7eSAndroid Build Coastguard Worker 	if (nsec < 0) {
817*49cdfc7eSAndroid Build Coastguard Worker 		tst_ts_set_sec(&t, sec - 1);
818*49cdfc7eSAndroid Build Coastguard Worker 		tst_ts_set_nsec(&t, nsec + 1000000000);
819*49cdfc7eSAndroid Build Coastguard Worker 	}
820*49cdfc7eSAndroid Build Coastguard Worker 
821*49cdfc7eSAndroid Build Coastguard Worker 	return t;
822*49cdfc7eSAndroid Build Coastguard Worker }
823*49cdfc7eSAndroid Build Coastguard Worker 
824*49cdfc7eSAndroid Build Coastguard Worker /*
825*49cdfc7eSAndroid Build Coastguard Worker  * Adds us microseconds to tst_ts.
826*49cdfc7eSAndroid Build Coastguard Worker  */
827*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_add_us(struct tst_ts t,long long us)828*49cdfc7eSAndroid Build Coastguard Worker tst_ts_add_us(struct tst_ts t, long long us)
829*49cdfc7eSAndroid Build Coastguard Worker {
830*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res = {.type = t.type};
831*49cdfc7eSAndroid Build Coastguard Worker 
832*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&res, tst_ts_get_sec(t) + us / 1000000);
833*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&res, tst_ts_get_nsec(t) + (us % 1000000) * 1000);
834*49cdfc7eSAndroid Build Coastguard Worker 
835*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_normalize(res);
836*49cdfc7eSAndroid Build Coastguard Worker }
837*49cdfc7eSAndroid Build Coastguard Worker 
838*49cdfc7eSAndroid Build Coastguard Worker /*
839*49cdfc7eSAndroid Build Coastguard Worker  * Adds us microseconds to struct timespec.
840*49cdfc7eSAndroid Build Coastguard Worker  */
841*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec
tst_timespec_add_us(struct timespec ts,long long us)842*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_add_us(struct timespec ts, long long us)
843*49cdfc7eSAndroid Build Coastguard Worker {
844*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res;
845*49cdfc7eSAndroid Build Coastguard Worker 
846*49cdfc7eSAndroid Build Coastguard Worker 	res = tst_ts_add_us(tst_ts_from_timespec(ts), us);
847*49cdfc7eSAndroid Build Coastguard Worker 
848*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_timespec(res);
849*49cdfc7eSAndroid Build Coastguard Worker }
850*49cdfc7eSAndroid Build Coastguard Worker 
851*49cdfc7eSAndroid Build Coastguard Worker /*
852*49cdfc7eSAndroid Build Coastguard Worker  * Substracts us microseconds from tst_ts.
853*49cdfc7eSAndroid Build Coastguard Worker  */
854*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_sub_us(struct tst_ts t,long long us)855*49cdfc7eSAndroid Build Coastguard Worker tst_ts_sub_us(struct tst_ts t, long long us)
856*49cdfc7eSAndroid Build Coastguard Worker {
857*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res = {.type = t.type};
858*49cdfc7eSAndroid Build Coastguard Worker 
859*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&res, tst_ts_get_sec(t) - us / 1000000);
860*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&res, tst_ts_get_nsec(t) - (us % 1000000) * 1000);
861*49cdfc7eSAndroid Build Coastguard Worker 
862*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_normalize(res);
863*49cdfc7eSAndroid Build Coastguard Worker }
864*49cdfc7eSAndroid Build Coastguard Worker 
865*49cdfc7eSAndroid Build Coastguard Worker /*
866*49cdfc7eSAndroid Build Coastguard Worker  * Substracts us microseconds from timespec.
867*49cdfc7eSAndroid Build Coastguard Worker  */
868*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec
tst_timespec_sub_us(struct timespec ts,long long us)869*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_sub_us(struct timespec ts, long long us)
870*49cdfc7eSAndroid Build Coastguard Worker {
871*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res;
872*49cdfc7eSAndroid Build Coastguard Worker 
873*49cdfc7eSAndroid Build Coastguard Worker 	res = tst_ts_sub_us(tst_ts_from_timespec(ts), us);
874*49cdfc7eSAndroid Build Coastguard Worker 
875*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_timespec(res);
876*49cdfc7eSAndroid Build Coastguard Worker }
877*49cdfc7eSAndroid Build Coastguard Worker 
878*49cdfc7eSAndroid Build Coastguard Worker /*
879*49cdfc7eSAndroid Build Coastguard Worker  * Adds two tst_ts structures.
880*49cdfc7eSAndroid Build Coastguard Worker  */
881*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_add(struct tst_ts t1,struct tst_ts t2)882*49cdfc7eSAndroid Build Coastguard Worker tst_ts_add(struct tst_ts t1, struct tst_ts t2)
883*49cdfc7eSAndroid Build Coastguard Worker {
884*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res = {.type = t1.type};
885*49cdfc7eSAndroid Build Coastguard Worker 
886*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&res, tst_ts_get_sec(t1) + tst_ts_get_sec(t2));
887*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&res, tst_ts_get_nsec(t1) + tst_ts_get_nsec(t2));
888*49cdfc7eSAndroid Build Coastguard Worker 
889*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_normalize(res);
890*49cdfc7eSAndroid Build Coastguard Worker }
891*49cdfc7eSAndroid Build Coastguard Worker 
892*49cdfc7eSAndroid Build Coastguard Worker /*
893*49cdfc7eSAndroid Build Coastguard Worker  * Adds two timespec structures.
894*49cdfc7eSAndroid Build Coastguard Worker  */
895*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec
tst_timespec_add(struct timespec ts1,struct timespec ts2)896*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_add(struct timespec ts1, struct timespec ts2)
897*49cdfc7eSAndroid Build Coastguard Worker {
898*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res;
899*49cdfc7eSAndroid Build Coastguard Worker 
900*49cdfc7eSAndroid Build Coastguard Worker 	res = tst_ts_add(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
901*49cdfc7eSAndroid Build Coastguard Worker 
902*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_timespec(res);
903*49cdfc7eSAndroid Build Coastguard Worker }
904*49cdfc7eSAndroid Build Coastguard Worker 
905*49cdfc7eSAndroid Build Coastguard Worker /*
906*49cdfc7eSAndroid Build Coastguard Worker  * Substract two tst_ts structures.
907*49cdfc7eSAndroid Build Coastguard Worker  */
908*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_diff(struct tst_ts t1,struct tst_ts t2)909*49cdfc7eSAndroid Build Coastguard Worker tst_ts_diff(struct tst_ts t1, struct tst_ts t2)
910*49cdfc7eSAndroid Build Coastguard Worker {
911*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res = {.type = t1.type};
912*49cdfc7eSAndroid Build Coastguard Worker 
913*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_sec(&res, tst_ts_get_sec(t1) - tst_ts_get_sec(t2));
914*49cdfc7eSAndroid Build Coastguard Worker 	tst_ts_set_nsec(&res, tst_ts_get_nsec(t1) - tst_ts_get_nsec(t2));
915*49cdfc7eSAndroid Build Coastguard Worker 
916*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_normalize(res);
917*49cdfc7eSAndroid Build Coastguard Worker }
918*49cdfc7eSAndroid Build Coastguard Worker 
919*49cdfc7eSAndroid Build Coastguard Worker /*
920*49cdfc7eSAndroid Build Coastguard Worker  * Substract two timespec structures.
921*49cdfc7eSAndroid Build Coastguard Worker  */
922*49cdfc7eSAndroid Build Coastguard Worker static inline struct timespec
tst_timespec_diff(struct timespec ts1,struct timespec ts2)923*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_diff(struct timespec ts1, struct timespec ts2)
924*49cdfc7eSAndroid Build Coastguard Worker {
925*49cdfc7eSAndroid Build Coastguard Worker 	struct tst_ts res;
926*49cdfc7eSAndroid Build Coastguard Worker 
927*49cdfc7eSAndroid Build Coastguard Worker 	res = tst_ts_diff(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
928*49cdfc7eSAndroid Build Coastguard Worker 
929*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_timespec(res);
930*49cdfc7eSAndroid Build Coastguard Worker }
931*49cdfc7eSAndroid Build Coastguard Worker 
932*49cdfc7eSAndroid Build Coastguard Worker /*
933*49cdfc7eSAndroid Build Coastguard Worker  * Substract two tst_ts structures returns number of nanoseconds.
934*49cdfc7eSAndroid Build Coastguard Worker  */
935*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_ts_diff_ns(struct tst_ts t1,struct tst_ts t2)936*49cdfc7eSAndroid Build Coastguard Worker tst_ts_diff_ns(struct tst_ts t1, struct tst_ts t2)
937*49cdfc7eSAndroid Build Coastguard Worker {
938*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_ns(tst_ts_diff(t1, t2));
939*49cdfc7eSAndroid Build Coastguard Worker }
940*49cdfc7eSAndroid Build Coastguard Worker 
941*49cdfc7eSAndroid Build Coastguard Worker /*
942*49cdfc7eSAndroid Build Coastguard Worker  * Substract two timespec structures returns number of nanoseconds.
943*49cdfc7eSAndroid Build Coastguard Worker  */
944*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_timespec_diff_ns(struct timespec ts1,struct timespec ts2)945*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_diff_ns(struct timespec ts1, struct timespec ts2)
946*49cdfc7eSAndroid Build Coastguard Worker {
947*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_diff_ns(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
948*49cdfc7eSAndroid Build Coastguard Worker }
949*49cdfc7eSAndroid Build Coastguard Worker 
950*49cdfc7eSAndroid Build Coastguard Worker /*
951*49cdfc7eSAndroid Build Coastguard Worker  * Substract two tst_ts structures returns number of microseconds.
952*49cdfc7eSAndroid Build Coastguard Worker  */
953*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_ts_diff_us(struct tst_ts t1,struct tst_ts t2)954*49cdfc7eSAndroid Build Coastguard Worker tst_ts_diff_us(struct tst_ts t1, struct tst_ts t2)
955*49cdfc7eSAndroid Build Coastguard Worker {
956*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_us(tst_ts_diff(t1, t2));
957*49cdfc7eSAndroid Build Coastguard Worker }
958*49cdfc7eSAndroid Build Coastguard Worker 
959*49cdfc7eSAndroid Build Coastguard Worker /*
960*49cdfc7eSAndroid Build Coastguard Worker  * Substract two timespec structures returns number of microseconds.
961*49cdfc7eSAndroid Build Coastguard Worker  */
962*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_timespec_diff_us(struct timespec ts1,struct timespec ts2)963*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_diff_us(struct timespec ts1, struct timespec ts2)
964*49cdfc7eSAndroid Build Coastguard Worker {
965*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_diff_us(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
966*49cdfc7eSAndroid Build Coastguard Worker }
967*49cdfc7eSAndroid Build Coastguard Worker 
968*49cdfc7eSAndroid Build Coastguard Worker /*
969*49cdfc7eSAndroid Build Coastguard Worker  * Substract two tst_ts structures returns number of milliseconds.
970*49cdfc7eSAndroid Build Coastguard Worker  */
971*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_ts_diff_ms(struct tst_ts t1,struct tst_ts t2)972*49cdfc7eSAndroid Build Coastguard Worker tst_ts_diff_ms(struct tst_ts t1, struct tst_ts t2)
973*49cdfc7eSAndroid Build Coastguard Worker {
974*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_ms(tst_ts_diff(t1, t2));
975*49cdfc7eSAndroid Build Coastguard Worker }
976*49cdfc7eSAndroid Build Coastguard Worker 
977*49cdfc7eSAndroid Build Coastguard Worker /*
978*49cdfc7eSAndroid Build Coastguard Worker  * Substract two timespec structures returns number of milliseconds.
979*49cdfc7eSAndroid Build Coastguard Worker  */
980*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_timespec_diff_ms(struct timespec ts1,struct timespec ts2)981*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_diff_ms(struct timespec ts1, struct timespec ts2)
982*49cdfc7eSAndroid Build Coastguard Worker {
983*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_diff_ms(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
984*49cdfc7eSAndroid Build Coastguard Worker }
985*49cdfc7eSAndroid Build Coastguard Worker 
986*49cdfc7eSAndroid Build Coastguard Worker /*
987*49cdfc7eSAndroid Build Coastguard Worker  * Returns absolute value of difference between two timespec structures.
988*49cdfc7eSAndroid Build Coastguard Worker  */
989*49cdfc7eSAndroid Build Coastguard Worker static inline struct tst_ts
tst_ts_abs_diff(struct tst_ts t1,struct tst_ts t2)990*49cdfc7eSAndroid Build Coastguard Worker tst_ts_abs_diff(struct tst_ts t1, struct tst_ts t2)
991*49cdfc7eSAndroid Build Coastguard Worker {
992*49cdfc7eSAndroid Build Coastguard Worker 	if (tst_ts_lt(t1, t2))
993*49cdfc7eSAndroid Build Coastguard Worker 		return tst_ts_diff(t2, t1);
994*49cdfc7eSAndroid Build Coastguard Worker 	else
995*49cdfc7eSAndroid Build Coastguard Worker 		return tst_ts_diff(t1, t2);
996*49cdfc7eSAndroid Build Coastguard Worker }
997*49cdfc7eSAndroid Build Coastguard Worker 
998*49cdfc7eSAndroid Build Coastguard Worker /*
999*49cdfc7eSAndroid Build Coastguard Worker  * Returns absolute value of difference between two tst_ts structures in
1000*49cdfc7eSAndroid Build Coastguard Worker  * microseconds.
1001*49cdfc7eSAndroid Build Coastguard Worker  */
1002*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_ts_abs_diff_us(struct tst_ts t1,struct tst_ts t2)1003*49cdfc7eSAndroid Build Coastguard Worker tst_ts_abs_diff_us(struct tst_ts t1, struct tst_ts t2)
1004*49cdfc7eSAndroid Build Coastguard Worker {
1005*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_us(tst_ts_abs_diff(t1, t2));
1006*49cdfc7eSAndroid Build Coastguard Worker }
1007*49cdfc7eSAndroid Build Coastguard Worker 
1008*49cdfc7eSAndroid Build Coastguard Worker /*
1009*49cdfc7eSAndroid Build Coastguard Worker  * Returns absolute value of difference between two timespec structures in
1010*49cdfc7eSAndroid Build Coastguard Worker  * microseconds.
1011*49cdfc7eSAndroid Build Coastguard Worker  */
1012*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_timespec_abs_diff_us(struct timespec ts1,struct timespec ts2)1013*49cdfc7eSAndroid Build Coastguard Worker tst_timespec_abs_diff_us(struct timespec ts1, struct timespec ts2)
1014*49cdfc7eSAndroid Build Coastguard Worker {
1015*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_abs_diff_us(tst_ts_from_timespec(ts1), tst_ts_from_timespec(ts2));
1016*49cdfc7eSAndroid Build Coastguard Worker }
1017*49cdfc7eSAndroid Build Coastguard Worker 
1018*49cdfc7eSAndroid Build Coastguard Worker /*
1019*49cdfc7eSAndroid Build Coastguard Worker  * Returns absolute value of difference between two timespec structures in
1020*49cdfc7eSAndroid Build Coastguard Worker  * milliseconds.
1021*49cdfc7eSAndroid Build Coastguard Worker  */
1022*49cdfc7eSAndroid Build Coastguard Worker static inline long long
tst_ts_abs_diff_ms(struct tst_ts t1,struct tst_ts t2)1023*49cdfc7eSAndroid Build Coastguard Worker tst_ts_abs_diff_ms(struct tst_ts t1, struct tst_ts t2)
1024*49cdfc7eSAndroid Build Coastguard Worker {
1025*49cdfc7eSAndroid Build Coastguard Worker 	return tst_ts_to_ms(tst_ts_abs_diff(t1, t2));
1026*49cdfc7eSAndroid Build Coastguard Worker }
1027*49cdfc7eSAndroid Build Coastguard Worker 
1028*49cdfc7eSAndroid Build Coastguard Worker /*
1029*49cdfc7eSAndroid Build Coastguard Worker  * Exits the test with TCONF if particular timer is not supported. This is
1030*49cdfc7eSAndroid Build Coastguard Worker  * intended to be used in test setup. There is no cleanup callback parameter as
1031*49cdfc7eSAndroid Build Coastguard Worker  * you are expected to call it before initializing any resources that has to be
1032*49cdfc7eSAndroid Build Coastguard Worker  * cleaned up later.
1033*49cdfc7eSAndroid Build Coastguard Worker  *
1034*49cdfc7eSAndroid Build Coastguard Worker  * @clk_id: Posix clock to use.
1035*49cdfc7eSAndroid Build Coastguard Worker  */
1036*49cdfc7eSAndroid Build Coastguard Worker void tst_timer_check(clockid_t clk_id);
1037*49cdfc7eSAndroid Build Coastguard Worker 
1038*49cdfc7eSAndroid Build Coastguard Worker /*
1039*49cdfc7eSAndroid Build Coastguard Worker  * Marks a start time for given clock type.
1040*49cdfc7eSAndroid Build Coastguard Worker  *
1041*49cdfc7eSAndroid Build Coastguard Worker  * @clk_id: Posix clock to use.
1042*49cdfc7eSAndroid Build Coastguard Worker  */
1043*49cdfc7eSAndroid Build Coastguard Worker void tst_timer_start(clockid_t clk_id);
1044*49cdfc7eSAndroid Build Coastguard Worker 
1045*49cdfc7eSAndroid Build Coastguard Worker /*
1046*49cdfc7eSAndroid Build Coastguard Worker  * Returns true if timer started by tst_timer_start() has been running for
1047*49cdfc7eSAndroid Build Coastguard Worker  * longer than ms seconds.
1048*49cdfc7eSAndroid Build Coastguard Worker  *
1049*49cdfc7eSAndroid Build Coastguard Worker  * @ms: Time interval in milliseconds.
1050*49cdfc7eSAndroid Build Coastguard Worker  */
1051*49cdfc7eSAndroid Build Coastguard Worker int tst_timer_expired_ms(long long ms);
1052*49cdfc7eSAndroid Build Coastguard Worker 
1053*49cdfc7eSAndroid Build Coastguard Worker /*
1054*49cdfc7eSAndroid Build Coastguard Worker  * Marks timer end time.
1055*49cdfc7eSAndroid Build Coastguard Worker  */
1056*49cdfc7eSAndroid Build Coastguard Worker void tst_timer_stop(void);
1057*49cdfc7eSAndroid Build Coastguard Worker 
1058*49cdfc7eSAndroid Build Coastguard Worker /*
1059*49cdfc7eSAndroid Build Coastguard Worker  * Retuns elapsed time in struct timespec.
1060*49cdfc7eSAndroid Build Coastguard Worker  */
1061*49cdfc7eSAndroid Build Coastguard Worker struct timespec tst_timer_elapsed(void);
1062*49cdfc7eSAndroid Build Coastguard Worker 
1063*49cdfc7eSAndroid Build Coastguard Worker /*
1064*49cdfc7eSAndroid Build Coastguard Worker  * Returns elapsed time in milliseconds.
1065*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timer_elapsed_ms(void)1066*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timer_elapsed_ms(void)
1067*49cdfc7eSAndroid Build Coastguard Worker {
1068*49cdfc7eSAndroid Build Coastguard Worker 	return tst_timespec_to_ms(tst_timer_elapsed());
1069*49cdfc7eSAndroid Build Coastguard Worker }
1070*49cdfc7eSAndroid Build Coastguard Worker 
1071*49cdfc7eSAndroid Build Coastguard Worker /*
1072*49cdfc7eSAndroid Build Coastguard Worker  * Returns elapsed time in microseconds.
1073*49cdfc7eSAndroid Build Coastguard Worker  */
tst_timer_elapsed_us(void)1074*49cdfc7eSAndroid Build Coastguard Worker static inline long long tst_timer_elapsed_us(void)
1075*49cdfc7eSAndroid Build Coastguard Worker {
1076*49cdfc7eSAndroid Build Coastguard Worker 	return tst_timespec_to_us(tst_timer_elapsed());
1077*49cdfc7eSAndroid Build Coastguard Worker }
1078*49cdfc7eSAndroid Build Coastguard Worker 
1079*49cdfc7eSAndroid Build Coastguard Worker #endif /* TST_TIMER */
1080