cpufreq: interactive: take idle notifications only when
 active

Register an idle notifier only when the governor is active.  Also
short-circuit work of idle end if the governor is not enabled.

Signed-off-by: Sam Leffler <sleffler@chromium.org>
Change-Id: I4cae36dd2e7389540d337d74745ffbaa0131870f
cpufreq: interactive: keep freezer happy when not current
 governor

Fix a problem where the hung task mechanism was deeming the interactive
clock boost thread as hung.  This was because the thread is created at
module init but never run/woken up until needed.  If the governor is not
being used this can be forever.  To workaround this explicitly wake up
the thread once all the necessary data structures are initialized.  The
latter required some minor code shuffle.

Signed-off-by: Sam Leffler <sleffler@chromium.org>
Change-Id: Ie2c058dd75dcb6460ea10e7ac997e46baf66b1fe
cpufreq: interactive: handle speed up and down in the
 realtime task

Not useful to have a separate, non-realtime workqueue for speed down
events, avoid priority inversion for speed up events.

Change-Id: Iddcd05545245c847aa1bbe0b8790092914c813d2
Signed-off-by: Todd Poynor <toddpoynor@google.com>
cpufreq: interactive: remove input_boost handling

Now handled in userspace Power HAL instead.

Change-Id: I78a4a2fd471308bfcd785bbefcc65fede27314cf
Signed-off-by: Todd Poynor <toddpoynor@google.com>
cpufreq: Fix panic when setting sampling rate

Kernel panics when trying to set the sampling rate before the ondemand
governor CPUFREQ_GOV_START notification is received.

[<c078e500>] panic+0x15c
[<c0012354>] die+0x19c
[<c0018e60>] __do_kernel_fault+0x64
[<c0793660>] do_page_fault+0x3b8
[<c0008514>] do_DataAbort+0x134
[<c0791c58>] __dabt_svc+0x38
[<c02b5c68>] __list_add+0x38
[<c078f1b0>] __mutex_lock_slowpath+0x128
[<c078fc68>] mutex_lock+0x20
[<c05409c4>] store_sampling_rate+0x98
[<c02a6648>] kobj_attr_store+0x18
[<c0183124>] sysfs_write_file+0x108
[<c0131758>] vfs_write+0xac
[<c013188c>] sys_write+0x3c
[<c000e340>] ret_fast_syscall+0x0

Initialize the mutex as part of cpufreq_gov_dbs_init().

Change-Id: Ie9014407d724d7a0a81c076be47df5d08f513407
Signed-off-by: Praveen Chidambaram <pchidamb@codeaurora.org>
cpufreq: fix interactive bug during hotplug

When a new cpu is added and if does not enter idle
for long, the interactive timer is not started and hence
the cpu remains at lowest frequecny, despite the system
load. This impacts mainly benchmarks. Starting a timer
at governor start to handle low frequency.

Change-Id: I8ac9705b9f166a95715c985efacd2ae8ef387cb7
Signed-off-by: Narayanan Gopalakrishnan <nargop@codeaurora.org>
msm: ipc: Fix race condition between route & close_port
 operations

QMI Client is closing the interface port with IPC Router, while the
IPC Router is handling an incoming QMI message from modem for that
client. There is a race condition between these two operations. This in
turn leads to IPC Router trying to lock the wakelock which has been
destroyed as part of close operation. IPC Router gains exclusive
access to the interface port information, so that close operation
does not happen in parallel to the route operation.

CRs-Fixed: 367561
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
(cherry picked from commit be9954bc046aa9238f17fd2d420973a273906b81)

Change-Id: Ieff91b8959003a4d19e7c8d6a6aa2f1b39698990
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: ipc: Update the work item in the read path

IPC Message Router schedules a work item to read incoming messages
from the remote subsystems. Once a message is read, the work item
queues itself again in the workqueue. The queued work item performs
an uninterruptible wait for further messages. This causes the "loadavg"
to be consistently greater than 1. So refactor the read path such that
the read work item is queued only after the message has arrived.

CRs-Fixed: 383657
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
(cherry picked from commit 872ecd84746547eb5d82c04080439b46fc2426d7)

Change-Id: If91e8738bad8b33f91af55ec69795693e20b3d3e
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: kgsl: Always add a start identifier to a command
 sequence

Add command sequence start identifier for commands submitted from
kgsl as well since this will be used during recovery. We will just
try recovery and not try to differentiate between commands from
kgsl or from user space.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit c3ad5803d537142ae15841afefba0831e9ed6134)

Change-Id: Ic4c499e5a8ba2201b07f3892ec1147beb36222a1
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Introduce recovery data structure for hang
 recovery

Create a new data structure that holds all the information required
for recovering from hangs. This data structure is initialized as soon
as hang is detected because if the GPU is under DOS attack then by
the time we start recovery the recovery data may have changed.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit ba6c70b85941267c552b154be1729aef4e944da6)

Change-Id: I1c3e6931ee41565dd24ba40473f0200d9b0edaff
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Dhivya Subramanian <dthiru@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Use recovery data structure to extract valid
 commands

Use the data set in the recovery structure when extracting
valid commands from the ringbuffer instead of reading
it from the device/memory.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit adb1602262d7a8cf988ef1ced622ea6cc1aecc99)

Change-Id: Ifb8df7bd5d22424a2f942ec30ebe47d20b2c7fd5
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Create a separate function to extract valid
 commands

Create a separate function that extracts valid commands from good
contexts and invalid commands from bad contexts during recovery

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 1d577fe6fc5cdf768c5f3fe59b56adcd0e86db19)

Change-Id: Ic5d570a049032d2eb54094829bc12462d7aa65fc
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Separate function to detect last command in
 recovery

Make the code more readable by writing a separate function to
detect the end of last command that is assumed to be successfully
executed by the GPU

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit bb7b32a2cd7c42783f608fa750b7cb23821a587e)

Change-Id: Ibd71fd588533e99747607c7725aae8f098127478
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Turn on preamble to enable replay of commands

Turn on the preamble of the IB sequence in which hang is assumed
to have happened so that the bad sequence can be replayed.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 2a85f1fb19278fa530cb31dca0198583b77fc8be)

Change-Id: I3f572c02f0805b6acdf4dac669416ff202950117
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Do not restore per context timestamp states

We do not have to restore the per context timestamp states during
recovery as this data is irrelevant after recovery.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 1caba1c8066b77d3955300c95a9be2489418b094)

Change-Id: I054bbac15c250e3caf80ace8312bf30b95202996
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Write a separate function to set the reset status

Write a separate function that sets the reset status of each
context after recovery.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 29ed38ee8491fd873b304f3d2edad2a4a0395017)

Change-Id: Id59fc0e193b4ef8b2e424556fde25aa948f335dd
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Mark the hung context in recovery before
 extraction

Mark the context that has caused a hang in recovery before
calling the extraction function. This updates the context
state correctly early in recovery.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit b9f1e831b78da1192c189aab507272298ae9eb9b)

Change-Id: I07ebb82a1c64b72113cdd7ae17f9e0c699077ab3
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Expire timestamps after recovery

Expire the global timestamp and timestamps of contexts that have
cause at the end of recovery. This will prevent any users waiting
on timestamps of hung contexts to return without waiting.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 5f085f45b19b1fd209eef1cb02b2bb68ad40f505)

Change-Id: Ie4da058f215398440c02c0bf1bea60fa60764e13
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: Try to replay commands from bad context in
 recovery

Replay the all the commands that have not been executed by the GPU
in recovery with preamble turned on for the first command to see
if that succeeds. If it does then we have recovered all contexts.
If that fails then replay commands only from contexts that are
in a good state.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 32240ef6d4ae43ea735aad0b023d2a1305203415)

Conflicts:

	drivers/gpu/msm/adreno.c

Change-Id: Id81e1ba50c83dde37077d2fa2bcbf565e1c604a7
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>

Conflicts:

	drivers/gpu/msm/adreno.c

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: kgsl: In recovery search for command stream after
 global eop

In recovery search for the timestamp of the command stream after
global eop instead of searching for the command stream of the
global eop and then moving the pointer forward till the start of
the command stream following global eop. This is because if the
ringbuffer is full then the global eop timestamp may have been
overwritten, so its more reliable to search for the timestamp
that occurs after global eop.

CRs-Fixed: 351680
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
(cherry picked from commit 6f6ecb3ef3eb66ef8e07ae8473682f8b36091376)

Change-Id: I3b9d76588b0cb9f83a4eb089b8c4b31bfcc9a22d
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>