diff mbox

[04/19] drm/i915: Pull the context->pin_count dec into the common intel_context_unpin

Message ID 20180517074055.14638-4-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson May 17, 2018, 7:40 a.m. UTC
As all backends implement the same pin_count mechanism and do a
dec-and-test as their first step, pull that into the common
intel_context_unpin(). This also pulls into the caller, eliminating the
indirect call in the usual steady state case. The intel_context_pin()
side is a little more complicated as it combines the lookup/alloc as
well as pinning the state, and so is left for a later date.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_context.h      |  4 ++++
 drivers/gpu/drm/i915/intel_lrc.c             | 13 +------------
 drivers/gpu/drm/i915/intel_ringbuffer.c      |  6 ------
 drivers/gpu/drm/i915/selftests/mock_engine.c |  3 ---
 4 files changed, 5 insertions(+), 21 deletions(-)

Comments

Tvrtko Ursulin May 17, 2018, 10:20 a.m. UTC | #1
On 17/05/2018 08:40, Chris Wilson wrote:
> As all backends implement the same pin_count mechanism and do a
> dec-and-test as their first step, pull that into the common
> intel_context_unpin(). This also pulls into the caller, eliminating the
> indirect call in the usual steady state case. The intel_context_pin()
> side is a little more complicated as it combines the lookup/alloc as
> well as pinning the state, and so is left for a later date.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>   drivers/gpu/drm/i915/i915_gem_context.h      |  4 ++++
>   drivers/gpu/drm/i915/intel_lrc.c             | 13 +------------
>   drivers/gpu/drm/i915/intel_ringbuffer.c      |  6 ------
>   drivers/gpu/drm/i915/selftests/mock_engine.c |  3 ---
>   4 files changed, 5 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
> index 749a4ff566f5..c3262b4dd2ee 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.h
> +++ b/drivers/gpu/drm/i915/i915_gem_context.h
> @@ -285,6 +285,10 @@ static inline void __intel_context_pin(struct intel_context *ce)
>   
>   static inline void intel_context_unpin(struct intel_context *ce)
>   {
> +	GEM_BUG_ON(!ce->pin_count);
> +	if (--ce->pin_count)
> +		return;
> +
>   	GEM_BUG_ON(!ce->ops);
>   	ce->ops->unpin(ce);
>   }
> diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
> index 960948617748..f3470b95d64e 100644
> --- a/drivers/gpu/drm/i915/intel_lrc.c
> +++ b/drivers/gpu/drm/i915/intel_lrc.c
> @@ -1344,7 +1344,7 @@ static void execlists_context_destroy(struct intel_context *ce)
>   	__i915_gem_object_release_unless_active(ce->state->obj);
>   }
>   
> -static void __execlists_context_unpin(struct intel_context *ce)
> +static void execlists_context_unpin(struct intel_context *ce)
>   {
>   	intel_ring_unpin(ce->ring);
>   
> @@ -1355,17 +1355,6 @@ static void __execlists_context_unpin(struct intel_context *ce)
>   	i915_gem_context_put(ce->gem_context);
>   }
>   
> -static void execlists_context_unpin(struct intel_context *ce)
> -{
> -	lockdep_assert_held(&ce->gem_context->i915->drm.struct_mutex);

Do you want to preserve these asserts?

> -	GEM_BUG_ON(ce->pin_count == 0);
> -
> -	if (--ce->pin_count)
> -		return;
> -
> -	__execlists_context_unpin(ce);
> -}
> -
>   static int __context_pin(struct i915_gem_context *ctx, struct i915_vma *vma)
>   {
>   	unsigned int flags;
> diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
> index 0c0c9f531e4e..001cf6bcb349 100644
> --- a/drivers/gpu/drm/i915/intel_ringbuffer.c
> +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
> @@ -1195,12 +1195,6 @@ static void intel_ring_context_destroy(struct intel_context *ce)
>   
>   static void intel_ring_context_unpin(struct intel_context *ce)
>   {
> -	lockdep_assert_held(&ce->gem_context->i915->drm.struct_mutex);
> -	GEM_BUG_ON(ce->pin_count == 0);
> -
> -	if (--ce->pin_count)
> -		return;
> -
>   	if (ce->state) {
>   		ce->state->obj->pin_global--;
>   		i915_vma_unpin(ce->state);
> diff --git a/drivers/gpu/drm/i915/selftests/mock_engine.c b/drivers/gpu/drm/i915/selftests/mock_engine.c
> index 33eddfc1f8ce..f1ac7453053e 100644
> --- a/drivers/gpu/drm/i915/selftests/mock_engine.c
> +++ b/drivers/gpu/drm/i915/selftests/mock_engine.c
> @@ -74,9 +74,6 @@ static void hw_delay_complete(struct timer_list *t)
>   
>   static void mock_context_unpin(struct intel_context *ce)
>   {
> -	if (--ce->pin_count)
> -		return;
> -
>   	i915_gem_context_put(ce->gem_context);
>   }
>   
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
Chris Wilson May 17, 2018, 10:35 a.m. UTC | #2
Quoting Tvrtko Ursulin (2018-05-17 11:20:22)
> 
> On 17/05/2018 08:40, Chris Wilson wrote:
> > As all backends implement the same pin_count mechanism and do a
> > dec-and-test as their first step, pull that into the common
> > intel_context_unpin(). This also pulls into the caller, eliminating the
> > indirect call in the usual steady state case. The intel_context_pin()
> > side is a little more complicated as it combines the lookup/alloc as
> > well as pinning the state, and so is left for a later date.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > ---
> >   drivers/gpu/drm/i915/i915_gem_context.h      |  4 ++++
> >   drivers/gpu/drm/i915/intel_lrc.c             | 13 +------------
> >   drivers/gpu/drm/i915/intel_ringbuffer.c      |  6 ------
> >   drivers/gpu/drm/i915/selftests/mock_engine.c |  3 ---
> >   4 files changed, 5 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
> > index 749a4ff566f5..c3262b4dd2ee 100644
> > --- a/drivers/gpu/drm/i915/i915_gem_context.h
> > +++ b/drivers/gpu/drm/i915/i915_gem_context.h
> > @@ -285,6 +285,10 @@ static inline void __intel_context_pin(struct intel_context *ce)
> >   
> >   static inline void intel_context_unpin(struct intel_context *ce)
> >   {
> > +     GEM_BUG_ON(!ce->pin_count);
> > +     if (--ce->pin_count)
> > +             return;
> > +
> >       GEM_BUG_ON(!ce->ops);
> >       ce->ops->unpin(ce);
> >   }
> > diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
> > index 960948617748..f3470b95d64e 100644
> > --- a/drivers/gpu/drm/i915/intel_lrc.c
> > +++ b/drivers/gpu/drm/i915/intel_lrc.c
> > @@ -1344,7 +1344,7 @@ static void execlists_context_destroy(struct intel_context *ce)
> >       __i915_gem_object_release_unless_active(ce->state->obj);
> >   }
> >   
> > -static void __execlists_context_unpin(struct intel_context *ce)
> > +static void execlists_context_unpin(struct intel_context *ce)
> >   {
> >       intel_ring_unpin(ce->ring);
> >   
> > @@ -1355,17 +1355,6 @@ static void __execlists_context_unpin(struct intel_context *ce)
> >       i915_gem_context_put(ce->gem_context);
> >   }
> >   
> > -static void execlists_context_unpin(struct intel_context *ce)
> > -{
> > -     lockdep_assert_held(&ce->gem_context->i915->drm.struct_mutex);
> 
> Do you want to preserve these asserts?

They were to document ce->pin_count as guarded by the mutex. And our
headers wouldn't accept putting it into the inline.

So ~o~. It lost its immediate relevance, and the unpin branch calls
should each be guarded by the lockdep assert where required. The one
that's missing would be obj->pin_global--. :|

(As for struct_mutex removal I think targeting the unpin branches is
going to be my first step...)
-Chris
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h
index 749a4ff566f5..c3262b4dd2ee 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.h
+++ b/drivers/gpu/drm/i915/i915_gem_context.h
@@ -285,6 +285,10 @@  static inline void __intel_context_pin(struct intel_context *ce)
 
 static inline void intel_context_unpin(struct intel_context *ce)
 {
+	GEM_BUG_ON(!ce->pin_count);
+	if (--ce->pin_count)
+		return;
+
 	GEM_BUG_ON(!ce->ops);
 	ce->ops->unpin(ce);
 }
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 960948617748..f3470b95d64e 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -1344,7 +1344,7 @@  static void execlists_context_destroy(struct intel_context *ce)
 	__i915_gem_object_release_unless_active(ce->state->obj);
 }
 
-static void __execlists_context_unpin(struct intel_context *ce)
+static void execlists_context_unpin(struct intel_context *ce)
 {
 	intel_ring_unpin(ce->ring);
 
@@ -1355,17 +1355,6 @@  static void __execlists_context_unpin(struct intel_context *ce)
 	i915_gem_context_put(ce->gem_context);
 }
 
-static void execlists_context_unpin(struct intel_context *ce)
-{
-	lockdep_assert_held(&ce->gem_context->i915->drm.struct_mutex);
-	GEM_BUG_ON(ce->pin_count == 0);
-
-	if (--ce->pin_count)
-		return;
-
-	__execlists_context_unpin(ce);
-}
-
 static int __context_pin(struct i915_gem_context *ctx, struct i915_vma *vma)
 {
 	unsigned int flags;
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 0c0c9f531e4e..001cf6bcb349 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -1195,12 +1195,6 @@  static void intel_ring_context_destroy(struct intel_context *ce)
 
 static void intel_ring_context_unpin(struct intel_context *ce)
 {
-	lockdep_assert_held(&ce->gem_context->i915->drm.struct_mutex);
-	GEM_BUG_ON(ce->pin_count == 0);
-
-	if (--ce->pin_count)
-		return;
-
 	if (ce->state) {
 		ce->state->obj->pin_global--;
 		i915_vma_unpin(ce->state);
diff --git a/drivers/gpu/drm/i915/selftests/mock_engine.c b/drivers/gpu/drm/i915/selftests/mock_engine.c
index 33eddfc1f8ce..f1ac7453053e 100644
--- a/drivers/gpu/drm/i915/selftests/mock_engine.c
+++ b/drivers/gpu/drm/i915/selftests/mock_engine.c
@@ -74,9 +74,6 @@  static void hw_delay_complete(struct timer_list *t)
 
 static void mock_context_unpin(struct intel_context *ce)
 {
-	if (--ce->pin_count)
-		return;
-
 	i915_gem_context_put(ce->gem_context);
 }