Skip to contentSkip to conversation

drm/amdgpu: Add support for logging process info in amdgpu_vm.

PATCH Superseded Andrey Grodzovsky 3 participants 4 messages Jul 4, 2018 – Jul 5, 2018 2 messages not in the archive

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/amdgpu: Add support for logging process info in amdgpu_vm.

Add process and thread names and pids and a function to extract this info from relevant amdgpu_vm.

v2: Add documentation and fix identation.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 14 ++++++++++++++
 2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +21 -0
index 712af5c..845f73a 100644
@@ -2942,3 +2942,24 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 
 	return 0;
 }
+
+/**
+ * amdgpu_vm_task_info - Extracts task info for a PASID.
+ *
+ * @dev: drm device pointer
+ * @pasid: PASID identifier for VM
+ * @task_info: task_info to fill.
+ */
+void amdgpu_vm_task_info(struct amdgpu_device *adev, unsigned int pasid,
+			 struct amdgpu_task_info *task_info)
+{
+	struct amdgpu_vm *vm;
+
+	spin_lock(&adev->vm_manager.pasid_lock);
+
+	vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
+	if (vm)
+		*task_info = vm->task_info;
+
+	spin_unlock(&adev->vm_manager.pasid_lock);
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +14 -0
index 061b99a..cd4025e 100644
@@ -164,6 +164,14 @@ struct amdgpu_vm_pt {
 #define AMDGPU_VM_FAULT_PASID(fault) ((u64)(fault) >> 48)
 #define AMDGPU_VM_FAULT_ADDR(fault)  ((u64)(fault) & 0xfffffffff000ULL)
 
+
+struct amdgpu_task_info {
+	char	process_name[TASK_COMM_LEN];
+	char	task_name[TASK_COMM_LEN];
+	pid_t	pid;
+	pid_t	tgid;
+};
+
 struct amdgpu_vm {
 	/* tree of virtual addresses mapped */
 	struct rb_root_cached	va;
@@ -215,6 +223,9 @@ struct amdgpu_vm {
 
 	/* Valid while the PD is reserved or fenced */
 	uint64_t		pd_phys_addr;
+
+	/* Some basic info about the task */
+	struct amdgpu_task_info task_info;
 };
 
 struct amdgpu_vm_manager {
@@ -317,4 +328,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
 				  struct amdgpu_job *job);
 void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);
 
+void amdgpu_vm_task_info(struct amdgpu_device *adev, unsigned int pasid,
+			 struct amdgpu_task_info *task_info);
+
 #endif
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1530716678-15352-1-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH v2 2/2 drm/admgpu: Present amdgpu_task_info in VM_FAULTS.

Extract and present the reposnsible process and thread when VM_FAULT happens.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 12 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c  | 10 ++++++++--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  |  9 +++++++--
 3 files changed, 27 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +12 -0
index 7a625f3..1c483ea 100644
@@ -187,6 +187,18 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
 	if (p->uf_entry.robj)
 		p->job->uf_addr = uf_offset;
 	kfree(chunk_array);
+
+	/* Use this opportunity to fill in task info for the vm */
+	if (!vm->task_info.pid) {
+		vm->task_info.pid = current->pid;
+		get_task_comm(vm->task_info.task_name, current);
+
+		if (current->group_leader->mm == current->mm) {
+			vm->task_info.tgid = current->group_leader->pid;
+			get_task_comm(vm->task_info.process_name, current->group_leader);
+		}
+	}
+
 	return 0;
 
 free_all_kdata:
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +8 -2
index 08753e7..7ad19f9 100644
@@ -46,6 +46,7 @@
 
 #include "ivsrcid/ivsrcid_vislands30.h"
 
+#include "amdgpu_vm.h"
 
 static void gmc_v8_0_set_gmc_funcs(struct amdgpu_device *adev);
 static void gmc_v8_0_set_irq_funcs(struct amdgpu_device *adev);
@@ -1449,8 +1450,13 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
 		gmc_v8_0_set_fault_enable_default(adev, false);
 
 	if (printk_ratelimit()) {
-		dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
-			entry->src_id, entry->src_data[0]);
+		struct amdgpu_task_info task_info = { 0 };
+
+		amdgpu_vm_task_info(adev, entry->pasid, &task_info);
+
+		dev_err(adev->dev, "GPU fault detected: %d 0x%08x for process %s pid %d thread %s pid %d\n",
+			entry->src_id, entry->src_data[0], task_info.process_name,
+			task_info.tgid, task_info.task_name, task_info.pid);
 		dev_err(adev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_ADDR   0x%08X\n",
 			addr);
 		dev_err(adev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -2
index 691a659..384a89c 100644
@@ -259,11 +259,16 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
 	}
 
 	if (printk_ratelimit()) {
+		struct amdgpu_task_info task_info = { 0 };
+
+		amdgpu_vm_task_info(adev, entry->pasid, &task_info);
+
 		dev_err(adev->dev,
-			"[%s] VMC page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
+			"[%s] VMC page fault (src_id:%u ring:%u vmid:%u pasid:%u, for process %s pid %d thread %s pid %d\n)\n",
 			entry->vmid_src ? "mmhub" : "gfxhub",
 			entry->src_id, entry->ring_id, entry->vmid,
-			entry->pasid);
+			entry->pasid, task_info.process_name, task_info.tgid,
+			task_info.task_name, task_info.pid);
 		dev_err(adev->dev, "  at page 0x%016llx from %d\n",
 			addr, entry->client_id);
 		if (!amdgpu_sriov_vf(adev))
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1530716678-15352-2-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH v2 2/2] drm/admgpu: Present amdgpu_task_info in VM_FAULTS.

Quoted 20 lines · Andrey Grodzovsky

Extract and present the reposnsible process and thread when VM_FAULT happens.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 12 ++++++++++++
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c  | 10 ++++++++--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  |  9 +++++++--
  3 files changed, 27 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -0
index 7a625f3..1c483ea 100644
@@ -187,6 +187,18 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data)
  	if (p->uf_entry.robj)
  		p->job->uf_addr = uf_offset;
  	kfree(chunk_array);
+
+	/* Use this opportunity to fill in task info for the vm */

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data) · line 201

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -0
+	if (!vm->task_info.pid) {
+		vm->task_info.pid = current->pid;
+		get_task_comm(vm->task_info.task_name, current);
+
+		if (current->group_leader->mm == current->mm) {
+			vm->task_info.tgid = current->group_leader->pid;
+			get_task_comm(vm->task_info.process_name, current->group_leader);
+		}
+	}
+

you can wrap this segment to  a function like amdgpu_vm_set_task_info.

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
  	return 0;
 
  free_all_kdata:
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -0
index 08753e7..7ad19f9 100644
@@ -46,6 +46,7 @@
 
  #include "ivsrcid/ivsrcid_vislands30.h"
 
+#include "amdgpu_vm.h"
 
  static void gmc_v8_0_set_gmc_funcs(struct amdgpu_device *adev);
  static void gmc_v8_0_set_irq_funcs(struct amdgpu_device *adev);

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev, · line 1455

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 -2
@@ -1449,8 +1450,13 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,
  		gmc_v8_0_set_fault_enable_default(adev, false);
 
  	if (printk_ratelimit()) {
-		dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
-			entry->src_id, entry->src_data[0]);
+		struct amdgpu_task_info task_info = { 0 };
+
+		amdgpu_vm_task_info(adev, entry->pasid, &task_info);

you can rename this function to amdgpu_vm_get_task_info.

general, it looks very good to me and does what I want to do before.

Thanks,
David Zhou

Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +4 -0
+
+		dev_err(adev->dev, "GPU fault detected: %d 0x%08x for process %s pid %d thread %s pid %d\n",
+			entry->src_id, entry->src_data[0], task_info.process_name,
+			task_info.tgid, task_info.task_name, task_info.pid);
  		dev_err(adev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_ADDR   0x%08X\n",
  			addr);
  		dev_err(adev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +4 -0
index 691a659..384a89c 100644
@@ -259,11 +259,16 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
  	}
 
  	if (printk_ratelimit()) {
+		struct amdgpu_task_info task_info = { 0 };
+
+		amdgpu_vm_task_info(adev, entry->pasid, &task_info);
+
  		dev_err(adev->dev,

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, · line 274

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +3 -2
-			"[%s] VMC page fault (src_id:%u ring:%u vmid:%u pasid:%u)\n",
+			"[%s] VMC page fault (src_id:%u ring:%u vmid:%u pasid:%u, for process %s pid %d thread %s pid %d\n)\n",
  			entry->vmid_src ? "mmhub" : "gfxhub",
  			entry->src_id, entry->ring_id, entry->vmid,
-			entry->pasid);
+			entry->pasid, task_info.process_name, task_info.tgid,
+			task_info.task_name, task_info.pid);
  		dev_err(adev->dev, "  at page 0x%016llx from %d\n",
  			addr, entry->client_id);
  		if (!amdgpu_sriov_vf(adev))

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw
In reply to a message not in the archive

Am 04.07.2018 um 17:04 schrieb Andrey Grodzovsky:

Quoted 30 lines

Add process and thread names and pids and a function to extract this info from relevant amdgpu_vm.

v2: Add documentation and fix identation.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 +++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 14 ++++++++++++++
  2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +11 -0
index 712af5c..845f73a 100644
@@ -2942,3 +2942,24 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 
  	return 0;
  }
+
+/**
+ * amdgpu_vm_task_info - Extracts task info for a PASID.
+ *
+ * @dev: drm device pointer
+ * @pasid: PASID identifier for VM
+ * @task_info: task_info to fill.
+ */
+void amdgpu_vm_task_info(struct amdgpu_device *adev, unsigned int pasid,
+			 struct amdgpu_task_info *task_info)
+{

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 2965

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+	struct amdgpu_vm *vm;
+
+	spin_lock(&adev->vm_manager.pasid_lock);
+
+	vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
+	if (vm)
+		*task_info = vm->task_info;
+
+	spin_unlock(&adev->vm_manager.pasid_lock);
+}

As David suggested as well I would both add the amdgpu_vm_get_task_info() and amdgpu_vm_set_task_info() calls in this patch and then wire up everything in the second path.

Apart from that looks good to me,
Christian.

Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +11 -0
index 061b99a..cd4025e 100644
@@ -164,6 +164,14 @@ struct amdgpu_vm_pt {
  #define AMDGPU_VM_FAULT_PASID(fault) ((u64)(fault) >> 48)
  #define AMDGPU_VM_FAULT_ADDR(fault)  ((u64)(fault) & 0xfffffffff000ULL)
 
+
+struct amdgpu_task_info {
+	char	process_name[TASK_COMM_LEN];
+	char	task_name[TASK_COMM_LEN];
+	pid_t	pid;
+	pid_t	tgid;
+};
+
  struct amdgpu_vm {
  	/* tree of virtual addresses mapped */
  	struct rb_root_cached	va;
@@ -215,6 +223,9 @@ struct amdgpu_vm {
 
  	/* Valid while the PD is reserved or fenced */
  	uint64_t		pd_phys_addr;
+
+	/* Some basic info about the task */
+	struct amdgpu_task_info task_info;
  };
 
  struct amdgpu_vm_manager {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring, · line 334

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -0
@@ -317,4 +328,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,
  				  struct amdgpu_job *job);
  void amdgpu_vm_check_compute_bug(struct amdgpu_device *adev);
 
+void amdgpu_vm_task_info(struct amdgpu_device *adev, unsigned int pasid,
+			 struct amdgpu_task_info *task_info);
+
  #endif

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx