| 1 | #ifndef _LINUX_TIME_H
|
|---|
| 2 | #define _LINUX_TIME_H
|
|---|
| 3 |
|
|---|
| 4 | #include <asm/param.h>
|
|---|
| 5 | #include <linux/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 | struct timeval {
|
|---|
| 50 | time_t tv_sec; /* seconds */
|
|---|
| 51 | suseconds_t tv_usec; /* microseconds */
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | struct timezone {
|
|---|
| 55 | int tz_minuteswest; /* minutes west of Greenwich */
|
|---|
| 56 | int tz_dsttime; /* type of dst correction */
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | #define NFDBITS __NFDBITS
|
|---|
| 60 |
|
|---|
| 61 | #ifdef __KERNEL__
|
|---|
| 62 | extern void do_gettimeofday(struct timeval *tv);
|
|---|
| 63 | extern void do_settimeofday(struct timeval *tv);
|
|---|
| 64 | extern void get_fast_time(struct timeval *tv);
|
|---|
| 65 | extern void (*do_get_fast_time)(struct timeval *);
|
|---|
| 66 | #endif
|
|---|
| 67 |
|
|---|
| 68 | #define FD_SETSIZE __FD_SETSIZE
|
|---|
| 69 | #define FD_SET(fd,fdsetp) __FD_SET(fd,fdsetp)
|
|---|
| 70 | #define FD_CLR(fd,fdsetp) __FD_CLR(fd,fdsetp)
|
|---|
| 71 | #define FD_ISSET(fd,fdsetp) __FD_ISSET(fd,fdsetp)
|
|---|
| 72 | #define FD_ZERO(fdsetp) __FD_ZERO(fdsetp)
|
|---|
| 73 |
|
|---|
| 74 | /*
|
|---|
| 75 | * Names of the interval timers, and structure
|
|---|
| 76 | * defining a timer setting.
|
|---|
| 77 | */
|
|---|
| 78 | #define ITIMER_REAL 0
|
|---|
| 79 | #define ITIMER_VIRTUAL 1
|
|---|
| 80 | #define ITIMER_PROF 2
|
|---|
| 81 |
|
|---|
| 82 | struct itimerspec {
|
|---|
| 83 | struct timespec it_interval; /* timer period */
|
|---|
| 84 | struct timespec it_value; /* timer expiration */
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | struct itimerval {
|
|---|
| 88 | struct timeval it_interval; /* timer interval */
|
|---|
| 89 | struct timeval it_value; /* current value */
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | /* msecs_to_jiffies */
|
|---|
| 93 | #ifndef CONFIG_HAVE_MSECS_TO_JIFFIES
|
|---|
| 94 | static __inline__ unsigned int jiffies_to_msecs(const unsigned long j)
|
|---|
| 95 | {
|
|---|
| 96 | #if (HZ <= 1000 && !(1000 % HZ))
|
|---|
| 97 | return (1000 / HZ) * j;
|
|---|
| 98 | #elif (HZ > 1000 && !(HZ % 1000))
|
|---|
| 99 | return (j + (HZ / 1000) - 1)/(HZ / 1000);
|
|---|
| 100 | #else
|
|---|
| 101 | return (j * 1000) / HZ;
|
|---|
| 102 | #endif
|
|---|
| 103 | }
|
|---|
| 104 | static __inline__ unsigned long msecs_to_jiffies(const unsigned int m)
|
|---|
| 105 | {
|
|---|
| 106 | if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
|
|---|
| 107 | return MAX_JIFFY_OFFSET;
|
|---|
| 108 | #if (HZ <= 1000 && !(1000 % HZ))
|
|---|
| 109 | return (m + (1000 / HZ) - 1) / (1000 / HZ);
|
|---|
| 110 | #elif (HZ > 1000 && !(HZ % 1000))
|
|---|
| 111 | return m * (HZ / 1000);
|
|---|
| 112 | #else
|
|---|
| 113 | return (m * HZ + 999) / 1000;
|
|---|
| 114 | #endif
|
|---|
| 115 | }
|
|---|
| 116 | #endif
|
|---|
| 117 |
|
|---|
| 118 | /* wrapper for getnstimeofday()
|
|---|
| 119 | * it's needed for recent 2.6 kernels, too, due to lack of EXPORT_SYMBOL
|
|---|
| 120 | */
|
|---|
| 121 | #define getnstimeofday(x) do { \
|
|---|
| 122 | struct timeval __x; \
|
|---|
| 123 | do_gettimeofday(&__x); \
|
|---|
| 124 | (x)->tv_sec = __x.tv_sec; \
|
|---|
| 125 | (x)->tv_nsec = __x.tv_usec * 1000; \
|
|---|
| 126 | } while (0)
|
|---|
| 127 |
|
|---|
| 128 | #define do_posix_clock_monotonic_gettime getnstimeofday
|
|---|
| 129 |
|
|---|
| 130 | void msleep(unsigned int msecs);
|
|---|
| 131 |
|
|---|
| 132 | #endif
|
|---|