iris: remove iris_monitor_config
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Tue, 9 Jun 2020 12:54:10 +0000 (14:54 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 6 Jul 2020 21:43:59 +0000 (21:43 +0000)
perf_cfg is enough - it already contains almost all necessary
information and is constructed in a more optimal way (O(n) vs O(n^2)
- it uses hash table to build the unique counter list).

"Almost all", because it doesn't contain OA raw counters, but
we should have not exposed them anyway. Quoting Mark Janes:
"I see no reason to include the OA raw counters in the list that
are provided to the user. They are unusable.
The MDAPI library can be used to configure raw counters in a way
that provides esoteric metrics, but that library is written against
INTEL_performance_query."

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Mark Janes <mark.a.janes@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5399>

src/gallium/drivers/iris/iris_monitor.c
src/gallium/drivers/iris/iris_monitor.h
src/gallium/drivers/iris/iris_screen.h
src/intel/perf/gen_perf.c
src/intel/perf/gen_perf.h

index a8409607c7a94c464bc8cf5b625f9a25f5c2313f..80bddcc3b316363c1dea3cf9061e8bcd4c320b0f 100644 (file)
@@ -43,24 +43,19 @@ iris_get_monitor_info(struct pipe_screen *pscreen, unsigned index,
                       struct pipe_driver_query_info *info)
 {
    const struct iris_screen *screen = (struct iris_screen *)pscreen;
-   assert(screen->monitor_cfg);
-   if (!screen->monitor_cfg)
+   const struct gen_perf_config *perf_cfg = screen->perf_cfg;
+   assert(perf_cfg);
+   if (!perf_cfg)
       return 0;
 
-   const struct iris_monitor_config *monitor_cfg = screen->monitor_cfg;
-
    if (!info) {
       /* return the number of metrics */
-      return monitor_cfg->num_counters;
+      return perf_cfg->n_counters;
    }
 
-   const struct gen_perf_config *perf_cfg = monitor_cfg->perf_cfg;
-   const int group = monitor_cfg->counters[index].group;
-   const int counter_index = monitor_cfg->counters[index].counter;
-   struct gen_perf_query_counter *counter =
-      &perf_cfg->queries[group].counters[counter_index];
+   struct gen_perf_query_counter *counter = perf_cfg->counters[index];
 
-   info->group_id = group;
+   info->group_id = counter->location.group_idx;
    info->name = counter->name;
    info->query_type = PIPE_QUERY_DRIVER_SPECIFIC + index;
 
@@ -97,84 +92,18 @@ iris_get_monitor_info(struct pipe_screen *pscreen, unsigned index,
 static bool
 iris_monitor_init_metrics(struct iris_screen *screen)
 {
-   struct iris_monitor_config *monitor_cfg =
-      rzalloc(screen, struct iris_monitor_config);
-   struct gen_perf_config *perf_cfg = NULL;
-   if (unlikely(!monitor_cfg))
-      goto allocation_error;
-   perf_cfg = gen_perf_new(monitor_cfg);
+   struct gen_perf_config *perf_cfg = gen_perf_new(screen);
    if (unlikely(!perf_cfg))
-      goto allocation_error;
+      return false;
 
-   monitor_cfg->perf_cfg = perf_cfg;
+   screen->perf_cfg = perf_cfg;
 
    iris_perf_init_vtbl(perf_cfg);
 
    gen_perf_init_metrics(perf_cfg, &screen->devinfo, screen->fd,
                          true /* pipeline stats*/);
-   screen->monitor_cfg = monitor_cfg;
-
-   /* a gallium "group" is equivalent to a gen "query"
-    * a gallium "query" is equivalent to a gen "query_counter"
-    *
-    * Each gen_query supports a specific number of query_counters.  To
-    * allocate the array of iris_monitor_counter, we need an upper bound
-    * (ignoring duplicate query_counters).
-    */
-   int gen_query_counters_count = 0;
-   for (int gen_query_id = 0;
-        gen_query_id < perf_cfg->n_queries;
-        ++gen_query_id) {
-      gen_query_counters_count += perf_cfg->queries[gen_query_id].n_counters;
-   }
 
-   monitor_cfg->counters = rzalloc_size(monitor_cfg,
-                                        sizeof(struct iris_monitor_counter) *
-                                        gen_query_counters_count);
-   if (unlikely(!monitor_cfg->counters))
-      goto allocation_error;
-
-   int iris_monitor_id = 0;
-   for (int group = 0; group < perf_cfg->n_queries; ++group) {
-      for (int counter = 0;
-           counter < perf_cfg->queries[group].n_counters;
-           ++counter) {
-         /* Check previously identified metrics to filter out duplicates. The
-          * user is not helped by having the same metric available in several
-          * groups. (n^2 algorithm).
-          */
-         bool duplicate = false;
-         for (int existing_group = 0;
-              existing_group < group && !duplicate;
-              ++existing_group) {
-            for (int existing_counter = 0;
-                 existing_counter < perf_cfg->queries[existing_group].n_counters && !duplicate;
-                 ++existing_counter) {
-               const char *current_name =
-                  perf_cfg->queries[group].counters[counter].name;
-               const char *existing_name =
-                  perf_cfg->queries[existing_group].counters[existing_counter].name;
-               if (strcmp(current_name, existing_name) == 0) {
-                  duplicate = true;
-               }
-            }
-         }
-         if (duplicate)
-            continue;
-         monitor_cfg->counters[iris_monitor_id].group = group;
-         monitor_cfg->counters[iris_monitor_id].counter = counter;
-         ++iris_monitor_id;
-      }
-   }
-   monitor_cfg->num_counters = iris_monitor_id;
-   return monitor_cfg->num_counters;
-
-allocation_error:
-   if (monitor_cfg)
-      free(monitor_cfg->counters);
-   free(perf_cfg);
-   free(monitor_cfg);
-   return false;
+   return perf_cfg->n_counters > 0;
 }
 
 int
@@ -183,13 +112,12 @@ iris_get_monitor_group_info(struct pipe_screen *pscreen,
                             struct pipe_driver_query_group_info *info)
 {
    struct iris_screen *screen = (struct iris_screen *)pscreen;
-   if (!screen->monitor_cfg) {
+   if (!screen->perf_cfg) {
       if (!iris_monitor_init_metrics(screen))
          return 0;
    }
 
-   const struct iris_monitor_config *monitor_cfg = screen->monitor_cfg;
-   const struct gen_perf_config *perf_cfg = monitor_cfg->perf_cfg;
+   const struct gen_perf_config *perf_cfg = screen->perf_cfg;
 
    if (!info) {
       /* return the count that can be queried */
@@ -214,14 +142,13 @@ static void
 iris_init_monitor_ctx(struct iris_context *ice)
 {
    struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
-   struct iris_monitor_config *monitor_cfg = screen->monitor_cfg;
 
    ice->perf_ctx = gen_perf_new_context(ice);
    if (unlikely(!ice->perf_ctx))
       return;
 
    struct gen_perf_context *perf_ctx = ice->perf_ctx;
-   struct gen_perf_config *perf_cfg = monitor_cfg->perf_cfg;
+   struct gen_perf_config *perf_cfg = screen->perf_cfg;
    gen_perf_init_context(perf_ctx,
                          perf_cfg,
                          ice,
@@ -238,8 +165,7 @@ iris_create_monitor_object(struct iris_context *ice,
                            unsigned *query_types)
 {
    struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
-   struct iris_monitor_config *monitor_cfg = screen->monitor_cfg;
-   struct gen_perf_config *perf_cfg = monitor_cfg->perf_cfg;
+   struct gen_perf_config *perf_cfg = screen->perf_cfg;
    struct gen_perf_query_object *query_obj = NULL;
 
    /* initialize perf context if this has not already been done.  This
@@ -252,8 +178,8 @@ iris_create_monitor_object(struct iris_context *ice,
 
    assert(num_queries > 0);
    int query_index = query_types[0] - PIPE_QUERY_DRIVER_SPECIFIC;
-   assert(query_index <= monitor_cfg->num_counters);
-   const int group = monitor_cfg->counters[query_index].group;
+   assert(query_index <= perf_cfg->n_counters);
+   const int group = perf_cfg->counters[query_index]->location.group_idx;
 
    struct iris_monitor_object *monitor =
       calloc(1, sizeof(struct iris_monitor_object));
@@ -270,10 +196,10 @@ iris_create_monitor_object(struct iris_context *ice,
       unsigned current_query_index = current_query - PIPE_QUERY_DRIVER_SPECIFIC;
 
       /* all queries must be in the same group */
-      assert(current_query_index <= monitor_cfg->num_counters);
-      assert(monitor_cfg->counters[current_query_index].group == group);
+      assert(current_query_index <= perf_cfg->n_counters);
+      assert(perf_cfg->counters[current_query_index]->location.group_idx == group);
       monitor->active_counters[i] =
-         monitor_cfg->counters[current_query_index].counter;
+         perf_cfg->counters[current_query_index]->location.counter_idx;
    }
 
    /* create the gen_perf_query */
index cb9dbd6e992a7b83cd6f6fe054e84849572fab64..3c4ca1604a50d62dfd19d0a28d77b584bb05de78 100644 (file)
 
 #include "pipe/p_screen.h"
 
-struct iris_monitor_counter {
-   int group;
-   int counter;
-};
-
-struct iris_monitor_config {
-   struct gen_perf_config *perf_cfg;
-
-   /* gallium requires an index for each counter */
-   int num_counters;
-   struct iris_monitor_counter *counters;
-};
-
 int iris_get_monitor_info(struct pipe_screen *pscreen, unsigned index,
                           struct pipe_driver_query_info *info);
 int iris_get_monitor_group_info(struct pipe_screen *pscreen,
index 836954fc1d619b6e32e2e69096b6ba334ec858d5..1a03a3f46df5ca615260f4b744a78df1f37a2dd6 100644 (file)
@@ -36,7 +36,6 @@
 
 struct gen_l3_config;
 struct brw_vue_map;
-struct iris_monitor_config;
 struct iris_vs_prog_key;
 struct iris_tcs_prog_key;
 struct iris_tes_prog_key;
@@ -201,7 +200,7 @@ struct iris_screen {
    struct isl_device isl_dev;
    struct iris_bufmgr *bufmgr;
    struct brw_compiler *compiler;
-   struct iris_monitor_config *monitor_cfg;
+   struct gen_perf_config *perf_cfg;
 
    const struct gen_l3_config *l3_config_3d;
    const struct gen_l3_config *l3_config_cs;
index 24fee821474471478ac6e6f0080fe1e68f10d1aa..4de459dfb936d15bb0f9f5ae4ed4c5c111dd5b1e 100644 (file)
@@ -626,6 +626,8 @@ build_unique_counter_list(struct gen_perf_config *perf)
          unique_counter = counter;
          unique_counter->query_mask = BITFIELD64_BIT(q);
 
+         unique_counter->location.group_idx = q;
+         unique_counter->location.counter_idx = c;
          _mesa_hash_table_insert(counters_table, unique_counter->symbol_name, unique_counter);
       }
    }
index c9c8a3042a8fdc1ac56db6d066c487e61907e555..ca4a66a2e9d49864439a86fd66ccac38e3d61fe9 100644 (file)
@@ -173,6 +173,15 @@ struct gen_perf_query_counter {
    size_t offset;
    uint64_t query_mask;
 
+   /**
+    * Each counter can be a part of many groups, each time at different index.
+    * This struct stores one of those locations.
+    */
+   struct {
+      int group_idx; /* query/group number */
+      int counter_idx; /* index inside of query/group */
+   } location;
+
    union {
       uint64_t (*oa_counter_read_uint64)(struct gen_perf_config *perf,
                                          const struct gen_perf_query_info *query,