cpuquiet: Add GCOV_PROFILE

Include cpuquiet in GCOV profiling when enabled by defconfig.

Change-Id: I448602d2c79f4113b99e6546743585e629fa726e
Signed-off-by: Juha Tukkinen <jtukkinen@nvidia.com>
Reviewed-on: http://git-master/r/131127
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>

Rebase-Id: R7daa534f10a211bf7b15a253f5cfee7a126428f0

Conflicts:
	drivers/cpuquiet/Makefile
cpuquiet: Add GCOV_PROFILE for governors

Include cpuquiet in GCOV profiling when enabled by defconfig.

Change-Id: Iadac806d4b7efd9e34afa765dbec59f0491b96a8
Signed-off-by: Juha Tukkinen <jtukkinen@nvidia.com>
Reviewed-on: http://git-master/r/192980
Reviewed-by: Automatic_Commit_Validation_User
cpuquiet: Fix warning about unused variable

drivers/cpuquiet/governors/runnable_threads.c: In function 'runnables_work_func':
drivers/cpuquiet/governors/runnable_threads.c:184:14: warning: unused variable 'state' [-Wunused-variable]

Change-Id: I26c2288876043cf3dd21e1b57317a1f5b2de5a9b
Signed-off-by: Sami Liedes <sliedes@nvidia.com>
Reviewed-on: http://git-master/r/197469
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
cpuquiet: Remove synchronization from runnables_work_func()

runnables_stop() can deadlock when cancel_work_sync() waits for the
work function to end and the work function blocks on the same lock
held by runnables_stop().

Removing the locks from runnables_work_func() fixes this. This should
be safe because runnables_lock protects runnables_state and
runnables_work_func() only reads runnables_state. Also, the functions
that change state to DISABLED do a cancel_work_sync() to guarantee the
work function stopped running.

Bug 1215668

Change-Id: I70617b3b0fc81db8555869e67e3b11652af8d94c
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-on: http://git-master/r/193881
Reviewed-by: Mandar Padmawar <mpadmawar@nvidia.com>
Tested-by: Mandar Padmawar <mpadmawar@nvidia.com>
ARM: tegra: cpuquiet: Fix cpuquiet notifiers

The notifiers now properly fire on every cluster switch

Change-Id: I381301cf62f25b49532326cc7759696c7f6797b7
Signed-off-by: Sai Charan Gurrappadi <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/118376
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

Rebase-Id: Rd93d027e02b4f1122becef42916b28e652c76980
ARM: tegra: Ignore PmQos when disabled

The cpu hotplug drivers should only bother updating state or switching
to the G cluster if the driver is not disabled

Bug 1032096

Change-Id: Ice938b094bbf48fef47afa3915b1a48362fb256d
Signed-off-by: Sai Charan Gurrappadi <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/122859
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Aleksandr Frid <afrid@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

Rebase-Id: R8840db867a4b54be73d296dd26c9935f4112aeee
cpuquiet: Fix cpuquiet for k3.4

Change-Id: I75d8dba6c9c4c43152c819e08beeccb1e3c07c0c
Signed-off-by: Sai Charan Gurrappadi <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/123850
Reviewed-by: Varun Colbert <vcolbert@nvidia.com>
Tested-by: Varun Colbert <vcolbert@nvidia.com>

Rebase-Id: R06aaf7d4745c3b989c1329115df3dd804b0b35a9
cpuquiet: Enable cpuquiet by default

Enable cpuquiet by default if autohotplug is enabled. Cpuquiet will now
replace autohotplug as the hotplugging infrastructure. The down_delay in
the balanced governor has also been increased to 2s from 500ms to match
a similar patch for autohotplug.

Change-Id: I36747af67c55547b3dee95f7d435f9ebc075d393
Signed-off-by: Sai Charan Gurrappadi <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/123851
Reviewed-by: Varun Colbert <vcolbert@nvidia.com>
Tested-by: Varun Colbert <vcolbert@nvidia.com>

Rebase-Id: R80c32cedfac36c7b342ca8dee58a5991e1d60439

Conflicts:
	arch/arm/mach-tegra/Makefile
cpuquiet: Add notifiers for the runnables governor

The governor stops sampling whenever the device is busy and starts its
sampling loop when the device is free.

Change-Id: Ifdae4a84e56c2734be48e49f6112b537602a02da
Signed-off-by: Sai Charan Gurrappadi <sgurrappadi@nvidia.com>
Reviewed-on: http://git-master/r/124680
Reviewed-by: Varun Colbert <vcolbert@nvidia.com>
Tested-by: Varun Colbert <vcolbert@nvidia.com>

Rebase-Id: R5caf7ff378d963d090369e0c0b65f8328234de3e
ARM: tegra: cpuquiet: Bring back hotplug stats support

Hotplug stats are needed for dfs_log and Power Signature. Cpuquiet
provides similar stats in the core layer, but cannot provide stats for
LP cpu, since this is only visible at the driver level.

Bug 1045785

Change-Id: I6c5c26912d1a26637e81c73741637fbd2bee6157
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-on: http://git-master/r/131210
Reviewed-by: Automatic_Commit_Validation_User
Tested-by: Shaoming Feng <shaomingf@nvidia.com>
Reviewed-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
GVS: Gerrit_Virtual_Submit

Rebase-Id: R8e578267939d0bcde96d4851fb46b44da78baf28
ARM: tegra: cpuquiet: add min/max_cpus debugfs nodes back

Bug 1047573

Change-Id: I7209ca87075b3d8a1d53141c48fe8fbdd86c4728
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-on: http://git-master/r/131606
Reviewed-by: Automatic_Commit_Validation_User
Tested-by: Ilan Aelion <iaelion@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

Rebase-Id: R81f2ceacae7865e1941c3eb7fb3950a9a0195f5c
ARM: tegra: cpuquiet: Bring back hotplug stats support

Hotplug stats are needed for dfs_log and Power Signature. Cpuquiet
provides similar stats in the core layer, but cannot provide stats for
LP cpu, since this is only visible at the driver level.

Bug 1045785

(cherry picked from commit ec6f32c8c39b574a6d01596a8d31060e47d20905)
Reviewed-on: http://git-master/r/134271

Change-Id: I808c5b9597d32d7297257d4cf8767aa0f9ab0473
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Signed-off-by: Deepak Nibade <dnibade@nvidia.com>
Reviewed-on: http://git-master/r/143137
Reviewed-by: Rohan Somvanshi <rsomvanshi@nvidia.com>
Tested-by: Rohan Somvanshi <rsomvanshi@nvidia.com>

Rebase-Id: R6dc5d809303f53eb71031c8c947c754426db4889
ARM: tegra: refactor cpuquiet driver

Refactor the cpuquiet driver to use 1 workqueue which handles the
clusterswitch and cpu online/offline operations.

Functional changes compared to the previous driver:

+ changing no_lp also triggers a clusterswitch if the current cluster is the
  LP cluster.

+ removing all QoS constraints will return to the configuration as defined by
  the governor.

+ the minimum CPUs online QoS constraint will always prevail above the maximum
  CPUs online constraint. If both constraints are set, the maximum CPUs online
  constraint will be clamped to the minimum constraint.

bug 1047545
bug 1055406

Change-Id: Ib52de2578254c282f23f972484a6532d24fdc0e9
Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-on: http://git-master/r/134391
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
ARM: tegra: cpuquiet: Fix compiler warnings

Bug 1055406

Change-Id: I5033cc19e170d932c3697821a0f3273957789995
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-on: http://git-master/r/164384
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Peter De Schrijver <pdeschrijver@nvidia.com>
ARM: tegra: avoid race condition between cpufreq and clusterswitch

Avoid a race condition between cpufreq and clusterswitch and also make writes
to no_lp and enable synchronous operations.

bug 1178947

Change-Id: Ib9608f8a0a22be84d3c0916babb7e43c1f6df2e1
Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-on: http://git-master/r/165751
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
ARM: tegra: Rework timer for clusterswitching

This patch introduces a separate timer for clusterswitching. The timer will
queue the usual workitem on expiry. This allows all other operations to
happen immediately without having to cancel a delayed workitem. It also allows
the timer itself to be canceled when the conditions for a clusterswitch are
no longer fulfilled.

bug 1178947

Change-Id: Ieb63baf5a38ebcca29ad938365e46530f755a105
Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-on: http://git-master/r/170533
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Tested-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
ARM: tegra: only do clusterswitching in 1 CPU mode

Only consider clusterswitching when there is a single CPU online.
This is done by ignoring frequency changes when there are more cores
online and registering a notifier to immediately switch to the slow
cluster if there is only 1 CPU online and the frequency is below
idle_bottom_freq.

bug 1178947
bug 1202877

Change-Id: I1244f866de1d32c268d36c835cd90d9c6cba1481
Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-on: http://git-master/r/172346
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
ARM: tegra: Only check for LP switch on CPU_POST_DEAD

Apparently the cpu hotplug notifier can be called when the kernel can't sleep.
In those cases blocking operations can cause a kernel panic. Solve this by
only doing potentially blocking operations when a CPU has been removed. This
shouldn't cause any power regressions as we can only switch to the slow
cluster when only CPU0 is online.

Bug 1189926
Bug 1211686
Bug 1213817

Change-Id: I54356d2a8a8ae3a5253b9b2c216ada283955e585
Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-on: http://git-master/r/188688
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Shridhar Rasal <srasal@nvidia.com>
ARM: tegra: cpuquiet: Honor G->LP delay on last core down

We cluster switch G->LP when 2 conditions are met:
1) we are in single core mode
2) CPU freq reaches idle_bottom_freq

After these 2 conditions are met, we wait for down_delay ms before
cluster switching. This patch ensures the timeout is also honored when
the first condition is met last.

Bug 1226607

Change-Id: Ic36f9cab09a5967b71409e44dbe89290f39cb26b
Signed-off-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-on: http://git-master/r/196171
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
ARM: tegra: cpuquiet: make userspace governor actions synchronous

Userspace expects changes to happen synchronously. Implement this by waiting
with a (configureable) timeout for the action to happen.

Bug 1220065

Change-Id: I81301719707e4baf2b3aea62c38fc771ffe1205d
Signed-off-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-on: http://git-master/r/200013
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

Conflicts:
	include/linux/cpuquiet.h