From 249a6daa5dab70e6289111687a3e4926f018ae6d Mon Sep 17 00:00:00 2001
From: Jordan Crouse <jcrouse@codeaurora.org>
Date: Tue, 15 Oct 2013 09:05:53 -0600
Subject: [PATCH] msm: kgsl: Re-run the events handler when inflight goes to
 zero

The event code is sensitive to race conditions with the GPU. We just
can't spend all day the event loops waiting for timestamp to expire.
The dispatcher loop on the other hand is far less sensitive to the
race with the GPU so we have a very good idea when the GPU is idle.

When inflight goes to zero re-run re-queue the event handler to catch
any stragglers.

Conflicts:

	drivers/gpu/msm/adreno_dispatch.c

CRs-fixed: 551825
Change-Id: Ic0dedbad9d02fca89724bf791d9c7212712a8014
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
---
 drivers/gpu/msm/adreno_dispatch.c |  6 ++++--
 drivers/gpu/msm/kgsl_events.c     | 12 +-----------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/msm/adreno_dispatch.c b/drivers/gpu/msm/adreno_dispatch.c
index 67dba70167d7..3bcc7a3bb8f7 100644
--- a/drivers/gpu/msm/adreno_dispatch.c
+++ b/drivers/gpu/msm/adreno_dispatch.c
@@ -1332,12 +1332,14 @@ static void adreno_dispatcher_work(struct work_struct *work)
 	 * into suspend even if there are queued command batches
 	 */
 
+	mutex_lock(&device->mutex);
 	if (count && dispatcher->inflight == 0) {
-		mutex_lock(&device->mutex);
 		del_timer_sync(&dispatcher->fault_timer);
 		kgsl_active_count_put(device);
-		mutex_unlock(&device->mutex);
+		/* Queue back up the event processor to catch stragglers */
+		queue_work(device->work_queue, &device->ts_expired_ws);
 	}
+	mutex_unlock(&device->mutex);
 
 	/* Dispatch new commands if we have the room */
 	if (dispatcher->inflight < _dispatcher_inflight)
diff --git a/drivers/gpu/msm/kgsl_events.c b/drivers/gpu/msm/kgsl_events.c
index ad122adf8fe0..277eae0127c2 100644
--- a/drivers/gpu/msm/kgsl_events.c
+++ b/drivers/gpu/msm/kgsl_events.c
@@ -383,19 +383,9 @@ void kgsl_process_events(struct work_struct *work)
 	struct kgsl_context *context, *tmp;
 	uint32_t timestamp;
 
-	/*
-	 * Bail unless the global timestamp has advanced.  We can safely do this
-	 * outside of the mutex for speed
-	 */
-
-	timestamp = kgsl_readtimestamp(device, NULL, KGSL_TIMESTAMP_RETIRED);
-	if (timestamp == device->events_last_timestamp)
-		return;
-
 	mutex_lock(&device->mutex);
 
-	device->events_last_timestamp = timestamp;
-
+	timestamp = kgsl_readtimestamp(device, NULL, KGSL_TIMESTAMP_RETIRED);
 	_retire_events(device, &device->events, timestamp);
 
 	/* Now process all of the pending contexts */
-- 
GitLab