drm/amdgpu: Add trace events for pid register/deregister
Subsystems (2)
PATCH 1/1 drm/amdgpu: Add trace events for pid register/deregister
Some debugging applications need to track when a process starts or stops using the amdgpu driver. For those processes, add ftrace events that track when a amdgpu_vm task info is changed or destroyed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 17 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++ 2 files changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +17 -0
@@ -732,6 +732,23 @@ TRACE_EVENT(amdgpu_userq_state_changed, __entry->client_id, __entry->queue_type, __entry->doorbell_index, __entry->to) ); +TRACE_EVENT (amdgpu_register_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu register pid %d" , + __entry->pid) +); +TRACE_EVENT (amdgpu_deregister_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu deregister pid %d" , + __entry->pid) +); +#undef AMDGPU_JOB_GET_TIMELINE_NAME#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -0
@@ -2457,6 +2457,9 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref) { struct amdgpu_task_info *ti = container_of(kref, struct amdgpu_task_info, refcount); +if (ti->task.pid) +trace_amdgpu_deregister_pid (ti->task.pid); +kfree (ti); }
@@ -2543,6 +2546,10 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)if (vm->task_info->task.pid == current->pid)return ; +if (vm->task_info->task.pid) +trace_amdgpu_deregister_pid (vm->task_info->task.pid); +trace_amdgpu_register_pid (current->pid); + vm->task_info->task.pid = current->pid;get_task_comm (vm->task_info->task.comm, current);
Signature · 1 line
2.34.1
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
Quoted 53 lines · David Francis
Some debugging applications need to track when a process starts or stops using the amdgpu driver. For those processes, add ftrace events that track when a
amdgpu_vmtask info is changed or destroyed.Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 17 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++ 2 files changed, 24 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +17
-0@@ -732,6 +732,23 @@ TRACE_EVENT(amdgpu_userq_state_changed, __entry->client_id, __entry->queue_type, __entry->doorbell_index, __entry->to) ); +TRACE_EVENT (amdgpu_register_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu register pid %d" , + __entry->pid) +); +TRACE_EVENT (amdgpu_deregister_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu deregister pid %d" , + __entry->pid) +); +#undef AMDGPU_JOB_GET_TIMELINE_NAME#endif drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0@@ -2457,6 +2457,9 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref) { struct amdgpu_task_info *ti = container_of(kref, struct amdgpu_task_info, refcount); +if (ti->task.pid) +trace_amdgpu_deregister_pid (ti->task.pid); +kfree (ti); }@@ -2543,6 +2546,10 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too. Chose a better function to add the trace although trace in itself is fine.
Regards
Sunil Khatri
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0if (vm->task_info->task.pid == current->pid)return ; +if (vm->task_info->task.pid) +trace_amdgpu_deregister_pid (vm->task_info->task.pid); +trace_amdgpu_register_pid (current->pid); + vm->task_info->task.pid = current->pid;get_task_comm (vm->task_info->task.comm, current);
Quoted 3 lines
This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too.
This function is called when the last ref to an task_info is put. Many places in the code temporarily acquire references to a task_info but only amdgpu_vm holds the long-term reference, acquired in amdgpu_vm_create_task_info and relased in amdgpu_vm_fini.
Tying the trace to the lifetime of task_info also guarantees that there will be exactly one such trace for each task_info, matching the register trace semantics
David Francis
________________________________________
From: Khatri, Sunil <[email protected]>
Sent: Tuesday, July 28, 2026 8:26 AM
To: Francis, David; [email protected]
Cc: Liu, Shuzhou (Bill); Khatri, Sunil
Subject: Re: [PATCH] drm/amdgpu: Add trace events for pid register/deregister
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
Quoted 53 lines · David Francis
Some debugging applications need to track when a process starts or stops using the amdgpu driver. For those processes, add ftrace events that track when a
amdgpu_vmtask info is changed or destroyed.Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 17 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++ 2 files changed, 24 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +17
-0@@ -732,6 +732,23 @@ TRACE_EVENT(amdgpu_userq_state_changed, __entry->client_id, __entry->queue_type, __entry->doorbell_index, __entry->to) ); +TRACE_EVENT (amdgpu_register_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu register pid %d" , + __entry->pid) +); +TRACE_EVENT (amdgpu_deregister_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu deregister pid %d" , + __entry->pid) +); +#undef AMDGPU_JOB_GET_TIMELINE_NAME#endif drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0@@ -2457,6 +2457,9 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref) { struct amdgpu_task_info *ti = container_of(kref, struct amdgpu_task_info, refcount); +if (ti->task.pid) +trace_amdgpu_deregister_pid (ti->task.pid); +kfree (ti); }@@ -2543,6 +2546,10 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too.
Chose a better function to add the trace although trace in itself is fine.
Regards
Sunil Khatri
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0if (vm->task_info->task.pid == current->pid)return ; +if (vm->task_info->task.pid) +trace_amdgpu_deregister_pid (vm->task_info->task.pid); +trace_amdgpu_register_pid (current->pid); + vm->task_info->task.pid = current->pid;get_task_comm (vm->task_info->task.comm, current);
Quoted 11 lines · David
Quoted 3 lines
This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too.
This function is called when the last ref to an
task_infois put. Many places in the code temporarily acquire references to atask_infobut onlyamdgpu_vmholds the long-term reference, acquired inamdgpu_vm_create_task_infoand relased inamdgpu_vm_fini.Tying the trace to the lifetime of
task_infoalso guarantees that there will be exactly one such trace for eachtask_info, matching the register trace semantics
For begining, amdgpu_vm_init sounds like a better choice for ending, amdgpu_vm_destroy_task_info is correct.
Regards
Sunil Khatri
Quoted 83 lines
David Francis
________________________________________
From: Khatri, Sunil <[email protected]>
Sent: Tuesday, July 28, 2026 8:26 AM
To: Francis, David; [email protected]
Cc: Liu, Shuzhou (Bill); Khatri, Sunil
Subject: Re: [PATCH] drm/amdgpu: Add trace events for pid register/deregisterdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
Quoted 53 lines · David Francis
Some debugging applications need to track when a process starts or stops using the amdgpu driver. For those processes, add ftrace events that track when a
amdgpu_vmtask info is changed or destroyed.Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 17 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++ 2 files changed, 24 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +17
-0@@ -732,6 +732,23 @@ TRACE_EVENT(amdgpu_userq_state_changed, __entry->client_id, __entry->queue_type, __entry->doorbell_index, __entry->to) ); +TRACE_EVENT (amdgpu_register_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu register pid %d" , + __entry->pid) +); +TRACE_EVENT (amdgpu_deregister_pid, + TP_PROTO(uint32_t pid), +TP_ARGS (pid), +TP_STRUCT__entry (__field (uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), +TP_printk ("amdgpu deregister pid %d" , + __entry->pid) +); +#undef AMDGPU_JOB_GET_TIMELINE_NAME#endif drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0@@ -2457,6 +2457,9 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref) { struct amdgpu_task_info *ti = container_of(kref, struct amdgpu_task_info, refcount); +if (ti->task.pid) +trace_amdgpu_deregister_pid (ti->task.pid); +kfree (ti); }@@ -2543,6 +2546,10 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too.
Chose a better function to add the trace although trace in itself is fine.Regards
Sunil KhatriQuoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0if (vm->task_info->task.pid == current->pid)return ; +if (vm->task_info->task.pid) +trace_amdgpu_deregister_pid (vm->task_info->task.pid); +trace_amdgpu_register_pid (current->pid); + vm->task_info->task.pid = current->pid;get_task_comm (vm->task_info->task.comm, current);
Quoted 10 lines · Sunil
Quoted 8 lines · David
Quoted 3 lines
This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too.
This function is called when the last ref to an
task_infois put. Many places in the code temporarily acquire references to atask_infobut onlyamdgpu_vmholds the long-term reference, acquired inamdgpu_vm_create_task_infoand relased inamdgpu_vm_fini.
Quoted 5 lines
Quoted 3 lines
Tying the trace to the lifetime of
task_infoalso guarantees that there will be exactly one such trace for eachtask_info, matching the register trace semanticsFor begining,
amdgpu_vm_initsounds like a better choice
Anywhere After line , r = amdgpu_vm_create_task_info(vm);
Regards
Sunil Khatri
Quoted 90 lines
for ending,
amdgpu_vm_destroy_task_infois correct.Regards
Sunil KhatriQuoted 85 lines
David Francis
________________________________________
From: Khatri, Sunil <[email protected]>
Sent: Tuesday, July 28, 2026 8:26 AM
To: Francis, David; [email protected]
Cc: Liu, Shuzhou (Bill); Khatri, Sunil
Subject: Re: [PATCH] drm/amdgpu: Add trace events for pid register/deregisterQuoted 54 lines · David Francis
Some debugging applications need to track when a process starts or stops using the amdgpu driver. For those processes, add ftrace events that track when a
amdgpu_vmtask info is changed or destroyed.Signed-off-by David Francis <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h| 17 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 7 +++++++2 files changed, 24 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +17
-0@@ -732,6 +732,23 @@ TRACE_EVENT(amdgpu_userq_state_changed, __entry->client_id, __entry->queue_type, __entry->doorbell_index, __entry->to) ); +TRACE_EVENT (amdgpu_register_pid, + TP_PROTO(uint32_t pid), + TP_ARGS(pid), + TP_STRUCT__entry(__field(uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), + TP_printk("amdgpu register pid %d", + __entry->pid) +); +TRACE_EVENT (amdgpu_deregister_pid, + TP_PROTO(uint32_t pid), + TP_ARGS(pid), + TP_STRUCT__entry(__field(uint32_t, pid)), + TP_fast_assign(__entry->pid = pid;), + TP_printk("amdgpu deregister pid %d", + __entry->pid) +); + #undef AMDGPU_JOB_GET_TIMELINE_NAME #endifdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0@@ -2457,6 +2457,9 @@ static void amdgpu_vm_destroy_task_info(struct kref *kref) { struct amdgpu_task_info *ti = container_of(kref, struct amdgpu_task_info, refcount); + if (ti->task.pid) + trace_amdgpu_deregister_pid(ti->task.pid); + kfree(ti); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm · line 2546
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -2543,6 +2546,10 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)This function is called from many places and will not match when a process start and similarly for stop. Better find a unique function, also this will be called for KGD and KFD processes too.
Chose a better function to add the trace although trace in itself is fine.Regards
Sunil KhatriQuoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0if (vm->task_info->task.pid == current->pid) return; + if (vm->task_info->task.pid) +trace_amdgpu_deregister_pid (vm->task_info->task.pid); + trace_amdgpu_register_pid(current->pid); + vm->task_info->task.pid = current->pid; get_task_comm(vm->task_info->task.comm, current);