1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _TICK_SCHED_H 3 #define _TICK_SCHED_H 4 5 #include <linux/hrtimer.h> 6 7 enum tick_device_mode { 8 TICKDEV_MODE_PERIODIC, 9 TICKDEV_MODE_ONESHOT, 10 }; 11 12 struct tick_device { 13 struct clock_event_device *evtdev; 14 enum tick_device_mode mode; 15 }; 16 17 /* The CPU is in the tick idle mode */ 18 #define TS_FLAG_INIDLE BIT(0) 19 /* The idle tick has been stopped */ 20 #define TS_FLAG_STOPPED BIT(1) 21 /* 22 * Indicator that the CPU is actively in the tick idle mode; 23 * it is reset during irq handling phases. 24 */ 25 #define TS_FLAG_IDLE_ACTIVE BIT(2) 26 /* CPU was the last one doing do_timer before going idle */ 27 #define TS_FLAG_DO_TIMER_LAST BIT(3) 28 /* NO_HZ is enabled */ 29 #define TS_FLAG_NOHZ BIT(4) 30 /* High resolution tick mode */ 31 #define TS_FLAG_HIGHRES BIT(5) 32 33 /** 34 * struct tick_sched - sched tick emulation and no idle tick control/stats 35 * 36 * @flags: State flags gathering the TS_FLAG_* features 37 * @got_idle_tick: Tick timer function has run with @inidle set 38 * @stalled_jiffies: Number of stalled jiffies detected across ticks 39 * @last_tick_jiffies: Value of jiffies seen on last tick 40 * @sched_timer: hrtimer to schedule the periodic tick in high 41 * resolution mode 42 * @last_tick: Store the last tick expiry time when the tick 43 * timer is modified for nohz sleeps. This is necessary 44 * to resume the tick timer operation in the timeline 45 * when the CPU returns from nohz sleep. 46 * @next_tick: Next tick to be fired when in dynticks mode. 47 * @idle_waketime: Time when the idle was interrupted 48 * @idle_entrytime: Time when the idle call was entered 49 * @last_jiffies: Base jiffies snapshot when next event was last computed 50 * @timer_expires_base: Base time clock monotonic for @timer_expires 51 * @timer_expires: Anticipated timer expiration time (in case sched tick is stopped) 52 * @next_timer: Expiry time of next expiring timer for debugging purpose only 53 * @idle_expires: Next tick in idle, for debugging purpose only 54 * @idle_calls: Total number of idle calls 55 * @idle_sleeps: Number of idle calls, where the sched tick was stopped 56 * @tick_dep_mask: Tick dependency mask - is set, if someone needs the tick 57 * @check_clocks: Notification mechanism about clocksource changes 58 */ 59 struct tick_sched { 60 /* Common flags */ 61 unsigned long flags; 62 63 /* Tick handling: jiffies stall check */ 64 unsigned int stalled_jiffies; 65 unsigned long last_tick_jiffies; 66 67 /* Tick handling */ 68 struct hrtimer sched_timer; 69 ktime_t last_tick; 70 ktime_t next_tick; 71 ktime_t idle_waketime; 72 unsigned int got_idle_tick; 73 74 /* Idle entry */ 75 ktime_t idle_entrytime; 76 77 /* Tick stop */ 78 unsigned long last_jiffies; 79 u64 timer_expires_base; 80 u64 timer_expires; 81 u64 next_timer; 82 ktime_t idle_expires; 83 unsigned long idle_calls; 84 unsigned long idle_sleeps; 85 86 /* Full dynticks handling */ 87 atomic_t tick_dep_mask; 88 89 /* Clocksource changes */ 90 unsigned long check_clocks; 91 }; 92 93 extern struct tick_sched *tick_get_tick_sched(int cpu); 94 95 extern void tick_setup_sched_timer(bool hrtimer); 96 #if defined CONFIG_TICK_ONESHOT 97 extern void tick_sched_timer_dying(int cpu); 98 #else 99 static inline void tick_sched_timer_dying(int cpu) { } 100 #endif 101 102 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 103 extern int __tick_broadcast_oneshot_control(enum tick_broadcast_state state); 104 #else 105 static inline int 106 __tick_broadcast_oneshot_control(enum tick_broadcast_state state) 107 { 108 return -EBUSY; 109 } 110 #endif 111 112 #endif 113