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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
* Copyright © 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef DISK_CACHE_OS_H
#define DISK_CACHE_OS_H
#include "util/u_queue.h"
#if DETECT_OS_WINDOWS
/* TODO: implement disk cache support on windows */
#else
#include "util/fossilize_db.h"
#include "util/mesa_cache_db.h"
#include "util/mesa_cache_db_multipart.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Number of bits to mask off from a cache key to get an index. */
#define CACHE_INDEX_KEY_BITS 16
/* Mask for computing an index from a key. */
#define CACHE_INDEX_KEY_MASK ((1 << CACHE_INDEX_KEY_BITS) - 1)
/* The number of keys that can be stored in the index. */
#define CACHE_INDEX_MAX_KEYS (1 << CACHE_INDEX_KEY_BITS)
enum disk_cache_type {
DISK_CACHE_NONE,
DISK_CACHE_MULTI_FILE,
DISK_CACHE_SINGLE_FILE,
DISK_CACHE_DATABASE,
};
struct disk_cache {
/* The path to the cache directory. */
char *path;
bool path_init_failed;
/* Thread queue for compressing and writing cache entries to disk */
struct util_queue cache_queue;
struct foz_db foz_db;
struct mesa_cache_db_multipart cache_db;
enum disk_cache_type type;
/* Seed for rand, which is used to pick a random directory */
uint64_t seed_xorshift128plus[2];
/* A pointer to the mmapped index file within the cache directory. */
uint8_t *index_mmap;
size_t index_mmap_size;
/* Pointer to total size of all objects in cache (within index_mmap) */
p_atomic_uint64_t *size;
/* Pointer to stored keys, (within index_mmap). */
uint8_t *stored_keys;
/* Maximum size of all cached objects (in bytes). */
uint64_t max_size;
/* Driver cache keys. */
uint8_t *driver_keys_blob;
size_t driver_keys_blob_size;
disk_cache_put_cb blob_put_cb;
disk_cache_get_cb blob_get_cb;
/* Don't compress cached data. This is for testing purposes only. */
bool compression_disabled;
struct {
bool enabled;
unsigned hits;
unsigned misses;
} stats;
/* Internal RO FOZ cache for combined use of RO and RW caches. */
struct disk_cache *foz_ro_cache;
};
struct cache_entry_file_data {
uint32_t crc32;
uint32_t uncompressed_size;
};
struct disk_cache_put_job {
struct util_queue_fence fence;
struct disk_cache *cache;
cache_key key;
/* Copy of cache data to be compressed and written. */
void *data;
/* Size of data to be compressed and written. */
size_t size;
struct cache_item_metadata cache_item_metadata;
};
char *
disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name,
const char *driver_id,
enum disk_cache_type cache_type);
void
disk_cache_evict_lru_item(struct disk_cache *cache);
void
disk_cache_evict_item(struct disk_cache *cache, char *filename);
void *
disk_cache_load_item_foz(struct disk_cache *cache, const cache_key key,
size_t *size);
void *
disk_cache_load_item(struct disk_cache *cache, char *filename, size_t *size);
char *
disk_cache_get_cache_filename(struct disk_cache *cache, const cache_key key);
bool
disk_cache_write_item_to_disk_foz(struct disk_cache_put_job *dc_job);
void
disk_cache_write_item_to_disk(struct disk_cache_put_job *dc_job,
char *filename);
bool
disk_cache_enabled(void);
bool
disk_cache_load_cache_index_foz(void *mem_ctx, struct disk_cache *cache);
bool
disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache,
char *path);
void
disk_cache_destroy_mmap(struct disk_cache *cache);
void *
disk_cache_db_load_item(struct disk_cache *cache, const cache_key key,
size_t *size);
bool
disk_cache_db_write_item_to_disk(struct disk_cache_put_job *dc_job);
bool
disk_cache_db_load_cache_index(void *mem_ctx, struct disk_cache *cache);
#ifdef __cplusplus
}
#endif
#endif
#endif /* DISK_CACHE_OS_H */
|