drm/i915: Wait until the intel_wakeref idle callback is complete
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 18 Nov 2019 23:02:46 +0000 (23:02 +0000)
committerJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Mon, 25 Nov 2019 13:28:59 +0000 (15:28 +0200)
When waiting for idle, serialise with any ongoing callback so that it
will have completed before completing the wait.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191118230254.2615942-12-chris@chris-wilson.co.uk
(cherry picked from commit f4ba0707c825d60f1d0f5ce7bd3d875e68f3e204)
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
drivers/gpu/drm/i915/intel_wakeref.c
drivers/gpu/drm/i915/intel_wakeref.h

index 868cc78048d00a6bf5bb716168559fe08aacb587..ad26d7f4ca3df1b004b24540d8ca161e3b463256 100644 (file)
@@ -109,8 +109,17 @@ void __intel_wakeref_init(struct intel_wakeref *wf,
 
 int intel_wakeref_wait_for_idle(struct intel_wakeref *wf)
 {
-       return wait_var_event_killable(&wf->wakeref,
-                                      !intel_wakeref_is_active(wf));
+       int err;
+
+       might_sleep();
+
+       err = wait_var_event_killable(&wf->wakeref,
+                                     !intel_wakeref_is_active(wf));
+       if (err)
+               return err;
+
+       intel_wakeref_unlock_wait(wf);
+       return 0;
 }
 
 static void wakeref_auto_timeout(struct timer_list *t)
index 5f0c972a80fb433d08b474fdb21e7da7b0d589ae..affe4de3746b56c496332b4963b1ef956191b5e6 100644 (file)
@@ -151,6 +151,21 @@ intel_wakeref_unlock(struct intel_wakeref *wf)
        mutex_unlock(&wf->mutex);
 }
 
+/**
+ * intel_wakeref_unlock_wait: Wait until the active callback is complete
+ * @wf: the wakeref
+ *
+ * Waits for the active callback (under the @wf->mutex or another CPU) is
+ * complete.
+ */
+static inline void
+intel_wakeref_unlock_wait(struct intel_wakeref *wf)
+{
+       mutex_lock(&wf->mutex);
+       mutex_unlock(&wf->mutex);
+       flush_work(&wf->work);
+}
+
 /**
  * intel_wakeref_is_active: Query whether the wakeref is currently held
  * @wf: the wakeref