Add lulzactiveq governor (tweaked)

credits to Gokhanmoral, Roberto, Tegrak and AndiP71
cpufreq & hotplug updates

CPU hotplug, writeback: Don't call writeback_set_ratelimit() too often during hotplug

The CPU hotplug callback related to writeback calls writeback_set_ratelimit()
during every state change in the hotplug sequence. This is unnecessary
since num_online_cpus() changes only once during the entire hotplug operation.

So invoke the function only once per hotplug, thereby avoiding the
unnecessary repetition of those costly calculations.

Change-Id: I9d13e74a60632bf079faebb80477ce86121f1a8c
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
cpufreq: Resolve CPUFREQ_NOTIFY issue

When the cpufreq_stat receives the frequency policy notification,
it checks if the frequency table and stats table are present for the cpu.
If both are present, it returns with -EBUSY error to the notification.
Due to this, none of the other registered modules receive this
notification.

If the stat table and sysfs nodes are already created, return 0 instead
of returning EBUSY error.

Change-Id: I1fd4a46e6a65edfc6253c4271288f10912ae2ad7
Signed-off-by: Archana Sathyakumar <asathyak@codeaurora.org>
cpufreq: Retain only online cpus in managed_policy->cpus

cpufreq's handling of cpu online event can incorrectly initialize
managed_policy->cpus to include offline cpus. This causes cpufreq
governors to include offline cpus in their idle time computation, which
causes frequency to shoot up beyond normal levels (on systems where 2 or
more cpus need to be synchronized wrt frequency change).

This frequency shootup was not seen prior to commit 21111be8 which
changed idle time accounting for offline cpus. Prior to commit 21111be8,
idle time statistics for offline cpus would include their offline time
as well. Post commit 21111be8, offline time is not included in a cpu's
idle time statistics.

As a result, ondemand (or other cpufreq) governors would see unchanged
idle time for offline cpus, causing them to interpret those (offline)
cpus as 100% busy, which is wrong.

This patch fixes the issue by modifying cpufreq's hotplug handling to
retain only online cpus in managed_policy->cpus field. cpufreq governors
would then skip such offline cpus from idle time calculations.

Change-Id: Id2eba8c0ec3367609369b2e42a4e1386ff2e7ab5
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
YankasusQ governor

It's a one to one copy of PegasusQ with only a few parameters changed for now.

Main goal is to provide a playing ground for experimenting without "breaking" close to stockness by keeping PegasusQ unchanged
YankasusQ governor

Based on PegasusQ. Introducing cpu frequency limitations based on the number of cores online.

sysfs additions :

- cpu_max_freq_1 : max. freq. applied when running on 1 core (defaults to 1.0GHz)
- cpu_max_freq_2 : max. freq. applied when running on 2 cores (defaults to 1.1GHz)
- cpu_max_freq_3 : max. freq. applied when running on 3 cores (defaults to 1.2GHz)
- cpu_max_freq_4 : max. freq. applied when running on 4 cores (defaults to 1.4GHz)
- cpu_max_freq_current : currently applied max. frequency (read-only)

NB: hotplug frequencies and rq thresholds have been revised up to keep the device running on as little cores as possible.
YankasusQ governor updated

Based on PegasusQ. Introducing cpu frequency limitations based on the number of cores online, stanby frequency and online cores limitations.

sysfs additions :

- cpu_max_freq_stdby : max. freq. applied when screen off (defaults to 800MHz)
- max_cpu_lock_stdby : max. cores online when screen off (defaults to 1)

sysfs interface :

- cpu_max_freq_1 : max. freq. applied when running on 1 core (defaults to 1.0GHz)
- cpu_max_freq_2 : max. freq. applied when running on 2 cores (defaults to 1.1GHz)
- cpu_max_freq_3 : max. freq. applied when running on 3 cores (defaults to 1.2GHz)
- cpu_max_freq_4 : max. freq. applied when running on 4 cores (defaults to 1.4GHz)
- cpu_max_freq_current : currently applied max. frequency (read-only)

NB: hotplug frequencies and rq thresholds have been revised up to keep the device running on as little cores as possible.

Thanx to ZaneZam for inspiring me for these changes !
Based on PegasusQ. Introducing cpu frequency limitations based on the number of cores online, stanby frequency and online cores limitations.

Fixed standby CPU freq. limit not being applied if current number of cores online <= to max_cpu_lock_stdby.
Fixed enforce CPU freq. limit at all times.
Removed limit of cores in standby, it's limited at one anyway.

sysfs interface :

- cpu_max_freq_1 : max. freq. applied when running on 1 core (defaults to 1.0GHz)
- cpu_max_freq_2 : max. freq. applied when running on 2 cores (defaults to 1.1GHz)
- cpu_max_freq_3 : max. freq. applied when running on 3 cores (defaults to 1.2GHz)
- cpu_max_freq_4 : max. freq. applied when running on 4 cores (defaults to 1.4GHz)
- cpu_max_freq_current : currently applied max. frequency (read-only)
- cpu_max_freq_stdby : max. freq. applied when screen off (defaults to 800MHz)

NB: hotplug frequencies and rq thresholds have been revised up to keep the device running on as little cores as possible.
YankasusQ : Don't change prev_step and sampling_rate in suspend
YankasusQ : Push CPU frequency to maximum on late_resume
Added support for scaling_available_frequencies sysfs interface
cpufreq: zzmoove governor (zanezam)

credits to zanezam, mialwe and ktoonsez
cpufreq : ZZMoove Governor 0.4

 * Version 0.4 - limits
 *
 *	- added "soft"-freqency-limit. the term "soft" means here that this is unfortuneately not a hard limit. a hard limit is only possible with
 *	  cpufreq driver which is the freqency "giver" the governor is the "decision maker". So now the governor will scale up to only the given up
 *	  limit on higher system load but if the cpufreq driver "wants" to go above that limit the freqency will go up there. u can see this for
 *	  example with touchboost or wake up freqencies (1000 and 800 mhz) where the governor will be bypassed by the cpufreq driver.
 *	  but nevertheless this soft-limit will reduce the use of freqencies higer than given limit and therefore it will reduce power consumption.
 *
 *	  for this function following new tuneables were indroduced:
 *
 *	  freq_limit_sleep		 -> limit freqency on early suspend (possible values 0 disable limit, 200-1600, default: 0)
 *	  freq_limit			 -> limit freqency on awake (possible values 0 disable limit, 200-1600, default: 0)
 *
 *	- added scaling frequencies to frequency tables for a faster up/down scaling. This should bring more performance but on the other hand it
 *	  can be of course a little bit more power consumptive.
 *
 *	  for this function following new tuneables were indroduced:
 *
 *	  fast_scaling			 -> fast scaling on awake (possible values 0 disable or 1 enable, default: 0)
 *	  fast_scaling_sleep (sysfs)	 -> fast scaling on early suspend (possible values 0 disable or 1 enable, default: 0)
 *
 *	- added tuneable "freq_step_sleep" for setting the freq step at early suspend (possible values same as freq_step 0 to 100, default 5)
 *	- added DEF_FREQ_STEP and IGNORE_NICE definitions
 *	- changed downscaling cpufreq relation to the "lower way"
 *	- code/documentation cleaning
cpufreq: zzmoove governor v0.5

Changelog:

- completely reworked fast scaling functionality. now using a 'line jump' logic instead of fixed freq 'colums'.
  fast scaling now in 4 steps and 2 modes possible (mode 1: only fast scaling up and mode2: fast scaling up/down)
- added support for 'Dynamic Screen Frequency Scaling' (original implementation into zzmoove governor highly improved by Yank555)
  originated by AndreiLux more info: http://forum.xda-developers.com/showpost.php?p=38499071&postcount=3
- re-enabled broken conservative sampling down factor functionality ('down skip' method).
  originated by Stratosk - upstream kernel 3.10rc1:
  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?id=refs%2Ftags%2Fv3.10-rc1&qt=author&q=Stratos+Ka
- changed down threshold check to act like it should.
  originated by Stratosk - upstream kernel 3.10rc1:
  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?id=refs%2Ftags%2Fv3.10-rc1&qt=author&q=Stratos+Ka
- implemented/ported 'early demand' from ondemand governor.
  originated by Stratosk - more info: http://www.semaphore.gr/80-latests/98-ondemand-early-demand
- implemented/ported 'sampling down momentum' from ondemand governor.
  originated by Stratosk - more info: http://www.semaphore.gr/80-latests/80-sampling-down-momentum
- modified some original conservative code parts regarding frequency scaling which should work better now.
  originated by DerTeufel1980: https://github.com/DerTeufel/android_kernel_samsung_smdk4412/commit/6bab622344c548be853db19adf28c3917896f0a0
- added the possibility to use sampling down momentum or conservative 'down skip' method.
- increased possible max sampling rate sleep multiplier to 4 and sampling down factor to 100000
  accordingly to sampling down momentum implementation.
- added frequency search limit for more efficient frequency searching in scaling 'table' and for improving
  frequency 'hard' and 'soft' limit handling.
- added cpu idle exit time handling like it is in lulzactive
  again work from ktoonsez : https://github.com/ktoonsez/KT747-JB/commit/a5931bee6ea9e69f386a340229745da6f2443b78
  description in lulzactive governor:
  https://github.com/ktoonsez/KT747-JB/blob/a5931bee6ea9e69f386a340229745da6f2443b78/drivers/cpufreq/cpufreq_lulzactive.c
- fixed a little scaling step mistake and added overclocking frequencies up to 1800 mhz in scaling frequency 'tables'.
- fixed possible freezes during start/stop/reload of governor and frequency limit change.
- fixed hotplugging logic at online core 0+3 or 0+2 situations and improved hotplugging in general by
  removing mutex locks and skipping hotplugging when it is not needed.
- added possibility to disable hotplugging (that's a debugging relict but i thought maybe someone will find that usefull so i didn't remove it)
- try to fix lags when coming from suspend if hotplug limitation at sleep was active by enabling all offline cores during resume.
- code cleaning and documentation.

Signed-off-by: ZaneZam <cyxman@yahoo.com>
cpufreq: zzmoove governor v0.5.1b (by ZaneZam)

Changelog:

- highly optimised scaling logic (thx and credits to Yank555)
- simplified some tuneables by using already available stuff instead of using redundant code (thx Yank555)
- reduced/optimised hotplug logic and preperation for automatic detection of available cores
  (maybe this fixes also the scaling/core stuck problems)
- finally fixed the freezing issue on governor stop!
cpufreq: zzmoove governor v0.6 (ZaneZam)

Version 0.6 - flexibility (in cooperation with Yank555)

Changelog:

- removed fixed scaling lookup tables and use the system frequency table instead
changed scaling logic accordingly for this modification (thx and credits to Yank555)
- reduced new hotplug logic loop to a minimum
- again try to fix stuck issues by using seperate hotplug functions out of dbs_check_cpu (credits to ktoonesz)
- added support for 2 and 8 core systems and added automatic detection of cores were it is needed
(for setting the different core modes you can use the macro 'MAX_CORES'. possible values are: 2,4 or 8, default are 4 cores)
reduced core threshold defaults to only one up/down default and use an array to hold all threshold values
- fixed some mistakes in 'frequency tuneables' (Yank555):
stop looping once the frequency has been found
return invalid error if new frequency is not found in the frequency table
cpufreq: zzmoove governor v0.7 (aka. tamed beast)

 * Version 0.7 - slow down (in cooperation with Yank555)
 *
 *	- reindroduced the "old way" of hotplugging and scaling in form of the "Legacy Mode" (macros for enabling/disabling this done by Yank555, thx!)
 *	  NOTE: this mode can only handle 4 cores and a scaling max frequency up to 1800mhz.
 *	- added hotplug idle threshold for a balanced load at CPU idle to reduce possible higher idle temperatures when running on just one core.
 *        (inspired by JustArchi's observations, thx!)
 *	- added hotplug block cycles to reduce possible hotplugging overhead (credits to ktoonsez)
 *	- added possibility to disable hotplugging only at suspend (inspired by a request of STAticKY, thx for the idea)
 *	- introduced hotplug frequency thresholds (credits to Yank555)
 *	- hotplug tuneables handling optimized (credits to Yank555)
 *	- added version information tuneable (credits to Yank555)
 *
 *	  for this functions following new tuneables were indroduced:
 *
 *	  legacy_mode			-> for switching to the "old" method of scaling/hotplugging. possible values 0 to disable,
 *					   any values above 0 to enable (default is 0)
 *	  				   NOTE: the legacy mode has to be enabled by uncommenting the macro ENABLE_LEGACY_MODE below!
 *	  hotplug_idle_threshold	-> amount of load under which hotplugging should be disabled at idle times (respectively at scaling minimum).
 *					   possible values 0 disable, from 1 to 100 (default is 0)
 *	  hotplug_block_cycles		-> slow down hotplugging by waiting a given amount of cycles before plugging.
 *					   possible values 0 disbale, any values above 0 (default is 0)
 *	  disable_hotplug_sleep		-> same as disable_hotplug but will only take effect at suspend.
 *					   possible values 0 disable, any values above 0 to enable (default is 0)
 *	  up_threshold_hotplug_freq1	-> hotplug up frequency threshold for core1.
 *					   possible values 0 disable and range from over down_threshold_hotplug_freq1 to max scaling freqency (default is 0)
 *	  up_threshold_hotplug_freq2	-> hotplug up frequency threshold for core2.
 *					   possible values 0 disable and range from over down_threshold_hotplug_freq2 to max scaling freqency (default is 0)
 *	  up_threshold_hotplug_freq3	-> hotplug up frequency threshold for core3.
 *					   possible values 0 disable and range from over down_threshold_hotplug_freq3 to max scaling freqency (default is 0)
 *	  down_threshold_hotplug_freq1	-> hotplug down frequency threshold for core1.
 *					   possible values 0 disable and range from min saling to under up_threshold_hotplug_freq1 freqency (default is 0)
 *	  down_threshold_hotplug_freq2	-> hotplug down frequency threshold for core2.
 *					   possible values 0 disable and range from min saling to under up_threshold_hotplug_freq2 freqency (default is 0)
 *	  down_threshold_hotplug_freq3	-> hotplug down frequency threshold for core3.
 *					   possible values 0 disable and range from min saling to under up_threshold_hotplug_freq3 freqency (default is 0)
 *	  version			-> show the version of zzmoove governor