diff options
Diffstat (limited to 'include/linux/time.h')
| -rw-r--r-- | include/linux/time.h | 186 | 
1 files changed, 94 insertions, 92 deletions
| diff --git a/include/linux/time.h b/include/linux/time.h index 797ccd813bb0..614dd8465839 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include <linux/types.h> | 4 | #include <linux/types.h> | 
| 5 | 5 | ||
| 6 | #ifdef __KERNEL__ | 6 | #ifdef __KERNEL__ | 
| 7 | #include <linux/seqlock.h> | 7 | # include <linux/seqlock.h> | 
| 8 | #endif | 8 | #endif | 
| 9 | 9 | ||
| 10 | #ifndef _STRUCT_TIMESPEC | 10 | #ifndef _STRUCT_TIMESPEC | 
| @@ -13,7 +13,7 @@ struct timespec { | |||
| 13 | time_t tv_sec; /* seconds */ | 13 | time_t tv_sec; /* seconds */ | 
| 14 | long tv_nsec; /* nanoseconds */ | 14 | long tv_nsec; /* nanoseconds */ | 
| 15 | }; | 15 | }; | 
| 16 | #endif /* _STRUCT_TIMESPEC */ | 16 | #endif | 
| 17 | 17 | ||
| 18 | struct timeval { | 18 | struct timeval { | 
| 19 | time_t tv_sec; /* seconds */ | 19 | time_t tv_sec; /* seconds */ | 
| @@ -27,93 +27,103 @@ struct timezone { | |||
| 27 | 27 | ||
| 28 | #ifdef __KERNEL__ | 28 | #ifdef __KERNEL__ | 
| 29 | 29 | ||
| 30 | /* Parameters used to convert the timespec values */ | 30 | /* Parameters used to convert the timespec values: */ | 
| 31 | #define MSEC_PER_SEC (1000L) | 31 | #define MSEC_PER_SEC 1000L | 
| 32 | #define USEC_PER_SEC (1000000L) | 32 | #define USEC_PER_SEC 1000000L | 
| 33 | #define NSEC_PER_SEC (1000000000L) | 33 | #define NSEC_PER_SEC 1000000000L | 
| 34 | #define NSEC_PER_USEC (1000L) | 34 | #define NSEC_PER_USEC 1000L | 
| 35 | 35 | ||
| 36 | static __inline__ int timespec_equal(struct timespec *a, struct timespec *b) | 36 | static __inline__ int timespec_equal(struct timespec *a, struct timespec *b) | 
| 37 | { | 37 | { | 
| 38 | return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); | 38 | return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); | 
| 39 | } | 39 | } | 
| 40 | 40 | ||
| 41 | /* Converts Gregorian date to seconds since 1970-01-01 00:00:00. | 41 | extern unsigned long mktime(const unsigned int year, const unsigned int mon, | 
| 42 | * Assumes input in normal date format, i.e. 1980-12-31 23:59:59 | 42 | const unsigned int day, const unsigned int hour, | 
| 43 | * => year=1980, mon=12, day=31, hour=23, min=59, sec=59. | 43 | const unsigned int min, const unsigned int sec); | 
| 44 | * | 44 | |
| 45 | * [For the Julian calendar (which was used in Russia before 1917, | 45 | extern void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec); | 
| 46 | * Britain & colonies before 1752, anywhere else before 1582, | 46 | |
| 47 | * and is still in use by some communities) leave out the | 47 | /* | 
| 48 | * -year/100+year/400 terms, and add 10.] | 48 | * Returns true if the timespec is norm, false if denorm: | 
| 49 | * | ||
| 50 | * This algorithm was first published by Gauss (I think). | ||
| 51 | * | ||
| 52 | * WARNING: this function will overflow on 2106-02-07 06:28:16 on | ||
| 53 | * machines were long is 32-bit! (However, as time_t is signed, we | ||
| 54 | * will already get problems at other places on 2038-01-19 03:14:08) | ||
| 55 | */ | 49 | */ | 
| 56 | static inline unsigned long | 50 | #define timespec_valid(ts) \ | 
| 57 | mktime (unsigned int year, unsigned int mon, | 51 | (((ts)->tv_sec >= 0) && (((unsigned) (ts)->tv_nsec) < NSEC_PER_SEC)) | 
| 58 | unsigned int day, unsigned int hour, | 52 | |
| 59 | unsigned int min, unsigned int sec) | 53 | /* | 
| 60 | { | 54 | * 64-bit nanosec type. Large enough to span 292+ years in nanosecond | 
| 61 | if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */ | 55 | * resolution. Ought to be enough for a while. | 
| 62 | mon += 12; /* Puts Feb last since it has leap day */ | 56 | */ | 
| 63 | year -= 1; | 57 | typedef s64 nsec_t; | 
| 64 | } | ||
| 65 | |||
| 66 | return ((( | ||
| 67 | (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) + | ||
| 68 | year*365 - 719499 | ||
| 69 | )*24 + hour /* now have hours */ | ||
| 70 | )*60 + min /* now have minutes */ | ||
| 71 | )*60 + sec; /* finally seconds */ | ||
| 72 | } | ||
| 73 | 58 | ||
| 74 | extern struct timespec xtime; | 59 | extern struct timespec xtime; | 
| 75 | extern struct timespec wall_to_monotonic; | 60 | extern struct timespec wall_to_monotonic; | 
| 76 | extern seqlock_t xtime_lock; | 61 | extern seqlock_t xtime_lock; | 
| 77 | 62 | ||
| 78 | static inline unsigned long get_seconds(void) | 63 | static inline unsigned long get_seconds(void) | 
| 79 | { | 64 | { | 
| 80 | return xtime.tv_sec; | 65 | return xtime.tv_sec; | 
| 81 | } | 66 | } | 
| 82 | 67 | ||
| 83 | struct timespec current_kernel_time(void); | 68 | struct timespec current_kernel_time(void); | 
| 84 | 69 | ||
| 85 | #define CURRENT_TIME (current_kernel_time()) | 70 | #define CURRENT_TIME (current_kernel_time()) | 
| 86 | #define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 }) | 71 | #define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 }) | 
| 87 | 72 | ||
| 88 | extern void do_gettimeofday(struct timeval *tv); | 73 | extern void do_gettimeofday(struct timeval *tv); | 
| 89 | extern int do_settimeofday(struct timespec *tv); | 74 | extern int do_settimeofday(struct timespec *tv); | 
| 90 | extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz); | 75 | extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz); | 
| 91 | extern void clock_was_set(void); // call when ever the clock is set | 76 | #define do_posix_clock_monotonic_gettime(ts) ktime_get_ts(ts) | 
| 92 | extern int do_posix_clock_monotonic_gettime(struct timespec *tp); | 77 | extern long do_utimes(int dfd, char __user *filename, struct timeval *times); | 
| 93 | extern long do_utimes(char __user * filename, struct timeval * times); | ||
| 94 | struct itimerval; | 78 | struct itimerval; | 
| 95 | extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue); | 79 | extern int do_setitimer(int which, struct itimerval *value, | 
| 80 | struct itimerval *ovalue); | ||
| 96 | extern int do_getitimer(int which, struct itimerval *value); | 81 | extern int do_getitimer(int which, struct itimerval *value); | 
| 97 | extern void getnstimeofday (struct timespec *tv); | 82 | extern void getnstimeofday(struct timespec *tv); | 
| 98 | extern void getnstimestamp(struct timespec *ts); | ||
| 99 | 83 | ||
| 100 | extern struct timespec timespec_trunc(struct timespec t, unsigned gran); | 84 | extern struct timespec timespec_trunc(struct timespec t, unsigned gran); | 
| 101 | 85 | ||
| 102 | static inline void | 86 | /** | 
| 103 | set_normalized_timespec (struct timespec *ts, time_t sec, long nsec) | 87 | * timespec_to_ns - Convert timespec to nanoseconds | 
| 88 | * @ts: pointer to the timespec variable to be converted | ||
| 89 | * | ||
| 90 | * Returns the scalar nanosecond representation of the timespec | ||
| 91 | * parameter. | ||
| 92 | */ | ||
| 93 | static inline nsec_t timespec_to_ns(const struct timespec *ts) | ||
| 104 | { | 94 | { | 
| 105 | while (nsec >= NSEC_PER_SEC) { | 95 | return ((nsec_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; | 
| 106 | nsec -= NSEC_PER_SEC; | ||
| 107 | ++sec; | ||
| 108 | } | ||
| 109 | while (nsec < 0) { | ||
| 110 | nsec += NSEC_PER_SEC; | ||
| 111 | --sec; | ||
| 112 | } | ||
| 113 | ts->tv_sec = sec; | ||
| 114 | ts->tv_nsec = nsec; | ||
| 115 | } | 96 | } | 
| 116 | 97 | ||
| 98 | /** | ||
| 99 | * timeval_to_ns - Convert timeval to nanoseconds | ||
| 100 | * @ts: pointer to the timeval variable to be converted | ||
| 101 | * | ||
| 102 | * Returns the scalar nanosecond representation of the timeval | ||
| 103 | * parameter. | ||
| 104 | */ | ||
| 105 | static inline nsec_t timeval_to_ns(const struct timeval *tv) | ||
| 106 | { | ||
| 107 | return ((nsec_t) tv->tv_sec * NSEC_PER_SEC) + | ||
| 108 | tv->tv_usec * NSEC_PER_USEC; | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * ns_to_timespec - Convert nanoseconds to timespec | ||
| 113 | * @nsec: the nanoseconds value to be converted | ||
| 114 | * | ||
| 115 | * Returns the timespec representation of the nsec parameter. | ||
| 116 | */ | ||
| 117 | extern struct timespec ns_to_timespec(const nsec_t nsec); | ||
| 118 | |||
| 119 | /** | ||
| 120 | * ns_to_timeval - Convert nanoseconds to timeval | ||
| 121 | * @nsec: the nanoseconds value to be converted | ||
| 122 | * | ||
| 123 | * Returns the timeval representation of the nsec parameter. | ||
| 124 | */ | ||
| 125 | extern struct timeval ns_to_timeval(const nsec_t nsec); | ||
| 126 | |||
| 117 | #endif /* __KERNEL__ */ | 127 | #endif /* __KERNEL__ */ | 
| 118 | 128 | ||
| 119 | #define NFDBITS __NFDBITS | 129 | #define NFDBITS __NFDBITS | 
| @@ -126,49 +136,41 @@ set_normalized_timespec (struct timespec *ts, time_t sec, long nsec) | |||
| 126 | 136 | ||
| 127 | /* | 137 | /* | 
| 128 | * Names of the interval timers, and structure | 138 | * Names of the interval timers, and structure | 
| 129 | * defining a timer setting. | 139 | * defining a timer setting: | 
| 130 | */ | 140 | */ | 
| 131 | #define ITIMER_REAL 0 | 141 | #define ITIMER_REAL 0 | 
| 132 | #define ITIMER_VIRTUAL 1 | 142 | #define ITIMER_VIRTUAL 1 | 
| 133 | #define ITIMER_PROF 2 | 143 | #define ITIMER_PROF 2 | 
| 134 | 144 | ||
| 135 | struct itimerspec { | 145 | struct itimerspec { | 
| 136 | struct timespec it_interval; /* timer period */ | 146 | struct timespec it_interval; /* timer period */ | 
| 137 | struct timespec it_value; /* timer expiration */ | 147 | struct timespec it_value; /* timer expiration */ | 
| 138 | }; | 148 | }; | 
| 139 | 149 | ||
| 140 | struct itimerval { | 150 | struct itimerval { | 
| 141 | struct timeval it_interval; /* timer interval */ | 151 | struct timeval it_interval; /* timer interval */ | 
| 142 | struct timeval it_value; /* current value */ | 152 | struct timeval it_value; /* current value */ | 
| 143 | }; | 153 | }; | 
| 144 | 154 | ||
| 145 | |||
| 146 | /* | 155 | /* | 
| 147 | * The IDs of the various system clocks (for POSIX.1b interval timers). | 156 | * The IDs of the various system clocks (for POSIX.1b interval timers): | 
| 148 | */ | 157 | */ | 
| 149 | #define CLOCK_REALTIME 0 | 158 | #define CLOCK_REALTIME 0 | 
| 150 | #define CLOCK_MONOTONIC 1 | 159 | #define CLOCK_MONOTONIC 1 | 
| 151 | #define CLOCK_PROCESS_CPUTIME_ID 2 | 160 | #define CLOCK_PROCESS_CPUTIME_ID 2 | 
| 152 | #define CLOCK_THREAD_CPUTIME_ID 3 | 161 | #define CLOCK_THREAD_CPUTIME_ID 3 | 
| 153 | #define CLOCK_REALTIME_HR 4 | ||
| 154 | #define CLOCK_MONOTONIC_HR 5 | ||
| 155 | 162 | ||
| 156 | /* | 163 | /* | 
| 157 | * The IDs of various hardware clocks | 164 | * The IDs of various hardware clocks: | 
| 158 | */ | 165 | */ | 
| 159 | 166 | #define CLOCK_SGI_CYCLE 10 | |
| 160 | 167 | #define MAX_CLOCKS 16 | |
| 161 | #define CLOCK_SGI_CYCLE 10 | 168 | #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) | 
| 162 | #define MAX_CLOCKS 16 | 169 | #define CLOCKS_MONO CLOCK_MONOTONIC | 
| 163 | #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC | \ | ||
| 164 | CLOCK_REALTIME_HR | CLOCK_MONOTONIC_HR) | ||
| 165 | #define CLOCKS_MONO (CLOCK_MONOTONIC & CLOCK_MONOTONIC_HR) | ||
| 166 | 170 | ||
| 167 | /* | 171 | /* | 
| 168 | * The various flags for setting POSIX.1b interval timers. | 172 | * The various flags for setting POSIX.1b interval timers: | 
| 169 | */ | 173 | */ | 
| 170 | 174 | #define TIMER_ABSTIME 0x01 | |
| 171 | #define TIMER_ABSTIME 0x01 | ||
| 172 | |||
| 173 | 175 | ||
| 174 | #endif | 176 | #endif | 
