xref: /aosp_15_r20/external/mesa3d/src/freedreno/perfcntrs/freedreno_perfcntr.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2018 Rob Clark <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Rob Clark <[email protected]>
7  */
8 
9 #ifndef FREEDRENO_PERFCNTR_H_
10 #define FREEDRENO_PERFCNTR_H_
11 
12 #include "util/macros.h"
13 
14 #include "freedreno_dev_info.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /*
21  * Mapping very closely to the AMD_performance_monitor extension, adreno has
22  * groups of performance counters where each group has N counters, which can
23  * select from M different countables (things that can be counted), where
24  * generally M > N.
25  */
26 
27 /* Describes a single counter: */
28 struct fd_perfcntr_counter {
29    /* offset of the select register to choose what to count: */
30    unsigned select_reg;
31    /* offset of the lo/hi 32b to read current counter value: */
32    unsigned counter_reg_lo;
33    unsigned counter_reg_hi;
34    /* Optional, most counters don't have enable/clear registers: */
35    unsigned enable;
36    unsigned clear;
37 };
38 
39 enum fd_perfcntr_type {
40    FD_PERFCNTR_TYPE_UINT64,
41    FD_PERFCNTR_TYPE_UINT,
42    FD_PERFCNTR_TYPE_FLOAT,
43    FD_PERFCNTR_TYPE_PERCENTAGE,
44    FD_PERFCNTR_TYPE_BYTES,
45    FD_PERFCNTR_TYPE_MICROSECONDS,
46    FD_PERFCNTR_TYPE_HZ,
47    FD_PERFCNTR_TYPE_DBM,
48    FD_PERFCNTR_TYPE_TEMPERATURE,
49    FD_PERFCNTR_TYPE_VOLTS,
50    FD_PERFCNTR_TYPE_AMPS,
51    FD_PERFCNTR_TYPE_WATTS,
52 };
53 
54 /* Whether an average value per frame or a cumulative value should be
55  * displayed.
56  */
57 enum fd_perfcntr_result_type {
58    FD_PERFCNTR_RESULT_TYPE_AVERAGE,
59    FD_PERFCNTR_RESULT_TYPE_CUMULATIVE,
60 };
61 
62 /* Describes a single countable: */
63 struct fd_perfcntr_countable {
64    const char *name;
65    /* selector register enum value to select this countable: */
66    unsigned selector;
67 
68    /* description of the countable: */
69    enum fd_perfcntr_type query_type;
70    enum fd_perfcntr_result_type result_type;
71 };
72 
73 /* Describes an entire counter group: */
74 struct fd_perfcntr_group {
75    const char *name;
76    unsigned num_counters;
77    const struct fd_perfcntr_counter *counters;
78    unsigned num_countables;
79    const struct fd_perfcntr_countable *countables;
80 };
81 
82 const struct fd_perfcntr_group *fd_perfcntrs(const struct fd_dev_id *id, unsigned *count);
83 
84 #define COUNTER_BASE(_sel, _lo, _hi) {                                         \
85       .select_reg = _sel, .counter_reg_lo = _lo, .counter_reg_hi = _hi,        \
86    }
87 
88 #define COUNTER(_sel, _lo, _hi) COUNTER_BASE(REG(_sel), REG(_lo), REG(_hi))
89 
90 #define COUNTER2(_sel, _lo, _hi, _en, _clr) {                                  \
91       .select_reg = REG(_sel), .counter_reg_lo = REG(_lo),                     \
92       .counter_reg_hi = REG(_hi), .enable = REG(_en), .clear = REG(_clr),      \
93    }
94 
95 #define COUNTABLE_BASE(_sel_name, _sel, _query_type, _result_type ) {          \
96       .name = _sel_name, .selector = _sel,                                     \
97       .query_type = FD_PERFCNTR_TYPE_##_query_type,                            \
98       .result_type = FD_PERFCNTR_RESULT_TYPE_##_result_type,                   \
99    }
100 
101 #define COUNTABLE(_selector, _query_type, _result_type)                        \
102    COUNTABLE_BASE(#_selector, _selector, _query_type, _result_type)
103 
104 #define GROUP(_name, _counters, _countables) {                                 \
105       .name = _name, .num_counters = ARRAY_SIZE(_counters),                    \
106       .counters = _counters, .num_countables = ARRAY_SIZE(_countables),        \
107       .countables = _countables,                                               \
108    }
109 
110 #ifdef __cplusplus
111 } /* end of extern "C" */
112 #endif
113 
114 #endif /* FREEDRENO_PERFCNTR_H_ */
115