}
#ifdef CONFIG_NO_IDLE_HZ
-
/**
- * hrtimer_get_next - get next hrtimer to expire
+ * hrtimer_get_next_event - get the time until next expiry event
*
- * @bases: ktimer base array
+ * Returns the delta to the next expiry event or KTIME_MAX if no timer
+ * is pending.
*/
-static inline struct hrtimer * hrtimer_get_next(struct hrtimer_base *bases)
+ktime_t hrtimer_get_next_event(void)
{
+ struct hrtimer_base *base = __get_cpu_var(hrtimer_bases);
+ ktime_t delta, mindelta = { .tv64 = KTIME_MAX };
unsigned long flags;
- struct hrtimer *timer = NULL;
int i;
- for (i = 0; i < MAX_HRTIMER_BASES; i++) {
- struct hrtimer_base *base;
- struct hrtimer *cur;
+ for (i = 0; i < MAX_HRTIMER_BASES; i++, base++) {
+ struct hrtimer *timer;
- base = &bases[i];
spin_lock_irqsave(&base->lock, flags);
- cur = rb_entry(base->first, struct hrtimer, node);
- spin_unlock_irqrestore(&base->lock, flags);
-
- if (cur == NULL)
+ if (!base->first) {
+ spin_unlock_irqrestore(&base->lock, flags);
continue;
-
- if (timer == NULL || cur->expires.tv64 < timer->expires.tv64)
- timer = cur;
+ }
+ timer = rb_entry(base->first, struct hrtimer, node);
+ delta.tv64 = timer->expires.tv64;
+ spin_unlock_irqrestore(&base->lock, flags);
+ delta = ktime_sub(delta, base->get_time());
+ if (delta.tv64 < mindelta.tv64)
+ mindelta.tv64 = delta.tv64;
}
-
- return timer;
+ if (mindelta.tv64 < 0)
+ mindelta.tv64 = 0;
+ return mindelta;
}
-
-/**
- * ktime_to_jiffies - converts ktime to jiffies
- *
- * @event: ktime event to be converted to jiffies
- *
- * Caller must take care xtime locking.
- */
-static inline unsigned long ktime_to_jiffies(const ktime_t event)
-{
- ktime_t now, delta;
-
- now = timespec_to_ktime(xtime);
- delta = ktime_sub(event, now);
-
- return jiffies + (((delta.tv64 * NSEC_CONVERSION) >>
- (NSEC_JIFFIE_SC - SEC_JIFFIE_SC)) >> SEC_JIFFIE_SC);
-}
-
-/**
- * hrtimer_next_jiffie - get next hrtimer event in jiffies
- *
- * Called from next_timer_interrupt() to get the next hrtimer event.
- * Eventually we should change next_timer_interrupt() to return
- * results in nanoseconds instead of jiffies. Caller must host xtime_lock.
- */
-int hrtimer_next_jiffie(unsigned long *next_jiffie)
-{
- struct hrtimer_base *base = __get_cpu_var(hrtimer_bases);
- struct hrtimer * timer;
-
- timer = hrtimer_get_next(base);
- if (timer == NULL)
- return -EAGAIN;
-
- *next_jiffie = ktime_to_jiffies(timer->expires);
-
- return 0;
-}
-
#endif
/**