1 /* 2 * Copyright © 2020 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 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef INTEL_MEASURE_H 25 #define INTEL_MEASURE_H 26 27 #include <pthread.h> 28 #include <stdio.h> 29 #include <stdbool.h> 30 #include <stdint.h> 31 32 #include "util/list.h" 33 34 enum intel_measure_snapshot_type { 35 INTEL_SNAPSHOT_UNDEFINED, 36 INTEL_SNAPSHOT_BLIT, 37 INTEL_SNAPSHOT_CCS_AMBIGUATE, 38 INTEL_SNAPSHOT_CCS_COLOR_CLEAR, 39 INTEL_SNAPSHOT_CCS_PARTIAL_RESOLVE, 40 INTEL_SNAPSHOT_CCS_RESOLVE, 41 INTEL_SNAPSHOT_COMPUTE, 42 INTEL_SNAPSHOT_COPY, 43 INTEL_SNAPSHOT_DRAW, 44 INTEL_SNAPSHOT_HIZ_AMBIGUATE, 45 INTEL_SNAPSHOT_HIZ_CLEAR, 46 INTEL_SNAPSHOT_HIZ_RESOLVE, 47 INTEL_SNAPSHOT_MCS_AMBIGUATE, 48 INTEL_SNAPSHOT_MCS_COLOR_CLEAR, 49 INTEL_SNAPSHOT_MCS_PARTIAL_RESOLVE, 50 INTEL_SNAPSHOT_SLOW_COLOR_CLEAR, 51 INTEL_SNAPSHOT_SLOW_DEPTH_CLEAR, 52 INTEL_SNAPSHOT_SECONDARY_BATCH, 53 INTEL_SNAPSHOT_END, 54 }; 55 56 enum intel_measure_events { 57 INTEL_MEASURE_DRAW = (1 << 0), 58 INTEL_MEASURE_RENDERPASS = (1 << 1), 59 INTEL_MEASURE_SHADER = (1 << 2), 60 INTEL_MEASURE_BATCH = (1 << 3), 61 INTEL_MEASURE_FRAME = (1 << 4), 62 }; 63 64 struct intel_measure_config { 65 66 /* Stderr, or optionally set with INTEL_MEASURE=file={path{ */ 67 FILE *file; 68 69 /* Events that will be measured. Set only one flag, with 70 * INTEL_MEASURE=[draw,rt,shader,batch,frame] */ 71 enum intel_measure_events flags; 72 73 /* Optionally set with INTEL_MEASURE=start={num} */ 74 unsigned start_frame; 75 76 /* Optionally calculated with INTEL_MEASURE=count={num} based on 77 * start_frame 78 */ 79 unsigned end_frame; 80 81 /* Number of events to combine per line of output. Optionally set with 82 * INTEL_MEASURE=interval={num} 83 */ 84 unsigned event_interval; 85 86 /* Max snapshots per batch. Set with 87 * INTEL_MEASURE=batch_size={num}. Additional snapshots will be dropped. 88 */ 89 unsigned batch_size; 90 91 /* Max number of batch measurements that can be buffered, for combining 92 * snapshots into frame or interval data. 93 */ 94 unsigned buffer_size; 95 96 /* Fifo which will be read to enable measurements at run-time. Set with 97 * INTEL_MEASURE=control={path}. `echo {num} > {path}` will collect num 98 * frames of measurements, beginning with the next frame boundary. 99 */ 100 int control_fh; 101 102 /* true when snapshots are currently being collected */ 103 bool enabled; 104 105 /* Measure CPU timing, not GPU timing */ 106 bool cpu_measure; 107 }; 108 109 struct intel_measure_batch; 110 111 struct intel_measure_snapshot { 112 enum intel_measure_snapshot_type type; 113 unsigned count, event_count; 114 const char* event_name; 115 uint32_t renderpass; 116 uint32_t vs, tcs, tes, gs, fs, cs, ms, ts; 117 /* for vulkan secondary command buffers */ 118 struct intel_measure_batch *secondary; 119 }; 120 121 struct intel_measure_buffered_result { 122 struct intel_measure_snapshot snapshot; 123 uint64_t start_ts, end_ts, idle_duration, batch_size; 124 unsigned frame, batch_count, event_index, primary_renderpass; 125 ; 126 }; 127 128 struct intel_measure_ringbuffer { 129 unsigned head, tail; 130 struct intel_measure_buffered_result results[0]; 131 }; 132 133 /* This function will be called when enqueued snapshots have been processed */ 134 typedef void (*intel_measure_release_batch_cb)(struct intel_measure_batch *base); 135 136 struct intel_measure_device { 137 struct intel_measure_config *config; 138 unsigned frame; 139 unsigned render_pass_count; 140 intel_measure_release_batch_cb release_batch; 141 142 /* Holds the list of (iris/anv)_measure_batch snapshots that have been 143 * submitted for rendering, but have not completed. 144 */ 145 pthread_mutex_t mutex; 146 struct list_head queued_snapshots; 147 148 /* Holds completed snapshots that may need to be combined before being 149 * written out 150 */ 151 struct intel_measure_ringbuffer *ringbuffer; 152 }; 153 154 struct intel_measure_batch { 155 struct list_head link; 156 unsigned index; 157 unsigned frame, batch_count, event_count; 158 uint64_t batch_size; 159 uint32_t renderpass, primary_renderpass; 160 uint64_t *timestamps; 161 struct intel_measure_snapshot snapshots[0]; 162 }; 163 164 void intel_measure_init(struct intel_measure_device *device); 165 const char * intel_measure_snapshot_string(enum intel_measure_snapshot_type type); 166 bool intel_measure_state_changed(const struct intel_measure_batch *batch, 167 uint32_t vs, uint32_t tcs, uint32_t tes, 168 uint32_t gs, uint32_t fs, uint32_t cs, 169 uint32_t ms, uint32_t ts); 170 void intel_measure_frame_transition(unsigned frame); 171 172 bool intel_measure_ready(struct intel_measure_batch *batch); 173 174 struct intel_device_info; 175 void intel_measure_print_cpu_result(unsigned int frame, 176 unsigned int batch_count, 177 uint64_t batch_size, 178 unsigned int event_index, 179 unsigned int event_count, 180 unsigned int count, 181 const char* event_name); 182 void intel_measure_gather(struct intel_measure_device *device, 183 const struct intel_device_info *info); 184 185 #endif /* INTEL_MEASURE_H */ 186