18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _TICK_SCHED_H
38c2ecf20Sopenharmony_ci#define _TICK_SCHED_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/hrtimer.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_cienum tick_device_mode {
88c2ecf20Sopenharmony_ci	TICKDEV_MODE_PERIODIC,
98c2ecf20Sopenharmony_ci	TICKDEV_MODE_ONESHOT,
108c2ecf20Sopenharmony_ci};
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct tick_device {
138c2ecf20Sopenharmony_ci	struct clock_event_device *evtdev;
148c2ecf20Sopenharmony_ci	enum tick_device_mode mode;
158c2ecf20Sopenharmony_ci};
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cienum tick_nohz_mode {
188c2ecf20Sopenharmony_ci	NOHZ_MODE_INACTIVE,
198c2ecf20Sopenharmony_ci	NOHZ_MODE_LOWRES,
208c2ecf20Sopenharmony_ci	NOHZ_MODE_HIGHRES,
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/**
248c2ecf20Sopenharmony_ci * struct tick_sched - sched tick emulation and no idle tick control/stats
258c2ecf20Sopenharmony_ci * @sched_timer:	hrtimer to schedule the periodic tick in high
268c2ecf20Sopenharmony_ci *			resolution mode
278c2ecf20Sopenharmony_ci * @check_clocks:	Notification mechanism about clocksource changes
288c2ecf20Sopenharmony_ci * @nohz_mode:		Mode - one state of tick_nohz_mode
298c2ecf20Sopenharmony_ci * @inidle:		Indicator that the CPU is in the tick idle mode
308c2ecf20Sopenharmony_ci * @tick_stopped:	Indicator that the idle tick has been stopped
318c2ecf20Sopenharmony_ci * @idle_active:	Indicator that the CPU is actively in the tick idle mode;
328c2ecf20Sopenharmony_ci *			it is resetted during irq handling phases.
338c2ecf20Sopenharmony_ci * @do_timer_lst:	CPU was the last one doing do_timer before going idle
348c2ecf20Sopenharmony_ci * @got_idle_tick:	Tick timer function has run with @inidle set
358c2ecf20Sopenharmony_ci * @last_tick:		Store the last tick expiry time when the tick
368c2ecf20Sopenharmony_ci *			timer is modified for nohz sleeps. This is necessary
378c2ecf20Sopenharmony_ci *			to resume the tick timer operation in the timeline
388c2ecf20Sopenharmony_ci *			when the CPU returns from nohz sleep.
398c2ecf20Sopenharmony_ci * @next_tick:		Next tick to be fired when in dynticks mode.
408c2ecf20Sopenharmony_ci * @idle_jiffies:	jiffies at the entry to idle for idle time accounting
418c2ecf20Sopenharmony_ci * @idle_calls:		Total number of idle calls
428c2ecf20Sopenharmony_ci * @idle_sleeps:	Number of idle calls, where the sched tick was stopped
438c2ecf20Sopenharmony_ci * @idle_entrytime:	Time when the idle call was entered
448c2ecf20Sopenharmony_ci * @idle_waketime:	Time when the idle was interrupted
458c2ecf20Sopenharmony_ci * @idle_exittime:	Time when the idle state was left
468c2ecf20Sopenharmony_ci * @idle_sleeptime:	Sum of the time slept in idle with sched tick stopped
478c2ecf20Sopenharmony_ci * @iowait_sleeptime:	Sum of the time slept in idle with sched tick stopped, with IO outstanding
488c2ecf20Sopenharmony_ci * @timer_expires:	Anticipated timer expiration time (in case sched tick is stopped)
498c2ecf20Sopenharmony_ci * @timer_expires_base:	Base time clock monotonic for @timer_expires
508c2ecf20Sopenharmony_ci * @next_timer:		Expiry time of next expiring timer for debugging purpose only
518c2ecf20Sopenharmony_ci * @tick_dep_mask:	Tick dependency mask - is set, if someone needs the tick
528c2ecf20Sopenharmony_ci * @last_tick_jiffies:	Value of jiffies seen on last tick
538c2ecf20Sopenharmony_ci * @stalled_jiffies:	Number of stalled jiffies detected across ticks
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_cistruct tick_sched {
568c2ecf20Sopenharmony_ci	struct hrtimer			sched_timer;
578c2ecf20Sopenharmony_ci	unsigned long			check_clocks;
588c2ecf20Sopenharmony_ci	enum tick_nohz_mode		nohz_mode;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	unsigned int			inidle		: 1;
618c2ecf20Sopenharmony_ci	unsigned int			tick_stopped	: 1;
628c2ecf20Sopenharmony_ci	unsigned int			idle_active	: 1;
638c2ecf20Sopenharmony_ci	unsigned int			do_timer_last	: 1;
648c2ecf20Sopenharmony_ci	unsigned int			got_idle_tick	: 1;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	ktime_t				last_tick;
678c2ecf20Sopenharmony_ci	ktime_t				next_tick;
688c2ecf20Sopenharmony_ci	unsigned long			idle_jiffies;
698c2ecf20Sopenharmony_ci	unsigned long			idle_calls;
708c2ecf20Sopenharmony_ci	unsigned long			idle_sleeps;
718c2ecf20Sopenharmony_ci	ktime_t				idle_entrytime;
728c2ecf20Sopenharmony_ci	ktime_t				idle_waketime;
738c2ecf20Sopenharmony_ci	ktime_t				idle_exittime;
748c2ecf20Sopenharmony_ci	ktime_t				idle_sleeptime;
758c2ecf20Sopenharmony_ci	ktime_t				iowait_sleeptime;
768c2ecf20Sopenharmony_ci	unsigned long			last_jiffies;
778c2ecf20Sopenharmony_ci	u64				timer_expires;
788c2ecf20Sopenharmony_ci	u64				timer_expires_base;
798c2ecf20Sopenharmony_ci	u64				next_timer;
808c2ecf20Sopenharmony_ci	ktime_t				idle_expires;
818c2ecf20Sopenharmony_ci	atomic_t			tick_dep_mask;
828c2ecf20Sopenharmony_ci	unsigned long			last_tick_jiffies;
838c2ecf20Sopenharmony_ci	unsigned int			stalled_jiffies;
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciextern struct tick_sched *tick_get_tick_sched(int cpu);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciextern void tick_setup_sched_timer(void);
898c2ecf20Sopenharmony_ci#if defined CONFIG_NO_HZ_COMMON || defined CONFIG_HIGH_RES_TIMERS
908c2ecf20Sopenharmony_ciextern void tick_cancel_sched_timer(int cpu);
918c2ecf20Sopenharmony_ci#else
928c2ecf20Sopenharmony_cistatic inline void tick_cancel_sched_timer(int cpu) { }
938c2ecf20Sopenharmony_ci#endif
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
968c2ecf20Sopenharmony_ciextern int __tick_broadcast_oneshot_control(enum tick_broadcast_state state);
978c2ecf20Sopenharmony_ci#else
988c2ecf20Sopenharmony_cistatic inline int
998c2ecf20Sopenharmony_ci__tick_broadcast_oneshot_control(enum tick_broadcast_state state)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	return -EBUSY;
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci#endif
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#endif
106