Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_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* Christian Gmeiner <[email protected]>25*/2627#include "etnaviv_context.h"28#include "etnaviv_perfmon.h"29#include "etnaviv_screen.h"3031static const char *group_names[] = {32[ETNA_QUERY_HI_GROUP_ID] = "HI",33[ETNA_QUERY_PE_GROUP_ID] = "PE",34[ETNA_QUERY_SH_GROUP_ID] = "SH",35[ETNA_QUERY_PA_GROUP_ID] = "PA",36[ETNA_QUERY_SE_GROUP_ID] = "SE",37[ETNA_QUERY_RA_GROUP_ID] = "RA",38[ETNA_QUERY_TX_GROUP_ID] = "TX",39[ETNA_QUERY_MC_GROUP_ID] = "MC",40};4142static const struct etna_perfmon_config query_config[] = {43{44.name = "hi-total-cycles",45.type = ETNA_QUERY_HI_TOTAL_CYCLES,46.group_id = ETNA_QUERY_HI_GROUP_ID,47.source = (const struct etna_perfmon_source[]) {48{ "HI", "TOTAL_CYCLES" }49}50},51{52.name = "hi-idle-cycles",53.type = ETNA_QUERY_HI_IDLE_CYCLES,54.group_id = ETNA_QUERY_HI_GROUP_ID,55.source = (const struct etna_perfmon_source[]) {56{ "HI", "IDLE_CYCLES" }57}58},59{60.name = "hi-axi-cycles-read-request-stalled",61.type = ETNA_QUERY_HI_AXI_CYCLES_READ_REQUEST_STALLED,62.group_id = ETNA_QUERY_HI_GROUP_ID,63.source = (const struct etna_perfmon_source[]) {64{ "HI", "AXI_CYCLES_READ_REQUEST_STALLED" }65}66},67{68.name = "hi-axi-cycles-write-request-stalled",69.type = ETNA_QUERY_HI_AXI_CYCLES_WRITE_REQUEST_STALLED,70.group_id = ETNA_QUERY_HI_GROUP_ID,71.source = (const struct etna_perfmon_source[]) {72{ "HI", "AXI_CYCLES_WRITE_REQUEST_STALLED" }73}74},75{76.name = "hi-axi-cycles-write-data-stalled",77.type = ETNA_QUERY_HI_AXI_CYCLES_WRITE_DATA_STALLED,78.group_id = ETNA_QUERY_HI_GROUP_ID,79.source = (const struct etna_perfmon_source[]) {80{ "HI", "AXI_CYCLES_WRITE_DATA_STALLED" }81}82},83{84.name = "pe-pixel-count-killed-by-color-pipe",85.type = ETNA_QUERY_PE_PIXEL_COUNT_KILLED_BY_COLOR_PIPE,86.group_id = ETNA_QUERY_PE_GROUP_ID,87.source = (const struct etna_perfmon_source[]) {88{ "PE", "PIXEL_COUNT_KILLED_BY_COLOR_PIPE" }89}90},91{92.name = "pe-pixel-count-killed-by-depth-pipe",93.type = ETNA_QUERY_PE_PIXEL_COUNT_KILLED_BY_DEPTH_PIPE,94.group_id = ETNA_QUERY_PE_GROUP_ID,95.source = (const struct etna_perfmon_source[]) {96{ "PE", "PIXEL_COUNT_KILLED_BY_DEPTH_PIPE" }97}98},99{100.name = "pe-pixel-count-drawn-by-color-pipe",101.type = ETNA_QUERY_PE_PIXEL_COUNT_DRAWN_BY_COLOR_PIPE,102.group_id = ETNA_QUERY_PE_GROUP_ID,103.source = (const struct etna_perfmon_source[]) {104{ "PE", "PIXEL_COUNT_DRAWN_BY_COLOR_PIPE" }105}106},107{108.name = "pe-pixel-count-drawn-by-depth-pipe",109.type = ETNA_QUERY_PE_PIXEL_COUNT_DRAWN_BY_DEPTH_PIPE,110.group_id = ETNA_QUERY_PE_GROUP_ID,111.source = (const struct etna_perfmon_source[]) {112{ "PE", "PIXEL_COUNT_DRAWN_BY_DEPTH_PIPE" }113}114},115{116.name = "sh-shader-cycles",117.type = ETNA_QUERY_SH_SHADER_CYCLES,118.group_id = ETNA_QUERY_SH_GROUP_ID,119.source = (const struct etna_perfmon_source[]) {120{ "SH", "SHADER_CYCLES" }121}122},123{124.name = "sh-ps-inst-counter",125.type = ETNA_QUERY_SH_PS_INST_COUNTER,126.group_id = ETNA_QUERY_SH_GROUP_ID,127.source = (const struct etna_perfmon_source[]) {128{ "SH", "PS_INST_COUNTER" }129}130},131{132.name = "sh-rendered-pixel-counter",133.type = ETNA_QUERY_SH_RENDERED_PIXEL_COUNTER,134.group_id = ETNA_QUERY_SH_GROUP_ID,135.source = (const struct etna_perfmon_source[]) {136{ "SH", "RENDERED_PIXEL_COUNTER" }137}138},139{140.name = "sh-vs-inst-counter",141.type = ETNA_QUERY_SH_VS_INST_COUNTER,142.group_id = ETNA_QUERY_SH_GROUP_ID,143.source = (const struct etna_perfmon_source[]) {144{ "SH", "VS_INST_COUNTER" }145}146},147{148.name = "sh-rendered-vertice-counter",149.type = ETNA_QUERY_SH_RENDERED_VERTICE_COUNTER,150.group_id = ETNA_QUERY_SH_GROUP_ID,151.source = (const struct etna_perfmon_source[]) {152{ "SH", "RENDERED_VERTICE_COUNTER" }153}154},155{156.name = "sh-vtx-branch-inst-counter",157.type = ETNA_QUERY_SH_RENDERED_VERTICE_COUNTER,158.group_id = ETNA_QUERY_SH_GROUP_ID,159.source = (const struct etna_perfmon_source[]) {160{ "SH", "VTX_BRANCH_INST_COUNTER" }161}162},163{164.name = "sh-vtx-texld-inst-counter",165.type = ETNA_QUERY_SH_RENDERED_VERTICE_COUNTER,166.group_id = ETNA_QUERY_SH_GROUP_ID,167.source = (const struct etna_perfmon_source[]) {168{ "SH", "VTX_TEXLD_INST_COUNTER" }169}170},171{172.name = "sh-plx-branch-inst-counter",173.type = ETNA_QUERY_SH_RENDERED_VERTICE_COUNTER,174.group_id = ETNA_QUERY_SH_GROUP_ID,175.source = (const struct etna_perfmon_source[]) {176{ "SH", "PXL_BRANCH_INST_COUNTER" }177}178},179{180.name = "sh-plx-texld-inst-counter",181.type = ETNA_QUERY_SH_RENDERED_VERTICE_COUNTER,182.group_id = ETNA_QUERY_SH_GROUP_ID,183.source = (const struct etna_perfmon_source[]) {184{ "SH", "PXL_TEXLD_INST_COUNTER" }185}186},187{188.name = "pa-input-vtx-counter",189.type = ETNA_QUERY_PA_INPUT_VTX_COUNTER,190.group_id = ETNA_QUERY_PA_GROUP_ID,191.source = (const struct etna_perfmon_source[]) {192{ "PA", "INPUT_VTX_COUNTER" }193}194},195{196.name = "pa-input-prim-counter",197.type = ETNA_QUERY_PA_INPUT_PRIM_COUNTER,198.group_id = ETNA_QUERY_PA_GROUP_ID,199.source = (const struct etna_perfmon_source[]) {200{ "PA", "INPUT_PRIM_COUNTER" }201}202},203{204.name = "pa-output-prim-counter",205.type = ETNA_QUERY_PA_OUTPUT_PRIM_COUNTER,206.group_id = ETNA_QUERY_PA_GROUP_ID,207.source = (const struct etna_perfmon_source[]) {208{ "PA", "OUTPUT_PRIM_COUNTER" }209}210},211{212.name = "pa-depth-clipped-counter",213.type = ETNA_QUERY_PA_DEPTH_CLIPPED_COUNTER,214.group_id = ETNA_QUERY_PA_GROUP_ID,215.source = (const struct etna_perfmon_source[]) {216{ "PA", "DEPTH_CLIPPED_COUNTER" }217}218},219{220.name = "pa-trivial-rejected-counter",221.type = ETNA_QUERY_PA_TRIVIAL_REJECTED_COUNTER,222.group_id = ETNA_QUERY_PA_GROUP_ID,223.source = (const struct etna_perfmon_source[]) {224{ "PA", "TRIVIAL_REJECTED_COUNTER" }225}226},227{228.name = "pa-culled-counter",229.type = ETNA_QUERY_PA_CULLED_COUNTER,230.group_id = ETNA_QUERY_PA_GROUP_ID,231.source = (const struct etna_perfmon_source[]) {232{ "PA", "CULLED_COUNTER" }233}234},235{236.name = "se-culled-triangle-count",237.type = ETNA_QUERY_SE_CULLED_TRIANGLE_COUNT,238.group_id = ETNA_QUERY_SE_GROUP_ID,239.source = (const struct etna_perfmon_source[]) {240{ "SE", "CULLED_TRIANGLE_COUNT" }241}242},243{244.name = "se-culled-lines-count",245.type = ETNA_QUERY_SE_CULLED_LINES_COUNT,246.group_id = ETNA_QUERY_SE_GROUP_ID,247.source = (const struct etna_perfmon_source[]) {248{ "SE", "CULLED_LINES_COUNT" }249}250},251{252.name = "ra-valid-pixel-count",253.type = ETNA_QUERY_RA_VALID_PIXEL_COUNT,254.group_id = ETNA_QUERY_RA_GROUP_ID,255.source = (const struct etna_perfmon_source[]) {256{ "RA", "VALID_PIXEL_COUNT" }257}258},259{260.name = "ra-total-quad-count",261.type = ETNA_QUERY_RA_TOTAL_QUAD_COUNT,262.group_id = ETNA_QUERY_RA_GROUP_ID,263.source = (const struct etna_perfmon_source[]) {264{ "RA", "TOTAL_QUAD_COUNT" }265}266},267{268.name = "ra-valid-quad-count-after-early-z",269.type = ETNA_QUERY_RA_VALID_QUAD_COUNT_AFTER_EARLY_Z,270.group_id = ETNA_QUERY_RA_GROUP_ID,271.source = (const struct etna_perfmon_source[]) {272{ "RA", "VALID_QUAD_COUNT_AFTER_EARLY_Z" }273}274},275{276.name = "ra-total-primitive-count",277.type = ETNA_QUERY_RA_TOTAL_PRIMITIVE_COUNT,278.group_id = ETNA_QUERY_RA_GROUP_ID,279.source = (const struct etna_perfmon_source[]) {280{ "RA", "TOTAL_PRIMITIVE_COUNT" }281}282},283{284.name = "ra-pipe-cache-miss-counter",285.type = ETNA_QUERY_RA_PIPE_CACHE_MISS_COUNTER,286.group_id = ETNA_QUERY_RA_GROUP_ID,287.source = (const struct etna_perfmon_source[]) {288{ "RA", "PIPE_CACHE_MISS_COUNTER" }289}290},291{292.name = "ra-prefetch-cache-miss-counter",293.type = ETNA_QUERY_RA_PREFETCH_CACHE_MISS_COUNTER,294.group_id = ETNA_QUERY_RA_GROUP_ID,295.source = (const struct etna_perfmon_source[]) {296{ "RA", "PREFETCH_CACHE_MISS_COUNTER" }297}298},299{300.name = "ra-pculled-quad-count",301.type = ETNA_QUERY_RA_CULLED_QUAD_COUNT,302.group_id = ETNA_QUERY_RA_GROUP_ID,303.source = (const struct etna_perfmon_source[]) {304{ "RA", "CULLED_QUAD_COUNT" }305}306},307{308.name = "tx-total-bilinear-requests",309.type = ETNA_QUERY_TX_TOTAL_BILINEAR_REQUESTS,310.group_id = ETNA_QUERY_TX_GROUP_ID,311.source = (const struct etna_perfmon_source[]) {312{ "TX", "TOTAL_BILINEAR_REQUESTS" }313}314},315{316.name = "tx-total-trilinear-requests",317.type = ETNA_QUERY_TX_TOTAL_TRILINEAR_REQUESTS,318.group_id = ETNA_QUERY_TX_GROUP_ID,319.source = (const struct etna_perfmon_source[]) {320{ "TX", "TOTAL_TRILINEAR_REQUESTS" }321}322},323{324.name = "tx-total-discarded-texture-requests",325.type = ETNA_QUERY_TX_TOTAL_DISCARDED_TEXTURE_REQUESTS,326.group_id = ETNA_QUERY_TX_GROUP_ID,327.source = (const struct etna_perfmon_source[]) {328{ "TX", "TOTAL_DISCARDED_TEXTURE_REQUESTS" }329}330},331{332.name = "tx-total-texture-requests",333.type = ETNA_QUERY_TX_TOTAL_TEXTURE_REQUESTS,334.group_id = ETNA_QUERY_TX_GROUP_ID,335.source = (const struct etna_perfmon_source[]) {336{ "TX", "TOTAL_TEXTURE_REQUESTS" }337}338},339{340.name = "tx-mem-read-count",341.type = ETNA_QUERY_TX_MEM_READ_COUNT,342.group_id = ETNA_QUERY_TX_GROUP_ID,343.source = (const struct etna_perfmon_source[]) {344{ "TX", "MEM_READ_COUNT" }345}346},347{348.name = "tx-mem-read-in-8b-count",349.type = ETNA_QUERY_TX_MEM_READ_IN_8B_COUNT,350.group_id = ETNA_QUERY_TX_GROUP_ID,351.source = (const struct etna_perfmon_source[]) {352{ "TX", "MEM_READ_IN_8B_COUNT" }353}354},355{356.name = "tx-cache-miss-count",357.type = ETNA_QUERY_TX_CACHE_MISS_COUNT,358.group_id = ETNA_QUERY_TX_GROUP_ID,359.source = (const struct etna_perfmon_source[]) {360{ "TX", "CACHE_MISS_COUNT" }361}362},363{364.name = "tx-cache-hit-texel-count",365.type = ETNA_QUERY_TX_CACHE_HIT_TEXEL_COUNT,366.group_id = ETNA_QUERY_TX_GROUP_ID,367.source = (const struct etna_perfmon_source[]) {368{ "TX", "CACHE_HIT_TEXEL_COUNT" }369}370},371{372.name = "tx-cache-miss-texel-count",373.type = ETNA_QUERY_TX_CACHE_MISS_TEXEL_COUNT,374.group_id = ETNA_QUERY_TX_GROUP_ID,375.source = (const struct etna_perfmon_source[]) {376{ "TX", "CACHE_MISS_TEXEL_COUNT" }377}378},379{380.name = "mc-total-read-req-8b-from-pipeline",381.type = ETNA_QUERY_MC_TOTAL_READ_REQ_8B_FROM_PIPELINE,382.group_id = ETNA_QUERY_MC_GROUP_ID,383.source = (const struct etna_perfmon_source[]) {384{ "MC", "TOTAL_READ_REQ_8B_FROM_PIPELINE" }385}386},387{388.name = "mc-total-read-req-8b-from-ip",389.type = ETNA_QUERY_MC_TOTAL_READ_REQ_8B_FROM_IP,390.group_id = ETNA_QUERY_MC_GROUP_ID,391.source = (const struct etna_perfmon_source[]) {392{ "MC", "TOTAL_READ_REQ_8B_FROM_IP" }393}394},395{396.name = "mc-total-write-req-8b-from-pipeline",397.type = ETNA_QUERY_MC_TOTAL_WRITE_REQ_8B_FROM_PIPELINE,398.group_id = ETNA_QUERY_MC_GROUP_ID,399.source = (const struct etna_perfmon_source[]) {400{ "MC", "TOTAL_WRITE_REQ_8B_FROM_PIPELINE" }401}402}403};404405struct etna_perfmon_signal *406etna_pm_query_signal(struct etna_perfmon *perfmon,407const struct etna_perfmon_source *source)408{409struct etna_perfmon_domain *domain;410411domain = etna_perfmon_get_dom_by_name(perfmon, source->domain);412if (!domain)413return NULL;414415return etna_perfmon_get_sig_by_name(domain, source->signal);416}417418void419etna_pm_query_setup(struct etna_screen *screen)420{421screen->perfmon = etna_perfmon_create(screen->pipe);422423if (!screen->perfmon)424return;425426for (unsigned i = 0; i < ARRAY_SIZE(query_config); i++) {427const struct etna_perfmon_config *cfg = &query_config[i];428429if (!etna_pm_cfg_supported(screen->perfmon, cfg))430continue;431432util_dynarray_append(&screen->supported_pm_queries, unsigned, i);433}434}435436const struct etna_perfmon_config *437etna_pm_query_config(unsigned type)438{439for (unsigned i = 0; i < ARRAY_SIZE(query_config); i++)440if (query_config[i].type == type)441return &query_config[i];442443return NULL;444}445446int447etna_pm_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,448struct pipe_driver_query_info *info)449{450const struct etna_screen *screen = etna_screen(pscreen);451const unsigned num = screen->supported_pm_queries.size / sizeof(unsigned);452unsigned i;453454if (!info)455return num;456457if (index >= num)458return 0;459460i = *util_dynarray_element(&screen->supported_pm_queries, unsigned, index);461assert(i < ARRAY_SIZE(query_config));462463info->name = query_config[i].name;464info->query_type = query_config[i].type;465info->group_id = query_config[i].group_id;466467return 1;468}469470static471unsigned query_count(unsigned group)472{473unsigned count = 0;474475for (unsigned i = 0; i < ARRAY_SIZE(query_config); i++)476if (query_config[i].group_id == group)477count++;478479assert(count);480481return count;482}483484int485etna_pm_get_driver_query_group_info(struct pipe_screen *pscreen,486unsigned index,487struct pipe_driver_query_group_info *info)488{489if (!info)490return ARRAY_SIZE(group_names);491492if (index >= ARRAY_SIZE(group_names))493return 0;494495unsigned count = query_count(index);496497info->name = group_names[index];498info->max_active_queries = count;499info->num_queries = count;500501return 1;502}503504505