• Home
  • Raw
  • Download

Lines Matching +full:cache +full:- +full:name

29 #include "drm-uapi/v3d_drm.h"
33 /* Default max size of the bo cache, in MB.
37 * from testing those applications, the main consumer of the bo cache are
42 /* Discarded to use a V3D_DEBUG for this, as it would mean adding a run-time
50 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_dump_stats() local
52 mesa_logi(" BOs allocated: %d\n", device->bo_count); in bo_dump_stats()
53 mesa_logi(" BOs size: %dkb\n", device->bo_size / 1024); in bo_dump_stats()
54 mesa_logi(" BOs cached: %d\n", cache->cache_count); in bo_dump_stats()
55 mesa_logi(" BOs cached size: %dkb\n", cache->cache_size / 1024); in bo_dump_stats()
57 if (!list_is_empty(&cache->time_list)) { in bo_dump_stats()
58 struct v3dv_bo *first = list_first_entry(&cache->time_list, in bo_dump_stats()
61 struct v3dv_bo *last = list_last_entry(&cache->time_list, in bo_dump_stats()
65 mesa_logi(" oldest cache time: %ld\n", (long)first->free_time); in bo_dump_stats()
66 mesa_logi(" newest cache time: %ld\n", (long)last->free_time); in bo_dump_stats()
73 if (cache->size_list_size) { in bo_dump_stats()
75 for (uint32_t i = 0; i < cache->size_list_size; i++) { in bo_dump_stats()
76 if (list_is_empty(&cache->size_list[i])) in bo_dump_stats()
84 bo_remove_from_cache(struct v3dv_bo_cache *cache, struct v3dv_bo *bo) in bo_remove_from_cache() argument
86 list_del(&bo->time_list); in bo_remove_from_cache()
87 list_del(&bo->size_list); in bo_remove_from_cache()
89 cache->cache_count--; in bo_remove_from_cache()
90 cache->cache_size -= bo->size; in bo_remove_from_cache()
94 bo_from_cache(struct v3dv_device *device, uint32_t size, const char *name) in bo_from_cache() argument
96 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_from_cache() local
97 uint32_t page_index = size / 4096 - 1; in bo_from_cache()
99 if (cache->size_list_size <= page_index) in bo_from_cache()
104 mtx_lock(&cache->lock); in bo_from_cache()
105 if (!list_is_empty(&cache->size_list[page_index])) { in bo_from_cache()
106 bo = list_first_entry(&cache->size_list[page_index], in bo_from_cache()
114 mtx_unlock(&cache->lock); in bo_from_cache()
118 bo_remove_from_cache(cache, bo); in bo_from_cache()
119 bo->name = name; in bo_from_cache()
120 p_atomic_set(&bo->refcnt, 1); in bo_from_cache()
122 mtx_unlock(&cache->lock); in bo_from_cache()
133 assert(p_atomic_read(&bo->refcnt) == 0); in bo_free()
134 assert(bo->map == NULL); in bo_free()
136 if (!bo->is_import) { in bo_free()
137 device->bo_count--; in bo_free()
138 device->bo_size -= bo->size; in bo_free()
141 mesa_logi("Freed %s%s%dkb:\n", bo->name ? bo->name : "", in bo_free()
142 bo->name ? " " : "", bo->size / 1024); in bo_free()
147 uint32_t handle = bo->handle; in bo_free()
161 int ret = v3d_ioctl(device->pdevice->render_fd, DRM_IOCTL_GEM_CLOSE, &c); in bo_free()
172 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_cache_free_all() local
175 mtx_lock(&cache->lock); in bo_cache_free_all()
176 list_for_each_entry_safe(struct v3dv_bo, bo, &cache->time_list, in bo_cache_free_all()
178 bo_remove_from_cache(cache, bo); in bo_cache_free_all()
182 mtx_unlock(&cache->lock); in bo_cache_free_all()
191 const char *name, in v3dv_bo_init() argument
194 p_atomic_set(&bo->refcnt, 1); in v3dv_bo_init()
195 bo->handle = handle; in v3dv_bo_init()
196 bo->handle_bit = 1ull << (handle % 64); in v3dv_bo_init()
197 bo->size = size; in v3dv_bo_init()
198 bo->offset = offset; in v3dv_bo_init()
199 bo->map = NULL; in v3dv_bo_init()
200 bo->map_size = 0; in v3dv_bo_init()
201 bo->name = name; in v3dv_bo_init()
202 bo->private = private; in v3dv_bo_init()
203 bo->dumb_handle = -1; in v3dv_bo_init()
204 bo->is_import = false; in v3dv_bo_init()
205 bo->cl_branch_offset = 0xffffffff; in v3dv_bo_init()
206 list_inithead(&bo->list_link); in v3dv_bo_init()
217 bo->is_import = true; in v3dv_bo_init_import()
223 const char *name, in v3dv_bo_alloc() argument
232 bo = bo_from_cache(device, size, name); in v3dv_bo_alloc()
235 mesa_logi("Allocated %s %dkb from cache:\n", name, size / 1024); in v3dv_bo_alloc()
248 ret = v3d_ioctl(device->pdevice->render_fd, in v3dv_bo_alloc()
251 if (!list_is_empty(&device->bo_cache.time_list)) { in v3dv_bo_alloc()
263 bo = v3dv_device_lookup_bo(device->pdevice, create.handle); in v3dv_bo_alloc()
264 assert(bo && bo->handle == 0); in v3dv_bo_alloc()
266 v3dv_bo_init(bo, create.handle, size, create.offset, name, private); in v3dv_bo_alloc()
268 device->bo_count++; in v3dv_bo_alloc()
269 device->bo_size += bo->size; in v3dv_bo_alloc()
271 mesa_logi("Allocated %s %dkb:\n", name, size / 1024); in v3dv_bo_alloc()
283 assert(bo != NULL && size <= bo->size); in v3dv_bo_map_unsynchronized()
285 if (bo->map) in v3dv_bo_map_unsynchronized()
286 return bo->map; in v3dv_bo_map_unsynchronized()
290 map.handle = bo->handle; in v3dv_bo_map_unsynchronized()
291 int ret = v3d_ioctl(device->pdevice->render_fd, in v3dv_bo_map_unsynchronized()
298 bo->map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, in v3dv_bo_map_unsynchronized()
299 device->pdevice->render_fd, map.offset); in v3dv_bo_map_unsynchronized()
300 if (bo->map == MAP_FAILED) { in v3dv_bo_map_unsynchronized()
302 bo->handle, (long long)map.offset, (uint32_t)bo->size); in v3dv_bo_map_unsynchronized()
305 VG(VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, false)); in v3dv_bo_map_unsynchronized()
307 bo->map_size = size; in v3dv_bo_map_unsynchronized()
319 .handle = bo->handle, in v3dv_bo_wait()
322 return v3d_ioctl(device->pdevice->render_fd, in v3dv_bo_wait()
329 assert(bo && size <= bo->size); in v3dv_bo_map()
347 assert(bo && bo->map && bo->map_size > 0); in v3dv_bo_unmap()
349 munmap(bo->map, bo->map_size); in v3dv_bo_unmap()
350 VG(VALGRIND_FREELIKE_BLOCK(bo->map, 0)); in v3dv_bo_unmap()
351 bo->map = NULL; in v3dv_bo_unmap()
352 bo->map_size = 0; in v3dv_bo_unmap()
356 reallocate_size_list(struct v3dv_bo_cache *cache, in reallocate_size_list() argument
361 vk_alloc(&device->vk.alloc, sizeof(struct list_head) * size, 8, in reallocate_size_list()
365 mesa_loge("Failed to allocate host memory for cache bo list\n"); in reallocate_size_list()
368 struct list_head *old_list = cache->size_list; in reallocate_size_list()
373 for (int i = 0; i < cache->size_list_size; i++) { in reallocate_size_list()
374 struct list_head *old_head = &cache->size_list[i]; in reallocate_size_list()
378 new_list[i].next = old_head->next; in reallocate_size_list()
379 new_list[i].prev = old_head->prev; in reallocate_size_list()
380 new_list[i].next->prev = &new_list[i]; in reallocate_size_list()
381 new_list[i].prev->next = &new_list[i]; in reallocate_size_list()
384 for (int i = cache->size_list_size; i < size; i++) in reallocate_size_list()
387 cache->size_list = new_list; in reallocate_size_list()
388 cache->size_list_size = size; in reallocate_size_list()
389 vk_free(&device->vk.alloc, old_list); in reallocate_size_list()
397 device->bo_size = 0; in v3dv_bo_cache_init()
398 device->bo_count = 0; in v3dv_bo_cache_init()
399 list_inithead(&device->bo_cache.time_list); in v3dv_bo_cache_init()
400 /* FIXME: perhaps set a initial size for the size-list, to avoid run-time in v3dv_bo_cache_init()
403 device->bo_cache.size_list_size = 0; in v3dv_bo_cache_init()
407 device->bo_cache.max_cache_size = DEFAULT_MAX_BO_CACHE_SIZE; in v3dv_bo_cache_init()
409 device->bo_cache.max_cache_size = atoll(max_cache_size_str); in v3dv_bo_cache_init()
412 mesa_logi("MAX BO CACHE SIZE: %iMB\n", device->bo_cache.max_cache_size); in v3dv_bo_cache_init()
415 mtx_lock(&device->bo_cache.lock); in v3dv_bo_cache_init()
416 device->bo_cache.max_cache_size *= 1024 * 1024; in v3dv_bo_cache_init()
417 device->bo_cache.cache_count = 0; in v3dv_bo_cache_init()
418 device->bo_cache.cache_size = 0; in v3dv_bo_cache_init()
419 mtx_unlock(&device->bo_cache.lock); in v3dv_bo_cache_init()
426 vk_free(&device->vk.alloc, device->bo_cache.size_list); in v3dv_bo_cache_destroy()
439 struct v3dv_bo_cache *cache = &device->bo_cache; in free_stale_bos() local
442 list_for_each_entry_safe(struct v3dv_bo, bo, &cache->time_list, in free_stale_bos()
445 if (time - bo->free_time > 2) { in free_stale_bos()
452 bo_remove_from_cache(cache, bo); in free_stale_bos()
472 if (!p_atomic_dec_zero(&bo->refcnt)) in v3dv_bo_free()
475 if (bo->map) in v3dv_bo_free()
479 struct v3dv_bo_cache *cache = &device->bo_cache; in v3dv_bo_free() local
480 uint32_t page_index = bo->size / 4096 - 1; in v3dv_bo_free()
482 if (bo->private && in v3dv_bo_free()
483 bo->size > cache->max_cache_size - cache->cache_size) { in v3dv_bo_free()
485 mtx_lock(&cache->lock); in v3dv_bo_free()
487 mtx_unlock(&cache->lock); in v3dv_bo_free()
490 if (!bo->private || in v3dv_bo_free()
491 bo->size > cache->max_cache_size - cache->cache_size) { in v3dv_bo_free()
496 mtx_lock(&cache->lock); in v3dv_bo_free()
498 if (cache->size_list_size <= page_index) { in v3dv_bo_free()
499 if (!reallocate_size_list(cache, device, page_index + 1)) { in v3dv_bo_free()
502 * memory, so we also free all the bo cache. We need to call it to in v3dv_bo_free()
503 * not use the cache lock, as we are already under it. in v3dv_bo_free()
506 mtx_unlock(&cache->lock); in v3dv_bo_free()
511 bo->free_time = time.tv_sec; in v3dv_bo_free()
512 list_addtail(&bo->size_list, &cache->size_list[page_index]); in v3dv_bo_free()
513 list_addtail(&bo->time_list, &cache->time_list); in v3dv_bo_free()
515 cache->cache_count++; in v3dv_bo_free()
516 cache->cache_size += bo->size; in v3dv_bo_free()
519 mesa_logi("Freed %s %dkb to cache:\n", bo->name, bo->size / 1024); in v3dv_bo_free()
522 bo->name = NULL; in v3dv_bo_free()
526 mtx_unlock(&cache->lock); in v3dv_bo_free()