blob: 6b44dea154860d74f6c7708cc74ee4059f71d905 [file] [log] [blame]
From c285de794e3ca6769373d94b54a39503a60b8e20 Mon Sep 17 00:00:00 2001
From: Frank Henigman <fjhenigman@chromium.org>
Date: Wed, 28 May 2014 20:25:12 -0700
Subject: [PATCH 11/24] draw: keep some unused items in the llvm cache
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cache items are small, maybe 10K on average, and take a relatively
long time to create, so it's worth keeping some unused ones around
in case they are needed again.
When an upper limit is reached, delete the one that has been unused
the longest.
Change-Id: I9cdfb9d0de44ff0c3d9038259a172a7111becfe1
Signed-off-by: Stéphane Marchesin <marcheu@chromium.org>
Signed-off-by: Frank Henigman <fjhenigman@chromium.org>
---
src/gallium/auxiliary/draw/draw_llvm.c | 32 ++++++++++++++++++++++++++++++--
src/gallium/auxiliary/draw/draw_llvm.h | 12 ++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index cf4accfb8825..acc3de0582e6 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -62,6 +62,8 @@
#define DEBUG_STORE 0
+#define LLVM_CACHE_MAX_UNUSED 100
+
static struct llvm_cache llvm_cache = { NULL };
@@ -596,6 +598,12 @@ static void
llvm_cache_item_ref(struct llvm_cache_item *item)
{
++item->ref_count;
+ if (item->ref_count == 1) {
+ --llvm_cache.num_unused;
+
+ /* Previously unused item has come into use. Remove from unused list. */
+ remove_from_list(&item->list_item);
+ }
}
@@ -605,7 +613,21 @@ llvm_cache_item_unref(struct llvm_cache_item *item)
assert(item->ref_count > 0);
--item->ref_count;
if (item->ref_count == 0) {
- llvm_cache_item_destroy(item);
+ ++llvm_cache.num_unused;
+
+ /* Item went out of use. Insert at head of unused list. */
+ insert_at_head(&llvm_cache.unused, &item->list_item);
+
+ /* If now too many unused items in cache, get rid of oldest one. */
+ if (llvm_cache.num_unused > LLVM_CACHE_MAX_UNUSED) {
+ struct llvm_cache_list_item *discard = last_elem(&llvm_cache.unused);
+ assert(discard);
+ assert(discard->base);
+ remove_from_list(&discard->base->list_item);
+ util_hash_table_remove(llvm_cache.ht, &discard->base->key);
+ llvm_cache_item_destroy(discard->base);
+ --llvm_cache.num_unused;
+ }
}
}
@@ -619,9 +641,13 @@ llvm_cache_item_get(struct draw_llvm_variant *variant, unsigned num_inputs)
struct llvm_cache_item *item;
struct llvm_cache_key key;
- if (!llvm_cache.ht)
+ if (!llvm_cache.ht) {
llvm_cache.ht = util_hash_table_create(&llvm_cache_key_hash,
&llvm_cache_key_compare);
+ make_empty_list(&llvm_cache.unused);
+ llvm_cache.num_unused = 0;
+ }
+
if (!llvm_cache.ht)
return NULL;
@@ -689,6 +715,8 @@ llvm_cache_item_create(struct draw_llvm_variant *variant,
memcpy(&item->key, key, sizeof(*key));
+ item->list_item.base = item;
+
return item;
}
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 8e0033e8fe73..df33423855cc 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -389,9 +389,19 @@ struct draw_gs_llvm_variant_list_item
};
+struct llvm_cache_list_item
+{
+ struct llvm_cache_item *base;
+ struct llvm_cache_list_item *next, *prev;
+};
+
struct llvm_cache
{
struct util_hash_table *ht;
+
+ /* list of currently unused items in LRU order */
+ struct llvm_cache_list_item unused;
+ unsigned num_unused;
};
struct llvm_cache_key
@@ -410,6 +420,8 @@ struct llvm_cache_item
struct llvm_cache_key key;
unsigned ref_count;
+
+ struct llvm_cache_list_item list_item;
};
struct draw_llvm_variant
--
2.5.1