Commit ccd20945 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Try hard to bind the context

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/676Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Acked-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191205113726.413351-2-chris@chris-wilson.co.uk
parent a725d711
...@@ -113,13 +113,10 @@ void intel_context_unpin(struct intel_context *ce) ...@@ -113,13 +113,10 @@ void intel_context_unpin(struct intel_context *ce)
static int __context_pin_state(struct i915_vma *vma) static int __context_pin_state(struct i915_vma *vma)
{ {
u64 flags; unsigned int bias = i915_ggtt_pin_bias(vma) | PIN_OFFSET_BIAS;
int err; int err;
flags = i915_ggtt_pin_bias(vma) | PIN_OFFSET_BIAS; err = i915_ggtt_pin(vma, 0, bias | PIN_HIGH);
flags |= PIN_HIGH | PIN_GLOBAL;
err = i915_vma_pin(vma, 0, 0, flags);
if (err) if (err)
return err; return err;
......
...@@ -1934,9 +1934,7 @@ int gen6_ppgtt_pin(struct i915_ppgtt *base) ...@@ -1934,9 +1934,7 @@ int gen6_ppgtt_pin(struct i915_ppgtt *base)
* size. We allocate at the top of the GTT to avoid fragmentation. * size. We allocate at the top of the GTT to avoid fragmentation.
*/ */
if (!atomic_read(&ppgtt->pin_count)) { if (!atomic_read(&ppgtt->pin_count)) {
err = i915_vma_pin(ppgtt->vma, err = i915_ggtt_pin(ppgtt->vma, GEN6_PD_ALIGN, PIN_HIGH);
0, GEN6_PD_ALIGN,
PIN_GLOBAL | PIN_HIGH);
} }
if (!err) if (!err)
atomic_inc(&ppgtt->pin_count); atomic_inc(&ppgtt->pin_count);
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
#include "display/intel_frontbuffer.h" #include "display/intel_frontbuffer.h"
#include "gt/intel_engine.h" #include "gt/intel_engine.h"
#include "gt/intel_engine_heartbeat.h"
#include "gt/intel_gt.h" #include "gt/intel_gt.h"
#include "gt/intel_gt_requests.h"
#include "i915_drv.h" #include "i915_drv.h"
#include "i915_globals.h" #include "i915_globals.h"
...@@ -939,6 +941,38 @@ int i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags) ...@@ -939,6 +941,38 @@ int i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
return err; 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) void i915_vma_close(struct i915_vma *vma)
{ {
struct intel_gt *gt = vma->vm->gt; struct intel_gt *gt = vma->vm->gt;
......
...@@ -352,6 +352,7 @@ static inline void i915_vma_unlock(struct i915_vma *vma) ...@@ -352,6 +352,7 @@ static inline void i915_vma_unlock(struct i915_vma *vma)
int __must_check int __must_check
i915_vma_pin(struct i915_vma *vma, u64 size, u64 alignment, u64 flags); 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) static inline int i915_vma_pin_count(const struct i915_vma *vma)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment