2 * These are often used by timer.device itself, and inlining
3 * them saves us from function call overhead.
6 /* Add, then normalize */
7 #define ADDTIME(dest, src) \
8 (dest)->tv_micro += (src)->tv_micro; \
9 (dest)->tv_secs += (src)->tv_secs; \
10 while((dest)->tv_micro > 999999) \
13 (dest)->tv_micro -= 1000000; \
17 * Subtraction algorithm:
19 * 2. Check if wrap around will happen, when subtracting src->tv_micro
20 * from dest->tv_micro. If yes, then normalize, by adding 1 sec to
21 * micros and subtracting 1 sec from secs. Note: this check must be
22 * before subtracting src timeval from dest timeval!
24 #define SUBTIME(dest, src) \
25 while ((src)->tv_micro > 999999) \
28 (src)->tv_micro -= 1000000; \
30 while ((dest)->tv_micro > 999999) \
33 (dest)->tv_micro -= 1000000; \
35 if ((dest)->tv_micro < (src)->tv_micro) \
37 (dest)->tv_micro += 1000000; \
40 (dest)->tv_micro -= (src)->tv_micro; \
41 (dest)->tv_secs -= (src)->tv_secs;
43 static inline LONG
CMPTIME(struct timeval
*dest
, struct timeval
*src
)
47 if (dest
->tv_secs
== src
->tv_secs
)
48 diff
= src
->tv_micro
- dest
->tv_micro
;
50 diff
= src
->tv_secs
- dest
->tv_secs
;
61 * Add 'diff' EClock ticks to timeval in 'time'.
62 * Fraction of second value is stored in in 'frac'.
63 * This macro relies on (CPU-specific) tick2usec() implementation
65 #define INCTIME(time, frac, diff) \
67 if ((frac) >= TimerBase->tb_eclock_rate) \
69 (frac) -= TimerBase->tb_eclock_rate; \
72 (time).tv_micro = tick2usec(frac);