diff options
author | Marek Olšák <[email protected]> | 2018-09-07 15:37:45 -0400 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2018-09-14 21:05:37 -0400 |
commit | 7d41a7593a540d118926691a77ad4c59e9559143 (patch) | |
tree | 8df2c8037b2d40e59bb0ed341d93129615943bd2 /src/gallium/auxiliary | |
parent | 936e0dcd619bc092b9869b4be2e1b20c3631131f (diff) |
gallium/util: start with a random L3 cache index for AMD Zen
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/util/u_helpers.c | 20 |
1 files changed, 16 insertions, 4 deletions
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 <inttypes.h> /** @@ -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); } |