cpus: Avoid re-initializing fields cleared in cpu_common_reset_hold()
cover cpus: Avoid re-initializing fields cleared in cpu_common_reset_hold()
Having this call tree:
cpu_reset()
-> device_cold_reset()
-> DeviceClass::reset()
-> target_cpu_reset()
-> ResettablePhases::hold()
-> CPUClass::phases::hold()
-> cpu_common_reset_hold()If we call cpu_reset(), common fields will be reset in cpu_common_reset_hold(), we don't need to manually do it.
Remove the pointless re-assignments on CPUState.
Based-on: <[email protected]>
Philippe Mathieu-Daudé (3):
accel/tcg: Remove pointless initialization of cflags_next_tb target/cpus: Remove pointless re-assignment of
CPUState::exception_index
target/cpus: Remove pointless re-assignment of CPUState::halted
hw/core/cpu-common.c | 1 - hw/misc/mips_cpc.c | 1 - hw/ppc/e500.c | 1 - target/arm/arm-powerctl.c | 2 -- target/hppa/cpu.c | 2 -- target/loongarch/cpu.c | 1 - target/openrisc/cpu.c | 1 - 7 files changed, 9 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/3 accel/tcg: Remove pointless initialization of cflags_next_tb
cflags_next_tb is always re-initialized in the CPU Reset() handler in cpu_common_reset_hold(), no need to initialize it in cpu_common_initfn().
Message-Id: <[email protected]>
--- hw/core/cpu-common.c | 1 - 1 file changed, 1 deletion(-)
hw/core/cpu-common.c +0 -1
@@ -245,7 +245,6 @@ static void cpu_common_initfn(Object *obj)/* the default value is changed by qemu_init_vcpu() for system-mode */ cpu->nr_cores =1 ; cpu->nr_threads =1 ; - cpu->cflags_next_tb =-1 ;/* allocate storage for thread info, initialise condition variables */ cpu->thread =g_new0 (QemuThread,1 );
Signature · 1 line
2.47.1
PATCH 2/3 target/cpus: Remove pointless re-assignment of CPUState::exception_index
In reply to Philippe Mathieu-DaudéThe CPUState::exception_index field is always re-initialized by the parent CPU ResetHold() handler in cpu_common_reset_hold(), no need to have targets manually initializing it.
--- target/hppa/cpu.c | 1 - target/loongarch/cpu.c | 1 - target/openrisc/cpu.c | 1 - 3 files changed, 3 deletions(-)
target/hppa/cpu.c +0 -1
@@ -203,7 +203,6 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type)if (scc->parent_phases.hold) { scc->parent_phases.hold (obj, type); } - cs->exception_index =-1 ; cs->halted =0 ;cpu_set_pc (cs,0xf0000004 );
target/loongarch/cpu.c +0 -1
@@ -584,7 +584,6 @@ static void loongarch_cpu_reset_hold(Object *obj, ResetType type)#ifdef CONFIG_TCG restore_fp_status (env);#endif - cs->exception_index =-1 ; }static void loongarch_cpu_disas_set_info (CPUState *s,disassemble_info *info)
target/openrisc/cpu.c +0 -1
@@ -101,7 +101,6 @@ static void openrisc_cpu_reset_hold(Object *obj, ResetType type) cpu->env.pc =0x100 ; cpu->env.sr =SR_FO |SR_SM ; cpu->env.lock_addr =-1 ; - cs->exception_index =-1 ;cpu_set_fpcsr (&cpu->env,0 ); set_float_detect_tininess(float_tininess_before_rounding,
Signature · 1 line
2.47.1
Re: [PATCH 2/3] target/cpus: Remove pointless re-assignment of CPUState::exception_index
Quoted 10 lines · Philippe Mathieu-Daudé
TheCPUState::exception_indexfield is always re-initialized by the parent CPUResetHold()handler incpu_common_reset_hold(), no need to have targets manually initializing it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/hppa/cpu.c | 1 - target/loongarch/cpu.c | 1 - target/openrisc/cpu.c | 1 - 3 files changed, 3 deletions(-)
r~
PATCH 3/3 target/cpus: Remove pointless re-assignment of CPUState::halted
In reply to Philippe Mathieu-DaudéThe CPUState::halted field is always re-initialized in cpu_common_reset_hold(), itself called by cpu_reset(). No need to have targets manually initializing it.
--- hw/misc/mips_cpc.c | 1 - hw/ppc/e500.c | 1 - target/arm/arm-powerctl.c | 2 -- target/hppa/cpu.c | 1 - 4 files changed, 5 deletions(-)
hw/misc/mips_cpc.c +0 -1
@@ -38,7 +38,6 @@ static void mips_cpu_reset_async_work(CPUState *cs, run_on_cpu_data data)MIPSCPCState *cpc = (MIPSCPCState *) data.host_ptr;cpu_reset (cs); - cs->halted =0 ; cpc->vp_running |=1ULL << cs->cpu_index; }
hw/ppc/e500.c +0 -1
@@ -785,7 +785,6 @@ static void ppce500_cpu_reset(void *opaque)cpu_reset (cs);/* Set initial guest state. */ - cs->halted =0 ; env->gpr[1 ] = (16 * MiB) -8 ; env->gpr[3 ] = bi->dt_base; env->gpr[4 ] =0 ;
target/arm/arm-powerctl.c +0 -2
@@ -67,7 +67,6 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state);arm_emulate_firmware_reset (target_cpu_state, info->target_el); - target_cpu_state->halted =0 ;/* We check if the started CPU is now at the correct level */ assert (info->target_el ==arm_current_el (&target_cpu->env));
@@ -194,7 +193,6 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state); - target_cpu_state->halted =0 ;/* Finally set the power status */ assert (bql_locked ());
target/hppa/cpu.c +0 -1
@@ -203,7 +203,6 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type)if (scc->parent_phases.hold) { scc->parent_phases.hold (obj, type); } - cs->halted =0 ;cpu_set_pc (cs,0xf0000004 );memset (env,0 , offsetof(CPUHPPAState , end_reset_fields));
Signature · 1 line
2.47.1
Re: [PATCH 3/3] target/cpus: Remove pointless re-assignment of CPUState::halted
Am 30. Dezember 2024 15:39:29 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 29 lines
The
CPUState::haltedfield is always re-initialized incpu_common_reset_hold(), itself called bycpu_reset(). No need to have targets manually initializing it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/misc/mips_cpc.c | 1 - hw/ppc/e500.c | 1 - target/arm/arm-powerctl.c | 2 -- target/hppa/cpu.c | 1 - 4 files changed, 5 deletions(-)hw/misc/mips_cpc.c +0
-1@@ -38,7 +38,6 @@ static void mips_cpu_reset_async_work(CPUState *cs, run_on_cpu_data data)MIPSCPCState *cpc = (MIPSCPCState *) data.host_ptr;cpu_reset (cs); - cs->halted =0 ; cpc->vp_running |=1ULL << cs->cpu_index; }hw/ppc/e500.c +0
-0
hw/ppc/e500.c static void ppce500_cpu_reset(void *opaque) · line 790
Quoted 7 lines
hw/ppc/e500.c +0
-1@@ -785,7 +785,6 @@ static void ppce500_cpu_reset(void *opaque)cpu_reset (cs);/* Set initial guest state. */ - cs->halted =0 ; env->gpr[1 ] = (16 * MiB) -8 ; env->gpr[3 ] = bi->dt_base; env->gpr[4 ] =0 ;
For e500:
Quoted 32 lines
target/arm/arm-powerctl.c +0
-2@@ -67,7 +67,6 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state);arm_emulate_firmware_reset (target_cpu_state, info->target_el); - target_cpu_state->halted =0 ;/* We check if the started CPU is now at the correct level */ assert (info->target_el ==arm_current_el (&target_cpu->env));@@ -194,7 +193,6 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state); - target_cpu_state->halted =0 ;/* Finally set the power status */ assert (bql_locked ());target/hppa/cpu.c +0
-1@@ -203,7 +203,6 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type)if (scc->parent_phases.hold) { scc->parent_phases.hold (obj, type); } - cs->halted =0 ;cpu_set_pc (cs,0xf0000004 );memset (env,0 , offsetof(CPUHPPAState , end_reset_fields));
Re: [PATCH 3/3] target/cpus: Remove pointless re-assignment of CPUState::halted
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
The
CPUState::haltedfield is always re-initialized incpu_common_reset_hold(), itself called bycpu_reset(). No need to have targets manually initializing it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/misc/mips_cpc.c | 1 - hw/ppc/e500.c | 1 - target/arm/arm-powerctl.c | 2 -- target/hppa/cpu.c | 1 - 4 files changed, 5 deletions(-)
This is a behavior change if cpu->start_powered_off.
I think it's likely that "start powered off' should not apply to warm reset, and that otherwise this change is ok. But I think there's that nit to address first.
r~
Quoted 10 lines · Philippe Mathieu-Daudé
Having this call tree:
cpu_reset() -> device_cold_reset() -> DeviceClass::reset() -> target_cpu_reset() -> ResettablePhases::hold() -> CPUClass::phases::hold() -> cpu_common_reset_hold()
Quoted 4 lines
If we call
cpu_reset(), common fields will be reset incpu_common_reset_hold(), we don't need to manually do it.Remove the pointless re-assignments on CPUState.
Ping for patches 2 & 3?