xref: /aosp_15_r20/external/mesa3d/src/intel/perf/intel_perf_setup.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2018 Intel Corporation
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
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef INTEL_PERF_SETUP_H
25 #define INTEL_PERF_SETUP_H
26 
27 #include "perf/intel_perf.h"
28 
29 #define MIN(a, b) ((a < b) ? (a) : (b))
30 #define MAX(a, b) ((a > b) ? (a) : (b))
31 
32 static struct intel_perf_query_info *
intel_query_alloc(struct intel_perf_config * perf,int ncounters)33 intel_query_alloc(struct intel_perf_config *perf, int ncounters)
34 {
35    struct intel_perf_query_info *query = rzalloc(perf, struct intel_perf_query_info);
36    query->perf = perf;
37    query->kind = INTEL_PERF_QUERY_TYPE_OA;
38    query->n_counters = 0;
39    query->oa_metrics_set_id = 0; /* determined at runtime, via sysfs */
40    query->counters = rzalloc_array(query, struct intel_perf_query_counter, ncounters);
41    query->oa_format = intel_perf_get_oa_format(perf);
42 
43    /* Accumulation buffer offsets... */
44    if (perf->devinfo->verx10 >= 200) {
45       query->gpu_time_offset = 0;
46       query->gpu_clock_offset = query->gpu_time_offset + 1;
47       query->pec_offset = query->gpu_clock_offset + 1;
48       query->perfcnt_offset = query->pec_offset + 64;
49       query->rpstat_offset = query->perfcnt_offset + 2;
50    } else if (perf->devinfo->verx10 >= 125) {
51       query->gpu_time_offset = 0;
52       query->gpu_clock_offset = query->gpu_time_offset + 1;
53       query->a_offset = query->gpu_clock_offset + 1;
54       query->b_offset = query->a_offset + 38;
55       query->c_offset = query->b_offset + 8;
56       query->perfcnt_offset = query->c_offset + 8;
57       query->rpstat_offset = query->perfcnt_offset + 2;
58    } else if (perf->devinfo->verx10 >= 120) {
59       query->gpu_time_offset = 0;
60       query->gpu_clock_offset = query->gpu_time_offset + 1;
61       query->a_offset = query->gpu_clock_offset + 1;
62       query->b_offset = query->a_offset + 36;
63       query->c_offset = query->b_offset + 8;
64       query->perfcnt_offset = query->c_offset + 8;
65       query->rpstat_offset = query->perfcnt_offset + 2;
66    } else {
67       query->gpu_time_offset = 0;
68       query->a_offset = query->gpu_time_offset + 1;
69       query->b_offset = query->a_offset + 45;
70       query->c_offset = query->b_offset + 8;
71       query->perfcnt_offset = query->c_offset + 8;
72       query->rpstat_offset = query->perfcnt_offset + 2;
73    }
74 
75    return query;
76 }
77 
78 struct intel_perf_query_counter_data {
79    uint32_t name_idx;
80    uint32_t desc_idx;
81    uint32_t symbol_name_idx;
82    uint32_t category_idx;
83    enum intel_perf_counter_type type;
84    enum intel_perf_counter_data_type data_type;
85    enum intel_perf_counter_units units;
86 };
87 
88 #endif /* INTEL_PERF_SETUP_H */
89