[Intel-gfx] [PATCH] drm/i915: Prefer to reschedule the free_object worker rather than block

Chris Wilson chris at chris-wilson.co.uk
Tue Mar 28 15:18:16 UTC 2017


Avoid blocking the kworker by putting back the freed object list if we
cannot immediately take the mutex. We will try again shortly, and flush
the work when desperate.

References: https://bugs.freedesktop.org/show_bug.cgi?id=100434
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index ab77e38ec264..c2e5cb529b0f 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -4200,7 +4200,19 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
 {
 	struct drm_i915_gem_object *obj, *on;
 
-	mutex_lock(&i915->drm.struct_mutex);
+	if (!mutex_trylock(&i915->drm.struct_mutex)) {
+		/* If we fail to acquire the struct_mutex, put back the
+		 * freed list and we will try again in the future. By
+		 * rescheduling the task we prevent us from blocking
+		 * the worker indefinitely on a prolonged wait for
+		 * struct_mutex.
+		 */
+		if (llist_add_batch(llist_reverse_order(freed), freed,
+				    &i915->mm.free_list))
+			schedule_work(&i915->mm.free_work);
+		return;
+	}
+
 	intel_runtime_pm_get(i915);
 	llist_for_each_entry(obj, freed, freed) {
 		struct i915_vma *vma, *vn;
-- 
2.11.0



More information about the Intel-gfx mailing list