17ec681f3Smrg/* 27ec681f3Smrg * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org> 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 207ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 217ec681f3Smrg * SOFTWARE. 227ec681f3Smrg * 237ec681f3Smrg * Authors: 247ec681f3Smrg * Rob Clark <robclark@freedesktop.org> 257ec681f3Smrg */ 267ec681f3Smrg 277ec681f3Smrg#ifndef FREEDRENO_PERFCNTR_H_ 287ec681f3Smrg#define FREEDRENO_PERFCNTR_H_ 297ec681f3Smrg 307ec681f3Smrg#include "util/macros.h" 317ec681f3Smrg 327ec681f3Smrg#include "freedreno_dev_info.h" 337ec681f3Smrg 347ec681f3Smrg#ifdef __cplusplus 357ec681f3Smrgextern "C" { 367ec681f3Smrg#endif 377ec681f3Smrg 387ec681f3Smrg/* 397ec681f3Smrg * Mapping very closely to the AMD_performance_monitor extension, adreno has 407ec681f3Smrg * groups of performance counters where each group has N counters, which can 417ec681f3Smrg * select from M different countables (things that can be counted), where 427ec681f3Smrg * generally M > N. 437ec681f3Smrg */ 447ec681f3Smrg 457ec681f3Smrg/* Describes a single counter: */ 467ec681f3Smrgstruct fd_perfcntr_counter { 477ec681f3Smrg /* offset of the select register to choose what to count: */ 487ec681f3Smrg unsigned select_reg; 497ec681f3Smrg /* offset of the lo/hi 32b to read current counter value: */ 507ec681f3Smrg unsigned counter_reg_lo; 517ec681f3Smrg unsigned counter_reg_hi; 527ec681f3Smrg /* Optional, most counters don't have enable/clear registers: */ 537ec681f3Smrg unsigned enable; 547ec681f3Smrg unsigned clear; 557ec681f3Smrg}; 567ec681f3Smrg 577ec681f3Smrgenum fd_perfcntr_type { 587ec681f3Smrg FD_PERFCNTR_TYPE_UINT64, 597ec681f3Smrg FD_PERFCNTR_TYPE_UINT, 607ec681f3Smrg FD_PERFCNTR_TYPE_FLOAT, 617ec681f3Smrg FD_PERFCNTR_TYPE_PERCENTAGE, 627ec681f3Smrg FD_PERFCNTR_TYPE_BYTES, 637ec681f3Smrg FD_PERFCNTR_TYPE_MICROSECONDS, 647ec681f3Smrg FD_PERFCNTR_TYPE_HZ, 657ec681f3Smrg FD_PERFCNTR_TYPE_DBM, 667ec681f3Smrg FD_PERFCNTR_TYPE_TEMPERATURE, 677ec681f3Smrg FD_PERFCNTR_TYPE_VOLTS, 687ec681f3Smrg FD_PERFCNTR_TYPE_AMPS, 697ec681f3Smrg FD_PERFCNTR_TYPE_WATTS, 707ec681f3Smrg}; 717ec681f3Smrg 727ec681f3Smrg/* Whether an average value per frame or a cumulative value should be 737ec681f3Smrg * displayed. 747ec681f3Smrg */ 757ec681f3Smrgenum fd_perfcntr_result_type { 767ec681f3Smrg FD_PERFCNTR_RESULT_TYPE_AVERAGE, 777ec681f3Smrg FD_PERFCNTR_RESULT_TYPE_CUMULATIVE, 787ec681f3Smrg}; 797ec681f3Smrg 807ec681f3Smrg/* Describes a single countable: */ 817ec681f3Smrgstruct fd_perfcntr_countable { 827ec681f3Smrg const char *name; 837ec681f3Smrg /* selector register enum value to select this countable: */ 847ec681f3Smrg unsigned selector; 857ec681f3Smrg 867ec681f3Smrg /* description of the countable: */ 877ec681f3Smrg enum fd_perfcntr_type query_type; 887ec681f3Smrg enum fd_perfcntr_result_type result_type; 897ec681f3Smrg}; 907ec681f3Smrg 917ec681f3Smrg/* Describes an entire counter group: */ 927ec681f3Smrgstruct fd_perfcntr_group { 937ec681f3Smrg const char *name; 947ec681f3Smrg unsigned num_counters; 957ec681f3Smrg const struct fd_perfcntr_counter *counters; 967ec681f3Smrg unsigned num_countables; 977ec681f3Smrg const struct fd_perfcntr_countable *countables; 987ec681f3Smrg}; 997ec681f3Smrg 1007ec681f3Smrgconst struct fd_perfcntr_group *fd_perfcntrs(const struct fd_dev_id *id, unsigned *count); 1017ec681f3Smrg 1027ec681f3Smrg#define COUNTER(_sel, _lo, _hi) { \ 1037ec681f3Smrg .select_reg = REG(_sel), .counter_reg_lo = REG(_lo), \ 1047ec681f3Smrg .counter_reg_hi = REG(_hi), \ 1057ec681f3Smrg } 1067ec681f3Smrg 1077ec681f3Smrg#define COUNTER2(_sel, _lo, _hi, _en, _clr) { \ 1087ec681f3Smrg .select_reg = REG(_sel), .counter_reg_lo = REG(_lo), \ 1097ec681f3Smrg .counter_reg_hi = REG(_hi), .enable = REG(_en), .clear = REG(_clr), \ 1107ec681f3Smrg } 1117ec681f3Smrg 1127ec681f3Smrg#define COUNTABLE(_selector, _query_type, _result_type) { \ 1137ec681f3Smrg .name = #_selector, .selector = _selector, \ 1147ec681f3Smrg .query_type = FD_PERFCNTR_TYPE_##_query_type, \ 1157ec681f3Smrg .result_type = FD_PERFCNTR_RESULT_TYPE_##_result_type, \ 1167ec681f3Smrg } 1177ec681f3Smrg 1187ec681f3Smrg#define GROUP(_name, _counters, _countables) { \ 1197ec681f3Smrg .name = _name, .num_counters = ARRAY_SIZE(_counters), \ 1207ec681f3Smrg .counters = _counters, .num_countables = ARRAY_SIZE(_countables), \ 1217ec681f3Smrg .countables = _countables, \ 1227ec681f3Smrg } 1237ec681f3Smrg 1247ec681f3Smrg#ifdef __cplusplus 1257ec681f3Smrg} /* end of extern "C" */ 1267ec681f3Smrg#endif 1277ec681f3Smrg 1287ec681f3Smrg#endif /* FREEDRENO_PERFCNTR_H_ */ 129