diff options
author | Jerome Glisse <jglisse@redhat.com> | 2011-11-11 15:42:57 -0500 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2011-12-06 05:40:11 -0500 |
commit | 57de4ba959b290f0b8cf36ecd5e7f1b29d4b8a12 (patch) | |
tree | 8063f4dfaf1a22bf8cf7a5f0410d4e4929b250ec /drivers/gpu/drm/ttm | |
parent | 8e7e70522d760c4ccd4cd370ebfa0ba69e006c6e (diff) |
drm/ttm: simplify memory accounting for ttm user v2
Provide helper function to compute the kernel memory size needed
for each buffer object. Move all the accounting inside ttm, simplifying
driver and avoiding code duplication accross them.
v2 fix accounting of ghost object, one would have thought that i
would have run into the issue since a longtime but it seems
ghost object are rare when you have plenty of vram ;)
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Diffstat (limited to 'drivers/gpu/drm/ttm')
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo.c | 52 | ||||
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo_util.c | 1 |
2 files changed, 41 insertions, 12 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index cb7352712750..de7ad9991902 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c | |||
@@ -137,6 +137,7 @@ static void ttm_bo_release_list(struct kref *list_kref) | |||
137 | struct ttm_buffer_object *bo = | 137 | struct ttm_buffer_object *bo = |
138 | container_of(list_kref, struct ttm_buffer_object, list_kref); | 138 | container_of(list_kref, struct ttm_buffer_object, list_kref); |
139 | struct ttm_bo_device *bdev = bo->bdev; | 139 | struct ttm_bo_device *bdev = bo->bdev; |
140 | size_t acc_size = bo->acc_size; | ||
140 | 141 | ||
141 | BUG_ON(atomic_read(&bo->list_kref.refcount)); | 142 | BUG_ON(atomic_read(&bo->list_kref.refcount)); |
142 | BUG_ON(atomic_read(&bo->kref.refcount)); | 143 | BUG_ON(atomic_read(&bo->kref.refcount)); |
@@ -152,9 +153,9 @@ static void ttm_bo_release_list(struct kref *list_kref) | |||
152 | if (bo->destroy) | 153 | if (bo->destroy) |
153 | bo->destroy(bo); | 154 | bo->destroy(bo); |
154 | else { | 155 | else { |
155 | ttm_mem_global_free(bdev->glob->mem_glob, bo->acc_size); | ||
156 | kfree(bo); | 156 | kfree(bo); |
157 | } | 157 | } |
158 | ttm_mem_global_free(bdev->glob->mem_glob, acc_size); | ||
158 | } | 159 | } |
159 | 160 | ||
160 | int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, bool interruptible) | 161 | int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, bool interruptible) |
@@ -1157,6 +1158,17 @@ int ttm_bo_init(struct ttm_bo_device *bdev, | |||
1157 | { | 1158 | { |
1158 | int ret = 0; | 1159 | int ret = 0; |
1159 | unsigned long num_pages; | 1160 | unsigned long num_pages; |
1161 | struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; | ||
1162 | |||
1163 | ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); | ||
1164 | if (ret) { | ||
1165 | printk(KERN_ERR TTM_PFX "Out of kernel memory.\n"); | ||
1166 | if (destroy) | ||
1167 | (*destroy)(bo); | ||
1168 | else | ||
1169 | kfree(bo); | ||
1170 | return -ENOMEM; | ||
1171 | } | ||
1160 | 1172 | ||
1161 | size += buffer_start & ~PAGE_MASK; | 1173 | size += buffer_start & ~PAGE_MASK; |
1162 | num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; | 1174 | num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; |
@@ -1227,14 +1239,34 @@ out_err: | |||
1227 | } | 1239 | } |
1228 | EXPORT_SYMBOL(ttm_bo_init); | 1240 | EXPORT_SYMBOL(ttm_bo_init); |
1229 | 1241 | ||
1230 | static inline size_t ttm_bo_size(struct ttm_bo_global *glob, | 1242 | size_t ttm_bo_acc_size(struct ttm_bo_device *bdev, |
1231 | unsigned long num_pages) | 1243 | unsigned long bo_size, |
1244 | unsigned struct_size) | ||
1232 | { | 1245 | { |
1233 | size_t page_array_size = (num_pages * sizeof(void *) + PAGE_SIZE - 1) & | 1246 | unsigned npages = (PAGE_ALIGN(bo_size)) >> PAGE_SHIFT; |
1234 | PAGE_MASK; | 1247 | size_t size = 0; |
1235 | 1248 | ||
1236 | return glob->ttm_bo_size + 2 * page_array_size; | 1249 | size += ttm_round_pot(struct_size); |
1250 | size += PAGE_ALIGN(npages * sizeof(void *)); | ||
1251 | size += ttm_round_pot(sizeof(struct ttm_tt)); | ||
1252 | return size; | ||
1237 | } | 1253 | } |
1254 | EXPORT_SYMBOL(ttm_bo_acc_size); | ||
1255 | |||
1256 | size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev, | ||
1257 | unsigned long bo_size, | ||
1258 | unsigned struct_size) | ||
1259 | { | ||
1260 | unsigned npages = (PAGE_ALIGN(bo_size)) >> PAGE_SHIFT; | ||
1261 | size_t size = 0; | ||
1262 | |||
1263 | size += ttm_round_pot(struct_size); | ||
1264 | size += PAGE_ALIGN(npages * sizeof(void *)); | ||
1265 | size += PAGE_ALIGN(npages * sizeof(dma_addr_t)); | ||
1266 | size += ttm_round_pot(sizeof(struct ttm_dma_tt)); | ||
1267 | return size; | ||
1268 | } | ||
1269 | EXPORT_SYMBOL(ttm_bo_dma_acc_size); | ||
1238 | 1270 | ||
1239 | int ttm_bo_create(struct ttm_bo_device *bdev, | 1271 | int ttm_bo_create(struct ttm_bo_device *bdev, |
1240 | unsigned long size, | 1272 | unsigned long size, |
@@ -1248,10 +1280,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, | |||
1248 | { | 1280 | { |
1249 | struct ttm_buffer_object *bo; | 1281 | struct ttm_buffer_object *bo; |
1250 | struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; | 1282 | struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; |
1283 | size_t acc_size; | ||
1251 | int ret; | 1284 | int ret; |
1252 | 1285 | ||
1253 | size_t acc_size = | 1286 | acc_size = ttm_bo_acc_size(bdev, size, sizeof(struct ttm_buffer_object)); |
1254 | ttm_bo_size(bdev->glob, (size + PAGE_SIZE - 1) >> PAGE_SHIFT); | ||
1255 | ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); | 1287 | ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); |
1256 | if (unlikely(ret != 0)) | 1288 | if (unlikely(ret != 0)) |
1257 | return ret; | 1289 | return ret; |
@@ -1437,10 +1469,6 @@ int ttm_bo_global_init(struct drm_global_reference *ref) | |||
1437 | goto out_no_shrink; | 1469 | goto out_no_shrink; |
1438 | } | 1470 | } |
1439 | 1471 | ||
1440 | glob->ttm_bo_extra_size = ttm_round_pot(sizeof(struct ttm_tt)); | ||
1441 | glob->ttm_bo_size = glob->ttm_bo_extra_size + | ||
1442 | ttm_round_pot(sizeof(struct ttm_buffer_object)); | ||
1443 | |||
1444 | atomic_set(&glob->bo_count, 0); | 1472 | atomic_set(&glob->bo_count, 0); |
1445 | 1473 | ||
1446 | ret = kobject_init_and_add( | 1474 | ret = kobject_init_and_add( |
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 60f204d67dbb..f8187ead7b37 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c | |||
@@ -445,6 +445,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, | |||
445 | kref_init(&fbo->list_kref); | 445 | kref_init(&fbo->list_kref); |
446 | kref_init(&fbo->kref); | 446 | kref_init(&fbo->kref); |
447 | fbo->destroy = &ttm_transfered_destroy; | 447 | fbo->destroy = &ttm_transfered_destroy; |
448 | fbo->acc_size = 0; | ||
448 | 449 | ||
449 | *new_obj = fbo; | 450 | *new_obj = fbo; |
450 | return 0; | 451 | return 0; |