[Intel-gfx] [PATCH 2/3] drm: Convert drm_vma_manager to embedded interval-tree in drm_mm

David Herrmann dh.herrmann at gmail.com
Wed Aug 3 17:45:15 UTC 2016


Hi Chris

On Wed, Aug 3, 2016 at 5:04 PM, Chris Wilson <chris at chris-wilson.co.uk> wrote:
> Having added an interval-tree to struct drm_mm, we can replace the
> auxiliary rb-tree inside the drm_vma_manager with it.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> Cc: David Herrmann <dh.herrmann at gmail.com>
> Cc: dri-devel at lists.freedesktop.org
> ---

Should have done that right from start when writing drm_vma_manager..

Reviewed-by: David Herrmann <dh.herrmann at gmail.com>

Thanks
David

>  drivers/gpu/drm/drm_vma_manager.c | 43 ++++++++-------------------------------
>  include/drm/drm_vma_manager.h     |  2 --
>  2 files changed, 9 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_vma_manager.c b/drivers/gpu/drm/drm_vma_manager.c
> index f306c8855978..0aef432679f9 100644
> --- a/drivers/gpu/drm/drm_vma_manager.c
> +++ b/drivers/gpu/drm/drm_vma_manager.c
> @@ -86,7 +86,6 @@ void drm_vma_offset_manager_init(struct drm_vma_offset_manager *mgr,
>                                  unsigned long page_offset, unsigned long size)
>  {
>         rwlock_init(&mgr->vm_lock);
> -       mgr->vm_addr_space_rb = RB_ROOT;
>         drm_mm_init(&mgr->vm_addr_space_mm, page_offset, size);
>  }
>  EXPORT_SYMBOL(drm_vma_offset_manager_init);
> @@ -145,16 +144,16 @@ struct drm_vma_offset_node *drm_vma_offset_lookup_locked(struct drm_vma_offset_m
>                                                          unsigned long start,
>                                                          unsigned long pages)
>  {
> -       struct drm_vma_offset_node *node, *best;
> +       struct drm_mm_node *node, *best;
>         struct rb_node *iter;
>         unsigned long offset;
>
> -       iter = mgr->vm_addr_space_rb.rb_node;
> +       iter = mgr->vm_addr_space_mm.interval_tree.rb_node;
>         best = NULL;
>
>         while (likely(iter)) {
> -               node = rb_entry(iter, struct drm_vma_offset_node, vm_rb);
> -               offset = node->vm_node.start;
> +               node = rb_entry(iter, struct drm_mm_node, rb);
> +               offset = node->start;
>                 if (start >= offset) {
>                         iter = iter->rb_right;
>                         best = node;
> @@ -167,38 +166,17 @@ struct drm_vma_offset_node *drm_vma_offset_lookup_locked(struct drm_vma_offset_m
>
>         /* verify that the node spans the requested area */
>         if (best) {
> -               offset = best->vm_node.start + best->vm_node.size;
> +               offset = best->start + best->size;
>                 if (offset < start + pages)
>                         best = NULL;
>         }
>
> -       return best;
> -}
> -EXPORT_SYMBOL(drm_vma_offset_lookup_locked);
> -
> -/* internal helper to link @node into the rb-tree */
> -static void _drm_vma_offset_add_rb(struct drm_vma_offset_manager *mgr,
> -                                  struct drm_vma_offset_node *node)
> -{
> -       struct rb_node **iter = &mgr->vm_addr_space_rb.rb_node;
> -       struct rb_node *parent = NULL;
> -       struct drm_vma_offset_node *iter_node;
> -
> -       while (likely(*iter)) {
> -               parent = *iter;
> -               iter_node = rb_entry(*iter, struct drm_vma_offset_node, vm_rb);
> +       if (!best)
> +               return NULL;
>
> -               if (node->vm_node.start < iter_node->vm_node.start)
> -                       iter = &(*iter)->rb_left;
> -               else if (node->vm_node.start > iter_node->vm_node.start)
> -                       iter = &(*iter)->rb_right;
> -               else
> -                       BUG();
> -       }
> -
> -       rb_link_node(&node->vm_rb, parent, iter);
> -       rb_insert_color(&node->vm_rb, &mgr->vm_addr_space_rb);
> +       return container_of(best, struct drm_vma_offset_node, vm_node);
>  }
> +EXPORT_SYMBOL(drm_vma_offset_lookup_locked);
>
>  /**
>   * drm_vma_offset_add() - Add offset node to manager
> @@ -240,8 +218,6 @@ int drm_vma_offset_add(struct drm_vma_offset_manager *mgr,
>         if (ret)
>                 goto out_unlock;
>
> -       _drm_vma_offset_add_rb(mgr, node);
> -
>  out_unlock:
>         write_unlock(&mgr->vm_lock);
>         return ret;
> @@ -265,7 +241,6 @@ void drm_vma_offset_remove(struct drm_vma_offset_manager *mgr,
>         write_lock(&mgr->vm_lock);
>
>         if (drm_mm_node_allocated(&node->vm_node)) {
> -               rb_erase(&node->vm_rb, &mgr->vm_addr_space_rb);
>                 drm_mm_remove_node(&node->vm_node);
>                 memset(&node->vm_node, 0, sizeof(node->vm_node));
>         }
> diff --git a/include/drm/drm_vma_manager.h b/include/drm/drm_vma_manager.h
> index 06ea8e077ec2..afba6fcac853 100644
> --- a/include/drm/drm_vma_manager.h
> +++ b/include/drm/drm_vma_manager.h
> @@ -40,13 +40,11 @@ struct drm_vma_offset_file {
>  struct drm_vma_offset_node {
>         rwlock_t vm_lock;
>         struct drm_mm_node vm_node;
> -       struct rb_node vm_rb;
>         struct rb_root vm_files;
>  };
>
>  struct drm_vma_offset_manager {
>         rwlock_t vm_lock;
> -       struct rb_root vm_addr_space_rb;
>         struct drm_mm vm_addr_space_mm;
>  };
>
> --
> 2.8.1
>


More information about the Intel-gfx mailing list