[PATCH] mutex: dynamically disable mutex spinning at high load Date
 Thu, 4 Apr 2013 10:54:18 -0400

The Linux mutex code has a MUTEX_SPIN_ON_OWNER configuration
option that was enabled by default in major distributions like Red
Hat. Allowing threads waiting on mutex to spin while the mutex owner
is running will theoretically reduce latency on the acquisition of
mutex at the expense of energy efficiency as the spinning threads
are doing no useful work.

This is not a problem on a lightly loaded system where the CPU may
be idle anyway. On a highly loaded system, the spinning tasks may be
blocking other tasks from running even if they have higher priority
because the spinning was done with preemption disabled.

This patch will disable mutex spinning if the current load is high
enough. The load is considered high if there are 2 or more active tasks
waiting to run on the current CPU. If there is only one task waiting,
it will check the average load at the past minute (calc_load_tasks).
If it is more than double the number of active CPUs, the load is
considered high too.  This is a rather simple metric that does not
incur that much additional overhead.

The AIM7 benchmarks were run on 3.7.10 derived kernels to show the
performance changes with this patch on a 8-socket 80-core system
with hyperthreading off.  The table below shows the mean % change
in performance over a range of users for some AIM7 workloads with
just the less atomic operation patch (patch 1) vs the less atomic
operation patch plus this one (patches 1+3).

+--------------+-----------------+-----------------+-----------------+
|   Workload   | mean % change   | mean % change   | mean % change   |
|              | 10-100 users    | 200-1000 users  | 1100-2000 users |
+--------------+-----------------+-----------------+-----------------+
| alltests     |      0.0%       |     -0.1%       |    +5.0%        |
| five_sec     |     +1.5%       |     +1.3%       |    +1.3%        |
| fserver      |     +1.5%       |    +25.4%       |    +9.6%        |
| high_systime |     +0.1%       |      0.0%       |    +0.8%        |
| new_fserver  |     +0.2%       |    +11.9%       |   +14.1%        |
| shared       |     -1.2%       |     +0.3%       |    +1.8%        |
| short        |     +6.4%       |     +2.5%       |    +3.0%        |
+--------------+-----------------+-----------------+-----------------+
It can be seen that this patch provides some big performance
improvement for the fserver and new_fserver workloads while is still
generally positive for the other AIM7 workloads.

Signed-off-by: Waiman Long <Waiman.Long@hp.com>
Reviewed-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
modified for tuna kernel from LKML

Signed-off-by: Paul Reioux <reioux@gmail.com>
time: cast ->raw_interval to u64 to avoid shift overflow
Backport AIO from Linux 3.6.x

varunchitre15 <sachya001@hotmail.com>
shooteru:compile with -O2
backport lowmemorykiller from Google android kernel 3.4
lowmemorykiller: make default lowmemorykiller debug message useful

lowmemorykiller debug messages are inscrutable and mostly useful
for debugging the lowmemorykiller, not explaining why a process
was killed.  Make the messages more useful by prefixing them
with "lowmemorykiller: " and explaining in more readable terms
what was killed, who it was killed for, and why it was killed.

The messages now look like:
[   76.997631] lowmemorykiller: Killing 'droid.gallery3d' (2172), adj 1000,
[   76.997635]    to free 27436kB on behalf of 'kswapd0' (29) because
[   76.997638]    cache 122624kB is below limit 122880kB for oom_score_adj 1000
[   76.997641]    Free memory is -53356kB above reserved

A negative number for free memory above reserved means some of the
reserved memory has been used and is being regenerated by kswapd,
which is likely what called the shrinkers.

Change-Id: I1fe983381e73e124b90aa5d91cb66e55eaca390f
Signed-off-by: Colin Cross <ccross@android.com>
lib/string: use glibc version
tmpfs: fix mempolicy object leaks This patch fixes several mempolicy leaks in the tmpfs mount logic. These leaks are slow - on the order of one object leaked per mount attempt.

Leak 1 (umount doesn't free mpol allocated in mount):
    while true; do
        mount -t tmpfs -o mpol=interleave,size=100M nodev /mnt
        umount /mnt
    done

Leak 2 (errors parsing remount options will leak mpol):
    mount -t tmpfs -o size=100M nodev /mnt
    while true; do
        mount -o remount,mpol=interleave,size=x /mnt 2> /dev/null
    done
    umount /mnt

Leak 3 (multiple mpol per mount leak mpol):
    while true; do
        mount -t tmpfs -o mpol=interleave,mpol=interleave,size=100M nodev /mnt
        umount /mnt
    done

This patch fixes all of the above.  I could have broken the patch into
three pieces but is seemed easier to review as one.

Signed-off-by: Greg Thelen <gthelen@google.com>
modified for Mako kernel from LKML reference

Signed-off-by: faux123 <reioux@gmail.com>
Added optimized ARM RWSEM algorithm

Author:    Ezekeel <Ezekeel@gmail.com>
Add Dynamic read-ahead
rwsem: steal writing sem for better performance
Commit 5a50508 changes to rwsem from mutex, caused aim7 fork_test
performance to dropped 50%. Yuanhan liu did an analysis, found it was
caused by strict sequential writing. Ingo suggest stealing sem writing from
front task in wait queue. https://lkml.org/lkml/2013/1/29/84

So does this patch.
In this patch, I just allow write stealing to happen when the first waiter
is also writer. The performance fully is now fully recovered.

Reported-by: lkp@linux.intel.com
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Alex Shi <alex.shi@intel.com>
sched: disable gentle fair sleepers
msm: smd: Add SMSM state queue

To reduce the chance of missing SMSM state transitions,
push the SMSM state into a queue in the interrupt handler
and then pull the state for processing the in callback
workqueue.

Change-Id: Ib66bc15f7445369ea7ad2ca271a79ac10b8105a0
CRs-Fixed: 323725
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
msm: smd: add separate return code if SMD port is closing

Add EAGAIN return code if SMD port has been allocated, but
is currently pending a remote close.  This allows the client
to differentiate between ENODEV (port doesn't exist)
and EAGAIN (port not ready to be opened).

(cherry picked from commit bb2b1faf7d0fd51457e6fc452eef6c52f2023c64)

Change-Id: I1b057c0e3cc36b87f2d724325304ec941fcdb536
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
msm: smsm: Add SMSM notifier wakelock.

CRs-Fixed : 345581

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
(cherry picked from commit ff461d9d828499fec86b269cc65a3cfed8c5aaac)

Change-Id: I24845f52271fa98c36ec026bbf182240e965270a
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: smsm: Add SMSM notifier wakelock

Add wakelock that is locked in the SMSM interrupt handler and unlocked
in the workqueue after notifications have been completed.

This prevents the sleep code from putting the system to sleep before the
SMSM notification workqueue gets scheduled.

Change-Id: I45c4bc210d638ebccfecef883bb62abfbf9f2a1b
CRs-Fixed: 345581
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
msm: smd: Remove duplicate variable definitions

Remove duplicate local variable definitions that cause
variable aliasing and could result in accessing a null
pointer when dealing with open-close-open race
condition.

Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
(cherry picked from commit 724f317cf6176d0a48a994d0f98a4fb73019e3ce)

Change-Id: Ia891810ab42aa214a12fc7be7a09ed34dfdef387
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: smd: Do not use wakelock for local DEM notifications

Notify local SMSM callback clients without using a wakelock since SMSM
signaling is used by power management during power-down/-up sequencing
on DEM-based targets.  Grabbing a wakelock in this case will abort
power-down sequencing.

(cherry picked from commit da31d046ba0c5d3d1f674e9d35a39e9d0e4ae4df)

Change-Id: I1f7e3a3ae049573baaf8866efd79ad324a248f61
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
(cherry picked from commit 2240228f3be50b8a0ebd60d5f36cf6314f156404)
(cherry picked from commit 32c89ee88b9e1f020ba075d3688afb4d99033799)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: smsm: Fix race condition in SMSM notification

The SMSM snapshot logic takes a snapshot of the current SMSM state,
places it into a FIFO, increments a wakelock count, and then signals a
worker to process the state changes.  The worker processes the state
changes and then decrements the wakelock count.

In the previous case, the code would do the following:

Interrupt handler:
 1) insert data into FIFO
 2) increment wakelock count

Worker:
 a) verifies >= 1 snapshots are in FIFO
 b) processes snapshot
 c) decrements wakelock reference count

If the interrupt handler is interrupted between steps 1 and 2, then the
function flow would be 1abc2.  In this case, step c would fail because
the wakelock count would be zero and the wakelock would remain at 1 and
locked even though the FIFO would be empty.  This results in the
wakelock not getting released.

To resolve this, the order of 2 (now 1') and 1 (now 2') was swapped
which always ensures 1' will always occur before abc which results in
the proper ordering 1'2'abc.

CRS-Fixed: 349099
Change-Id: I388b4c2f76838f59337e94f83b65fa06e81bb875
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
(cherry picked from commit 96b55f6ec25d5812a0492fc39b6b44a6141795d2)
(cherry picked from commit 8c17b69afa7f2b7eb10df635f984b15d08c71da5)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: smd: Fix race condition while processing SMSM callback

When SMSM interrupt is received, a snapshot of SMSM callback is stored
in a kfifo. The snapshot is stored as
	a) SMSM state of each subsystem
	b) Wakelock usage information.

Then a work item is scheduled in global workqueue to process the snapshot
and notify the smsm clients. The smsm snapshot is processed as
	1) Lock the snapshot
	2) Retrieve SMSM states from kfifo and process them
	3) Unlock the snapshot
	4) Retrieve Wakelock usage information from kfifo

When back-to-back smsm interrupts are received, multiple work items are
scheduled in multiple cores. The first work item performs steps 1, 2 &
3 and got pre-empted. In the meanwhile the second work item starts
with Wakelock usage information and reports wrong smsm state to the SMSM
clients.

So schedule the work items in a single thread workqueue and interchange
steps 3 & 4 while processing the SMSM snapshot.

CRs-Fixed: 353552
Change-Id: Ic08e242653cc8d1648ad7a70bf7c5f6b7c089c4e
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
(cherry picked from commit 3249a223df201088289d113b80c70b9d23dea847)
(cherry picked from commit 492417630c5e4e42c09b7fe36c53dc9882a4ce4b)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>