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 * @offset: offset of this clock to the monotonic base 45 */ 46 struct hrtimer_clock_base { 47 struct hrtimer_cpu_base *cpu_base; 48 unsigned int index; 49 clockid_t clockid; 50 seqcount_raw_spinlock_t seq; 51 struct hrtimer *running; 52 struct timerqueue_head active; 53 ktime_t offset; 54 } __hrtimer_clock_base_align; 55 56 enum hrtimer_base_type { 57 HRTIMER_BASE_MONOTONIC, 58 HRTIMER_BASE_REALTIME, 59 HRTIMER_BASE_BOOTTIME, 60 HRTIMER_BASE_TAI, 61 HRTIMER_BASE_MONOTONIC_SOFT, 62 HRTIMER_BASE_REALTIME_SOFT, 63 HRTIMER_BASE_BOOTTIME_SOFT, 64 HRTIMER_BASE_TAI_SOFT, 65 HRTIMER_MAX_CLOCK_BASES, 66 }; 67 68 /** 69 * struct hrtimer_cpu_base - the per cpu clock bases 70 * @lock: lock protecting the base and associated clock bases 71 * and timers 72 * @cpu: cpu number 73 * @active_bases: Bitfield to mark bases with active timers 74 * @clock_was_set_seq: Sequence counter of clock was set events 75 * @hres_active: State of high resolution mode 76 * @in_hrtirq: hrtimer_interrupt() is currently executing 77 * @hang_detected: The last hrtimer interrupt detected a hang 78 * @softirq_activated: displays, if the softirq is raised - update of softirq 79 * related settings is not required then. 80 * @nr_events: Total number of hrtimer interrupt events 81 * @nr_retries: Total number of hrtimer interrupt retries 82 * @nr_hangs: Total number of hrtimer interrupt hangs 83 * @max_hang_time: Maximum time spent in hrtimer_interrupt 84 * @softirq_expiry_lock: Lock which is taken while softirq based hrtimer are 85 * expired 86 * @online: CPU is online from an hrtimers point of view 87 * @timer_waiters: A hrtimer_cancel() invocation waits for the timer 88 * callback to finish. 89 * @expires_next: absolute time of the next event, is required for remote 90 * hrtimer enqueue; it is the total first expiry time (hard 91 * and soft hrtimer are taken into account) 92 * @next_timer: Pointer to the first expiring timer 93 * @softirq_expires_next: Time to check, if soft queues needs also to be expired 94 * @softirq_next_timer: Pointer to the first expiring softirq based timer 95 * @clock_base: array of clock bases for this cpu 96 * 97 * Note: next_timer is just an optimization for __remove_hrtimer(). 98 * Do not dereference the pointer because it is not reliable on 99 * cross cpu removals. 100 */ 101 struct hrtimer_cpu_base { 102 raw_spinlock_t lock; 103 unsigned int cpu; 104 unsigned int active_bases; 105 unsigned int clock_was_set_seq; 106 unsigned int hres_active : 1, 107 in_hrtirq : 1, 108 hang_detected : 1, 109 softirq_activated : 1, 110 online : 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 call_single_data_t csd; 127 } ____cacheline_aligned; 128 129 130 #endif 131