util/u_queue: add UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
authorMarek Olšák <marek.olsak@amd.com>
Mon, 1 Oct 2018 19:51:06 +0000 (15:51 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Sun, 7 Oct 2018 02:05:58 +0000 (22:05 -0400)
Initial version discussed with Rob Clark under a different patch name.
This approach leaves his driver unaffected.

src/gallium/drivers/radeonsi/si_pipe.c
src/util/disk_cache.c
src/util/u_queue.c
src/util/u_queue.h

index 69f649faed932a667b711a46415eb1e67b709cd3..6c05440b0d8e55fa698f6006e1d41aa254b0d9b2 100644 (file)
@@ -890,7 +890,8 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
 
        if (!util_queue_init(&sscreen->shader_compiler_queue, "sh",
                             64, num_comp_hi_threads,
-                            UTIL_QUEUE_INIT_RESIZE_IF_FULL)) {
+                            UTIL_QUEUE_INIT_RESIZE_IF_FULL |
+                            UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY)) {
                si_destroy_shader_cache(sscreen);
                FREE(sscreen);
                return NULL;
@@ -900,6 +901,7 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
                             "shlo",
                             64, num_comp_lo_threads,
                             UTIL_QUEUE_INIT_RESIZE_IF_FULL |
+                            UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY |
                             UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY)) {
               si_destroy_shader_cache(sscreen);
               FREE(sscreen);
index 368ec4179273454eda94a0116fbf2515cf2578d8..0aa2646a9bb6e616debde74472c1fcabc0c6739f 100644 (file)
@@ -378,7 +378,8 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
     */
    util_queue_init(&cache->cache_queue, "disk$", 32, 1,
                    UTIL_QUEUE_INIT_RESIZE_IF_FULL |
-                   UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY);
+                   UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY |
+                   UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY);
 
    cache->path_init_failed = false;
 
index 22d2cdd0fa28fec14ae681b6861d6c125c657f2b..3812c824b6dab14a8586434dc12b6f10faddbfea 100644 (file)
@@ -239,6 +239,20 @@ util_queue_thread_func(void *input)
 
    free(input);
 
+#ifdef HAVE_PTHREAD_SETAFFINITY
+   if (queue->flags & UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY) {
+      /* Don't inherit the thread affinity from the parent thread.
+       * Set the full mask.
+       */
+      cpu_set_t cpuset;
+      CPU_ZERO(&cpuset);
+      for (unsigned i = 0; i < CPU_SETSIZE; i++)
+         CPU_SET(i, &cpuset);
+
+      pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
+   }
+#endif
+
    if (strlen(queue->name) > 0) {
       char name[16];
       util_snprintf(name, sizeof(name), "%s%i", queue->name, thread_index);
index 714d9243f00ed043d6d7eb3029751914af9e090c..4e63a76aab2f5255d3a45ee42b7fca64502d8b17 100644 (file)
@@ -48,6 +48,7 @@ extern "C" {
 
 #define UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY      (1 << 0)
 #define UTIL_QUEUE_INIT_RESIZE_IF_FULL            (1 << 1)
+#define UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY  (1 << 2)
 
 #if defined(__GNUC__) && defined(HAVE_LINUX_FUTEX_H)
 #define UTIL_QUEUE_FENCE_FUTEX