Skip to contentSkip to conversation

hw/core: Move hw_error() out of cpus.c

PATCH Superseded Philippe Mathieu-Daudé 3 participants 11 messages Sep 1, 2020 – Sep 2, 2020 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hw/core: Move hw_error() out of cpus.c

Move hw_error() out of cpus.c because we already have cpu_abort() there.

Philippe Mathieu-Daudé (2):
cpus: Do not dump CPU state when calling hw_error() hw/core: Move hw_error() out of cpus.c

 hw/core/error.c     | 38 ++++++++++++++++++++++++++++++++++++++
 softmmu/cpus.c      | 17 -----------------
 hw/core/meson.build |  1 +
 3 files changed, 39 insertions(+), 17 deletions(-)
 create mode 100644 hw/core/error.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 cpus: Do not dump CPU state when calling hw_error()

We already have cpu_abort() to dump CPU states and abort.

Restrict hw_error() to peripheral errors, hoping we can completely remove it by proper functions from "error-report.h" in the future.

---
 softmmu/cpus.c | 5 -----
 1 file changed, 5 deletions(-)
softmmu/cpus.c +0 -5
index a802e899abb..c96a04d7f18 100644
@@ -913,16 +913,11 @@ static void stop_tcg_kick_timer(void)
 void hw_error(const char *fmt, ...)
 {
     va_list ap;
-    CPUState *cpu;
 
     va_start(ap, fmt);
     fprintf(stderr, "qemu: hardware error: ");
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
-    CPU_FOREACH(cpu) {
-        fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
-        cpu_dump_state(cpu, stderr, CPU_DUMP_FPU);
-    }
     va_end(ap);
     abort();
 }
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 1/2] cpus: Do not dump CPU state when calling hw_error()

Quoted 6 lines · Philippe Mathieu-Daudé

We already have cpu_abort() to dump CPU states and abort.

Restrict hw_error() to peripheral errors, hoping we can completely remove it by proper functions from "error-report.h" in the future.

IIRC I rather suggested to rename the function to "cpu_hw_error" and only use it for real CPU problems...
But I think your approach here is fine as well. Please replace the "Suggested-by" with "Reviewed-by" now :-)

Thomas

Quoted 13 lines
---
 softmmu/cpus.c | 5 -----
 1 file changed, 5 deletions(-)
softmmu/cpus.c +0 -0
index a802e899abb..c96a04d7f18 100644
@@ -913,16 +913,11 @@ static void stop_tcg_kick_timer(void)
 void hw_error(const char *fmt, ...)
 {
     va_list ap;

softmmu/cpus.c static void stop_tcg_kick_timer(void) · line 925

Quoted 10 lines
softmmu/cpus.c +0 -5
-    CPUState *cpu;
 
     va_start(ap, fmt);
     fprintf(stderr, "qemu: hardware error: ");
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
-    CPU_FOREACH(cpu) {
-        fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
-        cpu_dump_state(cpu, stderr, CPU_DUMP_FPU);
-    }

You could argue that cpu_abort() only prints the state of one CPU and not of all. But I doubt that dumping the state of *all* CPUs is really helpful in any of the contexts where hw_error() is used. So I think it's fine to remove this CPU_FOREACH loop here.

Quoted 4 lines
softmmu/cpus.c +0 -0
     va_end(ap);
     abort();
 }
#3 lore raw

Re: [PATCH 1/2] cpus: Do not dump CPU state when calling hw_error()

Quoted 31 lines · Thomas Huth
Quoted 6 lines · Philippe Mathieu-Daudé

We already have cpu_abort() to dump CPU states and abort.

Restrict hw_error() to peripheral errors, hoping we can completely remove it by proper functions from "error-report.h" in the future.

IIRC I rather suggested to rename the function to "cpu_hw_error" and only use it for real CPU problems...
But I think your approach here is fine as well. Please replace the "Suggested-by" with "Reviewed-by" now :-)

Thomas

Quoted 15 lines
---
 softmmu/cpus.c | 5 -----
 1 file changed, 5 deletions(-)
softmmu/cpus.c +0 -1
index a802e899abb..c96a04d7f18 100644
@@ -913,16 +913,11 @@ static void stop_tcg_kick_timer(void)
 void hw_error(const char *fmt, ...)
 {
     va_list ap;
-    CPUState *cpu;
 
Quoted 13 lines

softmmu/cpus.c static void stop_tcg_kick_timer(void) · line 925

Quoted 8 lines
softmmu/cpus.c +0 -4
     va_start(ap, fmt);
     fprintf(stderr, "qemu: hardware error: ");
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
-    CPU_FOREACH(cpu) {
-        fprintf(stderr, "CPU #%d:\n", cpu->cpu_index);
-        cpu_dump_state(cpu, stderr, CPU_DUMP_FPU);
-    }

You could argue that cpu_abort() only prints the state of one CPU and not of all. But I doubt that dumping the state of *all* CPUs is really helpful in any of the contexts where hw_error() is used. So I think it's fine to remove this CPU_FOREACH loop here.

I find this not very practical when using more than 8 vCPUs. Personally I stopped looking at this output because it is too noisy.

Are there developers interested in having cpu_abort() dumping all vCPU registers? I can move that there. Or the interested ones can also do it later if they find it useful :)

Quoted 7 lines
Quoted 5 lines
softmmu/cpus.c +0 -0
     va_end(ap);
     abort();
 }
#4 lore raw

PATCH 2/2 hw/core: Move hw_error() out of cpus.c

In reply to Philippe Mathieu-Daudé

As hw_error() is unrelated to CPU error - for which we have cpu_abort() - move it out of cpus.c, under the hw/ directory.

---
Couldn't find better file/name to put it in...

---
 hw/core/error.c     | 38 ++++++++++++++++++++++++++++++++++++++
 softmmu/cpus.c      | 12 ------------
 hw/core/meson.build |  1 +
 3 files changed, 39 insertions(+), 12 deletions(-)
 create mode 100644 hw/core/error.c
hw/core/error.c new file +38 -0
new file mode 100644
index 00000000000..5a783c82dff
@@ -0,0 +1,38 @@
+/*
+ * Peripheral error reporting
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+
+void hw_error(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    fprintf(stderr, "qemu: hardware error: ");
+    vfprintf(stderr, fmt, ap);
+    fprintf(stderr, "\n");
+    va_end(ap);
+    abort();
+}
softmmu/cpus.c +0 -12
index c96a04d7f18..eca57c76c9b 100644
@@ -59,7 +59,6 @@
 #include "sysemu/replay.h"
 #include "sysemu/runstate.h"
 #include "hw/boards.h"
-#include "hw/hw.h"
 
 #include "sysemu/cpu-throttle.h"
 
@@ -910,17 +909,6 @@ static void stop_tcg_kick_timer(void)
 }
 
 /***********************************************************/
-void hw_error(const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    fprintf(stderr, "qemu: hardware error: ");
-    vfprintf(stderr, fmt, ap);
-    fprintf(stderr, "\n");
-    va_end(ap);
-    abort();
-}
 
 void cpu_synchronize_all_states(void)
 {
hw/core/meson.build +1 -0
index fc91f980758..99466dc93fd 100644
@@ -1,6 +1,7 @@
 # core qdev-related obj files, also used by *-user and unit tests
 hwcore_files = files(
   'bus.c',
+  'error.c',
   'fw-path-provider.c',
   'hotplug.c',
   'qdev-properties.c',
Signature · 1 line
2.26.2
Reviewed-by on v1 2/2
#5 lore raw
Quoted 93 lines · Philippe Mathieu-Daudé

As hw_error() is unrelated to CPU error - for which we have cpu_abort() - move it out of cpus.c, under the hw/ directory.

---
Couldn't find better file/name to put it in...

---
 hw/core/error.c     | 38 ++++++++++++++++++++++++++++++++++++++
 softmmu/cpus.c      | 12 ------------
 hw/core/meson.build |  1 +
 3 files changed, 39 insertions(+), 12 deletions(-)
 create mode 100644 hw/core/error.c
hw/core/error.c new file +38 -0
new file mode 100644
index 00000000000..5a783c82dff
@@ -0,0 +1,38 @@
+/*
+ * Peripheral error reporting
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hw.h"
+
+void hw_error(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    fprintf(stderr, "qemu: hardware error: ");
+    vfprintf(stderr, fmt, ap);
+    fprintf(stderr, "\n");
+    va_end(ap);
+    abort();
+}
softmmu/cpus.c +0 -12
index c96a04d7f18..eca57c76c9b 100644
@@ -59,7 +59,6 @@
 #include "sysemu/replay.h"
 #include "sysemu/runstate.h"
 #include "hw/boards.h"
-#include "hw/hw.h"
 
 #include "sysemu/cpu-throttle.h"
 
@@ -910,17 +909,6 @@ static void stop_tcg_kick_timer(void)
 }
 
 /***********************************************************/
-void hw_error(const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    fprintf(stderr, "qemu: hardware error: ");
-    vfprintf(stderr, fmt, ap);
-    fprintf(stderr, "\n");
-    va_end(ap);
-    abort();
-}
 
 void cpu_synchronize_all_states(void)
 {
hw/core/meson.build +0 -0
index fc91f980758..99466dc93fd 100644

hw/core/meson.build line 7

Quoted 7 lines
hw/core/meson.build +1 -0
@@ -1,6 +1,7 @@
 # core qdev-related obj files, also used by *-user and unit tests
 hwcore_files = files(
   'bus.c',
+  'error.c',
   'fw-path-provider.c',
   'hotplug.c',
   'qdev-properties.c',

Alternative ideas:

- Move the function as "static inline" into the header file instead - it's not so big, so an inline function should be ok here.

- Add a big fat warning comment to the header that this function should not be used for new code anymore.

Thomas

#6 lore raw
Quoted 3 lines · Thomas Huth

- Move the function as "static inline" into the header file instead - it's not so big, so an inline function should be ok here.

stdarg and inline do not mix.

Quoted 2 lines

- Add a big fat warning comment to the header that this function should not be used for new code anymore.

But certainly this.

r~

#7 lore raw
Quoted 11 lines · Richard Henderson
Quoted 3 lines · Thomas Huth

- Move the function as "static inline" into the header file instead - it's not so big, so an inline function should be ok here.

stdarg and inline do not mix.

Quoted 2 lines

- Add a big fat warning comment to the header that this function should not be used for new code anymore.

But certainly this.

Will do, but this has been proven to not work well...

Quoted 4 lines

r~

#8 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Richard Henderson
Quoted 3 lines · Thomas Huth

- Move the function as "static inline" into the header file instead - it's not so big, so an inline function should be ok here.

Quoted 8 lines
Quoted 6 lines

stdarg and inline do not mix.

Quoted 2 lines

- Add a big fat warning comment to the header that this function should not be used for new code anymore.

But certainly this.

Will do, but this has been proven to not work well...

... or add a warning to checkpatch.pl ?

Thomas

#9 lore raw
Quoted 9 lines · Thomas Huth
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson
Quoted 3 lines · Thomas Huth

- Move the function as "static inline" into the header file instead - it's not so big, so an inline function should be ok here.

stdarg and inline do not mix.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

- Add a big fat warning comment to the header that this function should not be used for new code anymore.

But certainly this.

Will do, but this has been proven to not work well...

... or add a warning to checkpatch.pl ?

This certainly works better :)

Quoted 4 lines

Thomas