]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
hrtimer: peek at the timer queue just before going idle
authorArjan van de Ven <arjan@linux.intel.com>
Wed, 10 Sep 2008 23:06:00 +0000 (16:06 -0700)
committerArjan van de Ven <arjan@linux.intel.com>
Thu, 11 Sep 2008 14:17:49 +0000 (07:17 -0700)
As part of going idle, we already look at the time of the next timer event to determine
which C-state to select etc.

This patch adds functionality that causes the timers that are past their
soft expire time, to fire at this time, before we calculate the next wakeup
time. This functionality will thus avoid wakeups by running timers before
going idle rather than specially waking up for it.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
drivers/cpuidle/cpuidle.c
include/linux/hrtimer.h
kernel/hrtimer.c

index 5ce07b517c5875def9106c5041402032c3f70fc1..2e3148499368b8b965e6845c7627caa6ce621be4 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/cpu.h>
 #include <linux/cpuidle.h>
 #include <linux/ktime.h>
+#include <linux/hrtimer.h>
 
 #include "cpuidle.h"
 
@@ -60,6 +61,12 @@ static void cpuidle_idle_call(void)
                return;
        }
 
+       /*
+        * run any timers that can be run now, at this point
+        * before calculating the idle duration etc.
+        */
+       hrtimer_peek_ahead_timers();
+
        /* ask the governor for the next state */
        next_state = cpuidle_curr_governor->select(dev);
        if (need_resched())
index 95db11f62ff25bdfdb293239c87b320839ef5fee..d93b1e1dc1699d77c0008fd276d11bd30157f195 100644 (file)
@@ -326,6 +326,11 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 extern ktime_t ktime_get(void);
 extern ktime_t ktime_get_real(void);
 
+
+DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
+extern void hrtimer_peek_ahead_timers(void);
+
+
 /* Exported timer functions: */
 
 /* Initialize timers: */
index 9a4c901855668fd0daecdd398456a01f348d32ca..eb2cf984959fe154a8c3cdd07129227a95bc6e31 100644 (file)
@@ -1381,6 +1381,36 @@ void hrtimer_interrupt(struct clock_event_device *dev)
                raise_softirq(HRTIMER_SOFTIRQ);
 }
 
+/**
+ * hrtimer_peek_ahead_timers -- run soft-expired timers now
+ *
+ * hrtimer_peek_ahead_timers will peek at the timer queue of
+ * the current cpu and check if there are any timers for which
+ * the soft expires time has passed. If any such timers exist,
+ * they are run immediately and then removed from the timer queue.
+ *
+ */
+void hrtimer_peek_ahead_timers(void)
+{
+       unsigned long flags;
+       struct tick_device *td;
+       struct clock_event_device *dev;
+
+       if (hrtimer_hres_active())
+               return;
+
+       local_irq_save(flags);
+       td = &__get_cpu_var(tick_cpu_device);
+       if (!td)
+               goto out;
+       dev = td->evtdev;
+       if (!dev)
+               goto out;
+       hrtimer_interrupt(dev);
+out:
+       local_irq_restore(flags);
+}
+
 static void run_hrtimer_softirq(struct softirq_action *h)
 {
        run_hrtimer_pending(&__get_cpu_var(hrtimer_bases));