Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_performance_query.c
4565 views
/*1* Copyright © 2019 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included11* in all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19* DEALINGS IN THE SOFTWARE.20*/2122#include <xf86drm.h>2324#include "iris_context.h"25#include "iris_perf.h"2627struct iris_perf_query {28struct gl_perf_query_object base;29struct intel_perf_query_object *query;30bool begin_succeeded;31};3233static unsigned34iris_init_perf_query_info(struct pipe_context *pipe)35{36struct iris_context *ice = (void *) pipe;37struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;38struct intel_perf_config *perf_cfg = NULL;3940/* make sure pipe perf counter type/data-type enums are matched with intel_perf's */41STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_EVENT == (enum pipe_perf_counter_type)INTEL_PERF_COUNTER_TYPE_EVENT);42STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_DURATION_NORM == (enum pipe_perf_counter_type)INTEL_PERF_COUNTER_TYPE_DURATION_NORM);43STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_DURATION_RAW == (enum pipe_perf_counter_type)INTEL_PERF_COUNTER_TYPE_DURATION_RAW);44STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_THROUGHPUT == (enum pipe_perf_counter_type)INTEL_PERF_COUNTER_TYPE_THROUGHPUT);45STATIC_ASSERT(PIPE_PERF_COUNTER_TYPE_RAW == (enum pipe_perf_counter_type)INTEL_PERF_COUNTER_TYPE_RAW);4647STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_BOOL32 == (enum pipe_perf_counter_data_type)INTEL_PERF_COUNTER_DATA_TYPE_BOOL32);48STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_UINT32 == (enum pipe_perf_counter_data_type)INTEL_PERF_COUNTER_DATA_TYPE_UINT32);49STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_UINT64 == (enum pipe_perf_counter_data_type)INTEL_PERF_COUNTER_DATA_TYPE_UINT64);50STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_FLOAT == (enum pipe_perf_counter_data_type)INTEL_PERF_COUNTER_DATA_TYPE_FLOAT);51STATIC_ASSERT(PIPE_PERF_COUNTER_DATA_TYPE_DOUBLE == (enum pipe_perf_counter_data_type)INTEL_PERF_COUNTER_DATA_TYPE_DOUBLE);5253if (!ice->perf_ctx)54ice->perf_ctx = intel_perf_new_context(ice);5556if (unlikely(!ice->perf_ctx))57return 0;5859perf_cfg = intel_perf_config(ice->perf_ctx);6061if (perf_cfg)62return perf_cfg->n_queries;6364perf_cfg = intel_perf_new(ice->perf_ctx);6566iris_perf_init_vtbl(perf_cfg);6768intel_perf_init_metrics(perf_cfg, &screen->devinfo, screen->fd,69true /* pipeline_statistics */,70true /* register snapshots */);7172intel_perf_init_context(ice->perf_ctx,73perf_cfg,74ice,75ice,76screen->bufmgr,77&screen->devinfo,78ice->batches[IRIS_BATCH_RENDER].hw_ctx_id,79screen->fd);8081return perf_cfg->n_queries;82}8384static struct pipe_query *85iris_new_perf_query_obj(struct pipe_context *pipe, unsigned query_index)86{87struct iris_context *ice = (void *) pipe;88struct intel_perf_context *perf_ctx = ice->perf_ctx;89struct intel_perf_query_object * obj =90intel_perf_new_query(perf_ctx, query_index);91if (unlikely(!obj))92return NULL;9394struct iris_perf_query *q = calloc(1, sizeof(struct iris_perf_query));95if (unlikely(!q)) {96intel_perf_delete_query(perf_ctx, obj);97return NULL;98}99100q->query = obj;101return (struct pipe_query *)&q->base;102}103104static bool105iris_begin_perf_query(struct pipe_context *pipe, struct pipe_query *q)106{107struct iris_context *ice = (void *) pipe;108struct iris_perf_query *perf_query= (struct iris_perf_query *) q;109struct intel_perf_query_object *obj = perf_query->query;110struct intel_perf_context *perf_ctx = ice->perf_ctx;111112return (perf_query->begin_succeeded = intel_perf_begin_query(perf_ctx, obj));113}114115static void116iris_end_perf_query(struct pipe_context *pipe, struct pipe_query *q)117{118struct iris_context *ice = (void *) pipe;119struct iris_perf_query *perf_query = (struct iris_perf_query *) q;120struct intel_perf_query_object *obj = perf_query->query;121struct intel_perf_context *perf_ctx = ice->perf_ctx;122123if (perf_query->begin_succeeded)124intel_perf_end_query(perf_ctx, obj);125}126127static void128iris_delete_perf_query(struct pipe_context *pipe, struct pipe_query *q)129{130struct iris_context *ice = (void *) pipe;131struct iris_perf_query *perf_query = (struct iris_perf_query *) q;132struct intel_perf_query_object *obj = perf_query->query;133struct intel_perf_context *perf_ctx = ice->perf_ctx;134135intel_perf_delete_query(perf_ctx, obj);136free(q);137}138139static void140iris_get_perf_query_info(struct pipe_context *pipe,141unsigned query_index,142const char **name,143uint32_t *data_size,144uint32_t *n_counters,145uint32_t *n_active)146{147struct iris_context *ice = (void *) pipe;148struct intel_perf_context *perf_ctx = ice->perf_ctx;149struct intel_perf_config *perf_cfg = intel_perf_config(perf_ctx);150const struct intel_perf_query_info *info = &perf_cfg->queries[query_index];151152*name = info->name;153*data_size = info->data_size;154*n_counters = info->n_counters;155*n_active = intel_perf_active_queries(perf_ctx, info);156}157158static void159iris_get_perf_counter_info(struct pipe_context *pipe,160unsigned query_index,161unsigned counter_index,162const char **name,163const char **desc,164uint32_t *offset,165uint32_t *data_size,166uint32_t *type_enum,167uint32_t *data_type_enum,168uint64_t *raw_max)169{170struct iris_context *ice = (void *) pipe;171struct intel_perf_context *perf_ctx = ice->perf_ctx;172struct intel_perf_config *perf_cfg = intel_perf_config(perf_ctx);173const struct intel_perf_query_info *info = &perf_cfg->queries[query_index];174const struct intel_perf_query_counter *counter =175&info->counters[counter_index];176177*name = counter->name;178*desc = counter->desc;179*offset = counter->offset;180*data_size = intel_perf_query_counter_get_size(counter);181*type_enum = counter->type;182*data_type_enum = counter->data_type;183*raw_max = counter->raw_max;184}185186static void187iris_wait_perf_query(struct pipe_context *pipe, struct pipe_query *q)188{189struct iris_context *ice = (void *) pipe;190struct iris_perf_query *perf_query = (struct iris_perf_query *) q;191struct intel_perf_query_object *obj = perf_query->query;192struct intel_perf_context *perf_ctx = ice->perf_ctx;193194if (perf_query->begin_succeeded)195intel_perf_wait_query(perf_ctx, obj, &ice->batches[IRIS_BATCH_RENDER]);196}197198static bool199iris_is_perf_query_ready(struct pipe_context *pipe, struct pipe_query *q)200{201struct iris_context *ice = (void *) pipe;202struct iris_perf_query *perf_query = (struct iris_perf_query *) q;203struct intel_perf_query_object *obj = perf_query->query;204struct intel_perf_context *perf_ctx = ice->perf_ctx;205206if (perf_query->base.Ready)207return true;208if (!perf_query->begin_succeeded)209return true;210211return intel_perf_is_query_ready(perf_ctx, obj,212&ice->batches[IRIS_BATCH_RENDER]);213}214215static bool216iris_get_perf_query_data(struct pipe_context *pipe,217struct pipe_query *q,218size_t data_size,219uint32_t *data,220uint32_t *bytes_written)221{222struct iris_context *ice = (void *) pipe;223struct iris_perf_query *perf_query = (struct iris_perf_query *) q;224struct intel_perf_query_object *obj = perf_query->query;225struct intel_perf_context *perf_ctx = ice->perf_ctx;226227if (perf_query->begin_succeeded) {228intel_perf_get_query_data(perf_ctx, obj, &ice->batches[IRIS_BATCH_RENDER],229data_size, data, bytes_written);230}231232return perf_query->begin_succeeded;233}234235void236iris_init_perfquery_functions(struct pipe_context *ctx)237{238ctx->init_intel_perf_query_info = iris_init_perf_query_info;239ctx->get_intel_perf_query_info = iris_get_perf_query_info;240ctx->get_intel_perf_query_counter_info = iris_get_perf_counter_info;241ctx->new_intel_perf_query_obj = iris_new_perf_query_obj;242ctx->begin_intel_perf_query = iris_begin_perf_query;243ctx->end_intel_perf_query = iris_end_perf_query;244ctx->delete_intel_perf_query = iris_delete_perf_query;245ctx->wait_intel_perf_query = iris_wait_perf_query;246ctx->is_intel_perf_query_ready = iris_is_perf_query_ready;247ctx->get_intel_perf_query_data = iris_get_perf_query_data;248}249250251