[Intel-gfx] [PATCH 16/29] drm/i915: Export intel_context_instance()
We want to pass in a intel_context into intel_context_pin() and that requires us to first be able to lookup the intel_context! Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/gt/intel_context.c| 37 +++--- drivers/gpu/drm/i915/gt/intel_context.h| 19 +++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 8 - drivers/gpu/drm/i915/gt/mock_engine.c | 8 - drivers/gpu/drm/i915/gvt/scheduler.c | 7 +++- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +-- drivers/gpu/drm/i915/i915_perf.c | 21 drivers/gpu/drm/i915/i915_request.c| 11 ++- 8 files changed, 83 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index 6ae6a3f58364..a1267739e369 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -104,7 +104,7 @@ void __intel_context_remove(struct intel_context *ce) spin_unlock(&ctx->hw_contexts_lock); } -static struct intel_context * +struct intel_context * intel_context_instance(struct i915_gem_context *ctx, struct intel_engine_cs *engine) { @@ -112,7 +112,7 @@ intel_context_instance(struct i915_gem_context *ctx, ce = intel_context_lookup(ctx, engine); if (likely(ce)) - return ce; + return intel_context_get(ce); ce = intel_context_alloc(); if (!ce) @@ -125,7 +125,7 @@ intel_context_instance(struct i915_gem_context *ctx, intel_context_free(ce); GEM_BUG_ON(intel_context_lookup(ctx, engine) != pos); - return pos; + return intel_context_get(pos); } struct intel_context * @@ -139,30 +139,30 @@ intel_context_pin_lock(struct i915_gem_context *ctx, if (IS_ERR(ce)) return ce; - if (mutex_lock_interruptible(&ce->pin_mutex)) + if (mutex_lock_interruptible(&ce->pin_mutex)) { + intel_context_put(ce); return ERR_PTR(-EINTR); + } return ce; } -struct intel_context * -intel_context_pin(struct i915_gem_context *ctx, - struct intel_engine_cs *engine) +void intel_context_pin_unlock(struct intel_context *ce) + __releases(ce->pin_mutex) { - struct intel_context *ce; - int err; - - ce = intel_context_instance(ctx, engine); - if (IS_ERR(ce)) - return ce; + mutex_unlock(&ce->pin_mutex); + intel_context_put(ce); +} - if (likely(atomic_inc_not_zero(&ce->pin_count))) - return ce; +int __intel_context_do_pin(struct intel_context *ce) +{ + int err; if (mutex_lock_interruptible(&ce->pin_mutex)) - return ERR_PTR(-EINTR); + return -EINTR; if (likely(!atomic_read(&ce->pin_count))) { + struct i915_gem_context *ctx = ce->gem_context; intel_wakeref_t wakeref; err = 0; @@ -172,7 +172,6 @@ intel_context_pin(struct i915_gem_context *ctx, goto err; i915_gem_context_get(ctx); - GEM_BUG_ON(ce->gem_context != ctx); mutex_lock(&ctx->mutex); list_add(&ce->active_link, &ctx->active_engines); @@ -186,11 +185,11 @@ intel_context_pin(struct i915_gem_context *ctx, GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */ mutex_unlock(&ce->pin_mutex); - return ce; + return 0; err: mutex_unlock(&ce->pin_mutex); - return ERR_PTR(err); + return err; } void intel_context_unpin(struct intel_context *ce) diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h index 9aeef88176b9..da342e9a8c2e 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.h +++ b/drivers/gpu/drm/i915/gt/intel_context.h @@ -49,11 +49,7 @@ intel_context_is_pinned(struct intel_context *ce) return atomic_read(&ce->pin_count); } -static inline void intel_context_pin_unlock(struct intel_context *ce) -__releases(ce->pin_mutex) -{ - mutex_unlock(&ce->pin_mutex); -} +void intel_context_pin_unlock(struct intel_context *ce); struct intel_context * __intel_context_insert(struct i915_gem_context *ctx, @@ -63,7 +59,18 @@ void __intel_context_remove(struct intel_context *ce); struct intel_context * -intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine); +intel_context_instance(struct i915_gem_context *ctx, + struct intel_engine_cs *engine); + +int __intel_context_do_pin(struct intel_context *ce); + +static inline int intel_context_pin(struct intel_context *ce) +{ + if (likely(atomic_inc_not_zero(&ce->pin_count))) + return 0; + + return __intel_context_do_pin(ce); +} static inline void __intel_context_pin(struct intel_context *ce) { diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/dri
Re: [Intel-gfx] [PATCH 16/29] drm/i915: Export intel_context_instance()
On 08/04/2019 10:17, Chris Wilson wrote: We want to pass in a intel_context into intel_context_pin() and that requires us to first be able to lookup the intel_context! Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/gt/intel_context.c| 37 +++--- drivers/gpu/drm/i915/gt/intel_context.h| 19 +++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 8 - drivers/gpu/drm/i915/gt/mock_engine.c | 8 - drivers/gpu/drm/i915/gvt/scheduler.c | 7 +++- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +-- drivers/gpu/drm/i915/i915_perf.c | 21 drivers/gpu/drm/i915/i915_request.c| 11 ++- 8 files changed, 83 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index 6ae6a3f58364..a1267739e369 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -104,7 +104,7 @@ void __intel_context_remove(struct intel_context *ce) spin_unlock(&ctx->hw_contexts_lock); } -static struct intel_context * +struct intel_context * intel_context_instance(struct i915_gem_context *ctx, struct intel_engine_cs *engine) { @@ -112,7 +112,7 @@ intel_context_instance(struct i915_gem_context *ctx, ce = intel_context_lookup(ctx, engine); if (likely(ce)) - return ce; + return intel_context_get(ce); ce = intel_context_alloc(); if (!ce) @@ -125,7 +125,7 @@ intel_context_instance(struct i915_gem_context *ctx, intel_context_free(ce); GEM_BUG_ON(intel_context_lookup(ctx, engine) != pos); - return pos; + return intel_context_get(pos); } struct intel_context * @@ -139,30 +139,30 @@ intel_context_pin_lock(struct i915_gem_context *ctx, if (IS_ERR(ce)) return ce; - if (mutex_lock_interruptible(&ce->pin_mutex)) + if (mutex_lock_interruptible(&ce->pin_mutex)) { + intel_context_put(ce); return ERR_PTR(-EINTR); + } return ce; } -struct intel_context * -intel_context_pin(struct i915_gem_context *ctx, - struct intel_engine_cs *engine) +void intel_context_pin_unlock(struct intel_context *ce) + __releases(ce->pin_mutex) { - struct intel_context *ce; - int err; - - ce = intel_context_instance(ctx, engine); - if (IS_ERR(ce)) - return ce; + mutex_unlock(&ce->pin_mutex); + intel_context_put(ce); +} - if (likely(atomic_inc_not_zero(&ce->pin_count))) - return ce; +int __intel_context_do_pin(struct intel_context *ce) +{ + int err; if (mutex_lock_interruptible(&ce->pin_mutex)) - return ERR_PTR(-EINTR); + return -EINTR; if (likely(!atomic_read(&ce->pin_count))) { + struct i915_gem_context *ctx = ce->gem_context; intel_wakeref_t wakeref; err = 0; @@ -172,7 +172,6 @@ intel_context_pin(struct i915_gem_context *ctx, goto err; i915_gem_context_get(ctx); - GEM_BUG_ON(ce->gem_context != ctx); mutex_lock(&ctx->mutex); list_add(&ce->active_link, &ctx->active_engines); @@ -186,11 +185,11 @@ intel_context_pin(struct i915_gem_context *ctx, GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */ mutex_unlock(&ce->pin_mutex); - return ce; + return 0; err: mutex_unlock(&ce->pin_mutex); - return ERR_PTR(err); + return err; } void intel_context_unpin(struct intel_context *ce) diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h index 9aeef88176b9..da342e9a8c2e 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.h +++ b/drivers/gpu/drm/i915/gt/intel_context.h @@ -49,11 +49,7 @@ intel_context_is_pinned(struct intel_context *ce) return atomic_read(&ce->pin_count); } -static inline void intel_context_pin_unlock(struct intel_context *ce) -__releases(ce->pin_mutex) -{ - mutex_unlock(&ce->pin_mutex); -} Could leave this as static inline since the only addition is kref_put so compiler could decide what to do? Don't mind either way. +void intel_context_pin_unlock(struct intel_context *ce); struct intel_context * __intel_context_insert(struct i915_gem_context *ctx, @@ -63,7 +59,18 @@ void __intel_context_remove(struct intel_context *ce); struct intel_context * -intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine); +intel_context_instance(struct i915_gem_context *ctx, + struct intel_engine_cs *engine); + +int __intel_context_do_pin(struct intel_context *ce); + +static inline int intel_context_pin(struct intel_context *ce) +{ + if (likely(atomic_inc_not_zero(&ce->pin_count))) + return 0; + + return __
Re: [Intel-gfx] [PATCH 16/29] drm/i915: Export intel_context_instance()
Quoting Tvrtko Ursulin (2019-04-10 13:06:04) > > On 08/04/2019 10:17, Chris Wilson wrote: > > We want to pass in a intel_context into intel_context_pin() and that > > requires us to first be able to lookup the intel_context! > > > > Signed-off-by: Chris Wilson > > --- > > drivers/gpu/drm/i915/gt/intel_context.c| 37 +++--- > > drivers/gpu/drm/i915/gt/intel_context.h| 19 +++ > > drivers/gpu/drm/i915/gt/intel_engine_cs.c | 8 - > > drivers/gpu/drm/i915/gt/mock_engine.c | 8 - > > drivers/gpu/drm/i915/gvt/scheduler.c | 7 +++- > > drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +-- > > drivers/gpu/drm/i915/i915_perf.c | 21 > > drivers/gpu/drm/i915/i915_request.c| 11 ++- > > 8 files changed, 83 insertions(+), 39 deletions(-) > > > > diff --git a/drivers/gpu/drm/i915/gt/intel_context.c > > b/drivers/gpu/drm/i915/gt/intel_context.c > > index 6ae6a3f58364..a1267739e369 100644 > > --- a/drivers/gpu/drm/i915/gt/intel_context.c > > +++ b/drivers/gpu/drm/i915/gt/intel_context.c > > @@ -104,7 +104,7 @@ void __intel_context_remove(struct intel_context *ce) > > spin_unlock(&ctx->hw_contexts_lock); > > } > > > > -static struct intel_context * > > +struct intel_context * > > intel_context_instance(struct i915_gem_context *ctx, > > struct intel_engine_cs *engine) > > { > > @@ -112,7 +112,7 @@ intel_context_instance(struct i915_gem_context *ctx, > > > > ce = intel_context_lookup(ctx, engine); > > if (likely(ce)) > > - return ce; > > + return intel_context_get(ce); > > > > ce = intel_context_alloc(); > > if (!ce) > > @@ -125,7 +125,7 @@ intel_context_instance(struct i915_gem_context *ctx, > > intel_context_free(ce); > > > > GEM_BUG_ON(intel_context_lookup(ctx, engine) != pos); > > - return pos; > > + return intel_context_get(pos); > > } > > > > struct intel_context * > > @@ -139,30 +139,30 @@ intel_context_pin_lock(struct i915_gem_context *ctx, > > if (IS_ERR(ce)) > > return ce; > > > > - if (mutex_lock_interruptible(&ce->pin_mutex)) > > + if (mutex_lock_interruptible(&ce->pin_mutex)) { > > + intel_context_put(ce); > > return ERR_PTR(-EINTR); > > + } > > > > return ce; > > } > > > > -struct intel_context * > > -intel_context_pin(struct i915_gem_context *ctx, > > - struct intel_engine_cs *engine) > > +void intel_context_pin_unlock(struct intel_context *ce) > > + __releases(ce->pin_mutex) > > { > > - struct intel_context *ce; > > - int err; > > - > > - ce = intel_context_instance(ctx, engine); > > - if (IS_ERR(ce)) > > - return ce; > > + mutex_unlock(&ce->pin_mutex); > > + intel_context_put(ce); > > +} > > > > - if (likely(atomic_inc_not_zero(&ce->pin_count))) > > - return ce; > > +int __intel_context_do_pin(struct intel_context *ce) > > +{ > > + int err; > > > > if (mutex_lock_interruptible(&ce->pin_mutex)) > > - return ERR_PTR(-EINTR); > > + return -EINTR; > > > > if (likely(!atomic_read(&ce->pin_count))) { > > + struct i915_gem_context *ctx = ce->gem_context; > > intel_wakeref_t wakeref; > > > > err = 0; > > @@ -172,7 +172,6 @@ intel_context_pin(struct i915_gem_context *ctx, > > goto err; > > > > i915_gem_context_get(ctx); > > - GEM_BUG_ON(ce->gem_context != ctx); > > > > mutex_lock(&ctx->mutex); > > list_add(&ce->active_link, &ctx->active_engines); > > @@ -186,11 +185,11 @@ intel_context_pin(struct i915_gem_context *ctx, > > GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */ > > > > mutex_unlock(&ce->pin_mutex); > > - return ce; > > + return 0; > > > > err: > > mutex_unlock(&ce->pin_mutex); > > - return ERR_PTR(err); > > + return err; > > } > > > > void intel_context_unpin(struct intel_context *ce) > > diff --git a/drivers/gpu/drm/i915/gt/intel_context.h > > b/drivers/gpu/drm/i915/gt/intel_context.h > > index 9aeef88176b9..da342e9a8c2e 100644 > > --- a/drivers/gpu/drm/i915/gt/intel_context.h > > +++ b/drivers/gpu/drm/i915/gt/intel_context.h > > @@ -49,11 +49,7 @@ intel_context_is_pinned(struct intel_context *ce) > > return atomic_read(&ce->pin_count); > > } > > > > -static inline void intel_context_pin_unlock(struct intel_context *ce) > > -__releases(ce->pin_mutex) > > -{ > > - mutex_unlock(&ce->pin_mutex); > > -} > > Could leave this as static inline since the only addition is kref_put so > compiler could decide what to do? Don't mind either way. In the next (or two) patch. > > +void intel_context_pin_unlock(struct intel_context *ce); > > > > struct intel_context * > > __intel_context_i
Re: [Intel-gfx] [PATCH 16/29] drm/i915: Export intel_context_instance()
On 10/04/2019 20:32, Chris Wilson wrote: Quoting Tvrtko Ursulin (2019-04-10 13:06:04) On 08/04/2019 10:17, Chris Wilson wrote: We want to pass in a intel_context into intel_context_pin() and that requires us to first be able to lookup the intel_context! Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/gt/intel_context.c| 37 +++--- drivers/gpu/drm/i915/gt/intel_context.h| 19 +++ drivers/gpu/drm/i915/gt/intel_engine_cs.c | 8 - drivers/gpu/drm/i915/gt/mock_engine.c | 8 - drivers/gpu/drm/i915/gvt/scheduler.c | 7 +++- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 11 +-- drivers/gpu/drm/i915/i915_perf.c | 21 drivers/gpu/drm/i915/i915_request.c| 11 ++- 8 files changed, 83 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index 6ae6a3f58364..a1267739e369 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -104,7 +104,7 @@ void __intel_context_remove(struct intel_context *ce) spin_unlock(&ctx->hw_contexts_lock); } -static struct intel_context * +struct intel_context * intel_context_instance(struct i915_gem_context *ctx, struct intel_engine_cs *engine) { @@ -112,7 +112,7 @@ intel_context_instance(struct i915_gem_context *ctx, ce = intel_context_lookup(ctx, engine); if (likely(ce)) - return ce; + return intel_context_get(ce); ce = intel_context_alloc(); if (!ce) @@ -125,7 +125,7 @@ intel_context_instance(struct i915_gem_context *ctx, intel_context_free(ce); GEM_BUG_ON(intel_context_lookup(ctx, engine) != pos); - return pos; + return intel_context_get(pos); } struct intel_context * @@ -139,30 +139,30 @@ intel_context_pin_lock(struct i915_gem_context *ctx, if (IS_ERR(ce)) return ce; - if (mutex_lock_interruptible(&ce->pin_mutex)) + if (mutex_lock_interruptible(&ce->pin_mutex)) { + intel_context_put(ce); return ERR_PTR(-EINTR); + } return ce; } -struct intel_context * -intel_context_pin(struct i915_gem_context *ctx, - struct intel_engine_cs *engine) +void intel_context_pin_unlock(struct intel_context *ce) + __releases(ce->pin_mutex) { - struct intel_context *ce; - int err; - - ce = intel_context_instance(ctx, engine); - if (IS_ERR(ce)) - return ce; + mutex_unlock(&ce->pin_mutex); + intel_context_put(ce); +} - if (likely(atomic_inc_not_zero(&ce->pin_count))) - return ce; +int __intel_context_do_pin(struct intel_context *ce) +{ + int err; if (mutex_lock_interruptible(&ce->pin_mutex)) - return ERR_PTR(-EINTR); + return -EINTR; if (likely(!atomic_read(&ce->pin_count))) { + struct i915_gem_context *ctx = ce->gem_context; intel_wakeref_t wakeref; err = 0; @@ -172,7 +172,6 @@ intel_context_pin(struct i915_gem_context *ctx, goto err; i915_gem_context_get(ctx); - GEM_BUG_ON(ce->gem_context != ctx); mutex_lock(&ctx->mutex); list_add(&ce->active_link, &ctx->active_engines); @@ -186,11 +185,11 @@ intel_context_pin(struct i915_gem_context *ctx, GEM_BUG_ON(!intel_context_is_pinned(ce)); /* no overflow! */ mutex_unlock(&ce->pin_mutex); - return ce; + return 0; err: mutex_unlock(&ce->pin_mutex); - return ERR_PTR(err); + return err; } void intel_context_unpin(struct intel_context *ce) diff --git a/drivers/gpu/drm/i915/gt/intel_context.h b/drivers/gpu/drm/i915/gt/intel_context.h index 9aeef88176b9..da342e9a8c2e 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.h +++ b/drivers/gpu/drm/i915/gt/intel_context.h @@ -49,11 +49,7 @@ intel_context_is_pinned(struct intel_context *ce) return atomic_read(&ce->pin_count); } -static inline void intel_context_pin_unlock(struct intel_context *ce) -__releases(ce->pin_mutex) -{ - mutex_unlock(&ce->pin_mutex); -} Could leave this as static inline since the only addition is kref_put so compiler could decide what to do? Don't mind either way. In the next (or two) patch. +void intel_context_pin_unlock(struct intel_context *ce); struct intel_context * __intel_context_insert(struct i915_gem_context *ctx, @@ -63,7 +59,18 @@ void __intel_context_remove(struct intel_context *ce); struct intel_context * -intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine); +intel_context_instance(struct i915_gem_context *ctx, +struct intel_engine_cs *engine); + +int __intel_context_do_pin(struct intel_context *ce); + +static