summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2016-06-27 20:46:02 -0400
committerAlex Waterman <alexw@nvidia.com>2016-07-19 14:30:45 -0400
commit5672cbdf6d8e7b8b93a08cd388097e2d1f0a8843 (patch)
treec00d0cc5c7f46ffe39c14bfdb6585716cd071bde /drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
parentb6569319c772d84087a0a1a6d7146bdcae8e9aab (diff)
gpu: nvgpu: Move buddy allocator to new file
Move the buddy allocator implementation to a new file to make the code more organized. Also, as part of this, commonize some macros and functions which will be used by future allocator implementations. Bug 1781897 Change-Id: I1611534d5d872bf3b4677f7a1cc024a94b1c437e Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1172116 Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/gk20a_allocator.h')
-rw-r--r--drivers/gpu/nvgpu/gk20a/gk20a_allocator.h200
1 files changed, 30 insertions, 170 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
index 74e23e6c..06819700 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
+++ b/drivers/gpu/nvgpu/gk20a/gk20a_allocator.h
@@ -17,8 +17,6 @@
17#ifndef GK20A_ALLOCATOR_H 17#ifndef GK20A_ALLOCATOR_H
18#define GK20A_ALLOCATOR_H 18#define GK20A_ALLOCATOR_H
19 19
20#include <linux/list.h>
21#include <linux/rbtree.h>
22#include <linux/debugfs.h> 20#include <linux/debugfs.h>
23#include <linux/seq_file.h> 21#include <linux/seq_file.h>
24#include <linux/platform_device.h> 22#include <linux/platform_device.h>
@@ -63,138 +61,6 @@ struct gk20a_allocator_ops {
63 struct seq_file *s, int lock); 61 struct seq_file *s, int lock);
64}; 62};
65 63
66/*
67 * Each buddy is an element in a binary tree.
68 */
69struct gk20a_buddy {
70 struct gk20a_buddy *parent; /* Parent node. */
71 struct gk20a_buddy *buddy; /* This node's buddy. */
72 struct gk20a_buddy *left; /* Lower address sub-node. */
73 struct gk20a_buddy *right; /* Higher address sub-node. */
74
75 struct list_head buddy_entry; /* List entry for various lists. */
76 struct rb_node alloced_entry; /* RB tree of allocations. */
77
78 u64 start; /* Start address of this buddy. */
79 u64 end; /* End address of this buddy. */
80 u64 order; /* Buddy order. */
81
82#define BALLOC_BUDDY_ALLOCED 0x1
83#define BALLOC_BUDDY_SPLIT 0x2
84#define BALLOC_BUDDY_IN_LIST 0x4
85 int flags; /* List of associated flags. */
86
87 /*
88 * Size of the PDE this buddy is using. This allows for grouping like
89 * sized allocations into the same PDE.
90 */
91#define BALLOC_PTE_SIZE_ANY 0x0
92#define BALLOC_PTE_SIZE_SMALL 0x1
93#define BALLOC_PTE_SIZE_BIG 0x2
94 int pte_size;
95};
96
97#define __buddy_flag_ops(flag, flag_up) \
98 static inline int buddy_is_ ## flag(struct gk20a_buddy *b) \
99 { \
100 return b->flags & BALLOC_BUDDY_ ## flag_up; \
101 } \
102 static inline void buddy_set_ ## flag(struct gk20a_buddy *b) \
103 { \
104 b->flags |= BALLOC_BUDDY_ ## flag_up; \
105 } \
106 static inline void buddy_clr_ ## flag(struct gk20a_buddy *b) \
107 { \
108 b->flags &= ~BALLOC_BUDDY_ ## flag_up; \
109 }
110
111/*
112 * int buddy_is_alloced(struct gk20a_buddy *b);
113 * void buddy_set_alloced(struct gk20a_buddy *b);
114 * void buddy_clr_alloced(struct gk20a_buddy *b);
115 *
116 * int buddy_is_split(struct gk20a_buddy *b);
117 * void buddy_set_split(struct gk20a_buddy *b);
118 * void buddy_clr_split(struct gk20a_buddy *b);
119 *
120 * int buddy_is_in_list(struct gk20a_buddy *b);
121 * void buddy_set_in_list(struct gk20a_buddy *b);
122 * void buddy_clr_in_list(struct gk20a_buddy *b);
123 */
124__buddy_flag_ops(alloced, ALLOCED);
125__buddy_flag_ops(split, SPLIT);
126__buddy_flag_ops(in_list, IN_LIST);
127
128/*
129 * Keeps info for a fixed allocation.
130 */
131struct gk20a_fixed_alloc {
132 struct list_head buddies; /* List of buddies. */
133 struct rb_node alloced_entry; /* RB tree of fixed allocations. */
134
135 u64 start; /* Start of fixed block. */
136 u64 end; /* End address. */
137};
138
139/*
140 * GPU buddy allocator for the various GPU address spaces. Each addressable unit
141 * doesn't have to correspond to a byte. In some cases each unit is a more
142 * complex object such as a comp_tag line or the like.
143 *
144 * The max order is computed based on the size of the minimum order and the size
145 * of the address space.
146 *
147 * order_size is the size of an order 0 buddy.
148 */
149struct gk20a_buddy_allocator {
150 struct gk20a_allocator *owner; /* Owner of this buddy allocator. */
151 struct vm_gk20a *vm; /* Parent VM - can be NULL. */
152
153 u64 base; /* Base address of the space. */
154 u64 length; /* Length of the space. */
155 u64 blk_size; /* Size of order 0 allocation. */
156 u64 blk_shift; /* Shift to divide by blk_size. */
157
158 int init; /* Non-zero if initialized. */
159
160 /* Internal stuff. */
161 u64 start; /* Real start (aligned to blk_size). */
162 u64 end; /* Real end, trimmed if needed. */
163 u64 count; /* Count of objects in space. */
164 u64 blks; /* Count of blks in the space. */
165 u64 max_order; /* Specific maximum order. */
166
167 struct rb_root alloced_buddies; /* Outstanding allocations. */
168 struct rb_root fixed_allocs; /* Outstanding fixed allocations. */
169
170 /*
171 * Impose an upper bound on the maximum order.
172 */
173#define GPU_BALLOC_MAX_ORDER 31
174#define GPU_BALLOC_ORDER_LIST_LEN (GPU_BALLOC_MAX_ORDER + 1)
175
176 struct list_head buddy_list[GPU_BALLOC_ORDER_LIST_LEN];
177 u64 buddy_list_len[GPU_BALLOC_ORDER_LIST_LEN];
178 u64 buddy_list_split[GPU_BALLOC_ORDER_LIST_LEN];
179 u64 buddy_list_alloced[GPU_BALLOC_ORDER_LIST_LEN];
180
181 /*
182 * This is for when the allocator is managing a GVA space (the
183 * GPU_BALLOC_GVA_SPACE bit is set in @flags). This requires
184 * that we group like sized allocations into PDE blocks.
185 */
186 u64 pte_blk_order;
187
188 int inited;
189
190#define GPU_BALLOC_GVA_SPACE 0x1
191 u64 flags;
192
193 u64 bytes_alloced;
194 u64 bytes_alloced_real;
195 u64 bytes_freed;
196};
197
198struct gk20a_allocator { 64struct gk20a_allocator {
199 char name[32]; 65 char name[32];
200 struct mutex lock; 66 struct mutex lock;
@@ -205,6 +71,11 @@ struct gk20a_allocator {
205 struct dentry *debugfs_entry; 71 struct dentry *debugfs_entry;
206}; 72};
207 73
74/*
75 * Allocator flags.
76 */
77#define GPU_BALLOC_GVA_SPACE 0x1
78
208static inline void alloc_lock(struct gk20a_allocator *a) 79static inline void alloc_lock(struct gk20a_allocator *a)
209{ 80{
210 mutex_lock(&a->lock); 81 mutex_lock(&a->lock);
@@ -215,42 +86,6 @@ static inline void alloc_unlock(struct gk20a_allocator *a)
215 mutex_unlock(&a->lock); 86 mutex_unlock(&a->lock);
216} 87}
217 88
218static inline struct gk20a_buddy_allocator *buddy_allocator(
219 struct gk20a_allocator *a)
220{
221 return (struct gk20a_buddy_allocator *)a->priv;
222}
223
224static inline struct list_head *balloc_get_order_list(
225 struct gk20a_buddy_allocator *a, int order)
226{
227 return &a->buddy_list[order];
228}
229
230static inline u64 balloc_order_to_len(struct gk20a_buddy_allocator *a,
231 int order)
232{
233 return (1 << order) * a->blk_size;
234}
235
236static inline u64 balloc_base_shift(struct gk20a_buddy_allocator *a,
237 u64 base)
238{
239 return base - a->start;
240}
241
242static inline u64 balloc_base_unshift(struct gk20a_buddy_allocator *a,
243 u64 base)
244{
245 return base + a->start;
246}
247
248static inline struct gk20a_allocator *balloc_owner(
249 struct gk20a_buddy_allocator *a)
250{
251 return a->owner;
252}
253
254/* 89/*
255 * Buddy allocator specific initializers. 90 * Buddy allocator specific initializers.
256 */ 91 */
@@ -262,6 +97,8 @@ int gk20a_buddy_allocator_init(struct gk20a_allocator *allocator,
262 const char *name, u64 base, u64 size, 97 const char *name, u64 base, u64 size,
263 u64 blk_size, u64 flags); 98 u64 blk_size, u64 flags);
264 99
100#define GPU_BALLOC_MAX_ORDER 31
101
265/* 102/*
266 * Allocator APIs. 103 * Allocator APIs.
267 */ 104 */
@@ -282,10 +119,33 @@ void gk20a_alloc_print_stats(struct gk20a_allocator *a,
282 struct seq_file *s, int lock); 119 struct seq_file *s, int lock);
283 120
284/* 121/*
122 * Common functionality for the internals of the allocators.
123 */
124void gk20a_init_alloc_debug(struct gk20a_allocator *a);
125void gk20a_fini_alloc_debug(struct gk20a_allocator *a);
126int __gk20a_alloc_common_init(struct gk20a_allocator *a,
127 const char *name, void *priv,
128 const struct gk20a_allocator_ops *ops);
129
130/*
285 * Debug stuff. 131 * Debug stuff.
286 */ 132 */
133extern u32 gk20a_alloc_tracing_on;
134
287void gk20a_alloc_debugfs_init(struct platform_device *pdev); 135void gk20a_alloc_debugfs_init(struct platform_device *pdev);
288 136
137#define gk20a_alloc_trace_func() \
138 do { \
139 if (gk20a_alloc_tracing_on) \
140 trace_printk("%s\n", __func__); \
141 } while (0)
142
143#define gk20a_alloc_trace_func_done() \
144 do { \
145 if (gk20a_alloc_tracing_on) \
146 trace_printk("%s_done\n", __func__); \
147 } while (0)
148
289#define __alloc_pstat(seq, allocator, fmt, arg...) \ 149#define __alloc_pstat(seq, allocator, fmt, arg...) \
290 do { \ 150 do { \
291 if (s) \ 151 if (s) \