@@ -111,6 +111,8 @@ enum tick_dep_bits {
#define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED)
#define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE)
+extern ktime_t tick_nohz_get_next_hrtimer(void);
+
#ifdef CONFIG_NO_HZ_COMMON
extern bool tick_nohz_enabled;
extern bool tick_nohz_tick_stopped(void);
@@ -123,6 +125,7 @@ extern void tick_nohz_idle_exit(void);
extern void tick_nohz_irq_exit(void);
extern bool tick_nohz_idle_got_tick(void);
extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next);
+extern ktime_t tick_nohz_get_next_timer(void);
extern unsigned long tick_nohz_get_idle_calls(void);
extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu);
extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
@@ -145,6 +148,10 @@ static inline void tick_nohz_idle_restart_tick(void) { }
static inline void tick_nohz_idle_enter(void) { }
static inline void tick_nohz_idle_exit(void) { }
static inline bool tick_nohz_idle_got_tick(void) { return false; }
+static inline ktime_t tick_nohz_get_next_timer(void)
+{
+ return tick_nohz_get_next_hrtimer();
+}
static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next)
{
@@ -443,6 +443,20 @@ void __init tick_nohz_init(void)
}
#endif
+/**
+ * tick_nohz_get_next_hrtimer - return the expected deadline for the
+ * next hrtimer
+ *
+ * Called from power state control code with interrupts disabled
+ *
+ * Returns a ktime_t based value giving the next deadline for the tick
+ * or an earlier hrtimer
+ */
+ktime_t tick_nohz_get_next_hrtimer(void)
+{
+ return __this_cpu_read(tick_cpu_device.evtdev)->next_event;
+}
+
/*
* NOHZ - aka dynamic tick functionality
*/
@@ -918,7 +932,7 @@ static void __tick_nohz_idle_stop_tick(struct tick_sched *ts)
int cpu = smp_processor_id();
/*
- * If tick_nohz_get_sleep_length() ran tick_nohz_next_event(), the
+ * If tick_nohz_get_next_timer() ran tick_nohz_next_event(), the
* tick timer expiration time is known already.
*/
if (ts->timer_expires_base)
@@ -1022,6 +1036,58 @@ bool tick_nohz_idle_got_tick(void)
return false;
}
+/**
+ * tick_nohz_get_next_timer - return the earliest timer deadline
+ *
+ * Called from power state control code with interrupts disabled
+ *
+ * Returns a ktime_t based value giving the earliest timer
+ */
+ktime_t tick_nohz_get_next_timer(void)
+{
+
+ struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
+ ktime_t next_tick, next_timer, next_hrtimer;
+ int cpu = smp_processor_id();
+
+ /*
+ * Actually the function returns the next hrtimer which can
+ * be the next tick or another hrtimer expiring before the tick.
+ */
+ next_tick = tick_nohz_get_next_hrtimer();
+
+ /*
+ * If we can not stop the tick, then in any case the next
+ * timer is the earliest one expiring with the hrtimer.
+ */
+ if (!can_stop_idle_tick(cpu, ts))
+ return next_tick;
+
+ /*
+ * Get the next low resolution timer led by the hrtimer. If
+ * there is no timer in this case, then we can rely on the
+ * hrtimer next event only coming from the call above.
+ */
+ next_timer = tick_nohz_next_event(ts, cpu);
+ if (!next_timer)
+ return next_tick;
+
+ /*
+ * This function will return the next timer after the
+ * sched_timer aka the tick. We know there is another hrtimer
+ * because the tick_nohz_next_event() returned a non zero
+ * deadline and we need a tick to make the lowres to expire.
+ */
+ next_hrtimer = hrtimer_next_event_without(&ts->sched_timer);
+
+ /*
+ * At this point, we have the next lowres timer and the next
+ * hrtimer which is not the tick. We need to figure out which
+ * one expires first.
+ */
+ return min_t(u64, next_hrtimer, next_timer);
+}
+
/**
* tick_nohz_get_sleep_length - return the expected length of the current sleep
* @delta_next: duration until the next event if the tick cannot be stopped