[Mesa-dev] [PATCH 09/11] gallium/hud: add glthread counters

Marek Olšák maraeo at gmail.com
Thu Jun 22 01:03:04 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/hud/hud_context.c |  9 ++++
 src/gallium/auxiliary/hud/hud_cpu.c     | 74 +++++++++++++++++++++++++++++++++
 src/gallium/auxiliary/hud/hud_private.h |  8 ++++
 3 files changed, 91 insertions(+)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 9ab7822..8172313 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -1146,20 +1146,29 @@ hud_parse_env_var(struct hud_context *hud, const char *env)
       }
       else if (strcmp(name, "cpu") == 0) {
          hud_cpu_graph_install(pane, ALL_CPUS);
       }
       else if (sscanf(name, "cpu%u%s", &i, s) == 1) {
          hud_cpu_graph_install(pane, i);
       }
       else if (strcmp(name, "API-thread-busy") == 0) {
          hud_thread_busy_install(pane, name, false);
       }
+      else if (strcmp(name, "API-thread-offloaded-slots") == 0) {
+         hud_thread_counter_install(pane, name, HUD_COUNTER_OFFLOADED);
+      }
+      else if (strcmp(name, "API-thread-direct-slots") == 0) {
+         hud_thread_counter_install(pane, name, HUD_COUNTER_DIRECT);
+      }
+      else if (strcmp(name, "API-thread-num-syncs") == 0) {
+         hud_thread_counter_install(pane, name, HUD_COUNTER_SYNCS);
+      }
       else if (strcmp(name, "main-thread-busy") == 0) {
          hud_thread_busy_install(pane, name, true);
       }
 #if HAVE_GALLIUM_EXTRA_HUD
       else if (sscanf(name, "nic-rx-%s", arg_name) == 1) {
          hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_RX);
       }
       else if (sscanf(name, "nic-tx-%s", arg_name) == 1) {
          hud_nic_graph_install(pane, arg_name, NIC_DIRECTION_TX);
       }
diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c
index 38403f9..4caaab6 100644
--- a/src/gallium/auxiliary/hud/hud_cpu.c
+++ b/src/gallium/auxiliary/hud/hud_cpu.c
@@ -300,10 +300,84 @@ hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main)
    gr->query_new_value = query_api_thread_busy_status;
 
    /* Don't use free() as our callback as that messes up Gallium's
     * memory debugger.  Use simple free_query_data() wrapper.
     */
    gr->free_query_data = free_query_data;
 
    hud_pane_add_graph(pane, gr);
    hud_pane_set_max_value(pane, 100);
 }
+
+struct counter_info {
+   enum hud_counter counter;
+   unsigned last_value;
+   int64_t last_time;
+};
+
+static unsigned get_counter(struct hud_graph *gr, enum hud_counter counter)
+{
+   struct util_queue_monitoring *mon = gr->pane->hud->monitored_queue;
+
+   if (!mon || !mon->queue)
+      return 0;
+
+   switch (counter) {
+   case HUD_COUNTER_OFFLOADED:
+      return mon->num_offloaded_items;
+   case HUD_COUNTER_DIRECT:
+      return mon->num_direct_items;
+   case HUD_COUNTER_SYNCS:
+      return mon->num_syncs;
+   default:
+      assert(0);
+      return 0;
+   }
+}
+
+static void
+query_thread_counter(struct hud_graph *gr)
+{
+   struct counter_info *info = gr->query_data;
+   int64_t now = os_time_get_nano();
+
+   if (info->last_time) {
+      if (info->last_time + gr->pane->period*1000 <= now) {
+         unsigned current_value = get_counter(gr, info->counter);
+
+         hud_graph_add_value(gr, current_value - info->last_value);
+         info->last_value = current_value;
+         info->last_time = now;
+      }
+   } else {
+      /* initialize */
+      info->last_value = get_counter(gr, info->counter);
+      info->last_time = now;
+   }
+}
+
+void hud_thread_counter_install(struct hud_pane *pane, const char *name,
+                                enum hud_counter counter)
+{
+   struct hud_graph *gr = CALLOC_STRUCT(hud_graph);
+   if (!gr)
+      return;
+
+   strcpy(gr->name, name);
+
+   gr->query_data = CALLOC_STRUCT(counter_info);
+   if (!gr->query_data) {
+      FREE(gr);
+      return;
+   }
+
+   ((struct counter_info*)gr->query_data)->counter = counter;
+   gr->query_new_value = query_thread_counter;
+
+   /* Don't use free() as our callback as that messes up Gallium's
+    * memory debugger.  Use simple free_query_data() wrapper.
+    */
+   gr->free_query_data = free_query_data;
+
+   hud_pane_add_graph(pane, gr);
+   hud_pane_set_max_value(pane, 100);
+}
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index b8726da..2b1717d 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -26,20 +26,26 @@
  **************************************************************************/
 
 #ifndef HUD_PRIVATE_H
 #define HUD_PRIVATE_H
 
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "util/list.h"
 #include "hud/font.h"
 
+enum hud_counter {
+   HUD_COUNTER_OFFLOADED,
+   HUD_COUNTER_DIRECT,
+   HUD_COUNTER_SYNCS,
+};
+
 struct hud_context {
    struct pipe_context *pipe;
    struct cso_context *cso;
 
    struct hud_batch_query_context *batch_query;
    struct list_head pane_list;
 
    struct util_queue_monitoring *monitored_queue;
 
    /* states */
@@ -138,20 +144,22 @@ void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
 /* graphs/queries */
 struct hud_batch_query_context;
 
 #define ALL_CPUS ~0 /* optionally set as cpu_index */
 
 int hud_get_num_cpus(void);
 
 void hud_fps_graph_install(struct hud_pane *pane);
 void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);
 void hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main);
+void hud_thread_counter_install(struct hud_pane *pane, const char *name,
+                                enum hud_counter counter);
 void hud_pipe_query_install(struct hud_batch_query_context **pbq,
                             struct hud_pane *pane, struct pipe_context *pipe,
                             const char *name, unsigned query_type,
                             unsigned result_index,
                             uint64_t max_value,
                             enum pipe_driver_query_type type,
                             enum pipe_driver_query_result_type result_type,
                             unsigned flags);
 boolean hud_driver_query_install(struct hud_batch_query_context **pbq,
                                  struct hud_pane *pane,
-- 
2.7.4



More information about the mesa-dev mailing list