Rev 5270 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5270 | Rev 6082 | ||
---|---|---|---|
1 | #ifndef _LINUX_TIME64_H |
1 | #ifndef _LINUX_TIME64_H |
2 | #define _LINUX_TIME64_H |
2 | #define _LINUX_TIME64_H |
3 | 3 | ||
4 | #include |
4 | #include |
- | 5 | #include |
|
5 | 6 | ||
6 | typedef __s64 time64_t; |
7 | typedef __s64 time64_t; |
7 | 8 | ||
8 | /* |
9 | /* |
9 | * This wants to go into uapi/linux/time.h once we agreed about the |
10 | * This wants to go into uapi/linux/time.h once we agreed about the |
10 | * userspace interfaces. |
11 | * userspace interfaces. |
11 | */ |
12 | */ |
12 | #if __BITS_PER_LONG == 64 |
13 | #if __BITS_PER_LONG == 64 |
13 | # define timespec64 timespec |
14 | # define timespec64 timespec |
- | 15 | #define itimerspec64 itimerspec |
|
14 | #else |
16 | #else |
15 | struct timespec64 { |
17 | struct timespec64 { |
16 | time64_t tv_sec; /* seconds */ |
18 | time64_t tv_sec; /* seconds */ |
17 | long tv_nsec; /* nanoseconds */ |
19 | long tv_nsec; /* nanoseconds */ |
18 | }; |
20 | }; |
- | 21 | ||
- | 22 | struct itimerspec64 { |
|
- | 23 | struct timespec64 it_interval; |
|
- | 24 | struct timespec64 it_value; |
|
- | 25 | }; |
|
- | 26 | ||
19 | #endif |
27 | #endif |
20 | 28 | ||
21 | /* Parameters used to convert the timespec values: */ |
29 | /* Parameters used to convert the timespec values: */ |
22 | #define MSEC_PER_SEC 1000L |
30 | #define MSEC_PER_SEC 1000L |
23 | #define USEC_PER_MSEC 1000L |
31 | #define USEC_PER_MSEC 1000L |
24 | #define NSEC_PER_USEC 1000L |
32 | #define NSEC_PER_USEC 1000L |
25 | #define NSEC_PER_MSEC 1000000L |
33 | #define NSEC_PER_MSEC 1000000L |
26 | #define USEC_PER_SEC 1000000L |
34 | #define USEC_PER_SEC 1000000L |
27 | #define NSEC_PER_SEC 1000000000L |
35 | #define NSEC_PER_SEC 1000000000L |
28 | #define FSEC_PER_SEC 1000000000000000LL |
36 | #define FSEC_PER_SEC 1000000000000000LL |
29 | 37 | ||
30 | /* Located here for timespec[64]_valid_strict */ |
38 | /* Located here for timespec[64]_valid_strict */ |
- | 39 | #define TIME64_MAX ((s64)~((u64)1 << 63)) |
|
31 | #define KTIME_MAX ((s64)~((u64)1 << 63)) |
40 | #define KTIME_MAX ((s64)~((u64)1 << 63)) |
32 | #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) |
41 | #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) |
33 | 42 | ||
34 | #if __BITS_PER_LONG == 64 |
43 | #if __BITS_PER_LONG == 64 |
35 | 44 | ||
36 | static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) |
45 | static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) |
37 | { |
46 | { |
38 | return ts64; |
47 | return ts64; |
39 | } |
48 | } |
40 | 49 | ||
41 | static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) |
50 | static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) |
42 | { |
51 | { |
43 | return ts; |
52 | return ts; |
44 | } |
53 | } |
- | 54 | ||
- | 55 | static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64) |
|
- | 56 | { |
|
- | 57 | return *its64; |
|
- | 58 | } |
|
- | 59 | ||
- | 60 | static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its) |
|
- | 61 | { |
|
- | 62 | return *its; |
|
- | 63 | } |
|
45 | 64 | ||
46 | # define timespec64_equal timespec_equal |
65 | # define timespec64_equal timespec_equal |
47 | # define timespec64_compare timespec_compare |
66 | # define timespec64_compare timespec_compare |
48 | # define set_normalized_timespec64 set_normalized_timespec |
67 | # define set_normalized_timespec64 set_normalized_timespec |
49 | # define timespec64_add_safe timespec_add_safe |
68 | # define timespec64_add_safe timespec_add_safe |
50 | # define timespec64_add timespec_add |
69 | # define timespec64_add timespec_add |
51 | # define timespec64_sub timespec_sub |
70 | # define timespec64_sub timespec_sub |
52 | # define timespec64_valid timespec_valid |
71 | # define timespec64_valid timespec_valid |
53 | # define timespec64_valid_strict timespec_valid_strict |
72 | # define timespec64_valid_strict timespec_valid_strict |
54 | # define timespec64_to_ns timespec_to_ns |
73 | # define timespec64_to_ns timespec_to_ns |
55 | # define ns_to_timespec64 ns_to_timespec |
74 | # define ns_to_timespec64 ns_to_timespec |
56 | # define timespec64_add_ns timespec_add_ns |
75 | # define timespec64_add_ns timespec_add_ns |
57 | 76 | ||
58 | #else |
77 | #else |
59 | 78 | ||
60 | static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) |
79 | static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) |
61 | { |
80 | { |
62 | struct timespec ret; |
81 | struct timespec ret; |
63 | 82 | ||
64 | ret.tv_sec = (time_t)ts64.tv_sec; |
83 | ret.tv_sec = (time_t)ts64.tv_sec; |
65 | ret.tv_nsec = ts64.tv_nsec; |
84 | ret.tv_nsec = ts64.tv_nsec; |
66 | return ret; |
85 | return ret; |
67 | } |
86 | } |
68 | 87 | ||
69 | static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) |
88 | static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) |
70 | { |
89 | { |
71 | struct timespec64 ret; |
90 | struct timespec64 ret; |
72 | 91 | ||
73 | ret.tv_sec = ts.tv_sec; |
92 | ret.tv_sec = ts.tv_sec; |
74 | ret.tv_nsec = ts.tv_nsec; |
93 | ret.tv_nsec = ts.tv_nsec; |
75 | return ret; |
94 | return ret; |
- | 95 | } |
|
- | 96 | ||
- | 97 | static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64) |
|
- | 98 | { |
|
- | 99 | struct itimerspec ret; |
|
- | 100 | ||
- | 101 | ret.it_interval = timespec64_to_timespec(its64->it_interval); |
|
- | 102 | ret.it_value = timespec64_to_timespec(its64->it_value); |
|
- | 103 | return ret; |
|
- | 104 | } |
|
- | 105 | ||
- | 106 | static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its) |
|
- | 107 | { |
|
- | 108 | struct itimerspec64 ret; |
|
- | 109 | ||
- | 110 | ret.it_interval = timespec_to_timespec64(its->it_interval); |
|
- | 111 | ret.it_value = timespec_to_timespec64(its->it_value); |
|
- | 112 | return ret; |
|
76 | } |
113 | } |
77 | 114 | ||
78 | static inline int timespec64_equal(const struct timespec64 *a, |
115 | static inline int timespec64_equal(const struct timespec64 *a, |
79 | const struct timespec64 *b) |
116 | const struct timespec64 *b) |
80 | { |
117 | { |
81 | return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); |
118 | return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); |
82 | } |
119 | } |
83 | 120 | ||
84 | /* |
121 | /* |
85 | * lhs < rhs: return <0 |
122 | * lhs < rhs: return <0 |
86 | * lhs == rhs: return 0 |
123 | * lhs == rhs: return 0 |
87 | * lhs > rhs: return >0 |
124 | * lhs > rhs: return >0 |
88 | */ |
125 | */ |
89 | static inline int timespec64_compare(const struct timespec64 *lhs, const struct timespec64 *rhs) |
126 | static inline int timespec64_compare(const struct timespec64 *lhs, const struct timespec64 *rhs) |
90 | { |
127 | { |
91 | if (lhs->tv_sec < rhs->tv_sec) |
128 | if (lhs->tv_sec < rhs->tv_sec) |
92 | return -1; |
129 | return -1; |
93 | if (lhs->tv_sec > rhs->tv_sec) |
130 | if (lhs->tv_sec > rhs->tv_sec) |
94 | return 1; |
131 | return 1; |
95 | return lhs->tv_nsec - rhs->tv_nsec; |
132 | return lhs->tv_nsec - rhs->tv_nsec; |
96 | } |
133 | } |
97 | 134 | ||
98 | extern void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 nsec); |
135 | extern void set_normalized_timespec64(struct timespec64 *ts, time64_t sec, s64 nsec); |
99 | 136 | ||
100 | /* |
137 | /* |
101 | * timespec64_add_safe assumes both values are positive and checks for |
138 | * timespec64_add_safe assumes both values are positive and checks for |
102 | * overflow. It will return TIME_T_MAX if the returned value would be |
139 | * overflow. It will return TIME_T_MAX if the returned value would be |
103 | * smaller then either of the arguments. |
140 | * smaller then either of the arguments. |
104 | */ |
141 | */ |
105 | extern struct timespec64 timespec64_add_safe(const struct timespec64 lhs, |
142 | extern struct timespec64 timespec64_add_safe(const struct timespec64 lhs, |
106 | const struct timespec64 rhs); |
143 | const struct timespec64 rhs); |
107 | 144 | ||
108 | 145 | ||
109 | static inline struct timespec64 timespec64_add(struct timespec64 lhs, |
146 | static inline struct timespec64 timespec64_add(struct timespec64 lhs, |
110 | struct timespec64 rhs) |
147 | struct timespec64 rhs) |
111 | { |
148 | { |
112 | struct timespec64 ts_delta; |
149 | struct timespec64 ts_delta; |
113 | set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec, |
150 | set_normalized_timespec64(&ts_delta, lhs.tv_sec + rhs.tv_sec, |
114 | lhs.tv_nsec + rhs.tv_nsec); |
151 | lhs.tv_nsec + rhs.tv_nsec); |
115 | return ts_delta; |
152 | return ts_delta; |
116 | } |
153 | } |
117 | 154 | ||
118 | /* |
155 | /* |
119 | * sub = lhs - rhs, in normalized form |
156 | * sub = lhs - rhs, in normalized form |
120 | */ |
157 | */ |
121 | static inline struct timespec64 timespec64_sub(struct timespec64 lhs, |
158 | static inline struct timespec64 timespec64_sub(struct timespec64 lhs, |
122 | struct timespec64 rhs) |
159 | struct timespec64 rhs) |
123 | { |
160 | { |
124 | struct timespec64 ts_delta; |
161 | struct timespec64 ts_delta; |
125 | set_normalized_timespec64(&ts_delta, lhs.tv_sec - rhs.tv_sec, |
162 | set_normalized_timespec64(&ts_delta, lhs.tv_sec - rhs.tv_sec, |
126 | lhs.tv_nsec - rhs.tv_nsec); |
163 | lhs.tv_nsec - rhs.tv_nsec); |
127 | return ts_delta; |
164 | return ts_delta; |
128 | } |
165 | } |
129 | 166 | ||
130 | /* |
167 | /* |
131 | * Returns true if the timespec64 is norm, false if denorm: |
168 | * Returns true if the timespec64 is norm, false if denorm: |
132 | */ |
169 | */ |
133 | static inline bool timespec64_valid(const struct timespec64 *ts) |
170 | static inline bool timespec64_valid(const struct timespec64 *ts) |
134 | { |
171 | { |
135 | /* Dates before 1970 are bogus */ |
172 | /* Dates before 1970 are bogus */ |
136 | if (ts->tv_sec < 0) |
173 | if (ts->tv_sec < 0) |
137 | return false; |
174 | return false; |
138 | /* Can't have more nanoseconds then a second */ |
175 | /* Can't have more nanoseconds then a second */ |
139 | if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) |
176 | if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) |
140 | return false; |
177 | return false; |
141 | return true; |
178 | return true; |
142 | } |
179 | } |
143 | 180 | ||
144 | static inline bool timespec64_valid_strict(const struct timespec64 *ts) |
181 | static inline bool timespec64_valid_strict(const struct timespec64 *ts) |
145 | { |
182 | { |
146 | if (!timespec64_valid(ts)) |
183 | if (!timespec64_valid(ts)) |
147 | return false; |
184 | return false; |
148 | /* Disallow values that could overflow ktime_t */ |
185 | /* Disallow values that could overflow ktime_t */ |
149 | if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) |
186 | if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) |
150 | return false; |
187 | return false; |
151 | return true; |
188 | return true; |
152 | } |
189 | } |
153 | 190 | ||
154 | /** |
191 | /** |
155 | * timespec64_to_ns - Convert timespec64 to nanoseconds |
192 | * timespec64_to_ns - Convert timespec64 to nanoseconds |
156 | * @ts: pointer to the timespec64 variable to be converted |
193 | * @ts: pointer to the timespec64 variable to be converted |
157 | * |
194 | * |
158 | * Returns the scalar nanosecond representation of the timespec64 |
195 | * Returns the scalar nanosecond representation of the timespec64 |
159 | * parameter. |
196 | * parameter. |
160 | */ |
197 | */ |
161 | static inline s64 timespec64_to_ns(const struct timespec64 *ts) |
198 | static inline s64 timespec64_to_ns(const struct timespec64 *ts) |
162 | { |
199 | { |
163 | return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; |
200 | return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; |
164 | } |
201 | } |
165 | 202 | ||
166 | /** |
203 | /** |
167 | * ns_to_timespec64 - Convert nanoseconds to timespec64 |
204 | * ns_to_timespec64 - Convert nanoseconds to timespec64 |
168 | * @nsec: the nanoseconds value to be converted |
205 | * @nsec: the nanoseconds value to be converted |
169 | * |
206 | * |
170 | * Returns the timespec64 representation of the nsec parameter. |
207 | * Returns the timespec64 representation of the nsec parameter. |
171 | */ |
208 | */ |
172 | extern struct timespec64 ns_to_timespec64(const s64 nsec); |
209 | extern struct timespec64 ns_to_timespec64(const s64 nsec); |
173 | 210 | ||
174 | /** |
211 | /** |
175 | * timespec64_add_ns - Adds nanoseconds to a timespec64 |
212 | * timespec64_add_ns - Adds nanoseconds to a timespec64 |
176 | * @a: pointer to timespec64 to be incremented |
213 | * @a: pointer to timespec64 to be incremented |
177 | * @ns: unsigned nanoseconds value to be added |
214 | * @ns: unsigned nanoseconds value to be added |
178 | * |
215 | * |
179 | * This must always be inlined because its used from the x86-64 vdso, |
216 | * This must always be inlined because its used from the x86-64 vdso, |
180 | * which cannot call other kernel functions. |
217 | * which cannot call other kernel functions. |
181 | */ |
218 | */ |
182 | static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns) |
219 | static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns) |
183 | { |
220 | { |
184 | a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); |
221 | a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); |
185 | a->tv_nsec = ns; |
222 | a->tv_nsec = ns; |
186 | } |
223 | } |
187 | 224 | ||
188 | #endif |
225 | #endif |
189 | 226 | ||
190 | #endif /* _LINUX_TIME64_H */>>0 |
227 | #endif /* _LINUX_TIME64_H */>>0 |
191 | >>><> |
228 | >>><>><> |