@@ -72,102 +72,246 @@ extern int register_refined_jiffies(long clock_tick_rate);
7272#endif
7373
7474/*
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
7676 * without sampling the sequence number in jiffies_lock.
7777 * 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
7884 */
7985extern u64 __cacheline_aligned_in_smp jiffies_64 ;
8086extern unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies ;
8187
8288#if (BITS_PER_LONG < 64 )
8389u64 get_jiffies_64 (void );
8490#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+ */
8599static inline u64 get_jiffies_64 (void )
86100{
87101 return (u64 )jiffies ;
88102}
89103#endif
90104
91105/*
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:
94108 * 1. Because people otherwise forget
95109 * 2. Because if the timer wrap changes in future you won't have to
96110 * 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
99117 *
100118 * Do this with "<0" and ">=0" to only test the sign of the result. A
101119 * good compiler would generate better code (and a really good compiler
102120 * wouldn't care). Gcc is currently neither.
121+ *
122+ * Return: %true is time a is after time b, otherwise %false.
103123 */
104124#define time_after (a ,b ) \
105125 (typecheck(unsigned long, a) && \
106126 typecheck(unsigned long, b) && \
107127 ((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+ */
108135#define time_before (a ,b ) time_after(b,a)
109136
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+ */
110144#define time_after_eq (a ,b ) \
111145 (typecheck(unsigned long, a) && \
112146 typecheck(unsigned long, b) && \
113147 ((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+ */
114155#define time_before_eq (a ,b ) time_after_eq(b,a)
115156
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.
118164 */
119165#define time_in_range (a ,b ,c ) \
120166 (time_after_eq(a,b) && \
121167 time_before_eq(a,c))
122168
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.
125176 */
126177#define time_in_range_open (a ,b ,c ) \
127178 (time_after_eq(a,b) && \
128179 time_before(a,c))
129180
130181/* Same as above, but does so with platform independent 64bit types.
131182 * 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+ */
133195#define time_after64 (a ,b ) \
134196 (typecheck(__u64, a) && \
135197 typecheck(__u64, b) && \
136198 ((__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+ */
137209#define time_before64 (a ,b ) time_after64(b,a)
138210
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+ */
139221#define time_after_eq64 (a ,b ) \
140222 (typecheck(__u64, a) && \
141223 typecheck(__u64, b) && \
142224 ((__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+ */
143235#define time_before_eq64 (a ,b ) time_after_eq64(b,a)
144236
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+ */
145245#define time_in_range64 (a , b , c ) \
146246 (time_after_eq64(a, b) && \
147247 time_before_eq64(a, c))
148248
149249/*
150- * These four macros compare jiffies and 'a' for convenience.
250+ * These eight macros compare jiffies[_64] and 'a' for convenience.
151251 */
152252
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+ */
154259#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+ */
155266#define time_is_before_jiffies64 (a ) time_after64(get_jiffies_64(), a)
156267
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+ */
158274#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+ */
159281#define time_is_after_jiffies64 (a ) time_before64(get_jiffies_64(), a)
160282
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+ */
162289#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+ */
163296#define time_is_before_eq_jiffies64 (a ) time_after_eq64(get_jiffies_64(), a)
164297
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+ */
166304#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+ */
167311#define time_is_after_eq_jiffies64 (a ) time_before_eq64(get_jiffies_64(), a)
168312
169313/*
170- * Have the 32 bit jiffies value wrap 5 minutes after boot
314+ * Have the 32- bit jiffies value wrap 5 minutes after boot
171315 * so jiffies wrap bugs show up earlier.
172316 */
173317#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
@@ -278,7 +422,7 @@ extern unsigned long preset_lpj;
278422#if BITS_PER_LONG < 64
279423# define MAX_SEC_IN_JIFFIES \
280424 (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 */
282426# define MAX_SEC_IN_JIFFIES \
283427 (SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 1) - 1)
284428
@@ -290,6 +434,12 @@ extern unsigned long preset_lpj;
290434extern unsigned int jiffies_to_msecs (const unsigned long j );
291435extern unsigned int jiffies_to_usecs (const unsigned long j );
292436
437+ /**
438+ * jiffies_to_nsecs - Convert jiffies to nanoseconds
439+ * @j: jiffies value
440+ *
441+ * Return: nanoseconds value
442+ */
293443static inline u64 jiffies_to_nsecs (const unsigned long j )
294444{
295445 return (u64 )jiffies_to_usecs (j ) * NSEC_PER_USEC ;
@@ -353,12 +503,14 @@ static inline unsigned long _msecs_to_jiffies(const unsigned int m)
353503 *
354504 * msecs_to_jiffies() checks for the passed in value being a constant
355505 * 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
357507 * allow constant folding and the actual conversion must be done at
358508 * 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
360510 * directly here and from __msecs_to_jiffies() in the case where
361511 * constant folding is not possible.
512+ *
513+ * Return: jiffies value
362514 */
363515static __always_inline unsigned long msecs_to_jiffies (const unsigned int m )
364516{
@@ -400,12 +552,14 @@ static inline unsigned long _usecs_to_jiffies(const unsigned int u)
400552 *
401553 * usecs_to_jiffies() checks for the passed in value being a constant
402554 * 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
404556 * allow constant folding and the actual conversion must be done at
405557 * 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
407559 * directly here and from __msecs_to_jiffies() in the case where
408560 * constant folding is not possible.
561+ *
562+ * Return: jiffies value
409563 */
410564static __always_inline unsigned long usecs_to_jiffies (const unsigned int u )
411565{
@@ -422,6 +576,7 @@ extern unsigned long timespec64_to_jiffies(const struct timespec64 *value);
422576extern void jiffies_to_timespec64 (const unsigned long jiffies ,
423577 struct timespec64 * value );
424578extern clock_t jiffies_to_clock_t (unsigned long x );
579+
425580static inline clock_t jiffies_delta_to_clock_t (long delta )
426581{
427582 return jiffies_to_clock_t (max (0L , delta ));
0 commit comments