-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path0002-draw-keep-some-unused-items-in-the-llvm-cache.patch
130 lines (110 loc) · 3.72 KB
/
0002-draw-keep-some-unused-items-in-the-llvm-cache.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
From 381cb9f9b19383f7a3e0397687458b4589abd9f0 Mon Sep 17 00:00:00 2001
From: Frank Henigman <[email protected]>
Date: Wed, 28 May 2014 20:25:12 -0700
Subject: [PATCH 02/13] 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 <[email protected]>
Signed-off-by: Frank Henigman <[email protected]>
---
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 8a95d2f..6887ee3 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 };
@@ -592,6 +594,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);
+ }
}
@@ -601,7 +609,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;
+ }
}
}
@@ -615,9 +637,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;
@@ -685,6 +711,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 38c30b6..9c36630 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -388,9 +388,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
@@ -409,6 +419,8 @@ struct llvm_cache_item
struct llvm_cache_key key;
unsigned ref_count;
+
+ struct llvm_cache_list_item list_item;
};
struct draw_llvm_variant
--
1.9.1