iris/perf: implement iris_create_monitor_object
authorMark Janes <mark.a.janes@intel.com>
Wed, 3 Jul 2019 19:38:16 +0000 (12:38 -0700)
committerMark Janes <mark.a.janes@intel.com>
Sat, 10 Aug 2019 02:28:14 +0000 (19:28 -0700)
This is the first call that provides the iris context to the monitor
implementation.  On the first call, use the iris context to initialize
the monitor context.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_monitor.c
src/gallium/drivers/iris/iris_monitor.h
src/gallium/drivers/iris/iris_query.c

index 158dfe70d715085056cd71be08a2eb553cdcf80b..2ca496d1d03eca9e4a039fe2035c215ca686ec0b 100644 (file)
@@ -606,6 +606,8 @@ struct iris_context {
       bool condition;
    } condition;
 
+   struct gen_perf_context *perf_ctx;
+
    struct {
       uint64_t dirty;
       uint64_t dirty_for_nos[IRIS_NOS_COUNT];
index 07045dd978331c9d703f64aca8362cb183e7a767..37c5bd93a2754a8c82dcc49186e241c4269e8e28 100644 (file)
 
 #include "perf/gen_perf.h"
 
+struct iris_monitor_object {
+   int num_active_counters;
+   int *active_counters;
+
+   size_t result_size;
+   unsigned char *result_buffer;
+
+   struct gen_perf_query_object *query;
+};
+
 int iris_get_monitor_info(struct pipe_screen *pscreen, unsigned index,
                           struct pipe_driver_query_info *info)
 {
@@ -279,3 +289,92 @@ int iris_get_monitor_group_info(struct pipe_screen *pscreen,
    info->num_queries = query->n_counters;
    return 1;
 }
+
+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;
+   gen_perf_init_context(perf_ctx,
+                         perf_cfg,
+                         ice,
+                         screen->bufmgr,
+                         &screen->devinfo,
+                         ice->batches[IRIS_BATCH_RENDER].hw_ctx_id,
+                         screen->fd);
+}
+
+/* entry point for GenPerfMonitorsAMD */
+struct iris_monitor_object *
+iris_create_monitor_object(struct iris_context *ice,
+                           unsigned num_queries,
+                           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_query_object *query_obj = NULL;
+
+   /* initialize perf context if this has not already been done.  This
+    * function is the first entry point that carries the gl context.
+    */
+   if (ice->perf_ctx == NULL) {
+      iris_init_monitor_ctx(ice);
+   }
+   struct gen_perf_context *perf_ctx = ice->perf_ctx;
+
+   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;
+
+   struct iris_monitor_object *monitor =
+      calloc(1, sizeof(struct iris_monitor_object));
+   if (unlikely(!monitor))
+      goto allocation_failure;
+
+   monitor->num_active_counters = num_queries;
+   monitor->active_counters = calloc(num_queries, sizeof(int));
+   if (unlikely(!monitor->active_counters))
+      goto allocation_failure;
+
+   for (int i = 0; i < num_queries; ++i) {
+      unsigned current_query = query_types[i];
+      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);
+      monitor->active_counters[i] =
+         monitor_cfg->counters[current_query_index].counter;
+   }
+
+   /* create the gen_perf_query */
+   query_obj = gen_perf_new_query(perf_ctx, group);
+   if (unlikely(!query_obj))
+      goto allocation_failure;
+
+   monitor->query = query_obj;
+   monitor->result_size = perf_cfg->queries[group].data_size;
+   monitor->result_buffer = calloc(1, monitor->result_size);
+   if (unlikely(!monitor->result_buffer))
+      goto allocation_failure;
+
+   return monitor;
+
+allocation_failure:
+   if (monitor) {
+      free(monitor->active_counters);
+      free(monitor->result_buffer);
+   }
+   free(query_obj);
+   free(monitor);
+   return NULL;
+}
index 2a7a72e3548c0a14797eea5a06b1264fdbd882e9..db014d079e9d3bc9417b3ff83bd54b844c4ebda1 100644 (file)
@@ -45,5 +45,12 @@ int iris_get_monitor_group_info(struct pipe_screen *pscreen,
                                 unsigned index,
                                 struct pipe_driver_query_group_info *info);
 
+struct iris_context;
+struct iris_screen;
+
+struct iris_monitor_object *
+iris_create_monitor_object(struct iris_context *ice,
+                           unsigned num_queries,
+                           unsigned *query_types);
 
 #endif
index 6d4a04f20b93e59b3fe954a80d681a15fea1a212..a50b47418df7aaf4e3aebbca5f924ce56163e854 100644 (file)
@@ -66,6 +66,8 @@ struct iris_query {
    struct iris_syncpt *syncpt;
 
    int batch_idx;
+
+   struct iris_monitor_object *monitor;
 };
 
 struct iris_query_snapshots {