1 /* SPDX-License-Identifier: GPL-2.0+ */
6 #include <linux/typecheck.h>
7 #include <linux/types.h>
9 unsigned long get_timer(unsigned long base);
12 * Return the current value of a monotonically increasing microsecond timer.
13 * Granularity may be larger than 1us if hardware does not support this.
15 unsigned long timer_get_us(void);
16 uint64_t get_timer_us(uint64_t base);
19 * timer_test_add_offset()
21 * Allow tests to add to the time reported through lib/time.c functions
22 * offset: number of milliseconds to advance the system time
24 void timer_test_add_offset(unsigned long offset);
27 * usec_to_tick() - convert microseconds to clock ticks
29 * @usec: duration in microseconds
30 * Return: duration in clock ticks
32 uint64_t usec_to_tick(unsigned long usec);
35 * These inlines deal with timer wrapping correctly. You are
36 * strongly encouraged to use them
37 * 1. Because people otherwise forget
38 * 2. Because if the timer wrap changes in future you won't have to
39 * alter your driver code.
41 * time_after(a,b) returns true if the time a is after time b.
43 * Do this with "<0" and ">=0" to only test the sign of the result. A
44 * good compiler would generate better code (and a really good compiler
45 * wouldn't care). Gcc is currently neither.
47 #define time_after(a,b) \
48 (typecheck(unsigned long, a) && \
49 typecheck(unsigned long, b) && \
50 ((long)((b) - (a)) < 0))
51 #define time_before(a,b) time_after(b,a)
53 #define time_after_eq(a,b) \
54 (typecheck(unsigned long, a) && \
55 typecheck(unsigned long, b) && \
56 ((long)((a) - (b)) >= 0))
57 #define time_before_eq(a,b) time_after_eq(b,a)
60 * Calculate whether a is in the range of [b, c].
62 #define time_in_range(a,b,c) \
63 (time_after_eq(a,b) && \
67 * Calculate whether a is in the range of [b, c).
69 #define time_in_range_open(a,b,c) \
70 (time_after_eq(a,b) && \