diff options
Diffstat (limited to 'include/linux/time.h')
-rw-r--r-- | include/linux/time.h | 185 |
1 files changed, 94 insertions, 91 deletions
diff --git a/include/linux/time.h b/include/linux/time.h index bfbe92d0767c..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,92 +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 | 83 | ||
99 | extern struct timespec timespec_trunc(struct timespec t, unsigned gran); | 84 | extern struct timespec timespec_trunc(struct timespec t, unsigned gran); |
100 | 85 | ||
101 | static inline void | 86 | /** |
102 | 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) | ||
103 | { | 94 | { |
104 | while (nsec >= NSEC_PER_SEC) { | 95 | return ((nsec_t) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; |
105 | nsec -= NSEC_PER_SEC; | ||
106 | ++sec; | ||
107 | } | ||
108 | while (nsec < 0) { | ||
109 | nsec += NSEC_PER_SEC; | ||
110 | --sec; | ||
111 | } | ||
112 | ts->tv_sec = sec; | ||
113 | ts->tv_nsec = nsec; | ||
114 | } | 96 | } |
115 | 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 | |||
116 | #endif /* __KERNEL__ */ | 127 | #endif /* __KERNEL__ */ |
117 | 128 | ||
118 | #define NFDBITS __NFDBITS | 129 | #define NFDBITS __NFDBITS |
@@ -125,49 +136,41 @@ set_normalized_timespec (struct timespec *ts, time_t sec, long nsec) | |||
125 | 136 | ||
126 | /* | 137 | /* |
127 | * Names of the interval timers, and structure | 138 | * Names of the interval timers, and structure |
128 | * defining a timer setting. | 139 | * defining a timer setting: |
129 | */ | 140 | */ |
130 | #define ITIMER_REAL 0 | 141 | #define ITIMER_REAL 0 |
131 | #define ITIMER_VIRTUAL 1 | 142 | #define ITIMER_VIRTUAL 1 |
132 | #define ITIMER_PROF 2 | 143 | #define ITIMER_PROF 2 |
133 | 144 | ||
134 | struct itimerspec { | 145 | struct itimerspec { |
135 | struct timespec it_interval; /* timer period */ | 146 | struct timespec it_interval; /* timer period */ |
136 | struct timespec it_value; /* timer expiration */ | 147 | struct timespec it_value; /* timer expiration */ |
137 | }; | 148 | }; |
138 | 149 | ||
139 | struct itimerval { | 150 | struct itimerval { |
140 | struct timeval it_interval; /* timer interval */ | 151 | struct timeval it_interval; /* timer interval */ |
141 | struct timeval it_value; /* current value */ | 152 | struct timeval it_value; /* current value */ |
142 | }; | 153 | }; |
143 | 154 | ||
144 | |||
145 | /* | 155 | /* |
146 | * 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): |
147 | */ | 157 | */ |
148 | #define CLOCK_REALTIME 0 | 158 | #define CLOCK_REALTIME 0 |
149 | #define CLOCK_MONOTONIC 1 | 159 | #define CLOCK_MONOTONIC 1 |
150 | #define CLOCK_PROCESS_CPUTIME_ID 2 | 160 | #define CLOCK_PROCESS_CPUTIME_ID 2 |
151 | #define CLOCK_THREAD_CPUTIME_ID 3 | 161 | #define CLOCK_THREAD_CPUTIME_ID 3 |
152 | #define CLOCK_REALTIME_HR 4 | ||
153 | #define CLOCK_MONOTONIC_HR 5 | ||
154 | 162 | ||
155 | /* | 163 | /* |
156 | * The IDs of various hardware clocks | 164 | * The IDs of various hardware clocks: |
157 | */ | 165 | */ |
158 | 166 | #define CLOCK_SGI_CYCLE 10 | |
159 | 167 | #define MAX_CLOCKS 16 | |
160 | #define CLOCK_SGI_CYCLE 10 | 168 | #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) |
161 | #define MAX_CLOCKS 16 | 169 | #define CLOCKS_MONO CLOCK_MONOTONIC |
162 | #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC | \ | ||
163 | CLOCK_REALTIME_HR | CLOCK_MONOTONIC_HR) | ||
164 | #define CLOCKS_MONO (CLOCK_MONOTONIC & CLOCK_MONOTONIC_HR) | ||
165 | 170 | ||
166 | /* | 171 | /* |
167 | * The various flags for setting POSIX.1b interval timers. | 172 | * The various flags for setting POSIX.1b interval timers: |
168 | */ | 173 | */ |
169 | 174 | #define TIMER_ABSTIME 0x01 | |
170 | #define TIMER_ABSTIME 0x01 | ||
171 | |||
172 | 175 | ||
173 | #endif | 176 | #endif |