Skip to contentSkip to conversation

drm/amdgpu: Add trace events for pid register/deregister

PATCH Superseded David Francis 2 participants 5 messages Jul 24 – Jul 28

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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
index 5324030a13f5..c79604b9dda1 100644
@@ -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
index aac8ace9d7a6..8d31a61e8c26 100644
@@ -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
#1 lore raw

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_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
index 5324030a13f5..c79604b9dda1 100644
@@ -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
index aac8ace9d7a6..8d31a61e8c26 100644
@@ -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 -0
  	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);
 
#2 lore raw
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_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
index 5324030a13f5..c79604b9dda1 100644
@@ -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
index aac8ace9d7a6..8d31a61e8c26 100644
@@ -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 -0
      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);
 
#3 lore raw
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_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

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/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_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
index 5324030a13f5..c79604b9dda1 100644
@@ -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
index aac8ace9d7a6..8d31a61e8c26 100644
@@ -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 -0
       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);
 
#4 lore raw
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_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.

Quoted 5 lines
Quoted 3 lines

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

Anywhere After line , r = amdgpu_vm_create_task_info(vm);

Regards
Sunil Khatri

Quoted 90 lines

for ending, amdgpu_vm_destroy_task_info is correct.

Regards
Sunil Khatri

Quoted 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/deregister

Quoted 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_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
index 5324030a13f5..c79604b9dda1 100644
@@ -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
index aac8ace9d7a6..8d31a61e8c26 100644
@@ -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 Khatri

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
        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);