lowmemorykiller.c: convert to use for_each_thread

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit ecf5772a34f936f5a7926669183fb87296fe93a6)
Signed-off-by: thirdzcee <thirdzcee@github.com>
introduce for_each_thread() to replace the buggy while_each_thread() (fix)

fix a merge derp. pointed out by neobuddy89

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit a1d9d9819c281c277775dbcb9464367a73edc928)
Signed-off-by: thirdzcee <thirdzcee@github.com>
Cpufreq: create/remove percpu sysfs nodes once

On cpu hotplug on/off, percpu "cpufreq" sysfs node and it's
sub nodes are freshly created and removed. This increases
cpu up/down latency.

Create percpu "cpufreq" sysfs node and it's sub nodes in driver
registration and remove it in unregistration. This decreases
cpu up/down latency significantly.

Change-Id: I5c2b02e74de0ae4fe08dedc959bd7402cd9b7aa5
Signed-off-by: Puneet Saxena <puneets@nvidia.com>
Reviewed-on: http://git-master/r/146812
(cherry picked from commit 298382285677fa791098d117ccc0a0a3d9ab0f9a)
Reviewed-on: http://git-master/r/219379
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Sachin Nikam <snikam@nvidia.com>

modified for use on Mako by faux123

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit a220115114d215bd0df953bb13232779eb053bdf)
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	drivers/cpufreq/cpufreq.c
msm_cpu_freq_limit: initial coding for controlling MSM quadcore cpus

this module will allow proper max frequency control across all msm cores

Signed-off-by: Paul Reioux <reioux@gmail.com>

Conflicts:

	arch/arm/mach-msm/Makefile

Conflicts:

	arch/arm/mach-msm/Makefile

(cherry picked from commit 8f9400a10abeb78e9f5cab3eeb3649919aece0c9)
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	arch/arm/mach-msm/Kconfig
	arch/arm/mach-msm/Makefile
msm_cpufreq_limit: add GPL V2 licensing to access to GPL symbols

Signed-off-by: faux123 <reioux@gmail.com>
(cherry picked from commit 527516deb9dfe7291ec331ccc680429913c8dd0c)
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	Makefile
cpufreq_limit: remove unused vars

Signed-off-by: faux123 <reioux@gmail.com>
(cherry picked from commit 165856014ba56884cfb94b778f0405161e14306c)
Signed-off-by: thirdzcee <thirdzcee@github.com>
mach-msm:cpufreq_limit: fix merge derp and minor code clean up

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 3ba1332605b1290e33d2263b4d40af0f1acd5d48)
Signed-off-by: thirdzcee <thirdzcee@github.com>
msm_turbo: initial coding for turbo boost on MSM architectures

tweaked for dual core architectures

Signed-off-by: Paul Reioux <reioux@gmail.com>
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:

	arch/arm/mach-msm/Kconfig

(cherry picked from commit 8615eec67231bf1e2213e9ee84c48f8dc9f0a81b)
Signed-off-by: thirdzcee <thirdzcee@github.com>
cpufreq: inject cpu turbo boost

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit c3bfd41fe85af286ec1e0f386ea3edf14c169e92)
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	arch/arm/mach-msm/cpufreq.c
cpufreq_limit: adapted for use as built-in kernel option

set default stock frequency and remove unnecessary debug messages

bump version to 1.2

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 6f67907c999bc22628b98146cd7aa49a50c7de8c)
Signed-off-by: thirdzcee <thirdzcee@github.com>
cpufreq: fix a logic derp with turbo boost

also enforce cpu limit at all times

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 17c7d826b89a541a618ba19a872817edbe3baf0a)
Signed-off-by: thirdzcee <thirdzcee@github.com>
cpufreq_limit: adapt for 8960

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit e696d51db62d3a668162ff49fc693bc3f6457656)
Signed-off-by: thirdzcee <thirdzcee@github.com>
Makefile: add new ARM specific flag

Signed-off-by: thirdzcee <thirdzcee@github.com>
introduce for_each_thread() to replace the buggy while_each_thread()

while_each_thread() and next_thread() should die, almost every lockless
usage is wrong.

1. Unless g == current, the lockless while_each_thread() is not safe.

   while_each_thread(g, t) can loop forever if g exits, next_thread()
   can't reach the unhashed thread in this case. Note that this can
   happen even if g is the group leader, it can exec.

2. Even if while_each_thread() itself was correct, people often use
   it wrongly.

   It was never safe to just take rcu_read_lock() and loop unless
   you verify that pid_alive(g) == T, even the first next_thread()
   can point to the already freed/reused memory.

This patch adds signal_struct->thread_head and task->thread_node to
create the normal rcu-safe list with the stable head.  The new
for_each_thread(g, t) helper is always safe under rcu_read_lock() as
long as this task_struct can't go away.

Note: of course it is ugly to have both task_struct->thread_node and the
old task_struct->thread_group, we will kill it later, after we change
the users of while_each_thread() to use for_each_thread().

Perhaps we can kill it even before we convert all users, we can
reimplement next_thread(t) using the new thread_head/thread_node.  But
we can't do this right now because this will lead to subtle behavioural
changes.  For example, do/while_each_thread() always sees at least one
task, while for_each_thread() can do nothing if the whole thread group
has died.  Or thread_group_empty(), currently its semantics is not clear
unless thread_group_leader(p) and we need to audit the callers before we
can change it.

So this patch adds the new interface which has to coexist with the old
one for some time, hopefully the next changes will be more or less
straightforward and the old one will go away soon.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Sergey Dyasly <dserrg@gmail.com>
Tested-by: Sergey Dyasly <dserrg@gmail.com>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Acked-by: David Rientjes <rientjes@google.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mandeep Singh Baines <msb@chromium.org>
Cc: "Ma, Xindong" <xindong.ma@intel.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: "Tu, Xiaobing" <xiaobing.tu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul Reioux <reioux@gmail.com>

backported to Linux 3.4

Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	kernel/fork.c

(cherry picked from commit ebc57ff272cfcbc53fe0b214afe861538939a467)
Signed-off-by: thirdzcee <thirdzcee@github.com>
intelli/msm_thermal: initial coding for Qualcomm S4 Pro devices

an intelligent MSM thermal throttling kernel driver designed to replace the
closed sourced thermald(aemon) from Qualcomm.

The current driver can throttle the SOC via core frequency scaling or via
core hotplug with user configurable sysfs entries to adjust the throttling
temperature thresholds for each.

Derived from Qualcomm's Open source repo.

Signed-off-by: Paul Reioux <reioux@gmail.com>
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:

	arch/arm/mach-msm/lge/mako/board-mako.c
	include/linux/msm_thermal.h

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 4432035122fcc6ee8d5db78ec8648d93a8a2618c)
Signed-off-by: thirdzcee <thirdzcee@github.com>
intelli-thermal: use its own dedicated workqueue

this should reduce the load on the shared global workqueue for other
processes and also give its own unique variable name for cpu limit

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit a151cfc60495e5a86ee69caa762fe6750c13fb82)
Signed-off-by: thirdzcee <thirdzcee@github.com>
intelli-thermal: increase sampling time to reduce sampling overhead

Signed-off-by: Paul Reioux <reioux@gmail.com>
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	drivers/thermal/intelli/msm_thermal.c

(cherry picked from commit 883a3b6953fab5c0c6b4a0141b6bcae3d43960f0)
Signed-off-by: thirdzcee <thirdzcee@github.com>
lowmemorykiller: use swapfree instead of swaptotal for better memory reclaim

Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 2f43f99f8423afd9d709f413211144c09a831710)
Signed-off-by: thirdzcee <thirdzcee@github.com>
ARM: be strict about FP exceptions in kernel mode

The support code in vfp_support_entry does not care whether the
exception that caused it to be invoked occurred in kernel mode or
in user mode. However, neither condition that could trigger this
exception (lazy restore and VFP bounce to support code) is
currently allowable in kernel mode.

In either case, print a message describing the condition before
letting the undefined instruction handler run its course and trigger
an oops.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel at linaro.org>
Acked-by: Nicolas Pitre <nico at linaro.org>
Signed-off-by: Paul Reioux <reioux@gmail.com>
(cherry picked from commit 0f137d3f46422d177c20f54cdcffad2c4095e61a)
Signed-off-by: thirdzcee <thirdzcee@github.com>
Backport vnswap/frontswap/zswap to Moto G

Signed-off-by: Paul Reioux <reioux@gmail.com>

Conflicts:
	include/linux/swap.h
	mm/page_io.c
	mm/shmem.c
	mm/swapfile.c

(cherry picked from commit 99b509c659547ed6f3b87523a5260ad133c06883)
Signed-off-by: thirdzcee <thirdzcee@github.com>

Conflicts:
	drivers/staging/Kconfig
	drivers/staging/Makefile
	mm/internal.h
	mm/page_io.c
	mm/swapfile.c
	mm/vmscan.c