summaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorDeepak Nibade <dnibade@nvidia.com>2017-04-07 05:45:16 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-04-18 04:15:12 -0400
commit486173a000ae7cebf6a3af7f95419544b5ecbd67 (patch)
tree996f21bc7d1ab39220d238ad1918b8c7de838d34 /drivers/gpu
parent26deb61b3b12c8f876133b78e64575d1478d0c95 (diff)
gpu: nvgpu: use nvgpu rbtree for page allocator
Use nvgpu rbtree instead of linux rbtree for page allocator Move to use nvgpu_rbtree_node structure and nvgpu_rbtree_* APIs Jira NVGPU-13 Change-Id: I3faf843762652c6005186cbe715377050f65ee2c Signed-off-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-on: http://git-master/r/1457858 Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/nvgpu/common/mm/page_allocator.c44
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/page_allocator.h13
2 files changed, 19 insertions, 38 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/page_allocator.c b/drivers/gpu/nvgpu/common/mm/page_allocator.c
index 14d66efe..1b6a2092 100644
--- a/drivers/gpu/nvgpu/common/mm/page_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/page_allocator.c
@@ -151,28 +151,10 @@ static void __nvgpu_free_pages(struct nvgpu_page_allocator *a,
151static int __insert_page_alloc(struct nvgpu_page_allocator *a, 151static int __insert_page_alloc(struct nvgpu_page_allocator *a,
152 struct nvgpu_page_alloc *alloc) 152 struct nvgpu_page_alloc *alloc)
153{ 153{
154 struct rb_node **new = &a->allocs.rb_node; 154 alloc->tree_entry.key_start = alloc->base;
155 struct rb_node *parent = NULL; 155 alloc->tree_entry.key_end = alloc->base + alloc->length;
156
157 while (*new) {
158 struct nvgpu_page_alloc *tmp =
159 container_of(*new, struct nvgpu_page_alloc,
160 tree_entry);
161
162 parent = *new;
163 if (alloc->base < tmp->base) {
164 new = &((*new)->rb_left);
165 } else if (alloc->base > tmp->base) {
166 new = &((*new)->rb_right);
167 } else {
168 WARN(1, "Duplicate entries in allocated list!\n");
169 return 0;
170 }
171 }
172
173 rb_link_node(&alloc->tree_entry, parent, new);
174 rb_insert_color(&alloc->tree_entry, &a->allocs);
175 156
157 nvgpu_rbtree_insert(&alloc->tree_entry, &a->allocs);
176 return 0; 158 return 0;
177} 159}
178 160
@@ -180,24 +162,16 @@ static struct nvgpu_page_alloc *__find_page_alloc(
180 struct nvgpu_page_allocator *a, 162 struct nvgpu_page_allocator *a,
181 u64 addr) 163 u64 addr)
182{ 164{
183 struct rb_node *node = a->allocs.rb_node;
184 struct nvgpu_page_alloc *alloc; 165 struct nvgpu_page_alloc *alloc;
166 struct nvgpu_rbtree_node *node = NULL;
185 167
186 while (node) { 168 nvgpu_rbtree_search(addr, &node, a->allocs);
187 alloc = container_of(node, struct nvgpu_page_alloc, tree_entry);
188
189 if (addr < alloc->base)
190 node = node->rb_left;
191 else if (addr > alloc->base)
192 node = node->rb_right;
193 else
194 break;
195 }
196
197 if (!node) 169 if (!node)
198 return NULL; 170 return NULL;
199 171
200 rb_erase(node, &a->allocs); 172 alloc = nvgpu_page_alloc_from_rbtree_node(node);
173
174 nvgpu_rbtree_unlink(node, &a->allocs);
201 175
202 return alloc; 176 return alloc;
203} 177}
@@ -906,7 +880,7 @@ int nvgpu_page_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
906 a->length = length; 880 a->length = length;
907 a->page_size = blk_size; 881 a->page_size = blk_size;
908 a->page_shift = __ffs(blk_size); 882 a->page_shift = __ffs(blk_size);
909 a->allocs = RB_ROOT; 883 a->allocs = NULL;
910 a->owner = __a; 884 a->owner = __a;
911 a->flags = flags; 885 a->flags = flags;
912 886
diff --git a/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h b/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h
index 92f48ac5..70ed81c3 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h
@@ -18,11 +18,11 @@
18#define PAGE_ALLOCATOR_PRIV_H 18#define PAGE_ALLOCATOR_PRIV_H
19 19
20#include <linux/list.h> 20#include <linux/list.h>
21#include <linux/rbtree.h>
22 21
23#include <nvgpu/allocator.h> 22#include <nvgpu/allocator.h>
24#include <nvgpu/kmem.h> 23#include <nvgpu/kmem.h>
25#include <nvgpu/list.h> 24#include <nvgpu/list.h>
25#include <nvgpu/rbtree.h>
26 26
27struct nvgpu_allocator; 27struct nvgpu_allocator;
28 28
@@ -110,7 +110,7 @@ struct nvgpu_page_alloc {
110 */ 110 */
111 u64 base; 111 u64 base;
112 112
113 struct rb_node tree_entry; 113 struct nvgpu_rbtree_node tree_entry;
114 114
115 /* 115 /*
116 * Set if this is a slab alloc. Points back to the slab page that owns 116 * Set if this is a slab alloc. Points back to the slab page that owns
@@ -120,6 +120,13 @@ struct nvgpu_page_alloc {
120 struct page_alloc_slab_page *slab_page; 120 struct page_alloc_slab_page *slab_page;
121}; 121};
122 122
123static inline struct nvgpu_page_alloc *
124nvgpu_page_alloc_from_rbtree_node(struct nvgpu_rbtree_node *node)
125{
126 return (struct nvgpu_page_alloc *)
127 ((uintptr_t)node - offsetof(struct nvgpu_page_alloc, tree_entry));
128};
129
123struct nvgpu_page_allocator { 130struct nvgpu_page_allocator {
124 struct nvgpu_allocator *owner; /* Owner of this allocator. */ 131 struct nvgpu_allocator *owner; /* Owner of this allocator. */
125 132
@@ -138,7 +145,7 @@ struct nvgpu_page_allocator {
138 u64 page_size; 145 u64 page_size;
139 u32 page_shift; 146 u32 page_shift;
140 147
141 struct rb_root allocs; /* Outstanding allocations. */ 148 struct nvgpu_rbtree_node *allocs; /* Outstanding allocations. */
142 149
143 struct page_alloc_slab *slabs; 150 struct page_alloc_slab *slabs;
144 int nr_slabs; 151 int nr_slabs;