mgr->base.create_buffer = pb_cache_manager_create_buffer;
mgr->base.flush = pb_cache_manager_flush;
mgr->provider = provider;
- pb_cache_init(&mgr->cache, usecs, size_factor, bypass_usage,
+ pb_cache_init(&mgr->cache, 1, usecs, size_factor, bypass_usage,
maximum_cache_size,
_pb_cache_buffer_destroy,
pb_cache_can_reclaim_buffer);
int64_t current_time = os_time_get();
- for (i = 0; i < ARRAY_SIZE(mgr->buckets); i++)
+ for (i = 0; i < mgr->num_heaps; i++)
release_expired_buffers_locked(&mgr->buckets[i], current_time);
/* Directly release any buffer that exceeds the limit. */
struct list_head *cur, *next;
int64_t now;
int ret = 0;
+
+ assert(bucket_index < mgr->num_heaps);
struct list_head *cache = &mgr->buckets[bucket_index];
mtx_lock(&mgr->mutex);
unsigned i;
mtx_lock(&mgr->mutex);
- for (i = 0; i < ARRAY_SIZE(mgr->buckets); i++) {
+ for (i = 0; i < mgr->num_heaps; i++) {
struct list_head *cache = &mgr->buckets[i];
curr = cache->next;
pb_cache_init_entry(struct pb_cache *mgr, struct pb_cache_entry *entry,
struct pb_buffer *buf, unsigned bucket_index)
{
+ assert(bucket_index < mgr->num_heaps);
+
memset(entry, 0, sizeof(*entry));
entry->buffer = buf;
entry->mgr = mgr;
* Initialize a caching buffer manager.
*
* @param mgr The cache buffer manager
+ * @param num_heaps Number of separate caches/buckets indexed by bucket_index
+ * for faster buffer matching (alternative to slower
+ * "usage"-based matching).
* @param usecs Unused buffers may be released from the cache after this
* time
* @param size_factor Declare buffers that are size_factor times bigger than
* @param can_reclaim Whether a buffer can be reclaimed (e.g. is not busy)
*/
void
-pb_cache_init(struct pb_cache *mgr, uint usecs, float size_factor,
+pb_cache_init(struct pb_cache *mgr, uint num_heaps,
+ uint usecs, float size_factor,
unsigned bypass_usage, uint64_t maximum_cache_size,
void (*destroy_buffer)(struct pb_buffer *buf),
bool (*can_reclaim)(struct pb_buffer *buf))
{
unsigned i;
- for (i = 0; i < ARRAY_SIZE(mgr->buckets); i++)
+ mgr->buckets = CALLOC(num_heaps, sizeof(struct list_head));
+ if (!mgr->buckets)
+ return;
+
+ for (i = 0; i < num_heaps; i++)
LIST_INITHEAD(&mgr->buckets[i]);
(void) mtx_init(&mgr->mutex, mtx_plain);
mgr->cache_size = 0;
mgr->max_cache_size = maximum_cache_size;
+ mgr->num_heaps = num_heaps;
mgr->usecs = usecs;
mgr->num_buffers = 0;
mgr->bypass_usage = bypass_usage;
{
pb_cache_release_all_buffers(mgr);
mtx_destroy(&mgr->mutex);
+ FREE(mgr->buckets);
+ mgr->buckets = NULL;
}
/* The cache is divided into buckets for minimizing cache misses.
* The driver controls which buffer goes into which bucket.
*/
- struct list_head buckets[4];
+ struct list_head *buckets;
mtx_t mutex;
uint64_t cache_size;
uint64_t max_cache_size;
+ unsigned num_heaps;
unsigned usecs;
unsigned num_buffers;
unsigned bypass_usage;
void pb_cache_release_all_buffers(struct pb_cache *mgr);
void pb_cache_init_entry(struct pb_cache *mgr, struct pb_cache_entry *entry,
struct pb_buffer *buf, unsigned bucket_index);
-void pb_cache_init(struct pb_cache *mgr, uint usecs, float size_factor,
+void pb_cache_init(struct pb_cache *mgr, uint num_heaps,
+ uint usecs, float size_factor,
unsigned bypass_usage, uint64_t maximum_cache_size,
void (*destroy_buffer)(struct pb_buffer *buf),
bool (*can_reclaim)(struct pb_buffer *buf));
usage = 1 << heap; /* Only set one usage bit for each heap. */
pb_cache_bucket = radeon_get_pb_cache_bucket_index(heap);
- assert(pb_cache_bucket < ARRAY_SIZE(ws->bo_cache.buckets));
/* Get a buffer from the cache. */
bo = (struct amdgpu_winsys_bo*)
goto fail_alloc;
/* Create managers. */
- pb_cache_init(&ws->bo_cache, 500000, ws->check_vm ? 1.0f : 2.0f, 0,
+ pb_cache_init(&ws->bo_cache, 4,
+ 500000, ws->check_vm ? 1.0f : 2.0f, 0,
(ws->info.vram_size + ws->info.gart_size) / 8,
amdgpu_bo_destroy, amdgpu_bo_can_reclaim);
usage = 1 << heap; /* Only set one usage bit for each heap. */
pb_cache_bucket = radeon_get_pb_cache_bucket_index(heap);
- assert(pb_cache_bucket < ARRAY_SIZE(ws->bo_cache.buckets));
bo = radeon_bo(pb_cache_reclaim_buffer(&ws->bo_cache, size, alignment,
usage, pb_cache_bucket));
if (!do_winsys_init(ws))
goto fail1;
- pb_cache_init(&ws->bo_cache, 500000, ws->check_vm ? 1.0f : 2.0f, 0,
+ pb_cache_init(&ws->bo_cache, 4,
+ 500000, ws->check_vm ? 1.0f : 2.0f, 0,
MIN2(ws->info.vram_size, ws->info.gart_size),
radeon_bo_destroy,
radeon_bo_can_reclaim);