diff mbox series

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

Message ID 20241114100113.150647-3-pierre-eric.pelloux-prayer@amd.com (mailing list archive)
State New, archived
Headers show
Series Improve gpu_scheduler trace events + uAPI | expand

Commit Message

Pierre-Eric Pelloux-Prayer Nov. 14, 2024, 10:01 a.m. UTC
This will be used in a later commit to trace the drm client_id in
some of the gpu_scheduler trace events.

Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
---
 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(-)

Comments

Tvrtko Ursulin Nov. 14, 2024, 12:01 p.m. UTC | #1
On 14/11/2024 10:01, Pierre-Eric Pelloux-Prayer wrote:
> 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.

> Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
> ---
>   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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> index b545940e512b..eede43701d51 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 98aa4beee36a..a0a129405323 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -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];
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> index c774cd019a10..1dd8e940d1e9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> @@ -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);

Have we defined somewhere zero is invalid or something?

Regards,

Tvrtko

>   	if (r)
>   		return r;
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> index ce6b9ba967ff..41a03477ba5d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> @@ -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,
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> index 3d0f8d182506..70294ca6202f 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/imagination/pvr_job.c b/drivers/gpu/drm/imagination/pvr_job.c
> index 618503a212a7..64152b57e8b1 100644
> --- a/drivers/gpu/drm/imagination/pvr_job.c
> +++ b/drivers/gpu/drm/imagination/pvr_job.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/imagination/pvr_queue.c b/drivers/gpu/drm/imagination/pvr_queue.c
> index c4f08432882b..598180fca141 100644
> --- a/drivers/gpu/drm/imagination/pvr_queue.c
> +++ b/drivers/gpu/drm/imagination/pvr_queue.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/imagination/pvr_queue.h b/drivers/gpu/drm/imagination/pvr_queue.h
> index e06ced69302f..bc556169b2cf 100644
> --- a/drivers/gpu/drm/imagination/pvr_queue.h
> +++ b/drivers/gpu/drm/imagination/pvr_queue.h
> @@ -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);
>   
> diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
> index 9bb997dbb4b9..f46f961afc56 100644
> --- a/drivers/gpu/drm/lima/lima_gem.c
> +++ b/drivers/gpu/drm/lima/lima_gem.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lima_sched.c
> index b40c90e97d7e..84599549661a 100644
> --- a/drivers/gpu/drm/lima/lima_sched.c
> +++ b/drivers/gpu/drm/lima/lima_sched.c
> @@ -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;
> diff --git a/drivers/gpu/drm/lima/lima_sched.h b/drivers/gpu/drm/lima/lima_sched.h
> index 85b23ba901d5..4041468586bd 100644
> --- a/drivers/gpu/drm/lima/lima_sched.h
> +++ b/drivers/gpu/drm/lima/lima_sched.h
> @@ -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,
> diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c
> index fba78193127d..ceeedd4186ef 100644
> --- a/drivers/gpu/drm/msm/msm_gem_submit.c
> +++ b/drivers/gpu/drm/msm/msm_gem_submit.c
> @@ -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;
> diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c b/drivers/gpu/drm/nouveau/nouveau_sched.c
> index 4412f2711fb5..ebc31adea39a 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_sched.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
> index 04d615df5259..a8135bd75cae 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/scheduler/sched_fence.c
> index 0f35f009b9d3..909b886cd379 100644
> --- a/drivers/gpu/drm/scheduler/sched_fence.c
> +++ b/drivers/gpu/drm/scheduler/sched_fence.c
> @@ -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;
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 7ce25281c74c..28ac709750e9 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
> index d607aa9c4ec2..a086da31f441 100644
> --- a/drivers/gpu/drm/v3d/v3d_submit.c
> +++ b/drivers/gpu/drm/v3d/v3d_submit.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/xe/xe_sched_job.c b/drivers/gpu/drm/xe/xe_sched_job.c
> index eeccc1c318ae..6617555e7a51 100644
> --- a/drivers/gpu/drm/xe/xe_sched_job.c
> +++ b/drivers/gpu/drm/xe/xe_sched_job.c
> @@ -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;
>   
> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> index 95e17504e46a..42c381449443 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -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);
Steven Price Nov. 15, 2024, 12:23 p.m. UTC | #2
On 14/11/2024 10:01, Pierre-Eric Pelloux-Prayer wrote:
> This will be used in a later commit to trace the drm client_id in
> some of the gpu_scheduler trace events.
> 
> Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
> ---
>  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(-)

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
Philipp Stanner Nov. 15, 2024, 2:56 p.m. UTC | #3
On Thu, 2024-11-14 at 11:01 +0100, Pierre-Eric Pelloux-Prayer wrote:
> 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

> 
> Signed-off-by: Pierre-Eric Pelloux-Prayer
> <pierre-eric.pelloux-prayer@amd.com>
> ---
>  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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> index b545940e512b..eede43701d51 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 98aa4beee36a..a0a129405323 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -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];
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> index c774cd019a10..1dd8e940d1e9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
> @@ -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)

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


>  {
>  	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;
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> index ce6b9ba967ff..41a03477ba5d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
> @@ -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

>  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,
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> index 3d0f8d182506..70294ca6202f 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/imagination/pvr_job.c
> b/drivers/gpu/drm/imagination/pvr_job.c
> index 618503a212a7..64152b57e8b1 100644
> --- a/drivers/gpu/drm/imagination/pvr_job.c
> +++ b/drivers/gpu/drm/imagination/pvr_job.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/imagination/pvr_queue.c
> b/drivers/gpu/drm/imagination/pvr_queue.c
> index c4f08432882b..598180fca141 100644
> --- a/drivers/gpu/drm/imagination/pvr_queue.c
> +++ b/drivers/gpu/drm/imagination/pvr_queue.c
> @@ -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)

same

>  {
>  	/* 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;
>  
> diff --git a/drivers/gpu/drm/imagination/pvr_queue.h
> b/drivers/gpu/drm/imagination/pvr_queue.h
> index e06ced69302f..bc556169b2cf 100644
> --- a/drivers/gpu/drm/imagination/pvr_queue.h
> +++ b/drivers/gpu/drm/imagination/pvr_queue.h
> @@ -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);

Same. Probably applies to the other patches, too.

>  
>  void pvr_queue_job_cleanup(struct pvr_job *job);
>  
> diff --git a/drivers/gpu/drm/lima/lima_gem.c
> b/drivers/gpu/drm/lima/lima_gem.c
> index 9bb997dbb4b9..f46f961afc56 100644
> --- a/drivers/gpu/drm/lima/lima_gem.c
> +++ b/drivers/gpu/drm/lima/lima_gem.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/lima/lima_sched.c
> b/drivers/gpu/drm/lima/lima_sched.c
> index b40c90e97d7e..84599549661a 100644
> --- a/drivers/gpu/drm/lima/lima_sched.c
> +++ b/drivers/gpu/drm/lima/lima_sched.c
> @@ -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;
> diff --git a/drivers/gpu/drm/lima/lima_sched.h
> b/drivers/gpu/drm/lima/lima_sched.h
> index 85b23ba901d5..4041468586bd 100644
> --- a/drivers/gpu/drm/lima/lima_sched.h
> +++ b/drivers/gpu/drm/lima/lima_sched.h
> @@ -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,
> diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c
> b/drivers/gpu/drm/msm/msm_gem_submit.c
> index fba78193127d..ceeedd4186ef 100644
> --- a/drivers/gpu/drm/msm/msm_gem_submit.c
> +++ b/drivers/gpu/drm/msm/msm_gem_submit.c
> @@ -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;
> diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c
> b/drivers/gpu/drm/nouveau/nouveau_sched.c
> index 4412f2711fb5..ebc31adea39a 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_sched.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c
> b/drivers/gpu/drm/panfrost/panfrost_drv.c
> index 04d615df5259..a8135bd75cae 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/scheduler/sched_fence.c
> b/drivers/gpu/drm/scheduler/sched_fence.c
> index 0f35f009b9d3..909b886cd379 100644
> --- a/drivers/gpu/drm/scheduler/sched_fence.c
> +++ b/drivers/gpu/drm/scheduler/sched_fence.c
> @@ -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;
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c
> b/drivers/gpu/drm/scheduler/sched_main.c
> index 7ce25281c74c..28ac709750e9 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/v3d/v3d_submit.c
> b/drivers/gpu/drm/v3d/v3d_submit.c
> index d607aa9c4ec2..a086da31f441 100644
> --- a/drivers/gpu/drm/v3d/v3d_submit.c
> +++ b/drivers/gpu/drm/v3d/v3d_submit.c
> @@ -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;
>  
> diff --git a/drivers/gpu/drm/xe/xe_sched_job.c
> b/drivers/gpu/drm/xe/xe_sched_job.c
> index eeccc1c318ae..6617555e7a51 100644
> --- a/drivers/gpu/drm/xe/xe_sched_job.c
> +++ b/drivers/gpu/drm/xe/xe_sched_job.c
> @@ -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;
>  
> diff --git a/include/drm/gpu_scheduler.h
> b/include/drm/gpu_scheduler.h
> index 95e17504e46a..42c381449443 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -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.


> +	 */
> +	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);
kernel test robot Nov. 17, 2024, 2:10 a.m. UTC | #4
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/202411170920.6ntlbMfi-lkp@intel.com/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/202411170920.6ntlbMfi-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411170920.6ntlbMfi-lkp@intel.com/

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
kernel test robot Nov. 17, 2024, 2:42 a.m. UTC | #5
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/202411171023.eCuLAjlT-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241117/202411171023.eCuLAjlT-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411171023.eCuLAjlT-lkp@intel.com/

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
Pierre-Eric Pelloux-Prayer Nov. 19, 2024, 1:39 p.m. UTC | #6
Le 14/11/2024 à 13:01, Tvrtko Ursulin a écrit :
> 
> On 14/11/2024 10:01, Pierre-Eric Pelloux-Prayer wrote:
>> 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


> 
>> Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
>> ---
>>   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(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> index b545940e512b..eede43701d51 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> index 98aa4beee36a..a0a129405323 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> @@ -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];
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> index c774cd019a10..1dd8e940d1e9 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> @@ -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);
> 
> Have we defined somewhere zero is invalid or something?
> 
> Regards,
> 
> Tvrtko
> 
>>       if (r)
>>           return r;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> index ce6b9ba967ff..41a03477ba5d 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> @@ -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,
>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/ 
>> etnaviv_gem_submit.c
>> index 3d0f8d182506..70294ca6202f 100644
>> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/imagination/pvr_job.c b/drivers/gpu/drm/imagination/pvr_job.c
>> index 618503a212a7..64152b57e8b1 100644
>> --- a/drivers/gpu/drm/imagination/pvr_job.c
>> +++ b/drivers/gpu/drm/imagination/pvr_job.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/imagination/pvr_queue.c b/drivers/gpu/drm/imagination/pvr_queue.c
>> index c4f08432882b..598180fca141 100644
>> --- a/drivers/gpu/drm/imagination/pvr_queue.c
>> +++ b/drivers/gpu/drm/imagination/pvr_queue.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/imagination/pvr_queue.h b/drivers/gpu/drm/imagination/pvr_queue.h
>> index e06ced69302f..bc556169b2cf 100644
>> --- a/drivers/gpu/drm/imagination/pvr_queue.h
>> +++ b/drivers/gpu/drm/imagination/pvr_queue.h
>> @@ -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);
>> diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
>> index 9bb997dbb4b9..f46f961afc56 100644
>> --- a/drivers/gpu/drm/lima/lima_gem.c
>> +++ b/drivers/gpu/drm/lima/lima_gem.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lima_sched.c
>> index b40c90e97d7e..84599549661a 100644
>> --- a/drivers/gpu/drm/lima/lima_sched.c
>> +++ b/drivers/gpu/drm/lima/lima_sched.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/lima/lima_sched.h b/drivers/gpu/drm/lima/lima_sched.h
>> index 85b23ba901d5..4041468586bd 100644
>> --- a/drivers/gpu/drm/lima/lima_sched.h
>> +++ b/drivers/gpu/drm/lima/lima_sched.h
>> @@ -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,
>> diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c
>> index fba78193127d..ceeedd4186ef 100644
>> --- a/drivers/gpu/drm/msm/msm_gem_submit.c
>> +++ b/drivers/gpu/drm/msm/msm_gem_submit.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c b/drivers/gpu/drm/nouveau/nouveau_sched.c
>> index 4412f2711fb5..ebc31adea39a 100644
>> --- a/drivers/gpu/drm/nouveau/nouveau_sched.c
>> +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
>> index 04d615df5259..a8135bd75cae 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
>> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/scheduler/sched_fence.c
>> index 0f35f009b9d3..909b886cd379 100644
>> --- a/drivers/gpu/drm/scheduler/sched_fence.c
>> +++ b/drivers/gpu/drm/scheduler/sched_fence.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
>> index 7ce25281c74c..28ac709750e9 100644
>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
>> index d607aa9c4ec2..a086da31f441 100644
>> --- a/drivers/gpu/drm/v3d/v3d_submit.c
>> +++ b/drivers/gpu/drm/v3d/v3d_submit.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/xe/xe_sched_job.c b/drivers/gpu/drm/xe/xe_sched_job.c
>> index eeccc1c318ae..6617555e7a51 100644
>> --- a/drivers/gpu/drm/xe/xe_sched_job.c
>> +++ b/drivers/gpu/drm/xe/xe_sched_job.c
>> @@ -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;
>> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
>> index 95e17504e46a..42c381449443 100644
>> --- a/include/drm/gpu_scheduler.h
>> +++ b/include/drm/gpu_scheduler.h
>> @@ -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);
Pierre-Eric Pelloux-Prayer Nov. 19, 2024, 1:48 p.m. UTC | #7
Le 15/11/2024 à 15:56, Philipp Stanner a écrit :
> On Thu, 2024-11-14 at 11:01 +0100, Pierre-Eric Pelloux-Prayer wrote:
>> 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.

> Some other comments below
> 
>>
>> Signed-off-by: Pierre-Eric Pelloux-Prayer
>> <pierre-eric.pelloux-prayer@amd.com>
>> ---
>>   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(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> index b545940e512b..eede43701d51 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> index 98aa4beee36a..a0a129405323 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> @@ -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];
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> index c774cd019a10..1dd8e940d1e9 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>> @@ -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)
> 
> 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.

> 
> 
>>   {
>>   	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;
>>   
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> index ce6b9ba967ff..41a03477ba5d 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>> @@ -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
> 
>>   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,
>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>> b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>> index 3d0f8d182506..70294ca6202f 100644
>> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/imagination/pvr_job.c
>> b/drivers/gpu/drm/imagination/pvr_job.c
>> index 618503a212a7..64152b57e8b1 100644
>> --- a/drivers/gpu/drm/imagination/pvr_job.c
>> +++ b/drivers/gpu/drm/imagination/pvr_job.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/imagination/pvr_queue.c
>> b/drivers/gpu/drm/imagination/pvr_queue.c
>> index c4f08432882b..598180fca141 100644
>> --- a/drivers/gpu/drm/imagination/pvr_queue.c
>> +++ b/drivers/gpu/drm/imagination/pvr_queue.c
>> @@ -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)
> 
> same

Ack.

> 
>>   {
>>   	/* 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;
>>   
>> diff --git a/drivers/gpu/drm/imagination/pvr_queue.h
>> b/drivers/gpu/drm/imagination/pvr_queue.h
>> index e06ced69302f..bc556169b2cf 100644
>> --- a/drivers/gpu/drm/imagination/pvr_queue.h
>> +++ b/drivers/gpu/drm/imagination/pvr_queue.h
>> @@ -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);
> 
> Same. Probably applies to the other patches, too.

Noted.

> 
>>   
>>   void pvr_queue_job_cleanup(struct pvr_job *job);
>>   
>> diff --git a/drivers/gpu/drm/lima/lima_gem.c
>> b/drivers/gpu/drm/lima/lima_gem.c
>> index 9bb997dbb4b9..f46f961afc56 100644
>> --- a/drivers/gpu/drm/lima/lima_gem.c
>> +++ b/drivers/gpu/drm/lima/lima_gem.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/lima/lima_sched.c
>> b/drivers/gpu/drm/lima/lima_sched.c
>> index b40c90e97d7e..84599549661a 100644
>> --- a/drivers/gpu/drm/lima/lima_sched.c
>> +++ b/drivers/gpu/drm/lima/lima_sched.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/lima/lima_sched.h
>> b/drivers/gpu/drm/lima/lima_sched.h
>> index 85b23ba901d5..4041468586bd 100644
>> --- a/drivers/gpu/drm/lima/lima_sched.h
>> +++ b/drivers/gpu/drm/lima/lima_sched.h
>> @@ -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,
>> diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c
>> b/drivers/gpu/drm/msm/msm_gem_submit.c
>> index fba78193127d..ceeedd4186ef 100644
>> --- a/drivers/gpu/drm/msm/msm_gem_submit.c
>> +++ b/drivers/gpu/drm/msm/msm_gem_submit.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c
>> b/drivers/gpu/drm/nouveau/nouveau_sched.c
>> index 4412f2711fb5..ebc31adea39a 100644
>> --- a/drivers/gpu/drm/nouveau/nouveau_sched.c
>> +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c
>> b/drivers/gpu/drm/panfrost/panfrost_drv.c
>> index 04d615df5259..a8135bd75cae 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
>> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/scheduler/sched_fence.c
>> b/drivers/gpu/drm/scheduler/sched_fence.c
>> index 0f35f009b9d3..909b886cd379 100644
>> --- a/drivers/gpu/drm/scheduler/sched_fence.c
>> +++ b/drivers/gpu/drm/scheduler/sched_fence.c
>> @@ -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;
>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c
>> b/drivers/gpu/drm/scheduler/sched_main.c
>> index 7ce25281c74c..28ac709750e9 100644
>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/v3d/v3d_submit.c
>> b/drivers/gpu/drm/v3d/v3d_submit.c
>> index d607aa9c4ec2..a086da31f441 100644
>> --- a/drivers/gpu/drm/v3d/v3d_submit.c
>> +++ b/drivers/gpu/drm/v3d/v3d_submit.c
>> @@ -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;
>>   
>> diff --git a/drivers/gpu/drm/xe/xe_sched_job.c
>> b/drivers/gpu/drm/xe/xe_sched_job.c
>> index eeccc1c318ae..6617555e7a51 100644
>> --- a/drivers/gpu/drm/xe/xe_sched_job.c
>> +++ b/drivers/gpu/drm/xe/xe_sched_job.c
>> @@ -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;
>>   
>> diff --git a/include/drm/gpu_scheduler.h
>> b/include/drm/gpu_scheduler.h
>> index 95e17504e46a..42c381449443 100644
>> --- a/include/drm/gpu_scheduler.h
>> +++ b/include/drm/gpu_scheduler.h
>> @@ -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

> 
> 
> Thx,
> P.
> 
> 
>> +	 */
>> +	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);
Pierre-Eric Pelloux-Prayer Nov. 19, 2024, 1:48 p.m. UTC | #8
Le 15/11/2024 à 13:23, Steven Price a écrit :
> On 14/11/2024 10:01, Pierre-Eric Pelloux-Prayer wrote:
>> This will be used in a later commit to trace the drm client_id in
>> some of the gpu_scheduler trace events.
>>
>> Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
>> ---
>>   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(-)
> 
> 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

> 
> I haven't checked if there any others missing.
> 
> Steve
Tvrtko Ursulin Nov. 19, 2024, 4:17 p.m. UTC | #9
On 19/11/2024 13:39, Pierre-Eric Pelloux-Prayer wrote:
> 
> 
> Le 14/11/2024 à 13:01, Tvrtko Ursulin a écrit :
>>
>> On 14/11/2024 10:01, Pierre-Eric Pelloux-Prayer wrote:
>>> 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

>>> Signed-off-by: Pierre-Eric Pelloux-Prayer 
>>> <pierre-eric.pelloux-prayer@amd.com>
>>> ---
>>>   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(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>>> index b545940e512b..eede43701d51 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> index 98aa4beee36a..a0a129405323 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> @@ -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];
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>>> index c774cd019a10..1dd8e940d1e9 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
>>> @@ -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);
>>
>> Have we defined somewhere zero is invalid or something?
>>
>> Regards,
>>
>> Tvrtko
>>
>>>       if (r)
>>>           return r;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h 
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>>> index ce6b9ba967ff..41a03477ba5d 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
>>> @@ -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,
>>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c 
>>> b/drivers/gpu/drm/etnaviv/ etnaviv_gem_submit.c
>>> index 3d0f8d182506..70294ca6202f 100644
>>> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/imagination/pvr_job.c 
>>> b/drivers/gpu/drm/imagination/pvr_job.c
>>> index 618503a212a7..64152b57e8b1 100644
>>> --- a/drivers/gpu/drm/imagination/pvr_job.c
>>> +++ b/drivers/gpu/drm/imagination/pvr_job.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/imagination/pvr_queue.c 
>>> b/drivers/gpu/drm/imagination/pvr_queue.c
>>> index c4f08432882b..598180fca141 100644
>>> --- a/drivers/gpu/drm/imagination/pvr_queue.c
>>> +++ b/drivers/gpu/drm/imagination/pvr_queue.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/imagination/pvr_queue.h 
>>> b/drivers/gpu/drm/imagination/pvr_queue.h
>>> index e06ced69302f..bc556169b2cf 100644
>>> --- a/drivers/gpu/drm/imagination/pvr_queue.h
>>> +++ b/drivers/gpu/drm/imagination/pvr_queue.h
>>> @@ -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);
>>> diff --git a/drivers/gpu/drm/lima/lima_gem.c 
>>> b/drivers/gpu/drm/lima/lima_gem.c
>>> index 9bb997dbb4b9..f46f961afc56 100644
>>> --- a/drivers/gpu/drm/lima/lima_gem.c
>>> +++ b/drivers/gpu/drm/lima/lima_gem.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/lima/lima_sched.c 
>>> b/drivers/gpu/drm/lima/lima_sched.c
>>> index b40c90e97d7e..84599549661a 100644
>>> --- a/drivers/gpu/drm/lima/lima_sched.c
>>> +++ b/drivers/gpu/drm/lima/lima_sched.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/lima/lima_sched.h 
>>> b/drivers/gpu/drm/lima/lima_sched.h
>>> index 85b23ba901d5..4041468586bd 100644
>>> --- a/drivers/gpu/drm/lima/lima_sched.h
>>> +++ b/drivers/gpu/drm/lima/lima_sched.h
>>> @@ -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,
>>> diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c 
>>> b/drivers/gpu/drm/msm/msm_gem_submit.c
>>> index fba78193127d..ceeedd4186ef 100644
>>> --- a/drivers/gpu/drm/msm/msm_gem_submit.c
>>> +++ b/drivers/gpu/drm/msm/msm_gem_submit.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c 
>>> b/drivers/gpu/drm/nouveau/nouveau_sched.c
>>> index 4412f2711fb5..ebc31adea39a 100644
>>> --- a/drivers/gpu/drm/nouveau/nouveau_sched.c
>>> +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c 
>>> b/drivers/gpu/drm/panfrost/panfrost_drv.c
>>> index 04d615df5259..a8135bd75cae 100644
>>> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
>>> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/scheduler/sched_fence.c 
>>> b/drivers/gpu/drm/scheduler/sched_fence.c
>>> index 0f35f009b9d3..909b886cd379 100644
>>> --- a/drivers/gpu/drm/scheduler/sched_fence.c
>>> +++ b/drivers/gpu/drm/scheduler/sched_fence.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
>>> b/drivers/gpu/drm/scheduler/sched_main.c
>>> index 7ce25281c74c..28ac709750e9 100644
>>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/v3d/v3d_submit.c 
>>> b/drivers/gpu/drm/v3d/v3d_submit.c
>>> index d607aa9c4ec2..a086da31f441 100644
>>> --- a/drivers/gpu/drm/v3d/v3d_submit.c
>>> +++ b/drivers/gpu/drm/v3d/v3d_submit.c
>>> @@ -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;
>>> diff --git a/drivers/gpu/drm/xe/xe_sched_job.c 
>>> b/drivers/gpu/drm/xe/xe_sched_job.c
>>> index eeccc1c318ae..6617555e7a51 100644
>>> --- a/drivers/gpu/drm/xe/xe_sched_job.c
>>> +++ b/drivers/gpu/drm/xe/xe_sched_job.c
>>> @@ -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;
>>> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
>>> index 95e17504e46a..42c381449443 100644
>>> --- a/include/drm/gpu_scheduler.h
>>> +++ b/include/drm/gpu_scheduler.h
>>> @@ -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);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index b545940e512b..eede43701d51 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 98aa4beee36a..a0a129405323 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -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];
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index c774cd019a10..1dd8e940d1e9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -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;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
index ce6b9ba967ff..41a03477ba5d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
@@ -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,
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
index 3d0f8d182506..70294ca6202f 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
@@ -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;
 
diff --git a/drivers/gpu/drm/imagination/pvr_job.c b/drivers/gpu/drm/imagination/pvr_job.c
index 618503a212a7..64152b57e8b1 100644
--- a/drivers/gpu/drm/imagination/pvr_job.c
+++ b/drivers/gpu/drm/imagination/pvr_job.c
@@ -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;
 
diff --git a/drivers/gpu/drm/imagination/pvr_queue.c b/drivers/gpu/drm/imagination/pvr_queue.c
index c4f08432882b..598180fca141 100644
--- a/drivers/gpu/drm/imagination/pvr_queue.c
+++ b/drivers/gpu/drm/imagination/pvr_queue.c
@@ -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;
 
diff --git a/drivers/gpu/drm/imagination/pvr_queue.h b/drivers/gpu/drm/imagination/pvr_queue.h
index e06ced69302f..bc556169b2cf 100644
--- a/drivers/gpu/drm/imagination/pvr_queue.h
+++ b/drivers/gpu/drm/imagination/pvr_queue.h
@@ -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);
 
diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
index 9bb997dbb4b9..f46f961afc56 100644
--- a/drivers/gpu/drm/lima/lima_gem.c
+++ b/drivers/gpu/drm/lima/lima_gem.c
@@ -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;
 
diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lima_sched.c
index b40c90e97d7e..84599549661a 100644
--- a/drivers/gpu/drm/lima/lima_sched.c
+++ b/drivers/gpu/drm/lima/lima_sched.c
@@ -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;
diff --git a/drivers/gpu/drm/lima/lima_sched.h b/drivers/gpu/drm/lima/lima_sched.h
index 85b23ba901d5..4041468586bd 100644
--- a/drivers/gpu/drm/lima/lima_sched.h
+++ b/drivers/gpu/drm/lima/lima_sched.h
@@ -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,
diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c
index fba78193127d..ceeedd4186ef 100644
--- a/drivers/gpu/drm/msm/msm_gem_submit.c
+++ b/drivers/gpu/drm/msm/msm_gem_submit.c
@@ -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;
diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c b/drivers/gpu/drm/nouveau/nouveau_sched.c
index 4412f2711fb5..ebc31adea39a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_sched.c
+++ b/drivers/gpu/drm/nouveau/nouveau_sched.c
@@ -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;
 
diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
index 04d615df5259..a8135bd75cae 100644
--- a/drivers/gpu/drm/panfrost/panfrost_drv.c
+++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
@@ -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;
 
diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/scheduler/sched_fence.c
index 0f35f009b9d3..909b886cd379 100644
--- a/drivers/gpu/drm/scheduler/sched_fence.c
+++ b/drivers/gpu/drm/scheduler/sched_fence.c
@@ -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;
diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
index 7ce25281c74c..28ac709750e9 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -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;
 
diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
index d607aa9c4ec2..a086da31f441 100644
--- a/drivers/gpu/drm/v3d/v3d_submit.c
+++ b/drivers/gpu/drm/v3d/v3d_submit.c
@@ -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;
 
diff --git a/drivers/gpu/drm/xe/xe_sched_job.c b/drivers/gpu/drm/xe/xe_sched_job.c
index eeccc1c318ae..6617555e7a51 100644
--- a/drivers/gpu/drm/xe/xe_sched_job.c
+++ b/drivers/gpu/drm/xe/xe_sched_job.c
@@ -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;
 
diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
index 95e17504e46a..42c381449443 100644
--- a/include/drm/gpu_scheduler.h
+++ b/include/drm/gpu_scheduler.h
@@ -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);