Skip to contentSkip to conversation

util/log: Add vu to dump content of vector unit

PATCH In review Kito Cheng 4 participants 5 messages Jul 8, 2022 – Jul 11, 2022 RISC-V

lore
Share & tools
lore

Kito Cheng

author
#0 lore raw

PATCH 1/2 util/log: Add vu to dump content of vector unit

Add new option for -d vu to dump the content of vector unit, many target has vector register, but there is no easy way to dump the content, we use this on downstream for a while to help debug, and I feel that's really useful, so I think it would be great to upstream that to save debug time for other people :)

---
 accel/tcg/cpu-exec.c  | 3 +++
 include/hw/core/cpu.h | 2 ++
 include/qemu/log.h    | 1 +
 util/log.c            | 2 ++
 4 files changed, 8 insertions(+)
accel/tcg/cpu-exec.c +3 -0
index a565a3f8ec..2cbec0a6ed 100644
@@ -221,6 +221,9 @@ static inline void log_cpu_exec(target_ulong pc, CPUState *cpu,
                 if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) {
                     flags |= CPU_DUMP_FPU;
                 }
+                if (qemu_loglevel_mask(CPU_LOG_TB_VU)) {
+                    flags |= CPU_DUMP_VU;
+                }
 #if defined(TARGET_I386)
                 flags |= CPU_DUMP_CCOP;
 #endif
include/hw/core/cpu.h +2 -0
index 996f94059f..7a767e17cd 100644
@@ -535,11 +535,13 @@ GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
  * @CPU_DUMP_CODE:
  * @CPU_DUMP_FPU: dump FPU register state, not just integer
  * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
+ * @CPU_DUMP_VU: dump vector register state
  */
 enum CPUDumpFlags {
     CPU_DUMP_CODE = 0x00010000,
     CPU_DUMP_FPU  = 0x00020000,
     CPU_DUMP_CCOP = 0x00040000,
+    CPU_DUMP_VU   = 0x00080000,
 };
 
 /**
include/qemu/log.h +1 -0
index c5643d8dd5..49bd0b0fbc 100644
@@ -35,6 +35,7 @@ bool qemu_log_separate(void);
 /* LOG_STRACE is used for user-mode strace logging. */
 #define LOG_STRACE         (1 << 19)
 #define LOG_PER_THREAD     (1 << 20)
+#define CPU_LOG_TB_VU      (1 << 21)
 
 /* Lock/unlock output. */
 
util/log.c +2 -0
index d6eb0378c3..775d122c2e 100644
@@ -441,6 +441,8 @@ const QEMULogItem qemu_log_items[] = {
 #ifdef CONFIG_PLUGIN
     { CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
 #endif
+    { CPU_LOG_TB_VU, "vu",
+      "include vector unit registers in the 'cpu' logging" },
     { LOG_STRACE, "strace",
       "log every user-mode syscall, its input, and its result" },
     { LOG_PER_THREAD, "tid",
Signature · 1 line
2.34.0
author
#1 lore raw

PATCH 2/2 target/riscv: Implement dump content of vector register

Implement -d cpu,vu to dump content of vector register.

---
 target/riscv/cpu.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
target/riscv/cpu.c +31 -0
index c1b96da7da..97b289d277 100644
@@ -72,6 +72,15 @@ const char * const riscv_fpr_regnames[] = {
   "f30/ft10", "f31/ft11"
 };
 
+const char * const riscv_vr_regnames[] = {
+  "v0",  "v1",  "v2",  "v3",  "v4",  "v5",
+  "v6",  "v7",  "v8",  "v9",  "v10", "v11",
+  "v12", "v13", "v14", "v15", "v16", "v17",
+  "v18", "v19", "v20", "v21", "v22", "v23",
+  "v24", "v25", "v26", "v27", "v28", "v29",
+  "v30", "v31"
+};
+
 static const char * const riscv_excp_names[] = {
     "misaligned_fetch",
     "fault_fetch",
@@ -375,6 +384,28 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
             }
         }
     }
+    if (flags & CPU_DUMP_VU) {
+        int vlen = cpu->cfg.vlen;
+        int n_chunk = vlen / 64;
+        if (vlen == 32) {
+            for (i = 0; i < 32; i++) {
+                qemu_fprintf(f, "0x%08" PRIx64 "\n", env->vreg[i]);
+            }
+        } else {
+            for (i = 0; i < 32; i++) {
+                qemu_fprintf(f, " %-8s ",
+                             riscv_vr_regnames[i]);
+
+                int vec_reg_offset = i * vlen / 64;
+                qemu_fprintf(f, "0x");
+                for (int j = n_chunk - 1; j >= 0; --j) {
+                    qemu_fprintf(f, "%016" PRIx64,
+                                 env->vreg[vec_reg_offset + j]);
+                }
+                qemu_fprintf(f, "\n");
+            }
+        }
+    }
 }
 
 static void riscv_cpu_set_pc(CPUState *cs, vaddr value)
Signature · 1 line
2.34.0
#2 lore raw

Re: [PATCH 2/2] target/riscv: Implement dump content of vector register

Quoted 28 lines · Kito Cheng

Implement -d cpu,vu to dump content of vector register.

---
  target/riscv/cpu.c | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
target/riscv/cpu.c +9 -0
index c1b96da7da..97b289d277 100644
@@ -72,6 +72,15 @@ const char * const riscv_fpr_regnames[] = {
    "f30/ft10", "f31/ft11"
  };
 
+const char * const riscv_vr_regnames[] = {
+  "v0",  "v1",  "v2",  "v3",  "v4",  "v5",
+  "v6",  "v7",  "v8",  "v9",  "v10", "v11",
+  "v12", "v13", "v14", "v15", "v16", "v17",
+  "v18", "v19", "v20", "v21", "v22", "v23",
+  "v24", "v25", "v26", "v27", "v28", "v29",
+  "v30", "v31"
+};
+
  static const char * const riscv_excp_names[] = {
      "misaligned_fetch",
      "fault_fetch",

target/riscv/cpu.c static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 393

Quoted 10 lines
target/riscv/cpu.c +7 -0
@@ -375,6 +384,28 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
              }
          }
      }
+    if (flags & CPU_DUMP_VU) {
+        int vlen = cpu->cfg.vlen;
+        int n_chunk = vlen / 64;
+        if (vlen == 32) {
+            for (i = 0; i < 32; i++) {
+                qemu_fprintf(f, "0x%08" PRIx64 "\n", env->vreg[i]);
+            }

Seems forget to dump the riscv_vr_regnames here.

Just another question: whether is it necessary to dump the vector related csrs too?

Regards,

Weiwei Li

Quoted 18 lines
target/riscv/cpu.c +15 -0
+        } else {
+            for (i = 0; i < 32; i++) {
+                qemu_fprintf(f, " %-8s ",
+                             riscv_vr_regnames[i]);
+
+                int vec_reg_offset = i * vlen / 64;
+                qemu_fprintf(f, "0x");
+                for (int j = n_chunk - 1; j >= 0; --j) {
+                    qemu_fprintf(f, "%016" PRIx64,
+                                 env->vreg[vec_reg_offset + j]);
+                }
+                qemu_fprintf(f, "\n");
+            }
+        }
+    }
  }
 
  static void riscv_cpu_set_pc(CPUState *cs, vaddr value)
Reviewed-by on v1 1/2
#3 lore raw
In reply to Kito Cheng
Quoted 76 lines · Kito Cheng

Add new option for -d vu to dump the content of vector unit, many target has vector register, but there is no easy way to dump the content, we use this on downstream for a while to help debug, and I feel that's really useful, so I think it would be great to upstream that to save debug time
for other people :)

---
 accel/tcg/cpu-exec.c  | 3 +++
 include/hw/core/cpu.h | 2 ++
 include/qemu/log.h    | 1 +
 util/log.c            | 2 ++
 4 files changed, 8 insertions(+)
accel/tcg/cpu-exec.c +3 -0
index a565a3f8ec..2cbec0a6ed 100644
@@ -221,6 +221,9 @@ static inline void log_cpu_exec(target_ulong pc,
 CPUState *cpu,
                 if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) {
                     flags |= CPU_DUMP_FPU;
                 }
+                if (qemu_loglevel_mask(CPU_LOG_TB_VU)) {
+                    flags |= CPU_DUMP_VU;
+                }
 #if defined(TARGET_I386)
                 flags |= CPU_DUMP_CCOP;

#endif

include/hw/core/cpu.h +0 -0
index 996f94059f..7a767e17cd 100644
@@ -535,11 +535,13 @@ GuestPanicInformation *cpu_get_crash_info(CPUState
 *cpu);
  * @CPU_DUMP_CODE:
  * @CPU_DUMP_FPU: dump FPU register state, not just integer
  * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization

state
+ * @CPU_DUMP_VU: dump vector register state
*/

 enum CPUDumpFlags {
     CPU_DUMP_CODE = 0x00010000,
     CPU_DUMP_FPU  = 0x00020000,
     CPU_DUMP_CCOP = 0x00040000,
include/hw/core/cpu.h +1 -0
+    CPU_DUMP_VU   = 0x00080000,
 };
 
 /**
include/qemu/log.h +1 -0
index c5643d8dd5..49bd0b0fbc 100644
@@ -35,6 +35,7 @@ bool qemu_log_separate(void);
 /* LOG_STRACE is used for user-mode strace logging. */
 #define LOG_STRACE         (1 << 19)
 #define LOG_PER_THREAD     (1 << 20)
+#define CPU_LOG_TB_VU      (1 << 21)
 
 /* Lock/unlock output. */
 
util/log.c +2 -1
index d6eb0378c3..775d122c2e 100644
@@ -441,6 +441,8 @@ const QEMULogItem qemu_log_items[] = {
 #ifdef CONFIG_PLUGIN
     { CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
 #endif
+    { CPU_LOG_TB_VU, "vu",
+      "include vector unit registers in the 'cpu' logging" },
     { LOG_STRACE, "strace",
       "log every user-mode syscall, its input, and its result" },
     { LOG_PER_THREAD, "tid",
--
Quoted 3 lines

2.34.0

#4 lore raw
In reply to Kito Cheng
Quoted 72 lines · Kito Cheng

Add new option for -d vu to dump the content of vector unit, many target has vector register, but there is no easy way to dump the content, we use this on downstream for a while to help debug, and I feel that's really useful, so I think it would be great to upstream that to save debug time for other people :)

---
  accel/tcg/cpu-exec.c  | 3 +++
  include/hw/core/cpu.h | 2 ++
  include/qemu/log.h    | 1 +
  util/log.c            | 2 ++
  4 files changed, 8 insertions(+)
accel/tcg/cpu-exec.c +3 -0
index a565a3f8ec..2cbec0a6ed 100644
@@ -221,6 +221,9 @@ static inline void log_cpu_exec(target_ulong pc, CPUState *cpu,
                  if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) {
                      flags |= CPU_DUMP_FPU;
                  }
+                if (qemu_loglevel_mask(CPU_LOG_TB_VU)) {
+                    flags |= CPU_DUMP_VU;
+                }
  #if defined(TARGET_I386)
                  flags |= CPU_DUMP_CCOP;
  #endif
include/hw/core/cpu.h +2 -0
index 996f94059f..7a767e17cd 100644
@@ -535,11 +535,13 @@ GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
   * @CPU_DUMP_CODE:
   * @CPU_DUMP_FPU: dump FPU register state, not just integer
   * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
+ * @CPU_DUMP_VU: dump vector register state
   */
  enum CPUDumpFlags {
      CPU_DUMP_CODE = 0x00010000,
      CPU_DUMP_FPU  = 0x00020000,
      CPU_DUMP_CCOP = 0x00040000,
+    CPU_DUMP_VU   = 0x00080000,
  };
 
  /**
include/qemu/log.h +1 -0
index c5643d8dd5..49bd0b0fbc 100644
@@ -35,6 +35,7 @@ bool qemu_log_separate(void);
  /* LOG_STRACE is used for user-mode strace logging. */
  #define LOG_STRACE         (1 << 19)
  #define LOG_PER_THREAD     (1 << 20)
+#define CPU_LOG_TB_VU      (1 << 21)
 
  /* Lock/unlock output. */
 
util/log.c +2 -1
index d6eb0378c3..775d122c2e 100644
@@ -441,6 +441,8 @@ const QEMULogItem qemu_log_items[] = {
  #ifdef CONFIG_PLUGIN
      { CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
  #endif
+    { CPU_LOG_TB_VU, "vu",
+      "include vector unit registers in the 'cpu' logging" },
      { LOG_STRACE, "strace",
        "log every user-mode syscall, its input, and its result" },
      { LOG_PER_THREAD, "tid",
--
Quoted 3 lines

2.34.0

I think this looks like a good idea, can see myself using it. I see a lot of places in the code where cpu_dump_state() is used with CPU_DUMP_FPU flag as a parameter. Do you think it is also the case to add this new flag CPU_DUMP_VU there too?

Best regards,

Signature · 3 lines
Víctor Cora Colombo
Instituto de Pesquisas ELDORADO
Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>