Revert "sched: Remove get_online_cpus() usage"

This reverts commit 7755290e4ee70b2ec1094452bb19fbd6053d5b68.

Revert "sched: Remove extra put_online_cpus() inside sched_setaffinity()"

This reverts commit 0372a8eb16e69345a12c1e1ce3c5e1aa4a758dca.

Revert "sched: Fix endless sync_sched/rcu() loop inside _cpu_down()"

This reverts commit 2baf8e44494bc6bd5e002d51740191f2c0da2470.

Revert "sched: Remove get_online_cpus() usage"

This reverts commit f0fbb1d0126e81adfb565474b5a3fd73425a98d0.

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
sched: Make scheduler aware of cpu frequency state

Capacity of a cpu (how much performance it can deliver) is partly
determined by its frequency (P) state, both current frequency as well
as max frequency it can reach.  Knowing frequency state of cpus will
help scheduler optimize various functions such as tracking every
task's cpu demand and placing tasks on various cpus.

This patch has scheduler registering for cpufreq notifications to
become aware of cpu's frequency state. Subsequent patches will make
use of derived information for various purposes, such as task's scaled
load (cpu demand) accounting and task placement.

Change-Id: I376dffa1e7f3f47d0496cd7e6ef8b5642ab79016
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
sched: window-based load stats for tasks

Provide a metric per task that specifies how cpu bound a task is. Task
execution is monitored over several time windows and the fraction of
the window for which task was found to be executing or wanting to run
is recorded as task's demand. Windows over which task was sleeping are
ignored. We track last 5 recent windows for every task and the maximum
demand seen in any of the previous 5 windows (where task had some
activity) drives freq demand for every task.

A per-cpu metric (rq->cumulative_runnable_avg) is also provided which
is an aggregation of cpu demand of all tasks currently enqueued on it.
rq->cumulative_runnable_avg will be useful to know if cpu frequency
will need to be changed to match task demand.

Change-Id: Ib83207b9ba8683cd3304ee8a2290695c34f08fe2
Signed-off-by: Srivatsa Vaddagiri <vatsa@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
cpufreq: cpu-boost: Introduce scheduler assisted load based syncs

Previously, on getting a migration notification cpu-boost changed
the scaling min of the destination frequency to match that of the
source frequency or sync_threshold whichever was minimum.

If the scheduler migration notification is extended with task load
(cpu demand) information, the cpu boost driver can use this load to
compute a suitable frequency for the migrating task. The required
frequency for the task is calculated by taking the load percentage
of the max frequency and no sync is performed if the load is less
than a particular value (migration_load_threshold).This change is
beneficial for both perf and power as demand of a task is taken into
consideration while making cpufreq decisions and unnecessary syncs
for lightweight tasks are avoided.

The task load information provided by scheduler comes from a
window-based load collection mechanism which also normalizes the
load collected by the scheduler to the max possible frequency
across all CPUs.

Change-Id: Id2ba91cc4139c90602557f9b3801fb06b3c38992
Signed-off-by: Rohit Gupta <rohgup@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
sched: Call the notify_on_migrate notifier chain for wakeups as well

Add a change to send notify_on_migrate hints on wakeups of
foreground tasks from scheduler if their load is above
wakeup_load_thresholds (default value is 60).
These hints can be used to choose an appropriate CPU frequency
corresponding to the load of the task being woken up.

Change-Id: Ieca413c1a8bd2b14a15a7591e8e15d22925c42ca
Signed-off-by: Rohit Gupta <rohgup@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
cpufreq: cpu-boost: Handle wakeup hints received for foreground tasks

A previous change modifies the notification conditions in the scheduler
to call the notifier chain even on foreground_thread wakeups for tasks
having load more than a threshold value.

If load_based_syncs is turned OFF then we do not need to perform
cpu boost for wakeup hints for foreground tasks from scheduler

Change-Id: Ifbdd3eccac5c9892dfc3a3c3edbfc0df766478ed
Signed-off-by: Rohit Gupta <rohgup@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
sched: Disable wakeup hints for foreground tasks by default

By default sched_wakeup_load_threshold is set to 60 and therefore
wakeup hints are sent out for those tasks whose loads are higher
that value. This might cause unnecessary wakeup boosts to happen
when load based syncing is turned ON for cpu-boost.
Disable the wake up hints by setting the sched_wakeup_load_threshold
to a value higher than 100 so that wakeup boost doesnt happen unless
it is explicitly turned ON from adb shell.

Change-Id: I9b8a594c2bfdf2e092cc645e50c0c21efc514c2f
Signed-off-by: Rohit Gupta <rohgup@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
msm: kgsl: Update calculation for graphics IOMMU context IDs

Calculate graphics IOMMU context IDs using the 'label' property of
the device tree node of that context. Context IDs are independent
of the register addresses of the SMMU device and its contexts, which
change for every target.

Change-Id: I16825d7248081997a442d4fb59ca5b04b88e33fd
Signed-off-by: Lokesh Batra <lbatra@codeaurora.org>
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
Signed-off-by: Prabhat Awasthi <pawasthi@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
mmc: sdhci-msm: fix issue with tuning command

As of now we ignore CRC/INDEX command failures to tuning command
and still wait for data from card but in case the card did not
receive the command, it won't send the data. This is causing
software request timeout for tuning commands. Hence, software
must not ignore such cmd errors for tuning commands but end the
request immediately after resetting the controller for both CMD
and DATA. Also, wait for 146 MCLK cycles for card to send out the
data and thus to move to transfer state. Its corresponding phase must
also be considered as bad phase.

CRs-fixed: 625855
Change-Id: Ic8462dd9c67e4f18a3ce73d972591772be8c6d10
Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
msm: rq_stats: Disable hotplug and stats by default

Userspace closed source mpdecision binary is nessecary for PowerHAL to work.
As it depends on rq_stats, let's at least disable hotplugging and stats
collection by default. /sys/devices/system/cpu/cpu0/rq-stats/hotplug_disable
is now writable, so hotplug can be reenabled.

Also, add some bits related to current cpu policy.

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
Revert "defconfig: Disable MSM Run Queue stats"

This reverts commit 9f3770e95b14e2fb5f194212cb12565977b2dd44.

We do this a little bit smarter now.

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
msm: hotplug: On- and offline cpus only when enabled

I mean really, really enabled...

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
sched: Calculate max_possible_freq based on current policy->max

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
cpufreq: ondemand: Calculate load_at_max_freq based on current policy->max

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
ARM: dts: msm8974: Allow power collapse as minimum l2 gdhs mode

This fixes warnings "IRQ40 no longer affine to CPUn". The switch
to C2 is also hardly understandable.

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
PM / devfreq: Get priv data for msm-adreno-tz governor from dev_profile

The devfreq infrastructure has several bugs and general design flaws
with private governor data support. As a workaround the msm-adreno-tz
governor gets it's private data from the device driver by doing a
container_of on the dev_profile registered by the device driver.

[myfluxi: Adapt to 8974, add yet unused stuff for conservative governor]

Change-Id: Ib9dffd063fe3aa5cfd55727d41f7633e88b3f998
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
soc: qcom: rq_stats: remove the redundant iowait check

Iowait_time check is redundant and it would lead to heavy load
due to miscaluculation of idle time. Hence remove this check
as iowait will considered based on io_busy flag.

[myfluxi: Adapt to msm 8974]

Change-Id: I4dd9f9c79205eca588daea8cc0fe892394a83391
CRs-fixed: 662052
Signed-off-by: Anji Jonnala <anjir@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
msm: hotplug: Remove the redundant iowait check

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
PM: devfreq: Fix simple_ondemand crashing on startup

Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>
msm: ocmem: Add macro and region size information to ocmem region

Some targets support half sized macros in the last region. Previously,
for these regions, only half the macros were turned on, and the clients
could not access memory. Read the hardware register to check if the
target supports half sized macros and update the calculation to switch
memory power states.

Change-Id: Idb6e6b8c11b42d3e0a72fa27bd8c63e48282af97
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
Signed-off-by: Joao Paulo <joaolrpaulo@gmail.com>