gallium/u_queue: add an option to name threads
authorMarek Olšák <marek.olsak@amd.com>
Sun, 12 Jun 2016 11:36:39 +0000 (13:36 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 24 Jun 2016 10:24:40 +0000 (12:24 +0200)
for debugging

v2: correct the snprintf use

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/util/u_queue.c
src/gallium/auxiliary/util/u_queue.h
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c

index a958c04d5db9999246562ce018eed1f0a5e7f3c0..de0422a0c13ba6080ca99e81cc878091ad7473b3 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "u_queue.h"
 #include "u_memory.h"
+#include "u_string.h"
 #include "os/os_time.h"
 
 static void
@@ -61,6 +62,12 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
 
    FREE(input);
 
+   if (queue->name) {
+      char name[16];
+      util_snprintf(name, sizeof(name), "%s:%i", queue->name, thread_index);
+      pipe_thread_setname(name);
+   }
+
    while (1) {
       struct util_queue_job job;
 
@@ -96,6 +103,7 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
 
 bool
 util_queue_init(struct util_queue *queue,
+                const char *name,
                 unsigned max_jobs,
                 unsigned num_threads,
                 void (*execute_job)(void *, int))
@@ -103,6 +111,7 @@ util_queue_init(struct util_queue *queue,
    unsigned i;
 
    memset(queue, 0, sizeof(*queue));
+   queue->name = name;
    queue->num_threads = num_threads;
    queue->max_jobs = max_jobs;
 
index f3aa4f6f5c6f488c3e74ee492e03fa407f077cb6..f005ad5ef4cb1e0ddb534f05f8f4d7913dd2f73e 100644 (file)
@@ -51,6 +51,7 @@ struct util_queue_job {
 
 /* Put this into your context. */
 struct util_queue {
+   const char *name;
    pipe_mutex lock;
    pipe_semaphore has_space;
    pipe_semaphore queued;
@@ -64,6 +65,7 @@ struct util_queue {
 };
 
 bool util_queue_init(struct util_queue *queue,
+                     const char *name,
                      unsigned max_jobs,
                      unsigned num_threads,
                      void (*execute_job)(void *, int));
index 22a81220ace2742f1512a5b3b5c787fb94fb50ba..8782665cca995c04c8d5e66cf86a06d5dc3c4a2b 100644 (file)
@@ -493,7 +493,7 @@ amdgpu_winsys_create(int fd, radeon_screen_create_t screen_create)
    pipe_mutex_init(ws->bo_fence_lock);
 
    if (sysconf(_SC_NPROCESSORS_ONLN) > 1 && debug_get_option_thread())
-      util_queue_init(&ws->cs_queue, 8, 1, amdgpu_cs_submit_ib);
+      util_queue_init(&ws->cs_queue, "amdgpu_cs", 8, 1, amdgpu_cs_submit_ib);
 
    /* Create the screen at the end. The winsys must be initialized
     * completely.
index 32d58b9b9e507e969e1d7aa012caed75cdc58af4..ea5d212803cb9932aa973015747088bd192cd2bb 100644 (file)
@@ -783,7 +783,7 @@ radeon_drm_winsys_create(int fd, radeon_screen_create_t screen_create)
     ws->info.gart_page_size = sysconf(_SC_PAGESIZE);
 
     if (ws->num_cpus > 1 && debug_get_option_thread())
-        util_queue_init(&ws->cs_queue, 8, 1,
+        util_queue_init(&ws->cs_queue, "radeon_cs", 8, 1,
                         radeon_drm_cs_emit_ioctl_oneshot);
 
     /* Create the screen at the end. The winsys must be initialized