This source file includes following definitions.
- get_jiffies_64
- jiffies_to_nsecs
- _msecs_to_jiffies
- _msecs_to_jiffies
- _msecs_to_jiffies
- msecs_to_jiffies
- _usecs_to_jiffies
- _usecs_to_jiffies
- usecs_to_jiffies
- timespec_to_jiffies
- jiffies_to_timespec
- jiffies_delta_to_clock_t
- jiffies_delta_to_msecs
1
2 #ifndef _LINUX_JIFFIES_H
3 #define _LINUX_JIFFIES_H
4
5 #include <linux/cache.h>
6 #include <linux/math64.h>
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/time.h>
10 #include <linux/timex.h>
11 #include <asm/param.h>
12 #include <generated/timeconst.h>
13
14
15
16
17
18
19
20
21 #if HZ >= 12 && HZ < 24
22 # define SHIFT_HZ 4
23 #elif HZ >= 24 && HZ < 48
24 # define SHIFT_HZ 5
25 #elif HZ >= 48 && HZ < 96
26 # define SHIFT_HZ 6
27 #elif HZ >= 96 && HZ < 192
28 # define SHIFT_HZ 7
29 #elif HZ >= 192 && HZ < 384
30 # define SHIFT_HZ 8
31 #elif HZ >= 384 && HZ < 768
32 # define SHIFT_HZ 9
33 #elif HZ >= 768 && HZ < 1536
34 # define SHIFT_HZ 10
35 #elif HZ >= 1536 && HZ < 3072
36 # define SHIFT_HZ 11
37 #elif HZ >= 3072 && HZ < 6144
38 # define SHIFT_HZ 12
39 #elif HZ >= 6144 && HZ < 12288
40 # define SHIFT_HZ 13
41 #else
42 # error Invalid value of HZ.
43 #endif
44
45
46
47
48
49
50
51
52
53
54 #define SH_DIV(NOM,DEN,LSH) ( (((NOM) / (DEN)) << (LSH)) \
55 + ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))
56
57
58 #define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)
59
60 extern int register_refined_jiffies(long clock_tick_rate);
61
62
63 #define TICK_NSEC ((NSEC_PER_SEC+HZ/2)/HZ)
64
65
66 #define TICK_USEC ((USEC_PER_SEC + HZ/2) / HZ)
67
68
69 #define USER_TICK_USEC ((1000000UL + USER_HZ/2) / USER_HZ)
70
71 #ifndef __jiffy_arch_data
72 #define __jiffy_arch_data
73 #endif
74
75
76
77
78
79
80 extern u64 __cacheline_aligned_in_smp jiffies_64;
81 extern unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies;
82
83 #if (BITS_PER_LONG < 64)
84 u64 get_jiffies_64(void);
85 #else
86 static inline u64 get_jiffies_64(void)
87 {
88 return (u64)jiffies;
89 }
90 #endif
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 #define time_after(a,b) \
106 (typecheck(unsigned long, a) && \
107 typecheck(unsigned long, b) && \
108 ((long)((b) - (a)) < 0))
109 #define time_before(a,b) time_after(b,a)
110
111 #define time_after_eq(a,b) \
112 (typecheck(unsigned long, a) && \
113 typecheck(unsigned long, b) && \
114 ((long)((a) - (b)) >= 0))
115 #define time_before_eq(a,b) time_after_eq(b,a)
116
117
118
119
120 #define time_in_range(a,b,c) \
121 (time_after_eq(a,b) && \
122 time_before_eq(a,c))
123
124
125
126
127 #define time_in_range_open(a,b,c) \
128 (time_after_eq(a,b) && \
129 time_before(a,c))
130
131
132
133
134 #define time_after64(a,b) \
135 (typecheck(__u64, a) && \
136 typecheck(__u64, b) && \
137 ((__s64)((b) - (a)) < 0))
138 #define time_before64(a,b) time_after64(b,a)
139
140 #define time_after_eq64(a,b) \
141 (typecheck(__u64, a) && \
142 typecheck(__u64, b) && \
143 ((__s64)((a) - (b)) >= 0))
144 #define time_before_eq64(a,b) time_after_eq64(b,a)
145
146 #define time_in_range64(a, b, c) \
147 (time_after_eq64(a, b) && \
148 time_before_eq64(a, c))
149
150
151
152
153
154
155 #define time_is_before_jiffies(a) time_after(jiffies, a)
156 #define time_is_before_jiffies64(a) time_after64(get_jiffies_64(), a)
157
158
159 #define time_is_after_jiffies(a) time_before(jiffies, a)
160 #define time_is_after_jiffies64(a) time_before64(get_jiffies_64(), a)
161
162
163 #define time_is_before_eq_jiffies(a) time_after_eq(jiffies, a)
164 #define time_is_before_eq_jiffies64(a) time_after_eq64(get_jiffies_64(), a)
165
166
167 #define time_is_after_eq_jiffies(a) time_before_eq(jiffies, a)
168 #define time_is_after_eq_jiffies64(a) time_before_eq64(get_jiffies_64(), a)
169
170
171
172
173
174 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
175
176
177
178
179
180
181
182
183
184
185
186
187
188 #define MAX_JIFFY_OFFSET ((LONG_MAX >> 1)-1)
189
190 extern unsigned long preset_lpj;
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263 #define SEC_JIFFIE_SC (31 - SHIFT_HZ)
264 #if !((((NSEC_PER_SEC << 2) / TICK_NSEC) << (SEC_JIFFIE_SC - 2)) & 0x80000000)
265 #undef SEC_JIFFIE_SC
266 #define SEC_JIFFIE_SC (32 - SHIFT_HZ)
267 #endif
268 #define NSEC_JIFFIE_SC (SEC_JIFFIE_SC + 29)
269 #define SEC_CONVERSION ((unsigned long)((((u64)NSEC_PER_SEC << SEC_JIFFIE_SC) +\
270 TICK_NSEC -1) / (u64)TICK_NSEC))
271
272 #define NSEC_CONVERSION ((unsigned long)((((u64)1 << NSEC_JIFFIE_SC) +\
273 TICK_NSEC -1) / (u64)TICK_NSEC))
274
275
276
277
278
279 #if BITS_PER_LONG < 64
280 # define MAX_SEC_IN_JIFFIES \
281 (long)((u64)((u64)MAX_JIFFY_OFFSET * TICK_NSEC) / NSEC_PER_SEC)
282 #else
283 # define MAX_SEC_IN_JIFFIES \
284 (SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 1) - 1)
285
286 #endif
287
288
289
290
291 extern unsigned int jiffies_to_msecs(const unsigned long j);
292 extern unsigned int jiffies_to_usecs(const unsigned long j);
293
294 static inline u64 jiffies_to_nsecs(const unsigned long j)
295 {
296 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
297 }
298
299 extern u64 jiffies64_to_nsecs(u64 j);
300 extern u64 jiffies64_to_msecs(u64 j);
301
302 extern unsigned long __msecs_to_jiffies(const unsigned int m);
303 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
304
305
306
307
308
309 static inline unsigned long _msecs_to_jiffies(const unsigned int m)
310 {
311 return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
312 }
313 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
314
315
316
317
318
319
320 static inline unsigned long _msecs_to_jiffies(const unsigned int m)
321 {
322 if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
323 return MAX_JIFFY_OFFSET;
324 return m * (HZ / MSEC_PER_SEC);
325 }
326 #else
327
328
329
330
331 static inline unsigned long _msecs_to_jiffies(const unsigned int m)
332 {
333 if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
334 return MAX_JIFFY_OFFSET;
335
336 return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) >> MSEC_TO_HZ_SHR32;
337 }
338 #endif
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364 static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)
365 {
366 if (__builtin_constant_p(m)) {
367 if ((int)m < 0)
368 return MAX_JIFFY_OFFSET;
369 return _msecs_to_jiffies(m);
370 } else {
371 return __msecs_to_jiffies(m);
372 }
373 }
374
375 extern unsigned long __usecs_to_jiffies(const unsigned int u);
376 #if !(USEC_PER_SEC % HZ)
377 static inline unsigned long _usecs_to_jiffies(const unsigned int u)
378 {
379 return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);
380 }
381 #else
382 static inline unsigned long _usecs_to_jiffies(const unsigned int u)
383 {
384 return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
385 >> USEC_TO_HZ_SHR32;
386 }
387 #endif
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411 static __always_inline unsigned long usecs_to_jiffies(const unsigned int u)
412 {
413 if (__builtin_constant_p(u)) {
414 if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
415 return MAX_JIFFY_OFFSET;
416 return _usecs_to_jiffies(u);
417 } else {
418 return __usecs_to_jiffies(u);
419 }
420 }
421
422 extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);
423 extern void jiffies_to_timespec64(const unsigned long jiffies,
424 struct timespec64 *value);
425 static inline unsigned long timespec_to_jiffies(const struct timespec *value)
426 {
427 struct timespec64 ts = timespec_to_timespec64(*value);
428
429 return timespec64_to_jiffies(&ts);
430 }
431
432 static inline void jiffies_to_timespec(const unsigned long jiffies,
433 struct timespec *value)
434 {
435 struct timespec64 ts;
436
437 jiffies_to_timespec64(jiffies, &ts);
438 *value = timespec64_to_timespec(ts);
439 }
440
441 extern unsigned long timeval_to_jiffies(const struct timeval *value);
442 extern void jiffies_to_timeval(const unsigned long jiffies,
443 struct timeval *value);
444
445 extern clock_t jiffies_to_clock_t(unsigned long x);
446 static inline clock_t jiffies_delta_to_clock_t(long delta)
447 {
448 return jiffies_to_clock_t(max(0L, delta));
449 }
450
451 static inline unsigned int jiffies_delta_to_msecs(long delta)
452 {
453 return jiffies_to_msecs(max(0L, delta));
454 }
455
456 extern unsigned long clock_t_to_jiffies(unsigned long x);
457 extern u64 jiffies_64_to_clock_t(u64 x);
458 extern u64 nsec_to_clock_t(u64 x);
459 extern u64 nsecs_to_jiffies64(u64 n);
460 extern unsigned long nsecs_to_jiffies(u64 n);
461
462 #define TIMESTAMP_SIZE 30
463
464 #endif