[Mesa-dev] [PATCH] util/disk_cache: don't require 64bit atomic operations

Grazvydas Ignotas notasas at gmail.com
Sun Mar 5 19:14:07 UTC 2017


There are still some distributions trying to support unfortunate people
with old or exotic CPUs that don't have 64bit atomic operations. Missing
64bit atomic ops can be detected at compile time, so provide a 32bit
fallback and add an appropriate cache size limit ceiling for that case.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93089
Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
---
no commit access

 src/util/disk_cache.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 4a8ee21..daa5c7b 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -37,6 +37,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <dirent.h>
+#include <limits.h>
 #include "zlib.h"
 
 #include "util/crc32.h"
@@ -56,6 +57,11 @@
 /* The number of keys that can be stored in the index. */
 #define CACHE_INDEX_MAX_KEYS (1 << CACHE_INDEX_KEY_BITS)
 
+/* limit maximum cache size on platforms that lack atomic 64bit operations */
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#define CACHE_SIZE_32BIT_LIMITED
+#endif
+
 struct disk_cache {
    /* The path to the cache directory. */
    char *path;
@@ -65,7 +71,11 @@ struct disk_cache {
    size_t index_mmap_size;
 
    /* Pointer to total size of all objects in cache (within index_mmap) */
+#ifndef CACHE_SIZE_32BIT_LIMITED
    uint64_t *size;
+#else
+   uint32_t *size;
+#endif
 
    /* Pointer to stored keys, (within index_mmap). */
    uint8_t *stored_keys;
@@ -363,7 +373,7 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
 
    close(fd);
 
-   cache->size = (uint64_t *) cache->index_mmap;
+   cache->size = (void *) cache->index_mmap;
    cache->stored_keys = cache->index_mmap + sizeof(uint64_t);
 
    max_size = 0;
@@ -398,6 +408,11 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
    if (max_size == 0)
       max_size = 1024*1024*1024;
 
+#ifdef CACHE_SIZE_32BIT_LIMITED
+   if (max_size > UINT_MAX - 1024*1024)
+      max_size = UINT_MAX - 1024*1024;
+#endif
+
    cache->max_size = max_size;
 
    ralloc_free(local);
-- 
2.7.4



More information about the mesa-dev mailing list