Skip to contentSkip to conversation

drm/amdkfd: add smi events for process start and end

PATCH In review Eric Huang 2 participants 3 messages Apr 7, 2025 – Apr 11, 2025

Subsystems (3)
lore
Share & tools
lore

Eric Huang

author
#0 lore raw

PATCH 1/1 drm/amdkfd: add smi events for process start and end

rocm-smi will be able to show the events for KFD process start/end, it is the implementation of this feature.

---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c    |  4 ++++
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h |  1 +
 include/uapi/linux/kfd_ioctl.h              |  5 +++++
 4 files changed, 31 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -0
index 7c0c24732481..41d7dc8c2850 100644
@@ -1054,6 +1054,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
 	for (i = 0; i < p->n_pdds; i++) {
 		struct kfd_process_device *pdd = p->pdds[i];
 
+		kfd_smi_event_process(pdd, false);
+
 		pr_debug("Releasing pdd (topology id %d, for pid %d)\n",
 			pdd->dev->id, p->lead_thread->pid);
 		kfd_process_device_destroy_cwsr_dgpu(pdd);
@@ -1715,6 +1717,8 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
 	pdd->pasid = avm->pasid;
 	pdd->drm_file = drm_file;
 
+	kfd_smi_event_process(pdd, true);
+
 	return 0;
 
 err_get_pasid:
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +21 -0
index 9b8169761ec5..727a4ce29fe6 100644
@@ -345,6 +345,27 @@ void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid,
 			  pid, address, last - address + 1, node->id, trigger));
 }
 
+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start)
+{
+	struct amdgpu_task_info *task_info;
+	struct amdgpu_vm *avm;
+
+	if (pdd->drm_priv)
+		return;
+
+	avm = drm_priv_to_vm(pdd->drm_priv);
+	task_info = amdgpu_vm_get_task_info_vm(avm);
+
+	if (task_info) {
+		kfd_smi_event_add(0, pdd->dev,
+				  start ? KFD_SMI_EVENT_PROCESS_START :
+				  KFD_SMI_EVENT_PROCESS_END,
+				  KFD_EVENT_FMT_PROCESS(task_info->pid,
+				  task_info->task_name));
+		amdgpu_vm_put_task_info(task_info);
+	}
+}
+
 int kfd_smi_event_open(struct kfd_node *dev, uint32_t *fd)
 {
 	struct kfd_smi_client *client;
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h +1 -0
index 503bff13d815..bb4d72b57387 100644
@@ -53,4 +53,5 @@ void kfd_smi_event_queue_restore_rescheduled(struct mm_struct *mm);
 void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid,
 				  unsigned long address, unsigned long last,
 				  uint32_t trigger);
+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start);
 #endif
include/uapi/linux/kfd_ioctl.h +5 -0
index 1e59344c5673..04c7d283dc7d 100644
@@ -536,6 +536,8 @@ enum kfd_smi_event {
 	KFD_SMI_EVENT_QUEUE_EVICTION = 9,
 	KFD_SMI_EVENT_QUEUE_RESTORE = 10,
 	KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
+	KFD_SMI_EVENT_PROCESS_START = 12,
+	KFD_SMI_EVENT_PROCESS_END = 13,
 
 	/*
 	 * max event number, as a flag bit to get events from all processes,
@@ -651,6 +653,9 @@ struct kfd_ioctl_smi_events_args {
 		"%lld -%d @%lx(%lx) %x %d\n", (ns), (pid), (addr), (size),\
 		(node), (unmap_trigger)
 
+#define KFD_EVENT_FMT_PROCESS(pid, task_name)\
+		"%x %s\n", (pid), (task_name)
+
 /**************************************************************************************************
  * CRIU IOCTLs (Checkpoint Restore In Userspace)
  *
Signature · 1 line
2.34.1
author
#1 lore raw

Ping ...

Quoted 98 lines · Eric Huang

rocm-smi will be able to show the events for KFD process start/end, it is the implementation of this feature.

---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c    |  4 ++++
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 21 +++++++++++++++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h |  1 +
  include/uapi/linux/kfd_ioctl.h              |  5 +++++
  4 files changed, 31 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -0
index 7c0c24732481..41d7dc8c2850 100644
@@ -1054,6 +1054,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
  	for (i = 0; i < p->n_pdds; i++) {
  		struct kfd_process_device *pdd = p->pdds[i];
 
+		kfd_smi_event_process(pdd, false);
+
  		pr_debug("Releasing pdd (topology id %d, for pid %d)\n",
  			pdd->dev->id, p->lead_thread->pid);
  		kfd_process_device_destroy_cwsr_dgpu(pdd);
@@ -1715,6 +1717,8 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
  	pdd->pasid = avm->pasid;
  	pdd->drm_file = drm_file;
 
+	kfd_smi_event_process(pdd, true);
+
  	return 0;
 
  err_get_pasid:
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +21 -0
index 9b8169761ec5..727a4ce29fe6 100644
@@ -345,6 +345,27 @@ void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid,
  			  pid, address, last - address + 1, node->id, trigger));
  }
 
+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start)
+{
+	struct amdgpu_task_info *task_info;
+	struct amdgpu_vm *avm;
+
+	if (pdd->drm_priv)
+		return;
+
+	avm = drm_priv_to_vm(pdd->drm_priv);
+	task_info = amdgpu_vm_get_task_info_vm(avm);
+
+	if (task_info) {
+		kfd_smi_event_add(0, pdd->dev,
+				  start ? KFD_SMI_EVENT_PROCESS_START :
+				  KFD_SMI_EVENT_PROCESS_END,
+				  KFD_EVENT_FMT_PROCESS(task_info->pid,
+				  task_info->task_name));
+		amdgpu_vm_put_task_info(task_info);
+	}
+}
+
  int kfd_smi_event_open(struct kfd_node *dev, uint32_t *fd)
  {
  	struct kfd_smi_client *client;
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h +1 -0
index 503bff13d815..bb4d72b57387 100644
@@ -53,4 +53,5 @@ void kfd_smi_event_queue_restore_rescheduled(struct mm_struct *mm);
  void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid,
  				  unsigned long address, unsigned long last,
  				  uint32_t trigger);
+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start);
  #endif
include/uapi/linux/kfd_ioctl.h +5 -0
index 1e59344c5673..04c7d283dc7d 100644
@@ -536,6 +536,8 @@ enum kfd_smi_event {
  	KFD_SMI_EVENT_QUEUE_EVICTION = 9,
  	KFD_SMI_EVENT_QUEUE_RESTORE = 10,
  	KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
+	KFD_SMI_EVENT_PROCESS_START = 12,
+	KFD_SMI_EVENT_PROCESS_END = 13,
 
  	/*
  	 * max event number, as a flag bit to get events from all processes,
@@ -651,6 +653,9 @@ struct kfd_ioctl_smi_events_args {
  		"%lld -%d @%lx(%lx) %x %d\n", (ns), (pid), (addr), (size),\
  		(node), (unmap_trigger)
 
+#define KFD_EVENT_FMT_PROCESS(pid, task_name)\
+		"%x %s\n", (pid), (task_name)
+
  /**************************************************************************************************
   * CRIU IOCTLs (Checkpoint Restore In Userspace)
   *
Reviewed-by
#2 lore raw

[Public]

Quoted 117 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Eric Huang
Sent: Friday, April 11, 2025 9:45 AM
To: Huang, JinHuiEric <[email protected]>; amd- [email protected]
Subject: Re: [PATCH] drm/amdkfd: add smi events for process start and end

Ping ...

Quoted 4 lines · Eric Huang

rocm-smi will be able to show the events for KFD process start/end, it is the implementation of this feature.

Review

Quoted 8 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_process.c    |  4 ++++
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 21 +++++++++++++++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h |  1 +
  include/uapi/linux/kfd_ioctl.h              |  5 +++++
  4 files changed, 31 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_process.c

drivers/gpu/drm/amd/amdkfd/kfd_process.c static void kfd_process_destroy_pdds(struct

Quoted 4 lines

index 7c0c24732481..41d7dc8c2850 100644

drivers/gpu/drm/amd/amdkfd/kfd_process.c +0 -0
@@ -1054,6 +1054,8 @@ static void kfd_process_destroy_pdds(struct

kfd_process *p)

drivers/gpu/drm/amd/amdkfd/kfd_process.c int kfd_process_device_init_vm(struct

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2 -0
    for (i = 0; i < p->n_pdds; i++) {
            struct kfd_process_device *pdd = p->pdds[i];
 
+           kfd_smi_event_process(pdd, false);
+
            pr_debug("Releasing pdd (topology id %d, for pid %d)\n",
                    pdd->dev->id, p->lead_thread->pid);
            kfd_process_device_destroy_cwsr_dgpu(pdd);
@@ -1715,6 +1717,8 @@ int kfd_process_device_init_vm(struct

kfd_process_device *pdd,

Review

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +2 -0
    pdd->pasid = avm->pasid;
    pdd->drm_file = drm_file;
 
+   kfd_smi_event_process(pdd, true);
+
    return 0;
 
  err_get_pasid:
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c void kfd_smi_event_unmap_from_gpu(struct kfd_node

Quoted 4 lines

index 9b8169761ec5..727a4ce29fe6 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +0 -0
@@ -345,6 +345,27 @@ void kfd_smi_event_unmap_from_gpu(struct kfd_node

*node, pid_t pid,

Review

Quoted 28 lines
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +21 -0
                      pid, address, last - address + 1, node->id, trigger));
  }
 
+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start)
+{
+   struct amdgpu_task_info *task_info;
+   struct amdgpu_vm *avm;
+
+   if (pdd->drm_priv)
+           return;
+
+   avm = drm_priv_to_vm(pdd->drm_priv);
+   task_info = amdgpu_vm_get_task_info_vm(avm);
+
+   if (task_info) {
+           kfd_smi_event_add(0, pdd->dev,
+                             start ? KFD_SMI_EVENT_PROCESS_START :
+                             KFD_SMI_EVENT_PROCESS_END,
+                             KFD_EVENT_FMT_PROCESS(task_info->pid,
+                             task_info->task_name));
+           amdgpu_vm_put_task_info(task_info);
+   }
+}
+
  int kfd_smi_event_open(struct kfd_node *dev, uint32_t *fd)
  {
    struct kfd_smi_client *client;
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h void kfd_smi_event_queue_restore_rescheduled(struct

Quoted 4 lines

index 503bff13d815..bb4d72b57387 100644

drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h +0 -0
@@ -53,4 +53,5 @@ void kfd_smi_event_queue_restore_rescheduled(struct

mm_struct *mm);

Quoted 19 lines
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h +1 -0
  void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid,
                              unsigned long address, unsigned long last,
                              uint32_t trigger);
+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start);
  #endif
include/uapi/linux/kfd_ioctl.h +2 -0
index 1e59344c5673..04c7d283dc7d 100644
@@ -536,6 +536,8 @@ enum kfd_smi_event {
    KFD_SMI_EVENT_QUEUE_EVICTION = 9,
    KFD_SMI_EVENT_QUEUE_RESTORE = 10,
    KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
+   KFD_SMI_EVENT_PROCESS_START = 12,
+   KFD_SMI_EVENT_PROCESS_END = 13,
 
    /*
     * max event number, as a flag bit to get events from all processes,

include/uapi/linux/kfd_ioctl.h struct kfd_ioctl_smi_events_args { · line 659

Quoted 7 lines
include/uapi/linux/kfd_ioctl.h +3 -0
@@ -651,6 +653,9 @@ struct kfd_ioctl_smi_events_args {
            "%lld -%d @%lx(%lx) %x %d\n", (ns), (pid), (addr), (size),\
            (node), (unmap_trigger)
 
+#define KFD_EVENT_FMT_PROCESS(pid, task_name)\
+           "%x %s\n", (pid), (task_name)
+
 

/************************************************************************************************ **

Quoted 2 lines
include/uapi/linux/kfd_ioctl.h +0 -0
   * CRIU IOCTLs (Checkpoint Restore In Userspace)
   *