Improve gpu_scheduler trace events + UAPI
Subsystems (19)
v11 cover Improve gpu_scheduler trace events + UAPI
Hi,
The initial goal of this series was to improve the drm and amdgpu trace events to be able to expose more of the inner workings of the scheduler and drivers to developers via tools.
Then, the series evolved to become focused only on gpu_scheduler. The changes around vblank events will be part of a different series, as well as the amdgpu ones.
Moreover Sima suggested to make some trace events stable uAPI, so tools can rely on them long term.
The first patches extend and cleanup the gpu scheduler events, then add a documentation entry in drm-uapi.rst.
The last 2 patches are new in v8. One is based on a suggestion from Tvrtko and gets rid of drm_sched_job::id. The other is a cleanup of amdgpu trace events to use the fence=%llu:%llu format.
The drm_sched_job patches don't affect gpuvis which has code to parse the gpu_scheduler events but these events are not enabled.
Changes since v10:
* fixed 2 errors reported by kernel test robot
* rebased on drm-misc-next
Changes since v9:
* fixed documentation link syntax
* fixed typos in commit messages
* spelled out that these events cannot be used before drm_sched_job_arm has been called
Changes since v8:
* swapped patches 8 & 9
* rebased on drm-next
Changes since v7:
* uint64_t -> u64
* reworked dependencies tracing (Tvrtko)
* use common name prefix for all events (Tvrtko)
* dropped drm_sched_job::id (Tvrtko)
Useful links:
- userspace tool using the updated events:
https://gitlab.freedesktop.org/tomstdenis/umr/-/merge_requests/37
- v8:
https://lists.freedesktop.org/archives/dri-devel/2025-March/496781.html
Pierre-Eric Pelloux-Prayer (10):
drm/debugfs: Output client_id in in drm_clients_info drm/sched: Store the drm client_id in drm_sched_fence drm/sched: Add device name to the drm_sched_process_job event drm/sched: Cleanup gpu_scheduler trace events
drm/sched: Trace dependencies for GPU jobs
drm/sched: Add the drm_client_id to the drm_sched_run/exec_job events drm/sched: Cleanup event names
drm: Get rid of drm_sched_job.id
drm/doc: Document some tracepoints as uAPI
drm/amdgpu: update trace format to match gpu_scheduler_trace
Documentation/gpu/drm-uapi.rst | 19 ++++ drivers/accel/amdxdna/aie2_ctx.c | 3 +- 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/amd/amdgpu/amdgpu_trace.h | 32 ++---- drivers/gpu/drm/drm_debugfs.c | 10 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/imagination/pvr_job.c | 2 +- drivers/gpu/drm/imagination/pvr_queue.c | 5 +- drivers/gpu/drm/imagination/pvr_queue.h | 2 +- drivers/gpu/drm/lima/lima_gem.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 6 +- drivers/gpu/drm/lima/lima_sched.h | 3 +- drivers/gpu/drm/lima/lima_trace.h | 6 +- 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/panthor/panthor_drv.c | 3 +- drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 5 +- drivers/gpu/drm/panthor/panthor_sched.h | 3 +- .../gpu/drm/scheduler/gpu_scheduler_trace.h | 103 +++++++++++++----- drivers/gpu/drm/scheduler/sched_entity.c | 16 ++- drivers/gpu/drm/scheduler/sched_fence.c | 4 +- drivers/gpu/drm/scheduler/sched_internal.h | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 12 +- .../gpu/drm/scheduler/tests/mock_scheduler.c | 3 +- drivers/gpu/drm/v3d/v3d_submit.c | 2 +- drivers/gpu/drm/xe/xe_sched_job.c | 3 +- include/drm/gpu_scheduler.h | 13 ++- 32 files changed, 191 insertions(+), 101 deletions(-)
Signature · 1 line
2.43.0
PATCH v11 1/10 drm/debugfs: Output client_id in in drm_clients_info
client_id is a unique id used by fdinfo. Having it listed in 'clients' output means a userspace application can correlate the fields, eg:
given a fdinfo id get the fdinfo name.
Geiven that client_id is a uint64_t, we use a %20llu printf format to keep the output aligned (20 = digit count of the biggest uint64_t).
--- drivers/gpu/drm/drm_debugfs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_debugfs.c +6 -4
@@ -77,14 +77,15 @@ static int drm_clients_info(struct seq_file *m, void *data)kuid_t uid;seq_printf (m, -"%20s %5s %3s master a %5s %10s %*s\n" , +"%20s %5s %3s master a %5s %10s %*s %20s\n" ,"command" ,"tgid" ,"dev" ,"uid" ,"magic" ,DRM_CLIENT_NAME_MAX_LEN , -"name" ); +"name" , +"id" );/* dev->filelist is sorted youngest first, but we want to present * oldest first (i.e. kernel, servers, clients), so walk backwardss.
@@ -100,7 +101,7 @@ static int drm_clients_info(struct seq_file *m, void *data) pid =rcu_dereference (priv->pid); task =pid_task (pid,PIDTYPE_TGID ); uid = task ?__task_cred (task)->euid :GLOBAL_ROOT_UID ; - seq_printf(m, "%20s %5d %3d %c %c %5d %10u %*s\n", + seq_printf(m, "%20s %5d %3d %c %c %5d %10u %*s %20llu\n", task ? task->comm : "<unknown>", pid_vnr(pid), priv->minor->index,
@@ -109,7 +110,8 @@ static int drm_clients_info(struct seq_file *m, void *data)from_kuid_munged (seq_user_ns (m), uid), priv->magic,DRM_CLIENT_NAME_MAX_LEN , - priv->client_name ? priv->client_name : "<unset>"); + priv->client_name ? priv->client_name :"<unset>" , + priv->client_id);rcu_read_unlock ();mutex_unlock (&priv->client_name_lock); }
Signature · 1 line
2.43.0
PATCH v11 2/10 drm/sched: Store the drm client_id in drm_sched_fence
In reply to Pierre-Eric Pelloux-PrayerThis will be used in a later commit to trace the drm client_id in some of the gpu_scheduler trace events.
This requires changing all the users of drm_sched_job_init to add an extra parameter.
The newly added drm_client_id field in the drm_sched_fence is a bit of a duplicate of the owner one. One suggestion I received was to merge those 2 fields - this can't be done right now as amdgpu uses some special values (AMDGPU_FENCE_OWNER_*) that can't really be translated into a client id. Christian is working on getting rid of those; when it's done we should be able to squash owner/drm_client_id together.
--- drivers/accel/amdxdna/aie2_ctx.c | 3 ++- 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/panthor/panthor_drv.c | 3 ++- drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 5 +++-- drivers/gpu/drm/panthor/panthor_sched.h | 3 ++- drivers/gpu/drm/scheduler/sched_fence.c | 4 +++- drivers/gpu/drm/scheduler/sched_internal.h | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 7 +++++-- drivers/gpu/drm/scheduler/tests/mock_scheduler.c | 3 ++- drivers/gpu/drm/v3d/v3d_submit.c | 2 +- drivers/gpu/drm/xe/xe_sched_job.c | 3 ++- include/drm/gpu_scheduler.h | 10 +++++++++- 26 files changed, 64 insertions(+), 34 deletions(-)
drivers/accel/amdxdna/aie2_ctx.c +2 -1
@@ -848,7 +848,8 @@ int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job *job, goto up_sem; } - ret =drm_sched_job_init (&job->base, &hwctx->priv->entity,1 , hwctx); + ret =drm_sched_job_init (&job->base, &hwctx->priv->entity,1 , hwctx, + hwctx->client->filp->client_id);if (ret) {XDNA_ERR (xdna,"DRM job init failed, ret %d" , ret); goto free_chain;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
@@ -639,7 +639,7 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device *adev, goto err; } - ret =amdgpu_job_alloc (adev,NULL ,NULL ,NULL ,1 , &job); + ret =amdgpu_job_alloc (adev,NULL ,NULL ,NULL ,1 , &job,0 );if (ret) goto err;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
@@ -293,7 +293,8 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,for (i =0 ; i < p->gang_size; ++i) { ret =amdgpu_job_alloc (p->adev, vm, p->entities[i], vm, - num_ibs[i], &p->jobs[i]); + num_ibs[i], &p->jobs[i], + p->filp->client_id);if (ret) goto free_all_kdata; p->jobs[i]->enforce_isolation = p->adev->enforce_isolation[fpriv->xcp_id];
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -3
@@ -204,7 +204,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, +u64 drm_client_id) {if (num_ibs ==0 )return -EINVAL ;
@@ -222,7 +223,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,
@@ -232,7 +234,7 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, {int r; - r =amdgpu_job_alloc (adev,NULL , entity, owner,1 , job); + r =amdgpu_job_alloc (adev,NULL , entity, owner,1 , job,0 );if (r)return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
@@ -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, +u64 drm_client_id); int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, struct drm_sched_entity *entity, void *owner, size_t size, enum amdgpu_ib_pool_type pool_type,
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +1 -1
@@ -534,7 +534,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ret =drm_sched_job_init (&submit->sched_job, &ctx->sched_entity[args->pipe], -1 , submit->ctx); +1 , submit->ctx, file->client_id);if (ret) goto err_submit_put;
drivers/gpu/drm/imagination/pvr_job.c +1 -1
@@ -446,7 +446,7 @@ create_job(struct pvr_device *pvr_dev,if (err) goto err_put_job; - err =pvr_queue_job_init (job); + err =pvr_queue_job_init (job, pvr_file->file->client_id);if (err) goto err_put_job;
drivers/gpu/drm/imagination/pvr_queue.c +3 -2
@@ -1073,6 +1073,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
@@ -1082,7 +1083,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,u64 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 ;
@@ -1099,7 +1100,7 @@ int pvr_queue_job_init(struct pvr_job *job)if (!pvr_cccb_cmdseq_can_fit (&queue->cccb,job_cmds_size (job, min_native_dep_count)))return -E2BIG ; - err =drm_sched_job_init (&job->base, &queue->entity,1 ,THIS_MODULE ); + err =drm_sched_job_init (&job->base, &queue->entity,1 ,THIS_MODULE , drm_client_id);if (err)return err;
drivers/gpu/drm/imagination/pvr_queue.h +1 -1
@@ -143,7 +143,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,u64 drm_client_id);void pvr_queue_job_cleanup (struct pvr_job *job);
drivers/gpu/drm/lima/lima_gem.c +1 -1
@@ -341,7 +341,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) err =lima_sched_task_init ( submit->task, submit->ctx->context + submit->pipe, - bos, submit->nr_bos, vm); + bos, submit->nr_bos, vm, file->client_id);if (err) goto err_out1;
drivers/gpu/drm/lima/lima_sched.c +4 -2
@@ -113,7 +113,8 @@ static inline struct lima_sched_pipe *to_lima_pipe(struct drm_gpu_scheduler *schint 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, +u64 drm_client_id) {int err, i;
@@ -124,7 +125,8 @@ int lima_sched_task_init(struct lima_sched_task *task,for (i =0 ; i < num_bos; i++)drm_gem_object_get (&bos[i]->base.base); - err =drm_sched_job_init (&task->base, &context->base,1 , vm); + err =drm_sched_job_init (&task->base, &context->base,1 , vm, + drm_client_id);if (err) {kfree (task->bos);return err;
drivers/gpu/drm/lima/lima_sched.h +2 -1
@@ -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, +u64 drm_client_id);void lima_sched_task_fini (struct lima_sched_task *task); int lima_sched_context_init(struct lima_sched_pipe *pipe,
drivers/gpu/drm/msm/msm_gem_submit.c +5 -3
@@ -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,u64 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);
@@ -693,7 +694,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, } } - submit =submit_create (dev, gpu, queue, args->nr_bos, args->nr_cmds); + submit =submit_create (dev, gpu, queue, args->nr_bos, args->nr_cmds, + file->client_id);if (IS_ERR (submit)) { ret =PTR_ERR (submit); goto out_post_unlock;
drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
@@ -87,7 +87,8 @@ nouveau_job_init(struct nouveau_job *job, } ret =drm_sched_job_init (&job->base, &sched->entity, - args->credits,NULL ); + args->credits,NULL , + job->file_priv->client_id);if (ret) goto err_free_chains;
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -1
@@ -312,7 +312,7 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data, ret =drm_sched_job_init (&job->base, &file_priv->sched_entity[slot], -1 ,NULL ); +1 ,NULL , file->client_id);if (ret) goto out_put_job;
drivers/gpu/drm/panthor/panthor_drv.c +2 -1
@@ -996,7 +996,8 @@ static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,const struct drm_panthor_queue_submit *qsubmit = &jobs_args[i];struct drm_sched_job *job; - job =panthor_job_create (pfile, args->group_handle, qsubmit); + job =panthor_job_create (pfile, args->group_handle, qsubmit, + file->client_id);if (IS_ERR (job)) { ret =PTR_ERR (job); goto out_cleanup_submit_ctx;
drivers/gpu/drm/panthor/panthor_mmu.c +1 -1
@@ -2523,7 +2523,7 @@ panthor_vm_bind_job_create(struct drm_file *file,kref_init (&job->refcount); job->vm =panthor_vm_get (vm); - ret =drm_sched_job_init (&job->base, &vm->entity,1 , vm); + ret =drm_sched_job_init (&job->base, &vm->entity,1 , vm, file->client_id);if (ret) goto err_put_job;
drivers/gpu/drm/panthor/panthor_sched.c +3 -2
@@ -3732,7 +3732,8 @@ struct panthor_vm *panthor_job_vm(struct drm_sched_job *sched_job)struct drm_sched_job *panthor_job_create (struct panthor_file *pfile,u16 group_handle, -const struct drm_panthor_queue_submit *qsubmit) +const struct drm_panthor_queue_submit *qsubmit, +u64 drm_client_id) {struct panthor_group_pool *gpool = pfile->groups;struct panthor_job *job;
@@ -3804,7 +3805,7 @@ panthor_job_create(struct panthor_file *pfile, ret =drm_sched_job_init (&job->base, &job->group->queues[job->queue_idx]->entity, - credits, job->group); + credits, job->group, drm_client_id);if (ret) goto err_put_job;
drivers/gpu/drm/panthor/panthor_sched.h +2 -1
@@ -29,7 +29,8 @@ int panthor_group_get_state(struct panthor_file *pfile,struct drm_sched_job *panthor_job_create (struct panthor_file *pfile,u16 group_handle, -const struct drm_panthor_queue_submit *qsubmit); +const struct drm_panthor_queue_submit *qsubmit, +u64 drm_client_id);struct drm_sched_job *panthor_job_get (struct drm_sched_job *job);struct panthor_vm *panthor_job_vm (struct drm_sched_job *sched_job);void panthor_job_put (struct drm_sched_job *job);
drivers/gpu/drm/scheduler/sched_fence.c +3 -1
@@ -205,7 +205,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, +u64 drm_client_id) {struct drm_sched_fence *fence =NULL ;
@@ -214,6 +215,7 @@ struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity,return NULL ; fence->owner = owner; + fence->drm_client_id = drm_client_id;spin_lock_init (&fence->lock);return fence;
drivers/gpu/drm/scheduler/sched_internal.h +1 -1
@@ -24,7 +24,7 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity);struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity);struct drm_sched_fence *drm_sched_fence_alloc (struct drm_sched_entity *s_entity, -void *owner); +void *owner,u64 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);
drivers/gpu/drm/scheduler/sched_main.c +5 -2
@@ -766,6 +766,8 @@ 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: &struct drm_file.client_id of the owner (used by trace +* events) * * Refer to drm_sched_entity_push_job() documentation * for locking considerations.
@@ -786,7 +788,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
@@ -812,7 +815,7 @@ int drm_sched_job_init(struct drm_sched_job *job, job->entity = entity; job->credits = credits; - job->s_fence =drm_sched_fence_alloc (entity, owner); + job->s_fence =drm_sched_fence_alloc (entity, owner, drm_client_id);if (!job->s_fence)return -ENOMEM ;
drivers/gpu/drm/scheduler/tests/mock_scheduler.c +2 -1
@@ -117,7 +117,8 @@ drm_mock_sched_job_new(struct kunit *test, ret =drm_sched_job_init (&job->base, &entity->base,1 , -NULL ); +NULL , +1 );KUNIT_ASSERT_EQ (test, ret,0 ); job->test = test;
drivers/gpu/drm/v3d/v3d_submit.c +1 -1
@@ -169,7 +169,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv, job->file = file_priv; ret =drm_sched_job_init (&job->base, &v3d_priv->sched_entity[queue], -1 , v3d_priv); +1 , v3d_priv, file_priv->client_id);if (ret)return ret;
drivers/gpu/drm/xe/xe_sched_job.c +2 -1
@@ -113,7 +113,8 @@ struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q,kref_init (&job->refcount);xe_exec_queue_get (job->q); - err =drm_sched_job_init (&job->drm, q->entity,1 ,NULL ); + err =drm_sched_job_init (&job->drm, q->entity,1 ,NULL , + q->xef->drm->client_id);if (err) goto err_free;
include/drm/gpu_scheduler.h +9 -1
@@ -305,6 +305,13 @@ struct drm_sched_fence {* @owner: job owner for debugging */ void *owner; + +/** +* @drm_client_id: +* +* The client_id of the drm_file which owns the job. +*/ +uint64_t drm_client_id; };struct drm_sched_fence *to_drm_sched_fence (struct dma_fence *f);
@@ -629,7 +636,8 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,int drm_sched_job_init (struct drm_sched_job *job,struct drm_sched_entity *entity, -u32 credits,void *owner); +u32 credits,void *owner, +u64 drm_client_id);void drm_sched_job_arm (struct drm_sched_job *job);void drm_sched_entity_push_job (struct drm_sched_job *sched_job); int drm_sched_job_add_dependency(struct drm_sched_job *job,
Signature · 1 line
2.43.0
Re: [PATCH v11 02/10] drm/sched: Store the drm client_id in drm_sched_fence
drivers/gpu/drm/xe/xe_sched_job.c struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q, · line 117
Quoted 12 lines · Pierre-Eric Pelloux-Prayer
drivers/gpu/drm/xe/xe_sched_job.c| 3 ++-drivers/gpu/drm/xe/xe_sched_job.c +2
-1@@ -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);
you can't do this here. xef is only !NULL if it's a job from userspace. For in-kernel jobs, xef is NULL and this explodes. Right now this completely breaks xe since one of the very first things we do is to submit a job to save the default context. Example:
https://intel-gfx-ci.01.org/tree/intel-xe/xe-3151-56d2b14961751a677ff1f7ff8b93a6c814ce2be3/bat-bmg-1/igt@[email protected]
<4> [] RIP: 0010:xe_sched_job_create+0xbd/0x390 [xe] <4> [] Code: c1 43 18 85 c0 0f 84 6f 02 00 00 8d 50 01 09 c2 0f 88 3e 02 00 00 48 8b 03 48 8b b3 d8 00 00 00 31 c9 4c 89 ef ba 01 00 00 00 <48> 8b 40 08 4c 8b 40 60 e8 86 64 7c ff 41 89 c4 85 c0 0f 85 9b 01 <4> [] RSP: 0018:ffffc900031972d8 EFLAGS: 00010246 <4> [] RAX: 0000000000000000 RBX: ffff88815fc40d00 RCX: 0000000000000000 <4> [] RDX: 0000000000000001 RSI: ffff88812e6552a8 RDI: ffff88815f939c40 <4> [] RBP: ffffc90003197318 R08: 0000000000000000 R09: 0000000000000000 <4> [] R10: 0000000000000000 R11: 0000000000000000 R12: ffffc90003197428 <4> [] R13: ffff88815f939c40 R14: ffff88811f054000 R15: ffff88815fc40d00 <4> [] FS: 00007681f2948940(0000) GS:ffff8888daf14000(0000) knlGS:0000000000000000 <4> [] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 <4> [] CR2: 0000000000000008 CR3: 0000000118315004 CR4: 0000000000f72ef0 <4> [] PKRU: 55555554 <4> [] Call Trace: <4> [] <TASK> <4> [] __xe_bb_create_job+0xa2/0x240 [xe] <4> [] ? find_held_lock+0x31/0x90 <4> [] ? xa_find_after+0x12c/0x250 <4> [] xe_bb_create_job+0x6e/0x380 [xe] <4> [] ? xa_find_after+0x136/0x250 <4> [] ? __drm_dev_dbg+0x7d/0xb0 <4> [] xe_gt_record_default_lrcs+0x542/0xb00 [xe]
Can we use 0 for in-kernel client since drm_file starts them from 1? Like this:
| diff --git a/drivers/gpu/drm/xe/xe_sched_job.c b/drivers/gpu/drm/xe/xe_sched_job.c | index 5921293b25db3..d21bf8f269640 100644 | --- a/drivers/gpu/drm/xe/xe_sched_job.c | +++ b/drivers/gpu/drm/xe/xe_sched_job.c | @@ -114,7 +114,7 @@ struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q, | xe_exec_queue_get(job->q); | | err = drm_sched_job_init(&job->drm, q->entity, 1, NULL, | - q->xef->drm->client_id); | + q->xef ? q->xef->drm->client_id : 0); | if (err) | goto err_free;
I tested with the above diff and it at least loads...
Also, I see this in intel-xe mailing list, but I'm not sure why we didn't have any CI results... I will check that.
Lucas De Marchi
Re: [PATCH v11 02/10] drm/sched: Store the drm client_id in drm_sched_fence
Hi,
Le 28/05/2025 à 21:07, Lucas De Marchi a écrit :
Quoted 10 lines · Pierre-Eric Pelloux-Prayer
Quoted 9 lines
drivers/gpu/drm/xe/xe_sched_job.c | 3 ++-
drivers/gpu/drm/xe/xe_sched_job.c +0
-0@@ -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);
Quoted 5 lines
drivers/gpu/drm/xe/xe_sched_job.c struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q, · line 117
Quoted 3 lines
drivers/gpu/drm/xe/xe_sched_job.c +2
-1- err = drm_sched_job_init(&job->drm, q->entity, 1, NULL); + err = drm_sched_job_init(&job->drm, q->entity, 1, NULL, + q->xef->drm->client_id);you can't do this here. xef is only !NULL if it's a job from userspace.
sorry about that.
Quoted 28 lines
For in-kernel jobs, xef is NULL and this explodes. Right now this
completely breaks xe since one of the very first things we do is
to submit a job to save the default context. Example:
https://intel-gfx-ci.01.org/tree/intel-xe/xe-3151-56d2b14961751a677ff1f7ff8b93a6c814ce2be3/bat- bmg-1/igt@[email protected]<4> [] RIP: 0010:xe_sched_job_create+0xbd/0x390 [xe]
<4> [] Code: c1 43 18 85 c0 0f 84 6f 02 00 00 8d 50 01 09 c2 0f 88 3e 02 00 00 48 8b 03 48 8b
b3 d8 00 00 00 31 c9 4c 89 ef ba 01 00 00 00 <48> 8b 40 08 4c 8b 40 60 e8 86 64 7c ff 41 89 c4 85 c0 0f 85 9b 01
<4> [] RSP: 0018:ffffc900031972d8 EFLAGS: 00010246
<4> [] RAX: 0000000000000000 RBX:ffff88815fc40d00RCX: 0000000000000000
<4> [] RDX: 0000000000000001 RSI:ffff88812e6552a8RDI:ffff88815f939c40
<4> [] RBP:ffffc90003197318R08: 0000000000000000 R09: 0000000000000000
<4> [] R10: 0000000000000000 R11: 0000000000000000 R12:ffffc90003197428
<4> [] R13:ffff88815f939c40R14:ffff88811f054000R15:ffff88815fc40d00
<4> [] FS: 00007681f2948940(0000) GS:ffff8888daf14000(0000) knlGS:0000000000000000
<4> [] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
<4> [] CR2: 0000000000000008 CR3: 0000000118315004 CR4:0000000000f72ef0
<4> [] PKRU: 55555554
<4> [] Call Trace:
<4> [] <TASK>
<4> []__xe_bb_create_job+0xa2/0x240[xe]
<4> [] ?find_held_lock+0x31/0x90
<4> [] ?xa_find_after+0x12c/0x250
<4> []xe_bb_create_job+0x6e/0x380[xe]
<4> [] ?xa_find_after+0x136/0x250
<4> [] ?__drm_dev_dbg+0x7d/0xb0
<4> []xe_gt_record_default_lrcs+0x542/0xb00[xe]
Quoted 1 line
Can we use 0 for in-kernel client since
drm_filestarts them from 1?
Yes, this is what amdgpu does.
Quoted 14 lines
Like this:
| diff --git a/drivers/gpu/drm/xe/xe_sched_job.c b/drivers/gpu/drm/xe/xe_sched_job.c | index 5921293b25db3..d21bf8f269640 100644 | --- a/drivers/gpu/drm/xe/xe_sched_job.c | +++ b/drivers/gpu/drm/xe/xe_sched_job.c | @@ -114,7 +114,7 @@ struct xe_sched_job *xe_sched_job_create(struct xe_exec_queue *q, | xe_exec_queue_get(job->q); | | err = drm_sched_job_init(&job->drm, q->entity, 1, NULL, | - q->xef->drm->client_id); | + q->xef ? q->xef->drm->client_id : 0); | if (err) | goto err_free;
Quoted 1 line
I tested with the above diff and it at least loads...
Thanks for looking into this, the change looks fine to me.
Pierre-Eric
Quoted 5 lines
Also, I see this in intel-xe mailing list, but I'm not sure why we didn't have any CI results... I will check that.
Lucas De Marchi
PATCH v11 3/10 drm/sched: Add device name to the drm_sched_process_job event
In reply to Pierre-Eric Pelloux-PrayerSince switching the scheduler from using kthreads to workqueues in commit a6149f039369 ("drm/sched: Convert drm scheduler to use a work queue rather than kthread") userspace applications cannot determine the device from the PID of the threads sending the trace events anymore.
Each queue had its own kthread which had a given PID for the whole time. So, at least for amdgpu, it was possible to associate a PID to the hardware queues of each GPU in the system. Then, when a drm_run_job trace event was received by userspace, the source PID allowed to associate it back to the correct GPU.
With workqueues this is not possible anymore, so the event needs to contain the dev_name() to identify the device.
--- drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +4 -2
@@ -42,6 +42,7 @@ DECLARE_EVENT_CLASS(drm_sched_job, __field(uint64_t, id) __field(u32, job_count) __field(int, hw_job_count) +__string (dev,dev_name (sched_job->sched->dev)) ), TP_fast_assign(
@@ -52,9 +53,10 @@ DECLARE_EVENT_CLASS(drm_sched_job, __entry->job_count =spsc_queue_count (&entity->job_queue); __entry->hw_job_count =atomic_read ( &sched_job->sched->credit_count); +__assign_str (dev); ), -TP_printk ("entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d" , - __entry->entity, __entry->id, +TP_printk ("dev=%s, entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d" , +__get_str (dev), __entry->entity, __entry->id, __entry->fence,__get_str (name), __entry->job_count, __entry->hw_job_count) );
Signature · 1 line
2.43.0
PATCH v11 4/10 drm/sched: Cleanup gpu_scheduler trace events
In reply to Pierre-Eric Pelloux-PrayerA fence uniquely identify a job, so this commits updates the places where a kernel pointer was used as an identifier by:
"fence=%llu:%llu"
--- .../gpu/drm/scheduler/gpu_scheduler_trace.h | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +23 -21
@@ -36,28 +36,28 @@ DECLARE_EVENT_CLASS(drm_sched_job, TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),TP_ARGS (sched_job, entity),TP_STRUCT__entry ( - __field(struct drm_sched_entity *, entity) -__field (struct dma_fence *,fence ) - __string(name, sched_job->sched->name) __field(uint64_t, id) + __string(name, sched_job->sched->name)__field (u32, job_count)__field (int, hw_job_count) __string(dev, dev_name(sched_job->sched->dev)) +__field (u64, fence_context) +__field (u64, fence_seqno) ), TP_fast_assign( - __entry->entity = entity; __entry->id = sched_job->id; - __entry->fence = &sched_job->s_fence->finished;__assign_str (name); __entry->job_count =spsc_queue_count (&entity->job_queue); __entry->hw_job_count =atomic_read ( &sched_job->sched->credit_count);__assign_str (dev); + __entry->fence_context = sched_job->s_fence->finished.context; + __entry->fence_seqno = sched_job->s_fence->finished.seqno; ), -TP_printk ("dev=%s, entity=%p, id=%llu, fence=%p, ring=%s, job count:%u, hw job count:%d" , -__get_str (dev), __entry->entity, __entry->id, - __entry->fence,__get_str (name), +TP_printk ("dev=%s, id=%llu, fence=%llu:%llu, ring=%s, job count:%u, hw job count:%d" , +__get_str (dev), __entry->id, + __entry->fence_context, __entry->fence_seqno,__get_str (name), __entry->job_count, __entry->hw_job_count) );
@@ -75,37 +75,39 @@ TRACE_EVENT(drm_sched_process_job, TP_PROTO(struct drm_sched_fence *fence),TP_ARGS (fence),TP_STRUCT__entry ( - __field(struct dma_fence *,fence ) + __field(u64, fence_context) +__field (u64 ,fence_seqno ) ),TP_fast_assign ( - __entry->fence = &fence->finished; + __entry->fence_context = fence->finished.context; + __entry->fence_seqno = fence->finished.seqno; ), -TP_printk ("fence=%p signaled" , __entry->fence) +TP_printk ("fence=%llu:%llu signaled" , + __entry->fence_context, __entry->fence_seqno) );TRACE_EVENT (drm_sched_job_wait_dep, TP_PROTO(struct drm_sched_job *sched_job, struct dma_fence *fence),TP_ARGS (sched_job, fence),TP_STRUCT__entry ( - __string(name, sched_job->sched->name) + __field(u64, fence_context) + __field(u64, fence_seqno) __field(uint64_t, id) - __field(struct dma_fence *, fence) - __field(uint64_t, ctx) -__field (unsigned, seqno) + __field(u64, ctx) +__field (u64, seqno) ),TP_fast_assign ( - __assign_str(name); + __entry->fence_context = sched_job->s_fence->finished.context; + __entry->fence_seqno = sched_job->s_fence->finished.seqno; __entry->id = sched_job->id; - __entry->fence = fence; __entry->ctx = fence->context; __entry->seqno = fence->seqno; ), -TP_printk ("job ring=%s, id=%llu, depends fence=%p, context=%llu, seq=%u" , -__get_str (name), __entry->id, - __entry->fence, __entry->ctx, - __entry->seqno) +TP_printk ("fence=%llu:%llu, id=%llu depends on unsignalled fence=%llu:%llu" , + __entry->fence_context, __entry->fence_seqno, __entry->id, + __entry->ctx, __entry->seqno) );#endif /* _GPU_SCHED_TRACE_H_ */
Signature · 1 line
2.43.0
PATCH v11 5/10 drm/sched: Trace dependencies for GPU jobs
In reply to Pierre-Eric Pelloux-PrayerWe can't trace dependencies from drm_sched_job_add_dependency because when it's called the job's fence is not available yet.
So instead each dependency is traced individually when drm_sched_entity_push_job is used.
Tracing the dependencies allows tools to analyze the dependencies between the jobs (previously it was only possible for fences traced by drm_sched_job_wait_dep).
--- .../gpu/drm/scheduler/gpu_scheduler_trace.h | 23 +++++++++++++++++++ drivers/gpu/drm/scheduler/sched_entity.c | 8 +++++++ 2 files changed, 31 insertions(+)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +23 -0
@@ -87,6 +87,29 @@ TRACE_EVENT(drm_sched_process_job, __entry->fence_context, __entry->fence_seqno) ); +TRACE_EVENT (drm_sched_job_add_dep, + TP_PROTO(struct drm_sched_job *sched_job, struct dma_fence *fence), +TP_ARGS (sched_job, fence), +TP_STRUCT__entry ( + __field(u64, fence_context) + __field(u64, fence_seqno) + __field(u64, id) + __field(u64, ctx) +__field (u64, seqno) + ), + +TP_fast_assign ( + __entry->fence_context = sched_job->s_fence->finished.context; + __entry->fence_seqno = sched_job->s_fence->finished.seqno; + __entry->id = sched_job->id; + __entry->ctx = fence->context; + __entry->seqno = fence->seqno; + ), +TP_printk ("fence=%llu:%llu, id=%llu depends on fence=%llu:%llu" , + __entry->fence_context, __entry->fence_seqno, __entry->id, + __entry->ctx, __entry->seqno) +); + TRACE_EVENT(drm_sched_job_wait_dep, TP_PROTO(struct drm_sched_job *sched_job, struct dma_fence *fence), TP_ARGS(sched_job, fence),
drivers/gpu/drm/scheduler/sched_entity.c +8 -0
@@ -586,6 +586,14 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)ktime_t submit_ts;trace_drm_sched_job (sched_job, entity); + +if (trace_drm_sched_job_add_dep_enabled ()) { +struct dma_fence *entry; +unsigned long index; + +xa_for_each (&sched_job->dependencies, index, entry) +trace_drm_sched_job_add_dep (sched_job, entry); + }atomic_inc (entity->rq->sched->score);WRITE_ONCE (entity->last_user, current->group_leader);
Signature · 1 line
2.43.0
PATCH v11 6/10 drm/sched: Add the drm_client_id to the drm_sched_run/exec_job events
In reply to Pierre-Eric Pelloux-PrayerFor processes with multiple drm_file instances, the drm_client_id is the only way to map jobs back to their unique owner.
It's even more useful if drm client_name is set, because now a tool can map jobs to the client name instead of only having access to the process name.
--- drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +4 -2
@@ -43,6 +43,7 @@ DECLARE_EVENT_CLASS(drm_sched_job, __string(dev, dev_name(sched_job->sched->dev)) __field(u64, fence_context) __field(u64, fence_seqno) +__field (u64, client_id) ), TP_fast_assign(
@@ -54,11 +55,12 @@ DECLARE_EVENT_CLASS(drm_sched_job,__assign_str (dev); __entry->fence_context = sched_job->s_fence->finished.context; __entry->fence_seqno = sched_job->s_fence->finished.seqno; + __entry->client_id = sched_job->s_fence->drm_client_id; ), -TP_printk ("dev=%s, id=%llu, fence=%llu:%llu, ring=%s, job count:%u, hw job count:%d" , +TP_printk ("dev=%s, id=%llu, fence=%llu:%llu, ring=%s, job count:%u, hw job count:%d, client_id:%llu" ,__get_str (dev), __entry->id, __entry->fence_context, __entry->fence_seqno,__get_str (name), - __entry->job_count, __entry->hw_job_count) + __entry->job_count, __entry->hw_job_count, __entry->client_id) ); DEFINE_EVENT(drm_sched_job, drm_sched_job,
Signature · 1 line
2.43.0
PATCH v11 7/10 drm/sched: Cleanup event names
In reply to Pierre-Eric Pelloux-PrayerAll events now start with the same prefix (drm_sched_job_).
drm_sched_job_wait_dep was misleading because it wasn't waiting at all. It's now replaced by trace_drm_sched_job_unschedulable, which is only traced if the job cannot be scheduled. For moot dependencies, nothing is traced.
--- drivers/gpu/drm/scheduler/gpu_scheduler_trace.h | 8 ++++---- drivers/gpu/drm/scheduler/sched_entity.c | 8 ++++---- drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +4 -4
@@ -63,17 +63,17 @@ DECLARE_EVENT_CLASS(drm_sched_job, __entry->job_count, __entry->hw_job_count, __entry->client_id) ); -DEFINE_EVENT (drm_sched_job, drm_sched_job, +DEFINE_EVENT (drm_sched_job, drm_sched_job_queue, TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),TP_ARGS (sched_job, entity) ); -DEFINE_EVENT (drm_sched_job, drm_run_job, +DEFINE_EVENT (drm_sched_job, drm_sched_job_run, TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity),TP_ARGS (sched_job, entity) ); -TRACE_EVENT(drm_sched_process_job, +TRACE_EVENT(drm_sched_job_done, TP_PROTO(struct drm_sched_fence *fence), TP_ARGS(fence), TP_STRUCT__entry(
@@ -112,7 +112,7 @@ TRACE_EVENT(drm_sched_job_add_dep, __entry->ctx, __entry->seqno) ); -TRACE_EVENT(drm_sched_job_wait_dep, +TRACE_EVENT(drm_sched_job_unschedulable, TP_PROTO(struct drm_sched_job *sched_job, struct dma_fence *fence), TP_ARGS(sched_job, fence), TP_STRUCT__entry(
drivers/gpu/drm/scheduler/sched_entity.c +4 -4
@@ -476,10 +476,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)while ((entity->dependency =drm_sched_job_dependency (sched_job, entity))) { -trace_drm_sched_job_wait_dep (sched_job, entity->dependency); - -if (drm_sched_entity_add_dependency_cb (entity)) +if (drm_sched_entity_add_dependency_cb (entity)) { +trace_drm_sched_job_unschedulable (sched_job, entity->dependency);return NULL ; + } }/* skip jobs from entity that marked guilty */
@@ -585,7 +585,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)bool first;ktime_t submit_ts; -trace_drm_sched_job (sched_job, entity); +trace_drm_sched_job_queue (sched_job, entity);if (trace_drm_sched_job_add_dep_enabled ()) {struct dma_fence *entry;
drivers/gpu/drm/scheduler/sched_main.c +2 -2
@@ -401,7 +401,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)atomic_sub (s_job->credits, &sched->credit_count);atomic_dec (sched->score); -trace_drm_sched_process_job (s_fence); +trace_drm_sched_job_done (s_fence);dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);
@@ -1234,7 +1234,7 @@ static void drm_sched_run_job_work(struct work_struct *w)atomic_add (sched_job->credits, &sched->credit_count);drm_sched_job_begin (sched_job); -trace_drm_run_job (sched_job, entity); +trace_drm_sched_job_run (sched_job, entity);/* * The run_job() callback must by definition return a fence whose * refcount has been incremented for the scheduler already.
Signature · 1 line
2.43.0
PATCH v11 8/10 drm: Get rid of drm_sched_job.id
In reply to Pierre-Eric Pelloux-PrayerIts only purpose was for trace events, but jobs can already be uniquely identified using their fence.
The downside of using the fence is that it's only available after 'drm_sched_job_arm' was called which is true for all trace events that used job.id so they can safely switch to using it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 18 ++++++------------ drivers/gpu/drm/lima/lima_trace.h | 6 ++---- .../gpu/drm/scheduler/gpu_scheduler_trace.h | 18 ++++++------------ drivers/gpu/drm/scheduler/sched_main.c | 1 - include/drm/gpu_scheduler.h | 3 --- 5 files changed, 14 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +6 -12
@@ -167,7 +167,6 @@ TRACE_EVENT(amdgpu_cs_ioctl, TP_PROTO(struct amdgpu_job *job),TP_ARGS (job),TP_STRUCT__entry ( - __field(uint64_t, sched_job_id) __string(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job))__field (unsigned int ,context ) __field(unsigned int, seqno)
@@ -177,15 +176,14 @@ TRACE_EVENT(amdgpu_cs_ioctl, ), TP_fast_assign( - __entry->sched_job_id = job->base.id; __assign_str(timeline); __entry->context = job->base.s_fence->finished.context; __entry->seqno = job->base.s_fence->finished.seqno;__assign_str (ring); __entry->num_ibs = job->num_ibs; ), -TP_printk ("sched_job=%llu, timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u" , - __entry->sched_job_id,__get_str (timeline), __entry->context, +TP_printk ("timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u" , +__get_str (timeline), __entry->context, __entry->seqno,__get_str (ring), __entry->num_ibs) );
@@ -193,7 +191,6 @@ TRACE_EVENT(amdgpu_sched_run_job, TP_PROTO(struct amdgpu_job *job),TP_ARGS (job),TP_STRUCT__entry ( - __field(uint64_t, sched_job_id) __string(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job))__field (unsigned int ,context ) __field(unsigned int, seqno)
@@ -202,15 +199,14 @@ TRACE_EVENT(amdgpu_sched_run_job, ), TP_fast_assign( - __entry->sched_job_id = job->base.id; __assign_str(timeline); __entry->context = job->base.s_fence->finished.context; __entry->seqno = job->base.s_fence->finished.seqno;__assign_str (ring); __entry->num_ibs = job->num_ibs; ), -TP_printk ("sched_job=%llu, timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u" , - __entry->sched_job_id,__get_str (timeline), __entry->context, +TP_printk ("timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u" , +__get_str (timeline), __entry->context, __entry->seqno,__get_str (ring), __entry->num_ibs) );
@@ -551,7 +547,6 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,TP_ARGS (sched_job, fence),TP_STRUCT__entry ( __string(ring, sched_job->base.sched->name) - __field(uint64_t, id) __field(struct dma_fence *, fence) __field(uint64_t, ctx) __field(unsigned, seqno)
@@ -559,13 +554,12 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,TP_fast_assign ( __assign_str(ring); - __entry->id = sched_job->base.id; __entry->fence = fence; __entry->ctx = fence->context; __entry->seqno = fence->seqno; ), -TP_printk ("job ring=%s, id=%llu, need pipe sync to fence=%p, context=%llu, seq=%u" , -__get_str (ring), __entry->id, +TP_printk ("job ring=%s need pipe sync to fence=%p, context=%llu, seq=%u" , +__get_str (ring), __entry->fence, __entry->ctx, __entry->seqno) );
drivers/gpu/drm/lima/lima_trace.h +2 -4
@@ -14,21 +14,19 @@ DECLARE_EVENT_CLASS(lima_task, TP_PROTO(struct lima_sched_task *task),TP_ARGS (task),TP_STRUCT__entry ( - __field(uint64_t, task_id) __field(unsigned int, context)__field (unsigned int ,seqno ) __string(pipe, task->base.sched->name) ),TP_fast_assign ( - __entry->task_id = task->base.id; __entry->context = task->base.s_fence->finished.context; __entry->seqno = task->base.s_fence->finished.seqno;__assign_str (pipe); ), -TP_printk ("task=%llu, context=%u seqno=%u pipe=%s" , - __entry->task_id, __entry->context, __entry->seqno, +TP_printk ("context=%u seqno=%u pipe=%s" , + __entry->context, __entry->seqno,__get_str (pipe)) );
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +6 -12
@@ -36,7 +36,6 @@ DECLARE_EVENT_CLASS(drm_sched_job, TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity), TP_ARGS(sched_job, entity), TP_STRUCT__entry( - __field(uint64_t, id) __string(name, sched_job->sched->name) __field(u32, job_count) __field(int, hw_job_count)
@@ -47,7 +46,6 @@ DECLARE_EVENT_CLASS(drm_sched_job, ), TP_fast_assign( - __entry->id = sched_job->id; __assign_str(name); __entry->job_count =spsc_queue_count (&entity->job_queue); __entry->hw_job_count = atomic_read(
@@ -57,8 +55,8 @@ DECLARE_EVENT_CLASS(drm_sched_job, __entry->fence_seqno = sched_job->s_fence->finished.seqno; __entry->client_id = sched_job->s_fence->drm_client_id; ), -TP_printk ("dev=%s, id=%llu, fence=%llu:%llu, ring=%s, job count:%u, hw job count:%d, client_id:%llu" , -__get_str (dev), __entry->id, +TP_printk ("dev=%s, fence=%llu:%llu, ring=%s, job count:%u, hw job count:%d, client_id:%llu" , +__get_str (dev), __entry->fence_context, __entry->fence_seqno,__get_str (name), __entry->job_count, __entry->hw_job_count, __entry->client_id) );
@@ -95,7 +93,6 @@ TRACE_EVENT(drm_sched_job_add_dep,TP_STRUCT__entry (__field (u64 ,fence_context )__field (u64, fence_seqno) -__field (u64, id)__field (u64, ctx)__field (u64, seqno) ),
@@ -103,12 +100,11 @@ TRACE_EVENT(drm_sched_job_add_dep,TP_fast_assign ( __entry->fence_context = sched_job->s_fence->finished.context; __entry->fence_seqno = sched_job->s_fence->finished.seqno; - __entry->id = sched_job->id; __entry->ctx = fence->context; __entry->seqno = fence->seqno; ), -TP_printk ("fence=%llu:%llu, id=%llu depends on fence=%llu:%llu" , - __entry->fence_context, __entry->fence_seqno, __entry->id, +TP_printk ("fence=%llu:%llu depends on fence=%llu:%llu" , + __entry->fence_context, __entry->fence_seqno, __entry->ctx, __entry->seqno) );
@@ -118,7 +114,6 @@ TRACE_EVENT(drm_sched_job_unschedulable,TP_STRUCT__entry (__field (u64 ,fence_context )__field (u64, fence_seqno) -__field (uint64_t, id)__field (u64, ctx)__field (u64, seqno) ),
@@ -126,12 +121,11 @@ TRACE_EVENT(drm_sched_job_unschedulable,TP_fast_assign ( __entry->fence_context = sched_job->s_fence->finished.context; __entry->fence_seqno = sched_job->s_fence->finished.seqno; - __entry->id = sched_job->id; __entry->ctx = fence->context; __entry->seqno = fence->seqno; ), -TP_printk ("fence=%llu:%llu, id=%llu depends on unsignalled fence=%llu:%llu" , - __entry->fence_context, __entry->fence_seqno, __entry->id, +TP_printk ("fence=%llu:%llu depends on unsignalled fence=%llu:%llu" , + __entry->fence_context, __entry->fence_seqno, __entry->ctx, __entry->seqno) );
drivers/gpu/drm/scheduler/sched_main.c +0 -1
@@ -855,7 +855,6 @@ void drm_sched_job_arm(struct drm_sched_job *job) job->sched = sched; job->s_priority = entity->priority; - job->id =atomic64_inc_return (&sched->job_id_count);drm_sched_fence_init (job->s_fence, job->entity); }
include/drm/gpu_scheduler.h +0 -3
@@ -326,7 +326,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);* @finish_cb: the callback for the finished fence. * @credits: the number of credits this job contributes to the scheduler * @work: Helper to reschedule job kill to different context. -* @id: a unique id assigned to each job scheduled on the scheduler. * @karma: increment on every hang caused by this job. If this exceeds the hang * limit of the scheduler then the job is marked guilty and will not * be scheduled further.
@@ -339,8 +338,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);* to schedule the job. */ struct drm_sched_job { -u64 id; -/** * @submit_ts: *
Signature · 1 line
2.43.0
PATCH v11 9/10 drm/doc: Document some tracepoints as uAPI
In reply to Pierre-Eric Pelloux-PrayerThis commit adds a document section in drm-uapi.rst about tracepoints, and mark the events gpu_scheduler_trace.h as stable uAPI.
The goal is to explicitly state that tools can rely on the fields, formats and semantics of these events.
--- Documentation/gpu/drm-uapi.rst | 19 ++++++++++++++++ .../gpu/drm/scheduler/gpu_scheduler_trace.h | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+)
Documentation/gpu/drm-uapi.rst +19 -0
@@ -693,3 +693,22 @@ dma-buf interoperability Please see Documentation/userspace-api/dma-buf-alloc-exchange.rst for information on how dma-buf is integrated and exposed within DRM. + + +Trace events +============ + +See Documentation/trace/tracepoints.rst for information about using +Linux Kernel Tracepoints. +In the DRM subsystem, some events are considered stable uAPI to avoid +breaking tools (e.g.: GPUVis, umr) relying on them. Stable means that fields +cannot be removed, nor their formatting updated. Adding new fields is +possible, under the normal uAPI requirements. + +Stable uAPI events +------------------ + +From ``drivers/gpu/drm/scheduler/gpu_scheduler_trace.h`` + +.. kernel-doc:: drivers/gpu/drm/scheduler/gpu_scheduler_trace.h + :doc: uAPI trace events
drivers/gpu/drm/scheduler/gpu_scheduler_trace.h +22 -0
@@ -32,6 +32,28 @@#define TRACE_SYSTEM gpu_scheduler#define TRACE_INCLUDE_FILE gpu_scheduler_trace +/** +* DOC: uAPI trace events +* +* ``drm_sched_job_queue``, ``drm_sched_job_run``, ``drm_sched_job_add_dep``, +* ``drm_sched_job_done`` and ``drm_sched_job_unschedulable`` are considered +* stable uAPI. +* +* Common trace events attributes: +* +* * ``dev`` - the dev_name() of the device running the job. +* +* * ``ring`` - the hardware ring running the job. Together with ``dev`` it +* uniquely identifies where the job is going to be executed. +* +* * ``fence`` - the &struct dma_fence.context and the &struct dma_fence.seqno of +* &struct drm_sched_fence.finished +* +* All the events depends on drm_sched_job_arm() having been called already for +* the job because they use &struct drm_sched_job.sched or +* &struct drm_sched_job.s_fence. +*/ + DECLARE_EVENT_CLASS(drm_sched_job, TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity), TP_ARGS(sched_job, entity),
Signature · 1 line
2.43.0
PATCH v11 10/10 drm/amdgpu: update trace format to match gpu_scheduler_trace
In reply to Pierre-Eric Pelloux-PrayerLog fences using the same format for coherency.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +10 -12
@@ -168,8 +168,8 @@ TRACE_EVENT(amdgpu_cs_ioctl,TP_ARGS (job),TP_STRUCT__entry ( __string(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job)) -__field (unsigned int ,context ) - __field(unsigned int, seqno) + __field(u64, context) + __field(u64, seqno) __field(struct dma_fence *, fence) __string(ring, to_amdgpu_ring(job->base.sched)->name) __field(u32, num_ibs)
@@ -182,7 +182,7 @@ TRACE_EVENT(amdgpu_cs_ioctl,__assign_str (ring); __entry->num_ibs = job->num_ibs; ), -TP_printk ("timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u" , +TP_printk ("timeline=%s, fence=%llu:%llu, ring_name=%s, num_ibs=%u" ,__get_str (timeline), __entry->context, __entry->seqno,__get_str (ring), __entry->num_ibs) );
@@ -192,8 +192,8 @@ TRACE_EVENT(amdgpu_sched_run_job,TP_ARGS (job),TP_STRUCT__entry ( __string(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job)) -__field (unsigned int ,context ) - __field(unsigned int, seqno) + __field(u64, context) + __field(u64, seqno) __string(ring, to_amdgpu_ring(job->base.sched)->name)__field (u32, num_ibs) ),
@@ -205,7 +205,7 @@ TRACE_EVENT(amdgpu_sched_run_job,__assign_str (ring); __entry->num_ibs = job->num_ibs; ), -TP_printk ("timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u" , +TP_printk ("timeline=%s, fence=%llu:%llu, ring_name=%s, num_ibs=%u" ,__get_str (timeline), __entry->context, __entry->seqno,__get_str (ring), __entry->num_ibs) );
@@ -548,8 +548,8 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,TP_STRUCT__entry ( __string(ring, sched_job->base.sched->name) __field(struct dma_fence *, fence) - __field(uint64_t, ctx) -__field (unsigned, seqno) + __field(u64, ctx) +__field (u64, seqno) ), TP_fast_assign(
@@ -558,10 +558,8 @@ TRACE_EVENT(amdgpu_ib_pipe_sync, __entry->ctx = fence->context; __entry->seqno = fence->seqno; ), -TP_printk ("job ring=%s need pipe sync to fence=%p, context=%llu, seq=%u" , -__get_str (ring), - __entry->fence, __entry->ctx, - __entry->seqno) +TP_printk ("job ring=%s need pipe sync to fence=%llu:%llu" , +__get_str (ring), __entry->ctx, __entry->seqno) ); TRACE_EVENT(amdgpu_reset_reg_dumps,
Signature · 1 line
2.43.0
Philipp Stanner
AppliedQuoted 49 lines · Pierre-Eric Pelloux-Prayer
Hi,
The initial goal of this series was to improve the drm and amdgpu trace events to be able to expose more of the inner workings of the scheduler and drivers to developers via tools.
Then, the series evolved to become focused only on
gpu_scheduler. The changes around vblank events will be part of a different series, as well as the amdgpu ones.Moreover Sima suggested to make some trace events stable uAPI, so tools can rely on them long term.
The first patches extend and cleanup the gpu scheduler events, then add a documentation entry in
drm-uapi.rst.The last 2 patches are new in v8. One is based on a suggestion from Tvrtko and gets rid of
drm_sched_job::id. The other is a cleanup of amdgpu trace events to use the fence=%llu:%llu format.The
drm_sched_jobpatches don't affect gpuvis which has code to parse thegpu_schedulerevents but these events are not enabled.Changes since v10:
* fixed 2 errors reported by kernel test robot
* rebased on drm-misc-nextChanges since v9:
* fixed documentation link syntax
* fixed typos in commit messages
* spelled out that these events cannot be used beforedrm_sched_job_armhas been calledChanges since v8:
* swapped patches 8 & 9
* rebased on drm-nextChanges since v7:
*uint64_t-> u64
* reworked dependencies tracing (Tvrtko)
* use common name prefix for all events (Tvrtko)
* droppeddrm_sched_job::id(Tvrtko)Useful links:
- userspace tool using the updated events:
https://gitlab.freedesktop.org/tomstdenis/umr/-/merge_requests/37
- v8:
https://lists.freedesktop.org/archives/dri-devel/2025-March/496781.html
Quoted 12 lines
Pierre-Eric Pelloux-Prayer (10):
drm/debugfs: Outputclient_idin indrm_clients_infodrm/sched: Store the drmclient_idindrm_sched_fencedrm/sched: Add device name to thedrm_sched_process_jobevent drm/sched: Cleanupgpu_schedulertrace events drm/sched: Trace dependencies for GPU jobs drm/sched: Add thedrm_client_idto the drm_sched_run/exec_job events
drm/sched: Cleanup event names
drm: Get rid of drm_sched_job.id
drm/doc: Document some tracepoints as uAPI drm/amdgpu: update trace format to matchgpu_scheduler_trace
Applied to drm-misc-next
Thanks
P.
Quoted 36 lines
Documentation/gpu/drm-uapi.rst | 19 ++++ drivers/accel/amdxdna/aie2_ctx.c | 3 +- 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/amd/amdgpu/amdgpu_trace.h | 32 ++---- drivers/gpu/drm/drm_debugfs.c | 10 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/imagination/pvr_job.c | 2 +- drivers/gpu/drm/imagination/pvr_queue.c | 5 +- drivers/gpu/drm/imagination/pvr_queue.h | 2 +- drivers/gpu/drm/lima/lima_gem.c | 2 +-
drivers/gpu/drm/lima/lima_sched.c | 6 +- drivers/gpu/drm/lima/lima_sched.h | 3 +- drivers/gpu/drm/lima/lima_trace.h | 6 +-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/panthor/panthor_drv.c | 3 +- drivers/gpu/drm/panthor/panthor_mmu.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 5 +- drivers/gpu/drm/panthor/panthor_sched.h | 3 +- .../gpu/drm/scheduler/gpu_scheduler_trace.h | 103 +++++++++++++--- --
drivers/gpu/drm/scheduler/sched_entity.c | 16 ++- drivers/gpu/drm/scheduler/sched_fence.c | 4 +- drivers/gpu/drm/scheduler/sched_internal.h | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 12 +- .../gpu/drm/scheduler/tests/mock_scheduler.c | 3 +- drivers/gpu/drm/v3d/v3d_submit.c | 2 +- drivers/gpu/drm/xe/xe_sched_job.c | 3 +- include/drm/gpu_scheduler.h | 13 ++-32 files changed, 191 insertions(+), 101 deletions(-)