aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRebecca Schultz Zavin2012-11-15 12:36:10 -0600
committerArve Hjønnevåg2013-02-19 19:56:01 -0600
commit78be6b326cfaa8be5e5b8bede173e9d150ddab2e (patch)
tree14b5393d2167754e661f4212582f19ce7705727e
parent39fc7db12e7d4c4cf884ee351f6e6474a877abfd (diff)
downloadkernel-common-78be6b326cfaa8be5e5b8bede173e9d150ddab2e.tar.gz
kernel-common-78be6b326cfaa8be5e5b8bede173e9d150ddab2e.tar.xz
kernel-common-78be6b326cfaa8be5e5b8bede173e9d150ddab2e.zip
gpu: ion: Switch heap rbtree to a prio list
Switches the rbtree tree of heaps for a plist. This significantly simplifies the code and the list is small and is modified only at first boot so the rbtree is unnecessary. This also switches the traversal of the heap list to traverse from highest to lowest id's. This allows allocations to pass a heap mask that falls back on the system heap -- typically id 0, which is the common case. Change-Id: I715be6f4cf020a84ca4f1947c30ee3d2559fb523 Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
-rw-r--r--drivers/gpu/ion/ion.c35
-rw-r--r--drivers/gpu/ion/ion_priv.h4
2 files changed, 10 insertions, 29 deletions
diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
index 3384a099cd0..a686af33250 100644
--- a/drivers/gpu/ion/ion.c
+++ b/drivers/gpu/ion/ion.c
@@ -49,7 +49,7 @@ struct ion_device {
49 struct rb_root buffers; 49 struct rb_root buffers;
50 struct mutex buffer_lock; 50 struct mutex buffer_lock;
51 struct rw_semaphore lock; 51 struct rw_semaphore lock;
52 struct rb_root heaps; 52 struct plist_head heaps;
53 long (*custom_ioctl) (struct ion_client *client, unsigned int cmd, 53 long (*custom_ioctl) (struct ion_client *client, unsigned int cmd,
54 unsigned long arg); 54 unsigned long arg);
55 struct rb_root clients; 55 struct rb_root clients;
@@ -389,10 +389,10 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
389 size_t align, unsigned int heap_mask, 389 size_t align, unsigned int heap_mask,
390 unsigned int flags) 390 unsigned int flags)
391{ 391{
392 struct rb_node *n;
393 struct ion_handle *handle; 392 struct ion_handle *handle;
394 struct ion_device *dev = client->dev; 393 struct ion_device *dev = client->dev;
395 struct ion_buffer *buffer = NULL; 394 struct ion_buffer *buffer = NULL;
395 struct ion_heap *heap;
396 396
397 pr_debug("%s: len %d align %d heap_mask %u flags %x\n", __func__, len, 397 pr_debug("%s: len %d align %d heap_mask %u flags %x\n", __func__, len,
398 align, heap_mask, flags); 398 align, heap_mask, flags);
@@ -408,8 +408,7 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
408 len = PAGE_ALIGN(len); 408 len = PAGE_ALIGN(len);
409 409
410 down_read(&dev->lock); 410 down_read(&dev->lock);
411 for (n = rb_first(&dev->heaps); n != NULL; n = rb_next(n)) { 411 plist_for_each_entry(heap, &dev->heaps, node) {
412 struct ion_heap *heap = rb_entry(n, struct ion_heap, node);
413 /* if the client doesn't support this heap type */ 412 /* if the client doesn't support this heap type */
414 if (!((1 << heap->type) & client->heap_mask)) 413 if (!((1 << heap->type) & client->heap_mask))
415 continue; 414 continue;
@@ -1266,10 +1265,6 @@ static const struct file_operations debug_heap_fops = {
1266 1265
1267void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap) 1266void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
1268{ 1267{
1269 struct rb_node **p = &dev->heaps.rb_node;
1270 struct rb_node *parent = NULL;
1271 struct ion_heap *entry;
1272
1273 if (!heap->ops->allocate || !heap->ops->free || !heap->ops->map_dma || 1268 if (!heap->ops->allocate || !heap->ops->free || !heap->ops->map_dma ||
1274 !heap->ops->unmap_dma) 1269 !heap->ops->unmap_dma)
1275 pr_err("%s: can not add heap with invalid ops struct.\n", 1270 pr_err("%s: can not add heap with invalid ops struct.\n",
@@ -1277,26 +1272,12 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
1277 1272
1278 heap->dev = dev; 1273 heap->dev = dev;
1279 down_write(&dev->lock); 1274 down_write(&dev->lock);
1280 while (*p) { 1275 /* use negative heap->id to reverse the priority -- when traversing
1281 parent = *p; 1276 the list later attempt higher id numbers first */
1282 entry = rb_entry(parent, struct ion_heap, node); 1277 plist_node_init(&heap->node, -heap->id);
1283 1278 plist_add(&heap->node, &dev->heaps);
1284 if (heap->id < entry->id) {
1285 p = &(*p)->rb_left;
1286 } else if (heap->id > entry->id ) {
1287 p = &(*p)->rb_right;
1288 } else {
1289 pr_err("%s: can not insert multiple heaps with "
1290 "id %d\n", __func__, heap->id);
1291 goto end;
1292 }
1293 }
1294
1295 rb_link_node(&heap->node, parent, p);
1296 rb_insert_color(&heap->node, &dev->heaps);
1297 debugfs_create_file(heap->name, 0664, dev->debug_root, heap, 1279 debugfs_create_file(heap->name, 0664, dev->debug_root, heap,
1298 &debug_heap_fops); 1280 &debug_heap_fops);
1299end:
1300 up_write(&dev->lock); 1281 up_write(&dev->lock);
1301} 1282}
1302 1283
@@ -1330,7 +1311,7 @@ struct ion_device *ion_device_create(long (*custom_ioctl)
1330 idev->buffers = RB_ROOT; 1311 idev->buffers = RB_ROOT;
1331 mutex_init(&idev->buffer_lock); 1312 mutex_init(&idev->buffer_lock);
1332 init_rwsem(&idev->lock); 1313 init_rwsem(&idev->lock);
1333 idev->heaps = RB_ROOT; 1314 plist_head_init(&idev->heaps);
1334 idev->clients = RB_ROOT; 1315 idev->clients = RB_ROOT;
1335 return idev; 1316 return idev;
1336} 1317}
diff --git a/drivers/gpu/ion/ion_priv.h b/drivers/gpu/ion/ion_priv.h
index 21c196305bf..e719a625084 100644
--- a/drivers/gpu/ion/ion_priv.h
+++ b/drivers/gpu/ion/ion_priv.h
@@ -126,11 +126,11 @@ struct ion_heap_ops {
126 * that are allocated from a specially reserved heap. 126 * that are allocated from a specially reserved heap.
127 */ 127 */
128struct ion_heap { 128struct ion_heap {
129 struct rb_node node; 129 struct plist_node node;
130 struct ion_device *dev; 130 struct ion_device *dev;
131 enum ion_heap_type type; 131 enum ion_heap_type type;
132 struct ion_heap_ops *ops; 132 struct ion_heap_ops *ops;
133 int id; 133 unsigned int id;
134 const char *name; 134 const char *name;
135 int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *); 135 int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *);
136}; 136};