aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2013-08-21 11:23:12 -0700
committerColin Cross <ccross@android.com>2013-09-19 23:03:33 -0500
commit002119eeb221cf1efd7afda836da768ff1cd0ad9 (patch)
tree29d053b0dabbce9f2427408ca4137de130783b9f
parent1126d98d8e34d771afcc72ce5d1c37ad4d474402 (diff)
downloadlinaro-lsk-002119eeb221cf1efd7afda836da768ff1cd0ad9.tar.gz
ion: index client->handles rbtree by buffer
The only remaining users of the client->handles rbtree are iterating through it like a list. Keep the rbtree, but change its index to be the buffer address instead of the handle address, which makes ion_handle_lookup a fast rbtree search. Change-Id: Ie7d974b3a5d9831c0d664de85ddae8db3c3abdf9 Signed-off-by: Colin Cross <ccross@android.com>
-rw-r--r--drivers/gpu/ion/ion.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
index 8d43ad12ea6..9f73052c392 100644
--- a/drivers/gpu/ion/ion.c
+++ b/drivers/gpu/ion/ion.c
@@ -388,13 +388,16 @@ static int ion_handle_put(struct ion_handle *handle)
static struct ion_handle *ion_handle_lookup(struct ion_client *client,
struct ion_buffer *buffer)
{
- struct rb_node *n;
-
- for (n = rb_first(&client->handles); n; n = rb_next(n)) {
- struct ion_handle *handle = rb_entry(n, struct ion_handle,
- node);
- if (handle->buffer == buffer)
- return handle;
+ struct rb_node *n = client->handles.rb_node;
+
+ while (n) {
+ struct ion_handle *entry = rb_entry(n, struct ion_handle, node);
+ if (buffer < entry->buffer)
+ n = n->rb_left;
+ else if (buffer > entry->buffer)
+ n = n->rb_right;
+ else
+ return entry;
}
return ERR_PTR(-EINVAL);
}
@@ -432,9 +435,9 @@ static int ion_handle_add(struct ion_client *client, struct ion_handle *handle)
parent = *p;
entry = rb_entry(parent, struct ion_handle, node);
- if (handle < entry)
+ if (handle->buffer < entry->buffer)
p = &(*p)->rb_left;
- else if (handle > entry)
+ else if (handle->buffer > entry->buffer)
p = &(*p)->rb_right;
else
WARN(1, "%s: buffer already found.", __func__);