[444] | 1 | #ifndef _LINUX_TIME_H |
---|
| 2 | #define _LINUX_TIME_H |
---|
| 3 | |
---|
| 4 | #include <asm/param.h> |
---|
| 5 | #include <sys/types.h> |
---|
| 6 | |
---|
| 7 | #ifndef _STRUCT_TIMESPEC |
---|
| 8 | #define _STRUCT_TIMESPEC |
---|
| 9 | struct timespec { |
---|
| 10 | time_t tv_sec; /* seconds */ |
---|
| 11 | long tv_nsec; /* nanoseconds */ |
---|
| 12 | }; |
---|
| 13 | #endif /* _STRUCT_TIMESPEC */ |
---|
| 14 | |
---|
| 15 | /* |
---|
| 16 | * Change timeval to jiffies, trying to avoid the |
---|
| 17 | * most obvious overflows.. |
---|
| 18 | * |
---|
| 19 | * And some not so obvious. |
---|
| 20 | * |
---|
| 21 | * Note that we don't want to return MAX_LONG, because |
---|
| 22 | * for various timeout reasons we often end up having |
---|
| 23 | * to wait "jiffies+1" in order to guarantee that we wait |
---|
| 24 | * at _least_ "jiffies" - so "jiffies+1" had better still |
---|
| 25 | * be positive. |
---|
| 26 | */ |
---|
| 27 | #define MAX_JIFFY_OFFSET ((~0UL >> 1)-1) |
---|
| 28 | |
---|
| 29 | static __inline__ unsigned long |
---|
| 30 | timespec_to_jiffies(struct timespec *value) |
---|
| 31 | { |
---|
| 32 | unsigned long sec = value->tv_sec; |
---|
| 33 | long nsec = value->tv_nsec; |
---|
| 34 | |
---|
| 35 | if (sec >= (MAX_JIFFY_OFFSET / HZ)) |
---|
| 36 | return MAX_JIFFY_OFFSET; |
---|
| 37 | nsec += 1000000000L / HZ - 1; |
---|
| 38 | nsec /= 1000000000L / HZ; |
---|
| 39 | return HZ * sec + nsec; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | static __inline__ void |
---|
| 43 | jiffies_to_timespec(unsigned long jiffies, struct timespec *value) |
---|
| 44 | { |
---|
| 45 | value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ); |
---|
| 46 | value->tv_sec = jiffies / HZ; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | #ifndef _STRUCT_TIMEVAL |
---|
| 50 | #define _STRUCT_TIMEVAL |
---|
| 51 | struct timeval { |
---|
| 52 | time_t tv_sec; /* seconds */ |
---|
| 53 | suseconds_t tv_usec; /* microseconds */ |
---|
| 54 | }; |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | struct timezone { |
---|
| 58 | int tz_minuteswest; /* minutes west of Greenwich */ |
---|
| 59 | int tz_dsttime; /* type of dst correction */ |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | #define ITIMER_REAL 0 |
---|
| 63 | #define ITIMER_VIRTUAL 1 |
---|
| 64 | #define ITIMER_PROF 2 |
---|
| 65 | |
---|
| 66 | struct itimerspec { |
---|
| 67 | struct timespec it_interval; /* timer period */ |
---|
| 68 | struct timespec it_value; /* timer expiration */ |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | struct itimerval { |
---|
| 72 | struct timeval it_interval; /* timer interval */ |
---|
| 73 | struct timeval it_value; /* current value */ |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | #endif |
---|