All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: David Herrmann <dh.herrmann@gmail.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 04/12] drm: extract legacy ctxbitmap flushing
Date: Wed, 23 Jul 2014 21:26:59 +0200	[thread overview]
Message-ID: <20140723192659.GA15237@phenom.ffwll.local> (raw)
In-Reply-To: <1406129207-1302-5-git-send-email-dh.herrmann@gmail.com>

On Wed, Jul 23, 2014 at 05:26:39PM +0200, David Herrmann wrote:
> The ctxbitmap code is only used by legacy drivers so lets try to keep it
> as separated as possible. Furthermore, the locking is non-obvious and
> kinda weird with ctxlist_mutex *and* struct_mutex. Keeping all ctxbitmap
> access in one file is much easier to review and makes drm_release() more
> readable.
> 
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

I've started to sprinkle _legacy_ over all the functions only used for
non-kms drivers, so that the dragon dungeons are clearly marked off. With
that this is Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>.
-Daniel

> ---
>  drivers/gpu/drm/drm_context.c | 30 ++++++++++++++++++++++++++++++
>  drivers/gpu/drm/drm_fops.c    | 20 +-------------------
>  include/drm/drmP.h            |  1 +
>  3 files changed, 32 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
> index a4b017b..c045505 100644
> --- a/drivers/gpu/drm/drm_context.c
> +++ b/drivers/gpu/drm/drm_context.c
> @@ -111,6 +111,36 @@ void drm_ctxbitmap_cleanup(struct drm_device * dev)
>  	mutex_unlock(&dev->struct_mutex);
>  }
>  
> +/**
> + * drm_ctxbitmap_flush() - Flush all contexts owned by a file
> + * @dev: DRM device to operate on
> + * @file: Open file to flush contexts for
> + *
> + * This iterates over all contexts on @dev and drops them if they're owned by
> + * @file. Note that after this call returns, new contexts might be added if
> + * the file is still alive.
> + */
> +void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file)
> +{
> +	struct drm_ctx_list *pos, *tmp;
> +
> +	mutex_lock(&dev->ctxlist_mutex);
> +
> +	list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) {
> +		if (pos->tag == file &&
> +		    pos->handle != DRM_KERNEL_CONTEXT) {
> +			if (dev->driver->context_dtor)
> +				dev->driver->context_dtor(dev, pos->handle);
> +
> +			drm_ctxbitmap_free(dev, pos->handle);
> +			list_del(&pos->head);
> +			kfree(pos);
> +		}
> +	}
> +
> +	mutex_unlock(&dev->ctxlist_mutex);
> +}
> +
>  /*@}*/
>  
>  /******************************************************************/
> diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
> index 8e73519..fb81d1c 100644
> --- a/drivers/gpu/drm/drm_fops.c
> +++ b/drivers/gpu/drm/drm_fops.c
> @@ -452,25 +452,7 @@ int drm_release(struct inode *inode, struct file *filp)
>  	if (dev->driver->driver_features & DRIVER_GEM)
>  		drm_gem_release(dev, file_priv);
>  
> -	mutex_lock(&dev->ctxlist_mutex);
> -	if (!list_empty(&dev->ctxlist)) {
> -		struct drm_ctx_list *pos, *n;
> -
> -		list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
> -			if (pos->tag == file_priv &&
> -			    pos->handle != DRM_KERNEL_CONTEXT) {
> -				if (dev->driver->context_dtor)
> -					dev->driver->context_dtor(dev,
> -								  pos->handle);
> -
> -				drm_ctxbitmap_free(dev, pos->handle);
> -
> -				list_del(&pos->head);
> -				kfree(pos);
> -			}
> -		}
> -	}
> -	mutex_unlock(&dev->ctxlist_mutex);
> +	drm_ctxbitmap_flush(dev, file_priv);
>  
>  	mutex_lock(&dev->master_mutex);
>  
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index d1730c5..d91e09f 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -1242,6 +1242,7 @@ extern int drm_rmctx(struct drm_device *dev, void *data,
>  extern int drm_ctxbitmap_init(struct drm_device *dev);
>  extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
>  extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
> +extern void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file);
>  
>  extern int drm_setsareactx(struct drm_device *dev, void *data,
>  			   struct drm_file *file_priv);
> -- 
> 2.0.2
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

  reply	other threads:[~2014-07-23 19:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 15:26 [PATCH 00/12] DRM: Random Cleanups David Herrmann
2014-07-23 15:26 ` [PATCH 01/12] drm: remove unused "struct drm_freelist" David Herrmann
2014-07-23 19:17   ` Daniel Vetter
2014-07-23 15:26 ` [PATCH 02/12] drm: drop unused "struct drm_queue" David Herrmann
2014-07-23 19:35   ` Daniel Vetter
2014-07-24 11:35     ` David Herrmann
2014-07-23 15:26 ` [PATCH 03/12] drm: call ->firstopen() before ->open() David Herrmann
2014-07-23 19:25   ` Daniel Vetter
2014-07-24  9:31     ` David Herrmann
2014-07-24 10:18       ` Daniel Vetter
2014-07-24 13:47       ` Alex Deucher
2014-07-23 15:26 ` [PATCH 04/12] drm: extract legacy ctxbitmap flushing David Herrmann
2014-07-23 19:26   ` Daniel Vetter [this message]
2014-07-24  9:34     ` David Herrmann
2014-07-24 10:19       ` Daniel Vetter
2014-07-23 15:26 ` [PATCH 05/12] drm: drop i386 verification David Herrmann
2014-07-23 15:26 ` [PATCH 06/12] drm: fix __alpha__ PCI lookup David Herrmann
2014-07-23 19:29   ` Daniel Vetter
2014-07-23 19:36     ` Daniel Vetter
2014-07-23 15:26 ` [PATCH 07/12] drm: drop redundant drm_file->is_master David Herrmann
2014-07-24  9:52   ` Daniel Vetter
2014-07-24 21:38     ` David Herrmann
2014-07-25  7:56       ` Daniel Vetter
2014-07-28 15:26         ` David Herrmann
2014-07-23 15:26 ` [PATCH 08/12] drm: don't de-authenticate clients on master-close David Herrmann
2014-07-24  9:57   ` Daniel Vetter
2014-07-23 15:26 ` [PATCH 09/12] drm: move module initialization to drm_stub.c David Herrmann
2014-07-23 15:26 ` [PATCH 10/12] drm: merge drm_drv.c into drm_ioctl.c David Herrmann
2014-07-23 16:16   ` David Herrmann
2014-07-23 19:33   ` Daniel Vetter
2014-07-23 15:26 ` [PATCH 11/12] drm: make minor->index available early David Herrmann
2014-07-24 10:03   ` Daniel Vetter
2014-07-24 10:16     ` David Herrmann
2014-07-24 12:30       ` Daniel Vetter
2014-07-23 15:26 ` [PATCH 12/12] drm: make sysfs device always available for minors David Herrmann
2014-07-24 10:36   ` Daniel Vetter
2014-07-24 10:48     ` David Herrmann
2014-07-24 12:31       ` Daniel Vetter
2014-07-23 16:24 ` [PATCH 00/12] DRM: Random Cleanups Alex Deucher

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=20140723192659.GA15237@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dh.herrmann@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.