1/*
2 * Copyright © 2021 Collabora, Ltd.
3 * Author: Antonio Caggiano <antonio.caggiano@collabora.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the 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 THE
18 * 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
21 * THE SOFTWARE.
22 */
23
24#ifndef PAN_PERF_H
25#define PAN_PERF_H
26
27#include <stdint.h>
28
29#if defined(__cplusplus)
30extern "C" {
31#endif
32
33#define PAN_PERF_MAX_CATEGORIES 4
34#define PAN_PERF_MAX_COUNTERS 64
35
36struct panfrost_device;
37struct panfrost_perf_category;
38struct panfrost_perf;
39
40enum panfrost_perf_counter_units {
41   PAN_PERF_COUNTER_UNITS_CYCLES,
42   PAN_PERF_COUNTER_UNITS_JOBS,
43   PAN_PERF_COUNTER_UNITS_TASKS,
44   PAN_PERF_COUNTER_UNITS_PRIMITIVES,
45   PAN_PERF_COUNTER_UNITS_BEATS,
46   PAN_PERF_COUNTER_UNITS_REQUESTS,
47   PAN_PERF_COUNTER_UNITS_WARPS,
48   PAN_PERF_COUNTER_UNITS_QUADS,
49   PAN_PERF_COUNTER_UNITS_TILES,
50   PAN_PERF_COUNTER_UNITS_INSTRUCTIONS,
51   PAN_PERF_COUNTER_UNITS_TRANSACTIONS,
52   PAN_PERF_COUNTER_UNITS_THREADS,
53   PAN_PERF_COUNTER_UNITS_BYTES,
54   PAN_PERF_COUNTER_UNITS_PIXELS,
55   PAN_PERF_COUNTER_UNITS_ISSUES,
56};
57
58struct panfrost_perf_counter {
59   const char *name;
60   const char *desc;
61   const char *symbol_name;
62   enum panfrost_perf_counter_units units;
63   // Offset of this counter's value within the category
64   uint32_t offset;
65   unsigned category_index;
66};
67
68struct panfrost_perf_category {
69   const char *name;
70
71   struct panfrost_perf_counter counters[PAN_PERF_MAX_COUNTERS];
72   uint32_t n_counters;
73
74   /* Offset of this category within the counters memory block */
75   unsigned offset;
76};
77
78struct panfrost_perf_config {
79   const char *name;
80
81   struct panfrost_perf_category categories[PAN_PERF_MAX_CATEGORIES];
82   uint32_t n_categories;
83};
84
85struct panfrost_perf {
86   struct panfrost_device *dev;
87
88   const struct panfrost_perf_config* cfg;
89
90   // Memory where to dump counter values
91   uint32_t *counter_values;
92   uint32_t n_counter_values;
93
94   /* Offsets of categories */
95   unsigned category_offset[PAN_PERF_MAX_CATEGORIES];
96};
97
98uint32_t
99panfrost_perf_counter_read(const struct panfrost_perf_counter *counter,
100            const struct panfrost_perf *perf);
101
102void
103panfrost_perf_init(struct panfrost_perf *perf, struct panfrost_device *dev);
104
105int
106panfrost_perf_enable(struct panfrost_perf *perf);
107
108int
109panfrost_perf_disable(struct panfrost_perf *perf);
110
111int
112panfrost_perf_dump(struct panfrost_perf *perf);
113
114#if defined(__cplusplus)
115} // extern "C"
116#endif
117
118#endif // PAN_PERF_H
119