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> 6 #include <linux/timerqueue.h> 7 #include <linux/seqlock.h> 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 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 88 * @timer_waiters: A hrtimer_cancel() invocation waits for the timer 89 * callback to finish. 90 * @expires_next: absolute time of the next event, is required for remote 91 * hrtimer enqueue; it is the total first expiry time (hard 92 * and soft hrtimer are taken into account) 93 * @next_timer: Pointer to the first expiring timer 94 * @softirq_expires_next: Time to check, if soft queues needs also to be expired 95 * @softirq_next_timer: Pointer to the first expiring softirq based timer 96 * @clock_base: array of clock bases for this cpu 97 * 98 * Note: next_timer is just an optimization for __remove_hrtimer(). 99 * Do not dereference the pointer because it is not reliable on 100 * cross cpu removals. 101 */ 102 struct hrtimer_cpu_base { 103 raw_spinlock_t lock; 104 unsigned int cpu; 105 unsigned int active_bases; 106 unsigned int clock_was_set_seq; 107 unsigned int hres_active : 1, 108 in_hrtirq : 1, 109 hang_detected : 1, 110 softirq_activated : 1; 111 #ifdef CONFIG_HIGH_RES_TIMERS 112 unsigned int nr_events; 113 unsigned short nr_retries; 114 unsigned short nr_hangs; 115 unsigned int max_hang_time; 116 #endif 117 #ifdef CONFIG_PREEMPT_RT 118 spinlock_t softirq_expiry_lock; 119 atomic_t timer_waiters; 120 #endif 121 ktime_t expires_next; 122 struct hrtimer *next_timer; 123 ktime_t softirq_expires_next; 124 struct hrtimer *softirq_next_timer; 125 struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES]; 126 } ____cacheline_aligned; 127 128 129 #endif 130