<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Calibri;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - AMD Internal Distribution Only]<br>
</p>
<br>
<div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Series is:</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Huang, Trigger <Trigger.Huang@amd.com><br>
<b>Sent:</b> Wednesday, August 21, 2024 4:38 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Khatri, Sunil <Sunil.Khatri@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Huang, Trigger <Trigger.Huang@amd.com><br>
<b>Subject:</b> [PATCH v4 2/2] drm/amdgpu: Do core dump immediately when job tmo</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">From: Trigger Huang <Trigger.Huang@amd.com><br>
<br>
Do the coredump immediately after a job timeout to get a closer<br>
representation of GPU's error status.<br>
<br>
V2: This will skip printing vram_lost as the GPU reset is not<br>
happened yet (Alex)<br>
<br>
V3: Unconditionally call the core dump as we care about all the reset<br>
functions(soft-recovery and queue reset and full adapter reset, Alex)<br>
<br>
V4: Do the dump after adev->job_hang = true (Sunil)<br>
<br>
Signed-off-by: Trigger Huang <Trigger.Huang@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 68 ++++++++++++++++++++++++-<br>
 1 file changed, 67 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c<br>
index c6a1783fc9ef..3000a49b3e5c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c<br>
@@ -30,6 +30,61 @@<br>
 #include "amdgpu.h"<br>
 #include "amdgpu_trace.h"<br>
 #include "amdgpu_reset.h"<br>
+#include "amdgpu_dev_coredump.h"<br>
+#include "amdgpu_xgmi.h"<br>
+<br>
+static void amdgpu_job_do_core_dump(struct amdgpu_device *adev,<br>
+                                   struct amdgpu_job *job)<br>
+{<br>
+       int i;<br>
+<br>
+       dev_info(adev->dev, "Dumping IP State\n");<br>
+       for (i = 0; i < adev->num_ip_blocks; i++) {<br>
+               if (adev->ip_blocks[i].version->funcs->dump_ip_state)<br>
+                       adev->ip_blocks[i].version->funcs<br>
+                               ->dump_ip_state((void *)adev);<br>
+               dev_info(adev->dev, "Dumping IP State Completed\n");<br>
+       }<br>
+<br>
+       amdgpu_coredump(adev, true, false, job);<br>
+}<br>
+<br>
+static void amdgpu_job_core_dump(struct amdgpu_device *adev,<br>
+                                struct amdgpu_job *job)<br>
+{<br>
+       struct list_head device_list, *device_list_handle =  NULL;<br>
+       struct amdgpu_device *tmp_adev = NULL;<br>
+       struct amdgpu_hive_info *hive = NULL;<br>
+<br>
+       if (!amdgpu_sriov_vf(adev))<br>
+               hive = amdgpu_get_xgmi_hive(adev);<br>
+       if (hive)<br>
+               mutex_lock(&hive->hive_lock);<br>
+       /*<br>
+        * Reuse the logic in amdgpu_device_gpu_recover() to build list of<br>
+        * devices for code dump<br>
+        */<br>
+       INIT_LIST_HEAD(&device_list);<br>
+       if (!amdgpu_sriov_vf(adev) && (adev->gmc.xgmi.num_physical_nodes > 1) && hive) {<br>
+               list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head)<br>
+                       list_add_tail(&tmp_adev->reset_list, &device_list);<br>
+               if (!list_is_first(&adev->reset_list, &device_list))<br>
+                       list_rotate_to_front(&adev->reset_list, &device_list);<br>
+               device_list_handle = &device_list;<br>
+       } else {<br>
+               list_add_tail(&adev->reset_list, &device_list);<br>
+               device_list_handle = &device_list;<br>
+       }<br>
+<br>
+       /* Do the coredump for each device */<br>
+       list_for_each_entry(tmp_adev, device_list_handle, reset_list)<br>
+               amdgpu_job_do_core_dump(tmp_adev, job);<br>
+<br>
+       if (hive) {<br>
+               mutex_unlock(&hive->hive_lock);<br>
+               amdgpu_put_xgmi_hive(hive);<br>
+       }<br>
+}<br>
 <br>
 static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)<br>
 {<br>
@@ -48,9 +103,14 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)<br>
                 return DRM_GPU_SCHED_STAT_ENODEV;<br>
         }<br>
 <br>
-<br>
         adev->job_hang = true;<br>
 <br>
+       /*<br>
+        * Do the coredump immediately after a job timeout to get a very<br>
+        * close dump/snapshot/representation of GPU's current error status<br>
+        */<br>
+       amdgpu_job_core_dump(adev, job);<br>
+<br>
         if (amdgpu_gpu_recovery &&<br>
             amdgpu_ring_soft_recovery(ring, job->vmid, s_job->s_fence->parent)) {<br>
                 dev_err(adev->dev, "ring %s timeout, but soft recovered\n",<br>
@@ -101,6 +161,12 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)<br>
                 reset_context.src = AMDGPU_RESET_SRC_JOB;<br>
                 clear_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);<br>
 <br>
+               /*<br>
+                * To avoid an unnecessary extra coredump, as we have already<br>
+                * got the very close representation of GPU's error status<br>
+                */<br>
+               set_bit(AMDGPU_SKIP_COREDUMP, &reset_context.flags);<br>
+<br>
                 r = amdgpu_device_gpu_recover(ring->adev, job, &reset_context);<br>
                 if (r)<br>
                         dev_err(adev->dev, "GPU Recovery Failed: %d\n", r);<br>
-- <br>
2.34.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>