Module: Mesa
Branch: master
Commit: 7d41a7593a540d118926691a77ad4c59e9559143
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7d41a7593a540d118926691a77ad4c59e9559143

Author: Marek Olšák <[email protected]>
Date:   Fri Sep  7 15:37:45 2018 -0400

gallium/util: start with a random L3 cache index for AMD Zen

---

 src/gallium/auxiliary/util/u_helpers.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_helpers.c 
b/src/gallium/auxiliary/util/u_helpers.c
index 8095242efd..14367e5a11 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);
    }
 

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to