@@ -72,102 +72,246 @@ extern int register_refined_jiffies(long clock_tick_rate);
72
72
#endif
73
73
74
74
/*
75
- * The 64-bit value is not atomic - you MUST NOT read it
75
+ * The 64-bit value is not atomic on 32-bit systems - you MUST NOT read it
76
76
* without sampling the sequence number in jiffies_lock.
77
77
* get_jiffies_64() will do this for you as appropriate.
78
+ *
79
+ * jiffies and jiffies_64 are at the same address for little-endian systems
80
+ * and for 64-bit big-endian systems.
81
+ * On 32-bit big-endian systems, jiffies is the lower 32 bits of jiffies_64
82
+ * (i.e., at address @jiffies_64 + 4).
83
+ * See arch/ARCH/kernel/vmlinux.lds.S
78
84
*/
79
85
extern u64 __cacheline_aligned_in_smp jiffies_64 ;
80
86
extern unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies ;
81
87
82
88
#if (BITS_PER_LONG < 64 )
83
89
u64 get_jiffies_64 (void );
84
90
#else
91
+ /**
92
+ * get_jiffies_64 - read the 64-bit non-atomic jiffies_64 value
93
+ *
94
+ * When BITS_PER_LONG < 64, this uses sequence number sampling using
95
+ * jiffies_lock to protect the 64-bit read.
96
+ *
97
+ * Return: current 64-bit jiffies value
98
+ */
85
99
static inline u64 get_jiffies_64 (void )
86
100
{
87
101
return (u64 )jiffies ;
88
102
}
89
103
#endif
90
104
91
105
/*
92
- * These inlines deal with timer wrapping correctly. You are
93
- * strongly encouraged to use them
106
+ * These inlines deal with timer wrapping correctly. You are
107
+ * strongly encouraged to use them:
94
108
* 1. Because people otherwise forget
95
109
* 2. Because if the timer wrap changes in future you won't have to
96
110
* alter your driver code.
97
- *
98
- * time_after(a,b) returns true if the time a is after time b.
111
+ */
112
+
113
+ /**
114
+ * time_after - returns true if the time a is after time b.
115
+ * @a: first comparable as unsigned long
116
+ * @b: second comparable as unsigned long
99
117
*
100
118
* Do this with "<0" and ">=0" to only test the sign of the result. A
101
119
* good compiler would generate better code (and a really good compiler
102
120
* wouldn't care). Gcc is currently neither.
121
+ *
122
+ * Return: %true is time a is after time b, otherwise %false.
103
123
*/
104
124
#define time_after (a ,b ) \
105
125
(typecheck(unsigned long, a) && \
106
126
typecheck(unsigned long, b) && \
107
127
((long)((b) - (a)) < 0))
128
+ /**
129
+ * time_before - returns true if the time a is before time b.
130
+ * @a: first comparable as unsigned long
131
+ * @b: second comparable as unsigned long
132
+ *
133
+ * Return: %true is time a is before time b, otherwise %false.
134
+ */
108
135
#define time_before (a ,b ) time_after(b,a)
109
136
137
+ /**
138
+ * time_after_eq - returns true if the time a is after or the same as time b.
139
+ * @a: first comparable as unsigned long
140
+ * @b: second comparable as unsigned long
141
+ *
142
+ * Return: %true is time a is after or the same as time b, otherwise %false.
143
+ */
110
144
#define time_after_eq (a ,b ) \
111
145
(typecheck(unsigned long, a) && \
112
146
typecheck(unsigned long, b) && \
113
147
((long)((a) - (b)) >= 0))
148
+ /**
149
+ * time_before_eq - returns true if the time a is before or the same as time b.
150
+ * @a: first comparable as unsigned long
151
+ * @b: second comparable as unsigned long
152
+ *
153
+ * Return: %true is time a is before or the same as time b, otherwise %false.
154
+ */
114
155
#define time_before_eq (a ,b ) time_after_eq(b,a)
115
156
116
- /*
117
- * Calculate whether a is in the range of [b, c].
157
+ /**
158
+ * time_in_range - Calculate whether a is in the range of [b, c].
159
+ * @a: time to test
160
+ * @b: beginning of the range
161
+ * @c: end of the range
162
+ *
163
+ * Return: %true is time a is in the range [b, c], otherwise %false.
118
164
*/
119
165
#define time_in_range (a ,b ,c ) \
120
166
(time_after_eq(a,b) && \
121
167
time_before_eq(a,c))
122
168
123
- /*
124
- * Calculate whether a is in the range of [b, c).
169
+ /**
170
+ * time_in_range_open - Calculate whether a is in the range of [b, c).
171
+ * @a: time to test
172
+ * @b: beginning of the range
173
+ * @c: end of the range
174
+ *
175
+ * Return: %true is time a is in the range [b, c), otherwise %false.
125
176
*/
126
177
#define time_in_range_open (a ,b ,c ) \
127
178
(time_after_eq(a,b) && \
128
179
time_before(a,c))
129
180
130
181
/* Same as above, but does so with platform independent 64bit types.
131
182
* These must be used when utilizing jiffies_64 (i.e. return value of
132
- * get_jiffies_64() */
183
+ * get_jiffies_64()). */
184
+
185
+ /**
186
+ * time_after64 - returns true if the time a is after time b.
187
+ * @a: first comparable as __u64
188
+ * @b: second comparable as __u64
189
+ *
190
+ * This must be used when utilizing jiffies_64 (i.e. return value of
191
+ * get_jiffies_64()).
192
+ *
193
+ * Return: %true is time a is after time b, otherwise %false.
194
+ */
133
195
#define time_after64 (a ,b ) \
134
196
(typecheck(__u64, a) && \
135
197
typecheck(__u64, b) && \
136
198
((__s64)((b) - (a)) < 0))
199
+ /**
200
+ * time_before64 - returns true if the time a is before time b.
201
+ * @a: first comparable as __u64
202
+ * @b: second comparable as __u64
203
+ *
204
+ * This must be used when utilizing jiffies_64 (i.e. return value of
205
+ * get_jiffies_64()).
206
+ *
207
+ * Return: %true is time a is before time b, otherwise %false.
208
+ */
137
209
#define time_before64 (a ,b ) time_after64(b,a)
138
210
211
+ /**
212
+ * time_after_eq64 - returns true if the time a is after or the same as time b.
213
+ * @a: first comparable as __u64
214
+ * @b: second comparable as __u64
215
+ *
216
+ * This must be used when utilizing jiffies_64 (i.e. return value of
217
+ * get_jiffies_64()).
218
+ *
219
+ * Return: %true is time a is after or the same as time b, otherwise %false.
220
+ */
139
221
#define time_after_eq64 (a ,b ) \
140
222
(typecheck(__u64, a) && \
141
223
typecheck(__u64, b) && \
142
224
((__s64)((a) - (b)) >= 0))
225
+ /**
226
+ * time_before_eq64 - returns true if the time a is before or the same as time b.
227
+ * @a: first comparable as __u64
228
+ * @b: second comparable as __u64
229
+ *
230
+ * This must be used when utilizing jiffies_64 (i.e. return value of
231
+ * get_jiffies_64()).
232
+ *
233
+ * Return: %true is time a is before or the same as time b, otherwise %false.
234
+ */
143
235
#define time_before_eq64 (a ,b ) time_after_eq64(b,a)
144
236
237
+ /**
238
+ * time_in_range64 - Calculate whether a is in the range of [b, c].
239
+ * @a: time to test
240
+ * @b: beginning of the range
241
+ * @c: end of the range
242
+ *
243
+ * Return: %true is time a is in the range [b, c], otherwise %false.
244
+ */
145
245
#define time_in_range64 (a , b , c ) \
146
246
(time_after_eq64(a, b) && \
147
247
time_before_eq64(a, c))
148
248
149
249
/*
150
- * These four macros compare jiffies and 'a' for convenience.
250
+ * These eight macros compare jiffies[_64] and 'a' for convenience.
151
251
*/
152
252
153
- /* time_is_before_jiffies(a) return true if a is before jiffies */
253
+ /**
254
+ * time_is_before_jiffies - return true if a is before jiffies
255
+ * @a: time (unsigned long) to compare to jiffies
256
+ *
257
+ * Return: %true is time a is before jiffies, otherwise %false.
258
+ */
154
259
#define time_is_before_jiffies (a ) time_after(jiffies, a)
260
+ /**
261
+ * time_is_before_jiffies64 - return true if a is before jiffies_64
262
+ * @a: time (__u64) to compare to jiffies_64
263
+ *
264
+ * Return: %true is time a is before jiffies_64, otherwise %false.
265
+ */
155
266
#define time_is_before_jiffies64 (a ) time_after64(get_jiffies_64(), a)
156
267
157
- /* time_is_after_jiffies(a) return true if a is after jiffies */
268
+ /**
269
+ * time_is_after_jiffies - return true if a is after jiffies
270
+ * @a: time (unsigned long) to compare to jiffies
271
+ *
272
+ * Return: %true is time a is after jiffies, otherwise %false.
273
+ */
158
274
#define time_is_after_jiffies (a ) time_before(jiffies, a)
275
+ /**
276
+ * time_is_after_jiffies64 - return true if a is after jiffies_64
277
+ * @a: time (__u64) to compare to jiffies_64
278
+ *
279
+ * Return: %true is time a is after jiffies_64, otherwise %false.
280
+ */
159
281
#define time_is_after_jiffies64 (a ) time_before64(get_jiffies_64(), a)
160
282
161
- /* time_is_before_eq_jiffies(a) return true if a is before or equal to jiffies*/
283
+ /**
284
+ * time_is_before_eq_jiffies - return true if a is before or equal to jiffies
285
+ * @a: time (unsigned long) to compare to jiffies
286
+ *
287
+ * Return: %true is time a is before or the same as jiffies, otherwise %false.
288
+ */
162
289
#define time_is_before_eq_jiffies (a ) time_after_eq(jiffies, a)
290
+ /**
291
+ * time_is_before_eq_jiffies64 - return true if a is before or equal to jiffies_64
292
+ * @a: time (__u64) to compare to jiffies_64
293
+ *
294
+ * Return: %true is time a is before or the same jiffies_64, otherwise %false.
295
+ */
163
296
#define time_is_before_eq_jiffies64 (a ) time_after_eq64(get_jiffies_64(), a)
164
297
165
- /* time_is_after_eq_jiffies(a) return true if a is after or equal to jiffies*/
298
+ /**
299
+ * time_is_after_eq_jiffies - return true if a is after or equal to jiffies
300
+ * @a: time (unsigned long) to compare to jiffies
301
+ *
302
+ * Return: %true is time a is after or the same as jiffies, otherwise %false.
303
+ */
166
304
#define time_is_after_eq_jiffies (a ) time_before_eq(jiffies, a)
305
+ /**
306
+ * time_is_after_eq_jiffies64 - return true if a is after or equal to jiffies_64
307
+ * @a: time (__u64) to compare to jiffies_64
308
+ *
309
+ * Return: %true is time a is after or the same as jiffies_64, otherwise %false.
310
+ */
167
311
#define time_is_after_eq_jiffies64 (a ) time_before_eq64(get_jiffies_64(), a)
168
312
169
313
/*
170
- * Have the 32 bit jiffies value wrap 5 minutes after boot
314
+ * Have the 32- bit jiffies value wrap 5 minutes after boot
171
315
* so jiffies wrap bugs show up earlier.
172
316
*/
173
317
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
@@ -278,7 +422,7 @@ extern unsigned long preset_lpj;
278
422
#if BITS_PER_LONG < 64
279
423
# define MAX_SEC_IN_JIFFIES \
280
424
(long)((u64)((u64)MAX_JIFFY_OFFSET * TICK_NSEC) / NSEC_PER_SEC)
281
- #else /* take care of overflow on 64 bits machines */
425
+ #else /* take care of overflow on 64-bit machines */
282
426
# define MAX_SEC_IN_JIFFIES \
283
427
(SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 1) - 1)
284
428
@@ -290,6 +434,12 @@ extern unsigned long preset_lpj;
290
434
extern unsigned int jiffies_to_msecs (const unsigned long j );
291
435
extern unsigned int jiffies_to_usecs (const unsigned long j );
292
436
437
+ /**
438
+ * jiffies_to_nsecs - Convert jiffies to nanoseconds
439
+ * @j: jiffies value
440
+ *
441
+ * Return: nanoseconds value
442
+ */
293
443
static inline u64 jiffies_to_nsecs (const unsigned long j )
294
444
{
295
445
return (u64 )jiffies_to_usecs (j ) * NSEC_PER_USEC ;
@@ -353,12 +503,14 @@ static inline unsigned long _msecs_to_jiffies(const unsigned int m)
353
503
*
354
504
* msecs_to_jiffies() checks for the passed in value being a constant
355
505
* via __builtin_constant_p() allowing gcc to eliminate most of the
356
- * code, __msecs_to_jiffies() is called if the value passed does not
506
+ * code. __msecs_to_jiffies() is called if the value passed does not
357
507
* allow constant folding and the actual conversion must be done at
358
508
* runtime.
359
- * the HZ range specific helpers _msecs_to_jiffies() are called both
509
+ * The HZ range specific helpers _msecs_to_jiffies() are called both
360
510
* directly here and from __msecs_to_jiffies() in the case where
361
511
* constant folding is not possible.
512
+ *
513
+ * Return: jiffies value
362
514
*/
363
515
static __always_inline unsigned long msecs_to_jiffies (const unsigned int m )
364
516
{
@@ -400,12 +552,14 @@ static inline unsigned long _usecs_to_jiffies(const unsigned int u)
400
552
*
401
553
* usecs_to_jiffies() checks for the passed in value being a constant
402
554
* via __builtin_constant_p() allowing gcc to eliminate most of the
403
- * code, __usecs_to_jiffies() is called if the value passed does not
555
+ * code. __usecs_to_jiffies() is called if the value passed does not
404
556
* allow constant folding and the actual conversion must be done at
405
557
* runtime.
406
- * the HZ range specific helpers _usecs_to_jiffies() are called both
558
+ * The HZ range specific helpers _usecs_to_jiffies() are called both
407
559
* directly here and from __msecs_to_jiffies() in the case where
408
560
* constant folding is not possible.
561
+ *
562
+ * Return: jiffies value
409
563
*/
410
564
static __always_inline unsigned long usecs_to_jiffies (const unsigned int u )
411
565
{
@@ -422,6 +576,7 @@ extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);
422
576
extern void jiffies_to_timespec64 (const unsigned long jiffies ,
423
577
struct timespec64 * value );
424
578
extern clock_t jiffies_to_clock_t (unsigned long x );
579
+
425
580
static inline clock_t jiffies_delta_to_clock_t (long delta )
426
581
{
427
582
return jiffies_to_clock_t (max (0L , delta ));
0 commit comments