summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util/u_helpers.c
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2018-09-05 23:10:57 -0400
committerMarek Olšák <[email protected]>2018-09-07 16:03:30 -0400
commit8d473f555a0c3c94cffd18e68a13274488dcfb17 (patch)
treea0ca440547d0c224de102b074ad1b84494a18568 /src/gallium/auxiliary/util/u_helpers.c
parente5e3b5cdcc38ce1111b134e6fe5bc4d00c8c715f (diff)
st/mesa: pin driver threads to a specific L3 cache on AMD Zen (v2)
v2: use set_context_param Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util/u_helpers.c')
-rw-r--r--src/gallium/auxiliary/util/u_helpers.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c
index 365238631a2..7d45b2f06db 100644
--- a/src/gallium/auxiliary/util/u_helpers.c
+++ b/src/gallium/auxiliary/util/u_helpers.c
@@ -25,9 +25,11 @@
*
**************************************************************************/
+#include "util/u_cpu_detect.h"
#include "util/u_helpers.h"
#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
+#include "util/u_thread.h"
#include <inttypes.h>
/**
@@ -118,6 +120,46 @@ util_upload_index_buffer(struct pipe_context *pipe,
return *out_buffer != NULL;
}
+/**
+ * Called by MakeCurrent. Used to notify the driver that the application
+ * thread may have been changed.
+ *
+ * The function pins the current thread and driver threads to a group of
+ * CPU cores that share the same L3 cache. This is needed for good multi-
+ * threading performance on AMD Zen CPUs.
+ *
+ * \param upper_thread thread in the state tracker that also needs to be
+ * pinned.
+ */
+void
+util_context_thread_changed(struct pipe_context *ctx, thrd_t *upper_thread)
+{
+ thrd_t current = thrd_current();
+ int cache = util_get_L3_for_pinned_thread(current,
+ util_cpu_caps.cores_per_L3);
+
+ /* 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;
+
+ /* Choose a different L3 cache for each subsequent MakeCurrent. */
+ cache = p_atomic_inc_return(&last_cache) % num_caches;
+ util_pin_thread_to_L3(current, cache, util_cpu_caps.cores_per_L3);
+ }
+
+ /* Tell the driver to pin its threads to the same L3 cache. */
+ if (ctx->set_context_param) {
+ ctx->set_context_param(ctx, PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE,
+ cache);
+ }
+
+ /* Do the same for the upper level thread if there is any (e.g. glthread) */
+ if (upper_thread)
+ util_pin_thread_to_L3(*upper_thread, cache, util_cpu_caps.cores_per_L3);
+}
+
/* This is a helper for hardware bring-up. Don't remove. */
struct pipe_query *
util_begin_pipestat_query(struct pipe_context *ctx)