util: replace UTIL_MAX_CPUS by util_cpu_caps.num_cpu_mask_bits
to reduce overhead when setting thread affinity. Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8017>
This commit is contained in:
@@ -2173,7 +2173,7 @@ tc_set_context_param(struct pipe_context *_pipe,
|
||||
/* Pin the gallium thread as requested. */
|
||||
util_set_thread_affinity(tc->queue.threads[0],
|
||||
util_cpu_caps.L3_affinity_mask[value],
|
||||
NULL, UTIL_MAX_CPUS);
|
||||
NULL, util_cpu_caps.num_cpu_mask_bits);
|
||||
|
||||
/* Execute this immediately (without enqueuing).
|
||||
* It's required to be thread-safe.
|
||||
|
||||
@@ -328,7 +328,7 @@ static void amdgpu_pin_threads_to_L3_cache(struct radeon_winsys *rws,
|
||||
|
||||
util_set_thread_affinity(ws->cs_queue.threads[0],
|
||||
util_cpu_caps.L3_affinity_mask[cache],
|
||||
NULL, UTIL_MAX_CPUS);
|
||||
NULL, util_cpu_caps.num_cpu_mask_bits);
|
||||
}
|
||||
|
||||
static uint32_t kms_handle_hash(const void *key)
|
||||
|
||||
@@ -805,7 +805,7 @@ static void radeon_pin_threads_to_L3_cache(struct radeon_winsys *ws,
|
||||
if (util_queue_is_initialized(&rws->cs_queue)) {
|
||||
util_set_thread_affinity(rws->cs_queue.threads[0],
|
||||
util_cpu_caps.L3_affinity_mask[cache],
|
||||
NULL, UTIL_MAX_CPUS);
|
||||
NULL, util_cpu_caps.num_cpu_mask_bits);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ _mesa_glthread_flush_batch(struct gl_context *ctx)
|
||||
|
||||
util_set_thread_affinity(glthread->queue.threads[0],
|
||||
util_cpu_caps.L3_affinity_mask[L3_cache],
|
||||
NULL, UTIL_MAX_CPUS);
|
||||
NULL, util_cpu_caps.num_cpu_mask_bits);
|
||||
ctx->Driver.PinDriverToL3Cache(ctx, L3_cache);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ get_cpu_topology(void)
|
||||
|
||||
if (util_set_current_thread_affinity(mask,
|
||||
!saved ? saved_mask : NULL,
|
||||
UTIL_MAX_CPUS)) {
|
||||
util_cpu_caps.num_cpu_mask_bits)) {
|
||||
saved = true;
|
||||
allowed_mask[i / 32] |= cpu_bit;
|
||||
|
||||
@@ -528,7 +528,8 @@ get_cpu_topology(void)
|
||||
}
|
||||
|
||||
/* Restore the original affinity mask. */
|
||||
util_set_current_thread_affinity(saved_mask, NULL, UTIL_MAX_CPUS);
|
||||
util_set_current_thread_affinity(saved_mask, NULL,
|
||||
util_cpu_caps.num_cpu_mask_bits);
|
||||
} else {
|
||||
if (debug_get_option_dump_cpu())
|
||||
fprintf(stderr, "Cannot set thread affinity for any thread.\n");
|
||||
@@ -569,6 +570,8 @@ util_cpu_detect_once(void)
|
||||
util_cpu_caps.nr_cpus = 1;
|
||||
#endif
|
||||
|
||||
util_cpu_caps.num_cpu_mask_bits = align(util_cpu_caps.nr_cpus, 32);
|
||||
|
||||
/* Make the fallback cacheline size nonzero so that it can be
|
||||
* safely passed to align().
|
||||
*/
|
||||
|
||||
@@ -98,6 +98,7 @@ struct util_cpu_caps {
|
||||
|
||||
unsigned num_L3_caches;
|
||||
unsigned cores_per_L3;
|
||||
unsigned num_cpu_mask_bits;
|
||||
|
||||
uint16_t cpu_to_L3[UTIL_MAX_CPUS];
|
||||
/* Affinity masks for each L3 cache. */
|
||||
|
||||
+3
-2
@@ -27,7 +27,7 @@
|
||||
#include "u_queue.h"
|
||||
|
||||
#include "c11/threads.h"
|
||||
|
||||
#include "util/u_cpu_detect.h"
|
||||
#include "util/os_time.h"
|
||||
#include "util/u_string.h"
|
||||
#include "util/u_thread.h"
|
||||
@@ -258,7 +258,8 @@ util_queue_thread_func(void *input)
|
||||
uint32_t mask[UTIL_MAX_CPUS / 32];
|
||||
|
||||
memset(mask, 0xff, sizeof(mask));
|
||||
util_set_current_thread_affinity(mask, NULL, UTIL_MAX_CPUS);
|
||||
util_set_current_thread_affinity(mask, NULL,
|
||||
util_cpu_caps.num_cpu_mask_bits);
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
Reference in New Issue
Block a user