sched: Limit setaffinity with CPU_HOTPLUG

Some applications do not count CPU's correctly and make bad
decisions on systems with hotplugged CPU's.

Limit app's ability to use setaffinity based on CONFIG_CPU_HOTPLUG.

Change-Id: I133cff0c0c71553ca1febfb044dba59bda38cb33
Signed-off-by: Chris Fries <C.Fries@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/528092
SLT-Approved: Gerrit Code Review <gerrit-blurdev@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Christopher Fries <qcf001@motorola.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Igor Kovalenko <cik009@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
ARM: smp: Wait just 1 second for other CPU to halt

Currently, the busyloop waiting for a 2nd CPU to stop takes about 4
seconds.  Adjust for the overhead of the loop by looping every 1ms
instead of 1us.

Change-Id: If04a4dc16425fff3898233eea2a0fff95f5db287
Signed-off-by: Chris Fries <C.Fries@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/537864
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Igor Kovalenko <cik009@motorola.com>
Reviewed-by: Russell Knize <rknize2@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
[LINARO] workqueues: Introduce new flag WQ_POWER_EFFICIENT for power oriented workqueues

Adapted for 3.4 from lsk-v3.10

Workqueues can be performance or power-oriented. Currently, most workqueues are
bound to the CPU they were created on. This gives good performance (due to cache
effects) at the cost of potentially waking up otherwise idle cores (Idle from
scheduler's perspective. Which may or may not be physically idle) just to
process some work. To save power, we can allow the work to be rescheduled on a
core that is already awake.

Workqueues created with the WQ_UNBOUND flag will allow some power savings.
However, we don't change the default behaviour of the system.  To enable
power-saving behaviour, a new config option CONFIG_WQ_POWER_EFFICIENT needs to
be turned on. This option can also be overridden by the
workqueue.power_efficient boot parameter.

tj: Updated config description and comments.  Renamed
    CONFIG_WQ_POWER_EFFICIENT to CONFIG_WQ_POWER_EFFICIENT_DEFAULT.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
(cherry picked from commit cee22a15052faa817e3ec8985a28154d3fabc7aa)
Signed-off-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>

Conflicts:
	kernel/workqueue.c
[LINARO] workqueue: Add system wide power_efficient workqueues

Adapted for 3.4 from lsk-v3.10

This patch adds system wide workqueues aligned towards power saving. This is
done by allocating them with WQ_UNBOUND flag if 'wq_power_efficient' is set to
'true'.

tj: updated comments a bit.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
(cherry picked from commit 0668106ca3865ba945e155097fb042bf66d364d3)
Signed-off-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
[LINARO] block: queue work on power efficient wq

Adapted for 3.4 from lsk-v3.10

Block layer uses workqueues for multiple purposes. There is no real dependency
of scheduling these on the cpu which scheduled them.

On a idle system, it is observed that and idle cpu wakes up many times just to
service this work. It would be better if we can schedule it on a cpu which the
scheduler believes to be the most appropriate one.

This patch replaces normal workqueues with power efficient versions.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
(cherry picked from commit 695588f9454bdbc7c1a2fbb8a6bfdcfba6183348)
Signed-off-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
[LINARO] PHYLIB: queue work on system_power_efficient_wq

Adapted for 3.4 from lsk-v3.10

Phylib uses workqueues for multiple purposes. There is no real dependency of
scheduling these on the cpu which scheduled them.

On a idle system, it is observed that and idle cpu wakes up many times just to
service this work. It would be better if we can schedule it on a cpu which the
scheduler believes to be the most appropriate one.

This patch replaces system_wq with system_power_efficient_wq for PHYLIB.

Cc: David S. Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Tejun Heo <tj@kernel.org>
(cherry picked from commit bbb47bdeae756f04b896b55b51f230f3eb21f207)
Signed-off-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
[LINARO] ASoC: pcm: Use the power efficient workqueue for delayed powerdown

Adapted for 3.4 from lsk-v3.10

There is no need to use a normal per-CPU workqueue for delayed power downs
as they're not timing or performance critical and waking up a core for them
would defeat some of the point.

Signed-off-by: Mark Brown <broonie@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
(cherry picked from commit d4e1a73acd4e894f8332f2093bceaef585cfab67)
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
[LINARO] regulator: core: Use the power efficient workqueue for delayed powerdown

There is no need to use a normal per-CPU workqueue for delayed power downs
as they're not timing or performance critical and waking up a core for them
would defeat some of the point.

Signed-off-by: Mark Brown <broonie@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Liam Girdwood <liam.r.girdwood@intel.com>
(cherry picked from commit 070260f07c7daec311f2466eb9d1df475d5a46f8)

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
[LINARO] ASoC: jack: Use power efficient workqueue

The accessory detect debounce work is not performance sensitive so let
the scheduler run it wherever is most efficient rather than in a per CPU
workqueue by using the system power efficient workqueue.

Signed-off-by: Mark Brown <broonie@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
(cherry picked from commit e6058aaadcd473e5827720dc143af56aabbeecc7)

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
defconfig: CONFIG_WQ_POWER_EFFICIENT_DEFAULT
ARM: timer-sp: Set dynamic irq affinity

When a cpu goes to a deep idle state where its local timer is shutdown, it
notifies the time frame work to use the broadcast timer instead.

Unfortunately, the broadcast device could wake up any CPU, including an idle one
which is not concerned by the wake up at all.

This implies, in the worst case, an idle CPU will wake up to send an IPI to
another idle cpu.

This patch fixes this for ARM platforms using timer-sp, by setting
CLOCK_EVT_FEAT_DYNIRQ feature.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
ARM: msm: Configure Krait-specific setting

Set Krait-specific configuration setting when enabling
MMU only on appropriate cores.

Signed-off-by: Osvaldo Banuelos <osvaldob@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
perf/arm: Fix armpmu_map_hw_event()

Fix constraint check in armpmu_map_hw_event().

Reported-and-tested-by: Vince Weaver <vincent.weaver@maine.edu>
Cc: <stable@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Patrick Tjin <pattjin@google.com>
staging: android: lowmemorykiller: select a new task to kill

Under certain circumstances, a process may take time to handle a SIGKILL.
When lowmemkiller is called again shortly after, it would pick the same
process to kill over and over, so that we cann't get free memory for long time.

Solution is to check fatal_signal_pending() on the selected task, and if it's
already pending, select a new task to kill.

Cherry-pick 5e3358093351e5d48e21250e31896b855542f22c
Reviewed-on: http://gerrit.pcs.mot.com/479831

Change-Id: I53445114451ffaba293f3c7174fb0b01ed0d34b6
Signed-off-by: Tianshui Shi <kfp634@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/505410
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
Reviewed-by: Jason Hrycay <jason.hrycay@motorola.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
(cherry picked from commit da093001caf06ed2296b4f79c84cc48ce713eac6)

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
mm: compaction: compact normal zone

Compact normal zone when system run into early suspend.

There isn't need to compact other zones since there isn't
big memory block needs in those zones on our platform.

This is ported from the following patch:

 * (CR) compact normal zone only in early suspend
   Reviewed-on: http://gerrit.pcs.mot.com/494963

Change-Id: If81d1d440a365bd54a6bd6d23ef851493280692c
Signed-off-by: Yi-wei Zhao <gbjc64@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/507168
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Jason Hrycay <jason.hrycay@motorola.com>
(cherry picked from commit a8cb0d740ddbe26511f280b958d6c6b41e7bb7e2)

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
compact all zones on earlysuspend

mm: compaction: add Android-specific hook.

On larger memory configurations the bulk of memory is in the high
zone and in the 3.4 Android kernels ION and KGSL attempt to make
large allocations. So it's no longer enough to compact just normal
zone. That simplifies things by removing the need for some code.
The suitability of compaction per zone is checked implicitly, so we
will only do anything "expensive" when there's a good reason. Given
that the screen is off at that time, user won't notice anything.
This takes about 150ms on 2GB configuration with MSM8960pro CPU.

Also the code added previously to install earlysuspend handler
was not properly checking for CONFIG_HAS_EARLYSUSPEND, which means
Android-specific code has been stuffed into generic kernel code.
Fix that too, while we're at it.

Change-Id: Icd7b5ec3a304d47611602bdac3e2aad6f4faf8c1
Signed-off-by: Igor Kovalenko <cik009@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/522737
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit 88cdf7ab16589afff4f72226980541e15816c8f4)

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
mm: compaction: do suspend compaction in workqueue

Move compact_nodes_suspend out of the direct early suspend workqueue
to avoid long delays in the suspend path on a heavily loaded system;
examples being heavily use of filesystem contending with the pages
that are trying to be compacted.

Signed-off-by: Yuan Jiangli <jlyuan@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/535748
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Christopher Fries <qcf001@motorola.com>
Reviewed-by: Igor Kovalenko <cik009@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>

(cherry-pick from commit  6e202c2572708430f682987b2240eae50dadb1e3)

Change-Id: Ifcf8e0ff8f60d3c7f099d95653a43ba9651eeb28
Reviewed-on: http://gerrit.pcs.mot.com/540977
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
mm: page_alloc: retry direct compaction

When system load is heavy, memory commpaction may encounter
transient failure; add retry mechanism. And add the following
statistic variable "compact_retry_success" in /proc/vmstat
to see how many compaction success due to the retry.

And __zone_watermark_ok() will easily return false when system
is busy, which will make compaction failure as well. Amend some
to save margin cases.

This patch is ported from the patch:
 * (CR) mem compaction enhancement
   Reviewed-on: http://gerrit.pcs.mot.com/494962

Change-Id: I049a29542926d94f78c723278a711bbf6a87b4a1
Signed-off-by: Yi-wei Zhao <gbjc64@motorola.com>

Conflicts:

	mm/page_alloc.c

Signed-off-by: Luis Cruz <ljc2491@gmail.com>
msm: bam_dmux: UL inactivity timeout is too high

Reduce UL_TIMEOUT from 1000 ms to 200 ms to improve current drain
for idle use case.

Change-Id: I83eba12e28506735ff15f52533dda653872fc9f2
Signed-off-by: Alexander Filonenko <vtp684@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/538334
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Connie Zhao <czhao1@motorola.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Reviewed-by: Igor Kovalenko <cik009@motorola.com>
Reviewed-by: Christopher Fries <c.fries@motorola.com>
SLT-Approved: Christopher Fries <c.fries@motorola.com>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>
Delay UL powerdown if BAM is in polling mode

Change-Id: I982c669863390d5ea828d8dd3158e76dab3163e9
Reviewed-on: http://gerrit.pcs.mot.com/548359
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Igor Kovalenko <cik009@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Alexander Filonenko <alexf@motorola.com>
SLT-Approved: Christopher Fries <c.fries@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: Luis Cruz <ljc2491@gmail.com>