This simple governor takes into account the predictable events: the timer sleep
duration and the next expected IO sleep duration. By mixing both it deduced
what idle state fits better. This governor must be extended to a statistical
approach to predict all the other events.

The main purpose of this governor is to handle the guessed next events in a
categorized way:
        1. deterministic events : timers
        2. guessed events : IOs
        3. predictable events : keystroke, incoming network packet, ...

This governor is aimed to be moved later near the scheduler, so this one
can inspect/inject more informations and act proactively rather than
reactively.

Signed-off-by: Daniel Lezcano <[email protected]>
---
 drivers/cpuidle/Kconfig            |  4 +++
 drivers/cpuidle/governors/Makefile |  1 +
 drivers/cpuidle/governors/select.c | 55 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+)
 create mode 100644 drivers/cpuidle/governors/select.c

diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig
index 32748c3..11e9781 100644
--- a/drivers/cpuidle/Kconfig
+++ b/drivers/cpuidle/Kconfig
@@ -25,6 +25,10 @@ config CPU_IDLE_GOV_MENU
        bool "Menu governor (for tickless system)"
        default y
 
+config CPU_IDLE_GOV_SELECT
+       bool "Select governor (for tickless system)"
+       default y
+
 menu "ARM CPU Idle Drivers"
 depends on ARM
 source "drivers/cpuidle/Kconfig.arm"
diff --git a/drivers/cpuidle/governors/Makefile 
b/drivers/cpuidle/governors/Makefile
index 1b51272..fa45520 100644
--- a/drivers/cpuidle/governors/Makefile
+++ b/drivers/cpuidle/governors/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_CPU_IDLE_GOV_LADDER) += ladder.o
 obj-$(CONFIG_CPU_IDLE_GOV_MENU) += menu.o
+obj-$(CONFIG_CPU_IDLE_GOV_SELECT) += select.o
diff --git a/drivers/cpuidle/governors/select.c 
b/drivers/cpuidle/governors/select.c
new file mode 100644
index 0000000..0de7095
--- /dev/null
+++ b/drivers/cpuidle/governors/select.c
@@ -0,0 +1,55 @@
+/*
+ * select.c - the select governor
+ *
+ * Copyright (C) 2014 Daniel Lezcano <[email protected]>
+ *
+*/
+
+#include <linux/cpuidle.h>
+
+static int select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
+                 struct cpuidle_times *times)
+{
+       int i, index = 0, latency_req = times->latency_req;
+       unsigned int next_event;
+
+       /*
+        * If the guessed IO next event is zero, that means there is no IO
+        * pending, so we ignore it in the equation
+        */
+       next_event = times->next_io_event ? 
+               min(times->next_io_event, times->next_timer_event) :
+               times->next_timer_event;
+
+       for (i = 0; i < drv->state_count; i++) {
+
+               struct cpuidle_state *s = &drv->states[i];
+               struct cpuidle_state_usage *su = &dev->states_usage[i];
+
+               if (s->disabled || su->disable)
+                       continue;
+               if (s->target_residency > next_event)
+                       continue;
+               if (s->exit_latency > latency_req)
+                       continue;
+
+               index = i;
+       }
+
+       return index;
+}
+
+static struct cpuidle_governor select_governor = {
+       .name   = "select",
+       .rating = 10,
+       .select = select,
+       .owner  = THIS_MODULE,
+};
+
+static int __init select_init(void)
+{
+       return cpuidle_register_governor(&select_governor);
+}
+
+postcore_initcall(select_init);
+
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to