Skip to contentSkip to conversation

Improve gpu_scheduler trace events + uAPI

PATCH Superseded Pierre-Eric Pelloux-Prayer 5 participants 16 messages Jun 14, 2024 – Jul 10, 2024

Subsystems (4)

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v5 cover Improve gpu_scheduler trace events + uAPI

Hi,

The initial goal of this series was to improve the drm and amdgpu trace events to be able to expose more of the inner workings of the scheduler and drivers to developers via tools.

Then, the series evolved to become focused only on gpu_scheduler. The changes around vblank events will be part of a different series, as well as the amdgpu ones.

Moreover Sima suggested to make some trace events stable uAPI, so tools can rely on them long term.

So, with this v5, the first 3 patches refactor and improve the existing gpu_scheduler events.

The last one adds a documentation entry in drm-uapi.rst.

Useful links:
- userspace tool using the updated events:
https://gitlab.freedesktop.org/tomstdenis/umr/-/merge_requests/37
- gpuvis ticket about this series:
https://github.com/mikesart/gpuvis/issues/87
- v4:
https://lists.freedesktop.org/archives/dri-devel/2024-June/457121.html

Pierre-Eric Pelloux-Prayer (4):
drm/sched: add device name to the drm_sched_process_job event drm/sched: cleanup gpu_scheduler trace events drm/sched: trace dependencies for gpu jobs
drm/doc: document some tracepoints as uAPI

 Documentation/gpu/drm-uapi.rst                |  19 +++
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 124 ++++++++++++++----
 drivers/gpu/drm/scheduler/sched_entity.c      |   8 +-
 drivers/gpu/drm/scheduler/sched_main.c        |   2 +-
 4 files changed, 126 insertions(+), 27 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v5 1/4 drm/sched: add device name to the drm_sched_process_job event

Until the switch from kthread to workqueue, a userspace application could determine the source device from the pid of the thread sending the event.

With workqueues this is not possible anymore, so the event needs to contain the dev_name() to identify the device.

---
 drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +8 -2
index c75302ca3427..1f9c5a884487 100644
@@ -42,6 +42,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			     __field(uint64_t, id)
 			     __field(u32, job_count)
 			     __field(int, hw_job_count)
+			     __string(dev, dev_name(sched_job->sched->dev))
 			     ),
 
 	    TP_fast_assign(
@@ -52,6 +53,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			   __entry->job_count = spsc_queue_count(&entity->job_queue);
 			   __entry->hw_job_count = atomic_read(
 				   &sched_job->sched->credit_count);
+			   __assign_str(dev);
 			   ),
 	    TP_printk("entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d",
 		      __entry->entity, __entry->id,
@@ -64,9 +66,13 @@ DEFINE_EVENT(drm_sched_job, drm_sched_job,
 	    TP_ARGS(sched_job, entity)
 );
 
-DEFINE_EVENT(drm_sched_job, drm_run_job,
+DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
 	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity)
+	    TP_ARGS(sched_job, entity),
+	    TP_printk("dev=%s, entity=%p id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d",
+		      __get_str(dev), __entry->entity, __entry->id,
+		      __entry->fence, __get_str(name),
+		      __entry->job_count, __entry->hw_job_count)
 );
 
 TRACE_EVENT(drm_sched_process_job,
Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH v5 1/4] drm/sched: add device name to the drm_sched_process_job event

Am 14.06.24 um 10:16 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 34 lines

Until the switch from kthread to workqueue, a userspace application could determine the source device from the pid of the thread sending the event.

With workqueues this is not possible anymore, so the event needs to contain the dev_name() to identify the device.

---
  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +2 -0
index c75302ca3427..1f9c5a884487 100644
@@ -42,6 +42,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
  			     __field(uint64_t, id)
  			     __field(u32, job_count)
  			     __field(int, hw_job_count)
+			     __string(dev, dev_name(sched_job->sched->dev))
  			     ),
 
  	    TP_fast_assign(
@@ -52,6 +53,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
  			   __entry->job_count = spsc_queue_count(&entity->job_queue);
  			   __entry->hw_job_count = atomic_read(
  				   &sched_job->sched->credit_count);
+			   __assign_str(dev);
  			   ),
  	    TP_printk("entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d",
  		      __entry->entity, __entry->id,
@@ -64,9 +66,13 @@ DEFINE_EVENT(drm_sched_job, drm_sched_job,
  	    TP_ARGS(sched_job, entity)
  );

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h DEFINE_EVENT(drm_sched_job, drm_sched_job, · line 75

Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +6 -2
 
-DEFINE_EVENT(drm_sched_job, drm_run_job,
+DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
  	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity)
+	    TP_ARGS(sched_job, entity),
+	    TP_printk("dev=%s, entity=%p id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d",
+		      __get_str(dev), __entry->entity, __entry->id,
+		      __entry->fence, __get_str(name),
+		      __entry->job_count, __entry->hw_job_count)

Why not doing that in the TP_printk() of the drm_sched_job event class?

The device should now be available for all trace events of that class.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
  );
 
  TRACE_EVENT(drm_sched_process_job,
#3 lore raw

Re: [PATCH v5 1/4] drm/sched: add device name to the drm_sched_process_job event

Hi,

Le 14/06/2024 à 11:08, Christian König a écrit :

Quoted 40 lines

Am 14.06.24 um 10:16 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 37 lines

Until the switch from kthread to workqueue, a userspace application could determine the source device from the pid of the thread sending the event.

With workqueues this is not possible anymore, so the event needs to contain the dev_name() to identify the device.

---
  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 10 ++++++++--

  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
index c75302ca3427..1f9c5a884487 100644
@@ -42,6 +42,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
                    __field(uint64_t, id)
                    __field(u32, job_count)
                    __field(int, hw_job_count)
+                 __string(dev, dev_name(sched_job->sched->dev))
                    ),

          TP_fast_assign(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
@@ -52,6 +53,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
                  __entry->job_count = spsc_queue_count(&entity->job_queue);

                 __entry->hw_job_count = atomic_read( &sched_job->sched->credit_count);
+               __assign_str(dev);
                 ),
          TP_printk("entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d", __entry->entity, __entry->id,

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -2
@@ -64,9 +66,13 @@ DEFINE_EVENT(drm_sched_job, drm_sched_job,
           TP_ARGS(sched_job, entity)
   );
-DEFINE_EVENT(drm_sched_job, drm_run_job,
+DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
           TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-        TP_ARGS(sched_job, entity)
Quoted 9 lines

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h DEFINE_EVENT(drm_sched_job, drm_sched_job, · line 75

Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +5 -0
+        TP_ARGS(sched_job, entity),
+        TP_printk("dev=%s, entity=%p id=%llu, fence=%p, ring=%s, job 
 count:%u, hw job count:%d",
+              __get_str(dev), __entry->entity, __entry->id,
+              __entry->fence, __get_str(name),
+              __entry->job_count, __entry->hw_job_count)

Why not doing that in the TP_printk() of the drm_sched_job event class?

I didn't because drm_sched_job + drm_run_job usually work in pair so the ring+device information will be available anyway.

But maybe you're right and it's better to add it in the event the job never gets scheduled.

For the other events it's not necessary IMO: the first event will always be drm_sched_job, so it's possible to figure out which the device/ring for a given job.

Regards,
Pierre-eric

Quoted 7 lines

The device should now be available for all trace events of that class.

Regards,
Christian.

Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
   );
   TRACE_EVENT(drm_sched_process_job,
#4 lore raw

Re: [PATCH v5 1/4] drm/sched: add device name to the drm_sched_process_job event

Am 17.06.24 um 14:54 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 53 lines

Hi,

Le 14/06/2024 à 11:08, Christian König a écrit :

Quoted 40 lines

Am 14.06.24 um 10:16 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 37 lines

Until the switch from kthread to workqueue, a userspace application could determine the source device from the pid of the thread sending the event.

With workqueues this is not possible anymore, so the event needs to contain the dev_name() to identify the device.

---
  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 10 ++++++++--

  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
index c75302ca3427..1f9c5a884487 100644
@@ -42,6 +42,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
                    __field(uint64_t, id)
                    __field(u32, job_count)
                    __field(int, hw_job_count)
+                 __string(dev, dev_name(sched_job->sched->dev))
                    ),

          TP_fast_assign(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
@@ -52,6 +53,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
                  __entry->job_count = spsc_queue_count(&entity->job_queue);

                 __entry->hw_job_count = atomic_read( &sched_job->sched->credit_count);
+               __assign_str(dev);
                 ),
          TP_printk("entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d", __entry->entity, __entry->id,

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -2
@@ -64,9 +66,13 @@ DEFINE_EVENT(drm_sched_job, drm_sched_job,
           TP_ARGS(sched_job, entity)
   );
-DEFINE_EVENT(drm_sched_job, drm_run_job,
+DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
           TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-        TP_ARGS(sched_job, entity)
Quoted 9 lines

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h DEFINE_EVENT(drm_sched_job, drm_sched_job, · line 75

Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +5 -0
+        TP_ARGS(sched_job, entity),
+        TP_printk("dev=%s, entity=%p id=%llu, fence=%p, ring=%s, 
 job count:%u, hw job count:%d",
+              __get_str(dev), __entry->entity, __entry->id,
+              __entry->fence, __get_str(name),
+              __entry->job_count, __entry->hw_job_count)

Why not doing that in the TP_printk() of the drm_sched_job event class?

Quoted 5 lines

I didn't because drm_sched_job + drm_run_job usually work in pair so the ring+device information will be available anyway.

But maybe you're right and it's better to add it in the event the job never gets scheduled.

For the other events it's not necessary IMO: the first event will always be drm_sched_job, so it's possible to figure out which the device/ring for a given job.

Yeah, but we have that strace in the trace event even when we don't print it.

I would just go ahead and always print it even when it is available somehow else.

Regards,
Christian.

Quoted 11 lines

Regards,
Pierre-eric

Quoted 7 lines

The device should now be available for all trace events of that class.

Regards,
Christian.

Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
   );
   TRACE_EVENT(drm_sched_process_job,
#5 lore raw

PATCH v5 2/4 drm/sched: cleanup gpu_scheduler trace events

In reply to Pierre-Eric Pelloux-Prayer

A fence uniquely identify a job, so this commits updates the places where a kernel pointer was used as an identifier by:

"fence=(context:%llu, seqno:%lld)"

---
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 45 ++++++++++---------
 1 file changed, 25 insertions(+), 20 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +25 -20
index 1f9c5a884487..f6da377cdb99 100644
@@ -36,28 +36,29 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
 	    TP_ARGS(sched_job, entity),
 	    TP_STRUCT__entry(
-			     __field(struct drm_sched_entity *, entity)
-			     __field(struct dma_fence *, fence)
 			     __string(name, sched_job->sched->name)
 			     __field(uint64_t, id)
 			     __field(u32, job_count)
 			     __field(int, hw_job_count)
 			     __string(dev, dev_name(sched_job->sched->dev))
+			     __field(uint64_t, fence_context)
+			     __field(uint64_t, fence_seqno)
 			     ),
 
 	    TP_fast_assign(
-			   __entry->entity = entity;
 			   __entry->id = sched_job->id;
-			   __entry->fence = &sched_job->s_fence->finished;
 			   __assign_str(name);
 			   __entry->job_count = spsc_queue_count(&entity->job_queue);
 			   __entry->hw_job_count = atomic_read(
 				   &sched_job->sched->credit_count);
 			   __assign_str(dev);
+			   __entry->fence_context = sched_job->s_fence->finished.context;
+			   __entry->fence_seqno = sched_job->s_fence->finished.seqno;
+
 			   ),
-	    TP_printk("entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d",
-		      __entry->entity, __entry->id,
-		      __entry->fence, __get_str(name),
+	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
+		      __entry->id,
+		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
 		      __entry->job_count, __entry->hw_job_count)
 );
 
@@ -69,9 +70,9 @@ DEFINE_EVENT(drm_sched_job, drm_sched_job,
 DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
 	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
 	    TP_ARGS(sched_job, entity),
-	    TP_printk("dev=%s, entity=%p id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d",
-		      __get_str(dev), __entry->entity, __entry->id,
-		      __entry->fence, __get_str(name),
+	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
+		      __get_str(dev), __entry->id,
+		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
 		      __entry->job_count, __entry->hw_job_count)
 );
 
@@ -79,37 +80,41 @@ TRACE_EVENT(drm_sched_process_job,
 	    TP_PROTO(struct drm_sched_fence *fence),
 	    TP_ARGS(fence),
 	    TP_STRUCT__entry(
-		    __field(struct dma_fence *, fence)
+		    __field(uint64_t, fence_context)
+		    __field(uint64_t, fence_seqno)
 		    ),
 
 	    TP_fast_assign(
-		    __entry->fence = &fence->finished;
+		    __entry->fence_context = fence->finished.context;
+		    __entry->fence_seqno = fence->finished.seqno;
 		    ),
-	    TP_printk("fence=%p signaled", __entry->fence)
+	    TP_printk("fence=(context:%llu, seqno:%lld) signaled",
+		      __entry->fence_context, __entry->fence_seqno)
 );
 
 TRACE_EVENT(drm_sched_job_wait_dep,
 	    TP_PROTO(struct drm_sched_job *sched_job, struct dma_fence *fence),
 	    TP_ARGS(sched_job, fence),
 	    TP_STRUCT__entry(
-			     __string(name, sched_job->sched->name)
+			     __field(uint64_t, fence_context)
+			     __field(uint64_t, fence_seqno)
 			     __field(uint64_t, id)
 			     __field(struct dma_fence *, fence)
 			     __field(uint64_t, ctx)
-			     __field(unsigned, seqno)
+			     __field(uint64_t, seqno)
 			     ),
 
 	    TP_fast_assign(
-			   __assign_str(name);
+			   __entry->fence_context = sched_job->s_fence->finished.context;
+			   __entry->fence_seqno = sched_job->s_fence->finished.seqno;
 			   __entry->id = sched_job->id;
 			   __entry->fence = fence;
 			   __entry->ctx = fence->context;
 			   __entry->seqno = fence->seqno;
 			   ),
-	    TP_printk("job ring=%s, id=%llu, depends fence=%p, context=%llu, seq=%u",
-		      __get_str(name), __entry->id,
-		      __entry->fence, __entry->ctx,
-		      __entry->seqno)
+	    TP_printk("fence=(context:%llu, seqno:%lld), id=%llu, dependencies:{(context:%llu, seqno:%lld)}",
+		      __entry->fence_context, __entry->fence_seqno, __entry->id,
+		      __entry->ctx, __entry->seqno)
 );
 
 #endif
Signature · 1 line
2.40.1
#6 lore raw

PATCH v5 3/4 drm/sched: trace dependencies for gpu jobs

In reply to Pierre-Eric Pelloux-Prayer

Trace the fence dependencies similarly to how we print fences:

... , dependencies:{(context:606, seqno:38006)}

This allows tools to analyze the dependencies between the jobs (previously it was only possible for fences traced by drm_sched_job_wait_dep).

Since drm_sched_job and drm_run_job use the same base event class, the caller of trace_drm_run_job have to pass a dep_count of 0 (which is ignored because dependencies are only considered at submit time).

---
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 59 ++++++++++++++++---
 drivers/gpu/drm/scheduler/sched_entity.c      |  8 ++-
 drivers/gpu/drm/scheduler/sched_main.c        |  2 +-
 3 files changed, 58 insertions(+), 11 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +50 -9
index f6da377cdb99..0abcad26839c 100644
@@ -26,15 +26,41 @@
 
 #include <linux/stringify.h>
 #include <linux/types.h>
+#include <linux/trace_seq.h>
 #include <linux/tracepoint.h>
 
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM gpu_scheduler
 #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+#ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
+#define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
+/* Similar to trace_print_array_seq but for fences. */
+static inline const char *__print_dma_fence_array(struct trace_seq *p, const void *buf, int count)
+{
+	const char *ret = trace_seq_buffer_ptr(p);
+	u64 *fences = (u64 *) buf;
+	const char *prefix = "";
+
+	trace_seq_putc(p, '{');
+	for (int i = 0; i < count; i++) {
+		u64 context = fences[2 * i], seqno = fences[2 * i + 1];
+
+		trace_seq_printf(p, "%s(context:%llu, seqno:%lld)",
+				 prefix, context, seqno);
+		prefix = ",";
+	}
+	trace_seq_putc(p, '}');
+	trace_seq_putc(p, 0);
+
+	return ret;
+}
+#endif
+
 DECLARE_EVENT_CLASS(drm_sched_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity),
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, dep_count),
 	    TP_STRUCT__entry(
 			     __string(name, sched_job->sched->name)
 			     __field(uint64_t, id)
@@ -43,9 +69,14 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			     __string(dev, dev_name(sched_job->sched->dev))
 			     __field(uint64_t, fence_context)
 			     __field(uint64_t, fence_seqno)
+			     __field(int, n_deps)
+			     __dynamic_array(u64, deps, dep_count * 2)
 			     ),
 
 	    TP_fast_assign(
+			   unsigned long idx;
+			   struct dma_fence *fence;
+			   u64 *dyn_arr;
 			   __entry->id = sched_job->id;
 			   __assign_str(name);
 			   __entry->job_count = spsc_queue_count(&entity->job_queue);
@@ -54,22 +85,32 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			   __assign_str(dev);
 			   __entry->fence_context = sched_job->s_fence->finished.context;
 			   __entry->fence_seqno = sched_job->s_fence->finished.seqno;
-
+			   __entry->n_deps = dep_count;
+			   if (dep_count) {
+				dyn_arr = __get_dynamic_array(deps);
+				xa_for_each(&sched_job->dependencies, idx, fence) {
+					dyn_arr[2 * idx] = fence->context;
+					dyn_arr[2 * idx + 1] = fence->seqno;
+				}
+			   }
 			   ),
-	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
+	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d, dependencies:%s",
 		      __entry->id,
 		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
-		      __entry->job_count, __entry->hw_job_count)
+		      __entry->job_count, __entry->hw_job_count,
+		      __print_dma_fence_array(p, __get_dynamic_array(deps), __entry->n_deps))
 );
 
 DEFINE_EVENT(drm_sched_job, drm_sched_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity)
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, dep_count)
 );
 
 DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity),
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, 0),
 	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
 		      __get_str(dev), __entry->id,
 		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
drivers/gpu/drm/scheduler/sched_entity.c +7 -1
index 58c8161289fe..aa33a9d29b14 100644
@@ -583,7 +583,13 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
 	bool first;
 	ktime_t submit_ts;
 
-	trace_drm_sched_job(sched_job, entity);
+	if (trace_drm_sched_job_enabled()) {
+		unsigned long index;
+		void *f;
+
+		xa_for_each(&sched_job->dependencies, index, f) { }
+		trace_drm_sched_job(sched_job, entity, index);
+	}
 	atomic_inc(entity->rq->sched->score);
 	WRITE_ONCE(entity->last_user, current->group_leader);
 
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 7e90c9f95611..0bc9b7b24b34 100644
@@ -1201,7 +1201,7 @@ static void drm_sched_run_job_work(struct work_struct *w)
 	atomic_add(sched_job->credits, &sched->credit_count);
 	drm_sched_job_begin(sched_job);
 
-	trace_drm_run_job(sched_job, entity);
+	trace_drm_run_job(sched_job, entity, 0);
 	fence = sched->ops->run_job(sched_job);
 	complete_all(&entity->entity_idle);
 	drm_sched_fence_scheduled(s_fence, fence);
Signature · 1 line
2.40.1
#7 lore raw

Re: [PATCH v5 3/4] drm/sched: trace dependencies for gpu jobs

Am Freitag, dem 14.06.2024 um 10:16 +0200 schrieb Pierre-Eric Pelloux- Prayer:

Quoted 126 lines

Trace the fence dependencies similarly to how we print fences:

... , dependencies:{(context:606, seqno:38006)}

This allows tools to analyze the dependencies between the jobs (previously it was only possible for fences traced by drm_sched_job_wait_dep).

Since drm_sched_job and drm_run_job use the same base event class, the caller of trace_drm_run_job have to pass a dep_count of 0 (which is ignored because dependencies are only considered at submit time).

---
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 59 ++++++++++++++++---
 drivers/gpu/drm/scheduler/sched_entity.c      |  8 ++-
 drivers/gpu/drm/scheduler/sched_main.c        |  2 +-
 3 files changed, 58 insertions(+), 11 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +50 -9
index f6da377cdb99..0abcad26839c 100644
@@ -26,15 +26,41 @@
 
 #include <linux/stringify.h>
 #include <linux/types.h>
+#include <linux/trace_seq.h>
 #include <linux/tracepoint.h>
 
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM gpu_scheduler
 #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+#ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
+#define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
+/* Similar to trace_print_array_seq but for fences. */
+static inline const char *__print_dma_fence_array(struct trace_seq *p, const void *buf, int count)
+{
+	const char *ret = trace_seq_buffer_ptr(p);
+	u64 *fences = (u64 *) buf;
+	const char *prefix = "";
+
+	trace_seq_putc(p, '{');
+	for (int i = 0; i < count; i++) {
+		u64 context = fences[2 * i], seqno = fences[2 * i + 1];
+
+		trace_seq_printf(p, "%s(context:%llu, seqno:%lld)",
+				 prefix, context, seqno);
+		prefix = ",";
+	}
+	trace_seq_putc(p, '}');
+	trace_seq_putc(p, 0);
+
+	return ret;
+}
+#endif
+
 DECLARE_EVENT_CLASS(drm_sched_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity),
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, dep_count),
 	    TP_STRUCT__entry(
 			     __string(name, sched_job->sched->name)
 			     __field(uint64_t, id)
@@ -43,9 +69,14 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			     __string(dev, dev_name(sched_job->sched->dev))
 			     __field(uint64_t, fence_context)
 			     __field(uint64_t, fence_seqno)
+			     __field(int, n_deps)
+			     __dynamic_array(u64, deps, dep_count * 2)
 			     ),
 
 	    TP_fast_assign(
+			   unsigned long idx;
+			   struct dma_fence *fence;
+			   u64 *dyn_arr;
 			   __entry->id = sched_job->id;
 			   __assign_str(name);
 			   __entry->job_count = spsc_queue_count(&entity->job_queue);
@@ -54,22 +85,32 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			   __assign_str(dev);
 			   __entry->fence_context = sched_job->s_fence->finished.context;
 			   __entry->fence_seqno = sched_job->s_fence->finished.seqno;
-
+			   __entry->n_deps = dep_count;
+			   if (dep_count) {
+				dyn_arr = __get_dynamic_array(deps);
+				xa_for_each(&sched_job->dependencies, idx, fence) {
+					dyn_arr[2 * idx] = fence->context;
+					dyn_arr[2 * idx + 1] = fence->seqno;
+				}
+			   }
 			   ),
-	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
+	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d, dependencies:%s",
 		      __entry->id,
 		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
-		      __entry->job_count, __entry->hw_job_count)
+		      __entry->job_count, __entry->hw_job_count,
+		      __print_dma_fence_array(p, __get_dynamic_array(deps), __entry->n_deps))
 );
 
 DEFINE_EVENT(drm_sched_job, drm_sched_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity)
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, dep_count)
 );
 
 DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity),
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, 0),
 	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
 		      __get_str(dev), __entry->id,
 		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
drivers/gpu/drm/scheduler/sched_entity.c +0 -0
index 58c8161289fe..aa33a9d29b14 100644

drivers/gpu/drm/scheduler/sched_entity.c void drm_sched_entity_push_job(struct drm_sched_job *sched_job) · line 590

Quoted 9 lines
drivers/gpu/drm/scheduler/sched_entity.c +5 -1
@@ -583,7 +583,13 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
 	bool first;
 	ktime_t submit_ts;
 
-	trace_drm_sched_job(sched_job, entity);
+	if (trace_drm_sched_job_enabled()) {
+		unsigned long index;
+		void *f;
+
+		xa_for_each(&sched_job->dependencies, index, f) { }

I did need to do a double take on that one. While using index for the total number of dependencies is correct for the dense and at this point in time fully populated dependencies array, it is a bit non-obvious. Maybe add a small comment here or have an actual counter in the loop body?

Regards,
Lucas

Quoted 18 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+		trace_drm_sched_job(sched_job, entity, index);
+	}
 	atomic_inc(entity->rq->sched->score);
 	WRITE_ONCE(entity->last_user, current->group_leader);
 
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 7e90c9f95611..0bc9b7b24b34 100644
@@ -1201,7 +1201,7 @@ static void drm_sched_run_job_work(struct work_struct *w)
 	atomic_add(sched_job->credits, &sched->credit_count);
 	drm_sched_job_begin(sched_job);
 
-	trace_drm_run_job(sched_job, entity);
+	trace_drm_run_job(sched_job, entity, 0);
 	fence = sched->ops->run_job(sched_job);
 	complete_all(&entity->entity_idle);
 	drm_sched_fence_scheduled(s_fence, fence);
#8 lore raw

Re: [PATCH v5 3/4] drm/sched: trace dependencies for gpu jobs

Le 03/07/2024 à 13:05, Lucas Stach a écrit :

Quoted 131 lines

Am Freitag, dem 14.06.2024 um 10:16 +0200 schrieb Pierre-Eric Pelloux- Prayer:

Quoted 129 lines

Trace the fence dependencies similarly to how we print fences:

... , dependencies:{(context:606, seqno:38006)}

This allows tools to analyze the dependencies between the jobs (previously it was only possible for fences traced by drm_sched_job_wait_dep).

Since drm_sched_job and drm_run_job use the same base event class, the caller of trace_drm_run_job have to pass a dep_count of 0 (which is ignored because dependencies are only considered at submit time).

---
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 59 ++++++++++++++++---
  drivers/gpu/drm/scheduler/sched_entity.c      |  8 ++-
  drivers/gpu/drm/scheduler/sched_main.c        |  2 +-
  3 files changed, 58 insertions(+), 11 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +50 -9
index f6da377cdb99..0abcad26839c 100644
@@ -26,15 +26,41 @@
 
  #include <linux/stringify.h>
  #include <linux/types.h>
+#include <linux/trace_seq.h>
  #include <linux/tracepoint.h>
 
  #undef TRACE_SYSTEM
  #define TRACE_SYSTEM gpu_scheduler
  #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+#ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
+#define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
+/* Similar to trace_print_array_seq but for fences. */
+static inline const char *__print_dma_fence_array(struct trace_seq *p, const void *buf, int count)
+{
+	const char *ret = trace_seq_buffer_ptr(p);
+	u64 *fences = (u64 *) buf;
+	const char *prefix = "";
+
+	trace_seq_putc(p, '{');
+	for (int i = 0; i < count; i++) {
+		u64 context = fences[2 * i], seqno = fences[2 * i + 1];
+
+		trace_seq_printf(p, "%s(context:%llu, seqno:%lld)",
+				 prefix, context, seqno);
+		prefix = ",";
+	}
+	trace_seq_putc(p, '}');
+	trace_seq_putc(p, 0);
+
+	return ret;
+}
+#endif
+
  DECLARE_EVENT_CLASS(drm_sched_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity),
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, dep_count),
  	    TP_STRUCT__entry(
  			     __string(name, sched_job->sched->name)
  			     __field(uint64_t, id)
@@ -43,9 +69,14 @@ DECLARE_EVENT_CLASS(drm_sched_job,
  			     __string(dev, dev_name(sched_job->sched->dev))
  			     __field(uint64_t, fence_context)
  			     __field(uint64_t, fence_seqno)
+			     __field(int, n_deps)
+			     __dynamic_array(u64, deps, dep_count * 2)
  			     ),
 
  	    TP_fast_assign(
+			   unsigned long idx;
+			   struct dma_fence *fence;
+			   u64 *dyn_arr;
  			   __entry->id = sched_job->id;
  			   __assign_str(name);
  			   __entry->job_count = spsc_queue_count(&entity->job_queue);
@@ -54,22 +85,32 @@ DECLARE_EVENT_CLASS(drm_sched_job,
  			   __assign_str(dev);
  			   __entry->fence_context = sched_job->s_fence->finished.context;
  			   __entry->fence_seqno = sched_job->s_fence->finished.seqno;
-
+			   __entry->n_deps = dep_count;
+			   if (dep_count) {
+				dyn_arr = __get_dynamic_array(deps);
+				xa_for_each(&sched_job->dependencies, idx, fence) {
+					dyn_arr[2 * idx] = fence->context;
+					dyn_arr[2 * idx + 1] = fence->seqno;
+				}
+			   }
  			   ),
-	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
+	    TP_printk("id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d, dependencies:%s",
  		      __entry->id,
  		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
-		      __entry->job_count, __entry->hw_job_count)
+		      __entry->job_count, __entry->hw_job_count,
+		      __print_dma_fence_array(p, __get_dynamic_array(deps), __entry->n_deps))
  );
 
  DEFINE_EVENT(drm_sched_job, drm_sched_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity)
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, dep_count)
  );
 
  DEFINE_EVENT_PRINT(drm_sched_job, drm_run_job,
-	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),
-	    TP_ARGS(sched_job, entity),
+	    TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity,
+		     unsigned int dep_count),
+	    TP_ARGS(sched_job, entity, 0),
  	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
  		      __get_str(dev), __entry->id,
  		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
drivers/gpu/drm/scheduler/sched_entity.c +0 -0
index 58c8161289fe..aa33a9d29b14 100644
@@ -583,7 +583,13 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
  	bool first;
  	ktime_t submit_ts;
 
Quoted 12 lines

drivers/gpu/drm/scheduler/sched_entity.c void drm_sched_entity_push_job(struct drm_sched_job *sched_job) · line 590

Quoted 6 lines
drivers/gpu/drm/scheduler/sched_entity.c +5 -1
-	trace_drm_sched_job(sched_job, entity);
+	if (trace_drm_sched_job_enabled()) {
+		unsigned long index;
+		void *f;
+
+		xa_for_each(&sched_job->dependencies, index, f) { }

I did need to do a double take on that one. While using index for the total number of dependencies is correct for the dense and at this point in time fully populated dependencies array, it is a bit non-obvious. Maybe add a small comment here or have an actual counter in the loop body?

Makes sense. I'll add a counter in v6.

thanks,
Pierre-Eric

Quoted 22 lines

Regards,
Lucas

Quoted 18 lines
drivers/gpu/drm/scheduler/sched_entity.c +2 -0
+		trace_drm_sched_job(sched_job, entity, index);
+	}
  	atomic_inc(entity->rq->sched->score);
  	WRITE_ONCE(entity->last_user, current->group_leader);
 
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 7e90c9f95611..0bc9b7b24b34 100644
@@ -1201,7 +1201,7 @@ static void drm_sched_run_job_work(struct work_struct *w)
  	atomic_add(sched_job->credits, &sched->credit_count);
  	drm_sched_job_begin(sched_job);
 
-	trace_drm_run_job(sched_job, entity);
+	trace_drm_run_job(sched_job, entity, 0);
  	fence = sched->ops->run_job(sched_job);
  	complete_all(&entity->entity_idle);
  	drm_sched_fence_scheduled(s_fence, fence);
#9 lore raw

PATCH v5 4/4 drm/doc: document some tracepoints as uAPI

In reply to Pierre-Eric Pelloux-Prayer

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
 Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++
 2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +19 -0
index 370d820be248..78496793a8f0 100644
@@ -570,3 +570,22 @@ dma-buf interoperability
 
 Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for
 information on how dma-buf is integrated and exposed within DRM.
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints documentation.
+In the drm subsystem, some events are considered stable uAPI to avoid
+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -0
index 0abcad26839c..63113803cdd5 100644
@@ -33,6 +33,28 @@
 #define TRACE_SYSTEM gpu_scheduler
 #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with ``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
 #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
 #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
 /* Similar to trace_print_array_seq but for fences. */
Signature · 1 line
2.40.1
#10 lore raw

Re: [PATCH v5 4/4] drm/doc: document some tracepoints as uAPI

[adding more people to this thread based on the drivers using gpu_scheduler]

Hi,

Christian's comment on patch 1/5 will be addressed in v6, but before pushing another version I'd like to know if there's a consensus among the drivers maintainers regarding the changes proposed in this series.

Thanks!
Pierre-Eric

Le 14/06/2024 à 10:16, Pierre-Eric Pelloux-Prayer a écrit :

Quoted 73 lines

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
  Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++
  2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +19 -0
index 370d820be248..78496793a8f0 100644
@@ -570,3 +570,22 @@ dma-buf interoperability
 
  Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for
  information on how dma-buf is integrated and exposed within DRM.
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints documentation.
+In the drm subsystem, some events are considered stable uAPI to avoid
+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -0
index 0abcad26839c..63113803cdd5 100644
@@ -33,6 +33,28 @@
  #define TRACE_SYSTEM gpu_scheduler
  #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with ``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
  #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  /* Similar to trace_print_array_seq but for fences. */
Acked-by
#11 lore raw

Re: [PATCH v5 4/4] drm/doc: document some tracepoints as uAPI

Hi Pierre-Eric,

Am Montag, dem 01.07.2024 um 14:44 +0200 schrieb Pierre-Eric Pelloux- Prayer:

Quoted 8 lines

[adding more people to this thread based on the drivers using gpu_scheduler]

Hi,

Christian's comment on patch 1/5 will be addressed in v6, but before pushing another version I'd like to know if there's a consensus among the drivers maintainers regarding the changes proposed in this series.

I absolutely agree with the changes done in this series. The pointer values in the existing tracepoints are close to useless. Being able to tie events together through a stable representation of the fences is a very welcome improvement.

Regards,
Lucas

Quoted 78 lines

Thanks!
Pierre-Eric

Le 14/06/2024 à 10:16, Pierre-Eric Pelloux-Prayer a écrit :

Quoted 73 lines

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
  Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++
  2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +19 -0
index 370d820be248..78496793a8f0 100644
@@ -570,3 +570,22 @@ dma-buf interoperability
 
  Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for
  information on how dma-buf is integrated and exposed within DRM.
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints documentation.
+In the drm subsystem, some events are considered stable uAPI to avoid
+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -0
index 0abcad26839c..63113803cdd5 100644
@@ -33,6 +33,28 @@
  #define TRACE_SYSTEM gpu_scheduler
  #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with ``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
  #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  /* Similar to trace_print_array_seq but for fences. */
#12 lore raw

Re: [PATCH v5 4/4] drm/doc: document some tracepoints as uAPI

In reply to Pierre-Eric Pelloux-Prayer

Am Freitag, dem 14.06.2024 um 10:16 +0200 schrieb Pierre-Eric Pelloux- Prayer:

Quoted 20 lines

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
 Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++
 2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +0 -0
index 370d820be248..78496793a8f0 100644
@@ -570,3 +570,22 @@ dma-buf interoperability
 
 Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for
 information on how dma-buf is integrated and exposed within DRM.

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 582

Quoted 10 lines
Documentation/gpu/drm-uapi.rst +10 -0
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints documentation.
+In the drm subsystem, some events are considered stable uAPI to avoid
+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.

What are those "normal uAPI requirements" in this context? Aside from not being able to remove or change any fields?

Regards,
Lucas

Quoted 43 lines
Documentation/gpu/drm-uapi.rst +9 -0
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -0
index 0abcad26839c..63113803cdd5 100644
@@ -33,6 +33,28 @@
 #define TRACE_SYSTEM gpu_scheduler
 #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with ``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
 #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
 #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
 /* Similar to trace_print_array_seq but for fences. */
#13 lore raw

Re: [PATCH v5 4/4] drm/doc: document some tracepoints as uAPI

Le 03/07/2024 à 12:46, Lucas Stach a écrit :

Quoted 20 lines

Am Freitag, dem 14.06.2024 um 10:16 +0200 schrieb Pierre-Eric Pelloux- Prayer:

Quoted 18 lines

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
  Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++
  2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +0 -0
index 370d820be248..78496793a8f0 100644
@@ -570,3 +570,22 @@ dma-buf interoperability
 
Quoted 15 lines

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 582

Quoted 12 lines
Documentation/gpu/drm-uapi.rst +10 -0
  Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for
  information on how dma-buf is integrated and exposed within DRM.
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints documentation.
+In the drm subsystem, some events are considered stable uAPI to avoid
+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.

What are those "normal uAPI requirements" in this context? Aside from not being able to remove or change any fields?

The ones from https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements

For the trace events, the sentence "patches must be reviewed and ready for merging into a suitable and canonical upstream project" could be read as "gpuvis patches must be reviewed and ready for merging".

Thanks,
Pierre-Eric

Quoted 47 lines

Regards,
Lucas

Quoted 43 lines
Documentation/gpu/drm-uapi.rst +9 -0
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -0
index 0abcad26839c..63113803cdd5 100644
@@ -33,6 +33,28 @@
  #define TRACE_SYSTEM gpu_scheduler
  #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with ``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
  #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  /* Similar to trace_print_array_seq but for fences. */
Acked-by on v5 4/4
#14 lore raw

Re: [PATCH v5 4/4] drm/doc: document some tracepoints as uAPI

In reply to Pierre-Eric Pelloux-Prayer

Hi Pierre,

Quoted 17 lines · Pierre-Eric Pelloux-Prayer

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
  Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++
  2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +0 -0
index 370d820be248..78496793a8f0 100644

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 578

Quoted 9 lines
Documentation/gpu/drm-uapi.rst +6 -0
@@ -570,3 +570,22 @@ dma-buf interoperability
 
  Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for
  information on how dma-buf is integrated and exposed within DRM.
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints documentation.

I would write it:

"See Documentation/trace/tracepoints.rst for information about using Linux Kernel Tracepoints."

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 579

Quoted 1 line
Documentation/gpu/drm-uapi.rst +1 -0
+In the drm subsystem, some events are considered stable uAPI to avoid

Super small nit: s/drm/DRM

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 580

Quoted 1 line
Documentation/gpu/drm-uapi.rst +1 -0
+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields

Super small nit:

1. s/eg:/e.g.:
2. s/gpuvis/GPUVis (maybe a URL to it?)
3. Maybe a URL to umr?

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 588

Quoted 8 lines
Documentation/gpu/drm-uapi.rst +8 -0
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Super small nit: from the rest of the file, I see that a title was never needed. Do we need it here?

Quoted 9 lines
Documentation/gpu/drm-uapi.rst +3 -0
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
index 0abcad26839c..63113803cdd5 100644

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h line 41

Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +6 -0
@@ -33,6 +33,28 @@
  #define TRACE_SYSTEM gpu_scheduler
  #define TRACE_INCLUDE_FILE gpu_scheduler_trace
 
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.

Super small nit again, but I believe we should format function names with ``foo()``, if I understood kerneldoc documentation correctly.

Apart from all those nits, I completely agree with Lucas, it is great to see this improvement.

Best Regards,
- Maíra

Quoted 19 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +16 -0
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with ``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
  #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  /* Similar to trace_print_array_seq but for fences. */
#15 lore raw

Re: [PATCH v5 4/4] drm/doc: document some tracepoints as uAPI

Hi Maíra,

Le 03/07/2024 à 17:41, Maíra Canal a écrit :

Quoted 82 lines

Hi Pierre,

Quoted 25 lines · Pierre-Eric Pelloux-Prayer

This commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.

The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.

---
  Documentation/gpu/drm-uapi.rst                | 19 ++++++++++++++++ .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 22 +++++++++++++++++++

  2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +0 -0
index 370d820be248..78496793a8f0 100644
@@ -570,3 +570,22 @@ dma-buf interoperability

  Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for information on how dma-buf is integrated and exposed within DRM.

Documentation/gpu/drm-uapi.rst +6 -0
+
+
+Trace events
+============
+
+See Documentation/trace/tracepoints.rst for the tracepoints 
Quoted 1 line

documentation.

I would write it:

"See Documentation/trace/tracepoints.rst for information about using Linux Kernel Tracepoints."

Quoted 1 line

+In the drm subsystem, some events are considered stable uAPI to avoid

Super small nit: s/drm/DRM

Quoted 2 lines

+breaking tools (eg: gpuvis, umr) relying on them. Stable means that fields

Super small nit:

1. s/eg:/e.g.:
2. s/gpuvis/GPUVis (maybe a URL to it?)
3. Maybe a URL to umr?

Documentation/gpu/drm-uapi.rst dma-buf interoperability · line 588

Quoted 8 lines
Documentation/gpu/drm-uapi.rst +8 -0
+cannot be removed, nor their formatting updated. Adding new fields is
+possible, under the normal uAPI requirements.
+
+Stable uAPI events
+------------------
+
+From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Super small nit: from the rest of the file, I see that a title was never needed. Do we need it here?

Quoted 9 lines
Documentation/gpu/drm-uapi.rst +3 -0
+
+.. kernel-doc::  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h
+   :doc: uAPI trace events
\ No newline at end of file
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
index 0abcad26839c..63113803cdd5 100644

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h line 40

Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +6 -0
@@ -33,6 +33,28 @@
   #define TRACE_SYSTEM gpu_scheduler
   #define TRACE_INCLUDE_FILE gpu_scheduler_trace
+
+/**
+ * DOC: uAPI trace events
+ *
+ * ``drm_sched_job``, ``drm_run_job``, ``drm_sched_process_job``,
+ * and ``drm_sched_job_wait_dep`` are considered stable uAPI.

Super small nit again, but I believe we should format function names with ``foo()``, if I understood kerneldoc documentation correctly.

Quoted 4 lines

Apart from all those nits, I completely agree with Lucas, it is great to see this improvement.

Thanks a lot for the feedback, I'll integrate it in v6.

Regards,
Pierre-Eric

Quoted 24 lines

Best Regards,
- Maíra

Quoted 20 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +9 -0
+ *
+ * Common trace events attributes:
+ *
+ * * ``id``    - this is &drm_sched_job->id. It uniquely idenfies a job
+ *   inside a &struct drm_gpu_scheduler.
+ *
+ * * ``dev``   - the dev_name() of the device running the job.
+ *
+ * * ``ring``  - the hardware ring running the job. Together with 

``dev`` it
+ *   uniquely identifies where the job is going to be executed.
+ *
+ * * ``fence`` - the &dma_fence.context and the &dma_fence.seqno of
+ *   &drm_sched_fence.finished
+ *
+ */
+
  #ifndef __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  #define __TRACE_EVENT_GPU_SCHEDULER_PRINT_FN
  /* Similar to trace_print_array_seq but for fences. */