cpufreq: interactive: Add sysfs boost interface for hints from userspace
authorTodd Poynor <toddpoynor@google.com>
Tue, 24 Apr 2012 03:42:41 +0000 (20:42 -0700)
committerJohn Stultz <john.stultz@linaro.org>
Tue, 16 Feb 2016 21:52:38 +0000 (13:52 -0800)
The explicit hint on/off version.

Change-Id: Ibf62b6d45bf6fb8c9c055b9bdaf074ce9374c04f
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Documentation/cpu-freq/governors.txt
drivers/cpufreq/cpufreq_interactive.c
include/trace/events/cpufreq_interactive.h

index 4172cada2c0e19f11f568efc324b392ecc0df53e..4fcaa43dbe5c0f038df5e8cd4ac898065f89f84f 100644 (file)
@@ -267,6 +267,9 @@ not idle.  Default is 20000 uS.
 input_boost: If non-zero, boost speed of all CPUs to hispeed_freq on
 touchscreen activity.  Default is 0.
 
+boost: If non-zero, immediately boost speed of all CPUs to
+hispeed_freq.  If zero, allow CPU speeds to drop below hispeed_freq.
+
 
 3. The Governor Interface in the CPUfreq Core
 =============================================
index 90db2c30e2f9bfc4ec551bfe81c73058da58ddd9..07b7cafaffddbef17c7b1c1a16a9ed8aa6b6ef01 100644 (file)
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/input.h>
+#include <asm/cputime.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/cpufreq_interactive.h>
 
-#include <asm/cputime.h>
-
 static atomic_t active_count = ATOMIC_INIT(0);
 
 struct cpufreq_interactive_cpuinfo {
@@ -94,7 +93,7 @@ static unsigned long timer_rate;
 static unsigned long above_hispeed_delay_val;
 
 /*
- * Boost to hispeed on touchscreen input.
+ * Boost pulse to hispeed on touchscreen input.
  */
 
 static int input_boost_val;
@@ -106,6 +105,12 @@ struct cpufreq_interactive_inputopen {
 
 static struct cpufreq_interactive_inputopen inputopen;
 
+/*
+ * Non-zero means longer-term speed boost active.
+ */
+
+static int boost_val;
+
 static int cpufreq_governor_interactive(struct cpufreq_policy *policy,
                unsigned int event);
 
@@ -189,7 +194,7 @@ static void cpufreq_interactive_timer(unsigned long data)
        if (load_since_change > cpu_load)
                cpu_load = load_since_change;
 
-       if (cpu_load >= go_hispeed_load) {
+       if (cpu_load >= go_hispeed_load || boost_val) {
                if (pcpu->target_freq <= pcpu->policy->min) {
                        new_freq = hispeed_freq;
                } else {
@@ -517,6 +522,12 @@ static void cpufreq_interactive_boost(void)
                wake_up_process(up_task);
 }
 
+/*
+ * Pulsed boost on input event raises CPUs to hispeed_freq and lets
+ * usual algorithm of min_sample_time  decide when to allow speed
+ * to drop.
+ */
+
 static void cpufreq_interactive_input_event(struct input_handle *handle,
                                            unsigned int type,
                                            unsigned int code, int value)
@@ -732,6 +743,34 @@ static ssize_t store_input_boost(struct kobject *kobj, struct attribute *attr,
 
 define_one_global_rw(input_boost);
 
+static ssize_t show_boost(struct kobject *kobj, struct attribute *attr,
+                         char *buf)
+{
+       return sprintf(buf, "%d\n", boost_val);
+}
+
+static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
+                          const char *buf, size_t count)
+{
+       int ret;
+       unsigned long val;
+
+       ret = kstrtoul(buf, 0, &val);
+       if (ret < 0)
+               return ret;
+
+       boost_val = val;
+
+       if (boost_val)
+               cpufreq_interactive_boost();
+       else
+               trace_cpufreq_interactive_unboost(hispeed_freq);
+
+       return count;
+}
+
+define_one_global_rw(boost);
+
 static struct attribute *interactive_attributes[] = {
        &hispeed_freq_attr.attr,
        &go_hispeed_load_attr.attr,
@@ -739,6 +778,7 @@ static struct attribute *interactive_attributes[] = {
        &min_sample_time_attr.attr,
        &timer_rate_attr.attr,
        &input_boost.attr,
+       &boost.attr,
        NULL,
 };
 
index 19e070b897ac36cfc4295376ecbf5ec2a0597db6..ae6f232e498fc5241756920389223dd201251038 100644 (file)
@@ -93,6 +93,19 @@ TRACE_EVENT(cpufreq_interactive_boost,
            ),
            TP_printk("freq=%lu", __entry->freq)
 );
+
+TRACE_EVENT(cpufreq_interactive_unboost,
+           TP_PROTO(unsigned long freq),
+           TP_ARGS(freq),
+           TP_STRUCT__entry(
+                   __field(unsigned long, freq)
+           ),
+           TP_fast_assign(
+                   __entry->freq = freq;
+           ),
+           TP_printk("freq=%lu", __entry->freq)
+);
+
 #endif /* _TRACE_CPUFREQ_INTERACTIVE_H */
 
 /* This part must be outside protection */