1 /* 2 * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Rob Clark <robclark@freedesktop.org> 25 */ 26 27 #ifndef FREEDRENO_PERFCNTR_H_ 28 #define FREEDRENO_PERFCNTR_H_ 29 30 #include "util/macros.h" 31 32 /* 33 * Mapping very closely to the AMD_performance_monitor extension, adreno has 34 * groups of performance counters where each group has N counters, which can 35 * select from M different countables (things that can be counted), where 36 * generally M > N. 37 */ 38 39 /* Describes a single counter: */ 40 struct fd_perfcntr_counter { 41 /* offset of the select register to choose what to count: */ 42 unsigned select_reg; 43 /* offset of the lo/hi 32b to read current counter value: */ 44 unsigned counter_reg_lo; 45 unsigned counter_reg_hi; 46 /* Optional, most counters don't have enable/clear registers: */ 47 unsigned enable; 48 unsigned clear; 49 }; 50 51 52 enum fd_perfcntr_type { 53 FD_PERFCNTR_TYPE_UINT64, 54 FD_PERFCNTR_TYPE_UINT, 55 FD_PERFCNTR_TYPE_FLOAT, 56 FD_PERFCNTR_TYPE_PERCENTAGE, 57 FD_PERFCNTR_TYPE_BYTES, 58 FD_PERFCNTR_TYPE_MICROSECONDS, 59 FD_PERFCNTR_TYPE_HZ, 60 FD_PERFCNTR_TYPE_DBM, 61 FD_PERFCNTR_TYPE_TEMPERATURE, 62 FD_PERFCNTR_TYPE_VOLTS, 63 FD_PERFCNTR_TYPE_AMPS, 64 FD_PERFCNTR_TYPE_WATTS, 65 }; 66 67 /* Whether an average value per frame or a cumulative value should be 68 * displayed. 69 */ 70 enum fd_perfcntr_result_type { 71 FD_PERFCNTR_RESULT_TYPE_AVERAGE, 72 FD_PERFCNTR_RESULT_TYPE_CUMULATIVE, 73 }; 74 75 76 /* Describes a single countable: */ 77 struct fd_perfcntr_countable { 78 const char *name; 79 /* selector register enum value to select this countable: */ 80 unsigned selector; 81 82 /* description of the countable: */ 83 enum fd_perfcntr_type query_type; 84 enum fd_perfcntr_result_type result_type; 85 }; 86 87 /* Describes an entire counter group: */ 88 struct fd_perfcntr_group { 89 const char *name; 90 unsigned num_counters; 91 const struct fd_perfcntr_counter *counters; 92 unsigned num_countables; 93 const struct fd_perfcntr_countable *countables; 94 }; 95 96 const struct fd_perfcntr_group *fd_perfcntrs(unsigned gpu_id, unsigned *count); 97 98 #define COUNTER(_sel, _lo, _hi) { \ 99 .select_reg = REG(_sel), \ 100 .counter_reg_lo = REG(_lo), \ 101 .counter_reg_hi = REG(_hi), \ 102 } 103 104 #define COUNTER2(_sel, _lo, _hi, _en, _clr) { \ 105 .select_reg = REG(_sel), \ 106 .counter_reg_lo = REG(_lo), \ 107 .counter_reg_hi = REG(_hi), \ 108 .enable = REG(_en), \ 109 .clear = REG(_clr), \ 110 } 111 112 #define COUNTABLE(_selector, _query_type, _result_type) { \ 113 .name = #_selector, \ 114 .selector = _selector, \ 115 .query_type = FD_PERFCNTR_TYPE_ ## _query_type, \ 116 .result_type = FD_PERFCNTR_RESULT_TYPE_ ## _result_type, \ 117 } 118 119 #define GROUP(_name, _counters, _countables) { \ 120 .name = _name, \ 121 .num_counters = ARRAY_SIZE(_counters), \ 122 .counters = _counters, \ 123 .num_countables = ARRAY_SIZE(_countables), \ 124 .countables = _countables, \ 125 } 126 127 #endif /* FREEDRENO_PERFCNTR_H_ */ 128