drm/amdkfd: Add unmap from GPU SMI event
authorPhilip Yang <Philip.Yang@amd.com>
Thu, 20 Jan 2022 21:43:42 +0000 (16:43 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 30 Jun 2022 19:31:21 +0000 (15:31 -0400)
SVM range unmapped from GPUs when range is unmapped from CPU, or with
xnack on from MMU notifier when range is evicted or migrated.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.h
drivers/gpu/drm/amd/amdkfd/kfd_svm.c

index 3917c38..e5896b7 100644 (file)
@@ -318,6 +318,15 @@ void kfd_smi_event_queue_restore_rescheduled(struct mm_struct *mm)
        kfd_unref_process(p);
 }
 
+void kfd_smi_event_unmap_from_gpu(struct kfd_dev *dev, pid_t pid,
+                                 unsigned long address, unsigned long last,
+                                 uint32_t trigger)
+{
+       kfd_smi_event_add(pid, dev, KFD_SMI_EVENT_UNMAP_FROM_GPU,
+                         "%lld -%d @%lx(%lx) %x %d\n", ktime_get_boottime_ns(),
+                         pid, address, last - address + 1, dev->id, trigger);
+}
+
 int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd)
 {
        struct kfd_smi_client *client;
index b232926..76fe4e0 100644 (file)
@@ -46,4 +46,7 @@ void kfd_smi_event_queue_eviction(struct kfd_dev *dev, pid_t pid,
                                  uint32_t trigger);
 void kfd_smi_event_queue_restore(struct kfd_dev *dev, pid_t pid);
 void kfd_smi_event_queue_restore_rescheduled(struct mm_struct *mm);
+void kfd_smi_event_unmap_from_gpu(struct kfd_dev *dev, pid_t pid,
+                                 unsigned long address, unsigned long last,
+                                 uint32_t trigger);
 #endif
index 8bfb7b9..fd89951 100644 (file)
@@ -1200,7 +1200,7 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 static int
 svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
-                         unsigned long last)
+                         unsigned long last, uint32_t trigger)
 {
        DECLARE_BITMAP(bitmap, MAX_GPU_INSTANCE);
        struct kfd_process_device *pdd;
@@ -1232,6 +1232,9 @@ svm_range_unmap_from_gpus(struct svm_range *prange, unsigned long start,
                        return -EINVAL;
                }
 
+               kfd_smi_event_unmap_from_gpu(pdd->dev, p->lead_thread->pid,
+                                            start, last, trigger);
+
                r = svm_range_unmap_from_gpu(pdd->dev->adev,
                                             drm_priv_to_vm(pdd->drm_priv),
                                             start, last, &fence);
@@ -1759,7 +1762,8 @@ out_reschedule:
  */
 static int
 svm_range_evict(struct svm_range *prange, struct mm_struct *mm,
-               unsigned long start, unsigned long last)
+               unsigned long start, unsigned long last,
+               enum mmu_notifier_event event)
 {
        struct svm_range_list *svms = prange->svms;
        struct svm_range *pchild;
@@ -1804,6 +1808,12 @@ svm_range_evict(struct svm_range *prange, struct mm_struct *mm,
                        msecs_to_jiffies(AMDGPU_SVM_RANGE_RESTORE_DELAY_MS));
        } else {
                unsigned long s, l;
+               uint32_t trigger;
+
+               if (event == MMU_NOTIFY_MIGRATE)
+                       trigger = KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY_MIGRATE;
+               else
+                       trigger = KFD_SVM_UNMAP_TRIGGER_MMU_NOTIFY;
 
                pr_debug("invalidate unmap svms 0x%p [0x%lx 0x%lx] from GPUs\n",
                         prange->svms, start, last);
@@ -1812,13 +1822,13 @@ svm_range_evict(struct svm_range *prange, struct mm_struct *mm,
                        s = max(start, pchild->start);
                        l = min(last, pchild->last);
                        if (l >= s)
-                               svm_range_unmap_from_gpus(pchild, s, l);
+                               svm_range_unmap_from_gpus(pchild, s, l, trigger);
                        mutex_unlock(&pchild->lock);
                }
                s = max(start, prange->start);
                l = min(last, prange->last);
                if (l >= s)
-                       svm_range_unmap_from_gpus(prange, s, l);
+                       svm_range_unmap_from_gpus(prange, s, l, trigger);
        }
 
        return r;
@@ -2232,6 +2242,7 @@ static void
 svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
                         unsigned long start, unsigned long last)
 {
+       uint32_t trigger = KFD_SVM_UNMAP_TRIGGER_UNMAP_FROM_CPU;
        struct svm_range_list *svms;
        struct svm_range *pchild;
        struct kfd_process *p;
@@ -2259,14 +2270,14 @@ svm_range_unmap_from_cpu(struct mm_struct *mm, struct svm_range *prange,
                s = max(start, pchild->start);
                l = min(last, pchild->last);
                if (l >= s)
-                       svm_range_unmap_from_gpus(pchild, s, l);
+                       svm_range_unmap_from_gpus(pchild, s, l, trigger);
                svm_range_unmap_split(mm, prange, pchild, start, last);
                mutex_unlock(&pchild->lock);
        }
        s = max(start, prange->start);
        l = min(last, prange->last);
        if (l >= s)
-               svm_range_unmap_from_gpus(prange, s, l);
+               svm_range_unmap_from_gpus(prange, s, l, trigger);
        svm_range_unmap_split(mm, prange, prange, start, last);
 
        if (unmap_parent)
@@ -2333,7 +2344,7 @@ svm_range_cpu_invalidate_pagetables(struct mmu_interval_notifier *mni,
                svm_range_unmap_from_cpu(mni->mm, prange, start, last);
                break;
        default:
-               svm_range_evict(prange, mni->mm, start, last);
+               svm_range_evict(prange, mni->mm, start, last, range->event);
                break;
        }