1 #undef TRACE_SYSTEM 2 #define TRACE_SYSTEM gpu 3 4 #if !defined(_TRACE_GPU_H) || defined(TRACE_HEADER_MULTI_READ) 5 #define _TRACE_GPU_H 6 7 #include <linux/tracepoint.h> 8 #include <linux/time.h> 9 10 #define show_secs_from_ns(ns) \ 11 ({ \ 12 u64 t = ns + (NSEC_PER_USEC / 2); \ 13 do_div(t, NSEC_PER_SEC); \ 14 t; \ 15 }) 16 17 #define show_usecs_from_ns(ns) \ 18 ({ \ 19 u64 t = ns + (NSEC_PER_USEC / 2) ; \ 20 u32 rem; \ 21 do_div(t, NSEC_PER_USEC); \ 22 rem = do_div(t, USEC_PER_SEC); \ 23 }) 24 25 /* 26 * The gpu_sched_switch event indicates that a switch from one GPU context to 27 * another occurred on one of the GPU hardware blocks. 28 * 29 * The gpu_name argument identifies the GPU hardware block. Each independently 30 * scheduled GPU hardware block should have a different name. This may be used 31 * in different ways for different GPUs. For example, if a GPU includes 32 * multiple processing cores it may use names "GPU 0", "GPU 1", etc. If a GPU 33 * includes a separately scheduled 2D and 3D hardware block, it might use the 34 * names "2D" and "3D". 35 * 36 * The timestamp argument is the timestamp at which the switch occurred on the 37 * GPU. These timestamps are in units of nanoseconds and must use 38 * approximately the same time as sched_clock, though they need not come from 39 * any CPU clock. The timestamps for a single hardware block must be 40 * monotonically nondecreasing. This means that if a variable compensation 41 * offset is used to translate from some other clock to the sched_clock, then 42 * care must be taken when increasing that offset, and doing so may result in 43 * multiple events with the same timestamp. 44 * 45 * The next_ctx_id argument identifies the next context that was running on 46 * the GPU hardware block. A value of 0 indicates that the hardware block 47 * will be idle. 48 * 49 * The next_prio argument indicates the priority of the next context at the 50 * time of the event. The exact numeric values may mean different things for 51 * different GPUs, but they should follow the rule that lower values indicate a 52 * higher priority. 53 * 54 * The next_job_id argument identifies the batch of work that the GPU will be 55 * working on. This should correspond to a job_id that was previously traced 56 * as a gpu_job_enqueue event when the batch of work was created. 57 */ 58 TRACE_EVENT(gpu_sched_switch, 59 60 TP_PROTO(const char *gpu_name, u64 timestamp, 61 u32 next_ctx_id, s32 next_prio, u32 next_job_id), 62 63 TP_ARGS(gpu_name, timestamp, next_ctx_id, next_prio, next_job_id), 64 65 TP_STRUCT__entry( 66 __string( gpu_name, gpu_name ) 67 __field( u64, timestamp ) 68 __field( u32, next_ctx_id ) 69 __field( s32, next_prio ) 70 __field( u32, next_job_id ) 71 ), 72 73 TP_fast_assign( 74 __assign_str(gpu_name, gpu_name); 75 __entry->timestamp = timestamp; 76 __entry->next_ctx_id = next_ctx_id; 77 __entry->next_prio = next_prio; 78 __entry->next_job_id = next_job_id; 79 ), 80 81 TP_printk("gpu_name=%s ts=%llu.%06lu next_ctx_id=%lu next_prio=%ld " 82 "next_job_id=%lu", 83 __get_str(gpu_name), 84 (unsigned long long)show_secs_from_ns(__entry->timestamp), 85 (unsigned long)show_usecs_from_ns(__entry->timestamp), 86 (unsigned long)__entry->next_ctx_id, 87 (long)__entry->next_prio, 88 (unsigned long)__entry->next_job_id) 89 ); 90 91 /* 92 * The gpu_job_enqueue event indicates that a batch of work has been queued up 93 * to be processed by the GPU. This event is not intended to indicate that 94 * the batch of work has been submitted to the GPU hardware, but rather that 95 * it has been submitted to the GPU kernel driver. 96 * 97 * This event should be traced on the thread that initiated the work being 98 * queued. For example, if a batch of work is submitted to the kernel by a 99 * userland thread, the event should be traced on that thread. 100 * 101 * The ctx_id field identifies the GPU context in which the batch of work 102 * being queued is to be run. 103 * 104 * The job_id field identifies the batch of work being queued within the given 105 * GPU context. The first batch of work submitted for a given GPU context 106 * should have a job_id of 0, and each subsequent batch of work should 107 * increment the job_id by 1. 108 * 109 * The type field identifies the type of the job being enqueued. The job 110 * types may be different for different GPU hardware. For example, a GPU may 111 * differentiate between "2D", "3D", and "compute" jobs. 112 */ 113 TRACE_EVENT(gpu_job_enqueue, 114 115 TP_PROTO(u32 ctx_id, u32 job_id, const char *type), 116 117 TP_ARGS(ctx_id, job_id, type), 118 119 TP_STRUCT__entry( 120 __field( u32, ctx_id ) 121 __field( u32, job_id ) 122 __string( type, type ) 123 ), 124 125 TP_fast_assign( 126 __entry->ctx_id = ctx_id; 127 __entry->job_id = job_id; 128 __assign_str(type, type); 129 ), 130 131 TP_printk("ctx_id=%lu job_id=%lu type=%s", 132 (unsigned long)__entry->ctx_id, 133 (unsigned long)__entry->job_id, 134 __get_str(type)) 135 ); 136 137 #undef show_secs_from_ns 138 #undef show_usecs_from_ns 139 140 #endif /* _TRACE_GPU_H */ 141 142 /* This part must be outside protection */ 143 #include <trace/define_trace.h> 144