| 1 |
/* |
| 2 |
* Copyright © 2026 Amazon.com, Inc. or its affiliates. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef __PAN_TRACE_H |
| 8 |
#define __PAN_TRACE_H |
| 9 |
|
| 10 |
#include "util/perf/cpu_trace.h" |
| 11 |
|
| 12 |
#ifdef __cplusplus |
| 13 |
extern "C" { |
| 14 |
#endif |
| 15 |
|
| 16 |
/* Panfrost wrappers for Mesa CPU scope traces. |
| 17 |
* |
| 18 |
* CPU tracing (not to be confused with GPU command stream tracing with |
| 19 |
* PAN_MESA_DEBUG=trace) is often enabled in release builds. Since each trace |
| 20 |
* pushed down the underlying tracing backend (Perfetto, Gpuvis, sysprof, etc) |
| 21 |
* has a slight cost, Panfrost extends the Mesa CPU scope traces by |
| 22 |
* associating each trace to a category that must be enabled at run-time. This |
| 23 |
* allows to keep adding useful trace points into Panfrost without worrying |
| 24 |
* about the implied inherent latency. |
| 25 |
* |
| 26 |
* There are 3 categories ("lib" for the shared utilities, "gl" for Gallium, |
| 27 |
* "vk" for PanVK) divided into subcategories so that subsystems can easily be |
| 28 |
* traced. A list of categories can be passed to Panfrost through the |
| 29 |
* PAN_CPU_TRACE environment variable like that: |
| 30 |
* |
| 31 |
* $ PAN_CPU_TRACE=gl,lib program |
| 32 |
* |
| 33 |
* Passing a category enables traces for all its subcategories. Subcategories |
| 34 |
* can be passed instead for finer grained traces like that: |
| 35 |
* |
| 36 |
* $ PAN_CPU_TRACE=gl.blit,gl.bo,gl.job program |
| 37 |
*/ |
| 38 |
|
| 39 |
/* Panfrost trace categories. |
| 40 |
* |
| 41 |
* To be kept in sync with the categories_table array in pan_trace.c. |
| 42 |
*/ |
| 43 |
/* clang-format off */ |
| 44 |
enum pan_trace_category { |
| 45 |
/* Library categories. */ |
| 46 |
PAN_TRACE_LIB_AFBC = BITFIELD_BIT(1), /* "lib.afbc" */ |
| 47 |
PAN_TRACE_LIB_DESC = BITFIELD_BIT(2), /* "lib.desc" */ |
| 48 |
PAN_TRACE_LIB_KMOD = BITFIELD_BIT(3), /* "lib.kmod" */ |
| 49 |
|
| 50 |
/* Gallium categories. */ |
| 51 |
PAN_TRACE_GL_BLIT = BITFIELD_BIT(4), /* "gl.blit" */ |
| 52 |
PAN_TRACE_GL_BO = BITFIELD_BIT(5), /* "gl.bo" */ |
| 53 |
PAN_TRACE_GL_CMDSTREAM = BITFIELD_BIT(6), /* "gl.cmdstream" */ |
| 54 |
PAN_TRACE_GL_CONTEXT = BITFIELD_BIT(7), /* "gl.context" */ |
| 55 |
PAN_TRACE_GL_CSF = BITFIELD_BIT(8), /* "gl.csf" */ |
| 56 |
PAN_TRACE_GL_DISK_CACHE = BITFIELD_BIT(9), /* "gl.disk_cache" */ |
| 57 |
PAN_TRACE_GL_FB_PRELOAD = BITFIELD_BIT(10), /* "gl.fb_preload" */ |
| 58 |
PAN_TRACE_GL_JM = BITFIELD_BIT(11), /* "gl.jm" */ |
| 59 |
PAN_TRACE_GL_JOB = BITFIELD_BIT(12), /* "gl.job" */ |
| 60 |
PAN_TRACE_GL_MEMPOOL = BITFIELD_BIT(13), /* "gl.mempool" */ |
| 61 |
PAN_TRACE_GL_RESOURCE = BITFIELD_BIT(14), /* "gl.resource" */ |
| 62 |
PAN_TRACE_GL_SHADER = BITFIELD_BIT(15), /* "gl.shader" */ |
| 63 |
|
| 64 |
/* Vulkan categories. */ |
| 65 |
PAN_TRACE_VK_CSF = BITFIELD_BIT(16), /* "vk.csf" */ |
| 66 |
}; |
| 67 |
/* clang-format on */ |
| 68 |
|
| 69 |
extern uint64_t pan_trace_categories; |
| 70 |
|
| 71 |
/* Add a Mesa CPU scope trace for a given Panfrost category using printf like |
| 72 |
* formatting. |
| 73 |
*/ |
| 74 |
#define PAN_TRACE_SCOPE(category, format, ...) \ |
| 75 |
MESA_TRACE_SCOPE_IF(category & pan_trace_categories, format, ##__VA_ARGS__) |
| 76 |
|
| 77 |
/* Add a Mesa CPU scope trace for a given Panfrost category using current |
| 78 |
* function name. |
| 79 |
*/ |
| 80 |
#define PAN_TRACE_FUNC(category) \ |
| 81 |
MESA_TRACE_FUNC_IF(category & pan_trace_categories) |
| 82 |
|
| 83 |
/* Parse the PAN_CPU_TRACE environment variable and initialize CPU tracing. |
| 84 |
* The PAN_CPU_TRACE environment variable stores a list of categories (see |
| 85 |
* enum pan_trace_category) separated by a comma, a semicolon or a space. |
| 86 |
*/ |
| 87 |
void pan_trace_init(void); |
| 88 |
|
| 89 |
#ifdef __cplusplus |
| 90 |
} /* extern C */ |
| 91 |
#endif |
| 92 |
|
| 93 |
#endif /* __PAN_TRACE_H */ |