drm/vmwgfx: Use an RBtree instead of linked list for MOB resources
With emulated coherent memory we need to be able to quickly look up a resource from the MOB offset. Instead of traversing a linked list with O(n) worst case, use an RBtree with O(log n) worst case complexity. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Deepak Rawat <drawat@vmware.com>
This commit is contained in:
@@ -41,11 +41,24 @@
|
||||
void vmw_resource_mob_attach(struct vmw_resource *res)
|
||||
{
|
||||
struct vmw_buffer_object *backup = res->backup;
|
||||
struct rb_node **new = &backup->res_tree.rb_node, *parent = NULL;
|
||||
|
||||
lockdep_assert_held(&backup->base.resv->lock.base);
|
||||
res->used_prio = (res->res_dirty) ? res->func->dirty_prio :
|
||||
res->func->prio;
|
||||
list_add_tail(&res->mob_head, &backup->res_list);
|
||||
|
||||
while (*new) {
|
||||
struct vmw_resource *this =
|
||||
container_of(*new, struct vmw_resource, mob_node);
|
||||
|
||||
parent = *new;
|
||||
new = (res->backup_offset < this->backup_offset) ?
|
||||
&((*new)->rb_left) : &((*new)->rb_right);
|
||||
}
|
||||
|
||||
rb_link_node(&res->mob_node, parent, new);
|
||||
rb_insert_color(&res->mob_node, &backup->res_tree);
|
||||
|
||||
vmw_bo_prio_add(backup, res->used_prio);
|
||||
}
|
||||
|
||||
@@ -59,7 +72,8 @@ void vmw_resource_mob_detach(struct vmw_resource *res)
|
||||
|
||||
lockdep_assert_held(&backup->base.resv->lock.base);
|
||||
if (vmw_resource_mob_attached(res)) {
|
||||
list_del_init(&res->mob_head);
|
||||
rb_erase(&res->mob_node, &backup->res_tree);
|
||||
RB_CLEAR_NODE(&res->mob_node);
|
||||
vmw_bo_prio_del(backup, res->used_prio);
|
||||
}
|
||||
}
|
||||
@@ -206,8 +220,8 @@ int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
|
||||
res->res_free = res_free;
|
||||
res->dev_priv = dev_priv;
|
||||
res->func = func;
|
||||
RB_CLEAR_NODE(&res->mob_node);
|
||||
INIT_LIST_HEAD(&res->lru_head);
|
||||
INIT_LIST_HEAD(&res->mob_head);
|
||||
INIT_LIST_HEAD(&res->binding_head);
|
||||
res->id = -1;
|
||||
res->backup = NULL;
|
||||
@@ -756,19 +770,20 @@ out_no_validate:
|
||||
*/
|
||||
void vmw_resource_unbind_list(struct vmw_buffer_object *vbo)
|
||||
{
|
||||
|
||||
struct vmw_resource *res, *next;
|
||||
struct ttm_validate_buffer val_buf = {
|
||||
.bo = &vbo->base,
|
||||
.num_shared = 0
|
||||
};
|
||||
|
||||
lockdep_assert_held(&vbo->base.resv->lock.base);
|
||||
list_for_each_entry_safe(res, next, &vbo->res_list, mob_head) {
|
||||
if (!res->func->unbind)
|
||||
continue;
|
||||
while (!RB_EMPTY_ROOT(&vbo->res_tree)) {
|
||||
struct rb_node *node = vbo->res_tree.rb_node;
|
||||
struct vmw_resource *res =
|
||||
container_of(node, struct vmw_resource, mob_node);
|
||||
|
||||
if (!WARN_ON_ONCE(!res->func->unbind))
|
||||
(void) res->func->unbind(res, res->res_dirty, &val_buf);
|
||||
|
||||
(void) res->func->unbind(res, res->res_dirty, &val_buf);
|
||||
res->backup_dirty = true;
|
||||
res->res_dirty = false;
|
||||
vmw_resource_mob_detach(res);
|
||||
|
Reference in New Issue
Block a user