Skip to contentSkip to conversation

drm/amdgpu: add reset register trace dump function

PATCH In review Sharma, Shashank 2 participants 7 messages Jan 21, 2022 – Jan 24, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 drm/amdgpu: add reset register trace dump function

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for
gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53 ++++++++++++++++++++++-
 drivers/gpu/drm/amd/include/amd_shared.h  |  1 +
 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
 		      __entry->seqno)
 );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+	    TP_PROTO(char *reg_dumps),
+	    TP_ARGS(reg_dumps),
+	    TP_STRUCT__entry(__string(dumps, reg_dumps)),
+	    TP_fast_assign(__assign_str(dumps, reg_dumps);),
+	    TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
 #undef AMDGPU_JOB_GET_TIMELINE_NAME
 #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
 #include "v10_structs.h"
 #include "gfx_v10_0.h"
 #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
 /*
  * Navi10 has two graphic rings to share each graphic pipe.
  * 1. Primary ring
@@ -188,6 +188,12 @@
 #define RLCG_ERROR_REPORT_ENABLED(adev) \
 	(amdgpu_sriov_reg_indirect_mmhub(adev) || 

amdgpu_sriov_reg_indirect_gc(adev))

+#define N_REGS (17)
+#define DUMP_REG(addr) do { \
+ (dump)[i][0] = (addr); \
+ (dump)[i++][1] = RREG32_SOC15_IP(GC, addr); \
+ } while (0)
+
MODULE_FIRMWARE("amdgpu/navi10_ce.bin"); MODULE_FIRMWARE("amdgpu/navi10_pfp.bin"); MODULE_FIRMWARE("amdgpu/navi10_me.bin");
@@ -7488,7 +7494,6 @@ static int gfx_v10_0_hw_init(void *handle)
{
int r;
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
if (!amdgpu_emu_mode)
gfx_v10_0_init_golden_registers(adev);

@@ -7602,6 +7607,49 @@ static int gfx_v10_0_hw_fini(void *handle)
return 0;
}

+static int gfx_v10_0_reset_reg_dumps(void *handle)
+{
+ struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+ uint32_t i = 0;
+ uint32_t (*dump)[2], n_regs = 0;
+ char *reg_dumps;
+
+ dump = kmalloc(N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+ reg_dumps = kmalloc(1024, GFP_KERNEL);
+
+ if (dump == NULL || reg_dumps == NULL)
+ return -ENOMEM;
+
+ DUMP_REG(mmGRBM_STATUS2);
+ DUMP_REG(mmGRBM_STATUS_SE0);
+ DUMP_REG(mmGRBM_STATUS_SE1);
+ DUMP_REG(mmGRBM_STATUS_SE2);
+ DUMP_REG(mmGRBM_STATUS_SE3);
+ DUMP_REG(mmSDMA0_STATUS_REG);
+ DUMP_REG(mmSDMA1_STATUS_REG);
+ DUMP_REG(mmCP_STAT);
+ DUMP_REG(mmCP_STALLED_STAT1);
+ DUMP_REG(mmCP_STALLED_STAT1);
+ DUMP_REG(mmCP_STALLED_STAT3);
+ DUMP_REG(mmCP_CPC_STATUS);
+ DUMP_REG(mmCP_CPC_BUSY_STAT);
+ DUMP_REG(mmCP_CPC_STALLED_STAT1);
+ DUMP_REG(mmCP_CPF_STATUS);
+ DUMP_REG(mmCP_CPF_BUSY_STAT);
+ DUMP_REG(mmCP_CPF_STALLED_STAT1);
+
+ n_regs = i;
+
+ for (i = 0; i < n_regs; i++)
+ sprintf(reg_dumps + strlen(reg_dumps), "%08x: %08x, ", dump[i][0], dump[i][1]);
+
+ trace_gfx_v10_0_reset_reg_dumps(reg_dumps);
+ kfree(dump);
+ kfree(reg_dumps);
+
+ return 0;
+}
+
static int gfx_v10_0_suspend(void *handle)
{
return gfx_v10_0_hw_fini(handle);
@@ -9367,6 +9415,7 @@ static const struct amd_ip_funcs gfx_v10_0_ip_funcs = {
.set_clockgating_state = gfx_v10_0_set_clockgating_state, .set_powergating_state = gfx_v10_0_set_powergating_state, .get_clockgating_state = gfx_v10_0_get_clockgating_state,
+ .reset_reg_dumps = gfx_v10_0_reset_reg_dumps,
};

static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {

drivers/gpu/drm/amd/include/amd_shared.h +1 -0
index 257f280d3d53..76d3a55278df 100644
@@ -296,6 +296,7 @@ struct amd_ip_funcs {
 				     enum amd_powergating_state state);
 	void (*get_clockgating_state)(void *handle, u32 *flags);
 	int (*enable_umd_pstate)(void *handle, enum amd_dpm_forced_level *level);
+	int (*reset_reg_dumps)(void *handle);
 };
 
 
Signature · 1 line
2.32.0
maintainer
#1 lore raw

Am 21.01.22 um 21:34 schrieb Sharma, Shashank:

Quoted 48 lines

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53 ++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h  |  1 +

 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
                __entry->seqno)
  );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+        TP_PROTO(char *reg_dumps),
+        TP_ARGS(reg_dumps),
+        TP_STRUCT__entry(__string(dumps, reg_dumps)),
+        TP_fast_assign(__assign_str(dumps, reg_dumps);),
+        TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
  #undef AMDGPU_JOB_GET_TIMELINE_NAME
  #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
  #include "v10_structs.h"
  #include "gfx_v10_0.h"
  #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
  /*
   * Navi10 has two graphic rings to share each graphic pipe.
   * 1. Primary ring

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c line 195

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -0
@@ -188,6 +188,12 @@
  #define RLCG_ERROR_REPORT_ENABLED(adev) \
      (amdgpu_sriov_reg_indirect_mmhub(adev) || amdgpu_sriov_reg_indirect_gc(adev))
 
+#define N_REGS (17)
+#define DUMP_REG(addr) do {                    \
+        (dump)[i][0] = (addr);                \
+        (dump)[i++][1] =  RREG32_SOC15_IP(GC, addr);    \
+    } while (0)

Those macros need an AMDGPU_ prefix and maybe some better names.

From the design POV I'm really wondering if it wouldn't be better if userspace defines the registers we want to dump in case of a crash.

Regards,
Christian.

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +44 -1
+
  MODULE_FIRMWARE("amdgpu/navi10_ce.bin");
  MODULE_FIRMWARE("amdgpu/navi10_pfp.bin");
  MODULE_FIRMWARE("amdgpu/navi10_me.bin");
@@ -7488,7 +7494,6 @@ static int gfx_v10_0_hw_init(void *handle)
  {
      int r;
      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
      if (!amdgpu_emu_mode)
          gfx_v10_0_init_golden_registers(adev);
 
@@ -7602,6 +7607,49 @@ static int gfx_v10_0_hw_fini(void *handle)
      return 0;
  }
 
+static int gfx_v10_0_reset_reg_dumps(void *handle)
+{
+    struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+    uint32_t i = 0;
+    uint32_t (*dump)[2], n_regs = 0;
+    char *reg_dumps;
+
+    dump = kmalloc(N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+    reg_dumps = kmalloc(1024, GFP_KERNEL);
+
+    if (dump == NULL || reg_dumps == NULL)
+        return -ENOMEM;
+
+    DUMP_REG(mmGRBM_STATUS2);
+    DUMP_REG(mmGRBM_STATUS_SE0);
+    DUMP_REG(mmGRBM_STATUS_SE1);
+    DUMP_REG(mmGRBM_STATUS_SE2);
+    DUMP_REG(mmGRBM_STATUS_SE3);
+    DUMP_REG(mmSDMA0_STATUS_REG);
+    DUMP_REG(mmSDMA1_STATUS_REG);
+    DUMP_REG(mmCP_STAT);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT3);
+    DUMP_REG(mmCP_CPC_STATUS);
+    DUMP_REG(mmCP_CPC_BUSY_STAT);
+    DUMP_REG(mmCP_CPC_STALLED_STAT1);
+    DUMP_REG(mmCP_CPF_STATUS);
+    DUMP_REG(mmCP_CPF_BUSY_STAT);
+    DUMP_REG(mmCP_CPF_STALLED_STAT1);
+
+    n_regs = i;
+
+    for (i = 0; i < n_regs; i++)
+        sprintf(reg_dumps + strlen(reg_dumps), "%08x: %08x, ", 
 dump[i][0], dump[i][1]);
+
+    trace_gfx_v10_0_reset_reg_dumps(reg_dumps);
+    kfree(dump);
+    kfree(reg_dumps);
+
+    return 0;
+}
+
  static int gfx_v10_0_suspend(void *handle)
  {

     return gfx_v10_0_hw_fini(handle);

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -0
@@ -9367,6 +9415,7 @@ static const struct amd_ip_funcs 
 gfx_v10_0_ip_funcs = {
      .set_clockgating_state = gfx_v10_0_set_clockgating_state,
      .set_powergating_state = gfx_v10_0_set_powergating_state,
      .get_clockgating_state = gfx_v10_0_get_clockgating_state,
+    .reset_reg_dumps = gfx_v10_0_reset_reg_dumps,
  };
 

 static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {

drivers/gpu/drm/amd/include/amd_shared.h +1 -0
index 257f280d3d53..76d3a55278df 100644
@@ -296,6 +296,7 @@ struct amd_ip_funcs {
                       enum amd_powergating_state state);
      void (*get_clockgating_state)(void *handle, u32 *flags);
      int (*enable_umd_pstate)(void *handle, enum amd_dpm_forced_level *level);
+    int (*reset_reg_dumps)(void *handle);
  };
 
 
#2 lore raw

Hello Christian,
Thank for your comments, please fine mine inline:

Quoted 52 lines · Christian König

Am 21.01.22 um 21:34 schrieb Sharma, Shashank:

Quoted 51 lines

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53 ++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h  |  1 +

 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
                __entry->seqno)
  );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+        TP_PROTO(char *reg_dumps),
+        TP_ARGS(reg_dumps),
+        TP_STRUCT__entry(__string(dumps, reg_dumps)),
+        TP_fast_assign(__assign_str(dumps, reg_dumps);),
+        TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
  #undef AMDGPU_JOB_GET_TIMELINE_NAME
  #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
  #include "v10_structs.h"
  #include "gfx_v10_0.h"
  #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
  /*
   * Navi10 has two graphic rings to share each graphic pipe.
   * 1. Primary ring
@@ -188,6 +188,12 @@
  #define RLCG_ERROR_REPORT_ENABLED(adev) \
      (amdgpu_sriov_reg_indirect_mmhub(adev) || amdgpu_sriov_reg_indirect_gc(adev))
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c line 195

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -0
+#define N_REGS (17)
+#define DUMP_REG(addr) do {                    \
+        (dump)[i][0] = (addr);                \
+        (dump)[i++][1] =  RREG32_SOC15_IP(GC, addr);    \
+    } while (0)

Those macros need an AMDGPU_ prefix and maybe some better names.

Agree, @Amar pls check this out.

Quoted 4 lines

From the design POV I'm really wondering if it wouldn't be better if
userspace defines the registers we want to dump in case of a crash.

I am not so sure about it. This means we have to communicate with the userspace and get the list of registers it wishes to see, do I smell a new IOCTL or DRM property ? I also feel that we have better filtering tools for a trace event in userspace than in kernel.

What do you think ?

- Shashank

Quoted 88 lines

Regards,
Christian.

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +44 -1
+
  MODULE_FIRMWARE("amdgpu/navi10_ce.bin");
  MODULE_FIRMWARE("amdgpu/navi10_pfp.bin");
  MODULE_FIRMWARE("amdgpu/navi10_me.bin");
@@ -7488,7 +7494,6 @@ static int gfx_v10_0_hw_init(void *handle)
  {
      int r;
      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
      if (!amdgpu_emu_mode)
          gfx_v10_0_init_golden_registers(adev);
 
@@ -7602,6 +7607,49 @@ static int gfx_v10_0_hw_fini(void *handle)
      return 0;
  }
 
+static int gfx_v10_0_reset_reg_dumps(void *handle)
+{
+    struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+    uint32_t i = 0;
+    uint32_t (*dump)[2], n_regs = 0;
+    char *reg_dumps;
+
+    dump = kmalloc(N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+    reg_dumps = kmalloc(1024, GFP_KERNEL);
+
+    if (dump == NULL || reg_dumps == NULL)
+        return -ENOMEM;
+
+    DUMP_REG(mmGRBM_STATUS2);
+    DUMP_REG(mmGRBM_STATUS_SE0);
+    DUMP_REG(mmGRBM_STATUS_SE1);
+    DUMP_REG(mmGRBM_STATUS_SE2);
+    DUMP_REG(mmGRBM_STATUS_SE3);
+    DUMP_REG(mmSDMA0_STATUS_REG);
+    DUMP_REG(mmSDMA1_STATUS_REG);
+    DUMP_REG(mmCP_STAT);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT3);
+    DUMP_REG(mmCP_CPC_STATUS);
+    DUMP_REG(mmCP_CPC_BUSY_STAT);
+    DUMP_REG(mmCP_CPC_STALLED_STAT1);
+    DUMP_REG(mmCP_CPF_STATUS);
+    DUMP_REG(mmCP_CPF_BUSY_STAT);
+    DUMP_REG(mmCP_CPF_STALLED_STAT1);
+
+    n_regs = i;
+
+    for (i = 0; i < n_regs; i++)
+        sprintf(reg_dumps + strlen(reg_dumps), "%08x: %08x, ", 
 dump[i][0], dump[i][1]);
+
+    trace_gfx_v10_0_reset_reg_dumps(reg_dumps);
+    kfree(dump);
+    kfree(reg_dumps);
+
+    return 0;
+}
+
  static int gfx_v10_0_suspend(void *handle)
  {

     return gfx_v10_0_hw_fini(handle);

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -0
@@ -9367,6 +9415,7 @@ static const struct amd_ip_funcs 
 gfx_v10_0_ip_funcs = {
      .set_clockgating_state = gfx_v10_0_set_clockgating_state,
      .set_powergating_state = gfx_v10_0_set_powergating_state,
      .get_clockgating_state = gfx_v10_0_get_clockgating_state,
+    .reset_reg_dumps = gfx_v10_0_reset_reg_dumps,
  };
 

 static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {

drivers/gpu/drm/amd/include/amd_shared.h +1 -0
index 257f280d3d53..76d3a55278df 100644
@@ -296,6 +296,7 @@ struct amd_ip_funcs {
                       enum amd_powergating_state state);
      void (*get_clockgating_state)(void *handle, u32 *flags);
      int (*enable_umd_pstate)(void *handle, enum amd_dpm_forced_level *level);
+    int (*reset_reg_dumps)(void *handle);
  };
 
 
maintainer
#3 lore raw

Am 24.01.22 um 17:45 schrieb Sharma, Shashank:

Quoted 64 lines

Hello Christian,
Thank for your comments, please fine mine inline:

Quoted 52 lines · Christian König

Am 21.01.22 um 21:34 schrieb Sharma, Shashank:

Quoted 51 lines

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53 ++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h  |  1 +

 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
                __entry->seqno)
  );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+        TP_PROTO(char *reg_dumps),
+        TP_ARGS(reg_dumps),
+        TP_STRUCT__entry(__string(dumps, reg_dumps)),
+        TP_fast_assign(__assign_str(dumps, reg_dumps);),
+        TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
  #undef AMDGPU_JOB_GET_TIMELINE_NAME
  #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
  #include "v10_structs.h"
  #include "gfx_v10_0.h"
  #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
  /*
   * Navi10 has two graphic rings to share each graphic pipe.
   * 1. Primary ring
@@ -188,6 +188,12 @@
  #define RLCG_ERROR_REPORT_ENABLED(adev) \
      (amdgpu_sriov_reg_indirect_mmhub(adev) || amdgpu_sriov_reg_indirect_gc(adev))
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c line 195

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -0
+#define N_REGS (17)
+#define DUMP_REG(addr) do {                    \
+        (dump)[i][0] = (addr);                \
+        (dump)[i++][1] =  RREG32_SOC15_IP(GC, addr);    \
+    } while (0)

Those macros need an AMDGPU_ prefix and maybe some better names.

Quoted 8 lines

Agree, @Amar pls check this out.

Quoted 3 lines

 From the design POV I'm really wondering if it wouldn't be better if userspace defines the registers we want to dump in case of a crash.

I am not so sure about it. This means we have to communicate with the userspace and get the list of registers it wishes to see, do I smell a new IOCTL or DRM property ? I also feel that we have better filtering tools for a trace event in userspace than in kernel.

What do you think ?

Just a writeable debugfs file should probably do it. We have a list of known registers filled in during boot (just reg offsets) and userspace can read/write the file to update it.

Christian.

Quoted 91 lines

- Shashank

Quoted 88 lines

Regards,
Christian.

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +44 -1
+
  MODULE_FIRMWARE("amdgpu/navi10_ce.bin");
  MODULE_FIRMWARE("amdgpu/navi10_pfp.bin");
  MODULE_FIRMWARE("amdgpu/navi10_me.bin");
@@ -7488,7 +7494,6 @@ static int gfx_v10_0_hw_init(void *handle)
  {
      int r;
      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
      if (!amdgpu_emu_mode)
          gfx_v10_0_init_golden_registers(adev);
 
@@ -7602,6 +7607,49 @@ static int gfx_v10_0_hw_fini(void *handle)
      return 0;
  }
 
+static int gfx_v10_0_reset_reg_dumps(void *handle)
+{
+    struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+    uint32_t i = 0;
+    uint32_t (*dump)[2], n_regs = 0;
+    char *reg_dumps;
+
+    dump = kmalloc(N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+    reg_dumps = kmalloc(1024, GFP_KERNEL);
+
+    if (dump == NULL || reg_dumps == NULL)
+        return -ENOMEM;
+
+    DUMP_REG(mmGRBM_STATUS2);
+    DUMP_REG(mmGRBM_STATUS_SE0);
+    DUMP_REG(mmGRBM_STATUS_SE1);
+    DUMP_REG(mmGRBM_STATUS_SE2);
+    DUMP_REG(mmGRBM_STATUS_SE3);
+    DUMP_REG(mmSDMA0_STATUS_REG);
+    DUMP_REG(mmSDMA1_STATUS_REG);
+    DUMP_REG(mmCP_STAT);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT3);
+    DUMP_REG(mmCP_CPC_STATUS);
+    DUMP_REG(mmCP_CPC_BUSY_STAT);
+    DUMP_REG(mmCP_CPC_STALLED_STAT1);
+    DUMP_REG(mmCP_CPF_STATUS);
+    DUMP_REG(mmCP_CPF_BUSY_STAT);
+    DUMP_REG(mmCP_CPF_STALLED_STAT1);
+
+    n_regs = i;
+
+    for (i = 0; i < n_regs; i++)
+        sprintf(reg_dumps + strlen(reg_dumps), "%08x: %08x, ", 
 dump[i][0], dump[i][1]);
+
+    trace_gfx_v10_0_reset_reg_dumps(reg_dumps);
+    kfree(dump);
+    kfree(reg_dumps);
+
+    return 0;
+}
+
  static int gfx_v10_0_suspend(void *handle)
  {

     return gfx_v10_0_hw_fini(handle);

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -0
@@ -9367,6 +9415,7 @@ static const struct amd_ip_funcs 
 gfx_v10_0_ip_funcs = {
      .set_clockgating_state = gfx_v10_0_set_clockgating_state,
      .set_powergating_state = gfx_v10_0_set_powergating_state,
      .get_clockgating_state = gfx_v10_0_get_clockgating_state,
+    .reset_reg_dumps = gfx_v10_0_reset_reg_dumps,
  };
 

 static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {

drivers/gpu/drm/amd/include/amd_shared.h +1 -0
index 257f280d3d53..76d3a55278df 100644
@@ -296,6 +296,7 @@ struct amd_ip_funcs {
                       enum amd_powergating_state state);
      void (*get_clockgating_state)(void *handle, u32 *flags);
      int (*enable_umd_pstate)(void *handle, enum amd_dpm_forced_level *level);
+    int (*reset_reg_dumps)(void *handle);
  };
 
 
#4 lore raw
Quoted 67 lines · Christian König

Am 24.01.22 um 17:45 schrieb Sharma, Shashank:

Quoted 66 lines

Hello Christian,
Thank for your comments, please fine mine inline:

Quoted 52 lines · Christian König

Am 21.01.22 um 21:34 schrieb Sharma, Shashank:

Quoted 51 lines

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53 ++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h  |  1 +

 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
                __entry->seqno)
  );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+        TP_PROTO(char *reg_dumps),
+        TP_ARGS(reg_dumps),
+        TP_STRUCT__entry(__string(dumps, reg_dumps)),
+        TP_fast_assign(__assign_str(dumps, reg_dumps);),
+        TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
  #undef AMDGPU_JOB_GET_TIMELINE_NAME
  #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
  #include "v10_structs.h"
  #include "gfx_v10_0.h"
  #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
  /*
   * Navi10 has two graphic rings to share each graphic pipe.
   * 1. Primary ring
@@ -188,6 +188,12 @@
  #define RLCG_ERROR_REPORT_ENABLED(adev) \
      (amdgpu_sriov_reg_indirect_mmhub(adev) || amdgpu_sriov_reg_indirect_gc(adev))
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c line 195

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -0
+#define N_REGS (17)
+#define DUMP_REG(addr) do {                    \
+        (dump)[i][0] = (addr);                \
+        (dump)[i++][1] =  RREG32_SOC15_IP(GC, addr);    \
+    } while (0)

Those macros need an AMDGPU_ prefix and maybe some better names.

Agree, @Amar pls check this out.

Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

 From the design POV I'm really wondering if it wouldn't be better if userspace defines the registers we want to dump in case of a crash.

I am not so sure about it. This means we have to communicate with the userspace and get the list of registers it wishes to see, do I smell a new IOCTL or DRM property ? I also feel that we have better filtering tools for a trace event in userspace than in kernel.

What do you think ?

Just a writeable debugfs file should probably do it. We have a list of known registers filled in during boot (just reg offsets) and userspace can read/write the file to update it.

Ok, so in this case, what would be our state machine ?
1. gpu_reset happened
2. uevent_sent from work queue
3. userspace goes and writes into debugfs files
4. kernel collects the desired register values

5 (a). kernel send the trace_event with desired values 6 (a). kernel sends another uevent to indicate trace_event

Or

5 (a+b). kernel loads the reg values via debugfs itself.

In both of these case, wouldn't it be too late to collect register values by the time userspace list arrives at kernel ?

Or do you have a better state machine in mind ?

- Shashank

Quoted 94 lines

Christian.

Quoted 91 lines

- Shashank

Quoted 88 lines

Regards,
Christian.

Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +44 -1
+
  MODULE_FIRMWARE("amdgpu/navi10_ce.bin");
  MODULE_FIRMWARE("amdgpu/navi10_pfp.bin");
  MODULE_FIRMWARE("amdgpu/navi10_me.bin");
@@ -7488,7 +7494,6 @@ static int gfx_v10_0_hw_init(void *handle)
  {
      int r;
      struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
      if (!amdgpu_emu_mode)
          gfx_v10_0_init_golden_registers(adev);
 
@@ -7602,6 +7607,49 @@ static int gfx_v10_0_hw_fini(void *handle)
      return 0;
  }
 
+static int gfx_v10_0_reset_reg_dumps(void *handle)
+{
+    struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+    uint32_t i = 0;
+    uint32_t (*dump)[2], n_regs = 0;
+    char *reg_dumps;
+
+    dump = kmalloc(N_REGS*2*sizeof(uint32_t), GFP_KERNEL);
+    reg_dumps = kmalloc(1024, GFP_KERNEL);
+
+    if (dump == NULL || reg_dumps == NULL)
+        return -ENOMEM;
+
+    DUMP_REG(mmGRBM_STATUS2);
+    DUMP_REG(mmGRBM_STATUS_SE0);
+    DUMP_REG(mmGRBM_STATUS_SE1);
+    DUMP_REG(mmGRBM_STATUS_SE2);
+    DUMP_REG(mmGRBM_STATUS_SE3);
+    DUMP_REG(mmSDMA0_STATUS_REG);
+    DUMP_REG(mmSDMA1_STATUS_REG);
+    DUMP_REG(mmCP_STAT);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT1);
+    DUMP_REG(mmCP_STALLED_STAT3);
+    DUMP_REG(mmCP_CPC_STATUS);
+    DUMP_REG(mmCP_CPC_BUSY_STAT);
+    DUMP_REG(mmCP_CPC_STALLED_STAT1);
+    DUMP_REG(mmCP_CPF_STATUS);
+    DUMP_REG(mmCP_CPF_BUSY_STAT);
+    DUMP_REG(mmCP_CPF_STALLED_STAT1);
+
+    n_regs = i;
+
+    for (i = 0; i < n_regs; i++)
+        sprintf(reg_dumps + strlen(reg_dumps), "%08x: %08x, ", 
 dump[i][0], dump[i][1]);
+
+    trace_gfx_v10_0_reset_reg_dumps(reg_dumps);
+    kfree(dump);
+    kfree(reg_dumps);
+
+    return 0;
+}
+
  static int gfx_v10_0_suspend(void *handle)
  {

     return gfx_v10_0_hw_fini(handle);

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -0
@@ -9367,6 +9415,7 @@ static const struct amd_ip_funcs 
 gfx_v10_0_ip_funcs = {
      .set_clockgating_state = gfx_v10_0_set_clockgating_state,
      .set_powergating_state = gfx_v10_0_set_powergating_state,
      .get_clockgating_state = gfx_v10_0_get_clockgating_state,
+    .reset_reg_dumps = gfx_v10_0_reset_reg_dumps,
  };
 

 static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {

drivers/gpu/drm/amd/include/amd_shared.h +1 -0
index 257f280d3d53..76d3a55278df 100644
@@ -296,6 +296,7 @@ struct amd_ip_funcs {
                       enum amd_powergating_state state);
      void (*get_clockgating_state)(void *handle, u32 *flags);
      int (*enable_umd_pstate)(void *handle, enum amd_dpm_forced_level *level);
+    int (*reset_reg_dumps)(void *handle);
  };
 
 
maintainer
#5 lore raw

Am 24.01.22 um 18:00 schrieb Sharma, Shashank:

Quoted 90 lines · Christian König
Quoted 68 lines

Am 24.01.22 um 17:45 schrieb Sharma, Shashank:

Quoted 67 lines

Hello Christian,
Thank for your comments, please fine mine inline:

Quoted 53 lines · Christian König

Am 21.01.22 um 21:34 schrieb Sharma, Shashank:

Quoted 52 lines

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53
++++++++++++++++++++++-
 drivers/gpu/drm/amd/include/amd_shared.h  |  1 +

 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
                __entry->seqno)
  );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+        TP_PROTO(char *reg_dumps),
+        TP_ARGS(reg_dumps),
+        TP_STRUCT__entry(__string(dumps, reg_dumps)),
+        TP_fast_assign(__assign_str(dumps, reg_dumps);),
+        TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
  #undef AMDGPU_JOB_GET_TIMELINE_NAME
  #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
  #include "v10_structs.h"
  #include "gfx_v10_0.h"
  #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
  /*
   * Navi10 has two graphic rings to share each graphic pipe.
   * 1. Primary ring
@@ -188,6 +188,12 @@
  #define RLCG_ERROR_REPORT_ENABLED(adev) \
      (amdgpu_sriov_reg_indirect_mmhub(adev) || amdgpu_sriov_reg_indirect_gc(adev))
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c line 195

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -0
+#define N_REGS (17)
+#define DUMP_REG(addr) do {                    \
+        (dump)[i][0] = (addr);                \
+        (dump)[i++][1] =  RREG32_SOC15_IP(GC, addr);    \
+    } while (0)

Those macros need an AMDGPU_ prefix and maybe some better names.

Agree, @Amar pls check this out.

Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

 From the design POV I'm really wondering if it wouldn't be better if userspace defines the registers we want to dump in case of a crash.

I am not so sure about it. This means we have to communicate with the userspace and get the list of registers it wishes to see, do I smell a new IOCTL or DRM property ? I also feel that we have better filtering tools for a trace event in userspace than in kernel.

What do you think ?

Just a writeable debugfs file should probably do it. We have a list of known registers filled in during boot (just reg offsets) and userspace can read/write the file to update it.

Ok, so in this case, what would be our state machine ?
1. gpu_reset happened
2. uevent_sent from work queue
3. userspace goes and writes into debugfs files
4. kernel collects the desired register values

5 (a). kernel send the trace_event with desired values 6 (a). kernel sends another uevent to indicate trace_event

Quoted 7 lines

Or

5 (a+b). kernel loads the reg values via debugfs itself.

In both of these case, wouldn't it be too late to collect register values by the time userspace list arrives at kernel ?

Or do you have a better state machine in mind ?

1. system boots, kernel loads a default register list to dump.
2. Userspace optionally updates this register list.
....
3. GPU reset happens, we dump the registers into the trace log.
4. We send udev event to signal the GPU reset to umr or other tool to save and store the trace log.

Regards,
Christian.

#6 lore raw
Quoted 99 lines · Christian König

Am 24.01.22 um 18:00 schrieb Sharma, Shashank:

Quoted 96 lines · Christian König
Quoted 68 lines

Am 24.01.22 um 17:45 schrieb Sharma, Shashank:

Quoted 67 lines

Hello Christian,
Thank for your comments, please fine mine inline:

Quoted 53 lines · Christian König

Am 21.01.22 um 21:34 schrieb Sharma, Shashank:

Quoted 52 lines

From 1c5c552eeddaffd9fb3e7d45ece1b2b28fccc575 Mon Sep 17 00:00:00 2001
From: Somalapuram Amaranath <[email protected]>
Date: Fri, 21 Jan 2022 14:19:10 +0530
Subject: [PATCH 3/4] drm/amdgpu: add reset register trace dump function for gfx_v10_0

Implementation of register trace dump function on the AMD GPU resets

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h |  8 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c    | 53
++++++++++++++++++++++-
 drivers/gpu/drm/amd/include/amd_shared.h  |  1 +

 3 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +8 -0
index d855cb53c7e0..c97b53b54333 100644
@@ -537,6 +537,14 @@ TRACE_EVENT(amdgpu_ib_pipe_sync,
                __entry->seqno)
  );
 
+TRACE_EVENT(gfx_v10_0_reset_reg_dumps,
+        TP_PROTO(char *reg_dumps),
+        TP_ARGS(reg_dumps),
+        TP_STRUCT__entry(__string(dumps, reg_dumps)),
+        TP_fast_assign(__assign_str(dumps, reg_dumps);),
+        TP_printk("amdgpu register dump {%s}", __get_str(dumps))
+);
+
  #undef AMDGPU_JOB_GET_TIMELINE_NAME
  #endif
 
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 16dbe593cba2..05974ed5416d 100644
@@ -46,7 +46,7 @@
  #include "v10_structs.h"
  #include "gfx_v10_0.h"
  #include "nbio_v2_3.h"
-
+#include "amdgpu_trace.h"
  /*
   * Navi10 has two graphic rings to share each graphic pipe.
   * 1. Primary ring
@@ -188,6 +188,12 @@
  #define RLCG_ERROR_REPORT_ENABLED(adev) \
      (amdgpu_sriov_reg_indirect_mmhub(adev) || amdgpu_sriov_reg_indirect_gc(adev))
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c line 195

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -0
+#define N_REGS (17)
+#define DUMP_REG(addr) do {                    \
+        (dump)[i][0] = (addr);                \
+        (dump)[i++][1] =  RREG32_SOC15_IP(GC, addr);    \
+    } while (0)

Those macros need an AMDGPU_ prefix and maybe some better names.

Agree, @Amar pls check this out.

Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

 From the design POV I'm really wondering if it wouldn't be better if userspace defines the registers we want to dump in case of a crash.

I am not so sure about it. This means we have to communicate with the userspace and get the list of registers it wishes to see, do I smell a new IOCTL or DRM property ? I also feel that we have better filtering tools for a trace event in userspace than in kernel.

What do you think ?

Just a writeable debugfs file should probably do it. We have a list of known registers filled in during boot (just reg offsets) and userspace can read/write the file to update it.

Ok, so in this case, what would be our state machine ?
1. gpu_reset happened
2. uevent_sent from work queue
3. userspace goes and writes into debugfs files
4. kernel collects the desired register values

5 (a). kernel send the trace_event with desired values 6 (a). kernel sends another uevent to indicate trace_event

Or

5 (a+b). kernel loads the reg values via debugfs itself.

In both of these case, wouldn't it be too late to collect register values by the time userspace list arrives at kernel ?

Quoted 8 lines
Quoted 1 line

Or do you have a better state machine in mind ?

1. system boots, kernel loads a default register list to dump.
2. Userspace optionally updates this register list.
....
3. GPU reset happens, we dump the registers into the trace log.
4. We send udev event to signal the GPU reset to umr or other tool to save and store the trace log.

Got it, let us rework in those lines.
- Shashank

Quoted 2 lines

Regards,
Christian.