#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
#include "util/u_thread.h"
+#include "util/os_time.h"
#include <inttypes.h>
/**
return *out_buffer != NULL;
}
+static unsigned L3_cache_number;
+static once_flag init_cache_number_flag = ONCE_FLAG_INIT;
+
+static void
+util_init_cache_number(void)
+{
+ /* Get a semi-random number. */
+ int64_t t = os_time_get_nano();
+ L3_cache_number = (t ^ (t >> 8) ^ (t >> 16));
+}
+
/**
* Called by MakeCurrent. Used to notify the driver that the application
* thread may have been changed.
/* If the main thread is not pinned, choose the L3 cache. */
if (cache == -1) {
- unsigned num_caches = util_cpu_caps.nr_cpus /
- util_cpu_caps.cores_per_L3;
- static unsigned last_cache;
+ unsigned num_L3_caches = util_cpu_caps.nr_cpus /
+ util_cpu_caps.cores_per_L3;
/* Choose a different L3 cache for each subsequent MakeCurrent. */
- cache = p_atomic_inc_return(&last_cache) % num_caches;
+ call_once(&init_cache_number_flag, util_init_cache_number);
+ cache = p_atomic_inc_return(&L3_cache_number) % num_L3_caches;
util_pin_thread_to_L3(current, cache, util_cpu_caps.cores_per_L3);
}