mali: 3-step clock/voltage control

Based on gokhanmoral's SiyahKernel patch at
https://bitbucket.org/gokhanmoral/siyahkernel/changeset/8f63f5d1c5cb
minus some unrelated cruft (what was that outercache stuff doing in
a Mali DVFS patch?)

Signed-off-by: Andrew Dodd <atd7@cornell.edu>
Revert "pm-hotplug: disable secondary cpu auto-hotplug when screen is off"

This reverts commit 0746aeb285341896877a3adddd79bdaa0cf4a6f6.

Prepare for tunable hotplugging logic from SiyahKernel

Signed-off-by: Andrew Dodd <atd7@cornell.edu>
pm-hotplug:  Add enhanced hotplugging tunables

This allows the on/off thresholds to be tuned dependent on screen state
along with the hotplugging poll rate.

It also lets hotplugging get locked out at lower frequencies (default
800 MHz)

Credit for this goes to gokhanmoral of SiyahKernel - this is a rebase
of all of his pm-hotplug commits minus the Tegrak stuff which is
unnecessary with this code.  (The only thing Tegrak Second Core can
achieve which this code can't is forcing CPU1 on - we never want
to do that since that inhibits all deeper idle states.)

Slightly different logic is used for the CPU1 turnon frequency -
allow it to turn on when it equals the limit.

Signed-off-by: Andrew Dodd <atd7@cornell.edu>
Merge branch 'master' into oc_codeworkx
drivers/staging: zcache: dynamic page cache/swap compression

(Historical note: This "new" zcache patchset supercedes both the
kztmem patchset and the "old" zcache patchset as described in:
http://lkml.org/lkml/2011/2/5/148)

HIGH LEVEL OVERVIEW

Zcache doubles RAM efficiency while providing a significant
performance boost on many workloads.

Summary for kernel DEVELOPERS: Zcache uses lzo1x compression to increase
RAM efficiency for both page cache and swap resulting in a significant
performance increase (3-4% or more) on memory-pressured workloads
due to a large reduction in disk I/O.  To do this, zcache uses an
in-kernel (no virtualization required) implementation of transcendent
memory ("tmem"), which has other proven uses and intriguing future uses
as well.

Summary for kernel MAINTAINERS: Zcache is a fully-functional,
in-kernel (non-virtualization) implementation of transcendent memory
("tmem"), providing an in-kernel user for cleancache and frontswap.
The patch is based on 2.6.37 and requires either the cleancache patch
or the frontswap patch or both.  The patch is proposed as a staging
driver to obtain broader exposure for further evolution and,
GregKH-willing, is merge-able at the next opportunity. Zcache will
hopefully also, Linus-and-akpm-willing, remove the barrier to merge-ability
for cleancache and frontswap.  Please note that there is a dependency
on xvmalloc.[ch], currently in drivers/staging/zram.

For kernel USERS seeking a new toy: Want to try it out?  A complete
monolithic patch for 2.6.37 including zcache, cleancache, and frontswap
can be downloaded at:
http://oss.oracle.com/projects/tmem/dist/files/zcache/zca...
(IMPORTANT NOTE: zcache MUST be specified as a kernel boot parameter or
nothing happens!) And if you love to see tons of detailed statstics
changing dynamically try running the following bash script in a big window
with "watch -d":
http://oss.oracle.com/projects/tmem/dist/files/zcache/zca...

VERSION HISTORY

Version 2 is a bit more restrictive of concurrency (disabling irqs
in gets and flushes) and fixes a build problem reported by gregkh.

Version 1 changed considerably from V0 thanks to some excellent feedback
from Jeremy Fitzhardinge.

Feedback from others would be greatly appreciated.  See "SPECIFIC AREAS
FOR HELP/FEEDBACK" below.
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
backported to linux 2.6.35 by faux123

Conflicts:

	mm/Kconfig
	mm/Makefile
staging:zcache: Enable zcache by default

due to kernel cmdline not being passed correctly, enable zcache by default
rather than relying on kernel cmdline interface.
zram: Support generic I/O requests
Currently, ramzwap devices (/dev/ramzswapX) can only
be used as swap disks since it was hard-coded to consider
only the first request in bio vector.

Now, we iterate over all the segments in an incoming
bio which allows us to handle all kinds of I/O requests.

ramzswap devices can still handle PAGE_SIZE aligned and
multiple of PAGE_SIZE sized I/O requests only. To ensure
that we get always get such requests only, we set following
request_queue attributes to PAGE_SIZE:
 - physical_block_size
 - logical_block_size
 - io_min
 - io_opt

Note: physical and logical block sizes were already set
equal to PAGE_SIZE and that seems to be sufficient to get
PAGE_SIZE aligned I/O.

Since we are no longer limited to handling swap requests
only, the next few patches rename ramzswap to zram. So,
the devices will then be called /dev/zram{0, 1, 2, ...}

Usage/Examples:
 1) Use as /tmp storage
 - mkfs.ext4 /dev/zram0
 - mount /dev/zram0 /tmp

 2) Use as swap:
 - mkswap /dev/zram0
 - swapon /dev/zram0 -p 10 # give highest priority to zram0

Performance:

 - I/O benchamark done with 'dd' command. Details can be
found here:
http://code.google.com/p/compcache/wiki/zramperf
Summary:
 - Maximum read speed (approx):
   - ram disk: 1200 MB/sec
   - zram disk: 600 MB/sec
 - Maximum write speed (approx):
   - ram disk: 500 MB/sec
   - zram disk: 160 MB/sec

Issues:

 - Double caching: We can potentially waste memory by having
two copies of a page -- one in page cache (uncompress) and
second in the device memory (compressed). However, during
reclaim, clean page cache pages are quickly freed, so this
does not seem to be a big problem.

 - Stale data: Not all filesystems support issuing 'discard'
requests to underlying block devices. So, if such filesystems
are used over zram devices, we can accumulate lot of stale
data in memory. Even for filesystems to do support discard
(example, ext4), we need to see how effective it is.

 - Scalability: There is only one (per-device) de/compression
buffer stats. This can lead to significant contention, especially
when used for generic (non-swap) purposes.

Signed-off-by: Nitin Gupta <ngupta@xxxxxxxxxx>
zram: Rename ramzswap files to zram
Related changes:
 - Modify revelant Kconfig and Makefile accordingly.
 - Change include filenames in code.
 - Remove dependency on CONFIG_SWAP in Kconfig as zram usage
is no longer limited to swap disks.

Signed-off-by: Nitin Gupta <ngupta@xxxxxxxxxx>
zram: Rename ramzswap to zram in code
Automated renames in code:
 - rzs* -> zram*
 - RZS* -> ZRAM*
 - ramzswap* -> zram*

Manual changes:
 - Edited comments/messages mentioning "swap"

Signed-off-by: Nitin Gupta <ngupta@xxxxxxxxxx>
zram: Rename ramzswap to zram in documentation
Related changes:
 - Included example to show usage as generic
(non-swap) disk with ext4 filesystem.
 - Renamed rzscontrol to zramconfig to match
with new device naming.

Signed-off-by: Nitin Gupta <ngupta@xxxxxxxxxx>
zram: various improvements and cleanups
The zram module creates RAM based block devices named /dev/zram<id>
(<id> = 0, 1, ...). Pages written to these disks are compressed and stored
in memory itself.

One of the major changes done is the replacement of ioctls with sysfs
interface. One of the advantages of this approach is we no longer depend on the
userspace tool (rzscontrol) which was used to set various parameters and check
statistics. Maintaining updated version of rzscontrol as changes were done to
ioctls, statistics exported etc. was a major pain.

Another significant change is the introduction of percpu stats and compression
buffers. Earlier, we had per-device buffers protected by a mutex. This was a
major bottleneck on multi-core systems. With these changes, benchmarks with
fio[1] showed a speedup of about 20% for write performance on dual-core
system (see patch 4/10 description for details).

For easier testing, a single patch against 2.6.35-git8 has been uploaded at:
http://compcache.googlecode.com/hg/sub-projects/mainline/zram_2.6.36-rc0.patch

[1] fio I/O benchmarking tool: http://freshmeat.net/projects/fio/

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
Modified by faux123
Staging: zram: make ZRAM depends on SYSFS
We can not configure zram device without sysfs anyway, so make zram
depends on it.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
modified by faux123
Staging: zram: round up the disk size provided by user
Currently disksize_store() round down the disk size provided by user.
This is probably not what one would expect, so round up instead.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Staging: zram: make zram_read return a bio error if the device is not
initialized

Make zram_read() return a bio error if the device is not initialized
instead of pretending nothing happened.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Staging: zram: simplify zram_make_request
zram_read() and zram_write() always return zero, so make them return
void to simplify the code.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
kernel:mm: Backported vzalloc to support ZRAM
zram: driver update to latest stable release on 2011-07-18

Backported by Faux123 from Linux 3.1-rc8
zram: Fix sparse warnings
Fixes sparse warning:
zram_drv.c:666:6: warning: symbol 'zram_slot_free_notify' was not
declared. Should it be static?

Also, max_zpage_size is now size_t just to be consistent with data-type
of other variables maintaining sizes of various kinds.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
zram: Kernel config option for number of devices
Allows configuring default number of zram devices
as kernel config option. User can override this
value using 'num_devices' module parameter.

Signed-off-by: Nitin Gupta <ngupta@vflare.org>
zram: Make gobal variables use unique names
Global variables 'num_devices' and 'devices' are too
general to be global. This patch switches the name to
be "zram_devices".

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
Signed-off-by: Nitin Gupta <ngupta@vflare.org>
modified by faux123