st/mesa: regularly re-pin driver threads to the CCX where the app thread is

This is used when glthread is disabled.

Mesa pretty much chases the app thread on the CPU.
The performance is the same as pinning the app thread.

Reviewed-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Marek Olšák 2018-11-12 18:10:59 -05:00
parent ce7f84eb77
commit 48f2160936
2 changed files with 34 additions and 0 deletions

View File

@ -193,6 +193,8 @@ struct st_context
/** This masks out unused shader resources. Only valid in draw calls. */
uint64_t active_states;
unsigned pin_thread_counter; /* for L3 thread pinning on AMD Zen */
/* If true, further analysis of states is required to know if something
* has changed. Used mainly for shaders.
*/

View File

@ -58,6 +58,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "util/u_cpu_detect.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_prim.h"
@ -66,6 +67,13 @@
#include "draw/draw_context.h"
#include "cso_cache/cso_context.h"
#ifdef PIPE_OS_LINUX
#include <sched.h>
#define HAVE_SCHED_GETCPU 1
#else
#define sched_getcpu() 0
#define HAVE_SCHED_GETCPU 0
#endif
/**
* Set the restart index.
@ -122,6 +130,30 @@ prepare_draw(struct st_context *st, struct gl_context *ctx)
st->gfx_shaders_may_be_dirty) {
st_validate_state(st, ST_PIPELINE_RENDER);
}
struct pipe_context *pipe = st->pipe;
/* Pin threads regularly to the same Zen CCX that the main thread is
* running on. The main thread can move between CCXs.
*/
if (unlikely(HAVE_SCHED_GETCPU && /* Linux */
/* AMD Zen */
util_cpu_caps.nr_cpus != util_cpu_caps.cores_per_L3 &&
/* no glthread */
ctx->CurrentClientDispatch != ctx->MarshalExec &&
/* driver support */
pipe->set_context_param &&
/* do it occasionally */
++st->pin_thread_counter % 512 == 0)) {
int cpu = sched_getcpu();
if (cpu >= 0) {
unsigned L3_cache = cpu / util_cpu_caps.cores_per_L3;
pipe->set_context_param(pipe,
PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE,
L3_cache);
}
}
}
/**