mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liviu Dudau <Liviu.Dudau@arm.com>
To: Laura Abbott <labbott@redhat.com>
Cc: "Sumit Semwal" <sumit.semwal@linaro.org>,
	"John Stultz" <john.stultz@linaro.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Riley Andrews" <riandrews@android.com>,
	"Laura Abbott" <labbott@fedoraproject.org>,
	"Daniel Vetter" <daniel.vetter@ffwll.ch>,
	linaro-mm-sig@lists.linaro.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org,
	"Eun Taik Lee" <eun.taik.lee@samsung.com>,
	"Jon Medhurst" <tixy@linaro.org>,
	"Mitchel Humpherys" <mitchelh@codeaurora.org>,
	"Jeremy Gebben" <jgebben@codeaurora.org>,
	"Bryan Huntsman" <bryanh@codeaurora.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Android Kernel Team" <kernel-team@android.com>
Subject: Re: [RFC][PATCH 2/6] staging: android: ion: Switch to using an idr to manage heaps
Date: Wed, 8 Jun 2016 14:13:56 +0100	[thread overview]
Message-ID: <20160608131356.GL1165@e106497-lin.cambridge.arm.com> (raw)
In-Reply-To: <1465237413-10549-3-git-send-email-labbott@redhat.com>

On Mon, Jun 06, 2016 at 11:23:29AM -0700, Laura Abbott wrote:
> From: Laura Abbott <labbott@fedoraproject.org>
> 
> 
> In anticipation of dynamic registration of heaps, switch to using
> an idr for heaps. The idr makes it easier to control the assignment
> and management + lookup of heap numbers.
> 
> Signed-off-by: Laura Abbott <labbott@redhat.com>
> ---
>  drivers/staging/android/ion/ion.c | 83 +++++++++++++++++++++++++--------------
>  1 file changed, 53 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
> index 306340a..739060f 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -55,13 +55,14 @@ struct ion_device {
>  	struct rb_root buffers;
>  	struct mutex buffer_lock;
>  	struct rw_semaphore lock;
> -	struct plist_head heaps;
>  	long (*custom_ioctl)(struct ion_client *client, unsigned int cmd,
>  			     unsigned long arg);
>  	struct rb_root clients;
>  	struct dentry *debug_root;
>  	struct dentry *heaps_debug_root;
>  	struct dentry *clients_debug_root;
> +	struct idr idr;
> +	int heap_cnt;
>  };
>  
>  /**
> @@ -488,39 +489,22 @@ static int ion_handle_add(struct ion_client *client, struct ion_handle *handle)
>  	return 0;
>  }
>  
> -struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
> -			     size_t align, unsigned int heap_id_mask,
> +static struct ion_handle *__ion_alloc(struct ion_client *client, size_t len,
> +			     size_t align, struct ion_heap *heap,
>  			     unsigned int flags)
>  {
>  	struct ion_handle *handle;
>  	struct ion_device *dev = client->dev;
>  	struct ion_buffer *buffer = NULL;
> -	struct ion_heap *heap;
>  	int ret;
>  
> -	pr_debug("%s: len %zu align %zu heap_id_mask %u flags %x\n", __func__,
> -		 len, align, heap_id_mask, flags);
> -	/*
> -	 * traverse the list of heaps available in this system in priority
> -	 * order.  If the heap type is supported by the client, and matches the
> -	 * request of the caller allocate from it.  Repeat until allocate has
> -	 * succeeded or all heaps have been tried
> -	 */
> +

Drop the (second) empty line here.

>  	len = PAGE_ALIGN(len);
>  
>  	if (!len)
>  		return ERR_PTR(-EINVAL);
>  
> -	down_read(&dev->lock);
> -	plist_for_each_entry(heap, &dev->heaps, node) {
> -		/* if the caller didn't specify this heap id */
> -		if (!((1 << heap->id) & heap_id_mask))
> -			continue;
> -		buffer = ion_buffer_create(heap, dev, len, align, flags);
> -		if (!IS_ERR(buffer))
> -			break;
> -	}
> -	up_read(&dev->lock);
> +	buffer = ion_buffer_create(heap, dev, len, align, flags);
>  
>  	if (buffer == NULL)
>  		return ERR_PTR(-ENODEV);
> @@ -549,6 +533,41 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
>  
>  	return handle;
>  }
> +
> +struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
> +				size_t align, unsigned int heap_mask,
> +				unsigned int flags)
> +{
> +	int bit;
> +	struct ion_handle *handle = ERR_PTR(-ENODEV);
> +
> +	pr_debug("%s: len %zu align %zu heap_id_mask %u flags %x\n", __func__,
> +		 len, align, heap_mask, flags);
> +
> +	down_read(&client->dev->lock);
> +	/*
> +	 * traverse the list of heaps available in this system in priority
> +	 * order.  If the heap type is supported by the client, and matches the
> +	 * request of the caller allocate from it.  Repeat until allocate has
> +	 * succeeded or all heaps have been tried
> +	 */
> +	for_each_set_bit(bit, (unsigned long *)&heap_mask, 32) {
> +		struct ion_heap *heap;
> +
> +		heap = idr_find(&client->dev->idr, bit);
> +		if (!heap)
> +			continue;
> +
> +		handle = __ion_alloc(client, len, align, heap, flags);
> +		if (IS_ERR(handle))
> +			continue;
> +		else
> +			break;
> +	}
> +
> +	up_read(&client->dev->lock);
> +	return handle;
> +}
>  EXPORT_SYMBOL(ion_alloc);
>  
>  static void ion_free_nolock(struct ion_client *client, struct ion_handle *handle)
> @@ -1587,6 +1606,7 @@ DEFINE_SIMPLE_ATTRIBUTE(debug_shrink_fops, debug_shrink_get,
>  int ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
>  {
>  	struct dentry *debug_file;
> +	int ret;
>  
>  	if (!heap->ops->allocate || !heap->ops->free || !heap->ops->map_dma ||
>  	    !heap->ops->unmap_dma) {
> @@ -1606,12 +1626,15 @@ int ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
>  
>  	heap->dev = dev;
>  	down_write(&dev->lock);
> -	/*
> -	 * use negative heap->id to reverse the priority -- when traversing
> -	 * the list later attempt higher id numbers first
> -	 */
> -	plist_node_init(&heap->node, -heap->id);
> -	plist_add(&heap->node, &dev->heaps);
> +
> +	ret = idr_alloc(&dev->idr, heap, heap->id, heap->id + 1, GFP_KERNEL);
> +	if (ret < 0 || ret != heap->id) {
> +		pr_info("%s: Failed to add heap id, expected %d got %d\n",
> +			__func__, heap->id, ret);
> +		up_write(&dev->lock);
> +		return ret < 0 ? ret : -EINVAL;
> +	}
> +
>  	debug_file = debugfs_create_file(heap->name, 0664,
>  					dev->heaps_debug_root, heap,
>  					&debug_heap_fops);
> @@ -1639,7 +1662,7 @@ int ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
>  				path, debug_name);
>  		}
>  	}
> -
> +	dev->heap_cnt++;
>  	up_write(&dev->lock);
>  	return 0;
>  }
> @@ -1689,7 +1712,7 @@ debugfs_done:
>  	idev->buffers = RB_ROOT;
>  	mutex_init(&idev->buffer_lock);
>  	init_rwsem(&idev->lock);
> -	plist_head_init(&idev->heaps);
> +	idr_init(&idev->idr);
>  	idev->clients = RB_ROOT;
>  	ion_root_client = &idev->clients;
>  	mutex_init(&debugfs_mutex);
> -- 
> 2.5.5
> 

Reviewed-by: Liviu Dudau <Liviu.Dudau@arm.com>

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

  reply	other threads:[~2016-06-08 13:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 18:23 [RFC][PATCH 0/6] ion: improved ABI Laura Abbott
2016-06-06 18:23 ` [RFC][PATCH 1/6] staging: android: ion: return error value for ion_device_add_heap Laura Abbott
2016-06-08 13:02   ` Liviu Dudau
2016-06-06 18:23 ` [RFC][PATCH 2/6] staging: android: ion: Switch to using an idr to manage heaps Laura Abbott
2016-06-08 13:13   ` Liviu Dudau [this message]
2016-06-06 18:23 ` [RFC][PATCH 3/6] staging: android: ion: Drop heap type masks Laura Abbott
2016-06-06 18:23 ` [RFC][PATCH 4/6] staging: android: ion: Pull out ion ioctls to a separate file Laura Abbott
2016-06-08 13:20   ` Liviu Dudau
2016-06-06 18:23 ` [RFC][PATCH 5/6] staging: android: ion: Add an ioctl for ABI checking Laura Abbott
2016-06-06 18:23 ` [RFC][PATCH 6/6] staging: android: ion: Introduce new ioctls for dynamic heaps Laura Abbott
2016-06-08 13:50   ` Liviu Dudau
2016-06-08 17:35     ` Laura Abbott
2016-06-08 15:34   ` Brian Starkey
2016-06-08 19:14     ` Laura Abbott
2016-06-09  8:25       ` Brian Starkey
2016-06-07  6:59 ` [Linaro-mm-sig] [RFC][PATCH 0/6] ion: improved ABI Chen Feng
2016-06-08 17:29   ` Laura Abbott
2016-06-08 15:15 ` Brian Starkey
2016-06-08 18:58   ` Laura Abbott

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=20160608131356.GL1165@e106497-lin.cambridge.arm.com \
    --to=liviu.dudau@arm.com \
    --cc=arve@android.com \
    --cc=bryanh@codeaurora.org \
    --cc=daniel.vetter@ffwll.ch \
    --cc=devel@driverdev.osuosl.org \
    --cc=eun.taik.lee@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jgebben@codeaurora.org \
    --cc=john.stultz@linaro.org \
    --cc=kernel-team@android.com \
    --cc=labbott@fedoraproject.org \
    --cc=labbott@redhat.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitchelh@codeaurora.org \
    --cc=riandrews@android.com \
    --cc=sumit.semwal@linaro.org \
    --cc=tixy@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®