+ /* 4 threads were chosen below because just about all modern CPUs currently
+ * available that run Mesa have *at least* 4 cores. For these CPUs allowing
+ * more threads can result in the queue being processed faster, thus
+ * avoiding excessive memory use due to a backlog of cache entrys building
+ * up in the queue. Since we set the UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY
+ * flag this should have little negative impact on low core systems.
+ *
+ * The queue will resize automatically when it's full, so adding new jobs
+ * doesn't stall.
+ */
+ util_queue_init(&cache->cache_queue, "disk$", 32, 4,
+ UTIL_QUEUE_INIT_RESIZE_IF_FULL |
+ UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY |
+ UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY);
+
+ cache->path_init_failed = false;
+
+ path_fail:
+
+ if (fd != -1)
+ close(fd);
+
+ cache->driver_keys_blob_size = cv_size;
+
+ /* Create driver id keys */
+ size_t id_size = strlen(driver_id) + 1;
+ size_t gpu_name_size = strlen(gpu_name) + 1;
+ cache->driver_keys_blob_size += id_size;
+ cache->driver_keys_blob_size += gpu_name_size;
+
+ /* We sometimes store entire structs that contains a pointers in the cache,
+ * use pointer size as a key to avoid hard to debug issues.
+ */
+ uint8_t ptr_size = sizeof(void *);
+ size_t ptr_size_size = sizeof(ptr_size);
+ cache->driver_keys_blob_size += ptr_size_size;
+
+ size_t driver_flags_size = sizeof(driver_flags);
+ cache->driver_keys_blob_size += driver_flags_size;
+
+ cache->driver_keys_blob =
+ ralloc_size(cache, cache->driver_keys_blob_size);
+ if (!cache->driver_keys_blob)
+ goto fail;
+
+ uint8_t *drv_key_blob = cache->driver_keys_blob;
+ DRV_KEY_CPY(drv_key_blob, &cache_version, cv_size)
+ DRV_KEY_CPY(drv_key_blob, driver_id, id_size)
+ DRV_KEY_CPY(drv_key_blob, gpu_name, gpu_name_size)
+ DRV_KEY_CPY(drv_key_blob, &ptr_size, ptr_size_size)
+ DRV_KEY_CPY(drv_key_blob, &driver_flags, driver_flags_size)
+
+ /* Seed our rand function */
+ s_rand_xorshift128plus(cache->seed_xorshift128plus, true);
+