Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Widawsky <ben@bwidawsk.net>
To: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Intel GFX <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 08/12] drm/i915: Update context_fini
Date: Wed, 24 Apr 2013 22:17:22 -0700	[thread overview]
Message-ID: <20130425051721.GA12845@bwidawsk.net> (raw)
In-Reply-To: <20130425041102.GA792@bwidawsk.net>

On Wed, Apr 24, 2013 at 09:11:02PM -0700, Ben Widawsky wrote:
> On Wed, Apr 24, 2013 at 06:11:40PM +0300, Mika Kuoppala wrote:
> > Ben Widawsky <ben@bwidawsk.net> writes:
> > 
> > > Make resets optional for fini. fini is only ever called in
> > > module_unload. It was therefore a good assumption that the GPU reset
> > > (see the comment in the function) was what we wanted. With an upcoming
> > > patch, we're going to add a few more callsites, one of which is GPU
> > > reset, where doing the extra reset isn't usual.
> > >
> > > On that same note, with more callers it makes sense to make the default
> > > context state consistent with the actual state (via NULLing the
> > > pointer).
> > >
> > > Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
> > > ---
> > >  drivers/gpu/drm/i915/i915_dma.c         | 2 +-
> > >  drivers/gpu/drm/i915/i915_drv.h         | 2 +-
> > >  drivers/gpu/drm/i915/i915_gem_context.c | 7 +++++--
> > >  3 files changed, 7 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
> > > index 3b315ba..a141b8a 100644
> > > --- a/drivers/gpu/drm/i915/i915_dma.c
> > > +++ b/drivers/gpu/drm/i915/i915_dma.c
> > > @@ -1764,7 +1764,7 @@ int i915_driver_unload(struct drm_device *dev)
> > >  		mutex_lock(&dev->struct_mutex);
> > >  		i915_gem_free_all_phys_object(dev);
> > >  		i915_gem_cleanup_ringbuffer(dev);
> > > -		i915_gem_context_fini(dev);
> > > +		i915_gem_context_fini(dev, true);
> > >  		mutex_unlock(&dev->struct_mutex);
> > >  		i915_gem_cleanup_aliasing_ppgtt(dev);
> > >  		i915_gem_cleanup_stolen(dev);
> > > diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> > > index 9717c69..618845e 100644
> > > --- a/drivers/gpu/drm/i915/i915_drv.h
> > > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > > @@ -1698,7 +1698,7 @@ struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
> > >  
> > >  /* i915_gem_context.c */
> > >  void i915_gem_context_init(struct drm_device *dev);
> > > -void i915_gem_context_fini(struct drm_device *dev);
> > > +void i915_gem_context_fini(struct drm_device *dev, bool reset);
> > >  void i915_gem_context_close(struct drm_device *dev, struct drm_file *file);
> > >  int i915_switch_context(struct intel_ring_buffer *ring,
> > >  			struct drm_file *file, int to_id);
> > > diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> > > index 411ace0..6030d83 100644
> > > --- a/drivers/gpu/drm/i915/i915_gem_context.c
> > > +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> > > @@ -259,7 +259,7 @@ void i915_gem_context_init(struct drm_device *dev)
> > >  	DRM_DEBUG_DRIVER("HW context support initialized\n");
> > >  }
> > >  
> > > -void i915_gem_context_fini(struct drm_device *dev)
> > > +void i915_gem_context_fini(struct drm_device *dev, bool reset)
> > >  {
> > >  	struct drm_i915_private *dev_priv = dev->dev_private;
> > >  
> > > @@ -269,11 +269,14 @@ void i915_gem_context_fini(struct drm_device *dev)
> > >  	/* The only known way to stop the gpu from accessing the hw context is
> > >  	 * to reset it. Do this as the very last operation to avoid confusing
> > >  	 * other code, leading to spurious errors. */
> > 
> > Should we switch to default context in here to be sure that 
> > the running context will get unreferenced correctly?...
> 
> I'm confused if you're talking about the object refcount, or the context
> refcount. The latter isn't yet introduced in this part of the series.
> But maybe I've missed your point, so let's discuss...
> 
> There are 3 ways we can end up at fini():
> 1. failed during some part of driver initialization
> 2. unload
>   Conceptually, 1 and 2 are the same, the GPU is idle, (explicitly so in
>   the latter case) and so therefore we know the default context must be
>   the last context context[1]. We know the retire worker has either been
>   called, or we've not yet submitted work, and we should therefore be
>   able to assert the object refcount is exactly 1.
> 
>   Given our discussion and the new reset parameter in fini, I can assert
>   last_context_obj == default_context->obj in the !reset case, and that
>   the refcount is 1.

I should add to this statement:
Getting the object reference count isn't possible, and it'd involve
changing drm_gem_object_unreference to return the value of kref_put()
which I'd prefer not to d.

Also the other assertion requires some extra artificial code to actually
assert last_context_obj == default_context->obj because the init case
will only work after enable().

> 
> 3. reset
>   In this case, it's a good question. Normally reset is called on a
>   hang, and we can't expect to be able to switch. I think
>   reset_ring_lists does everything I need, and then it follows into case
>   1 and 2. If I have missed something though, could you please explain
>   it a bit further fo rme?
> 
> > 
> > > -	intel_gpu_reset(dev); +	if (reset) +
> > > intel_gpu_reset(dev);
> > >  
> > >  	i915_gem_object_unpin(dev_priv->ring[RCS].default_context->obj);
> > >
> > 
> > ...and unreference the default context here so that it will get freed
> > on module unload.
> 
> Can you explain what I'm missing. Doesn't do_destroy just below take
> care of it?
> >
> 
>  
> > --Mika
> 
> For the context reference counting case, I think the questions are still
> applicable, and the answers are similar. You deref in reset_ring_lists,
> init fail and unload are the same... If you want me to use the
> context_unref interface, I can, but I would want to make unref return
> the val of kref_put() and do while(!context_unref(...)) just to be safe.
> 
> 
> You can take a look here to see how that's progressing:
> http://cgit.freedesktop.org/~bwidawsk/drm-intel/log/?h=ppgtt-ctx
> 
> It's quite volatile though, so be warned.
> 
> 
> > 
> > >  	do_destroy(dev_priv->ring[RCS].default_context);
> > > +
> > > +	dev_priv->ring[RCS].default_context = NULL;
> > >  }
> > >  
> > >  static int context_idr_cleanup(int id, void *p, void *data)
> > > -- 
> > > 1.8.2.1
> > >
> > > _______________________________________________
> > > Intel-gfx mailing list
> > > Intel-gfx@lists.freedesktop.org
> > > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> -- 
> Ben Widawsky, Intel Open Source Technology Center

-- 
Ben Widawsky, Intel Open Source Technology Center

  reply	other threads:[~2013-04-25  5:14 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-24  6:15 [PATCH 00/12] [RFC] PPGTT prep patches part 1 Ben Widawsky
2013-04-24  6:15 ` [PATCH 01/12] drm/i915: Assert mutex_is_locked on context lookup Ben Widawsky
2013-05-02 20:27   ` Jesse Barnes
2013-05-06  9:40     ` Daniel Vetter
2013-05-06  9:44       ` Daniel Vetter
2013-05-06 17:59         ` Ben Widawsky
2013-05-06 18:35           ` Daniel Vetter
2013-04-24  6:15 ` [PATCH 02/12] drm/i915: BUG_ON bad PPGTT offset Ben Widawsky
2013-05-02 20:28   ` Jesse Barnes
2013-05-06  9:48     ` Daniel Vetter
2013-05-06 18:03       ` Ben Widawsky
2013-05-06 18:37         ` Daniel Vetter
2013-05-08 16:48           ` Ben Widawsky
2013-05-08 17:55             ` Daniel Vetter
2013-04-24  6:15 ` [PATCH 03/12] drm/i915: make PDE|PTE platform specific Ben Widawsky
2013-05-02 21:26   ` Jesse Barnes
2013-05-02 22:49     ` Ben Widawsky
2013-05-02 22:55       ` Jesse Barnes
2013-05-06  9:47     ` Daniel Vetter
2013-05-08 16:49       ` Ben Widawsky
2013-05-08 17:52         ` Daniel Vetter
2013-04-24  6:15 ` [PATCH 04/12] drm/i915: Extract PDE writes Ben Widawsky
2013-05-02 21:27   ` Jesse Barnes
2013-05-06  9:50     ` Daniel Vetter
2013-04-24  6:15 ` [PATCH 05/12] drm: Optionally create mm blocks from top-to-bottom Ben Widawsky
2013-04-24  6:15 ` [PATCH 06/12] drm/i915: Use drm_mm for PPGTT PDEs Ben Widawsky
2013-05-02 21:42   ` Jesse Barnes
2013-04-24  6:15 ` [PATCH 07/12] drm/i915: Use PDEs as the guard page Ben Widawsky
2013-04-24  6:15 ` [PATCH 08/12] drm/i915: Update context_fini Ben Widawsky
2013-04-24 15:11   ` Mika Kuoppala
2013-04-25  4:11     ` Ben Widawsky
2013-04-25  5:17       ` Ben Widawsky [this message]
2013-04-25 15:01       ` Mika Kuoppala
2013-04-25 17:22         ` Ben Widawsky
2013-04-24  6:15 ` [PATCH 09/12] drm/i915: Split context enabling from init Ben Widawsky
2013-04-24 10:04   ` Chris Wilson
2013-04-24 16:39     ` Ben Widawsky
2013-04-24  6:15 ` [PATCH 10/12] drm/i915: destroy i915_gem_init_global_gtt Ben Widawsky
2013-04-24  6:15 ` [PATCH 11/12] drm/i915: Embed PPGTT into the context Ben Widawsky
2013-04-24  6:15 ` [PATCH 12/12] drm/i915: No contexts without ppgtt Ben Widawsky
2013-04-24 10:06   ` Chris Wilson
2013-04-24 16:39     ` Ben Widawsky
2013-04-24  9:53 ` [PATCH 00/12] [RFC] PPGTT prep patches part 1 Chris Wilson
2013-04-24 19:58 ` Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130425051721.GA12845@bwidawsk.net \
    --to=ben@bwidawsk.net \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox