fs/dyn_sync_cntrl: dynamic sync control + Tweaks

The dynamic sync control interface uses Android kernel's unique early
suspend / lat resume interface.

While screen is on, file sync is disabled
when screen is off, a file sync is called to flush all outstanding writes
and restore file sync operation as normal.

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

dynamic fsync: add kernel panic notifier to force flush outstanding data

more paranoia safety checks

Signed-off-by: Paul Reioux <reioux@gmail.com>
dynamic fsync: add reboot notifier to force flush outstanding data

this should further prevent data corruption from kernel panics and
forced reboots

bump version to 1.2

Signed-off-by: Paul Reioux <reioux@gmail.com>
fs/dyn_sync_cntrl: Linux 3.4 Kernel compatibility fixup

Signed-off-by: faux123 <reioux@gmail.com>
Enable Dynamic Sync Control by default
fs/sync: Make sync() satisfy many requests with one invocation

Dave Jones reported RCU stalls, overly long hrtimer interrupts, and
amazingly long NMI handlers from a trinity-induced workload involving
lots of concurrent sync() calls (https://lkml.org/lkml/2013/7/23/369).
There are any number of things that one might do to make sync() behave
better under high levels of contention, but it is also the case that
multiple concurrent sync() system calls can be satisfied by a single
sys_sync() invocation.

Given that this situation is reminiscent of rcu_barrier(), this commit
applies the rcu_barrier() approach to sys_sync().  This approach uses
a global mutex and a sequence counter.  The mutex is held across the
sync() operation, which eliminates contention between concurrent sync()
operations.  The counter is incremented at the beginning and end of
each sync() operation, so that it is odd while a sync() operation is in
progress and even otherwise, just like sequence locks.

The code that used to be in sys_sync() is now in do_sync(), and sys_sync()
now handles the concurrency.  The sys_sync() function first takes a
snapshot of the counter, then acquires the mutex, and then takes another
snapshot of the counter.  If the values of the two snapshots indicate that
a full do_sync() executed during the mutex acquisition, the sys_sync()
function releases the mutex and returns ("Our work is done!").  Otherwise,
sys_sync() increments the counter, invokes do_sync(), and increments
the counter again.

This approach allows a single call to do_sync() to satisfy an arbitrarily
large number of sync() system calls, which should eliminate issues due
to large numbers of concurrent invocations of the sync() system call.

Changes since v1 (https://lkml.org/lkml/2013/7/24/683):

o	Add a pair of memory barriers to keep the increments from
	bleeding into the do_sync() code.  (The failure probability
	is insanely low, but when you have several hundred million
	devices running Linux, you can expect several hundred instances
	of one-in-a-million failures.)

o	Actually CC some people who have experience in this area.

Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jan Kara <jack@suse.cz>
Cc: Curt Wohlgemuth <curtw@google.com>
Cc: Jens Axboe <jaxboe@fusionio.com>
Cc: linux-fsdevel@vger.kernel.org

Signed-off-by: Paul Reioux <reioux@gmail.com>
dynamic fsync: don't disable fdatasync()

Signed-off-by: Paul Reioux <reioux@gmail.com>
dynamic fsync: favor true case since most will be using this feature

Signed-off-by: Paul Reioux <reioux@gmail.com>
dynamic filesync: add some cache optimizations

and clean up file format and typos

bump version to 1.1

Signed-off-by: Paul Reioux <reioux@gmail.com>
fs/dyn_fsync: check dyn fsync control's active prior to performing fsync ops

Signed-off-by: Andrew Bartholomew <andrewb03@gmail.com>
kernel:sched: LOAD_FREQ (4*HZ+61) avoids loadavg Moire

LOAD_FREQ is (5*HZ+1) to avoid high load average when idle:
http://kerneltrap.org/mailarchive/linux-kernel/2007/10/3/328568

I suggest (4*HZ+61) for a better distribution.

With some seconds based load (like SSL heartbeats)
and LOAD_FREQ at (5*HZ+1) I see Moire patterns like inverse sawtooth,
since 2 or 3 probes hit the jobs (load increases quickly),
followed by several probes missing it.

A 4.61 sec interval gives optimal distribution over when within a
second a probe is taken, as .61 is close to golden ratio phi 1.618...
(test in http://ripke.com/goldenratio.c).

12*4.61 = 55.32 secs is still close to a minute,
and 13*4.61=59.93 is even closer than the current 12*5.01=60.12
(with exponents EXP_x adjusted to a ratio of 13 instead of 12).
KGSL: Add a simple GPU governor for Adreno xxx GPU series

initial coding for a Simple GPU governor based on my own work 2 years ago
from Sensation GB kernel commit: c1ea8f64167270d67915b4d4fb00910b1c0f513f

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

KGSL: Simple Governor: fix minor logic issue

Signed-off-by: Paul Reioux <reioux@gmail.com>
KGSL: simple governor: expose tunables to sysfs interface via module_param

Signed-off-by: Paul Reioux <reioux@gmail.com>
KGSL: make simple govenor a selectable option, co-exist with ondemand

also removed some hardcoded values

Signed-off-by: Paul Reioux <reioux@gmail.com>
KGSL: Simple Governor: some styling changes, early returns instead of assigning a val and returning in the end of the function call and change the copyright/author from the middle of the file to the header.

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

KGSL: Simple Governor: so I kinda butchered in a good way of course the original code from faux, but the simplicity is still here. Added an history so that we can track the average do that the frequency scaling is much more proporcional to the actual GPU load rather than having is ramp up every now and then due to spurious load spike. Also remove two useless ifs.

Signed-off-by: Francisco Franco <franciscofranco.1990@gmail.com>
Enable the Simple GPU Governor by default

Just some quick spelling fixes
Accuracy Filter Control: export accuracy filter items to userspace via
sysfs.

LG/mako touchscreen
Optimized ARM RWSEM algorithm

RWSEM implementation for ARM using atomic functions.
Heavily based on arch/sh/include/asm/rwsem.h

Signed-off-by: Ashwin Chaugule <ashwinc@codeaurora.org>
lib/int_sqrt.c: optimize square root algorithm

Optimize the current version of the shift-and-subtract (hardware)
algorithm, described by John von Newmann[1] and Guy L Steele.

Iterating 1,000,000 times, perf shows for the current version:

 Performance counter stats for './sqrt-curr' (10 runs):

         27.170996 task-clock                #    0.979 CPUs utilized            ( +-  3.19% )
                 3 context-switches          #    0.103 K/sec                    ( +-  4.76% )
                 0 cpu-migrations            #    0.004 K/sec                    ( +-100.00% )
               104 page-faults               #    0.004 M/sec                    ( +-  0.16% )
        64,921,199 cycles                    #    2.389 GHz                      ( +-  0.03% )
        28,967,789 stalled-cycles-frontend   #   44.62% frontend cycles idle     ( +-  0.18% )
   <not supported> stalled-cycles-backend
       104,502,623 instructions              #    1.61  insns per cycle
                                             #    0.28  stalled cycles per insn  ( +-  0.00% )
        34,088,368 branches                  # 1254.587 M/sec                    ( +-  0.00% )
             4,901 branch-misses             #    0.01% of all branches          ( +-  1.32% )

       0.027763015 seconds time elapsed                                          ( +-  3.22% )

And for the new version:

Performance counter stats for './sqrt-new' (10 runs):

          0.496869 task-clock                #    0.519 CPUs utilized            ( +-  2.38% )
                 0 context-switches          #    0.000 K/sec
                 0 cpu-migrations            #    0.403 K/sec                    ( +-100.00% )
               104 page-faults               #    0.209 M/sec                    ( +-  0.15% )
           590,760 cycles                    #    1.189 GHz                      ( +-  2.35% )
           395,053 stalled-cycles-frontend   #   66.87% frontend cycles idle     ( +-  3.67% )
   <not supported> stalled-cycles-backend
           398,963 instructions              #    0.68  insns per cycle
                                             #    0.99  stalled cycles per insn  ( +-  0.39% )
            70,228 branches                  #  141.341 M/sec                    ( +-  0.36% )
             3,364 branch-misses             #    4.79% of all branches          ( +-  5.45% )

       0.000957440 seconds time elapsed                                          ( +-  2.42% )

Furthermore, this saves space in instruction text:

   text    data     bss     dec     hex filename
    111       0       0     111      6f lib/int_sqrt-baseline.o
     89       0       0      89      59 lib/int_sqrt.o

[1] http://en.wikipedia.org/wiki/First_Draft_of_a_Report_on_the_EDVAC

Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Reviewed-by: Jonathan Gonzalez <jgonzlez@linets.cl>
Tested-by: Jonathan Gonzalez <jgonzlez@linets.cl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Async I/O latency to a ssd greatly increased, 34% gain (Creds: kleikamp)
dyn_sync_cntrl: disable by default
ARM: add auto hotplug driver
auto_hotplug: enhancements + tweaks

======
auto_hotplug: Tweaks for battery / Allow higher enable_load_threshold values
auto_hotplug: Add suspend_freq
auto_hotplug: rev 4 - let's lean a little more towards performance.

This includes:

1) Set DEFAULT_SAMPLING_PERIODS back to 10 (from 12)

2) Set DEFAULT_ENABLE_ALL_LOAD_THRESHOLD to (100 * CPUS)

3) Finally came back and fixed "stack the deck" like I had originally
intended after the quick test.

4) Updated to revision to 4.
auto_hotplug: stack the deck on auto_hotplug_late_resume to get things
moving quickly again
auto_hotplug: parameter validation for max_online_cpus

If validation fails, set max_online_cpus = CPUS_AVAILABLE instead of
"1"
auto_hotplug: enhancements (rev 3)

1) Added max_online_cpus (1-4) and exposed to sysfs via a module
parameter. Once set, only allow the chosen number of cores to be
online and make sure we compensate for it in the boostpulse function.

2) Make minor tweaks to mathkid's min_online_cpus

-Don't schedule work in the parameter set, just let it be done on the
next poll iteration.

-Misc style changes so that it matches the other code I have been
adding the module.
auto_hotplug: enable the min_online_cpus value

Use a module_param_cb to set the minimum number of online CPUs when the
screen is on.

The values are between 1-4.

usage:
echo '1' < /sys/module/auto_hotplug/parameters/min_online_cpus
auto_hotplug: enhancements (rev 2)

1) Added ability to change the number of sampling_periods on the fly via
sysfs (while preserving past history).

2) Added get/set for module parameters so user's can't set incorrect or
unreasonable values.

3) Tweaked defaults

4) Don't wait as long to start auto_hotplug (referenced franco's
git). Today's devices are much faster to boot however
if this code is ported to a slower core device, it may need to be
raised.

5) Debug mode tweaks
-Organize and reduce the number of line output.
-Attempt to make output more user friendly for those that aren't
reading the code.
auto_hotplug: enhancements

1) added module params so tuning an be adjusted in userspace and
debugging can easliy be enabled/disabled

/sys/module/auto_hotplug/parameters/debug
(N/Y - turn off/on debugging)

/sys/module/auto_hotplug/parameters/disable_load_threshold
(integer - load at which a CPU is disabled)

/sys/module/auto_hotplug/parameters/enable_load_threshold (integer -
load at which an extra CPU is enabled)

/sys/module/auto_hotplug/parameters/enable_all_load_threshold (integer -
load at wich all CPU's are enabled)

/sys/module/auto_hotplug/parameters/min_sampling_rate
(milliseconds, converted to jiffies at runtime)

2) lowered enable_load_threshold from 225 to 200 for a little more pep.

To-do: add get/set routines to keep values safe and in acceptable ranges
arm: auto hotplug - wrap all pr_info into the existing debug mode so we
don't spam the kernel log
defconfig: Auto-Hotplug