Skip to contentSkip to conversation

Improve gpu_scheduler trace events + uAPI

PATCH Superseded Pierre-Eric Pelloux-Prayer 8 participants 29 messages Nov 14, 2024 – Nov 21, 2024

Subsystems (14)

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 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.

The first patches extend and cleanup the gpu scheduler events.

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

Changes since v5:
* Addressed Christian, Maíra and Lucas' comments.
* Added patch 1, 2, 6 to include drm_client_id to the events. This is required when a single app uses multiple fds for the same device.
* Validated that the patches don't break gpuvis

Useful links:
- userspace tool using the updated events:
https://gitlab.freedesktop.org/tomstdenis/umr/-/merge_requests/37
- v5:
https://lists.freedesktop.org/archives/dri-devel/2024-June/457827.html

Pierre-Eric Pelloux-Prayer (7):
drm/debugfs: output client_id in in drm_clients_info drm/sched: store the drm client_id in drm_sched_fence 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/sched: add the drm_client_id to the drm_sched_run/exec_job events drm/doc: document some tracepoints as uAPI

 Documentation/gpu/drm-uapi.rst                |  19 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |   3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |   8 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h       |   3 +-
 drivers/gpu/drm/drm_debugfs.c                 |  10 +-
 drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c  |   2 +-
 drivers/gpu/drm/imagination/pvr_job.c         |   2 +-
 drivers/gpu/drm/imagination/pvr_queue.c       |   5 +-
 drivers/gpu/drm/imagination/pvr_queue.h       |   2 +-
 drivers/gpu/drm/lima/lima_gem.c               |   2 +-
 drivers/gpu/drm/lima/lima_sched.c             |   6 +-
 drivers/gpu/drm/lima/lima_sched.h             |   3 +-
 drivers/gpu/drm/msm/msm_gem_submit.c          |   8 +-
 drivers/gpu/drm/nouveau/nouveau_sched.c       |   3 +-
 drivers/gpu/drm/panfrost/panfrost_drv.c       |   2 +-
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 121 ++++++++++++++----
 drivers/gpu/drm/scheduler/sched_entity.c      |   8 +-
 drivers/gpu/drm/scheduler/sched_fence.c       |   4 +-
 drivers/gpu/drm/scheduler/sched_main.c        |   8 +-
 drivers/gpu/drm/v3d/v3d_submit.c              |   2 +-
 drivers/gpu/drm/xe/xe_sched_job.c             |   3 +-
 include/drm/gpu_scheduler.h                   |  12 +-
 23 files changed, 181 insertions(+), 57 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v6 1/7 drm/debugfs: output client_id in in drm_clients_info

client_id is a unique id used by fdinfo. Having it listed in 'clients' output means a userspace application can correlate the fields, eg:
given a fdinfo id get the fdinfo name.

---
 drivers/gpu/drm/drm_debugfs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_debugfs.c +6 -4
index 536409a35df4..4c0bd0cb5480 100644
@@ -77,14 +77,15 @@ static int drm_clients_info(struct seq_file *m, void *data)
 	kuid_t uid;
 
 	seq_printf(m,
-		   "%20s %5s %3s master a %5s %10s %*s\n",
+		   "%20s %5s %3s master a %5s %10s %*s %20s\n",
 		   "command",
 		   "tgid",
 		   "dev",
 		   "uid",
 		   "magic",
 		   DRM_CLIENT_NAME_MAX_LEN,
-		   "name");
+		   "name",
+		   "id");
 
 	/* dev->filelist is sorted youngest first, but we want to present
 	 * oldest first (i.e. kernel, servers, clients), so walk backwardss.
@@ -100,7 +101,7 @@ static int drm_clients_info(struct seq_file *m, void *data)
 		pid = rcu_dereference(priv->pid);
 		task = pid_task(pid, PIDTYPE_TGID);
 		uid = task ? __task_cred(task)->euid : GLOBAL_ROOT_UID;
-		seq_printf(m, "%20s %5d %3d   %c    %c %5d %10u %*s\n",
+		seq_printf(m, "%20s %5d %3d   %c    %c %5d %10u %*s %20lld\n",
 			   task ? task->comm : "<unknown>",
 			   pid_vnr(pid),
 			   priv->minor->index,
@@ -109,7 +110,8 @@ static int drm_clients_info(struct seq_file *m, void *data)
 			   from_kuid_munged(seq_user_ns(m), uid),
 			   priv->magic,
 			   DRM_CLIENT_NAME_MAX_LEN,
-			   priv->client_name ? priv->client_name : "<unset>");
+			   priv->client_name ? priv->client_name : "<unset>",
+			   priv->client_id);
 		rcu_read_unlock();
 		mutex_unlock(&priv->client_name_lock);
 	}
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v6 1/7] drm/debugfs: output client_id in in drm_clients_info

Quoted 51 lines · Pierre-Eric Pelloux-Prayer

client_id is a unique id used by fdinfo. Having it listed in 'clients'
output means a userspace application can correlate the fields, eg:
given a fdinfo id get the fdinfo name.

Signed-off-by: Pierre-Eric Pelloux-Prayer
<[email protected]>
---
 drivers/gpu/drm/drm_debugfs.c | 10 ++++++----

 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_debugfs.c +0 -0
index 536409a35df4..4c0bd0cb5480 100644
@@ -77,14 +77,15 @@ static int drm_clients_info(struct seq_file *m,
 void *data)
  	kuid_t uid;


  seq_printf(m,

drivers/gpu/drm/drm_debugfs.c +1 -1
-		   "%20s %5s %3s master a %5s %10s %*s\n",
+		   "%20s %5s %3s master a %5s %10s %*s %20s\n",

     "command",
     "tgid",
     "dev",
     "uid",
     "magic",
     DRM_CLIENT_NAME_MAX_LEN,

drivers/gpu/drm/drm_debugfs.c +2 -1
-		   "name");
+		   "name",
+		   "id");


  /* dev->filelist is sorted youngest first, but we want to present
  * oldest first (i.e. kernel, servers, clients), so walk backwardss.

drivers/gpu/drm/drm_debugfs.c +0 -0
@@ -100,7 +101,7 @@ static int drm_clients_info(struct seq_file *m,
 void *data)
  		pid = rcu_dereference(priv->pid);
  		task = pid_task(pid, PIDTYPE_TGID);

  uid = task ? __task_cred(task)->euid :
GLOBAL_ROOT_UID;

drivers/gpu/drm/drm_debugfs.c +0 -1
-		seq_printf(m, "%20s %5d %3d   %c    %c %5d %10u

%*s\n",

drivers/gpu/drm/drm_debugfs.c +1 -0
+		seq_printf(m, "%20s %5d %3d   %c    %c %5d %10u %*s

%20lld\n",
     task ? task->comm : "<unknown>", pid_vnr(pid), priv->minor->index,

drivers/gpu/drm/drm_debugfs.c static int drm_clients_info(struct seq_file *m, · line 117

Quoted 9 lines
drivers/gpu/drm/drm_debugfs.c +2 -1
@@ -109,7 +110,8 @@ static int drm_clients_info(struct seq_file *m,
 void *data)
  			   from_kuid_munged(seq_user_ns(m), uid),
  			   priv->magic,
  			   DRM_CLIENT_NAME_MAX_LEN,
-			   priv->client_name ? priv->client_name :
 "<unset>");
+			   priv->client_name ? priv->client_name :
 "<unset>",
+			   priv->client_id);

Similarly to Tvrtko's comment on the other patch: drm_file.client_id is a u64, so we don't have to print it signed with %20lld, do we?

P.

Quoted 3 lines

  rcu_read_unlock(); mutex_unlock(&priv->client_name_lock); }

#3 lore raw

PATCH v6 2/7 drm/sched: store the drm client_id in drm_sched_fence

In reply to Pierre-Eric Pelloux-Prayer

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++-
 drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +-
 drivers/gpu/drm/imagination/pvr_job.c        |  2 +-
 drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++--
 drivers/gpu/drm/imagination/pvr_queue.h      |  2 +-
 drivers/gpu/drm/lima/lima_gem.c              |  2 +-
 drivers/gpu/drm/lima/lima_sched.c            |  6 ++++--
 drivers/gpu/drm/lima/lima_sched.h            |  3 ++-
 drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---
 drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
 drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
 drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-
 drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++--
 drivers/gpu/drm/v3d/v3d_submit.c             |  2 +-
 drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++-
 include/drm/gpu_scheduler.h                  | 12 ++++++++++--
 19 files changed, 51 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index b545940e512b..eede43701d51 100644
@@ -681,7 +681,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device *adev,
 		goto err;
 	}
 
-	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job);
+	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job, 0);
 	if (ret)
 		goto err;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
index 98aa4beee36a..a0a129405323 100644
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
 
 	for (i = 0; i < p->gang_size; ++i) {
 		ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,
-				       num_ibs[i], &p->jobs[i]);
+				       num_ibs[i], &p->jobs[i],
+				       p->filp->client_id);
 		if (ret)
 			goto free_all_kdata;
 		p->jobs[i]->enforce_isolation = p->adev->enforce_isolation[fpriv->xcp_id];
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -3
index c774cd019a10..1dd8e940d1e9 100644
@@ -186,7 +186,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 
 int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		     struct drm_sched_entity *entity, void *owner,
-		     unsigned int num_ibs, struct amdgpu_job **job)
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id)
 {
 	if (num_ibs == 0)
 		return -EINVAL;
@@ -209,7 +210,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (!entity)
 		return 0;
 
-	return drm_sched_job_init(&(*job)->base, entity, 1, owner);
+	return drm_sched_job_init(&(*job)->base, entity, 1, owner,
+				  drm_client_id);
 }
 
 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
@@ -219,7 +221,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
 {
 	int r;
 
-	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job);
+	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job, 0);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
index ce6b9ba967ff..41a03477ba5d 100644
@@ -90,7 +90,8 @@ static inline struct amdgpu_ring *amdgpu_job_ring(struct amdgpu_job *job)
 
 int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		     struct drm_sched_entity *entity, void *owner,
-		     unsigned int num_ibs, struct amdgpu_job **job);
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id);
 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
 			     struct drm_sched_entity *entity, void *owner,
 			     size_t size, enum amdgpu_ib_pool_type pool_type,
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
index 3d0f8d182506..70294ca6202f 100644
@@ -535,7 +535,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 
 	ret = drm_sched_job_init(&submit->sched_job,
 				 &ctx->sched_entity[args->pipe],
-				 1, submit->ctx);
+				 1, submit->ctx, file->client_id);
 	if (ret)
 		goto err_submit_put;
 
drivers/gpu/drm/imagination/pvr_job.c +1 -1
index 618503a212a7..64152b57e8b1 100644
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,
 	if (err)
 		goto err_put_job;
 
-	err = pvr_queue_job_init(job);
+	err = pvr_queue_job_init(job, pvr_file->file->client_id);
 	if (err)
 		goto err_put_job;
 
drivers/gpu/drm/imagination/pvr_queue.c +3 -2
index c4f08432882b..598180fca141 100644
@@ -1059,6 +1059,7 @@ static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
 /**
  * pvr_queue_job_init() - Initialize queue related fields in a pvr_job object.
  * @job: The job to initialize.
+ * @drm_client_id: drm_file.client_id submitting the job
  *
  * Bind the job to a queue and allocate memory to guarantee pvr_queue_job_arm()
  * and pvr_queue_job_push() can't fail. We also make sure the context type is
@@ -1068,7 +1069,7 @@ static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
  *  * 0 on success, or
  *  * An error code if something failed.
  */
-int pvr_queue_job_init(struct pvr_job *job)
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id)
 {
 	/* Fragment jobs need at least one native fence wait on the geometry job fence. */
 	u32 min_native_dep_count = job->type == DRM_PVR_JOB_TYPE_FRAGMENT ? 1 : 0;
@@ -1085,7 +1086,7 @@ int pvr_queue_job_init(struct pvr_job *job)
 	if (!pvr_cccb_cmdseq_can_fit(&queue->cccb, job_cmds_size(job, min_native_dep_count)))
 		return -E2BIG;
 
-	err = drm_sched_job_init(&job->base, &queue->entity, 1, THIS_MODULE);
+	err = drm_sched_job_init(&job->base, &queue->entity, 1, THIS_MODULE, drm_client_id);
 	if (err)
 		return err;
 
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
index e06ced69302f..bc556169b2cf 100644
@@ -139,7 +139,7 @@ struct pvr_queue {
 
 bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
 
-int pvr_queue_job_init(struct pvr_job *job);
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id);
 
 void pvr_queue_job_cleanup(struct pvr_job *job);
 
drivers/gpu/drm/lima/lima_gem.c +1 -1
index 9bb997dbb4b9..f46f961afc56 100644
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
 
 	err = lima_sched_task_init(
 		submit->task, submit->ctx->context + submit->pipe,
-		bos, submit->nr_bos, vm);
+		bos, submit->nr_bos, vm, file->client_id);
 	if (err)
 		goto err_out1;
 
drivers/gpu/drm/lima/lima_sched.c +4 -2
index b40c90e97d7e..84599549661a 100644
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe *to_lima_pipe(struct drm_gpu_scheduler *sch
 int lima_sched_task_init(struct lima_sched_task *task,
 			 struct lima_sched_context *context,
 			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm)
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id)
 {
 	int err, i;
 
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task *task,
 	for (i = 0; i < num_bos; i++)
 		drm_gem_object_get(&bos[i]->base.base);
 
-	err = drm_sched_job_init(&task->base, &context->base, 1, vm);
+	err = drm_sched_job_init(&task->base, &context->base, 1, vm,
+				 drm_client_id);
 	if (err) {
 		kfree(task->bos);
 		return err;
drivers/gpu/drm/lima/lima_sched.h +2 -1
index 85b23ba901d5..4041468586bd 100644
@@ -88,7 +88,8 @@ struct lima_sched_pipe {
 int lima_sched_task_init(struct lima_sched_task *task,
 			 struct lima_sched_context *context,
 			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm);
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id);
 void lima_sched_task_fini(struct lima_sched_task *task);
 
 int lima_sched_context_init(struct lima_sched_pipe *pipe,
drivers/gpu/drm/msm/msm_gem_submit.c +5 -3
index fba78193127d..ceeedd4186ef 100644
@@ -30,7 +30,7 @@
 static struct msm_gem_submit *submit_create(struct drm_device *dev,
 		struct msm_gpu *gpu,
 		struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
-		uint32_t nr_cmds)
+		uint32_t nr_cmds, uint64_t drm_client_id)
 {
 	static atomic_t ident = ATOMIC_INIT(0);
 	struct msm_gem_submit *submit;
@@ -54,7 +54,8 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev,
 		return ERR_PTR(ret);
 	}
 
-	ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue);
+	ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue,
+				 drm_client_id);
 	if (ret) {
 		kfree(submit->hw_fence);
 		kfree(submit);
@@ -702,7 +703,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
 		}
 	}
 
-	submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds);
+	submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds,
+			       file->client_id);
 	if (IS_ERR(submit)) {
 		ret = PTR_ERR(submit);
 		goto out_post_unlock;
drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
index 4412f2711fb5..ebc31adea39a 100644
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job,
 	}
 
 	ret = drm_sched_job_init(&job->base, &sched->entity,
-				 args->credits, NULL);
+				 args->credits, NULL,
+				 job->file_priv->client_id);
 	if (ret)
 		goto err_free_chains;
 
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
index 04d615df5259..a8135bd75cae 100644
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data,
 
 	ret = drm_sched_job_init(&job->base,
 				 &file_priv->sched_entity[slot],
-				 1, NULL);
+				 1, NULL, file->client_id);
 	if (ret)
 		goto out_put_job;
 
drivers/gpu/drm/scheduler/sched_fence.c +3 -1
index 0f35f009b9d3..909b886cd379 100644
@@ -204,7 +204,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f)
 EXPORT_SYMBOL(to_drm_sched_fence);
 
 struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
-					      void *owner)
+					      void *owner,
+					      uint64_t drm_client_id)
 {
 	struct drm_sched_fence *fence = NULL;
 
@@ -213,6 +214,7 @@ struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
 		return NULL;
 
 	fence->owner = owner;
+	fence->drm_client_id = drm_client_id;
 	spin_lock_init(&fence->lock);
 
 	return fence;
drivers/gpu/drm/scheduler/sched_main.c +4 -2
index 7ce25281c74c..28ac709750e9 100644
@@ -776,6 +776,7 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
  * @credits: the number of credits this job contributes to the schedulers
  * credit limit
  * @owner: job owner for debugging
+ * @drm_client_id: drm_file.client_id of the owner
  *
  * Refer to drm_sched_entity_push_job() documentation
  * for locking considerations.
@@ -796,7 +797,8 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
  */
 int drm_sched_job_init(struct drm_sched_job *job,
 		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner)
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id)
 {
 	if (!entity->rq) {
 		/* This will most likely be followed by missing frames
@@ -822,7 +824,7 @@ int drm_sched_job_init(struct drm_sched_job *job,
 
 	job->entity = entity;
 	job->credits = credits;
-	job->s_fence = drm_sched_fence_alloc(entity, owner);
+	job->s_fence = drm_sched_fence_alloc(entity, owner, drm_client_id);
 	if (!job->s_fence)
 		return -ENOMEM;
 
drivers/gpu/drm/v3d/v3d_submit.c +1 -1
index d607aa9c4ec2..a086da31f441 100644
@@ -168,7 +168,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv,
 	job->file = file_priv;
 
 	ret = drm_sched_job_init(&job->base, &v3d_priv->sched_entity[queue],
-				 1, v3d_priv);
+				 1, v3d_priv, file_priv->client_id);
 	if (ret)
 		return ret;
 
drivers/gpu/drm/xe/xe_sched_job.c +2 -1
index eeccc1c318ae..6617555e7a51 100644
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q,
 	kref_init(&job->refcount);
 	xe_exec_queue_get(job->q);
 
-	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL);
+	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL,
+				 q->xef->drm->client_id);
 	if (err)
 		goto err_free;
 
include/drm/gpu_scheduler.h +10 -2
index 95e17504e46a..42c381449443 100644
@@ -311,6 +311,13 @@ struct drm_sched_fence {
          * @owner: job owner for debugging
          */
 	void				*owner;
+
+	/**
+	 * @drm_client_id:
+	 *
+	 * The client_id of the drm_file who owned the job.
+	 */
+	uint64_t			drm_client_id;
 };
 
 struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
@@ -563,7 +570,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 void drm_sched_fini(struct drm_gpu_scheduler *sched);
 int drm_sched_job_init(struct drm_sched_job *job,
 		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner);
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id);
 void drm_sched_job_arm(struct drm_sched_job *job);
 int drm_sched_job_add_dependency(struct drm_sched_job *job,
 				 struct dma_fence *fence);
@@ -624,7 +632,7 @@ bool drm_sched_entity_is_ready(struct drm_sched_entity *entity);
 int drm_sched_entity_error(struct drm_sched_entity *entity);
 
 struct drm_sched_fence *drm_sched_fence_alloc(
-	struct drm_sched_entity *s_entity, void *owner);
+	struct drm_sched_entity *s_entity, void *owner, uint64_t drm_client_id);
 void drm_sched_fence_init(struct drm_sched_fence *fence,
 			  struct drm_sched_entity *entity);
 void drm_sched_fence_free(struct drm_sched_fence *fence);
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

Quoted 2 lines · Pierre-Eric Pelloux-Prayer

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

I wonder if it would be tidier to store the drm_client_id in the entity via drm_sched_entity_init? It would still required trickling down the info to the callers, but perhaps that could be done via driver structs instead of expanding the number for function arguments in the API. To be discussed I think. But to me the drm_client_id just sticks out too much as an odd one out in some of these functions.

Quoted 75 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++-
  drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +-
  drivers/gpu/drm/imagination/pvr_job.c        |  2 +-
  drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++--
  drivers/gpu/drm/imagination/pvr_queue.h      |  2 +-
  drivers/gpu/drm/lima/lima_gem.c              |  2 +-
  drivers/gpu/drm/lima/lima_sched.c            |  6 ++++--
  drivers/gpu/drm/lima/lima_sched.h            |  3 ++-
  drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---
  drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
  drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-
  drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++--
  drivers/gpu/drm/v3d/v3d_submit.c             |  2 +-
  drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++-
  include/drm/gpu_scheduler.h                  | 12 ++++++++++--
  19 files changed, 51 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index b545940e512b..eede43701d51 100644
@@ -681,7 +681,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device *adev,
  		goto err;
  	}
 
-	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job);
+	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job, 0);
  	if (ret)
  		goto err;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
index 98aa4beee36a..a0a129405323 100644
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
 
  	for (i = 0; i < p->gang_size; ++i) {
  		ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,
-				       num_ibs[i], &p->jobs[i]);
+				       num_ibs[i], &p->jobs[i],
+				       p->filp->client_id);
  		if (ret)
  			goto free_all_kdata;
  		p->jobs[i]->enforce_isolation = p->adev->enforce_isolation[fpriv->xcp_id];
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -2
index c774cd019a10..1dd8e940d1e9 100644
@@ -186,7 +186,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 
  int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  		     struct drm_sched_entity *entity, void *owner,
-		     unsigned int num_ibs, struct amdgpu_job **job)
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id)
  {
  	if (num_ibs == 0)
  		return -EINVAL;
@@ -209,7 +210,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	if (!entity)
  		return 0;
 
-	return drm_sched_job_init(&(*job)->base, entity, 1, owner);
+	return drm_sched_job_init(&(*job)->base, entity, 1, owner,
+				  drm_client_id);
  }
 
  int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, · line 224

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
@@ -219,7 +221,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
  {
  	int r;
 
-	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job);
+	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job, 0);

Have we defined somewhere zero is invalid or something?

Regards,

Tvrtko

Quoted 314 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
  	if (r)
  		return r;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
index ce6b9ba967ff..41a03477ba5d 100644
@@ -90,7 +90,8 @@ static inline struct amdgpu_ring *amdgpu_job_ring(struct amdgpu_job *job)
 
  int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  		     struct drm_sched_entity *entity, void *owner,
-		     unsigned int num_ibs, struct amdgpu_job **job);
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id);
  int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
  			     struct drm_sched_entity *entity, void *owner,
  			     size_t size, enum amdgpu_ib_pool_type pool_type,
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
index 3d0f8d182506..70294ca6202f 100644
@@ -535,7 +535,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 
  	ret = drm_sched_job_init(&submit->sched_job,
  				 &ctx->sched_entity[args->pipe],
-				 1, submit->ctx);
+				 1, submit->ctx, file->client_id);
  	if (ret)
  		goto err_submit_put;
 
drivers/gpu/drm/imagination/pvr_job.c +1 -1
index 618503a212a7..64152b57e8b1 100644
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,
  	if (err)
  		goto err_put_job;
 
-	err = pvr_queue_job_init(job);
+	err = pvr_queue_job_init(job, pvr_file->file->client_id);
  	if (err)
  		goto err_put_job;
 
drivers/gpu/drm/imagination/pvr_queue.c +3 -2
index c4f08432882b..598180fca141 100644
@@ -1059,6 +1059,7 @@ static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
  /**
   * pvr_queue_job_init() - Initialize queue related fields in a pvr_job object.
   * @job: The job to initialize.
+ * @drm_client_id: drm_file.client_id submitting the job
   *
   * Bind the job to a queue and allocate memory to guarantee pvr_queue_job_arm()
   * and pvr_queue_job_push() can't fail. We also make sure the context type is
@@ -1068,7 +1069,7 @@ static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
   *  * 0 on success, or
   *  * An error code if something failed.
   */
-int pvr_queue_job_init(struct pvr_job *job)
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id)
  {
  	/* Fragment jobs need at least one native fence wait on the geometry job fence. */
  	u32 min_native_dep_count = job->type == DRM_PVR_JOB_TYPE_FRAGMENT ? 1 : 0;
@@ -1085,7 +1086,7 @@ int pvr_queue_job_init(struct pvr_job *job)
  	if (!pvr_cccb_cmdseq_can_fit(&queue->cccb, job_cmds_size(job, min_native_dep_count)))
  		return -E2BIG;
 
-	err = drm_sched_job_init(&job->base, &queue->entity, 1, THIS_MODULE);
+	err = drm_sched_job_init(&job->base, &queue->entity, 1, THIS_MODULE, drm_client_id);
  	if (err)
  		return err;
 
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
index e06ced69302f..bc556169b2cf 100644
@@ -139,7 +139,7 @@ struct pvr_queue {
 
  bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
 
-int pvr_queue_job_init(struct pvr_job *job);
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id);
 
  void pvr_queue_job_cleanup(struct pvr_job *job);
 
drivers/gpu/drm/lima/lima_gem.c +1 -1
index 9bb997dbb4b9..f46f961afc56 100644
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
 
  	err = lima_sched_task_init(
  		submit->task, submit->ctx->context + submit->pipe,
-		bos, submit->nr_bos, vm);
+		bos, submit->nr_bos, vm, file->client_id);
  	if (err)
  		goto err_out1;
 
drivers/gpu/drm/lima/lima_sched.c +4 -2
index b40c90e97d7e..84599549661a 100644
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe *to_lima_pipe(struct drm_gpu_scheduler *sch
  int lima_sched_task_init(struct lima_sched_task *task,
  			 struct lima_sched_context *context,
  			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm)
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id)
  {
  	int err, i;
 
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task *task,
  	for (i = 0; i < num_bos; i++)
  		drm_gem_object_get(&bos[i]->base.base);
 
-	err = drm_sched_job_init(&task->base, &context->base, 1, vm);
+	err = drm_sched_job_init(&task->base, &context->base, 1, vm,
+				 drm_client_id);
  	if (err) {
  		kfree(task->bos);
  		return err;
drivers/gpu/drm/lima/lima_sched.h +2 -1
index 85b23ba901d5..4041468586bd 100644
@@ -88,7 +88,8 @@ struct lima_sched_pipe {
  int lima_sched_task_init(struct lima_sched_task *task,
  			 struct lima_sched_context *context,
  			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm);
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id);
  void lima_sched_task_fini(struct lima_sched_task *task);
 
  int lima_sched_context_init(struct lima_sched_pipe *pipe,
drivers/gpu/drm/msm/msm_gem_submit.c +5 -3
index fba78193127d..ceeedd4186ef 100644
@@ -30,7 +30,7 @@
  static struct msm_gem_submit *submit_create(struct drm_device *dev,
  		struct msm_gpu *gpu,
  		struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
-		uint32_t nr_cmds)
+		uint32_t nr_cmds, uint64_t drm_client_id)
  {
  	static atomic_t ident = ATOMIC_INIT(0);
  	struct msm_gem_submit *submit;
@@ -54,7 +54,8 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev,
  		return ERR_PTR(ret);
  	}
 
-	ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue);
+	ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue,
+				 drm_client_id);
  	if (ret) {
  		kfree(submit->hw_fence);
  		kfree(submit);
@@ -702,7 +703,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
  		}
  	}
 
-	submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds);
+	submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds,
+			       file->client_id);
  	if (IS_ERR(submit)) {
  		ret = PTR_ERR(submit);
  		goto out_post_unlock;
drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
index 4412f2711fb5..ebc31adea39a 100644
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job,
  	}
 
  	ret = drm_sched_job_init(&job->base, &sched->entity,
-				 args->credits, NULL);
+				 args->credits, NULL,
+				 job->file_priv->client_id);
  	if (ret)
  		goto err_free_chains;
 
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
index 04d615df5259..a8135bd75cae 100644
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data,
 
  	ret = drm_sched_job_init(&job->base,
  				 &file_priv->sched_entity[slot],
-				 1, NULL);
+				 1, NULL, file->client_id);
  	if (ret)
  		goto out_put_job;
 
drivers/gpu/drm/scheduler/sched_fence.c +3 -1
index 0f35f009b9d3..909b886cd379 100644
@@ -204,7 +204,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f)
  EXPORT_SYMBOL(to_drm_sched_fence);
 
  struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
-					      void *owner)
+					      void *owner,
+					      uint64_t drm_client_id)
  {
  	struct drm_sched_fence *fence = NULL;
 
@@ -213,6 +214,7 @@ struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
  		return NULL;
 
  	fence->owner = owner;
+	fence->drm_client_id = drm_client_id;
  	spin_lock_init(&fence->lock);
 
  	return fence;
drivers/gpu/drm/scheduler/sched_main.c +4 -2
index 7ce25281c74c..28ac709750e9 100644
@@ -776,6 +776,7 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
   * @credits: the number of credits this job contributes to the schedulers
   * credit limit
   * @owner: job owner for debugging
+ * @drm_client_id: drm_file.client_id of the owner
   *
   * Refer to drm_sched_entity_push_job() documentation
   * for locking considerations.
@@ -796,7 +797,8 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
   */
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner)
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id)
  {
  	if (!entity->rq) {
  		/* This will most likely be followed by missing frames
@@ -822,7 +824,7 @@ int drm_sched_job_init(struct drm_sched_job *job,
 
  	job->entity = entity;
  	job->credits = credits;
-	job->s_fence = drm_sched_fence_alloc(entity, owner);
+	job->s_fence = drm_sched_fence_alloc(entity, owner, drm_client_id);
  	if (!job->s_fence)
  		return -ENOMEM;
 
drivers/gpu/drm/v3d/v3d_submit.c +1 -1
index d607aa9c4ec2..a086da31f441 100644
@@ -168,7 +168,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv,
  	job->file = file_priv;
 
  	ret = drm_sched_job_init(&job->base, &v3d_priv->sched_entity[queue],
-				 1, v3d_priv);
+				 1, v3d_priv, file_priv->client_id);
  	if (ret)
  		return ret;
 
drivers/gpu/drm/xe/xe_sched_job.c +2 -1
index eeccc1c318ae..6617555e7a51 100644
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q,
  	kref_init(&job->refcount);
  	xe_exec_queue_get(job->q);
 
-	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL);
+	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL,
+				 q->xef->drm->client_id);
  	if (err)
  		goto err_free;
 
include/drm/gpu_scheduler.h +10 -2
index 95e17504e46a..42c381449443 100644
@@ -311,6 +311,13 @@ struct drm_sched_fence {
           * @owner: job owner for debugging
           */
  	void				*owner;
+
+	/**
+	 * @drm_client_id:
+	 *
+	 * The client_id of the drm_file who owned the job.
+	 */
+	uint64_t			drm_client_id;
  };
 
  struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
@@ -563,7 +570,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
  void drm_sched_fini(struct drm_gpu_scheduler *sched);
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner);
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id);
  void drm_sched_job_arm(struct drm_sched_job *job);
  int drm_sched_job_add_dependency(struct drm_sched_job *job,
  				 struct dma_fence *fence);
@@ -624,7 +632,7 @@ bool drm_sched_entity_is_ready(struct drm_sched_entity *entity);
  int drm_sched_entity_error(struct drm_sched_entity *entity);
 
  struct drm_sched_fence *drm_sched_fence_alloc(
-	struct drm_sched_entity *s_entity, void *owner);
+	struct drm_sched_entity *s_entity, void *owner, uint64_t drm_client_id);
  void drm_sched_fence_init(struct drm_sched_fence *fence,
  			  struct drm_sched_entity *entity);
  void drm_sched_fence_free(struct drm_sched_fence *fence);
#5 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

Le 14/11/2024 à 13:01, Tvrtko Ursulin a écrit :

Quoted 6 lines · Pierre-Eric Pelloux-Prayer
Quoted 2 lines

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

I wonder if it would be tidier to store the drm_client_id in the entity via drm_sched_entity_init? It would still required trickling down the info to the callers, but perhaps that could be done via driver structs instead of expanding the number for function arguments in the API. To be discussed I think. But to me the drm_client_id just sticks out too much as an odd one out in some of these functions.

Storing drm_client_id in the scheduler fence was based on Christian' suggestion, but I'm fine with moving it somewhere else.

Pierre-Eric

Quoted 360 lines
Quoted 70 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +- drivers/gpu/drm/imagination/pvr_job.c        |  2 +- drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++-- drivers/gpu/drm/imagination/pvr_queue.h      |  2 +- drivers/gpu/drm/lima/lima_gem.c              |  2 +- drivers/gpu/drm/lima/lima_sched.c            |  6 ++++-- drivers/gpu/drm/lima/lima_sched.h            |  3 ++- drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---

  drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
  drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-

  drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++-- drivers/gpu/drm/v3d/v3d_submit.c             |  2 +- drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++- include/drm/gpu_scheduler.h                  | 12 ++++++++++--

  19 files changed, 51 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index b545940e512b..eede43701d51 100644
@@ -681,7 +681,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device *adev,
           goto err;
       }
-    ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job);
+    ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job, 0);
       if (ret)
           goto err;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
index 98aa4beee36a..a0a129405323 100644
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
       for (i = 0; i < p->gang_size; ++i) {
           ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,
-                       num_ibs[i], &p->jobs[i]);
+                       num_ibs[i], &p->jobs[i],
+                       p->filp->client_id);
           if (ret)
               goto free_all_kdata;
           p->jobs[i]->enforce_isolation = p->adev->enforce_isolation[fpriv->xcp_id];
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -2
index c774cd019a10..1dd8e940d1e9 100644
@@ -186,7 +186,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
   int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
                struct drm_sched_entity *entity, void *owner,
-             unsigned int num_ibs, struct amdgpu_job **job)
+             unsigned int num_ibs, struct amdgpu_job **job,
+             uint64_t drm_client_id)
   {
       if (num_ibs == 0)
           return -EINVAL;
@@ -209,7 +210,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
       if (!entity)
           return 0;
-    return drm_sched_job_init(&(*job)->base, entity, 1, owner);
+    return drm_sched_job_init(&(*job)->base, entity, 1, owner,
+                  drm_client_id);
   }
   int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, · line 223

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
@@ -219,7 +221,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
   {
       int r;
-    r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job);
+    r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job, 0);

Have we defined somewhere zero is invalid or something?

Regards,

Tvrtko

Quoted 279 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
       if (r)
           return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
index ce6b9ba967ff..41a03477ba5d 100644
@@ -90,7 +90,8 @@ static inline struct amdgpu_ring *amdgpu_job_ring(struct amdgpu_job *job)
   int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
                struct drm_sched_entity *entity, void *owner,
-             unsigned int num_ibs, struct amdgpu_job **job);
+             unsigned int num_ibs, struct amdgpu_job **job,
+             uint64_t drm_client_id);
   int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
                    struct drm_sched_entity *entity, void *owner,
                    size_t size, enum amdgpu_ib_pool_type pool_type,
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
index 3d0f8d182506..70294ca6202f 100644
@@ -535,7 +535,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
       ret = drm_sched_job_init(&submit->sched_job,
                    &ctx->sched_entity[args->pipe],
-                 1, submit->ctx);
+                 1, submit->ctx, file->client_id);
       if (ret)
           goto err_submit_put;
drivers/gpu/drm/imagination/pvr_job.c +1 -1
index 618503a212a7..64152b57e8b1 100644
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,
       if (err)
           goto err_put_job;
-    err = pvr_queue_job_init(job);
+    err = pvr_queue_job_init(job, pvr_file->file->client_id);
       if (err)
           goto err_put_job;
drivers/gpu/drm/imagination/pvr_queue.c +3 -2
index c4f08432882b..598180fca141 100644
@@ -1059,6 +1059,7 @@ static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
   /**
    * pvr_queue_job_init() - Initialize queue related fields in a pvr_job object.
    * @job: The job to initialize.
+ * @drm_client_id: drm_file.client_id submitting the job
    *
    * Bind the job to a queue and allocate memory to guarantee pvr_queue_job_arm()
    * and pvr_queue_job_push() can't fail. We also make sure the context type is
@@ -1068,7 +1069,7 @@ static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
    *  * 0 on success, or
    *  * An error code if something failed.
    */
-int pvr_queue_job_init(struct pvr_job *job)
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id)
   {
       /* Fragment jobs need at least one native fence wait on the geometry job fence. */
       u32 min_native_dep_count = job->type == DRM_PVR_JOB_TYPE_FRAGMENT ? 1 : 0;
@@ -1085,7 +1086,7 @@ int pvr_queue_job_init(struct pvr_job *job)
       if (!pvr_cccb_cmdseq_can_fit(&queue->cccb, job_cmds_size(job, min_native_dep_count)))
           return -E2BIG;
-    err = drm_sched_job_init(&job->base, &queue->entity, 1, THIS_MODULE);
+    err = drm_sched_job_init(&job->base, &queue->entity, 1, THIS_MODULE, drm_client_id);
       if (err)
           return err;
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
index e06ced69302f..bc556169b2cf 100644
@@ -139,7 +139,7 @@ struct pvr_queue {
   bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
-int pvr_queue_job_init(struct pvr_job *job);
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id);
   void pvr_queue_job_cleanup(struct pvr_job *job);
drivers/gpu/drm/lima/lima_gem.c +0 -0
index 9bb997dbb4b9..f46f961afc56 100644
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)

      err = lima_sched_task_init(
          submit->task, submit->ctx->context + submit->pipe, -        bos, submit->nr_bos, vm);
+        bos, submit->nr_bos, vm, file->client_id); if (err)
          goto err_out1;

drivers/gpu/drm/lima/lima_sched.c +4 -2
index b40c90e97d7e..84599549661a 100644
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe *to_lima_pipe(struct drm_gpu_scheduler *sch
   int lima_sched_task_init(struct lima_sched_task *task,
                struct lima_sched_context *context,
                struct lima_bo **bos, int num_bos,
-             struct lima_vm *vm)
+             struct lima_vm *vm,
+             uint64_t drm_client_id)
   {
       int err, i;
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task *task,
       for (i = 0; i < num_bos; i++)
           drm_gem_object_get(&bos[i]->base.base);
-    err = drm_sched_job_init(&task->base, &context->base, 1, vm);
+    err = drm_sched_job_init(&task->base, &context->base, 1, vm,
+                 drm_client_id);
       if (err) {
           kfree(task->bos);
           return err;
drivers/gpu/drm/lima/lima_sched.h +2 -1
index 85b23ba901d5..4041468586bd 100644
@@ -88,7 +88,8 @@ struct lima_sched_pipe {
   int lima_sched_task_init(struct lima_sched_task *task,
                struct lima_sched_context *context,
                struct lima_bo **bos, int num_bos,
-             struct lima_vm *vm);
+             struct lima_vm *vm,
+             uint64_t drm_client_id);
   void lima_sched_task_fini(struct lima_sched_task *task);
   int lima_sched_context_init(struct lima_sched_pipe *pipe,
drivers/gpu/drm/msm/msm_gem_submit.c +5 -3
index fba78193127d..ceeedd4186ef 100644
@@ -30,7 +30,7 @@
   static struct msm_gem_submit *submit_create(struct drm_device *dev,
           struct msm_gpu *gpu,
           struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
-        uint32_t nr_cmds)
+        uint32_t nr_cmds, uint64_t drm_client_id)
   {
       static atomic_t ident = ATOMIC_INIT(0);
       struct msm_gem_submit *submit;
@@ -54,7 +54,8 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev,
           return ERR_PTR(ret);
       }
-    ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue);
+    ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue,
+                 drm_client_id);
       if (ret) {
           kfree(submit->hw_fence);
           kfree(submit);
@@ -702,7 +703,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
           }
       }
-    submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds);
+    submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds,
+                   file->client_id);
       if (IS_ERR(submit)) {
           ret = PTR_ERR(submit);
           goto out_post_unlock;
drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
index 4412f2711fb5..ebc31adea39a 100644
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job,
       }
       ret = drm_sched_job_init(&job->base, &sched->entity,
-                 args->credits, NULL);
+                 args->credits, NULL,
+                 job->file_priv->client_id);
       if (ret)
           goto err_free_chains;
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
index 04d615df5259..a8135bd75cae 100644
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data,
       ret = drm_sched_job_init(&job->base,
                    &file_priv->sched_entity[slot],
-                 1, NULL);
+                 1, NULL, file->client_id);
       if (ret)
           goto out_put_job;
drivers/gpu/drm/scheduler/sched_fence.c +3 -1
index 0f35f009b9d3..909b886cd379 100644
@@ -204,7 +204,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f)
   EXPORT_SYMBOL(to_drm_sched_fence);
   struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
-                          void *owner)
+                          void *owner,
+                          uint64_t drm_client_id)
   {
       struct drm_sched_fence *fence = NULL;
@@ -213,6 +214,7 @@ struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
           return NULL;
       fence->owner = owner;
+    fence->drm_client_id = drm_client_id;
       spin_lock_init(&fence->lock);
       return fence;
drivers/gpu/drm/scheduler/sched_main.c +4 -2
index 7ce25281c74c..28ac709750e9 100644
@@ -776,6 +776,7 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
    * @credits: the number of credits this job contributes to the schedulers
    * credit limit
    * @owner: job owner for debugging
+ * @drm_client_id: drm_file.client_id of the owner
    *
    * Refer to drm_sched_entity_push_job() documentation
    * for locking considerations.
@@ -796,7 +797,8 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
    */
   int drm_sched_job_init(struct drm_sched_job *job,
                  struct drm_sched_entity *entity,
-               u32 credits, void *owner)
+               u32 credits, void *owner,
+               uint64_t drm_client_id)
   {
       if (!entity->rq) {
           /* This will most likely be followed by missing frames
@@ -822,7 +824,7 @@ int drm_sched_job_init(struct drm_sched_job *job,
       job->entity = entity;
       job->credits = credits;
-    job->s_fence = drm_sched_fence_alloc(entity, owner);
+    job->s_fence = drm_sched_fence_alloc(entity, owner, drm_client_id);
       if (!job->s_fence)
           return -ENOMEM;
drivers/gpu/drm/v3d/v3d_submit.c +1 -1
index d607aa9c4ec2..a086da31f441 100644
@@ -168,7 +168,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv,
       job->file = file_priv;
       ret = drm_sched_job_init(&job->base, &v3d_priv->sched_entity[queue],
-                 1, v3d_priv);
+                 1, v3d_priv, file_priv->client_id);
       if (ret)
           return ret;
drivers/gpu/drm/xe/xe_sched_job.c +2 -1
index eeccc1c318ae..6617555e7a51 100644
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q,
       kref_init(&job->refcount);
       xe_exec_queue_get(job->q);
-    err = drm_sched_job_init(&job->drm, q->entity, 1, NULL);
+    err = drm_sched_job_init(&job->drm, q->entity, 1, NULL,
+                 q->xef->drm->client_id);
       if (err)
           goto err_free;
include/drm/gpu_scheduler.h +9 -1
index 95e17504e46a..42c381449443 100644
@@ -311,6 +311,13 @@ struct drm_sched_fence {
            * @owner: job owner for debugging
            */
       void                *owner;
+
+    /**
+     * @drm_client_id:
+     *
+     * The client_id of the drm_file who owned the job.
+     */
+    uint64_t            drm_client_id;
   };
   struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
@@ -563,7 +570,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
   void drm_sched_fini(struct drm_gpu_scheduler *sched);
   int drm_sched_job_init(struct drm_sched_job *job,
                  struct drm_sched_entity *entity,
-               u32 credits, void *owner);
+               u32 credits, void *owner,
+               uint64_t drm_client_id);
   void drm_sched_job_arm(struct drm_sched_job *job);
   int drm_sched_job_add_dependency(struct drm_sched_job *job,
                    struct dma_fence *fence);
@@ -624,7 +632,7 @@ bool drm_sched_entity_is_ready(struct drm_sched_entity *entity);
   int drm_sched_entity_error(struct drm_sched_entity *entity);

  struct drm_sched_fence *drm_sched_fence_alloc(
-    struct drm_sched_entity *s_entity, void *owner);
+    struct drm_sched_entity *s_entity, void *owner, uint64_t drm_client_id); void drm_sched_fence_init(struct drm_sched_fence *fence,
                struct drm_sched_entity *entity);
  void drm_sched_fence_free(struct drm_sched_fence *fence);

#6 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

Quoted 11 lines · Pierre-Eric Pelloux-Prayer

Le 14/11/2024 à 13:01, Tvrtko Ursulin a écrit :

Quoted 6 lines · Pierre-Eric Pelloux-Prayer
Quoted 2 lines

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

I wonder if it would be tidier to store the drm_client_id in the entity via drm_sched_entity_init? It would still required trickling down the info to the callers, but perhaps that could be done via driver structs instead of expanding the number for function arguments in the API. To be discussed I think. But to me the drm_client_id just sticks out too much as an odd one out in some of these functions.

Storing drm_client_id in the scheduler fence was based on Christian' suggestion, but I'm fine with moving it somewhere else.

It can be stored in sched fence, what I was thinking about is whether storing it also in the entity could a) lessen the need to change so many function signatures and b) perhaps end up with not having to add a parameter to drm_sched_job_init at all. Because less churn is better and functions with multiple ints are difficult to use and easy to make a mistake.

I am not claiming it can definitely be made simpler but I have a feeling it is worth a look.

Regards,

Tvrtko

Quoted 384 lines
Quoted 384 lines
Quoted 73 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +- drivers/gpu/drm/imagination/pvr_job.c        |  2 +- drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++-- drivers/gpu/drm/imagination/pvr_queue.h      |  2 +- drivers/gpu/drm/lima/lima_gem.c              |  2 +- drivers/gpu/drm/lima/lima_sched.c            |  6 ++++-- drivers/gpu/drm/lima/lima_sched.h            |  3 ++- drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---

  drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
  drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-

  drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++-- drivers/gpu/drm/v3d/v3d_submit.c             |  2 +- drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++- include/drm/gpu_scheduler.h                  | 12 ++++++++++--

  19 files changed, 51 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index b545940e512b..eede43701d51 100644
@@ -681,7 +681,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device 
 *adev,
           goto err;
       }
-    ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job);
+    ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job, 0);
       if (ret)
           goto err;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
index 98aa4beee36a..a0a129405323 100644
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct 
 amdgpu_cs_parser *p,
       for (i = 0; i < p->gang_size; ++i) {
           ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,
-                       num_ibs[i], &p->jobs[i]);
+                       num_ibs[i], &p->jobs[i],
+                       p->filp->client_id);
           if (ret)
               goto free_all_kdata;
           p->jobs[i]->enforce_isolation = p->adev->enforce_isolation[fpriv->xcp_id];
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -2
index c774cd019a10..1dd8e940d1e9 100644
@@ -186,7 +186,8 @@ static enum drm_gpu_sched_stat 
 amdgpu_job_timedout(struct drm_sched_job *s_job)
   int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
                struct drm_sched_entity *entity, void *owner,
-             unsigned int num_ibs, struct amdgpu_job **job)
+             unsigned int num_ibs, struct amdgpu_job **job,
+             uint64_t drm_client_id)
   {
       if (num_ibs == 0)
           return -EINVAL;
@@ -209,7 +210,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, 
 struct amdgpu_vm *vm,
       if (!entity)
           return 0;
-    return drm_sched_job_init(&(*job)->base, entity, 1, owner);
+    return drm_sched_job_init(&(*job)->base, entity, 1, owner,
+                  drm_client_id);
   }
   int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c int amdgpu_job_alloc_with_ib(struct amdgpu_device · line 224

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
@@ -219,7 +221,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device 
 *adev,
   {
       int r;
-    r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job);
+    r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job, 0);

Have we defined somewhere zero is invalid or something?

Regards,

Tvrtko

Quoted 299 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
       if (r)
           return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
index ce6b9ba967ff..41a03477ba5d 100644
@@ -90,7 +90,8 @@ static inline struct amdgpu_ring 
 *amdgpu_job_ring(struct amdgpu_job *job)
   int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
                struct drm_sched_entity *entity, void *owner,
-             unsigned int num_ibs, struct amdgpu_job **job);
+             unsigned int num_ibs, struct amdgpu_job **job,
+             uint64_t drm_client_id);
   int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,
                    struct drm_sched_entity *entity, void *owner,
                    size_t size, enum amdgpu_ib_pool_type pool_type,
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
index 3d0f8d182506..70294ca6202f 100644
@@ -535,7 +535,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device 
 *dev, void *data,
       ret = drm_sched_job_init(&submit->sched_job,
                    &ctx->sched_entity[args->pipe],
-                 1, submit->ctx);
+                 1, submit->ctx, file->client_id);
       if (ret)
           goto err_submit_put;
drivers/gpu/drm/imagination/pvr_job.c +1 -1
index 618503a212a7..64152b57e8b1 100644
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,
       if (err)
           goto err_put_job;
-    err = pvr_queue_job_init(job);
+    err = pvr_queue_job_init(job, pvr_file->file->client_id);
       if (err)
           goto err_put_job;
drivers/gpu/drm/imagination/pvr_queue.c +1 -0
index c4f08432882b..598180fca141 100644
@@ -1059,6 +1059,7 @@ static int pvr_queue_cleanup_fw_context(struct 
 pvr_queue *queue)
   /**
    * pvr_queue_job_init() - Initialize queue related fields in a pvr_job object.
    * @job: The job to initialize.
+ * @drm_client_id: drm_file.client_id submitting the job
    *
    * Bind the job to a queue and allocate memory to guarantee pvr_queue_job_arm()

   * and pvr_queue_job_push() can't fail. We also make sure the context type is

drivers/gpu/drm/imagination/pvr_queue.c +1 -1
@@ -1068,7 +1069,7 @@ static int pvr_queue_cleanup_fw_context(struct 
 pvr_queue *queue)
    *  * 0 on success, or
    *  * An error code if something failed.
    */
-int pvr_queue_job_init(struct pvr_job *job)
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id)
   {
       /* Fragment jobs need at least one native fence wait on the geometry job fence. */

      u32 min_native_dep_count = job->type == DRM_PVR_JOB_TYPE_FRAGMENT ? 1 : 0;

drivers/gpu/drm/imagination/pvr_queue.c +1 -1
@@ -1085,7 +1086,7 @@ int pvr_queue_job_init(struct pvr_job *job)
       if (!pvr_cccb_cmdseq_can_fit(&queue->cccb, job_cmds_size(job, min_native_dep_count)))
           return -E2BIG;
-    err = drm_sched_job_init(&job->base, &queue->entity, 1, 
 THIS_MODULE);
+    err = drm_sched_job_init(&job->base, &queue->entity, 1, 
 THIS_MODULE, drm_client_id);
       if (err)
           return err;
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
index e06ced69302f..bc556169b2cf 100644
@@ -139,7 +139,7 @@ struct pvr_queue {
   bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
-int pvr_queue_job_init(struct pvr_job *job);
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id);
   void pvr_queue_job_cleanup(struct pvr_job *job);
drivers/gpu/drm/lima/lima_gem.c +0 -0
index 9bb997dbb4b9..f46f961afc56 100644
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct 
 lima_submit *submit)

      err = lima_sched_task_init(
          submit->task, submit->ctx->context + submit->pipe, -        bos, submit->nr_bos, vm);
+        bos, submit->nr_bos, vm, file->client_id); if (err)
          goto err_out1;

drivers/gpu/drm/lima/lima_sched.c +4 -2
index b40c90e97d7e..84599549661a 100644
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe 
 *to_lima_pipe(struct drm_gpu_scheduler *sch
   int lima_sched_task_init(struct lima_sched_task *task,
                struct lima_sched_context *context,
                struct lima_bo **bos, int num_bos,
-             struct lima_vm *vm)
+             struct lima_vm *vm,
+             uint64_t drm_client_id)
   {
       int err, i;
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task 
 *task,
       for (i = 0; i < num_bos; i++)
           drm_gem_object_get(&bos[i]->base.base);
-    err = drm_sched_job_init(&task->base, &context->base, 1, vm);
+    err = drm_sched_job_init(&task->base, &context->base, 1, vm,
+                 drm_client_id);
       if (err) {
           kfree(task->bos);
           return err;
drivers/gpu/drm/lima/lima_sched.h +2 -1
index 85b23ba901d5..4041468586bd 100644
@@ -88,7 +88,8 @@ struct lima_sched_pipe {
   int lima_sched_task_init(struct lima_sched_task *task,
                struct lima_sched_context *context,
                struct lima_bo **bos, int num_bos,
-             struct lima_vm *vm);
+             struct lima_vm *vm,
+             uint64_t drm_client_id);
   void lima_sched_task_fini(struct lima_sched_task *task);
   int lima_sched_context_init(struct lima_sched_pipe *pipe,
drivers/gpu/drm/msm/msm_gem_submit.c +5 -3
index fba78193127d..ceeedd4186ef 100644
@@ -30,7 +30,7 @@
   static struct msm_gem_submit *submit_create(struct drm_device *dev,
           struct msm_gpu *gpu,
           struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
-        uint32_t nr_cmds)
+        uint32_t nr_cmds, uint64_t drm_client_id)
   {
       static atomic_t ident = ATOMIC_INIT(0);
       struct msm_gem_submit *submit;
@@ -54,7 +54,8 @@ static struct msm_gem_submit *submit_create(struct 
 drm_device *dev,
           return ERR_PTR(ret);
       }
-    ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue);
+    ret = drm_sched_job_init(&submit->base, queue->entity, 1, queue,
+                 drm_client_id);
       if (ret) {
           kfree(submit->hw_fence);
           kfree(submit);
@@ -702,7 +703,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, 
 void *data,
           }
       }
-    submit = submit_create(dev, gpu, queue, args->nr_bos, 
 args->nr_cmds);
+    submit = submit_create(dev, gpu, queue, args->nr_bos, 
 args->nr_cmds,
+                   file->client_id);
       if (IS_ERR(submit)) {

          ret = PTR_ERR(submit);
          goto out_post_unlock;

drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
index 4412f2711fb5..ebc31adea39a 100644
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job,
       }
       ret = drm_sched_job_init(&job->base, &sched->entity,
-                 args->credits, NULL);
+                 args->credits, NULL,
+                 job->file_priv->client_id);
       if (ret)
           goto err_free_chains;
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
index 04d615df5259..a8135bd75cae 100644
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct 
 drm_device *dev, void *data,
       ret = drm_sched_job_init(&job->base,
                    &file_priv->sched_entity[slot],
-                 1, NULL);
+                 1, NULL, file->client_id);
       if (ret)
           goto out_put_job;
drivers/gpu/drm/scheduler/sched_fence.c +3 -1
index 0f35f009b9d3..909b886cd379 100644
@@ -204,7 +204,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct 
 dma_fence *f)
   EXPORT_SYMBOL(to_drm_sched_fence);
   struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,
-                          void *owner)
+                          void *owner,
+                          uint64_t drm_client_id)
   {
       struct drm_sched_fence *fence = NULL;
@@ -213,6 +214,7 @@ struct drm_sched_fence 
 *drm_sched_fence_alloc(struct drm_sched_entity *entity,
           return NULL;
       fence->owner = owner;
+    fence->drm_client_id = drm_client_id;
       spin_lock_init(&fence->lock);
       return fence;
drivers/gpu/drm/scheduler/sched_main.c +4 -2
index 7ce25281c74c..28ac709750e9 100644
@@ -776,6 +776,7 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
    * @credits: the number of credits this job contributes to the schedulers
    * credit limit
    * @owner: job owner for debugging
+ * @drm_client_id: drm_file.client_id of the owner
    *
    * Refer to drm_sched_entity_push_job() documentation
    * for locking considerations.
@@ -796,7 +797,8 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
    */
   int drm_sched_job_init(struct drm_sched_job *job,
                  struct drm_sched_entity *entity,
-               u32 credits, void *owner)
+               u32 credits, void *owner,
+               uint64_t drm_client_id)
   {
       if (!entity->rq) {
           /* This will most likely be followed by missing frames
@@ -822,7 +824,7 @@ int drm_sched_job_init(struct drm_sched_job *job,
       job->entity = entity;
       job->credits = credits;
-    job->s_fence = drm_sched_fence_alloc(entity, owner);
+    job->s_fence = drm_sched_fence_alloc(entity, owner, drm_client_id);
       if (!job->s_fence)
           return -ENOMEM;
drivers/gpu/drm/v3d/v3d_submit.c +1 -1
index d607aa9c4ec2..a086da31f441 100644
@@ -168,7 +168,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file 
 *file_priv,
       job->file = file_priv;
       ret = drm_sched_job_init(&job->base, &v3d_priv->sched_entity[queue],
-                 1, v3d_priv);
+                 1, v3d_priv, file_priv->client_id);
       if (ret)
           return ret;
drivers/gpu/drm/xe/xe_sched_job.c +2 -1
index eeccc1c318ae..6617555e7a51 100644
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct 
 xe_exec_queue *q,
       kref_init(&job->refcount);
       xe_exec_queue_get(job->q);
-    err = drm_sched_job_init(&job->drm, q->entity, 1, NULL);
+    err = drm_sched_job_init(&job->drm, q->entity, 1, NULL,
+                 q->xef->drm->client_id);
       if (err)
           goto err_free;
include/drm/gpu_scheduler.h +9 -1
index 95e17504e46a..42c381449443 100644
@@ -311,6 +311,13 @@ struct drm_sched_fence {
            * @owner: job owner for debugging
            */
       void                *owner;
+
+    /**
+     * @drm_client_id:
+     *
+     * The client_id of the drm_file who owned the job.
+     */
+    uint64_t            drm_client_id;
   };
   struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
@@ -563,7 +570,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
   void drm_sched_fini(struct drm_gpu_scheduler *sched);
   int drm_sched_job_init(struct drm_sched_job *job,
                  struct drm_sched_entity *entity,
-               u32 credits, void *owner);
+               u32 credits, void *owner,
+               uint64_t drm_client_id);
   void drm_sched_job_arm(struct drm_sched_job *job);
   int drm_sched_job_add_dependency(struct drm_sched_job *job,
                    struct dma_fence *fence);
@@ -624,7 +632,7 @@ bool drm_sched_entity_is_ready(struct 
 drm_sched_entity *entity);
   int drm_sched_entity_error(struct drm_sched_entity *entity);

  struct drm_sched_fence *drm_sched_fence_alloc(
-    struct drm_sched_entity *s_entity, void *owner); +    struct drm_sched_entity *s_entity, void *owner, uint64_t drm_client_id);
  void drm_sched_fence_init(struct drm_sched_fence *fence, struct drm_sched_entity *entity); void drm_sched_fence_free(struct drm_sched_fence *fence);

maintainer
#7 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

In reply to Pierre-Eric Pelloux-Prayer
Quoted 17 lines · Pierre-Eric Pelloux-Prayer

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++-
 drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +-
 drivers/gpu/drm/imagination/pvr_job.c        |  2 +-
 drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++--
 drivers/gpu/drm/imagination/pvr_queue.h      |  2 +-
 drivers/gpu/drm/lima/lima_gem.c              |  2 +-
 drivers/gpu/drm/lima/lima_sched.c            |  6 ++++--
 drivers/gpu/drm/lima/lima_sched.h            |  3 ++-
 drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---
Quoted 8 lines
 drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
 drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
 drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-
 drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++--
 drivers/gpu/drm/v3d/v3d_submit.c             |  2 +-
 drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++-
 include/drm/gpu_scheduler.h                  | 12 ++++++++++--
 19 files changed, 51 insertions(+), 27 deletions(-)

panthor appears to be missing from this list and it has two calls to drm_sched_job_init().

I haven't checked if there any others missing.

Steve

#8 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

Le 15/11/2024 à 13:23, Steven Price a écrit :

Quoted 27 lines · Pierre-Eric Pelloux-Prayer
Quoted 17 lines

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++-
  drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +-
  drivers/gpu/drm/imagination/pvr_job.c        |  2 +-
  drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++--
  drivers/gpu/drm/imagination/pvr_queue.h      |  2 +-
  drivers/gpu/drm/lima/lima_gem.c              |  2 +-
  drivers/gpu/drm/lima/lima_sched.c            |  6 ++++--
  drivers/gpu/drm/lima/lima_sched.h            |  3 ++-
  drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---
Quoted 8 lines
  drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
  drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-
  drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++--
  drivers/gpu/drm/v3d/v3d_submit.c             |  2 +-
  drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++-
  include/drm/gpu_scheduler.h                  | 12 ++++++++++--
  19 files changed, 51 insertions(+), 27 deletions(-)
Quoted 2 lines

panthor appears to be missing from this list and it has two calls to drm_sched_job_init().

Indeed, I missed it.

Thanks,
Pierre-Eric

Quoted 4 lines

I haven't checked if there any others missing.

Steve

#9 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

In reply to Pierre-Eric Pelloux-Prayer
Quoted 2 lines · Pierre-Eric Pelloux-Prayer

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

I think this commit message should detail what the patch is actual intended to do.

Especially, it should mention that several drivers are being touched.

Some other comments below

Quoted 69 lines

Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +- drivers/gpu/drm/imagination/pvr_job.c        |  2 +- drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++-- drivers/gpu/drm/imagination/pvr_queue.h      |  2 +- drivers/gpu/drm/lima/lima_gem.c              |  2 +- drivers/gpu/drm/lima/lima_sched.c            |  6 ++++-- drivers/gpu/drm/lima/lima_sched.h            |  3 ++- drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---

 drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
 drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
 drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-

 drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++-- drivers/gpu/drm/v3d/v3d_submit.c             |  2 +- drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++- include/drm/gpu_scheduler.h                  | 12 ++++++++++--

 19 files changed, 51 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
index b545940e512b..eede43701d51 100644
@@ -681,7 +681,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device
 *adev,
  		goto err;
  	}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
-	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job);
+	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job, 0);

  if (ret)
  goto err;

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 98aa4beee36a..a0a129405323 100644
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct
 amdgpu_cs_parser *p,


  for (i = 0; i < p->gang_size; ++i) {
  ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
-				       num_ibs[i], &p->jobs[i]);
+				       num_ibs[i], &p->jobs[i],
+				       p->filp->client_id);

  if (ret)
  goto free_all_kdata; p->jobs[i]->enforce_isolation = p->adev-

Quoted 1 line

enforce_isolation[fpriv->xcp_id];

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index c774cd019a10..1dd8e940d1e9 100644
@@ -186,7 +186,8 @@ static enum drm_gpu_sched_stat
 amdgpu_job_timedout(struct drm_sched_job *s_job)


 int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
       struct drm_sched_entity *entity, void *owner,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) · line 190

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -1
-		     unsigned int num_ibs, struct amdgpu_job **job)
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id)

You can take the short cut and use u64 instead of uint64_t. Easier to type for you and more congruent with the other code (in the kernel).

Quoted 35 lines

 {
  if (num_ibs == 0)
  return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -209,7 +210,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev,
 struct amdgpu_vm *vm,
  	if (!entity)
  		return 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -1
-	return drm_sched_job_init(&(*job)->base, entity, 1, owner);
+	return drm_sched_job_init(&(*job)->base, entity, 1, owner,
+				  drm_client_id);

 }

 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
@@ -219,7 +221,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device
 *adev,
  {
  	int r;

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
-	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job);
+	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job, 0);

  if (r)
  return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +0 -0
index ce6b9ba967ff..41a03477ba5d 100644
@@ -90,7 +90,8 @@ static inline struct amdgpu_ring
 *amdgpu_job_ring(struct amdgpu_job *job)


 int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
       struct drm_sched_entity *entity, void *owner,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.h static inline struct amdgpu_ring *amdgpu_job_ring(struct amdgpu_job *job) · line 94

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
-		     unsigned int num_ibs, struct amdgpu_job **job);
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id);

same

Quoted 52 lines

 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, struct drm_sched_entity *entity, void *owner,
       size_t size, enum amdgpu_ib_pool_type pool_type,

drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +0 -0
index 3d0f8d182506..70294ca6202f 100644
@@ -535,7 +535,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device
 *dev, void *data,


  ret = drm_sched_job_init(&submit->sched_job, &ctx->sched_entity[args->pipe],

drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
-				 1, submit->ctx);
+				 1, submit->ctx, file->client_id);

  if (ret)
  goto err_submit_put;

drivers/gpu/drm/imagination/pvr_job.c +0 -0
index 618503a212a7..64152b57e8b1 100644
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,
  	if (err)
  		goto err_put_job;

drivers/gpu/drm/imagination/pvr_job.c +1 -1
-	err = pvr_queue_job_init(job);
+	err = pvr_queue_job_init(job, pvr_file->file->client_id);

  if (err)
  goto err_put_job;

drivers/gpu/drm/imagination/pvr_queue.c +0 -0
index c4f08432882b..598180fca141 100644
@@ -1059,6 +1059,7 @@ static int pvr_queue_cleanup_fw_context(struct
 pvr_queue *queue)
  /**
   * pvr_queue_job_init() - Initialize queue related fields in a

pvr_job object.
  * @job: The job to initialize.
+ * @drm_client_id: drm_file.client_id submitting the job *
  * Bind the job to a queue and allocate memory to guarantee pvr_queue_job_arm()
  * and pvr_queue_job_push() can't fail. We also make sure the context type is

drivers/gpu/drm/imagination/pvr_queue.c static int pvr_queue_cleanup_fw_context(struct · line 1073

Quoted 6 lines
drivers/gpu/drm/imagination/pvr_queue.c +1 -1
@@ -1068,7 +1069,7 @@ static int pvr_queue_cleanup_fw_context(struct
 pvr_queue *queue)
   *  * 0 on success, or
   *  * An error code if something failed.
   */
-int pvr_queue_job_init(struct pvr_job *job)
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id)

same

Quoted 26 lines
drivers/gpu/drm/imagination/pvr_queue.c +0 -0
  {
  	/* Fragment jobs need at least one native fence wait on the

geometry job fence. */
  u32 min_native_dep_count = job->type ==
DRM_PVR_JOB_TYPE_FRAGMENT ? 1 : 0;

drivers/gpu/drm/imagination/pvr_queue.c +0 -0
@@ -1085,7 +1086,7 @@ int pvr_queue_job_init(struct pvr_job *job)
  	if (!pvr_cccb_cmdseq_can_fit(&queue->cccb,
 job_cmds_size(job, min_native_dep_count)))
  		return -E2BIG;

drivers/gpu/drm/imagination/pvr_queue.c +0 -1
-	err = drm_sched_job_init(&job->base, &queue->entity, 1,

THIS_MODULE);

drivers/gpu/drm/imagination/pvr_queue.c +1 -0
+	err = drm_sched_job_init(&job->base, &queue->entity, 1,

THIS_MODULE, drm_client_id);
  if (err)
  return err;

drivers/gpu/drm/imagination/pvr_queue.h +0 -0
index e06ced69302f..bc556169b2cf 100644
@@ -139,7 +139,7 @@ struct pvr_queue {


 bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);

drivers/gpu/drm/imagination/pvr_queue.h struct pvr_queue { · line 142

Quoted 2 lines
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
-int pvr_queue_job_init(struct pvr_job *job);
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id);

Same. Probably applies to the other patches, too.

Quoted 231 lines


 void pvr_queue_job_cleanup(struct pvr_job *job);

drivers/gpu/drm/lima/lima_gem.c +0 -0
index 9bb997dbb4b9..f46f961afc56 100644
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct
 lima_submit *submit)


  err = lima_sched_task_init(
  submit->task, submit->ctx->context + submit->pipe,

drivers/gpu/drm/lima/lima_gem.c +1 -1
-		bos, submit->nr_bos, vm);
+		bos, submit->nr_bos, vm, file->client_id);

  if (err)
  goto err_out1;

drivers/gpu/drm/lima/lima_sched.c +2 -1
index b40c90e97d7e..84599549661a 100644
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe
 *to_lima_pipe(struct drm_gpu_scheduler *sch
  int lima_sched_task_init(struct lima_sched_task *task,
  			 struct lima_sched_context *context,
  			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm)
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id)
  {
  	int err, i;

drivers/gpu/drm/lima/lima_sched.c +0 -0
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task
 *task,
  	for (i = 0; i < num_bos; i++)
  		drm_gem_object_get(&bos[i]->base.base);

drivers/gpu/drm/lima/lima_sched.c +0 -1
-	err = drm_sched_job_init(&task->base, &context->base, 1,

vm);

drivers/gpu/drm/lima/lima_sched.c +2 -0
+	err = drm_sched_job_init(&task->base, &context->base, 1, vm,
+				 drm_client_id);

  if (err) {
  kfree(task->bos);
  return err;

drivers/gpu/drm/lima/lima_sched.h +2 -1
index 85b23ba901d5..4041468586bd 100644
@@ -88,7 +88,8 @@ struct lima_sched_pipe {
  int lima_sched_task_init(struct lima_sched_task *task,
  			 struct lima_sched_context *context,
  			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm);
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id);
  void lima_sched_task_fini(struct lima_sched_task *task);


 int lima_sched_context_init(struct lima_sched_pipe *pipe,

drivers/gpu/drm/msm/msm_gem_submit.c +1 -1
index fba78193127d..ceeedd4186ef 100644
@@ -30,7 +30,7 @@
  static struct msm_gem_submit *submit_create(struct drm_device *dev,
  		struct msm_gpu *gpu,
  		struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
-		uint32_t nr_cmds)
+		uint32_t nr_cmds, uint64_t drm_client_id)
  {
  	static atomic_t ident = ATOMIC_INIT(0);
  	struct msm_gem_submit *submit;
@@ -54,7 +54,8 @@ static struct msm_gem_submit *submit_create(struct
 drm_device *dev,
  		return ERR_PTR(ret);
  	}

drivers/gpu/drm/msm/msm_gem_submit.c +0 -1
-	ret = drm_sched_job_init(&submit->base, queue->entity, 1,

queue);

drivers/gpu/drm/msm/msm_gem_submit.c +1 -0
+	ret = drm_sched_job_init(&submit->base, queue->entity, 1,

queue,

drivers/gpu/drm/msm/msm_gem_submit.c +1 -0
+				 drm_client_id);

  if (ret) {
  kfree(submit->hw_fence);
  kfree(submit);

drivers/gpu/drm/msm/msm_gem_submit.c +0 -0
@@ -702,7 +703,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev,
 void *data,
  		}
  	}

drivers/gpu/drm/msm/msm_gem_submit.c +0 -1
-	submit = submit_create(dev, gpu, queue, args->nr_bos, args-
Quoted 1 line

nr_cmds);

drivers/gpu/drm/msm/msm_gem_submit.c +1 -0
+	submit = submit_create(dev, gpu, queue, args->nr_bos, args-
Quoted 1 line

nr_cmds,

drivers/gpu/drm/msm/msm_gem_submit.c +1 -0
+			       file->client_id);

  if (IS_ERR(submit)) {
  ret = PTR_ERR(submit);
  goto out_post_unlock;

drivers/gpu/drm/nouveau/nouveau_sched.c +0 -0
index 4412f2711fb5..ebc31adea39a 100644
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job,
  	}


  ret = drm_sched_job_init(&job->base, &sched->entity,

drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
-				 args->credits, NULL);
+				 args->credits, NULL,
+				 job->file_priv->client_id);

  if (ret)
  goto err_free_chains;

drivers/gpu/drm/panfrost/panfrost_drv.c +0 -0
index 04d615df5259..a8135bd75cae 100644
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct
 drm_device *dev, void *data,


  ret = drm_sched_job_init(&job->base, &file_priv->sched_entity[slot],

drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
-				 1, NULL);
+				 1, NULL, file->client_id);

  if (ret)
  goto out_put_job;

drivers/gpu/drm/scheduler/sched_fence.c +0 -0
index 0f35f009b9d3..909b886cd379 100644
@@ -204,7 +204,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct
 dma_fence *f)
  EXPORT_SYMBOL(to_drm_sched_fence);


 struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,

drivers/gpu/drm/scheduler/sched_fence.c +2 -1
-					      void *owner)
+					      void *owner,
+					      uint64_t

drm_client_id)
 {
  struct drm_sched_fence *fence = NULL;

drivers/gpu/drm/scheduler/sched_fence.c +0 -0
@@ -213,6 +214,7 @@ struct drm_sched_fence
 *drm_sched_fence_alloc(struct drm_sched_entity *entity,
  		return NULL;


  fence->owner = owner;

drivers/gpu/drm/scheduler/sched_fence.c +1 -0
+	fence->drm_client_id = drm_client_id;

  spin_lock_init(&fence->lock);

  return fence;

drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 7ce25281c74c..28ac709750e9 100644
@@ -776,6 +776,7 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
   * @credits: the number of credits this job contributes to the

schedulers
  * credit limit
  * @owner: job owner for debugging
+ * @drm_client_id: drm_file.client_id of the owner *
  * Refer to drm_sched_entity_push_job() documentation
  * for locking considerations.

drivers/gpu/drm/scheduler/sched_main.c +2 -1
@@ -796,7 +797,8 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
   */
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner)
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id)
  {
  	if (!entity->rq) {
  		/* This will most likely be followed by missing

frames

drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -822,7 +824,7 @@ int drm_sched_job_init(struct drm_sched_job *job,


  job->entity = entity;
  job->credits = credits;

drivers/gpu/drm/scheduler/sched_main.c +1 -1
-	job->s_fence = drm_sched_fence_alloc(entity, owner);
+	job->s_fence = drm_sched_fence_alloc(entity, owner,

drm_client_id);
  if (!job->s_fence)
  return -ENOMEM;

drivers/gpu/drm/v3d/v3d_submit.c +0 -0
index d607aa9c4ec2..a086da31f441 100644
@@ -168,7 +168,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file
 *file_priv,
  	job->file = file_priv;


  ret = drm_sched_job_init(&job->base, &v3d_priv-

Quoted 1 line

sched_entity[queue],

drivers/gpu/drm/v3d/v3d_submit.c +1 -1
-				 1, v3d_priv);
+				 1, v3d_priv, file_priv->client_id);

  if (ret)
  return ret;

drivers/gpu/drm/xe/xe_sched_job.c +0 -0
index eeccc1c318ae..6617555e7a51 100644
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct
 xe_exec_queue *q,
  	kref_init(&job->refcount);
  	xe_exec_queue_get(job->q);

drivers/gpu/drm/xe/xe_sched_job.c +2 -1
-	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL);
+	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL,
+				 q->xef->drm->client_id);

  if (err)
  goto err_free;

include/drm/gpu_scheduler.h +0 -0
index 95e17504e46a..42c381449443 100644

include/drm/gpu_scheduler.h struct drm_sched_fence { · line 318

Quoted 8 lines
include/drm/gpu_scheduler.h +5 -0
@@ -311,6 +311,13 @@ struct drm_sched_fence {
           * @owner: job owner for debugging
           */
  	void				*owner;
+
+	/**
+	 * @drm_client_id:
+	 *
+	 * The client_id of the drm_file who owned the job.

s/who owned/which owns

Thx,
P.

Quoted 27 lines
include/drm/gpu_scheduler.h +2 -0
+	 */
+	uint64_t			drm_client_id;
  };


 struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);

include/drm/gpu_scheduler.h +2 -1
@@ -563,7 +570,8 @@ int drm_sched_init(struct drm_gpu_scheduler
 *sched,
  void drm_sched_fini(struct drm_gpu_scheduler *sched);
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner);
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id);
  void drm_sched_job_arm(struct drm_sched_job *job);
  int drm_sched_job_add_dependency(struct drm_sched_job *job,

  struct dma_fence *fence);

include/drm/gpu_scheduler.h +0 -0
@@ -624,7 +632,7 @@ bool drm_sched_entity_is_ready(struct
 drm_sched_entity *entity);
  int drm_sched_entity_error(struct drm_sched_entity *entity);


 struct drm_sched_fence *drm_sched_fence_alloc(

include/drm/gpu_scheduler.h +1 -1
-	struct drm_sched_entity *s_entity, void *owner);
+	struct drm_sched_entity *s_entity, void *owner, uint64_t

drm_client_id);
 void drm_sched_fence_init(struct drm_sched_fence *fence, struct drm_sched_entity *entity); void drm_sched_fence_free(struct drm_sched_fence *fence);

#10 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

Le 15/11/2024 à 15:56, Philipp Stanner a écrit :

Quoted 9 lines · Pierre-Eric Pelloux-Prayer
Quoted 2 lines

This will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.

I think this commit message should detail what the patch is actual intended to do.

Especially, it should mention that several drivers are being touched.

Ack.

Quoted 68 lines

Some other comments below

Quoted 66 lines

Signed-off-by: Pierre-Eric Pelloux-Prayer
<[email protected]>

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  3 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c      |  8 +++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  3 ++-
  drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c |  2 +-
  drivers/gpu/drm/imagination/pvr_job.c        |  2 +-
  drivers/gpu/drm/imagination/pvr_queue.c      |  5 +++--
  drivers/gpu/drm/imagination/pvr_queue.h      |  2 +-
  drivers/gpu/drm/lima/lima_gem.c              |  2 +-
  drivers/gpu/drm/lima/lima_sched.c            |  6 ++++--
  drivers/gpu/drm/lima/lima_sched.h            |  3 ++-
  drivers/gpu/drm/msm/msm_gem_submit.c         |  8 +++++---
  drivers/gpu/drm/nouveau/nouveau_sched.c      |  3 ++-
  drivers/gpu/drm/panfrost/panfrost_drv.c      |  2 +-
  drivers/gpu/drm/scheduler/sched_fence.c      |  4 +++-
  drivers/gpu/drm/scheduler/sched_main.c       |  6 ++++--
  drivers/gpu/drm/v3d/v3d_submit.c             |  2 +-
  drivers/gpu/drm/xe/xe_sched_job.c            |  3 ++-
  include/drm/gpu_scheduler.h                  | 12 ++++++++++--
  19 files changed, 51 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index b545940e512b..eede43701d51 100644
@@ -681,7 +681,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device
 *adev,
  		goto err;
  	}
 
-	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job);
+	ret = amdgpu_job_alloc(adev, NULL, NULL, NULL, 1, &job, 0);
  	if (ret)
  		goto err;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
index 98aa4beee36a..a0a129405323 100644
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct
 amdgpu_cs_parser *p,
 
  	for (i = 0; i < p->gang_size; ++i) {
  		ret = amdgpu_job_alloc(p->adev, vm, p->entities[i],
 vm,
-				       num_ibs[i], &p->jobs[i]);
+				       num_ibs[i], &p->jobs[i],
+				       p->filp->client_id);
  		if (ret)

  goto free_all_kdata; p->jobs[i]->enforce_isolation = p->adev-

Quoted 1 line

enforce_isolation[fpriv->xcp_id];

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
index c774cd019a10..1dd8e940d1e9 100644
@@ -186,7 +186,8 @@ static enum drm_gpu_sched_stat
 amdgpu_job_timedout(struct drm_sched_job *s_job)
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) · line 190

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -1
  int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm
 *vm,
  		     struct drm_sched_entity *entity, void *owner,
-		     unsigned int num_ibs, struct amdgpu_job **job)
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id)

You can take the short cut and use u64 instead of uint64_t. Easier to type for you and more congruent with the other code (in the kernel).

Ok, will do.

Quoted 95 lines
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0 -0
  {

  if (num_ibs == 0)
  return -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -1
@@ -209,7 +210,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev,
 struct amdgpu_vm *vm,
  	if (!entity)
  		return 0;
 
-	return drm_sched_job_init(&(*job)->base, entity, 1, owner);
+	return drm_sched_job_init(&(*job)->base, entity, 1, owner,
+				  drm_client_id);
  }
 

 int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,

drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -1
@@ -219,7 +221,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device
 *adev,
  {
  	int r;
 
-	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job);
+	r = amdgpu_job_alloc(adev, NULL, entity, owner, 1, job, 0);
  	if (r)
  		return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +0 -0
index ce6b9ba967ff..41a03477ba5d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_job.h static inline struct amdgpu_ring · line 96

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
@@ -90,7 +90,8 @@ static inline struct amdgpu_ring
 *amdgpu_job_ring(struct amdgpu_job *job)
 
  int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm
 *vm,
  		     struct drm_sched_entity *entity, void *owner,
-		     unsigned int num_ibs, struct amdgpu_job **job);
+		     unsigned int num_ibs, struct amdgpu_job **job,
+		     uint64_t drm_client_id);

same

Quoted 52 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +0 -0
  int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev,

       struct drm_sched_entity *entity, void
*owner,
       size_t size, enum amdgpu_ib_pool_type
pool_type,

drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
index 3d0f8d182506..70294ca6202f 100644
@@ -535,7 +535,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device
 *dev, void *data,
 
  	ret = drm_sched_job_init(&submit->sched_job,
  				 &ctx->sched_entity[args->pipe],
-				 1, submit->ctx);
+				 1, submit->ctx, file->client_id);
  	if (ret)
  		goto err_submit_put;
drivers/gpu/drm/imagination/pvr_job.c +1 -1
index 618503a212a7..64152b57e8b1 100644
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,
  	if (err)
  		goto err_put_job;
 
-	err = pvr_queue_job_init(job);
+	err = pvr_queue_job_init(job, pvr_file->file->client_id);
  	if (err)
  		goto err_put_job;
 
drivers/gpu/drm/imagination/pvr_queue.c +0 -0
index c4f08432882b..598180fca141 100644
@@ -1059,6 +1059,7 @@ static int pvr_queue_cleanup_fw_context(struct
 pvr_queue *queue)
  /**
   * pvr_queue_job_init() - Initialize queue related fields in a

pvr_job object.
  * @job: The job to initialize.
+ * @drm_client_id: drm_file.client_id submitting the job *
  * Bind the job to a queue and allocate memory to guarantee
pvr_queue_job_arm()
  * and pvr_queue_job_push() can't fail. We also make sure the
context type is

drivers/gpu/drm/imagination/pvr_queue.c +0 -0
@@ -1068,7 +1069,7 @@ static int pvr_queue_cleanup_fw_context(struct
Quoted 8 lines

drivers/gpu/drm/imagination/pvr_queue.c static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue) · line 1072

Quoted 6 lines
drivers/gpu/drm/imagination/pvr_queue.c +1 -1
 pvr_queue *queue)
   *  * 0 on success, or
   *  * An error code if something failed.
   */
-int pvr_queue_job_init(struct pvr_job *job)
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id)

same

Ack.

Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/imagination/pvr_queue.c +0 -0
  {
  	/* Fragment jobs need at least one native fence wait on the

geometry job fence. */
  u32 min_native_dep_count = job->type ==
DRM_PVR_JOB_TYPE_FRAGMENT ? 1 : 0;

drivers/gpu/drm/imagination/pvr_queue.c +1 -1
@@ -1085,7 +1086,7 @@ int pvr_queue_job_init(struct pvr_job *job)
  	if (!pvr_cccb_cmdseq_can_fit(&queue->cccb,
 job_cmds_size(job, min_native_dep_count)))
  		return -E2BIG;
 
-	err = drm_sched_job_init(&job->base, &queue->entity, 1,
 THIS_MODULE);
+	err = drm_sched_job_init(&job->base, &queue->entity, 1,
 THIS_MODULE, drm_client_id);

  if (err)
  return err;

drivers/gpu/drm/imagination/pvr_queue.h +0 -0
index e06ced69302f..bc556169b2cf 100644
@@ -139,7 +139,7 @@ struct pvr_queue {
 
Quoted 6 lines

drivers/gpu/drm/imagination/pvr_queue.h struct pvr_queue { · line 142

Quoted 4 lines
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
  bool pvr_queue_fence_is_ufo_backed(struct dma_fence *f);
 
-int pvr_queue_job_init(struct pvr_job *job);
+int pvr_queue_job_init(struct pvr_job *job, uint64_t drm_client_id);

Same. Probably applies to the other patches, too.

Noted.

Quoted 226 lines
Quoted 226 lines
drivers/gpu/drm/imagination/pvr_queue.h +0 -0
  void pvr_queue_job_cleanup(struct pvr_job *job);
 
drivers/gpu/drm/lima/lima_gem.c +1 -1
index 9bb997dbb4b9..f46f961afc56 100644
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct
 lima_submit *submit)
 
  	err = lima_sched_task_init(
  		submit->task, submit->ctx->context + submit->pipe,
-		bos, submit->nr_bos, vm);
+		bos, submit->nr_bos, vm, file->client_id);
  	if (err)
  		goto err_out1;
drivers/gpu/drm/lima/lima_sched.c +4 -2
index b40c90e97d7e..84599549661a 100644
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe
 *to_lima_pipe(struct drm_gpu_scheduler *sch
  int lima_sched_task_init(struct lima_sched_task *task,
  			 struct lima_sched_context *context,
  			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm)
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id)
  {
  	int err, i;
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task
 *task,
  	for (i = 0; i < num_bos; i++)
  		drm_gem_object_get(&bos[i]->base.base);
 
-	err = drm_sched_job_init(&task->base, &context->base, 1,
 vm);
+	err = drm_sched_job_init(&task->base, &context->base, 1, vm,
+				 drm_client_id);
  	if (err) {

  kfree(task->bos);
  return err;

drivers/gpu/drm/lima/lima_sched.h +2 -1
index 85b23ba901d5..4041468586bd 100644
@@ -88,7 +88,8 @@ struct lima_sched_pipe {
  int lima_sched_task_init(struct lima_sched_task *task,
  			 struct lima_sched_context *context,
  			 struct lima_bo **bos, int num_bos,
-			 struct lima_vm *vm);
+			 struct lima_vm *vm,
+			 uint64_t drm_client_id);
  void lima_sched_task_fini(struct lima_sched_task *task);
 
  int lima_sched_context_init(struct lima_sched_pipe *pipe,
drivers/gpu/drm/msm/msm_gem_submit.c +3 -2
index fba78193127d..ceeedd4186ef 100644
@@ -30,7 +30,7 @@
  static struct msm_gem_submit *submit_create(struct drm_device *dev,
  		struct msm_gpu *gpu,
  		struct msm_gpu_submitqueue *queue, uint32_t nr_bos,
-		uint32_t nr_cmds)
+		uint32_t nr_cmds, uint64_t drm_client_id)
  {
  	static atomic_t ident = ATOMIC_INIT(0);
  	struct msm_gem_submit *submit;
@@ -54,7 +54,8 @@ static struct msm_gem_submit *submit_create(struct
 drm_device *dev,
  		return ERR_PTR(ret);
  	}
 
-	ret = drm_sched_job_init(&submit->base, queue->entity, 1,
 queue);
+	ret = drm_sched_job_init(&submit->base, queue->entity, 1,
 queue,
+				 drm_client_id);

  if (ret) {
  kfree(submit->hw_fence);
  kfree(submit);

drivers/gpu/drm/msm/msm_gem_submit.c +2 -1
@@ -702,7 +703,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev,
 void *data,
  		}
  	}
 
-	submit = submit_create(dev, gpu, queue, args->nr_bos, args-
 > nr_cmds);
+	submit = submit_create(dev, gpu, queue, args->nr_bos, args-
 > nr_cmds,
+			       file->client_id);

  if (IS_ERR(submit)) {
  ret = PTR_ERR(submit);
  goto out_post_unlock;

drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
index 4412f2711fb5..ebc31adea39a 100644
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job,
  	}
 
  	ret = drm_sched_job_init(&job->base, &sched->entity,
-				 args->credits, NULL);
+				 args->credits, NULL,
+				 job->file_priv->client_id);
  	if (ret)
  		goto err_free_chains;
 
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
index 04d615df5259..a8135bd75cae 100644
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct
 drm_device *dev, void *data,
 
  	ret = drm_sched_job_init(&job->base,
  				 &file_priv->sched_entity[slot],
-				 1, NULL);
+				 1, NULL, file->client_id);
  	if (ret)
  		goto out_put_job;
drivers/gpu/drm/scheduler/sched_fence.c +2 -1
index 0f35f009b9d3..909b886cd379 100644
@@ -204,7 +204,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct
 dma_fence *f)
  EXPORT_SYMBOL(to_drm_sched_fence);
 
  struct drm_sched_fence *drm_sched_fence_alloc(struct
 drm_sched_entity *entity,
-					      void *owner)
+					      void *owner,
+					      uint64_t
 drm_client_id)

 {
  struct drm_sched_fence *fence = NULL;

drivers/gpu/drm/scheduler/sched_fence.c +1 -0
@@ -213,6 +214,7 @@ struct drm_sched_fence
 *drm_sched_fence_alloc(struct drm_sched_entity *entity,
  		return NULL;
 
  	fence->owner = owner;
+	fence->drm_client_id = drm_client_id;
  	spin_lock_init(&fence->lock);
 

  return fence;

drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 7ce25281c74c..28ac709750e9 100644
@@ -776,6 +776,7 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
   * @credits: the number of credits this job contributes to the

schedulers
  * credit limit
  * @owner: job owner for debugging
+ * @drm_client_id: drm_file.client_id of the owner *
  * Refer to drm_sched_entity_push_job() documentation
  * for locking considerations.

drivers/gpu/drm/scheduler/sched_main.c +2 -1
@@ -796,7 +797,8 @@ EXPORT_SYMBOL(drm_sched_resubmit_jobs);
   */
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner)
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id)
  {
  	if (!entity->rq) {
  		/* This will most likely be followed by missing

frames

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -822,7 +824,7 @@ int drm_sched_job_init(struct drm_sched_job *job,
 
  	job->entity = entity;
  	job->credits = credits;
-	job->s_fence = drm_sched_fence_alloc(entity, owner);
+	job->s_fence = drm_sched_fence_alloc(entity, owner,
 drm_client_id);
  	if (!job->s_fence)
  		return -ENOMEM;
drivers/gpu/drm/v3d/v3d_submit.c +1 -1
index d607aa9c4ec2..a086da31f441 100644
@@ -168,7 +168,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file
 *file_priv,
  	job->file = file_priv;
 
  	ret = drm_sched_job_init(&job->base, &v3d_priv-
 > sched_entity[queue],
-				 1, v3d_priv);
+				 1, v3d_priv, file_priv->client_id);
  	if (ret)

  return ret;

drivers/gpu/drm/xe/xe_sched_job.c +2 -1
index eeccc1c318ae..6617555e7a51 100644
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct
 xe_exec_queue *q,
  	kref_init(&job->refcount);
  	xe_exec_queue_get(job->q);
 
-	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL);
+	err = drm_sched_job_init(&job->drm, q->entity, 1, NULL,
+				 q->xef->drm->client_id);
  	if (err)
  		goto err_free;
Quoted 16 lines
Quoted 6 lines
include/drm/gpu_scheduler.h +0 -0
index 95e17504e46a..42c381449443 100644

include/drm/gpu_scheduler.h struct drm_sched_fence { · line 318

Quoted 8 lines
include/drm/gpu_scheduler.h +5 -0
@@ -311,6 +311,13 @@ struct drm_sched_fence {
           * @owner: job owner for debugging
           */
  	void				*owner;
+
+	/**
+	 * @drm_client_id:
+	 *
+	 * The client_id of the drm_file who owned the job.

s/who owned/which owns

Thanks, will fix.

Pierre-Eric

Quoted 33 lines

Thx,
P.

Quoted 27 lines
include/drm/gpu_scheduler.h +4 -1
+	 */
+	uint64_t			drm_client_id;
  };
 
  struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
@@ -563,7 +570,8 @@ int drm_sched_init(struct drm_gpu_scheduler
 *sched,
  void drm_sched_fini(struct drm_gpu_scheduler *sched);
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,
-		       u32 credits, void *owner);
+		       u32 credits, void *owner,
+		       uint64_t drm_client_id);
  void drm_sched_job_arm(struct drm_sched_job *job);
  int drm_sched_job_add_dependency(struct drm_sched_job *job,

  struct dma_fence *fence);

include/drm/gpu_scheduler.h +1 -1
@@ -624,7 +632,7 @@ bool drm_sched_entity_is_ready(struct
 drm_sched_entity *entity);
  int drm_sched_entity_error(struct drm_sched_entity *entity);
 
  struct drm_sched_fence *drm_sched_fence_alloc(
-	struct drm_sched_entity *s_entity, void *owner);
+	struct drm_sched_entity *s_entity, void *owner, uint64_t
 drm_client_id);
  void drm_sched_fence_init(struct drm_sched_fence *fence,

    struct drm_sched_entity *entity); void drm_sched_fence_free(struct drm_sched_fence *fence);

#11 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

In reply to Pierre-Eric Pelloux-Prayer
kernel test robot noticed the following build errors:

Hi Pierre-Eric,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-xe/drm-xe-next]
[also build test ERROR on next-20241115]
[cannot apply to linus/master drm-misc/drm-misc-next v6.12-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pierre-Eric-Pelloux-Prayer/drm-debugfs-output-client_id-in-in-drm_clients_info/20241114-180547
base:   https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next
patch link:    https://lore.kernel.org/r/20241114100113.150647-3-pierre-eric.pelloux-prayer%40amd.com
patch subject: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence
config: arm-randconfig-002-20241117 (https://download.01.org/0day-ci/archive/20241117/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 592c0fe55f6d9a811028b5f3507be91458ab2713)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241117/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/gpu/drm/panthor/panthor_mmu.c:5:
In file included from include/drm/drm_debugfs.h:38:
In file included from include/drm/drm_gpuvm.h:34:
In file included from include/drm/drm_gem.h:42:
In file included from include/drm/drm_vma_manager.h:27:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]

     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/gpu/drm/panthor/panthor_mmu.c:2472:57: error: too few arguments to function call, expected 5, have 4
    2472 |         ret = drm_sched_job_init(&job->base, &vm->entity, 1, vm);
         |               ~~~~~~~~~~~~~~~~~~                               ^
   include/drm/gpu_scheduler.h:571:5: note: 'drm_sched_job_init' declared here
     571 | int drm_sched_job_init(struct drm_sched_job *job,
         |     ^                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
     572 |                        struct drm_sched_entity *entity,
         |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     573 |                        u32 credits, void *owner,
         |                        ~~~~~~~~~~~~~~~~~~~~~~~~~
     574 |                        uint64_t drm_client_id);
         |                        ~~~~~~~~~~~~~~~~~~~~~~

1 warning and 1 error generated.
--
In file included from drivers/gpu/drm/panthor/panthor_sched.c:6:
In file included from include/drm/drm_gem_shmem_helper.h:7:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]

     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/gpu/drm/panthor/panthor_sched.c:3729:25: error: too few arguments to function call, expected 5, have 4
    3727 |         ret = drm_sched_job_init(&job->base,
         |               ~~~~~~~~~~~~~~~~~~
    3728 |                                  &job->group->queues[job->queue_idx]->entity,
    3729 |                                  credits, job->group);
         |                                                     ^
   include/drm/gpu_scheduler.h:571:5: note: 'drm_sched_job_init' declared here
     571 | int drm_sched_job_init(struct drm_sched_job *job,
         |     ^                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
     572 |                        struct drm_sched_entity *entity,
         |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     573 |                        u32 credits, void *owner,
         |                        ~~~~~~~~~~~~~~~~~~~~~~~~~
     574 |                        uint64_t drm_client_id);
         |                        ~~~~~~~~~~~~~~~~~~~~~~

1 warning and 1 error generated.

vim +2472 drivers/gpu/drm/panthor/panthor_mmu.c

647810ec247641e Boris Brezillon 2024-02-29  2435  
647810ec247641e Boris Brezillon 2024-02-29  2436  /**
647810ec247641e Boris Brezillon 2024-02-29  2437   * panthor_vm_bind_job_create() - Create a VM_BIND job
647810ec247641e Boris Brezillon 2024-02-29  2438   * @file: File.
647810ec247641e Boris Brezillon 2024-02-29  2439   * @vm: VM targeted by the VM_BIND job.
647810ec247641e Boris Brezillon 2024-02-29  2440   * @op: VM operation data.
647810ec247641e Boris Brezillon 2024-02-29  2441   *
647810ec247641e Boris Brezillon 2024-02-29  2442   * Return: A valid pointer on success, an ERR_PTR() otherwise.
647810ec247641e Boris Brezillon 2024-02-29  2443   */
647810ec247641e Boris Brezillon 2024-02-29  2444  struct drm_sched_job *
647810ec247641e Boris Brezillon 2024-02-29  2445  panthor_vm_bind_job_create(struct drm_file *file,
647810ec247641e Boris Brezillon 2024-02-29  2446  			   struct panthor_vm *vm,
647810ec247641e Boris Brezillon 2024-02-29  2447  			   const struct drm_panthor_vm_bind_op *op)
647810ec247641e Boris Brezillon 2024-02-29  2448  {
647810ec247641e Boris Brezillon 2024-02-29  2449  	struct panthor_vm_bind_job *job;
647810ec247641e Boris Brezillon 2024-02-29  2450  	int ret;
647810ec247641e Boris Brezillon 2024-02-29  2451  
647810ec247641e Boris Brezillon 2024-02-29  2452  	if (!vm)
647810ec247641e Boris Brezillon 2024-02-29  2453  		return ERR_PTR(-EINVAL);
647810ec247641e Boris Brezillon 2024-02-29  2454  
647810ec247641e Boris Brezillon 2024-02-29  2455  	if (vm->destroyed || vm->unusable)
647810ec247641e Boris Brezillon 2024-02-29  2456  		return ERR_PTR(-EINVAL);
647810ec247641e Boris Brezillon 2024-02-29  2457  
647810ec247641e Boris Brezillon 2024-02-29  2458  	job = kzalloc(sizeof(*job), GFP_KERNEL);
647810ec247641e Boris Brezillon 2024-02-29  2459  	if (!job)
647810ec247641e Boris Brezillon 2024-02-29  2460  		return ERR_PTR(-ENOMEM);
647810ec247641e Boris Brezillon 2024-02-29  2461  
647810ec247641e Boris Brezillon 2024-02-29  2462  	ret = panthor_vm_bind_prepare_op_ctx(file, vm, op, &job->ctx);
647810ec247641e Boris Brezillon 2024-02-29  2463  	if (ret) {
647810ec247641e Boris Brezillon 2024-02-29  2464  		kfree(job);
647810ec247641e Boris Brezillon 2024-02-29  2465  		return ERR_PTR(ret);
647810ec247641e Boris Brezillon 2024-02-29  2466  	}
647810ec247641e Boris Brezillon 2024-02-29  2467  
647810ec247641e Boris Brezillon 2024-02-29  2468  	INIT_WORK(&job->cleanup_op_ctx_work, panthor_vm_bind_job_cleanup_op_ctx_work);
647810ec247641e Boris Brezillon 2024-02-29  2469  	kref_init(&job->refcount);
647810ec247641e Boris Brezillon 2024-02-29  2470  	job->vm = panthor_vm_get(vm);
647810ec247641e Boris Brezillon 2024-02-29  2471  
647810ec247641e Boris Brezillon 2024-02-29 @2472  	ret = drm_sched_job_init(&job->base, &vm->entity, 1, vm);
647810ec247641e Boris Brezillon 2024-02-29  2473  	if (ret)
647810ec247641e Boris Brezillon 2024-02-29  2474  		goto err_put_job;
647810ec247641e Boris Brezillon 2024-02-29  2475  
647810ec247641e Boris Brezillon 2024-02-29  2476  	return &job->base;
647810ec247641e Boris Brezillon 2024-02-29  2477  
647810ec247641e Boris Brezillon 2024-02-29  2478  err_put_job:
647810ec247641e Boris Brezillon 2024-02-29  2479  	panthor_vm_bind_job_put(&job->base);
647810ec247641e Boris Brezillon 2024-02-29  2480  	return ERR_PTR(ret);
647810ec247641e Boris Brezillon 2024-02-29  2481  }
647810ec247641e Boris Brezillon 2024-02-29  2482  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence

In reply to Pierre-Eric Pelloux-Prayer
kernel test robot noticed the following build errors:

Hi Pierre-Eric,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-xe/drm-xe-next]
[also build test ERROR on next-20241115]
[cannot apply to linus/master drm-misc/drm-misc-next v6.12-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Pierre-Eric-Pelloux-Prayer/drm-debugfs-output-client_id-in-in-drm_clients_info/20241114-180547
base:   https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next
patch link:    https://lore.kernel.org/r/20241114100113.150647-3-pierre-eric.pelloux-prayer%40amd.com
patch subject: [PATCH v6 2/7] drm/sched: store the drm client_id in drm_sched_fence
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20241117/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241117/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpu/drm/panthor/panthor_mmu.c: In function 'panthor_vm_bind_job_create':

>> drivers/gpu/drm/panthor/panthor_mmu.c:2472:15: error: too few arguments to function 'drm_sched_job_init'
    2472 |         ret = drm_sched_job_init(&job->base, &vm->entity, 1, vm);
         |               ^~~~~~~~~~~~~~~~~~

In file included from drivers/gpu/drm/panthor/panthor_mmu.c:10:
include/drm/gpu_scheduler.h:571:5: note: declared here
571 | int drm_sched_job_init(struct drm_sched_job *job,
| ^~~~~~~~~~~~~~~~~~
--
drivers/gpu/drm/panthor/panthor_sched.c: In function 'panthor_job_create':

>> drivers/gpu/drm/panthor/panthor_sched.c:3727:15: error: too few arguments to function 'drm_sched_job_init'
    3727 |         ret = drm_sched_job_init(&job->base,
         |               ^~~~~~~~~~~~~~~~~~

In file included from drivers/gpu/drm/panthor/panthor_sched.c:8:
include/drm/gpu_scheduler.h:571:5: note: declared here
571 | int drm_sched_job_init(struct drm_sched_job *job,
| ^~~~~~~~~~~~~~~~~~

vim +/drm_sched_job_init +2472 drivers/gpu/drm/panthor/panthor_mmu.c

647810ec247641e Boris Brezillon 2024-02-29  2435  
647810ec247641e Boris Brezillon 2024-02-29  2436  /**
647810ec247641e Boris Brezillon 2024-02-29  2437   * panthor_vm_bind_job_create() - Create a VM_BIND job
647810ec247641e Boris Brezillon 2024-02-29  2438   * @file: File.
647810ec247641e Boris Brezillon 2024-02-29  2439   * @vm: VM targeted by the VM_BIND job.
647810ec247641e Boris Brezillon 2024-02-29  2440   * @op: VM operation data.
647810ec247641e Boris Brezillon 2024-02-29  2441   *
647810ec247641e Boris Brezillon 2024-02-29  2442   * Return: A valid pointer on success, an ERR_PTR() otherwise.
647810ec247641e Boris Brezillon 2024-02-29  2443   */
647810ec247641e Boris Brezillon 2024-02-29  2444  struct drm_sched_job *
647810ec247641e Boris Brezillon 2024-02-29  2445  panthor_vm_bind_job_create(struct drm_file *file,
647810ec247641e Boris Brezillon 2024-02-29  2446  			   struct panthor_vm *vm,
647810ec247641e Boris Brezillon 2024-02-29  2447  			   const struct drm_panthor_vm_bind_op *op)
647810ec247641e Boris Brezillon 2024-02-29  2448  {
647810ec247641e Boris Brezillon 2024-02-29  2449  	struct panthor_vm_bind_job *job;
647810ec247641e Boris Brezillon 2024-02-29  2450  	int ret;
647810ec247641e Boris Brezillon 2024-02-29  2451  
647810ec247641e Boris Brezillon 2024-02-29  2452  	if (!vm)
647810ec247641e Boris Brezillon 2024-02-29  2453  		return ERR_PTR(-EINVAL);
647810ec247641e Boris Brezillon 2024-02-29  2454  
647810ec247641e Boris Brezillon 2024-02-29  2455  	if (vm->destroyed || vm->unusable)
647810ec247641e Boris Brezillon 2024-02-29  2456  		return ERR_PTR(-EINVAL);
647810ec247641e Boris Brezillon 2024-02-29  2457  
647810ec247641e Boris Brezillon 2024-02-29  2458  	job = kzalloc(sizeof(*job), GFP_KERNEL);
647810ec247641e Boris Brezillon 2024-02-29  2459  	if (!job)
647810ec247641e Boris Brezillon 2024-02-29  2460  		return ERR_PTR(-ENOMEM);
647810ec247641e Boris Brezillon 2024-02-29  2461  
647810ec247641e Boris Brezillon 2024-02-29  2462  	ret = panthor_vm_bind_prepare_op_ctx(file, vm, op, &job->ctx);
647810ec247641e Boris Brezillon 2024-02-29  2463  	if (ret) {
647810ec247641e Boris Brezillon 2024-02-29  2464  		kfree(job);
647810ec247641e Boris Brezillon 2024-02-29  2465  		return ERR_PTR(ret);
647810ec247641e Boris Brezillon 2024-02-29  2466  	}
647810ec247641e Boris Brezillon 2024-02-29  2467  
647810ec247641e Boris Brezillon 2024-02-29  2468  	INIT_WORK(&job->cleanup_op_ctx_work, panthor_vm_bind_job_cleanup_op_ctx_work);
647810ec247641e Boris Brezillon 2024-02-29  2469  	kref_init(&job->refcount);
647810ec247641e Boris Brezillon 2024-02-29  2470  	job->vm = panthor_vm_get(vm);
647810ec247641e Boris Brezillon 2024-02-29  2471  
647810ec247641e Boris Brezillon 2024-02-29 @2472  	ret = drm_sched_job_init(&job->base, &vm->entity, 1, vm);
647810ec247641e Boris Brezillon 2024-02-29  2473  	if (ret)
647810ec247641e Boris Brezillon 2024-02-29  2474  		goto err_put_job;
647810ec247641e Boris Brezillon 2024-02-29  2475  
647810ec247641e Boris Brezillon 2024-02-29  2476  	return &job->base;
647810ec247641e Boris Brezillon 2024-02-29  2477  
647810ec247641e Boris Brezillon 2024-02-29  2478  err_put_job:
647810ec247641e Boris Brezillon 2024-02-29  2479  	panthor_vm_bind_job_put(&job->base);
647810ec247641e Boris Brezillon 2024-02-29  2480  	return ERR_PTR(ret);
647810ec247641e Boris Brezillon 2024-02-29  2481  }
647810ec247641e Boris Brezillon 2024-02-29  2482  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw

PATCH v6 3/7 drm/sched: add device name to the drm_sched_process_job event

In reply to Pierre-Eric Pelloux-Prayer

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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +4 -2
index c75302ca3427..c4ec28540656 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,9 +53,10 @@ 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,
+	    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)
 );
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH v6 3/7] drm/sched: add device name to the drm_sched_process_job event

Quoted 1 line · Pierre-Eric Pelloux-Prayer

Until the switch from kthread to workqueue,

Could you include the commit ID here where that happened?

"Since switching the scheduler from using kthreads to workqueues in commit 1234 ("foo: bar") userspace applications cannot determine the [...] anymore"

Quoted 2 lines

a userspace application could
determine the source device

source device of *what*? Should be mentioned.

Quoted 1 line

from the pid of the thread sending the event.

nit: s/pid/PID ?

Quoted 41 lines

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

Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]>
---
 drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 6 ++++--

 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
index c75302ca3427..c4ec28540656 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,9 +53,10 @@ 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);

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+			   __assign_str(dev);

     ),

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-	    TP_printk("entity=%p, id=%llu, fence=%p, ring=%s, job

count:%u, hw job count:%d",

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -1
-		      __entry->entity, __entry->id,
+	    TP_printk("dev=%s, entity=%p, id=%llu, fence=%p,

ring=%s, job count:%u, hw job count:%d",

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+		      __get_str(dev), __entry->entity, __entry->id,

        __entry->fence, __get_str(name), __entry->job_count, __entry->hw_job_count) );

#15 lore raw

Re: [PATCH v6 3/7] drm/sched: add device name to the drm_sched_process_job event

Hi Philipp,

Le 15/11/2024 à 16:03, Philipp Stanner a écrit :

Quoted 8 lines · Pierre-Eric Pelloux-Prayer
Quoted 1 line

Until the switch from kthread to workqueue,

Could you include the commit ID here where that happened?

"Since switching the scheduler from using kthreads to workqueues in commit 1234 ("foo: bar") userspace applications cannot determine the [...] anymore"

Sure.

Quoted 6 lines
Quoted 4 lines

a userspace application could
determine the source device

source device of *what*? Should be mentioned.

source device _of the event_.

Quoted 4 lines
Quoted 2 lines

from the pid of the thread sending the event.

nit: s/pid/PID ?

I'll update the commit message in the next version.

Thanks,
Pierre-Eric

Quoted 42 lines
Quoted 42 lines

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

Signed-off-by: Pierre-Eric Pelloux-Prayer
<[email protected]>

---
  drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
index c75302ca3427..c4ec28540656 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 +3 -2
@@ -52,9 +53,10 @@ 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,
+	    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) );

#16 lore raw

PATCH v6 4/7 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   | 39 +++++++++++--------
 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -17
index c4ec28540656..24358c4d5bbe 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("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)
 );
 
@@ -75,37 +76,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.43.0
#17 lore raw

Re: [PATCH v6 4/7] drm/sched: cleanup gpu_scheduler trace events

Quoted 4 lines · 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)"

Any special reason for %lld? Planning to use like -1 for unknown or something?

Btw in i915 we use fence=%llu:%llu which is more compact and IMO still readable so perhaps something to consider.

Regards,

Tvrtko

Quoted 98 lines
---
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 39 +++++++++++--------
  1 file changed, 22 insertions(+), 17 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -17
index c4ec28540656..24358c4d5bbe 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("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)
  );
 
@@ -75,37 +76,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
#18 lore raw

Re: [PATCH v6 4/7] drm/sched: cleanup gpu_scheduler trace events

Le 14/11/2024 à 12:50, Tvrtko Ursulin a écrit :

Quoted 9 lines · Pierre-Eric Pelloux-Prayer
Quoted 4 lines

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)"

Any special reason for %lld? Planning to use like -1 for unknown or something?

Indeed, %llu is better.

Quoted 1 line

Btw in i915 we use fence=%llu:%llu which is more compact and IMO still readable so perhaps something to consider.

I'll switch to "fence=%llu:%llu" unless others have concerns.

Thanks,
Pierre-Eric

Quoted 99 lines

Regards,

Tvrtko

Quoted 94 lines

---
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 39 +++++++++++--------

  1 file changed, 22 insertions(+), 17 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
index c4ec28540656..24358c4d5bbe 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("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)
  );

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
@@ -75,37 +76,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

#19 lore raw

Re: [PATCH v6 4/7] drm/sched: cleanup gpu_scheduler trace events

In reply to Pierre-Eric Pelloux-Prayer
Quoted 15 lines · On Thu, 14 Nov 2024 11:01:07 +0100 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   | 39 +++++++++++--------
 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
index c4ec28540656..24358c4d5bbe 100644

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h DECLARE_EVENT_CLASS(drm_sched_job, · line 39

Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -2
@@ -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)

The __string() is a 4 byte meta field in the trace event structure. This means if you have a 64bit (8 byte) field following it, there will likely be a 4 byte hole between the two fields.

I would suggest swapping the name field with the id field, then you will have four 4 byte fields in a row (name, job_count, hw_job_count, dev), which should fill all the holes.

-- Steve

Quoted 30 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +8 -5
 			     __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("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)
 );
 
#20 lore raw

Re: [PATCH v6 4/7] drm/sched: cleanup gpu_scheduler trace events

Le 14/11/2024 à 15:56, Steven Rostedt a écrit :

Quoted 29 lines
Quoted 15 lines · On Thu, 14 Nov 2024 11:01:07 +0100 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   | 39 +++++++++++--------
  1 file changed, 22 insertions(+), 17 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
index c4ec28540656..24358c4d5bbe 100644

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h DECLARE_EVENT_CLASS(drm_sched_job, · line 39

Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -2
@@ -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)

The __string() is a 4 byte meta field in the trace event structure. This means if you have a 64bit (8 byte) field following it, there will likely be a 4 byte hole between the two fields.

Quoted 3 lines

I would suggest swapping the name field with the id field, then you will have four 4 byte fields in a row (name, job_count, hw_job_count, dev), which should fill all the holes.

Good point, I'll swap them and check there's no hole.

Pierre-Eric

Quoted 34 lines

-- Steve

Quoted 30 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +8 -5
  			     __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("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)
  );
 
#21 lore raw

Re: [PATCH v6 4/7] drm/sched: cleanup gpu_scheduler trace events

In reply to Pierre-Eric Pelloux-Prayer
Quoted 1 line · Pierre-Eric Pelloux-Prayer

A fence uniquely identify a job, so this commits updates the places

s/identify/identifies

Quoted 1 line

where a kernel pointer was used as an identifier by:

But better sth like this:

"Currently, the scheduler's tracing infrastructure uses the job's dma_fence and the drm_sched_entity the job belongs to. The dma_fence alone, however, already uniquely identifies a job.

Use the dma_fence's context and sequence number exclusively identify a job in debug prints like so:

Quoted 121 lines

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

Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]>
---
 .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 39 +++++++++++------ --

 1 file changed, 22 insertions(+), 17 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
index c4ec28540656..24358c4d5bbe 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(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-			     __field(struct drm_sched_entity *,

entity)

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-			     __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-

Quoted 1 line

sched->dev))

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +2 -0
+			     __field(uint64_t, fence_context)
+			     __field(uint64_t, fence_seqno)

       ),

      TP_fast_assign(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-			   __entry->entity = entity;

     __entry->id = sched_job->id;

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-			   __entry->fence = &sched_job->s_fence-
Quoted 1 line

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);

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+			   __entry->fence_context = sched_job-
Quoted 1 line

s_fence->finished.context;

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+			   __entry->fence_seqno = sched_job-
Quoted 1 line

s_fence->finished.seqno;

+
     ),

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-	    TP_printk("dev=%s, entity=%p, id=%llu, fence=%p,

ring=%s, job count:%u, hw job count:%d",

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -2
-		      __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",

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +2 -0
+		      __get_str(dev), __entry->id,
+		      __entry->fence_context, __entry->fence_seqno,

__get_str(name),
        __entry->job_count, __entry->hw_job_count) );

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -0
@@ -75,37 +76,41 @@ TRACE_EVENT(drm_sched_process_job,
  	    TP_PROTO(struct drm_sched_fence *fence),
  	    TP_ARGS(fence),

      TP_STRUCT__entry(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +2 -1
-		    __field(struct dma_fence *, fence)
+		    __field(uint64_t, fence_context)
+		    __field(uint64_t, fence_seqno)

      ),

      TP_fast_assign(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -1
-		    __entry->fence = &fence->finished;
+		    __entry->fence_context = fence-
Quoted 1 line

finished.context;

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+		    __entry->fence_seqno = fence->finished.seqno;

      ),

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +2 -1
-	    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(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +2 -1
-			     __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)

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -1
-			     __field(unsigned, seqno)
+			     __field(uint64_t, seqno)

       ),

      TP_fast_assign(

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -1
-			   __assign_str(name);
+			   __entry->fence_context = sched_job-
Quoted 1 line

s_fence->finished.context;

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+			   __entry->fence_seqno = sched_job-
Quoted 1 line

s_fence->finished.seqno;

     __entry->id = sched_job->id; __entry->fence = fence; __entry->ctx = fence->context; __entry->seqno = fence->seqno; ),

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +0 -1
-	    TP_printk("job ring=%s, id=%llu, depends fence=%p,

context=%llu, seq=%u",

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -3
-		      __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)}",

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+		      __entry->fence_context, __entry->fence_seqno,

__entry->id,

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +1 -0
+		      __entry->ctx, __entry->seqno)

 );

 #endif

#22 lore raw

PATCH v6 5/7 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 24358c4d5bbe..67696f5e1331 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("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d",
+	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d, dependencies:%s",
 		      __get_str(dev), __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(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)
 );
 
 TRACE_EVENT(drm_sched_process_job,
drivers/gpu/drm/scheduler/sched_entity.c +7 -1
index 69bcf0e99d57..0ce3a82fe6fd 100644
@@ -592,7 +592,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, n = 0;
+		void *f;
+
+		xa_for_each(&sched_job->dependencies, index, f) { n++; }
+		trace_drm_sched_job(sched_job, entity, n);
+	}
 	atomic_inc(entity->rq->sched->score);
 	WRITE_ONCE(entity->last_user, current->group_leader);
 
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 28ac709750e9..56fdf6879506 100644
@@ -1214,7 +1214,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.43.0
#23 lore raw

PATCH v6 6/7 drm/sched: add the drm_client_id to the drm_sched_run/exec_job events

In reply to Pierre-Eric Pelloux-Prayer

For processes with multiple drm_file instances, the drm_client_id is the only way to map jobs back to their unique owner.

It's even more useful if drm client_name is set, because now a tool can map jobs to the client name instead of only having access to the process name.

---
 drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +5 -2
index 67696f5e1331..8340c7c0c6b6 100644
@@ -71,6 +71,7 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 			     __field(uint64_t, fence_seqno)
 			     __field(int, n_deps)
 			     __dynamic_array(u64, deps, dep_count * 2)
+			     __field(u64, client_id)
 			     ),
 
 	    TP_fast_assign(
@@ -93,12 +94,14 @@ DECLARE_EVENT_CLASS(drm_sched_job,
 					dyn_arr[2 * idx + 1] = fence->seqno;
 				}
 			   }
+			   __entry->client_id = sched_job->s_fence->drm_client_id;
 			   ),
-	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d, dependencies:%s",
+	    TP_printk("dev=%s, id=%llu, fence=(context:%llu, seqno:%lld), ring=%s, job count:%u, hw job count:%d, dependencies:%s, client_id:%lld",
 		      __get_str(dev), __entry->id,
 		      __entry->fence_context, __entry->fence_seqno, __get_str(name),
 		      __entry->job_count, __entry->hw_job_count,
-		      __print_dma_fence_array(p, __get_dynamic_array(deps), __entry->n_deps))
+		      __print_dma_fence_array(p, __get_dynamic_array(deps), __entry->n_deps),
+		      __entry->client_id)
 );
 
 DEFINE_EVENT(drm_sched_job, drm_sched_job,
Signature · 1 line
2.43.0
#24 lore raw

PATCH v6 7/7 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 b75cc9a70d1f..9603ac0f4c09 100644
@@ -583,3 +583,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 information about using
+Linux Kernel Tracepoints.
+In the DRM subsystem, some events are considered stable uAPI to avoid
+breaking tools (e.g.: 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 8340c7c0c6b6..ec230e558961 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.43.0
maintainer
#25 lore raw

Re: [PATCH v6 7/7] drm/doc: document some tracepoints as uAPI

Hi,

Am Donnerstag, dem 14.11.2024 um 11:01 +0100 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 57 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 b75cc9a70d1f..9603ac0f4c09 100644
@@ -583,3 +583,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 information about using
+Linux Kernel Tracepoints.
+In the DRM subsystem, some events are considered stable uAPI to avoid
+breaking tools (e.g.: 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 +7 -0
index 8340c7c0c6b6..ec230e558961 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.
+ *

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

Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +10 -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.
+ *

It might be nitpicky, but as we change the format of the tracepoints anyway and are about to declare them a ABI: I don't really like the ring name. Yes, in most hardware implementations today the mechanism to queue jobs is a ring buffer, but there are other mechanisms to schedule jobs (see for example the lima driver). Maybe we could rename this to something a bit more generic like "dev_queue" or something like that?

Regards,
Lucas

Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +5 -0
+ * * ``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. */
#26 lore raw

Re: [PATCH v6 7/7] drm/doc: document some tracepoints as uAPI

Quoted 84 lines · Lucas Stach

Hi,

Am Donnerstag, dem 14.11.2024 um 11:01 +0100 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 72 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.

Signed-off-by Pierre-Eric Pelloux-Prayer

<[email protected]>
---
 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 b75cc9a70d1f..9603ac0f4c09 100644
@@ -583,3 +583,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 information about

using

Documentation/gpu/drm-uapi.rst +2 -0
+Linux Kernel Tracepoints.
+In the DRM subsystem, some events are considered stable uAPI to

avoid
+breaking tools (e.g.: GPUVis, umr) relying on them. Stable means that fields
+cannot be removed, nor their formatting updated. Adding new fields is

Documentation/gpu/drm-uapi.rst +9 -0
+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 +0 -0
index 8340c7c0c6b6..ec230e558961 100644
@@ -33,6 +33,28 @@
  #define TRACE_SYSTEM gpu_scheduler
  #define TRACE_INCLUDE_FILE gpu_scheduler_trace

drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +10 -0
+
+/**
+ * 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

Quoted 8 lines

+ *   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.
+ *

Quoted 8 lines

It might be nitpicky, but as we change the format of the tracepoints anyway and are about to declare them a ABI: I don't really like the ring name. Yes, in most hardware implementations today the mechanism to
queue jobs is a ring buffer, but there are other mechanisms to schedule
jobs (see for example the lima driver). Maybe we could rename this to something a bit more generic like "dev_queue" or something like that?

While it might be true that the term isn't optimal or even formally correct, it is the term which is used everywhere, including presentations at conferences such as XDC and Plumbers.

So I think the price we'd pay for breaking consistency with the established term would be higher than the gained formal correctness.

Greetings,
P.

Quoted 14 lines

Regards,
Lucas

Quoted 9 lines

+ * * ``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. */

#27 lore raw
In reply to Pierre-Eric Pelloux-Prayer
Quoted 2 lines · Pierre-Eric Pelloux-Prayer

Hi,

Hi,

I have only just discovered this thread; Danilo and I (we're maintainers of the scheduler since early October) seem to miss on CC. Do you use scripts/get_maintainer?

I'll look into this series soonish.

Regards,
P.

Quoted 65 lines

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.

The first patches extend and cleanup the gpu scheduler events.

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

Changes since v5:
* Addressed Christian, Maíra and Lucas' comments.
* Added patch 1, 2, 6 to include drm_client_id to the events. This is required when a single app uses multiple fds for the same device.
* Validated that the patches don't break gpuvis

Useful links:
- userspace tool using the updated events:
https://gitlab.freedesktop.org/tomstdenis/umr/-/merge_requests/37
- v5:
https://lists.freedesktop.org/archives/dri-devel/2024-June/457827.html

Pierre-Eric Pelloux-Prayer (7):
  drm/debugfs: output client_id in in drm_clients_info drm/sched: store the drm client_id in drm_sched_fence 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/sched: add the drm_client_id to the drm_sched_run/exec_job events
  drm/doc: document some tracepoints as uAPI

 Documentation/gpu/drm-uapi.rst                |  19 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |   2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |   3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |   8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h       |   3 +- drivers/gpu/drm/drm_debugfs.c                 |  10 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c  |   2 +- drivers/gpu/drm/imagination/pvr_job.c         |   2 +- drivers/gpu/drm/imagination/pvr_queue.c       |   5 +- drivers/gpu/drm/imagination/pvr_queue.h       |   2 +- drivers/gpu/drm/lima/lima_gem.c               |   2 +- drivers/gpu/drm/lima/lima_sched.c             |   6 +- drivers/gpu/drm/lima/lima_sched.h             |   3 +- drivers/gpu/drm/msm/msm_gem_submit.c          |   8 +- drivers/gpu/drm/nouveau/nouveau_sched.c       |   3 +- drivers/gpu/drm/panfrost/panfrost_drv.c       |   2 +- .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 121 ++++++++++++++-- --
 drivers/gpu/drm/scheduler/sched_entity.c      |   8 +- drivers/gpu/drm/scheduler/sched_fence.c       |   4 +- drivers/gpu/drm/scheduler/sched_main.c        |   8 +- drivers/gpu/drm/v3d/v3d_submit.c              |   2 +- drivers/gpu/drm/xe/xe_sched_job.c             |   3 +- include/drm/gpu_scheduler.h                   |  12 +-

 23 files changed, 181 insertions(+), 57 deletions(-)
#28 lore raw

Le 15/11/2024 à 11:46, Philipp Stanner a écrit :

Quoted 9 lines · Pierre-Eric Pelloux-Prayer
Quoted 2 lines

Hi,

Hi,

I have only just discovered this thread; Danilo and I (we're maintainers of the scheduler since early October) seem to miss on CC. Do you use scripts/get_maintainer?

I've used the get_maintainer script initially, but then I've kept sending to the same list and I've missed the early October update. Sorry about that.

Quoted 2 lines

I'll look into this series soonish.

Thanks a lot!

Pierre-Eric

Quoted 69 lines

Regards,
P.

Quoted 65 lines

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.

The first patches extend and cleanup the gpu scheduler events.

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

Changes since v5:
* Addressed Christian, Maíra and Lucas' comments.
* Added patch 1, 2, 6 to include drm_client_id to the events. This is required when a single app uses multiple fds for the same
device.
* Validated that the patches don't break gpuvis

Useful links:
- userspace tool using the updated events:
https://gitlab.freedesktop.org/tomstdenis/umr/-/merge_requests/37
- v5:
https://lists.freedesktop.org/archives/dri-devel/2024-June/457827.html

Pierre-Eric Pelloux-Prayer (7):
  drm/debugfs: output client_id in in drm_clients_info drm/sched: store the drm client_id in drm_sched_fence 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/sched: add the drm_client_id to the drm_sched_run/exec_job
events
  drm/doc: document some tracepoints as uAPI

  Documentation/gpu/drm-uapi.rst                |  19 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |   3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c       |   8 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h       |   3 +-
  drivers/gpu/drm/drm_debugfs.c                 |  10 +-
  drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c  |   2 +-
  drivers/gpu/drm/imagination/pvr_job.c         |   2 +-
  drivers/gpu/drm/imagination/pvr_queue.c       |   5 +-
  drivers/gpu/drm/imagination/pvr_queue.h       |   2 +-
  drivers/gpu/drm/lima/lima_gem.c               |   2 +-
  drivers/gpu/drm/lima/lima_sched.c             |   6 +-
  drivers/gpu/drm/lima/lima_sched.h             |   3 +-
  drivers/gpu/drm/msm/msm_gem_submit.c          |   8 +-
  drivers/gpu/drm/nouveau/nouveau_sched.c       |   3 +-
  drivers/gpu/drm/panfrost/panfrost_drv.c       |   2 +-
  .../gpu/drm/scheduler/gpu_scheduler_trace.h   | 121 ++++++++++++++--
--
  drivers/gpu/drm/scheduler/sched_entity.c      |   8 +-
  drivers/gpu/drm/scheduler/sched_fence.c       |   4 +-
  drivers/gpu/drm/scheduler/sched_main.c        |   8 +-
  drivers/gpu/drm/v3d/v3d_submit.c              |   2 +-
  drivers/gpu/drm/xe/xe_sched_job.c             |   3 +-
  include/drm/gpu_scheduler.h                   |  12 +-
  23 files changed, 181 insertions(+), 57 deletions(-)