summaryrefslogtreecommitdiff
path: root/lib/mesa/src/gallium/auxiliary/pipebuffer
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2016-05-29 10:21:21 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2016-05-29 10:21:21 +0000
commit99b70277b7a71ca729b7723c0be213c9db46702c (patch)
tree756afa5d954f14d117bad3856a5eb9d5ab1b1a0d /lib/mesa/src/gallium/auxiliary/pipebuffer
parent3e40341f9dcd7c1bbc9afb8ddb812304820396cf (diff)
Import Mesa 11.2.2
Diffstat (limited to 'lib/mesa/src/gallium/auxiliary/pipebuffer')
-rw-r--r--lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.c100
-rw-r--r--lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.h14
2 files changed, 46 insertions, 68 deletions
diff --git a/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.c b/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.c
index 9b75ff0c1..ebd06b0e0 100644
--- a/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.c
+++ b/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.c
@@ -38,23 +38,22 @@ static void
destroy_buffer_locked(struct pb_cache_entry *entry)
{
struct pb_cache *mgr = entry->mgr;
- struct pb_buffer *buf = entry->buffer;
- assert(!pipe_is_referenced(&buf->reference));
+ assert(!pipe_is_referenced(&entry->buffer->reference));
if (entry->head.next) {
LIST_DEL(&entry->head);
assert(mgr->num_buffers);
--mgr->num_buffers;
- mgr->cache_size -= buf->size;
+ mgr->cache_size -= entry->buffer->size;
}
- mgr->destroy_buffer(buf);
+ entry->mgr->destroy_buffer(entry->buffer);
}
/**
* Free as many cache buffers from the list head as possible.
*/
static void
-release_expired_buffers_locked(struct list_head *cache)
+release_expired_buffers_locked(struct pb_cache *mgr)
{
struct list_head *curr, *next;
struct pb_cache_entry *entry;
@@ -62,9 +61,9 @@ release_expired_buffers_locked(struct list_head *cache)
now = os_time_get();
- curr = cache->next;
+ curr = mgr->cache.next;
next = curr->next;
- while (curr != cache) {
+ while (curr != &mgr->cache) {
entry = LIST_ENTRY(struct pb_cache_entry, curr, head);
if (!os_time_timeout(entry->start, entry->end, now))
@@ -85,29 +84,25 @@ void
pb_cache_add_buffer(struct pb_cache_entry *entry)
{
struct pb_cache *mgr = entry->mgr;
- struct list_head *cache = &mgr->buckets[entry->bucket_index];
- struct pb_buffer *buf = entry->buffer;
- unsigned i;
- mtx_lock(&mgr->mutex);
- assert(!pipe_is_referenced(&buf->reference));
+ pipe_mutex_lock(mgr->mutex);
+ assert(!pipe_is_referenced(&entry->buffer->reference));
- for (i = 0; i < ARRAY_SIZE(mgr->buckets); i++)
- release_expired_buffers_locked(&mgr->buckets[i]);
+ release_expired_buffers_locked(mgr);
/* Directly release any buffer that exceeds the limit. */
- if (mgr->cache_size + buf->size > mgr->max_cache_size) {
- mgr->destroy_buffer(buf);
- mtx_unlock(&mgr->mutex);
+ if (mgr->cache_size + entry->buffer->size > mgr->max_cache_size) {
+ entry->mgr->destroy_buffer(entry->buffer);
+ pipe_mutex_unlock(mgr->mutex);
return;
}
entry->start = os_time_get();
entry->end = entry->start + mgr->usecs;
- LIST_ADDTAIL(&entry->head, cache);
+ LIST_ADDTAIL(&entry->head, &mgr->cache);
++mgr->num_buffers;
- mgr->cache_size += buf->size;
- mtx_unlock(&mgr->mutex);
+ mgr->cache_size += entry->buffer->size;
+ pipe_mutex_unlock(mgr->mutex);
}
/**
@@ -119,24 +114,25 @@ static int
pb_cache_is_buffer_compat(struct pb_cache_entry *entry,
pb_size size, unsigned alignment, unsigned usage)
{
- struct pb_cache *mgr = entry->mgr;
struct pb_buffer *buf = entry->buffer;
- if (!pb_check_usage(usage, buf->usage))
+ if (usage & entry->mgr->bypass_usage)
return 0;
- /* be lenient with size */
- if (buf->size < size ||
- buf->size > (unsigned) (mgr->size_factor * size))
+ if (buf->size < size)
return 0;
- if (usage & mgr->bypass_usage)
+ /* be lenient with size */
+ if (buf->size > (unsigned) (entry->mgr->size_factor * size))
return 0;
if (!pb_check_alignment(alignment, buf->alignment))
return 0;
- return mgr->can_reclaim(buf) ? 1 : -1;
+ if (!pb_check_usage(usage, buf->usage))
+ return 0;
+
+ return entry->mgr->can_reclaim(buf) ? 1 : -1;
}
/**
@@ -145,25 +141,23 @@ pb_cache_is_buffer_compat(struct pb_cache_entry *entry,
*/
struct pb_buffer *
pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size,
- unsigned alignment, unsigned usage,
- unsigned bucket_index)
+ unsigned alignment, unsigned usage)
{
struct pb_cache_entry *entry;
struct pb_cache_entry *cur_entry;
struct list_head *cur, *next;
int64_t now;
int ret = 0;
- struct list_head *cache = &mgr->buckets[bucket_index];
- mtx_lock(&mgr->mutex);
+ pipe_mutex_lock(mgr->mutex);
entry = NULL;
- cur = cache->next;
+ cur = mgr->cache.next;
next = cur->next;
/* search in the expired buffers, freeing them in the process */
now = os_time_get();
- while (cur != cache) {
+ while (cur != &mgr->cache) {
cur_entry = LIST_ENTRY(struct pb_cache_entry, cur, head);
if (!entry && (ret = pb_cache_is_buffer_compat(cur_entry, size,
@@ -185,7 +179,7 @@ pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size,
/* keep searching in the hot buffers */
if (!entry && ret != -1) {
- while (cur != cache) {
+ while (cur != &mgr->cache) {
cur_entry = LIST_ENTRY(struct pb_cache_entry, cur, head);
ret = pb_cache_is_buffer_compat(cur_entry, size, alignment, usage);
@@ -208,13 +202,13 @@ pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size,
mgr->cache_size -= buf->size;
LIST_DEL(&entry->head);
--mgr->num_buffers;
- mtx_unlock(&mgr->mutex);
+ pipe_mutex_unlock(mgr->mutex);
/* Increase refcount */
pipe_reference_init(&buf->reference, 1);
return buf;
}
- mtx_unlock(&mgr->mutex);
+ pipe_mutex_unlock(mgr->mutex);
return NULL;
}
@@ -226,32 +220,26 @@ pb_cache_release_all_buffers(struct pb_cache *mgr)
{
struct list_head *curr, *next;
struct pb_cache_entry *buf;
- unsigned i;
- mtx_lock(&mgr->mutex);
- for (i = 0; i < ARRAY_SIZE(mgr->buckets); i++) {
- struct list_head *cache = &mgr->buckets[i];
-
- curr = cache->next;
+ pipe_mutex_lock(mgr->mutex);
+ curr = mgr->cache.next;
+ next = curr->next;
+ while (curr != &mgr->cache) {
+ buf = LIST_ENTRY(struct pb_cache_entry, curr, head);
+ destroy_buffer_locked(buf);
+ curr = next;
next = curr->next;
- while (curr != cache) {
- buf = LIST_ENTRY(struct pb_cache_entry, curr, head);
- destroy_buffer_locked(buf);
- curr = next;
- next = curr->next;
- }
}
- mtx_unlock(&mgr->mutex);
+ pipe_mutex_unlock(mgr->mutex);
}
void
pb_cache_init_entry(struct pb_cache *mgr, struct pb_cache_entry *entry,
- struct pb_buffer *buf, unsigned bucket_index)
+ struct pb_buffer *buf)
{
memset(entry, 0, sizeof(*entry));
entry->buffer = buf;
entry->mgr = mgr;
- entry->bucket_index = bucket_index;
}
/**
@@ -275,12 +263,8 @@ pb_cache_init(struct pb_cache *mgr, uint usecs, float size_factor,
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++)
- LIST_INITHEAD(&mgr->buckets[i]);
-
- (void) mtx_init(&mgr->mutex, mtx_plain);
+ LIST_INITHEAD(&mgr->cache);
+ pipe_mutex_init(mgr->mutex);
mgr->cache_size = 0;
mgr->max_cache_size = maximum_cache_size;
mgr->usecs = usecs;
@@ -298,5 +282,5 @@ void
pb_cache_deinit(struct pb_cache *mgr)
{
pb_cache_release_all_buffers(mgr);
- mtx_destroy(&mgr->mutex);
+ pipe_mutex_destroy(mgr->mutex);
}
diff --git a/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.h b/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.h
index d082eca8b..f0fa01226 100644
--- a/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.h
+++ b/lib/mesa/src/gallium/auxiliary/pipebuffer/pb_cache.h
@@ -42,17 +42,12 @@ struct pb_cache_entry
struct pb_buffer *buffer; /**< Pointer to the structure this is part of. */
struct pb_cache *mgr;
int64_t start, end; /**< Caching time interval */
- unsigned bucket_index;
};
struct pb_cache
{
- /* The cache is divided into buckets for minimizing cache misses.
- * The driver controls which buffer goes into which bucket.
- */
- struct list_head buckets[4];
-
- mtx_t mutex;
+ struct list_head cache;
+ pipe_mutex mutex;
uint64_t cache_size;
uint64_t max_cache_size;
unsigned usecs;
@@ -66,11 +61,10 @@ struct pb_cache
void pb_cache_add_buffer(struct pb_cache_entry *entry);
struct pb_buffer *pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size,
- unsigned alignment, unsigned usage,
- unsigned bucket_index);
+ unsigned alignment, unsigned 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);
+ struct pb_buffer *buf);
void pb_cache_init(struct pb_cache *mgr, uint usecs, float size_factor,
unsigned bypass_usage, uint64_t maximum_cache_size,
void (*destroy_buffer)(struct pb_buffer *buf),