Commit | Line | Data |
---|---|---|
32e29396 VF |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef _LINUX_HRTIMER_DEFS_H | |
3 | #define _LINUX_HRTIMER_DEFS_H | |
4 | ||
5 | #include <linux/ktime.h> | |
1a4729ec AMB |
6 | #include <linux/timerqueue.h> |
7 | #include <linux/seqlock.h> | |
32e29396 VF |
8 | |
9 | #ifdef CONFIG_HIGH_RES_TIMERS | |
10 | ||
11 | /* | |
12 | * The resolution of the clocks. The resolution value is returned in | |
13 | * the clock_getres() system call to give application programmers an | |
14 | * idea of the (in)accuracy of timers. Timer values are rounded up to | |
15 | * this resolution values. | |
16 | */ | |
17 | # define HIGH_RES_NSEC 1 | |
18 | # define KTIME_HIGH_RES (HIGH_RES_NSEC) | |
19 | # define MONOTONIC_RES_NSEC HIGH_RES_NSEC | |
20 | # define KTIME_MONOTONIC_RES KTIME_HIGH_RES | |
21 | ||
22 | #else | |
23 | ||
24 | # define MONOTONIC_RES_NSEC LOW_RES_NSEC | |
25 | # define KTIME_MONOTONIC_RES KTIME_LOW_RES | |
26 | ||
27 | #endif | |
28 | ||
1a4729ec AMB |
29 | #ifdef CONFIG_64BIT |
30 | # define __hrtimer_clock_base_align ____cacheline_aligned | |
31 | #else | |
32 | # define __hrtimer_clock_base_align | |
33 | #endif | |
34 | ||
35 | /** | |
36 | * struct hrtimer_clock_base - the timer base for a specific clock | |
37 | * @cpu_base: per cpu clock base | |
38 | * @index: clock type index for per_cpu support when moving a | |
39 | * timer to a base on another cpu. | |
40 | * @clockid: clock id for per_cpu support | |
41 | * @seq: seqcount around __run_hrtimer | |
42 | * @running: pointer to the currently running hrtimer | |
43 | * @active: red black tree root node for the active timers | |
44 | * @get_time: function to retrieve the current time of the clock | |
45 | * @offset: offset of this clock to the monotonic base | |
46 | */ | |
47 | struct hrtimer_clock_base { | |
48 | struct hrtimer_cpu_base *cpu_base; | |
49 | unsigned int index; | |
50 | clockid_t clockid; | |
51 | seqcount_raw_spinlock_t seq; | |
52 | struct hrtimer *running; | |
53 | struct timerqueue_head active; | |
54 | ktime_t (*get_time)(void); | |
55 | ktime_t offset; | |
56 | } __hrtimer_clock_base_align; | |
57 | ||
58 | enum hrtimer_base_type { | |
59 | HRTIMER_BASE_MONOTONIC, | |
60 | HRTIMER_BASE_REALTIME, | |
61 | HRTIMER_BASE_BOOTTIME, | |
62 | HRTIMER_BASE_TAI, | |
63 | HRTIMER_BASE_MONOTONIC_SOFT, | |
64 | HRTIMER_BASE_REALTIME_SOFT, | |
65 | HRTIMER_BASE_BOOTTIME_SOFT, | |
66 | HRTIMER_BASE_TAI_SOFT, | |
67 | HRTIMER_MAX_CLOCK_BASES, | |
68 | }; | |
69 | ||
70 | /** | |
71 | * struct hrtimer_cpu_base - the per cpu clock bases | |
72 | * @lock: lock protecting the base and associated clock bases | |
73 | * and timers | |
74 | * @cpu: cpu number | |
75 | * @active_bases: Bitfield to mark bases with active timers | |
76 | * @clock_was_set_seq: Sequence counter of clock was set events | |
77 | * @hres_active: State of high resolution mode | |
78 | * @in_hrtirq: hrtimer_interrupt() is currently executing | |
79 | * @hang_detected: The last hrtimer interrupt detected a hang | |
80 | * @softirq_activated: displays, if the softirq is raised - update of softirq | |
81 | * related settings is not required then. | |
82 | * @nr_events: Total number of hrtimer interrupt events | |
83 | * @nr_retries: Total number of hrtimer interrupt retries | |
84 | * @nr_hangs: Total number of hrtimer interrupt hangs | |
85 | * @max_hang_time: Maximum time spent in hrtimer_interrupt | |
86 | * @softirq_expiry_lock: Lock which is taken while softirq based hrtimer are | |
87 | * expired | |
94bf12af | 88 | * @online: CPU is online from an hrtimers point of view |
1a4729ec AMB |
89 | * @timer_waiters: A hrtimer_cancel() invocation waits for the timer |
90 | * callback to finish. | |
91 | * @expires_next: absolute time of the next event, is required for remote | |
92 | * hrtimer enqueue; it is the total first expiry time (hard | |
93 | * and soft hrtimer are taken into account) | |
94 | * @next_timer: Pointer to the first expiring timer | |
95 | * @softirq_expires_next: Time to check, if soft queues needs also to be expired | |
96 | * @softirq_next_timer: Pointer to the first expiring softirq based timer | |
97 | * @clock_base: array of clock bases for this cpu | |
98 | * | |
99 | * Note: next_timer is just an optimization for __remove_hrtimer(). | |
100 | * Do not dereference the pointer because it is not reliable on | |
101 | * cross cpu removals. | |
102 | */ | |
103 | struct hrtimer_cpu_base { | |
104 | raw_spinlock_t lock; | |
105 | unsigned int cpu; | |
106 | unsigned int active_bases; | |
107 | unsigned int clock_was_set_seq; | |
108 | unsigned int hres_active : 1, | |
109 | in_hrtirq : 1, | |
110 | hang_detected : 1, | |
94bf12af IM |
111 | softirq_activated : 1, |
112 | online : 1; | |
1a4729ec AMB |
113 | #ifdef CONFIG_HIGH_RES_TIMERS |
114 | unsigned int nr_events; | |
115 | unsigned short nr_retries; | |
116 | unsigned short nr_hangs; | |
117 | unsigned int max_hang_time; | |
118 | #endif | |
119 | #ifdef CONFIG_PREEMPT_RT | |
120 | spinlock_t softirq_expiry_lock; | |
121 | atomic_t timer_waiters; | |
122 | #endif | |
123 | ktime_t expires_next; | |
124 | struct hrtimer *next_timer; | |
125 | ktime_t softirq_expires_next; | |
126 | struct hrtimer *softirq_next_timer; | |
127 | struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES]; | |
128 | } ____cacheline_aligned; | |
129 | ||
130 | ||
32e29396 | 131 | #endif |