2 * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org>
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:
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
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
24 * Rob Clark <robclark@freedesktop.org>
27 #ifndef FREEDRENO_PERFCNTR_H_
28 #define FREEDRENO_PERFCNTR_H_
31 * Mapping very closely to the AMD_performance_monitor extension, adreno has
32 * groups of performance counters where each group has N counters, which can
33 * select from M different countables (things that can be counted), where
37 /* Describes a single counter: */
38 struct fd_perfcntr_counter
{
39 /* offset of the select register to choose what to count: */
41 /* offset of the lo/hi 32b to read current counter value: */
42 unsigned counter_reg_lo
;
43 unsigned counter_reg_hi
;
44 /* Optional, most counters don't have enable/clear registers: */
50 enum fd_perfcntr_type
{
51 FD_PERFCNTR_TYPE_UINT64
,
52 FD_PERFCNTR_TYPE_UINT
,
53 FD_PERFCNTR_TYPE_FLOAT
,
54 FD_PERFCNTR_TYPE_PERCENTAGE
,
55 FD_PERFCNTR_TYPE_BYTES
,
56 FD_PERFCNTR_TYPE_MICROSECONDS
,
59 FD_PERFCNTR_TYPE_TEMPERATURE
,
60 FD_PERFCNTR_TYPE_VOLTS
,
61 FD_PERFCNTR_TYPE_AMPS
,
62 FD_PERFCNTR_TYPE_WATTS
,
65 /* Whether an average value per frame or a cumulative value should be
68 enum fd_perfcntr_result_type
{
69 FD_PERFCNTR_RESULT_TYPE_AVERAGE
,
70 FD_PERFCNTR_RESULT_TYPE_CUMULATIVE
,
74 /* Describes a single countable: */
75 struct fd_perfcntr_countable
{
77 /* selector register enum value to select this countable: */
80 /* description of the countable: */
81 enum fd_perfcntr_type query_type
;
82 enum fd_perfcntr_result_type result_type
;
85 /* Describes an entire counter group: */
86 struct fd_perfcntr_group
{
88 unsigned num_counters
;
89 const struct fd_perfcntr_counter
*counters
;
90 unsigned num_countables
;
91 const struct fd_perfcntr_countable
*countables
;
94 const struct fd_perfcntr_group
*fd_perfcntrs(unsigned gpu_id
, unsigned *count
);
96 #define COUNTER(_sel, _lo, _hi) { \
97 .select_reg = REG(_sel), \
98 .counter_reg_lo = REG(_lo), \
99 .counter_reg_hi = REG(_hi), \
102 #define COUNTER2(_sel, _lo, _hi, _en, _clr) { \
103 .select_reg = REG(_sel), \
104 .counter_reg_lo = REG(_lo), \
105 .counter_reg_hi = REG(_hi), \
106 .enable = REG(_en), \
107 .clear = REG(_clr), \
110 #define COUNTABLE(_selector, _query_type, _result_type) { \
111 .name = #_selector, \
112 .selector = _selector, \
113 .query_type = FD_PERFCNTR_TYPE_ ## _query_type, \
114 .result_type = FD_PERFCNTR_RESULT_TYPE_ ## _result_type, \
117 #define GROUP(_name, _counters, _countables) { \
119 .num_counters = ARRAY_SIZE(_counters), \
120 .counters = _counters, \
121 .num_countables = ARRAY_SIZE(_countables), \
122 .countables = _countables, \
125 #endif /* FREEDRENO_PERFCNTR_H_ */