[PATCH 2/2] hw/core: Use qemu_log_trylock/unlock in cpu_common_reset_exit

Richard Henderson posted 2 patches 1 month ago
Maintainers: Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>
[PATCH 2/2] hw/core: Use qemu_log_trylock/unlock in cpu_common_reset_exit
Posted by Richard Henderson 1 month ago
Ensure that the "CPU Reset" message won't be separated
from the cpu_dump_state output.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 hw/core/cpu-common.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 26321be785..259cf2a3c3 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -135,10 +135,15 @@ static void cpu_common_reset_hold(Object *obj, ResetType type)
 static void cpu_common_reset_exit(Object *obj, ResetType type)
 {
     if (qemu_loglevel_mask(CPU_LOG_RESET)) {
-        CPUState *cpu = CPU(obj);
+        FILE *f = qemu_log_trylock();
 
-        qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
-        log_cpu_state(cpu, cpu->cc->reset_dump_flags);
+        if (f) {
+            CPUState *cpu = CPU(obj);
+
+            fprintf(f, "CPU Reset (CPU %d)\n", cpu->cpu_index);
+            cpu_dump_state(cpu, f, cpu->cc->reset_dump_flags);
+            qemu_log_unlock(f);
+        }
     }
 }
 
-- 
2.43.0
Re: [PATCH 2/2] hw/core: Use qemu_log_trylock/unlock in cpu_common_reset_exit
Posted by Philippe Mathieu-Daudé 1 month ago
On 27/8/25 07:38, Richard Henderson wrote:
> Ensure that the "CPU Reset" message won't be separated
> from the cpu_dump_state output.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   hw/core/cpu-common.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH 2/2] hw/core: Use qemu_log_trylock/unlock in cpu_common_reset_exit
Posted by Peter Maydell 1 month ago
On Wed, 27 Aug 2025 at 06:39, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Ensure that the "CPU Reset" message won't be separated
> from the cpu_dump_state output.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  hw/core/cpu-common.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index 26321be785..259cf2a3c3 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -135,10 +135,15 @@ static void cpu_common_reset_hold(Object *obj, ResetType type)
>  static void cpu_common_reset_exit(Object *obj, ResetType type)
>  {
>      if (qemu_loglevel_mask(CPU_LOG_RESET)) {
> -        CPUState *cpu = CPU(obj);
> +        FILE *f = qemu_log_trylock();
>
> -        qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
> -        log_cpu_state(cpu, cpu->cc->reset_dump_flags);
> +        if (f) {
> +            CPUState *cpu = CPU(obj);
> +
> +            fprintf(f, "CPU Reset (CPU %d)\n", cpu->cpu_index);
> +            cpu_dump_state(cpu, f, cpu->cc->reset_dump_flags);
> +            qemu_log_unlock(f);
> +        }
>      }
>  }

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM