diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2020-01-09 08:57:15 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2020-01-09 13:48:00 +0000 |
commit | 89f98d634f6b7a8433b59fef1543634b20fc18f2 (patch) | |
tree | 271d77c8aa8b4812c1e52d4b7b87756af461b732 /drivers/gpu/drm/i915/gt/intel_context.c | |
parent | feed5c7be22c25e9c777c821bcf955a13cf010ab (diff) |
drm/i915/gt: Push context state allocation earlier
Allow for knowledgeable users to preallocate the context state, and to
separate the allocation step from the pinning step during
intel_context_pin()
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200109085717.873326-1-chris@chris-wilson.co.uk
Diffstat (limited to 'drivers/gpu/drm/i915/gt/intel_context.c')
-rw-r--r-- | drivers/gpu/drm/i915/gt/intel_context.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index 5ea8305fd633..bc5ae18dbe3e 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -43,24 +43,42 @@ intel_context_create(struct intel_engine_cs *engine) return ce; } +int intel_context_alloc_state(struct intel_context *ce) +{ + int err = 0; + + if (mutex_lock_interruptible(&ce->pin_mutex)) + return -EINTR; + + if (!test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) { + err = ce->ops->alloc(ce); + if (unlikely(err)) + goto unlock; + + set_bit(CONTEXT_ALLOC_BIT, &ce->flags); + } + +unlock: + mutex_unlock(&ce->pin_mutex); + return err; +} + int __intel_context_do_pin(struct intel_context *ce) { int err; + if (unlikely(!test_bit(CONTEXT_ALLOC_BIT, &ce->flags))) { + err = intel_context_alloc_state(ce); + if (err) + return err; + } + if (mutex_lock_interruptible(&ce->pin_mutex)) return -EINTR; if (likely(!atomic_read(&ce->pin_count))) { intel_wakeref_t wakeref; - if (unlikely(!test_bit(CONTEXT_ALLOC_BIT, &ce->flags))) { - err = ce->ops->alloc(ce); - if (unlikely(err)) - goto err; - - __set_bit(CONTEXT_ALLOC_BIT, &ce->flags); - } - err = 0; with_intel_runtime_pm(ce->engine->uncore->rpm, wakeref) err = ce->ops->pin(ce); |