[Intel-gfx] [PATCH] drm/i915: Optimize drop-caches

Chris Wilson chris at chris-wilson.co.uk
Tue Jan 30 15:44:12 UTC 2018


Although this is a debugfs routine, so it may seem a little pointless to
optimize, it is heavily used by igt to idle the driver and HW between
every test. As such, speeding it from 40ms to 40us on a plain Broadwell
system is beneficial overall.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala at linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 3849ded354e3..db49c699036b 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -4045,16 +4045,20 @@ static int
 i915_drop_caches_set(void *data, u64 val)
 {
 	struct drm_i915_private *dev_priv = data;
-	struct drm_device *dev = &dev_priv->drm;
 	int ret = 0;
 
 	DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
 		  val, val & DROP_ALL);
 
-	/* No need to check and wait for gpu resets, only libdrm auto-restarts
-	 * on ioctls on -EAGAIN. */
-	if (val & (DROP_ACTIVE | DROP_RETIRE)) {
-		ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (val & DROP_ACTIVE) {
+		ret = i915_gem_wait_for_idle(dev_priv, I915_WAIT_INTERRUPTIBLE);
+		if (ret)
+			return ret;
+	}
+
+	if (val & (DROP_ACTIVE | DROP_RETIRE) &&
+	    READ_ONCE(dev_priv->gt.active_requests)) {
+		ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
 		if (ret)
 			return ret;
 
@@ -4066,7 +4070,7 @@ i915_drop_caches_set(void *data, u64 val)
 		if (val & DROP_RETIRE)
 			i915_gem_retire_requests(dev_priv);
 
-		mutex_unlock(&dev->struct_mutex);
+		mutex_unlock(&dev_priv->drm.struct_mutex);
 	}
 
 	fs_reclaim_acquire(GFP_KERNEL);
@@ -4084,8 +4088,9 @@ i915_drop_caches_set(void *data, u64 val)
 		drain_delayed_work(&dev_priv->gt.idle_work);
 
 	if (val & DROP_FREED) {
-		synchronize_rcu();
-		i915_gem_drain_freed_objects(dev_priv);
+		synchronize_rcu_expedited();
+		if (flush_work(&dev_priv->mm.free_work))
+			i915_gem_drain_freed_objects(dev_priv);
 	}
 
 	return ret;
-- 
2.15.1



More information about the Intel-gfx mailing list