drm/i915: Try hard to bind the context
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 5 Dec 2019 11:37:25 +0000 (11:37 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 5 Dec 2019 13:50:54 +0000 (13:50 +0000)
It is not acceptable for context pinning to fail with -ENOSPC as we
should always be able to make space in the GGTT. The only reason we may
fail is that other "temporary" context pins are reserving their space
and we need to wait for an available slot.

Closes: https://gitlab.freedesktop.org/drm/intel/issues/676
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191205113726.413351-2-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gt/intel_context.c
drivers/gpu/drm/i915/i915_gem_gtt.c
drivers/gpu/drm/i915/i915_vma.c
drivers/gpu/drm/i915/i915_vma.h

index c5e52ad..61c39e9 100644 (file)
@@ -113,13 +113,10 @@ void intel_context_unpin(struct intel_context *ce)
 
 static int __context_pin_state(struct i915_vma *vma)
 {
-       u64 flags;
+       unsigned int bias = i915_ggtt_pin_bias(vma) | PIN_OFFSET_BIAS;
        int err;
 
-       flags = i915_ggtt_pin_bias(vma) | PIN_OFFSET_BIAS;
-       flags |= PIN_HIGH | PIN_GLOBAL;
-
-       err = i915_vma_pin(vma, 0, 0, flags);
+       err = i915_ggtt_pin(vma, 0, bias | PIN_HIGH);
        if (err)
                return err;
 
index 10b3d6d..4da1dfe 100644 (file)
@@ -1934,9 +1934,7 @@ int gen6_ppgtt_pin(struct i915_ppgtt *base)
         * size. We allocate at the top of the GTT to avoid fragmentation.
         */
        if (!atomic_read(&ppgtt->pin_count)) {
-               err = i915_vma_pin(ppgtt->vma,
-                                  0, GEN6_PD_ALIGN,
-                                  PIN_GLOBAL | PIN_HIGH);
+               err = i915_ggtt_pin(ppgtt->vma, GEN6_PD_ALIGN, PIN_HIGH);
        }
        if (!err)
                atomic_inc(&ppgtt->pin_count);
index 564fa97..6db35b9 100644 (file)
@@ -28,7 +28,9 @@
 #include "display/intel_frontbuffer.h"
 
 #include "gt/intel_engine.h"
+#include "gt/intel_engine_heartbeat.h"
 #include "gt/intel_gt.h"
+#include "gt/intel_gt_requests.h"
 
 #include "i915_drv.h"
 #include "i915_globals.h"
@@ -939,6 +941,38 @@ err_pages:
        return err;
 }
 
+static void flush_idle_contexts(struct intel_gt *gt)
+{
+       struct intel_engine_cs *engine;
+       enum intel_engine_id id;
+
+       for_each_engine(engine, gt, id)
+               intel_engine_flush_barriers(engine);
+
+       intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
+}
+
+int i915_ggtt_pin(struct i915_vma *vma, u32 align, unsigned int flags)
+{
+       struct i915_address_space *vm = vma->vm;
+       int err;
+
+       GEM_BUG_ON(!i915_vma_is_ggtt(vma));
+
+       do {
+               err = i915_vma_pin(vma, 0, align, flags | PIN_GLOBAL);
+               if (err != -ENOSPC)
+                       return err;
+
+               /* Unlike i915_vma_pin, we don't take no for an answer! */
+               flush_idle_contexts(vm->gt);
+               if (mutex_lock_interruptible(&vm->mutex) == 0) {
+                       i915_gem_evict_vm(vm);
+                       mutex_unlock(&vm->mutex);
+               }
+       } while (1);
+}
+
 void i915_vma_close(struct i915_vma *vma)
 {
        struct intel_gt *gt = vma->vm->gt;
index f09f4f5..0e0b61c 100644 (file)
@@ -352,6 +352,7 @@ static inline void i915_vma_unlock(struct i915_vma *vma)
 
 int __must_check
 i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags);
+int i915_ggtt_pin(struct i915_vma *vma, u32 align, unsigned int flags);
 
 static inline int i915_vma_pin_count(const struct i915_vma *vma)
 {