gpu.h 4.9 KB

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