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 <[email protected]>
Cc: Mika Kuoppala <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
---
 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

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to