sched,rt: disable rt_runtime borrowing by default

Make the default RT_RUNTIME_SHARE setting reflect the most common
throttle role, that of safety mechanism to protect the box.

Bug 1269903

Change-Id: Id4ccf0095ea254f2e15fddc7ab02069f7f60a7c0
Signed-off-by: Mike Galbraith <bitbucket@online.de>
Reviewed-on: http://git-master/r/234274
(cherry picked from commit be74a12c8d8b987f569cdd0eec2aead3dcbdfa31)
Reviewed-on: http://git-master/r/237266
Tested-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Paul Walmsley <pwalmsley@nvidia.com>
GVS: Gerrit_Virtual_Submit

sched: remove redundant update_runtime notifier

migration_call() will do all the things that update_runtime() does.
So it seems update_runtime() is a redundant notifier, remove it.

Furthermore, there is potential risk that the current code will catch
BUG_ON at line 687 of rt.c when do cpu hotplug while there are realtime
threads running because of enable runtime twice.

Change-Id: I0fdad8d5a1cebb845d3f308b205dbd6517c3e4de
Cc: bitbucket@online.de
Signed-off-by: Neil Zhang <zhangwm@marvell.com>
Reviewed-on: http://git-master/r/215596
(cherry picked from commit 8f646de983f24361814d9a6ca679845fb2265807)
Reviewed-on: http://git-master/r/223067
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Tested-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-by: Paul Walmsley <pwalmsley@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

sched: reinitialize rq->next_balance when a CPU is hot-added

Reinitialize rq->next_balance when a CPU is hot-added.  Otherwise,
scheduler domain rebalancing may be skipped if rq->next_balance was
set to a future time when the CPU was last active, and the
newly-re-added CPU is in idle_balance().  As a result, the
newly-re-added CPU will remain idle with no tasks scheduled until the
softlockup watchdog runs - potentially 4 seconds later.  This can
waste energy and reduce performance.

This behavior can be observed in some SoC kernels, which use CPU
hotplug to dynamically remove and add CPUs in response to load.  In
one case that triggered this behavior,

0. the system started with all cores enabled, running multi-threaded
   CPU-bound code;

1. the system entered some single-threaded code;

2. a CPU went idle and was hot-removed;

3. the system started executing a multi-threaded CPU-bound task;

4. the CPU from event 2 was re-added, to respond to the load.

The time interval between events 2 and 4 was approximately 300
milliseconds.

Of course, ideally CPU hotplug would not be used in this manner,
but this patch does appear to fix a real bug.

Nvidia folks: this patch is submitted as at least a partial fix for
bug 1243368 ("[sched] Load-balancing not happening correctly after
cores brought online")

Change-Id: Iabac21e110402bb581b7db40c42babc951d378d0
Signed-off-by: Paul Walmsley <pwalmsley@nvidia.com>
Cc: Peter Boonstoppel <pboonstoppel@nvidia.com>
Reviewed-on: http://git-master/r/208927
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Peter Zu <pzu@nvidia.com>
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
GVS: Gerrit_Virtual_Submit
Tested-by: Peter Zu <pzu@nvidia.com>
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>
ARM: mm: implement LoUIS API for cache maintenance ops

ARM v7 architecture introduced the concept of cache levels and related
control registers. New processors like A7 and A15 embed an L2 unified cache
controller that becomes part of the cache level hierarchy. Some operations in
the kernel like cpu_suspend and __cpu_disable do not require a flush of the
entire cache hierarchy to DRAM but just the cache levels belonging to the
Level of Unification Inner Shareable (LoUIS), which in most of ARM v7 systems
correspond to L1.

The current cache flushing API used in cpu_suspend and __cpu_disable,
flush_cache_all(), ends up flushing the whole cache hierarchy since for
v7 it cleans and invalidates all cache levels up to Level of Coherency
(LoC) which cripples system performance when used in hot paths like hotplug
and cpuidle.

Therefore a new kernel cache maintenance API must be added to cope with
latest ARM system requirements.

This patch adds flush_cache_louis() to the ARM kernel cache maintenance API.

This function cleans and invalidates all data cache levels up to the
Level of Unification Inner Shareable (LoUIS) and invalidates the instruction
cache for processors that support it (> v7).

This patch also creates an alias of the cache LoUIS function to flush_kern_all
for all processor versions prior to v7, so that the current cache flushing
behaviour is unchanged for those processors.

v7 cache maintenance code implements a cache LoUIS function that cleans and
invalidates the D-cache up to LoUIS and invalidates the I-cache, according
to the new API.

Reviewed-by: Santosh Shilimkar <santosh.shilimkar@xxxxxx>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>

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

ARM: mm: rename jump labels in v7_flush_dcache_all function

This patch renames jump labels in v7_flush_dcache_all in order to define
a specific flush cache levels entry point.

TODO: factor out the level flushing loop if considered worthwhile and
      define the input registers requirements.

Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
Signed-off-by: Paul Reioux <reioux@gmail.com>

ARM: kernel: update cpu_suspend code to use cache LoUIS operations

In processors like A15/A7 L2 cache is unified and integrated within the
processor cache hierarchy, so that it is not considered an outer cache
anymore. For processors like A15/A7 flush_cache_all() ends up cleaning
all cache levels up to Level of Coherency (LoC) that includes
the L2 unified cache.

When a single CPU is suspended (CPU idle) a complete L2 clean is not
required, so generic cpu_suspend code must clean the data cache using the
newly introduced cache LoUIS function.

The context and stack pointer (context pointer) are cleaned to main memory
using cache area functions that operate on MVA and guarantee that the data
is written back to main memory (perform cache cleaning up to the Point of
Coherency - PoC) so that the processor can fetch the context when the MMU
is off in the cpu_resume code path.

outer_cache management remains unchanged.

Reviewed-by: Santosh Shilimkar <santosh.shilimkar@xxxxxx>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
Signed-off-by: Paul Reioux <reioux@gmail.com>

ARM: kernel: update __cpu_disable to use cache LoUIS maintenance API

When a CPU is hotplugged out caches that reside in its power domain
lose their contents and so must be cleaned to the next memory level.

Currently, __cpu_disable calls flush_cache_all() that for new generation
processor like A15/A7 ends up cleaning and invalidating all cache levels
up to Level of Coherency, which includes the unified L2.

This ends up being a waste of cycles since the L2 cache contents are not
lost on power down.

This patch updates __cpu_disable to use the new LoUIS API cache operations.

Reviewed-by: Santosh Shilimkar <santosh.shilimkar@xxxxxx>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
Signed-off-by: Paul Reioux <reioux@gmail.com>

ARM: mm: update __v7_setup() to the new LoUIS cache maintenance API

The ARMv7 processor setup function __v7_setup() cleans and invalidates the
CPU cache before enabling MMU to start the CPU with a clean CPU local cache.

But on ARMv7 architectures like Cortex-[A15/A8], this code will end
up flushing the L2 caches(up to level of Coherency) which is undesirable
and expensive. The setup functions are used in the CPU hotplug scenario too
and hence flushing all cache levels should be avoided.

This patch replaces the cache flushing call with the newly introduced
v7 dcache LoUIS API where only cache levels up to LoUIS are cleaned and
invalidated when a processors executes __v7_setup which is the expected
behavior.

For processors like A9 and A5 where the L2 cache is an outer one the
behavior should be unchanged.

Signed-off-by: Santosh Shilimkar <santosh.shilimkar@xxxxxx>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
Signed-off-by: Paul Reioux <reioux@gmail.com>
msm: Fix race condition in domain lookup

During lookup of domains we take a pointer to the root node
of the rb tree before taking the mutex to protect the rb tree.
However, the rb root node might change if another process updates
the rb tree after we take the pointer to the root node. This can
cause us to not find the entry that we are looking for.
Fix this by ensuring we have taken the mutex before getting the
root node pointer.

CRs-fixed: 493503
Change-Id: I4702740e486fda0cd92df0401d8e4706598a899b
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
input: touchscreen: export accuracy filter items to userspace via sysfs

LG/mako touchscreen

Conflicts:
	drivers/input/touchscreen/lge_touch_core.c
Conservative Config
gpu: ion: Improvements squashed

gpu: ion: Add null-pointer check after allocation

Check for failed allocation and return appropritate
return code if memory allocation fails.

Change-Id: Iefb83b5e30c3cc581ccecaf6e59eae621be98083
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

gpu: ion: Align va address to biggest buffer size

Align the virtual address to the max buffer size to
allow IOMMU mappings at the biggest buffer size.

Change-Id: I74ba665c1782e2f0631274766c5caeeb192224e0
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

gpu: ion: enable the kmalloc heap

There are some Ion clients who would like to use the kmalloc
heap. Enable it.

Change-Id: Ie818be9e1211d52d489ad2cb63d94e2fddfc0f01
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

msm: Add support for ION Flushing without virtual address

Video has very large buffers to be flushed. Due to lack of
vmalloc space, ion_map_kernel cannot be called on each of
the video buffers. With this change the ion handle can be
flushed without the need of the kernel mapping.

Change-Id: If026f21e44a2cce6c2b8c232fc80a69d0dabcd14
Signed-off-by: Neeti Desai <neetid@codeaurora.org>

Conflicts:

	drivers/gpu/ion/ion_cp_heap.c
	drivers/gpu/ion/msm/msm_ion.c

Signed-off-by: Maheshwar Ajja <majja@codeaurora.org>

gpu: ion: Use correct type for variables

Use correct type for variables to prevent overflow of signed
type when assiging from an unsigned type.

Change-Id: I0055d35c7310d111de590db3798950fd98f1b298
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

gpu: ion: Do fallback when allocating large sizes

The preferred allocation of memory for kernel data structures in
ION is to use kmalloc. This is mainly for performance reasons. However,
we are not guaranteed to be able to allocate large sizes. So to keep
the code performing well and at the same time allow for larger allocations,
implement a fallback mechanism for allocation of memory for ION kernel data
structures.

CRs-Fixed: 488521
Change-Id: I8c6a13ad74cce69f590920d28c01a58f7a540fd2
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
[Resolved merge conflict]
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>

gpu: ion: Free the sgtable for CMA based heaps

When an sgtable is allocated with sg_alloc_table, the table needs
to be destroyed in addition to being freed. Destroy the sgtable
when freeing the associated memory.

Change-Id: Iedba81146ba453070790f071848f86826f7eec9c
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Srinivasarao P <spathi@codeaurora.org>

gpu: ion: Minimize allocation fallback delay

When we allocate from iommu heap we first try to allocate 1M pages. If
that fails we try 64K pages, which falls back to 4K pages. However,
we don't want to incur too much overhead when allocating with fallbacks
so we don't want the higher order page allocation to retry, perform
reclaim, or run memory compaction.

Configure the GFP flags to ensure that when we allocate pages greater
than order 0 we don't try to do any retries, reclaim, access emergency
pools, or run memory compaction. This will ensure lower memory allocation
latency for applications.

CRs-Fixed: 470389
Change-Id: Ibb3483dddbedbc733a1f7968821e7bc47bedffcd
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

gpu: ion: remove stale variable

Tracking the number of user mappings should be done in the Ion
heaps. Remove the variable that was used to track this in core Ion.

Change-Id: I715280515e3010bd002314aefe0ec8cdb37c143d
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

gpu: ion: Remove get_flags ioctl

There are no callers of the get flags ioctl. Remove it
before anyone tries to use it again.

Change-Id: I857ef705fc864cce49f671124b96bd9f47b66ab2
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: Remove code for reusable heap

The reusable feature is no longer supported. Remove
the associated code.

Change-Id: I7cf6eb302969287d629603fa0ea05ad9714bfb70
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
cpufreq: conservative: squashed

cpufreq: Remove rwsem lock from CPUFREQ_GOV_STOP call (again)

We need to unlock the semaphore due to an enabled conservative governor and
those old input hook commits.

We should get rid of the unused input boost functions, for now this is good
enough.

<4>[ 1338.237854] ------------[ cut here ]------------
<4>[ 1338.238067] WARNING: at fs/sysfs/dir.c:508 sysfs_add_one+0x7c/0x9c()
<4>[ 1338.238189] sysfs: cannot create duplicate filename '/devices/system/cpu/c
pufreq/conservative'
<4>[ 1338.238403] [<c010c204>] (unwind_backtrace+0x0/0xe0) from [<c0167a18>] (wa
rn_slowpath_common+0x48/0x60)
<4>[ 1338.238616] [<c0167a18>] (warn_slowpath_common+0x48/0x60) from [<c0167a88>
] (warn_slowpath_fmt+0x2c/0x3c)
<4>[ 1338.238830] [<c0167a88>] (warn_slowpath_fmt+0x2c/0x3c) from [<c026dc38>] (
sysfs_add_one+0x7c/0x9c)
<4>[ 1338.238952] [<c026dc38>] (sysfs_add_one+0x7c/0x9c) from [<c026de34>] (crea
te_dir+0x58/0xb0)
<4>[ 1338.239166] [<c026de34>] (create_dir+0x58/0xb0) from [<c026e0e0>] (sysfs_c
reate_subdir+0x18/0x1c)
<4>[ 1338.241058] [<c026e0e0>] (sysfs_create_subdir+0x18/0x1c) from [<c026f530>]
 (internal_create_group+0x84/0x1e0)
<4>[ 1338.241180] [<c026f530>] (internal_create_group+0x84/0x1e0) from [<c059ee5
4>] (cpufreq_governor_dbs+0x22c/0x3f8)
<4>[ 1338.241302] [<c059ee54>] (cpufreq_governor_dbs+0x22c/0x3f8) from [<c059a06
c>] (__cpufreq_governor+0x50/0x5c)
<4>[ 1338.241394] [<c059a06c>] (__cpufreq_governor+0x50/0x5c) from [<c059a198>]
(__cpufreq_set_policy+0x120/0x168)
<4>[ 1338.241516] [<c059a198>] (__cpufreq_set_policy+0x120/0x168) from [<c059a85
0>] (cpufreq_add_dev_interface+0x274/0x2c4)
<4>[ 1338.241577] [<c059a850>] (cpufreq_add_dev_interface+0x274/0x2c4) from [<c0
59ac84>] (cpufreq_add_dev+0x3e4/0x43c)
<4>[ 1338.241699] [<c059ac84>] (cpufreq_add_dev+0x3e4/0x43c) from [<c0907e70>] (
cpufreq_cpu_callback+0x88/0x9c)
<4>[ 1338.241821] [<c0907e70>] (cpufreq_cpu_callback+0x88/0x9c) from [<c0189b34>
] (notifier_call_chain+0x38/0x68)
<4>[ 1338.241943] [<c0189b34>] (notifier_call_chain+0x38/0x68) from [<c0169958>]
 (__cpu_notify+0x28/0x40)
<4>[ 1338.242065] [<c0169958>] (__cpu_notify+0x28/0x40) from [<c0905c30>] (_cpu_
up+0xc8/0x1a8)
<4>[ 1338.242156] [<c0905c30>] (_cpu_up+0xc8/0x1a8) from [<c0905d74>] (cpu_up+0x
64/0x84)
<4>[ 1338.242248] [<c0905d74>] (cpu_up+0x64/0x84) from [<c0903fac>] (decide_hotp
lug_func+0x1e8/0x2ec)
<4>[ 1338.242370] [<c0903fac>] (decide_hotplug_func+0x1e8/0x2ec) from [<c017f108
>] (process_one_work+0x204/0x410)
<4>[ 1338.242462] [<c017f108>] (process_one_work+0x204/0x410) from [<c017f4c8>]
(worker_thread+0x188/0x2a8)
<4>[ 1338.242584] [<c017f4c8>] (worker_thread+0x188/0x2a8) from [<c0184390>] (kt
hread+0x84/0x94)
<4>[ 1338.242675] [<c0184390>] (kthread+0x84/0x94) from [<c0106d8c>] (kernel_thr
ead_exit+0x0/0x8)
<4>[ 1338.242767] ---[ end trace e6d9e62662a91860 ]---

cpufreq: conservative: Add idle micro accounting

Conflicts:
	drivers/cpufreq/cpufreq_conservative.c

cpufreq: conservative: Fix minor derp
mm/vmalloc.c: improvements squashed

mm, vmalloc: use well-defined find_last_bit() func

Our intention in here is to find last_bit within the region to flush.
There is well-defined function, find_last_bit() for this purpose and its
performance may be slightly better than current implementation.  So change
it.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Reviewed-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/vmalloc.c: remove dead code in vb_alloc

Space in a vmap block that was once allocated is considered dirty and
not made available for allocation again before the whole block is
recycled.  The result is that free space within a vmap block is always
contiguous.

So if a vmap block has enough free space for allocation, the allocation
is impossible to fail.  Thus, the fragmented block purging was never
invoked from vb_alloc().  So remove this dead code.

[ Same patches also sent by:

    Chanho Min <chanho.min@lge.com>
    Johannes Weiner <hannes@cmpxchg.org>

  but git doesn't do "multiple authors" ]

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/vmalloc.c: remove unused purge_fragmented_blocks_thiscpu

This function is nowhere used now, so remove it.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/vmalloc.c: remove alloc_map from vmap_block

As we have removed the dead code in the vb_alloc, it seems there is no
place to use the alloc_map.  So there is no reason to maintain the
alloc_map in vmap_block.

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/vmalloc.c: fix an overflow bug in alloc_vmap_area()

When searching a vmap area in the vmalloc space, we use (addr + size -
1) to check if the value is less than addr, which is an overflow.  But
we assign (addr + size) to vmap_area->va_end.

So if we come across the below case:

  (addr + size - 1) : not overflow
  (addr + size)     : overflow

we will assign an overflow value (e.g 0) to vmap_area->va_end, And this
will trigger BUG in __insert_vmap_area, causing system panic.

So using (addr + size) to check the overflow should be the correct
behaviour, not (addr + size - 1).

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Reported-by: Ghennadi Procopciuc <unix140@gmail.com>
Tested-by: Daniel Baluta <dbaluta@ixiacom.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm, vmalloc: remove useless variable in vmap_block

vbq in vmap_block isn't used. So remove it.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Reviewed-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/vmalloc: don't set area->caller twice

The caller address has already been set in set_vmalloc_vm(), there's no
need to set it again in __vmalloc_area_node.

Reviewed-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Mitsuo Hayasaka <mitsuo.hayasaka.hu@hitachi.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm, vmalloc: use clamp() to simplify code

Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
block: bfq: introduce the BFQ-v7r1 I/O sched for 3.4

Add the BFQ-v7r1 I/O scheduler to 3.4.
The general structure is borrowed from CFQ, as much of the code for
handling I/O contexts Over time, several useful features have been
ported from CFQ as well (details in the changelog in README.BFQ). A
(bfq_)queue is associated to each task doing I/O on a device, and each
time a scheduling decision has to be made a queue is selected and served
until it expires.

    - Slices are given in the service domain: tasks are assigned
      budgets, measured in number of sectors. Once got the disk, a task
      must however consume its assigned budget within a configurable
      maximum time (by default, the maximum possible value of the
      budgets is automatically computed to comply with this timeout).
      This allows the desired latency vs "throughput boosting" tradeoff
      to be set.

    - Budgets are scheduled according to a variant of WF2Q+, implemented
      using an augmented rb-tree to take eligibility into account while
      preserving an O(log N) overall complexity.

    - A low-latency tunable is provided; if enabled, both interactive
      and soft real-time applications are guaranteed a very low latency.

    - Latency guarantees are preserved also in the presence of NCQ.

    - Also with flash-based devices, a high throughput is achieved
      while still preserving latency guarantees.

    - BFQ features Early Queue Merge (EQM), a sort of fusion of the
      cooperating-queue-merging and the preemption mechanisms present
      in CFQ. EQM is in fact a unified mechanism that tries to get a
      sequential read pattern, and hence a high throughput, with any
      set of processes performing interleaved I/O over a contiguous
      sequence of sectors.

    - BFQ supports full hierarchical scheduling, exporting a cgroups
      interface.  Since each node has a full scheduler, each group can
      be assigned its own weight.

    - If the cgroups interface is not used, only I/O priorities can be
      assigned to processes, with ioprio values mapped to weights
      with the relation weight = IOPRIO_BE_NR - ioprio.

    - ioprio classes are served in strict priority order, i.e., lower
      priority queues are not served as long as there are higher
      priority queues.  Among queues in the same class the bandwidth is
      distributed in proportion to the weight of each queue. A very
      thin extra bandwidth is however guaranteed to the Idle class, to
      prevent it from starving.

Conflicts:
	block/bfq-cgroup.c
	block/bfq-ioc.c
	block/bfq-iosched.c
	block/bfq-sched.c
	block/bfq.h

block: bfq: add Early Queue Merge (EQM) to BFQ-v7r1 for 3.4.0

A set of processes may happen  to  perform interleaved reads,
i.e.,requests whose union would give rise to a  sequential read  pattern.  There are
two typical  cases: in the first  case,   processes  read  fixed-size chunks
of data at a fixed distance from each other, while in the second case
processes may read variable-size chunks at  variable distances. The latter case
occurs for  example with  KVM, which  splits the  I/O generated  by the  guest
into multiple chunks,  and lets these chunks  be served by a  pool of
cooperating processes,  iteratively  assigning  the  next  chunk of  I/O  to  the
first available  process. CFQ  uses actual  queue merging  for the  first type
of rocesses, whereas it  uses preemption to get a sequential  read pattern
out of the read requests  performed by the second type of  processes. In the
end it uses  two different  mechanisms to  achieve the  same goal: boosting
the throughput with interleaved I/O.

This patch introduces  Early Queue Merge (EQM), a unified mechanism to
get a sequential  read pattern  with both  types of  processes. The  main idea
is checking newly arrived requests against the next request of the active
queue both in case of actual request insert and in case of request merge. By
doing so, both the types of processes can be handled by just merging their queues.
EQM is  then simpler and  more compact than the  pair of mechanisms used in CFQ.

Finally, EQM  also preserves the  typical low-latency properties of BFQ,
by properly restoring the weight-raising state of  a queue when it gets back to a non-merged state.

Signed-off-by: Mauro Andreolini <mauro.andreolini@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Reviewed-by: Paolo Valente <paolo.valente@unimore.it>

bfq-iosched: Tuning for SSD

bfq-iosched: Set bfq_back_penalty = 1
BFQ Scheduler config
timers: iprovements squashed

timers: Create detach_if_pending() and use it

Most callers of detach_timer() have the same pattern around
them. Check whether the timer is pending and eventually updating
base->next_timer.

Create detach_if_pending() and replace the duplicated code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20120525214819.131246037@linutronix.de

timers: Consolidate base->next_timer update

Another bunch of mindlessly copied code. All callers of
internal_add_timer() except the recascading code updates
base->next_timer.

Move this into internal_add_timer() and let the cascading code call
__internal_add_timer().

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20120525214819.189946224@linutronix.de

timers: Add accounting of non deferrable timers

The code in get_next_timer_interrupt() is suboptimal as it has to run
through the cascade to find the next expiring timer. On a completely
idle core we should only do that when there is an active timer
enqueued and base->next_timer does not give us a fast answer.

Add accounting of the active timers to the now consolidated
attach/detach code. I deliberately avoided sanity checks because the
code is fully symetric and any fiddling with timers w/o using the API
functions will lead to cute explosions anyway. ulong is big enough
even on 32bit and if we really run into the situation to have more
than 1<<32 timers enqueued there, then we are definitely not in a
state to go idle and run through that code.

This allows us to fix another shortcoming of get_next_timer_interrupt().

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20120525214819.236377028@linutronix.de

timers: Improve get_next_timer_interrupt()

Gilad reported at

 http://lkml.kernel.org/r/1336056962-10465-2-git-send-email-gilad@benyossef.com

"Current timer code fails to correctly return a value meaning that
 there is no future timer event, with the result that the timer keeps
 getting re-armed in HZ one shot mode even when we could turn it off,
 generating unneeded interrupts.

 What is happening is that when __next_timer_interrupt() wishes
 to return a value that signifies "there is no future timer
 event", it returns (base->timer_jiffies + NEXT_TIMER_MAX_DELTA).

 However, the code in tick_nohz_stop_sched_tick(), which called
 __next_timer_interrupt() via get_next_timer_interrupt(),
 compares the return value to (last_jiffies + NEXT_TIMER_MAX_DELTA)
 to see if the timer needs to be re-armed.

 base->timer_jiffies != last_jiffies and so tick_nohz_stop_sched_tick()
 interperts the return value as indication that there is a distant
 future event 12 days from now and programs the timer to fire next
 after KTIME_MAX nsecs instead of avoiding to arm it. This ends up
 causing a needless interrupt once every KTIME_MAX nsecs."

Fix this by using the new active timer accounting. This avoids scans
when no active timer is enqueued completely, so we don't have to rely
on base->timer_next and base->timer_jiffies anymore.

Reported-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20120525214819.317535385@linutronix.de
hashtable: introduce a small and naive hashtable squashed

This hashtable implementation is using hlist buckets to provide a simple
hashtable to prevent it from getting reimplemented all over the kernel.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[ Merging this now, so that subsystems can start applying Sasha's
  patches that use this   - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

workqueue: use new hashtable implementation

Switch workqueues to use the new hashtable implementation. This reduces the
amount of generic unrelated code in the workqueues.

This patch depends on d9b482c ("hashtable: introduce a small and naive
hashtable") which was merged in v3.6.

Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

workqueue: fix find_worker_executing_work() brekage from hashtable conversion

42f8570f43 ("workqueue: use new hashtable implementation") incorrectly
made busy workers hashed by the pointer value of worker instead of
work.  This broke find_worker_executing_work() which in turn broke a
lot of fundamental operations of workqueue - non-reentrancy and
flushing among others.  The flush malfunction triggered warning in
disk event code in Fengguang's automated test.

 write_dev_root_ (3265) used greatest stack depth: 2704 bytes left
 ------------[ cut here ]------------
 WARNING: at /c/kernel-tests/src/stable/block/genhd.c:1574 disk_clear_events+0x\
cf/0x108()
 Hardware name: Bochs
 Modules linked in:
 Pid: 3328, comm: ata_id Not tainted 3.7.0-01930-gbff6343 #1167
 Call Trace:
  [<ffffffff810997c4>] warn_slowpath_common+0x83/0x9c
  [<ffffffff810997f7>] warn_slowpath_null+0x1a/0x1c
  [<ffffffff816aea77>] disk_clear_events+0xcf/0x108
  [<ffffffff811bd8be>] check_disk_change+0x27/0x59
  [<ffffffff822e48e2>] cdrom_open+0x49/0x68b
  [<ffffffff81ab0291>] idecd_open+0x88/0xb7
  [<ffffffff811be58f>] __blkdev_get+0x102/0x3ec
  [<ffffffff811bea08>] blkdev_get+0x18f/0x30f
  [<ffffffff811bebfd>] blkdev_open+0x75/0x80
  [<ffffffff8118f510>] do_dentry_open+0x1ea/0x295
  [<ffffffff8118f5f0>] finish_open+0x35/0x41
  [<ffffffff8119c720>] do_last+0x878/0xa25
  [<ffffffff8119c993>] path_openat+0xc6/0x333
  [<ffffffff8119cf37>] do_filp_open+0x38/0x86
  [<ffffffff81190170>] do_sys_open+0x6c/0xf9
  [<ffffffff8119021e>] sys_open+0x21/0x23
  [<ffffffff82c1c3d9>] system_call_fastpath+0x16/0x1b

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Cc: Sasha Levin <sasha.levin@oracle.com>

cgroup: use new hashtable implementation

Switch cgroup to use the new hashtable implementation. No functional changes.

Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

block,elevator: use new hashtable implementation

Switch elevator to use the new hashtable implementation. This reduces the
amount of generic unrelated code in the elevator.

This also removes the dymanic allocation of the hash table. The size of the table is
constant so there's no point in paying the price of an extra dereference when accessing
it.

This patch depends on d9b482c ("hashtable: introduce a small and naive
hashtable") which was merged in v3.6.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

mm/huge_memory.c: use new hashtable implementation

Switch hugemem to use the new hashtable implementation.  This reduces
the amount of generic unrelated code in the hugemem.

This also removes the dymanic allocation of the hash table.  The upside
is that we save a pointer dereference when accessing the hashtable, but
we lose 8KB if CONFIG_TRANSPARENT_HUGEPAGE is enabled but the processor
doesn't support hugepages.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: David Rientjes <rientjes@google.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

mm/ksm.c: use new hashtable implementation

Switch ksm to use the new hashtable implementation.  This reduces the
amount of generic unrelated code in the ksm module.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Mel Gorman <mgorman@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Added CPUfreq governor 'wheatley'

Thanks to r_data for taking the time to fix all the build errors for the Nexus 4.

cpufreq: wheatley: cleaning unused code

cpufreq: wheatley: added boost interface
Wheatley Config
preservative: by bedalus squashed

cpufreq: rename conservative preservative and mess with it

Conflicts:
	arch/arm/configs/cyanogen_mako_defconfig
	arch/arm/mach-msm/acpuclock-8064.c

preservative: make boost logic simpler and parameterise the optimal frequency

preservative: touch boost at 1242 MHz and lower optimal fq

...and remove one fq that is barely used

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c

Revert "preservative: touch boost at 1242 MHz and lower optimal fq"

This reverts commit 0e606d3a8896ee60b04f79aa62f90420e2cd291d.

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c

preservative: touch boost at 1242 MHz and lower optimal fq (without removing the unused frequency from the clock table)

hook cpu frequency into gpu control

Conflicts:
	drivers/gpu/msm/kgsl_pwrscale_trustzone.c

GPU: be less power mad!

GPU: try to get everything updating together

Conflicts:
	arch/arm/Kconfig
	arch/arm/configs/cyanogen_mako_defconfig
	drivers/gpu/msm/kgsl_pwrscale_trustzone.c

CPU and GPU tweaks for new 1.7GHz limit

preservative: add iowait discount

Revert "preservative: add iowait discount"

This reverts commit 13817fd287456eae881fbbfbf528b3f0d982ddb7.

preservative: make fq stay above 1134MHz to keep the bus speed high, add hysteresis to prevent spurius scaling below this point

Conflicts:
	arch/arm/mach-msm/msm_hotplug.c

preservative: allow 702MHz sleep and bring higher bus speeds down to 810MHz

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c
	arch/arm/mach-msm/msm_hotplug.c
	drivers/cpufreq/cpufreq_preservative.c

preservative: bring back all frequencies, no need to skip any as everything is solved in the clock tables now

preservative: change behaviour when asleep.

Get an early suspend hook from the hotplug driver to allow for
a drop the optimal frequency position. Drop opt_pos down to a level
where the bus speed is normal. Restore it when the device wakes (my
kernel uses mainly max bus speed when the device is not idle).

Allow scaling up to any fq even when asleep to ensure the dialer
app loads quickly.

Prevent touch events from boosting the fq when asleep.

Conflicts:
	arch/arm/mach-msm/msm_hotplug.c
	include/linux/cpufreq.h

experimental tweaks to idle fq; hotplug; preservative

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c
	arch/arm/mach-msm/msm_hotplug.c
	drivers/cpufreq/cpufreq_preservative.c

preservative: adjust scaling due to new low idle fq

preservative: change behaviour when asleep.

Get an early suspend hook from the hotplug driver to allow for
a drop the optimal frequency position. Drop opt_pos down to a level
where the bus speed is normal. Restore it when the device wakes (my
kernel uses mainly max bus speed when the device is not idle).

Allow scaling up to any fq even when asleep to ensure the dialer
app loads quickly.

Prevent touch events from boosting the fq when asleep.

Conflicts:
	arch/arm/mach-msm/msm_hotplug.c
	drivers/cpufreq/cpufreq_preservative.c
	include/linux/cpufreq.h

experimental tweaks to idle fq; hotplug; preservative

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c
	arch/arm/mach-msm/msm_hotplug.c
	drivers/cpufreq/cpufreq_preservative.c

preservative: adjust scaling due to new low idle fq

preservative: tidy up and increase rate

revert experimental changes

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c
	arch/arm/mach-msm/msm_hotplug.c
	drivers/gpu/msm/kgsl_pwrscale_trustzone.c

preservative: hook into GPU and bump optimum fq. to 810 MHz again

Conflicts:
	arch/arm/mach-msm/acpuclock-8064.c
	drivers/gpu/msm/kgsl_pwrscale_trustzone.c

Add 189 MHz

Remove go-opt
intelli-plug: Extern early_suspended
Add CPU_FREQ_GOV_PRESERVATIVE
msm: kgsl: by franciscofranco squashed

Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
ARM: msm: remove clock-debug

This is only used for development and testing, remove it.
--mrg666

Conflicts:
	arch/arm/mach-msm/Makefile

ARM: msm: disable nohlt debugfs node

Conflicts:
	arch/arm/mach-msm/Makefile

ARM: msm: disable MSM_SMD_LOGGING

also modify Makefile so that smd_rpc_sym.c is only compiled when
MSM_SMD_LOGGING enabled since it is only needed by smem_log.c
--mrg666

Conflicts:
	arch/arm/configs/mako_config
msm: kgsl: Protect against a potential overflow in kgsl_sg_alloc

Avoid allocating a scatterlist so large that it overflows the size
passed to the memory allocators.

CRs-fixed: 564448
Change-Id: Ic0dedbad2ab421ddec8f3be38d61c9bdf9ae5bd4
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

msm: kgsl: Add check for NULL value from dev_get_drvdata

Check to see if dev_get_drvdata returns NULL and handle it.

CRs-Fixed: 552580
Change-Id: Ic0dedbad426dbbe15896608213067ee7337f3b34
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

msm: kgsl: Restrict the maximum memory entries for bulk cache sync

Restrict the maximum number of memory entries that can be specified
to a single bulk cache sync call to PAGE_SIZE / sizeof(unsigned int)
so that the allocation can always fit within one page.

CRs-fixed: 578062
Change-Id: Ic0dedbad07e1986cd6ccc5b260ffef82b5adb6d3
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

msm: kgsl: Fix mem leak when page allocation fails

Page allocation may fail during OOM condition. Update
sglen and size to correct value (allocated) so that
they get freed in kgsl_sharedmem_free().

Change-Id: I1aa0ca77bb767523dfcf0f6cc3a21eac2b6b80e4
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>