1 /* 2 * Copyright © 2021 Collabora, Ltd. 3 * Author: Antonio Caggiano <[email protected]> 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) 30 extern "C" { 31 #endif 32 33 #define PAN_PERF_MAX_CATEGORIES 4 34 #define PAN_PERF_MAX_COUNTERS 64 35 36 struct pan_kmod_dev; 37 struct pan_kmod_dev_props; 38 struct panfrost_model; 39 struct panfrost_perf_category; 40 struct panfrost_perf; 41 42 enum panfrost_perf_counter_units { 43 PAN_PERF_COUNTER_UNITS_CYCLES, 44 PAN_PERF_COUNTER_UNITS_JOBS, 45 PAN_PERF_COUNTER_UNITS_TASKS, 46 PAN_PERF_COUNTER_UNITS_PRIMITIVES, 47 PAN_PERF_COUNTER_UNITS_BEATS, 48 PAN_PERF_COUNTER_UNITS_REQUESTS, 49 PAN_PERF_COUNTER_UNITS_WARPS, 50 PAN_PERF_COUNTER_UNITS_QUADS, 51 PAN_PERF_COUNTER_UNITS_TILES, 52 PAN_PERF_COUNTER_UNITS_INSTRUCTIONS, 53 PAN_PERF_COUNTER_UNITS_TRANSACTIONS, 54 PAN_PERF_COUNTER_UNITS_THREADS, 55 PAN_PERF_COUNTER_UNITS_BYTES, 56 PAN_PERF_COUNTER_UNITS_PIXELS, 57 PAN_PERF_COUNTER_UNITS_ISSUES, 58 }; 59 60 struct panfrost_perf_counter { 61 const char *name; 62 const char *desc; 63 const char *symbol_name; 64 enum panfrost_perf_counter_units units; 65 // Offset of this counter's value within the category 66 uint32_t offset; 67 unsigned category_index; 68 }; 69 70 struct panfrost_perf_category { 71 const char *name; 72 73 struct panfrost_perf_counter counters[PAN_PERF_MAX_COUNTERS]; 74 uint32_t n_counters; 75 76 /* Offset of this category within the counters memory block */ 77 unsigned offset; 78 }; 79 80 struct panfrost_perf_config { 81 const char *name; 82 83 struct panfrost_perf_category categories[PAN_PERF_MAX_CATEGORIES]; 84 uint32_t n_categories; 85 }; 86 87 struct panfrost_perf { 88 struct pan_kmod_dev *dev; 89 unsigned core_id_range; 90 const struct panfrost_perf_config *cfg; 91 92 // Memory where to dump counter values 93 uint32_t *counter_values; 94 uint32_t n_counter_values; 95 96 /* Offsets of categories */ 97 unsigned category_offset[PAN_PERF_MAX_CATEGORIES]; 98 }; 99 100 uint32_t panfrost_perf_counter_read(const struct panfrost_perf_counter *counter, 101 const struct panfrost_perf *perf); 102 103 void panfrost_perf_init(struct panfrost_perf *perf, int fd); 104 105 int panfrost_perf_enable(struct panfrost_perf *perf); 106 107 int panfrost_perf_disable(struct panfrost_perf *perf); 108 109 int panfrost_perf_dump(struct panfrost_perf *perf); 110 111 #if defined(__cplusplus) 112 } // extern "C" 113 #endif 114 115 #endif // PAN_PERF_H 116