[03/11] drm/i915: Wait until the intel_wakeref idle callback is complete
diff mbox series

Message ID 20191116175139.1790440-3-chris@chris-wilson.co.uk
State New
Headers show
Series
  • [01/11] drm/i915/gt: Close race between engine_park and intel_gt_retire_requests
Related show

Commit Message

Chris Wilson Nov. 16, 2019, 5:51 p.m. UTC
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>
---
 drivers/gpu/drm/i915/intel_wakeref.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/drivers/gpu/drm/i915/intel_wakeref.c b/drivers/gpu/drm/i915/intel_wakeref.c
index 8084cded62db..1241e3a3c024 100644
--- a/drivers/gpu/drm/i915/intel_wakeref.c
+++ b/drivers/gpu/drm/i915/intel_wakeref.c
@@ -98,10 +98,24 @@  void __intel_wakeref_init(struct intel_wakeref *wf,
 	INIT_WORK(&wf->work, __intel_wakeref_put_work);
 }
 
+static bool is_idle_wait(struct intel_wakeref *wf)
+{
+	bool result;
+
+	if (intel_wakeref_is_active(wf))
+		return false;
+
+	/* serialise with the wf->put() callback; wait until finished */
+	mutex_lock(&wf->mutex);
+	result = !intel_wakeref_is_active(wf);
+	mutex_unlock(&wf->mutex);
+
+	return result;
+}
+
 int intel_wakeref_wait_for_idle(struct intel_wakeref *wf)
 {
-	return wait_var_event_killable(&wf->wakeref,
-				       !intel_wakeref_is_active(wf));
+	return wait_var_event_killable(&wf->wakeref, is_idle_wait(wf));
 }
 
 static void wakeref_auto_timeout(struct timer_list *t)