staging: android: lowmemorykiller: select a new task to kill

Under certain circumstances, a process may take time to handle a SIGKILL.
When lowmemkiller is called again shortly after, it would pick the same
process to kill over and over, so that we cann't get free memory for long time.

Solution is to check fatal_signal_pending() on the selected task, and if it's
already pending, select a new task to kill.

Cherry-pick 5e3358093351e5d48e21250e31896b855542f22c
Reviewed-on: http://gerrit.pcs.mot.com/479831

Change-Id: I53445114451ffaba293f3c7174fb0b01ed0d34b6
Signed-off-by: Tianshui Shi <kfp634@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/505410
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
Reviewed-by: Jason Hrycay <jason.hrycay@motorola.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
(cherry picked from commit da093001caf06ed2296b4f79c84cc48ce713eac6)
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
trace: memkill: trace LMK and OOM kills

How to enable tracer:

  # mount -t debugfs nodev /sys/kernel/debug
  # echo 1 > /sys/kernel/debug/tracing/tracing_on
  # echo 1 > /sys/kernel/debug/tracing/events/memkill/enable
  # cat /sys/kernel/debug/tracing/trace

Event format:

  oom_kill: <pid> <comm> <total_vm> <anon_rss> <file_rss> <oom_score_adj> <order> <points> <cached> <freeswap>
  oom_kill_shared: <pid> <comm>
  lmk_kill: <pid> <comm> <selected_oom_adj> <selected_tasksize> <min_adj> <cached> <freeswap>

Change-Id: Ic45e181c62aead9b19d2a40363217f9220896096
Signed-off-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/480746
Reviewed-on: http://gerrit.pcs.mot.com/513174
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Jason Hrycay <jason.hrycay@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Thirumarai Selvi S <a16462@motorola.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Reviewed-by: Christopher Fries <qcf001@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit ef733ddfbb73cd33daf36720fa474ce4c8acb1f7)
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
trace: allow memkill tracing to be selectively enabled

Change-Id: I8a50d6b121192b0dc94e2a9a0e05246a47045e81
Signed-off-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/482673
Reviewed-on: http://gerrit.pcs.mot.com/513906
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Thirumarai Selvi S <a16462@motorola.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit fd9bd32cd8f005b0d2f6438935fdd0bc9654c938)
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
trace: memkill: per-zone page state for LMK

LMK considers memory status per zone. This change appends
gfp mask and per-zone free/file page state to LMK kill tracing.
A field <Node_id>:<Zone_id>:<Nr_free>:<Nr_page> is printed for
each zone.

Change-Id: I9627e5f486b1c32217c7d701fdaa7d05671c006b
Signed-off-by: Yuanyuan Zhong <a6510c@motorola.com>
(cherry picked from commit 2e59bf04b7634d3a9e28d088cb103f8d5fc18504)
Signed-off-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
trace: memkill: provide fixed zone info columns.

Maintain kernel trace log to always have fixed number of columns.

propagated_from: (CR)

Signed-off-by: Yi-wei Zhao <gbjc64@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/537078
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: David Ding <dding@motorola.com>
Reviewed-by: Dong-Dong Yang <gdb746@motorola.com>
Reviewed-by: Jeff Thompson <jthomps1@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit 8ac598bee92a14659b58f6ebaae4b3179fcc7e01)

Change-Id: I3e4ab2d5499a0f008b55bf3210fb40e234abc4a3
Reviewed-on: http://gerrit.pcs.mot.com/548484
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Reviewed-by: Jason Hrycay <jason.hrycay@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
staging: android: lowmemorykiller: implement task's adj rbtree

Based on the current LMK implementation, LMK has to scan all processes to
select the correct task to kill during low memory.
The basic idea for the optimization is to :
queue all tasks with oom_score_adj priority, and then LMK just selects the
proper task from the queue(rbtree) to kill.

performance improvement:
the current implementation: average time to find a task to kill : 1004us
the optimized implementation: average time to find a task to kill: 43us

Change-Id: I4dbbdd5673314dbbdabb71c3eff0dc229ce4ea91
Signed-off-by: Hong-Mei Li <a21834@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/548917
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
staging: android: lmk: check free memory when tasks switch to background

Add more free-memory check point.
This patch trigger low memory killer to scan free memory when a process is moved
to background task groups.

Change-Id: If50eef2fb2c05f57ab808f95a9408204058f4f9b
Signed-off-by: Hong-Mei Li <a21834@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/557973
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
SLTApproved: Yi-Wei Zhao <gbjc64@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
staging: android: lmk: skip if killed by lmk

A task can be selected to kill when it's already exiting. Sending
signal to the task at that state won't set TIF_SIGPENDING for it.
After that, every task including threads in the exiting task itself
running into lmk will compete for the mutex, then spend some time
waiting for the exiting task to release memory or try to send signal
to the same task again.
We want the exiting task to exit as early as possible but it's slowed
down greatly by the mutex and waiting. Skip lmk if current thread
group leader is exiting and is killed by lmk. Also delegate TIF_MEMDIE
to current task.

Change-Id: Id7839b81f183165871976666bfd4e04130a00610
Signed-off-by: Yuanyuan Zhong <zyy@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/584015
SLTApproved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Check Patch <CHEKPACH@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Russell Knize <rknize@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
staging: android: lmk: check TIF directly

When trying to fix that lmk can't kill an exiting task
(commit 895304e926352e0272964a421bd6271e47616ab3
(CR) staging: android: lmk: skip if killed by lmk),
additional check was added for the TIF_MEMDIE flag.
However the task lock has already been taken when examining
the task. The same helper function which tries to grab the
task lock again will be deadlocked.
Change to check the thread flag of thread group leader directly.

Change-Id: If1f880aaca2f053a54ab38c62f275f0a714eb5d2
Signed-off-by: Yuanyuan Zhong <zyy@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/587751
SLTApproved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Fix codec type detection failure error handling

Changes fixes the error handling exit point when the codec
type is not found.

Change-Id: I2923dc16880fe312741188b360620ea924fe4ca3
CRs-fixed: 517978
Signed-off-by: Gopikrishnaiah Anandan <agopik@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
mfd: wcd9xxx: Add support to parse new set of regulators

Chargepump supply to the codec can be supplied from multiple
regulators. Add support to maintain list of regulators for
chargepump that can be used by individual codec drivers to
dynamically enable/disable the regulators.

Change-Id: I22e2abac349f099ed60a786e50bc15cffd0a3aa2
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Correct the ondemand property for regulators

The chargepump regulators were incorrectly marked as static
regulators, causing the regulators to be enabled at boot time.
Correct the regulators, mark the chargepump regulators as
on-demand so they will be enabled only when needed.

Change-Id: I0ba9723e1fa2eaba4b69fc58b7c415bff6fe6ef5
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Change implementation to use callbacks

To use common mbhc code across multiple codecs, use
callback functions instead of mbhc version for each
codec. This will make the codec driver to handle the
codec dependent changes.

Change-Id: I83e1bab17a64add05baa83b6956e05fa5920be8a
Signed-off-by: Simmi Pateriya <simmip@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Enhance class H controller to support dynamic CP voltage

Codecs can operate at a lower voltage for vdd_buck, whereas
this voltage source being shared, it is not guaranteed that the
codec will always receive exactly the requested voltage. Add support
to class H controller to handle dynamic switching of the chargepump
voltage.

Change-Id: I68f93e0b070ec51db9b958f56c797edb5cbe0c85
Signed-off-by: Bhalchandra Gajare <gajare@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: fix HPHL DAC path enable sequence

The dac_ref_en bit should not be turned ON by codec
driver when headset is inserted. Setting the
dac_ref_en bit, and not resetting it when headset is
removed, will cause the DAPM framework to keep HPHL
DAC path connected.
This change returns the ownership of setting the
dac_ref_en bit to DAPM framework and fixes the HPHL DAC
path enablement issue when headset is inserted.

CRs-fixed: 483600
Change-Id: Iabfe09a82507579a443b87458dc8dba0d2cd5ce5
Signed-off-by: Banajit Goswami <bgoswa@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: don't assume PA is off during insertion detection

The mbhc find plug type can possibly run with audio playback on headphone.
This means micbias source can be from vddio as well as hphl status isn't
reliable.
Change micbias source to cfilt and don't refer hphl status when playback
is running with headphone during plug type detection.

Change-Id: Ie902b64927964c787dd91982d9236015ef302891
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Avoid mic schmitt trigger while finding plug type

Do not enable mic schmitt trigger when the plug type
determination work is interrupted by another mechanical
or electrical mbhc interrupt. Otherwise, enabling mic
schmitt trigger will cause spurious unwanted electrical
interrupts to be generated while plug type is getting
determined.

Change-Id: I3dce10b874c903ec517a6683cbcbc8d2a3d82c92
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: introduce headphone impedance detection support

Different headphones have different impedance that results in volume level
difference on ears as lower impedance headphone will have higher
volume with the same gain on PAs.
Provide impedance of headphones to be able to adjust gain according to
impedance so user can have consistent volume level with different
headphones.

Change-Id: I707f34344cd0068507bdd8a0192eb7afea1147f2
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: wcd9xxx: Add config variable to enable/disable impedance detection

Some of the codecs still do not support impedance detection feature.
Currently it is only enabled for wcd9320. So, add a config variable
to mbhc configuration to enable or disable impedance detection
calculation.

Change-Id: I2d32d4f3bbdcd6211accf1278dd5ab44d6520b6e
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>
ASoC: msm: Enable current source for plug type detection

Enable current source for detecting plug type on tapan.
Update cs_enable_flags accordingly to use current source
during insertion, polling and removal of the plug.

Change-Id: Iab8a79ef377b5a3bdf9cefa6a9b5ad33ece9c8a7
Signed-off-by: Phani Kumar Uppalapati <phaniu@codeaurora.org>
Signed-off-by: Dan Trifan <jimsth@gmail.com>