util/disk_cache: Add option to disable compression

The shader cache files produced by multi-file cache have a minimum size
limitation imposed by filesystem, usually it's 4KB. In order to make
cache tests suitable for a single file caches, we need to bypass the data
compression, making size of written out data determined for the eviction
testing.

The disk_cache_create() now checks whether driver_id name is set to
"make_check_uncompressed" in order to disable cache data compression.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16888>
This commit is contained in:
Dmitry Osipenko 2022-06-13 18:59:57 +03:00 committed by Marge Bot
parent 8e6bdb2ed3
commit 2a9b4ad177
3 changed files with 39 additions and 9 deletions

View file

@ -111,6 +111,13 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
if (cache->path == NULL)
goto path_fail;
/* Cache tests that want to have a disabled cache compression are using
* the "make_check_uncompressed" for the driver_id name. Hence here we
* disable disk cache compression when mesa's build tests require it.
*/
if (strcmp(driver_id, "make_check_uncompressed") == 0)
cache->compression_disabled = true;
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false)) {
if (!disk_cache_load_cache_index(local, cache))
goto path_fail;

View file

@ -550,10 +550,20 @@ parse_and_validate_cache_item(struct disk_cache *cache, void *cache_item,
/* Uncompress the cache data */
uncompressed_data = malloc(cf_data->uncompressed_size);
if (!util_compress_inflate(data, cache_data_size, uncompressed_data,
cf_data->uncompressed_size))
if (!uncompressed_data)
goto fail;
if (cache->compression_disabled) {
if (cf_data->uncompressed_size != cache_data_size)
goto fail;
memcpy(uncompressed_data, data, cache_data_size);
} else {
if (!util_compress_inflate(data, cache_data_size, uncompressed_data,
cf_data->uncompressed_size))
goto fail;
}
if (size)
*size = cf_data->uncompressed_size;
@ -638,15 +648,21 @@ create_cache_item_header_and_blob(struct disk_cache_put_job *dc_job,
/* Compress the cache item data */
size_t max_buf = util_compress_max_compressed_len(dc_job->size);
size_t compressed_size;
void *compressed_data = malloc(max_buf);
if (compressed_data == NULL)
return false;
size_t compressed_size =
util_compress_deflate(dc_job->data, dc_job->size,
compressed_data, max_buf);
if (compressed_size == 0)
goto fail;
if (dc_job->cache->compression_disabled) {
compressed_size = dc_job->size;
compressed_data = dc_job->data;
} else {
compressed_size =
util_compress_deflate(dc_job->data, dc_job->size,
compressed_data, max_buf);
if (compressed_size == 0)
goto fail;
}
/* Copy the driver_keys_blob, this can be used find information about the
* mesa version that produced the entry or deal with hash collisions,
@ -688,11 +704,15 @@ create_cache_item_header_and_blob(struct disk_cache_put_job *dc_job,
if (!blob_write_bytes(cache_blob, compressed_data, compressed_size))
goto fail;
free(compressed_data);
if (!dc_job->cache->compression_disabled)
free(compressed_data);
return true;
fail:
free(compressed_data);
if (!dc_job->cache->compression_disabled)
free(compressed_data);
return false;
}

View file

@ -75,6 +75,9 @@ struct disk_cache {
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 disk_cache_put_job {