| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#ifndef _PERF_BUDGET_H_ |
| 69 |
#define _PERF_BUDGET_H_ |
| 70 |
|
| 71 |
#include <stdbool.h> |
| 72 |
#include <stdint.h> |
| 73 |
|
| 74 |
#ifdef __cplusplus |
| 75 |
extern "C" { |
| 76 |
#endif |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
#define PERF_MAX_ZONES 16 |
| 84 |
#define PERF_RING_ZONES 8 |
| 85 |
#define PERF_ZONE_NAME_MAX 32 |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
#define PERF_SPIN_SPAN 32 |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
#define PERF_BOUNDARY_SLACK 8 |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
#define PERF_MARKER_STACK 8 |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
#define PERF_DEFAULT_CAPACITY 3600 |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
#define PERF_MARKER_PROTOCOL 1 |
| 113 |
|
| 114 |
typedef enum { |
| 115 |
PERF_IDLE_AUTO = 0, |
| 116 |
PERF_IDLE_MARKERS, |
| 117 |
PERF_IDLE_NONE, |
| 118 |
} perf_idle_mode_t; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
typedef struct { |
| 123 |
uint32_t frame; |
| 124 |
uint32_t total; |
| 125 |
uint32_t idle; |
| 126 |
uint32_t irq; |
| 127 |
uint32_t instructions; |
| 128 |
uint32_t host_us; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
uint32_t period_work; |
| 134 |
uint32_t zone[PERF_RING_ZONES]; |
| 135 |
} perf_frame_t; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
static inline uint32_t |
| 140 |
perf_frame_work(const perf_frame_t *f) |
| 141 |
{ |
| 142 |
return f->total - f->idle; |
| 143 |
} |
| 144 |
|
| 145 |
typedef struct { |
| 146 |
uint32_t min, mean, p50, p95, p99, max; |
| 147 |
} perf_stat_t; |
| 148 |
|
| 149 |
typedef struct { |
| 150 |
float seconds; |
| 151 |
int frames; |
| 152 |
uint32_t budget_cycles; |
| 153 |
perf_stat_t work; |
| 154 |
perf_stat_t budget_work; |
| 155 |
perf_stat_t total; |
| 156 |
perf_stat_t irq; |
| 157 |
perf_stat_t host_us; |
| 158 |
int overruns; |
| 159 |
float overrun_pct; |
| 160 |
uint32_t worst_overrun; |
| 161 |
uint32_t worst_frame; |
| 162 |
float mean_utilization; |
| 163 |
float p95_utilization; |
| 164 |
float max_utilization; |
| 165 |
} perf_window_t; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
typedef struct { |
| 174 |
char name[PERF_ZONE_NAME_MAX]; |
| 175 |
uint16_t start; |
| 176 |
uint16_t end; |
| 177 |
int16_t bank; |
| 178 |
bool is_idle; |
| 179 |
bool is_marker; |
| 180 |
uint8_t marker_id; |
| 181 |
bool used; |
| 182 |
} perf_zone_t; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
typedef struct { |
| 187 |
uint32_t frames; |
| 188 |
uint32_t overruns; |
| 189 |
uint32_t worst_overrun; |
| 190 |
uint32_t worst_frame; |
| 191 |
float worst_utilization; |
| 192 |
} perf_overrun_report_t; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
extern bool perf_budget_enabled; |
| 198 |
|
| 199 |
void perf_budget_step_(uint32_t clocks, uint16_t pc, uint8_t pbank, bool waiting, int irq_depth); |
| 200 |
void perf_budget_note_store_(void); |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
static inline void |
| 206 |
perf_budget_step(uint32_t clocks, uint16_t pc, uint8_t pbank, bool waiting, int irq_depth) |
| 207 |
{ |
| 208 |
if (perf_budget_enabled) |
| 209 |
perf_budget_step_(clocks, pc, pbank, waiting, irq_depth); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
static inline void |
| 215 |
perf_budget_note_store(void) |
| 216 |
{ |
| 217 |
if (perf_budget_enabled) |
| 218 |
perf_budget_note_store_(); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
void perf_budget_frame_end(uint32_t host_us); |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
typedef enum { |
| 233 |
PERF_OWNER_UI = 0, |
| 234 |
PERF_OWNER_DAP, |
| 235 |
PERF_OWNER_REMOTE, |
| 236 |
PERF_OWNER_COUNT |
| 237 |
} perf_owner_t; |
| 238 |
|
| 239 |
|
| 240 |
bool perf_budget_arm(perf_owner_t owner, bool want); |
| 241 |
bool perf_budget_owner_wants(perf_owner_t owner); |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
bool perf_budget_set_enabled(bool enabled); |
| 247 |
bool perf_budget_is_enabled(void); |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
void perf_budget_configure(uint32_t machine_khz, uint32_t cycles_per_frame, |
| 254 |
uint16_t scanlines_per_frame); |
| 255 |
|
| 256 |
void perf_budget_set_target_fps(float fps); |
| 257 |
float perf_budget_get_target_fps(void); |
| 258 |
float perf_budget_vsync_hz(void); |
| 259 |
|
| 260 |
uint32_t perf_budget_cycles_per_frame(void); |
| 261 |
uint32_t perf_budget_cycles_per_scanline(void); |
| 262 |
uint32_t perf_budget_budget_cycles(void); |
| 263 |
int perf_budget_frames_per_budget(void); |
| 264 |
|
| 265 |
void perf_budget_set_idle_mode(perf_idle_mode_t mode); |
| 266 |
perf_idle_mode_t perf_budget_get_idle_mode(void); |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
bool perf_budget_set_capacity(int frames); |
| 271 |
int perf_budget_capacity(void); |
| 272 |
|
| 273 |
void perf_budget_reset(void); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
void perf_budget_marker_write(uint8_t value); |
| 292 |
uint8_t perf_budget_marker_read(void); |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
int perf_budget_zone_add(const char *name, uint16_t start, uint16_t end, |
| 297 |
int16_t bank, bool is_idle); |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
int perf_budget_zone_add_marker(const char *name, uint8_t id); |
| 303 |
bool perf_budget_zone_remove(int index); |
| 304 |
void perf_budget_zone_clear(void); |
| 305 |
int perf_budget_zone_count(void); |
| 306 |
bool perf_budget_zone_get(int index, perf_zone_t *out); |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
bool perf_budget_last_frame(perf_frame_t *out); |
| 313 |
bool perf_budget_current_frame(perf_frame_t *out); |
| 314 |
int perf_budget_frame_count(void); |
| 315 |
uint32_t perf_budget_total_frames(void); |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
bool perf_budget_frame_at(int newest_index, perf_frame_t *out); |
| 322 |
|
| 323 |
|
| 324 |
bool perf_budget_window(float seconds, perf_window_t *out); |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
bool perf_budget_zone_window(int zone, float seconds, perf_stat_t *out); |
| 329 |
|
| 330 |
|
| 331 |
bool perf_budget_drain_overruns(perf_overrun_report_t *out); |
| 332 |
|
| 333 |
#ifdef __cplusplus |
| 334 |
} |
| 335 |
#endif |
| 336 |
|
| 337 |
#endif |