cpufreq: Manage only online cpus

cpufreq core doesn't manage offline cpus and if driver->init() has returned
mask including offline cpus, it may result in unwanted behavior by cpufreq core
or governors.

We need to get only online cpus in this mask. There are two places to fix this
mask, cpufreq core and cpufreq driver. It makes sense to do this at common place
and hence is done in core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
cpufreq: Save user policy min/max instead of policy min/max during hotplug

When a CPU is hotplugged off, various fields of the policy are saved so
that they can be restored when the CPU is hotplugged back in.

The existing code saves the policy min/max field during hotplug remove and
restores it into user policy min/max during hotplug add. This results in
the loss of the user policy min/max values across a hotplug remove/add.

Fix it by saving the user policy min/max instead of policy min/max during
hotplug remove. During a hotplug add, after user policy min/max is
restored, the policy min/max is already recomputed. So, there's no risk of
going beyound any limits imposed by the CPUFREQ_ADJUST/INCOMPATIBLE
notifiers.

Change-Id: Ib8e09fa324c1f80f095c5754b5dcf2685e8e4a66
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
cpufreq: Optimize cpufreq_frequency_table_verify()

cpufreq_frequency_table_verify() is rewritten here to make it more logical
and efficient.
 - merge multiple lines for variable declarations together.
 - quit early if any frequency between min/max is found.
 - don't call cpufreq_verify_within_limits() in case any valid freq is
   found as it is of no use.
 - rename the count variable as found and change its type to boolean.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
cpufreq: Fix policy getting stuck when user & kernel min/max don't overlap

Every __cpufreq_set_policy starts with checking the new policy min/max has
some overlap with the current policy min/max. This works out fine until we
end up with the policy min/max being set to a range that doesn't overlap
with the user policy min/max. Once we get into this situation, the check at
the start of __cpufreq_set_policy fails and prevents us from getting out of
this state.

This only happens when one of the CPUFREQ_ADJUST/CPUFREQ_INCOMPATIBLE
notifiers called inside __cpufreq_set_policy pick a min/max outside the
range of user policy min/max.

The real intent of the check at the start of __cpufreq_set_policy is to
make sure userspace can't set user policy min > user policy max. Since
__cpufreq_set_policy always gets called only with current user policy
min/max except when the actual user space policy min/max is changed, we can
fix the issue by simply checking the new policy min/max against current
user policy min/max.

Change-Id: Iaac805825e64d7985c41fb9052bd96baacdf3d6f
Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
kgsl: merge Interactive GPU governor.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: gpu: improve my gpu governor algorithm.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: kgsl: small change on the do_div operation.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: kgsl: no need to cast long because jiffies and window_time are already long.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: kgsl: change the load calculation equation & fix a couple of bugs, one of 'em was keeping the GPU on 320MHz if the GPU was not sleeping.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: kgsl: don't forcefully ramp down on sleep if there's still load higher than down_threshold.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: kgsl: remove the sample_time_ms and let the governor run its idle_check freely like Qualcomm intends. I was seeing some frames being lost because the sample_time_ms was too big.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
thermal: add my thermaldriver. Has a couple bits from original msm_thermal, but its generally stripped down. Default throtling point is 70ºC.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
drivers: thermal: fix throttling behavior.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
drivers: thermal: add more steps to prevent L1/TLB panic on weaker hardware. Before this commit it was easily reproduced by running Antutu Benchmark and it would crash on the CPU Floating point test. It won't crash anymore with the current settings due to be already throttled point when reaching that stage.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: therma: fix a derp where the device would be slammered to 729Mhz if it reached the thermal throttle threshold.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
msm: thermal: improve robustness of the thermal throttle routine.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
thermal: code cleanup.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: thermal: do not trigger the verify within limits when cpus go online/offline. Also do not make the workqueue available to the freezer path, we want the workqueue to be active and ready to recieve new works even during freezer phase.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: thermal: fix a bug where if a user underclocked + got thermal throttled he couldn't move max freq past the underclocked value.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
msm: thermal: decrease thermal threshold to 60C.

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>