On 28-07-2026 06:45 pm, Francis, David wrote:
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

For begining, amdgpu_vm_init sounds like a better choice
for ending, amdgpu_vm_destroy_task_info is correct.

Regards
Sunil Khatri


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


On 24-07-2026 06:51 pm, David Francis wrote:
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.

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(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
index 5324030a13f5..c79604b9dda1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h
@@ -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

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index aac8ace9d7a6..8d31a61e8c26 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -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
       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);

Reply via email to