History

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.

Eric Huang committed 1 year ago

Commit 4172b551 parent 1d9bff44 files · +31 −0Browse files

Unified · Split

4 files
  1. drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 −0
  2. drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +21 −0
  3. drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h +1 −0
  4. include/uapi/linux/kfd_ioctl.h +5 −0
drivers/gpu/drm/amd/amdkfd/kfd_process.c+4−0
@@ -1054,6 +1054,8 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) · 1053 unmodified lines
10541054 for (i = 0; i < p->n_pdds; i++) {
10551055 struct kfd_process_device *pdd = p->pdds[i];
10561056
1057+ kfd_smi_event_process(pdd, false);
1058+
10571059 pr_debug("Releasing pdd (topology id %d, for pid %d)\n",
10581060 pdd->dev->id, p->lead_thread->pid);
10591061 kfd_process_device_destroy_cwsr_dgpu(pdd);
@@ -1715,6 +1717,8 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd, · 655 unmodified lines
17151717 pdd->pasid = avm->pasid;
17161718 pdd->drm_file = drm_file;
17171719
1720+ kfd_smi_event_process(pdd, true);
1721+
17181722 return 0;
17191723
17201724 err_get_pasid:
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c+21−0
@@ -345,6 +345,27 @@ void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid, · 344 unmodified lines
345345 pid, address, last - address + 1, node->id, trigger));
346346 }
347347
348+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start)
349+{
350+ struct amdgpu_task_info *task_info;
351+ struct amdgpu_vm *avm;
352+
353+ if (pdd->drm_priv)
354+ return;
355+
356+ avm = drm_priv_to_vm(pdd->drm_priv);
357+ task_info = amdgpu_vm_get_task_info_vm(avm);
358+
359+ if (task_info) {
360+ kfd_smi_event_add(0, pdd->dev,
361+ start ? KFD_SMI_EVENT_PROCESS_START :
362+ KFD_SMI_EVENT_PROCESS_END,
363+ KFD_EVENT_FMT_PROCESS(task_info->pid,
364+ task_info->task_name));
365+ amdgpu_vm_put_task_info(task_info);
366+ }
367+}
368+
348369 int kfd_smi_event_open(struct kfd_node *dev, uint32_t *fd)
349370 {
350371 struct kfd_smi_client *client;
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h+1−0
@@ -53,4 +53,5 @@ void kfd_smi_event_queue_restore_rescheduled(struct mm_struct *mm); · 52 unmodified lines
5353 void kfd_smi_event_unmap_from_gpu(struct kfd_node *node, pid_t pid,
5454 unsigned long address, unsigned long last,
5555 uint32_t trigger);
56+void kfd_smi_event_process(struct kfd_process_device *pdd, bool start);
5657 #endif
include/uapi/linux/kfd_ioctl.h+5−0
@@ -536,6 +536,8 @@ enum kfd_smi_event { · 535 unmodified lines
536536 KFD_SMI_EVENT_QUEUE_EVICTION = 9,
537537 KFD_SMI_EVENT_QUEUE_RESTORE = 10,
538538 KFD_SMI_EVENT_UNMAP_FROM_GPU = 11,
539+ KFD_SMI_EVENT_PROCESS_START = 12,
540+ KFD_SMI_EVENT_PROCESS_END = 13,
539541
540542 /*
541543 * max event number, as a flag bit to get events from all processes,
@@ -651,6 +653,9 @@ struct kfd_ioctl_smi_events_args { · 109 unmodified lines
651653 "%lld -%d @%lx(%lx) %x %d\n", (ns), (pid), (addr), (size),\
652654 (node), (unmap_trigger)
653655
656+#define KFD_EVENT_FMT_PROCESS(pid, task_name)\
657+ "%x %s\n", (pid), (task_name)
658+
654659 /**************************************************************************************************
655660 * CRIU IOCTLs (Checkpoint Restore In Userspace)
656661 *