drm/amdkfd: add smi events for process start and end
authorEric Huang <jinhuieric.huang@amd.com>
Mon, 7 Apr 2025 19:32:33 +0000 (15:32 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 11 Apr 2025 21:01:25 +0000 (17:01 -0400)
rocm-smi will be able to show the events for KFD process
start/end, it is the implementation of this feature.

Signed-off-by: Eric Huang <jinhuieric.huang@amd.com>
Reviewed-by: Kent Russell <kent.russell@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_process.c
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h
include/uapi/linux/kfd_ioctl.h

index 7c0c24732481e9191e8cb699dd13989ed97f3356..41d7dc8c285070bb7357b98725d2c8832f8a9e53 100644 (file)
@@ -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:
index 9b8169761ec5be38090312b77bcbc8f85b20373f..727a4ce29fe63102dbf5d941137ca128629f95b5 100644 (file)
@@ -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;
index 503bff13d815336416689f8f0c6d8d59848df9cb..bb4d72b57387c913c509e14c597cbc888d56a497 100644 (file)
@@ -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
index 1e59344c5673e15b48f1524b8882f708fb5a6aeb..04c7d283dc7d7d28ecebfe8f0105bff9fdbb80a5 100644 (file)
@@ -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)
  *