• Home
  • Raw
  • Download

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

29 #include "drm-uapi/v3d_drm.h"
32 /* Default max size of the bo cache, in MB.
40 /* Discarded to use a V3D_DEBUG for this, as it would mean adding a run-time
48 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_dump_stats() local
50 fprintf(stderr, " BOs allocated: %d\n", device->bo_count); in bo_dump_stats()
51 fprintf(stderr, " BOs size: %dkb\n", device->bo_size / 1024); in bo_dump_stats()
52 fprintf(stderr, " BOs cached: %d\n", cache->cache_count); in bo_dump_stats()
53 fprintf(stderr, " BOs cached size: %dkb\n", cache->cache_size / 1024); in bo_dump_stats()
55 if (!list_is_empty(&cache->time_list)) { in bo_dump_stats()
56 struct v3dv_bo *first = list_first_entry(&cache->time_list, in bo_dump_stats()
59 struct v3dv_bo *last = list_last_entry(&cache->time_list, in bo_dump_stats()
63 fprintf(stderr, " oldest cache time: %ld\n", in bo_dump_stats()
64 (long)first->free_time); in bo_dump_stats()
65 fprintf(stderr, " newest cache time: %ld\n", in bo_dump_stats()
66 (long)last->free_time); in bo_dump_stats()
74 if (cache->size_list_size) { in bo_dump_stats()
76 for (uint32_t i = 0; i < cache->size_list_size; i++) { in bo_dump_stats()
77 if (list_is_empty(&cache->size_list[i])) in bo_dump_stats()
85 bo_remove_from_cache(struct v3dv_bo_cache *cache, struct v3dv_bo *bo) in bo_remove_from_cache() argument
87 list_del(&bo->time_list); in bo_remove_from_cache()
88 list_del(&bo->size_list); in bo_remove_from_cache()
90 cache->cache_count--; in bo_remove_from_cache()
91 cache->cache_size -= bo->size; in bo_remove_from_cache()
95 bo_from_cache(struct v3dv_device *device, uint32_t size, const char *name) in bo_from_cache() argument
97 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_from_cache() local
98 uint32_t page_index = size / 4096 - 1; in bo_from_cache()
100 if (cache->size_list_size <= page_index) in bo_from_cache()
105 mtx_lock(&cache->lock); in bo_from_cache()
106 if (!list_is_empty(&cache->size_list[page_index])) { in bo_from_cache()
107 bo = list_first_entry(&cache->size_list[page_index], in bo_from_cache()
115 mtx_unlock(&cache->lock); in bo_from_cache()
119 bo_remove_from_cache(cache, bo); in bo_from_cache()
120 bo->name = name; in bo_from_cache()
121 p_atomic_set(&bo->refcnt, 1); in bo_from_cache()
123 mtx_unlock(&cache->lock); in bo_from_cache()
134 assert(p_atomic_read(&bo->refcnt) == 0); in bo_free()
135 assert(bo->map == NULL); in bo_free()
139 c.handle = bo->handle; in bo_free()
140 int ret = v3dv_ioctl(device->pdevice->render_fd, DRM_IOCTL_GEM_CLOSE, &c); in bo_free()
142 fprintf(stderr, "close object %d: %s\n", bo->handle, strerror(errno)); in bo_free()
144 device->bo_count--; in bo_free()
145 device->bo_size -= bo->size; in bo_free()
149 bo->name ? bo->name : "", in bo_free()
150 bo->name ? " " : "", in bo_free()
151 bo->size / 1024); in bo_free()
168 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_cache_free_all() local
171 mtx_lock(&cache->lock); in bo_cache_free_all()
172 list_for_each_entry_safe(struct v3dv_bo, bo, &cache->time_list, in bo_cache_free_all()
174 bo_remove_from_cache(cache, bo); in bo_cache_free_all()
178 mtx_unlock(&cache->lock); in bo_cache_free_all()
187 const char *name, in v3dv_bo_init() argument
190 p_atomic_set(&bo->refcnt, 1); in v3dv_bo_init()
191 bo->handle = handle; in v3dv_bo_init()
192 bo->handle_bit = 1ull << (handle % 64); in v3dv_bo_init()
193 bo->size = size; in v3dv_bo_init()
194 bo->offset = offset; in v3dv_bo_init()
195 bo->map = NULL; in v3dv_bo_init()
196 bo->map_size = 0; in v3dv_bo_init()
197 bo->name = name; in v3dv_bo_init()
198 bo->private = private; in v3dv_bo_init()
199 bo->dumb_handle = -1; in v3dv_bo_init()
200 list_inithead(&bo->list_link); in v3dv_bo_init()
206 const char *name, in v3dv_bo_alloc() argument
215 bo = bo_from_cache(device, size, name); in v3dv_bo_alloc()
218 fprintf(stderr, "Allocated %s %dkb from cache:\n", in v3dv_bo_alloc()
219 name, size / 1024); in v3dv_bo_alloc()
234 int ret = v3dv_ioctl(device->pdevice->render_fd, in v3dv_bo_alloc()
237 if (!list_is_empty(&device->bo_cache.time_list) && in v3dv_bo_alloc()
251 bo = v3dv_device_lookup_bo(device->pdevice, create.handle); in v3dv_bo_alloc()
252 assert(bo && bo->handle == 0); in v3dv_bo_alloc()
254 v3dv_bo_init(bo, create.handle, size, create.offset, name, private); in v3dv_bo_alloc()
256 device->bo_count++; in v3dv_bo_alloc()
257 device->bo_size += bo->size; in v3dv_bo_alloc()
259 fprintf(stderr, "Allocated %s %dkb:\n", name, size / 1024); in v3dv_bo_alloc()
271 assert(bo != NULL && size <= bo->size); in v3dv_bo_map_unsynchronized()
273 if (bo->map) in v3dv_bo_map_unsynchronized()
274 return bo->map; in v3dv_bo_map_unsynchronized()
278 map.handle = bo->handle; in v3dv_bo_map_unsynchronized()
279 int ret = v3dv_ioctl(device->pdevice->render_fd, in v3dv_bo_map_unsynchronized()
286 bo->map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, in v3dv_bo_map_unsynchronized()
287 device->pdevice->render_fd, map.offset); in v3dv_bo_map_unsynchronized()
288 if (bo->map == MAP_FAILED) { in v3dv_bo_map_unsynchronized()
290 bo->handle, (long long)map.offset, (uint32_t)bo->size); in v3dv_bo_map_unsynchronized()
293 VG(VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, false)); in v3dv_bo_map_unsynchronized()
295 bo->map_size = size; in v3dv_bo_map_unsynchronized()
306 .handle = bo->handle, in v3dv_bo_wait()
309 return v3dv_ioctl(device->pdevice->render_fd, in v3dv_bo_wait()
316 assert(bo && size <= bo->size); in v3dv_bo_map()
334 assert(bo && bo->map && bo->map_size > 0); in v3dv_bo_unmap()
336 munmap(bo->map, bo->map_size); in v3dv_bo_unmap()
337 VG(VALGRIND_FREELIKE_BLOCK(bo->map, 0)); in v3dv_bo_unmap()
338 bo->map = NULL; in v3dv_bo_unmap()
339 bo->map_size = 0; in v3dv_bo_unmap()
343 reallocate_size_list(struct v3dv_bo_cache *cache, in reallocate_size_list() argument
348 vk_alloc(&device->vk.alloc, sizeof(struct list_head) * size, 8, in reallocate_size_list()
352 fprintf(stderr, "Failed to allocate host memory for cache bo list\n"); in reallocate_size_list()
355 struct list_head *old_list = cache->size_list; in reallocate_size_list()
360 for (int i = 0; i < cache->size_list_size; i++) { in reallocate_size_list()
361 struct list_head *old_head = &cache->size_list[i]; in reallocate_size_list()
365 new_list[i].next = old_head->next; in reallocate_size_list()
366 new_list[i].prev = old_head->prev; in reallocate_size_list()
367 new_list[i].next->prev = &new_list[i]; in reallocate_size_list()
368 new_list[i].prev->next = &new_list[i]; in reallocate_size_list()
371 for (int i = cache->size_list_size; i < size; i++) in reallocate_size_list()
374 cache->size_list = new_list; in reallocate_size_list()
375 cache->size_list_size = size; in reallocate_size_list()
376 vk_free(&device->vk.alloc, old_list); in reallocate_size_list()
384 device->bo_size = 0; in v3dv_bo_cache_init()
385 device->bo_count = 0; in v3dv_bo_cache_init()
386 list_inithead(&device->bo_cache.time_list); in v3dv_bo_cache_init()
387 /* FIXME: perhaps set a initial size for the size-list, to avoid run-time in v3dv_bo_cache_init()
390 device->bo_cache.size_list_size = 0; in v3dv_bo_cache_init()
394 device->bo_cache.max_cache_size = DEFAULT_MAX_BO_CACHE_SIZE; in v3dv_bo_cache_init()
396 device->bo_cache.max_cache_size = atoll(max_cache_size_str); in v3dv_bo_cache_init()
399 fprintf(stderr, "MAX BO CACHE SIZE: %iMB\n", device->bo_cache.max_cache_size); in v3dv_bo_cache_init()
402 device->bo_cache.max_cache_size *= 1024 * 1024; in v3dv_bo_cache_init()
403 device->bo_cache.cache_count = 0; in v3dv_bo_cache_init()
404 device->bo_cache.cache_size = 0; in v3dv_bo_cache_init()
411 vk_free(&device->vk.alloc, device->bo_cache.size_list); in v3dv_bo_cache_destroy()
424 struct v3dv_bo_cache *cache = &device->bo_cache; in free_stale_bos() local
427 list_for_each_entry_safe(struct v3dv_bo, bo, &cache->time_list, in free_stale_bos()
430 if (time - bo->free_time > 2) { in free_stale_bos()
437 bo_remove_from_cache(cache, bo); in free_stale_bos()
457 if (!p_atomic_dec_zero(&bo->refcnt)) in v3dv_bo_free()
460 if (bo->map) in v3dv_bo_free()
464 struct v3dv_bo_cache *cache = &device->bo_cache; in v3dv_bo_free() local
465 uint32_t page_index = bo->size / 4096 - 1; in v3dv_bo_free()
467 if (bo->private && in v3dv_bo_free()
468 bo->size > cache->max_cache_size - cache->cache_size) { in v3dv_bo_free()
470 mtx_lock(&cache->lock); in v3dv_bo_free()
472 mtx_unlock(&cache->lock); in v3dv_bo_free()
475 if (!bo->private || in v3dv_bo_free()
476 bo->size > cache->max_cache_size - cache->cache_size) { in v3dv_bo_free()
481 mtx_lock(&cache->lock); in v3dv_bo_free()
483 if (cache->size_list_size <= page_index) { in v3dv_bo_free()
484 if (!reallocate_size_list(cache, device, page_index + 1)) { in v3dv_bo_free()
487 * memory, so we also free all the bo cache. We need to call it to in v3dv_bo_free()
488 * not use the cache lock, as we are already under it. in v3dv_bo_free()
491 mtx_unlock(&cache->lock); in v3dv_bo_free()
496 bo->free_time = time.tv_sec; in v3dv_bo_free()
497 list_addtail(&bo->size_list, &cache->size_list[page_index]); in v3dv_bo_free()
498 list_addtail(&bo->time_list, &cache->time_list); in v3dv_bo_free()
500 cache->cache_count++; in v3dv_bo_free()
501 cache->cache_size += bo->size; in v3dv_bo_free()
504 fprintf(stderr, "Freed %s %dkb to cache:\n", in v3dv_bo_free()
505 bo->name, bo->size / 1024); in v3dv_bo_free()
508 bo->name = NULL; in v3dv_bo_free()
512 mtx_unlock(&cache->lock); in v3dv_bo_free()