Revert "Ondemand tweaks"

This reverts commit 115ba0ede450950411f3e07c2be4dc1311eda2a6.
some Ondemand tweaks

cpufreq: ondemand: Remove redundant return statement

After commit dfa5bb622555d9da0df21b50f46ebdeef390041b
"cpufreq: ondemand: Change the calculation of target frequency",
this return statement is no longer needed.

Reported-by: Henrik Nilsson <Karl.Henrik.Nilsson@gmail.com>
Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Simplify input event code

Thanks to SkipXS <sskkiipp@gmail.com>

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Fix hotplug deadlock with store_powersave_bias

store_powersave_bias() acquires the hotplug lock and the dbs_mutex
lock, but does so in the wrong order.  Deadlocks like the following
can result.

Thread A:
    get_online_cpus+0x3c/0x5c           <- acquires 'cpu_hotplug.lock'
    store_powersave_bias+0x80/0x3f4     <- acquires 'dbs_mutex'
    kobj_attr_store+0x14/0x20
    sysfs_write_file+0x108/0x13c
    vfs_write+0xb0/0x128
    sys_write+0x38/0x64

Thread B:
    cpufreq_governor_dbs+0x7c/0x55c     <- acquires 'dbs_mutex'
    __cpufreq_governor+0x90/0xe0
    __cpufreq_set_policy+0x1b0/0x258
    cpufreq_add_dev_interface+0x2cc/0x334
    cpufreq_add_dev+0x514/0x580
    cpufreq_cpu_callback+0x88/0x9c
    notifier_call_chain+0x38/0x68
    __cpu_notify+0x28/0x40
    _cpu_up+0xe4/0x118                  <- acquires 'cpu_hotplug.lock'
    cpu_up+0x64/0x80
    store_online+0x48/0x78
    dev_attr_store+0x18/0x24
    sysfs_write_file+0x108/0x13c
    vfs_write+0xb0/0x128
    sys_write+0x38/0x64

Fix this by flipping the order in which the locks are acquired and
released in store_powersave_bias so that it is the same as in the
hotplug path.

Change-Id: Idc59fb29d60b8f7fceb8ed0f2bb9eff4670abda7
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
cpufreq: ondemand: Fix locking in store_powersave_bias

store_powersave_bias() assumes that dbs_info->cur_policy will
not change while it is executing. If it does, memory corruption
can potentially result. Fix this by acquiring the dbs_lock.

Most noticeably, this resolves timer-related list corruptions
encountered when queue_delayed_work_on() is called from within
store_powersave_bias() while a CPU is being hotplugged in and
out.

CRs-Fixed: 494407
Change-Id: I0fd5cbef6834545274cad9481e574ec50b37b871
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
cpufreq: ondemand: Fix store_powersave_bias() race with hotplug

store_powersave_bias() assumes that CPUs will not be taken offline or
brought online while executing its for_each_online_cpu() loops. Fix
this race by blocking hotplug while executing in these loop.

CRs-Fixed: 494407
Change-Id: I0d5520444ec21a8d9b12fb73c06ac8442449fa85
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
cpufreq: ondemand: Boost CPU frequency only for touch input

Originally CPU frequency were boosted for any input event.
In some case, sensor sends a lot of input event, which
keep CPU in high frequency.  CPU frequency only need to
be boosted when real user interaction happens.

Change-Id: Ia3ad755b98d8363a17729926610b5dd6f0075288
CR-Fixed: 507519
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
cpufreq: ondemand: Add missing call to cpufreq_notify_utilization

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Default touch_load_duration to 1100

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Change default values for touch tunables

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Calculate the timer delay jiffies once

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Fix checkpatch warnings

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Export touch tunables to sysfs

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Introduce touch_load and touch_delay tunables

Introduce touch_load and touch_delay tunables that used to
boost frequency on touch.

Also remove unused input workqueue after drop of mpdecision.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Drop early_demand

Since we changed the calculation of target frequency early demand is
kind of useless.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Fix frequency increase comparison

up_threshold should compared against max_load. Fix it.

Also cleanup unused code from calculation change of freq_target method.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: freq_next should be proportional to cpuinfo.max_freq

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Calculate the next frequency proportional to current load

If load_freq < adj_up_threshold adjust the frequency proportional to
current load.
So, we don't wait for load to saturate the min frequency until
up_threshold. We adjust frequency immediately to a higher frequency.

Also, update the MICRO_FREQUENCY_UP_THRESHOLD to 95 and
MICRO_FREQUENCY_DOWN_DIFFERENTIAL to 3. We don't need more aggresive
values anymore.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Calculate gradient of CPU load to early
increase frequency

Instead of checking only the absolute value of CPU load_freq to increase
frequency, we detect forthcoming CPU load rise and increase frequency
earlier.

Every sampling rate, we calculate the gradient of load_freq. If it is
too steep we assume that the load most probably will go over
up_threshold in next iteration(s) and we increase frequency immediately.

New tuners are introduced:
- early_demand: to enable this functionality (disabled by default).
- grad_up_threshold: over this gradient of load we will increase
frequency immediately.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
cpufreq: ondemand: Calculate iowait time only when necessary

Currently we always calculate the CPU iowait time and add it to idle
time.
If we are in ondemand and we use io_is_busy, we re-calculate iowait time
and we subtract it from idle time.

With this patch iowait time is calculated only when necessary avoiding
the double call to get_cpu_iowait_time_us. We use a parameter in
function get_cpu_idle_time to distinguish when the iowait time will be
added to idle time or not, without the need of keeping the prev_io_wait.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
Acked-by: Viresh Kumar <viresh.kumar@linaro.,org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: ondemand: Fix typos in comments

Fix some typos in comments.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: ondemand: Replace down_differential tuner with adj_up_threshold

In order to avoid the calculation of up_threshold - down_differential
every time that the frequency must be decreased, we replace the
down_differential tuner with the adj_up_threshold which keeps the
difference across multiple checks.

Update the adj_up_threshold only when the up_theshold is also updated.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> (reverted from commit 115ba0ede450950411f3e07c2be4dc1311eda2a6)