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()
121 bo->name = name; in bo_from_cache()
123 mtx_unlock(&cache->lock); in bo_from_cache()
134 if (bo->map) 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()
155 vk_free(&device->vk.alloc, bo); in bo_free()
164 struct v3dv_bo_cache *cache = &device->bo_cache; in bo_cache_free_all() local
167 mtx_lock(&cache->lock); in bo_cache_free_all()
168 list_for_each_entry_safe(struct v3dv_bo, bo, &cache->time_list, in bo_cache_free_all()
170 bo_remove_from_cache(cache, bo); in bo_cache_free_all()
174 mtx_unlock(&cache->lock); in bo_cache_free_all()
183 const char *name, in v3dv_bo_init() argument
186 bo->handle = handle; in v3dv_bo_init()
187 bo->handle_bit = 1ull << (handle % 64); in v3dv_bo_init()
188 bo->size = size; in v3dv_bo_init()
189 bo->offset = offset; in v3dv_bo_init()
190 bo->map = NULL; in v3dv_bo_init()
191 bo->map_size = 0; in v3dv_bo_init()
192 bo->name = name; in v3dv_bo_init()
193 bo->private = private; in v3dv_bo_init()
194 bo->dumb_handle = -1; in v3dv_bo_init()
195 list_inithead(&bo->list_link); in v3dv_bo_init()
201 const char *name, in v3dv_bo_alloc() argument
210 bo = bo_from_cache(device, size, name); in v3dv_bo_alloc()
213 fprintf(stderr, "Allocated %s %dkb from cache:\n", in v3dv_bo_alloc()
214 name, size / 1024); in v3dv_bo_alloc()
221 bo = vk_alloc(&device->vk.alloc, sizeof(struct v3dv_bo), 8, in v3dv_bo_alloc()
237 int ret = v3dv_ioctl(device->pdevice->render_fd, in v3dv_bo_alloc()
240 if (!list_is_empty(&device->bo_cache.time_list) && in v3dv_bo_alloc()
247 vk_free(&device->vk.alloc, bo); in v3dv_bo_alloc()
255 v3dv_bo_init(bo, create.handle, size, create.offset, name, private); in v3dv_bo_alloc()
257 device->bo_count++; in v3dv_bo_alloc()
258 device->bo_size += bo->size; in v3dv_bo_alloc()
260 fprintf(stderr, "Allocated %s %dkb:\n", name, size / 1024); in v3dv_bo_alloc()
272 assert(bo != NULL && size <= bo->size); in v3dv_bo_map_unsynchronized()
274 if (bo->map) in v3dv_bo_map_unsynchronized()
275 return bo->map; in v3dv_bo_map_unsynchronized()
279 map.handle = bo->handle; in v3dv_bo_map_unsynchronized()
280 int ret = v3dv_ioctl(device->pdevice->render_fd, in v3dv_bo_map_unsynchronized()
287 bo->map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, in v3dv_bo_map_unsynchronized()
288 device->pdevice->render_fd, map.offset); in v3dv_bo_map_unsynchronized()
289 if (bo->map == MAP_FAILED) { in v3dv_bo_map_unsynchronized()
291 bo->handle, (long long)map.offset, (uint32_t)bo->size); in v3dv_bo_map_unsynchronized()
294 VG(VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, false)); in v3dv_bo_map_unsynchronized()
296 bo->map_size = size; in v3dv_bo_map_unsynchronized()
307 .handle = bo->handle, in v3dv_bo_wait()
310 return v3dv_ioctl(device->pdevice->render_fd, in v3dv_bo_wait()
317 assert(bo && size <= bo->size); in v3dv_bo_map()
335 assert(bo && bo->map && bo->map_size > 0); in v3dv_bo_unmap()
337 munmap(bo->map, bo->map_size); in v3dv_bo_unmap()
338 VG(VALGRIND_FREELIKE_BLOCK(bo->map, 0)); in v3dv_bo_unmap()
339 bo->map = NULL; in v3dv_bo_unmap()
340 bo->map_size = 0; in v3dv_bo_unmap()
344 reallocate_size_list(struct v3dv_bo_cache *cache, in reallocate_size_list() argument
349 vk_alloc(&device->vk.alloc, sizeof(struct list_head) * size, 8, in reallocate_size_list()
353 fprintf(stderr, "Failed to allocate host memory for cache bo list\n"); in reallocate_size_list()
356 struct list_head *old_list = cache->size_list; in reallocate_size_list()
361 for (int i = 0; i < cache->size_list_size; i++) { in reallocate_size_list()
362 struct list_head *old_head = &cache->size_list[i]; in reallocate_size_list()
366 new_list[i].next = old_head->next; in reallocate_size_list()
367 new_list[i].prev = old_head->prev; in reallocate_size_list()
368 new_list[i].next->prev = &new_list[i]; in reallocate_size_list()
369 new_list[i].prev->next = &new_list[i]; in reallocate_size_list()
372 for (int i = cache->size_list_size; i < size; i++) in reallocate_size_list()
375 cache->size_list = new_list; in reallocate_size_list()
376 cache->size_list_size = size; in reallocate_size_list()
377 vk_free(&device->vk.alloc, old_list); in reallocate_size_list()
385 device->bo_size = 0; in v3dv_bo_cache_init()
386 device->bo_count = 0; in v3dv_bo_cache_init()
387 list_inithead(&device->bo_cache.time_list); in v3dv_bo_cache_init()
388 /* FIXME: perhaps set a initial size for the size-list, to avoid run-time in v3dv_bo_cache_init()
391 device->bo_cache.size_list_size = 0; in v3dv_bo_cache_init()
395 device->bo_cache.max_cache_size = DEFAULT_MAX_BO_CACHE_SIZE; in v3dv_bo_cache_init()
397 device->bo_cache.max_cache_size = atoll(max_cache_size_str); in v3dv_bo_cache_init()
400 fprintf(stderr, "MAX BO CACHE SIZE: %iMB\n", device->bo_cache.max_cache_size); in v3dv_bo_cache_init()
403 device->bo_cache.max_cache_size *= 1024 * 1024; in v3dv_bo_cache_init()
404 device->bo_cache.cache_count = 0; in v3dv_bo_cache_init()
405 device->bo_cache.cache_size = 0; in v3dv_bo_cache_init()
412 vk_free(&device->vk.alloc, device->bo_cache.size_list); in v3dv_bo_cache_destroy()
425 struct v3dv_bo_cache *cache = &device->bo_cache; in free_stale_bos() local
428 list_for_each_entry_safe(struct v3dv_bo, bo, &cache->time_list, in free_stale_bos()
431 if (time - bo->free_time > 2) { in free_stale_bos()
438 bo_remove_from_cache(cache, bo); in free_stale_bos()
459 struct v3dv_bo_cache *cache = &device->bo_cache; in v3dv_bo_free() local
460 uint32_t page_index = bo->size / 4096 - 1; in v3dv_bo_free()
462 if (bo->private && in v3dv_bo_free()
463 bo->size > cache->max_cache_size - cache->cache_size) { in v3dv_bo_free()
465 mtx_lock(&cache->lock); in v3dv_bo_free()
467 mtx_unlock(&cache->lock); in v3dv_bo_free()
470 if (!bo->private || in v3dv_bo_free()
471 bo->size > cache->max_cache_size - cache->cache_size) { in v3dv_bo_free()
476 mtx_lock(&cache->lock); in v3dv_bo_free()
478 if (cache->size_list_size <= page_index) { in v3dv_bo_free()
479 if (!reallocate_size_list(cache, device, page_index + 1)) { in v3dv_bo_free()
482 * memory, so we also free all the bo cache. We need to call it to in v3dv_bo_free()
483 * not use the cache lock, as we are already under it. in v3dv_bo_free()
486 mtx_unlock(&cache->lock); in v3dv_bo_free()
491 bo->free_time = time.tv_sec; in v3dv_bo_free()
492 list_addtail(&bo->size_list, &cache->size_list[page_index]); in v3dv_bo_free()
493 list_addtail(&bo->time_list, &cache->time_list); in v3dv_bo_free()
495 cache->cache_count++; in v3dv_bo_free()
496 cache->cache_size += bo->size; in v3dv_bo_free()
499 fprintf(stderr, "Freed %s %dkb to cache:\n", in v3dv_bo_free()
500 bo->name, bo->size / 1024); in v3dv_bo_free()
503 bo->name = NULL; in v3dv_bo_free()
507 mtx_unlock(&cache->lock); in v3dv_bo_free()