From: Marek Olšák Date: Fri, 7 Sep 2018 19:37:45 +0000 (-0400) Subject: gallium/util: start with a random L3 cache index for AMD Zen X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7d41a7593a540d118926691a77ad4c59e9559143;p=mesa.git gallium/util: start with a random L3 cache index for AMD Zen --- diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c index 8095242efd9..14367e5a118 100644 --- a/src/gallium/auxiliary/util/u_helpers.c +++ b/src/gallium/auxiliary/util/u_helpers.c @@ -30,6 +30,7 @@ #include "util/u_inlines.h" #include "util/u_upload_mgr.h" #include "util/u_thread.h" +#include "util/os_time.h" #include /** @@ -120,6 +121,17 @@ util_upload_index_buffer(struct pipe_context *pipe, 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. @@ -141,12 +153,12 @@ util_context_thread_changed(struct pipe_context *ctx, thrd_t *upper_thread) /* 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); }