Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_query_acc_perfmon.c
4570 views
/*1* Copyright (c) 2017 Etnaviv Project2* Copyright (C) 2017 Zodiac Inflight Innovations3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sub license,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the12* next paragraph) shall be included in all copies or substantial portions13* of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25* Christian Gmeiner <[email protected]>26*/2728#include "util/u_memory.h"2930#include "etnaviv_context.h"31#include "etnaviv_debug.h"32#include "etnaviv_emit.h"33#include "etnaviv_query_acc.h"3435struct etna_pm_query36{37struct etna_acc_query base;3839struct etna_perfmon_signal *signal;40unsigned sequence;41};4243static inline struct etna_pm_query *44etna_pm_query(struct etna_acc_query *aq)45{46return (struct etna_pm_query *)aq;47}4849static inline void50pm_add_signal(struct etna_pm_query *pq, struct etna_perfmon *perfmon,51const struct etna_perfmon_config *cfg)52{53struct etna_perfmon_signal *signal = etna_pm_query_signal(perfmon, cfg->source);5455pq->signal = signal;56}5758static void59pm_query(struct etna_context *ctx, struct etna_acc_query *aq, unsigned flags)60{61struct etna_cmd_stream *stream = ctx->stream;62struct etna_pm_query *pq = etna_pm_query(aq);63unsigned offset;64assert(flags);6566if (aq->samples > 127) {67aq->samples = 127;68BUG("samples overflow perfmon");69}7071/* offset 0 is reserved for seq number */72offset = 1 + aq->samples;7374pq->sequence++;7576/* skip seq number of 0 as the buffer got zeroed out */77pq->sequence = MAX2(pq->sequence, 1);7879struct etna_perf p = {80.flags = flags,81.sequence = pq->sequence,82.bo = etna_resource(aq->prsc)->bo,83.signal = pq->signal,84.offset = offset85};8687etna_cmd_stream_perf(stream, &p);88resource_written(ctx, aq->prsc);8990/* force a flush in !wait case in etna_acc_get_query_result(..) */91aq->no_wait_cnt = 10;92}9394static bool95perfmon_supports(unsigned query_type)96{97return !!etna_pm_query_config(query_type);98}99100static struct etna_acc_query *101perfmon_allocate(struct etna_context *ctx, unsigned query_type)102{103struct etna_pm_query *pq;104const struct etna_perfmon_config *cfg;105106cfg = etna_pm_query_config(query_type);107if (!cfg)108return false;109110if (!etna_pm_cfg_supported(ctx->screen->perfmon, cfg))111return false;112113pq = CALLOC_STRUCT(etna_pm_query);114if (!pq)115return NULL;116117pm_add_signal(pq, ctx->screen->perfmon, cfg);118119return &pq->base;120}121122static void123perfmon_resume(struct etna_acc_query *aq, struct etna_context *ctx)124{125pm_query(ctx, aq, ETNA_PM_PROCESS_PRE);126}127128static void129perfmon_suspend(struct etna_acc_query *aq, struct etna_context *ctx)130{131pm_query(ctx, aq, ETNA_PM_PROCESS_POST);132}133134static bool135perfmon_result(struct etna_acc_query *aq, void *buf,136union pipe_query_result *result)137{138const struct etna_pm_query *pq = etna_pm_query(aq);139uint32_t sum = 0;140uint32_t *ptr = (uint32_t *)buf;141142/* check seq number */143if (pq->sequence > ptr[0])144return false;145146/* jump over seq number */147ptr++;148149assert(aq->samples % 2 == 0);150151/* each pair has a start and end value */152for (unsigned i = 0; i < aq->samples; i += 2)153sum += *(ptr + i + 1) - *(ptr + i);154155result->u32 = sum;156157return true;158}159160const struct etna_acc_sample_provider perfmon_provider = {161.supports = perfmon_supports,162.allocate = perfmon_allocate,163.resume = perfmon_resume,164.suspend = perfmon_suspend,165.result = perfmon_result,166};167168169