hppa CPU reset and speedup
v3 cover hppa CPU reset and speedup
Respin of:
https://lore.kernel.org/qemu-devel/[email protected]/
"Add CPU reset function and speed up runtime and translation."
- Remove hppa_cpu_init()
- Reset PSW using M bit (untested)
Helge, could we add a functional test booting Linux?
Helge Deller (4):
target/hppa: Convert hppa_cpu_init() to ResetHold handler hw/hppa: Reset vCPUs calling resettable_reset() target/hppa: Set PC on vCPU reset
target/hppa: Speed up hppa_is_pa20()
Philippe Mathieu-Daudé (1):
target/hppa: Only set PSW 'M' bit on reset
target/hppa/cpu.h | 11 +++++++++-- hw/hppa/machine.c | 6 +++--- target/hppa/cpu.c | 20 +++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-)
Signature · 1 line
2.47.1
PATCH v3 1/5 target/hppa: Convert hppa_cpu_init() to ResetHold handler
From: Helge Deller <[email protected]>
hppa_cpu_initfn() is called once when a HPPA CPU instance is initialized, but it sets fields which should be set each time a CPU resets. Rename it as a reset handler, having it matching the ResettablePhases::hold() signature, and register it as ResettableClass handler.
Since on reset the CPU registers and TLB entries are expected to be zero, add a memset() call clearing CPUHPPAState up to the &end_reset_fields marker.
--- target/hppa/cpu.h | 5 +++++ target/hppa/cpu.c | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
target/hppa/cpu.h +5 -0
@@ -263,6 +263,9 @@ typedef struct CPUArchState {IntervalTreeRoot tlb_root;HPPATLBEntry tlb[HPPA_TLB_ENTRIES ]; + +/* Fields up to this point are cleared by a CPU reset */ +struct {} end_reset_fields; } CPUHPPAState;/**
@@ -281,6 +284,7 @@ struct ArchCPU {/** * HPPACPUClass: * @parent_realize: The parent class' realize handler. +* @parent_phases: The parent class' reset phase handlers. * * An HPPA CPU model. */
@@ -288,6 +292,7 @@ struct HPPACPUClass {CPUClass parent_class;DeviceRealize parent_realize; +ResettablePhases parent_phases; };#include "exec/cpu-all.h"
target/hppa/cpu.c +12 -2
@@ -193,13 +193,20 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)tcg_cflags_set (cs,CF_PCREL ); } -static void hppa_cpu_initfn (Object *obj) +static void hppa_cpu_reset_hold (Object *obj,ResetType type) { +HPPACPUClass *scc =HPPA_CPU_GET_CLASS (obj);CPUState *cs =CPU (obj);HPPACPU *cpu =HPPA_CPU (obj);CPUHPPAState *env = &cpu->env; +if (scc->parent_phases.hold) { + scc->parent_phases.hold (obj, type); + } cs->exception_index =-1 ; + +memset (env,0 , offsetof(CPUHPPAState , end_reset_fields)); +cpu_hppa_loaded_fr0 (env);cpu_hppa_put_psw (env,PSW_W ); }
@@ -242,10 +249,14 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc);CPUClass *cc =CPU_CLASS (oc);HPPACPUClass *acc =HPPA_CPU_CLASS (oc); +ResettableClass *rc =RESETTABLE_CLASS (oc);device_class_set_parent_realize (dc, hppa_cpu_realizefn, &acc->parent_realize); +resettable_class_set_parent_phases (rc,NULL , hppa_cpu_reset_hold,NULL , + &acc->parent_phases); + cc->class_by_name = hppa_cpu_class_by_name; cc->has_work = hppa_cpu_has_work; cc->mmu_index = hppa_cpu_mmu_index;
@@ -269,7 +280,6 @@ static const TypeInfo hppa_cpu_type_infos[] = { .parent = TYPE_CPU, .instance_size = sizeof(HPPACPU), .instance_align = __alignof(HPPACPU), - .instance_init = hppa_cpu_initfn, .abstract = false, .class_size = sizeof(HPPACPUClass), .class_init = hppa_cpu_class_init,
Signature · 1 line
2.47.1
PATCH v3 2/5 hw/hppa: Reset vCPUs calling resettable_reset()
In reply to Philippe Mathieu-DaudéFrom: Helge Deller <[email protected]>
Rather than manually (and incompletely) resetting vCPUs, call resettable_reset() which will fully reset the vCPUs. Remove redundant assignations.
--- hw/hppa/machine.c | 6 +++--- target/hppa/cpu.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-)
hw/hppa/machine.c +3 -3
@@ -655,12 +655,12 @@ static void hppa_machine_reset(MachineState *ms, ResetType type)for (i =0 ; i < smp_cpus; i++) {CPUState *cs =CPU (cpu[i]); +/* reset CPU */ +resettable_reset (OBJECT (cs),RESET_TYPE_COLD ); +cpu_set_pc (cs, firmware_entry); cpu[i]->env.psw =PSW_Q ; cpu[i]->env.gr[5 ] =CPU_HPA + i *0x1000 ; - - cs->exception_index =-1 ; - cs->halted =0 ; }/* already initialized by machine_hppa_init()? */
target/hppa/cpu.c +1 -0
@@ -204,6 +204,7 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type) scc->parent_phases.hold (obj, type); } cs->exception_index =-1 ; + cs->halted =0 ;memset (env,0 , offsetof(CPUHPPAState , end_reset_fields));
Signature · 1 line
2.47.1
PATCH v3 3/5 target/hppa: Only set PSW 'M' bit on reset
In reply to Philippe Mathieu-DaudéOn reset:
"All PSW bits except the M bit is reset. The M bit is set."
Commit 1a19da0da44 ("target/hppa: Fill in hppa_cpu_do_interrupt / hppa_cpu_exec_interrupt") inadvertently set the W bit at RESET, remove it and set the M bit.
---
Only tested using QEMU mainstream test suite, IOW not much.
--- target/hppa/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/cpu.c +1 -1
@@ -209,7 +209,7 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type)memset (env,0 , offsetof(CPUHPPAState , end_reset_fields));cpu_hppa_loaded_fr0 (env); -cpu_hppa_put_psw (env,PSW_W ); +cpu_hppa_put_psw (env,PSW_M ); }static ObjectClass *hppa_cpu_class_by_name (const char *cpu_model)
Signature · 1 line
2.47.1
PATCH v3 4/5 target/hppa: Set PC on vCPU reset
In reply to Philippe Mathieu-DaudéFrom: Helge Deller <[email protected]>
On reset:
"The CPU begins fetching instructions from address 0xf0000004.
This address is in PDC space."
Switch vCPUs to 32-bit mode (PSW_W bit is not set) and start execution at address 0xf0000004.
--- target/hppa/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/hppa/cpu.c +1 -0
@@ -205,6 +205,7 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type) } cs->exception_index =-1 ; cs->halted =0 ; +cpu_set_pc (cs,0xf0000004 );memset (env,0 , offsetof(CPUHPPAState , end_reset_fields));
Signature · 1 line
2.47.1
PATCH v3 5/5 target/hppa: Speed up hppa_is_pa20()
In reply to Philippe Mathieu-DaudéFrom: Helge Deller <[email protected]>
Although the hppa_is_pa20() helper is costly due to string comparisons in object_dynamic_cast(), it is called quite often during memory lookups and at each start of a block of instruction translations. Speed hppa_is_pa20() up by calling object_dynamic_cast() only once at CPU creation and store the result in the is_pa20 of struct CPUArchState.
--- target/hppa/cpu.h | 6 ++++-- target/hppa/cpu.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-)
target/hppa/cpu.h +4 -2
@@ -266,6 +266,8 @@ typedef struct CPUArchState {/* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields; + +bool is_pa20; } CPUHPPAState;/**
@@ -297,9 +299,9 @@ struct HPPACPUClass {#include "exec/cpu-all.h" -static inline bool hppa_is_pa20 (CPUHPPAState *env) +static inline bool hppa_is_pa20 (const CPUHPPAState *env) { -return object_dynamic_cast (OBJECT (env_cpu (env)),TYPE_HPPA64_CPU ) !=NULL ; +return env->is_pa20; }static inline int HPPA_BTLB_ENTRIES (CPUHPPAState *env)
target/hppa/cpu.c +2 -0
@@ -209,6 +209,8 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type)memset (env,0 , offsetof(CPUHPPAState , end_reset_fields)); + env->is_pa20 = !!object_dynamic_cast (obj,TYPE_HPPA64_CPU ); +cpu_hppa_loaded_fr0 (env);cpu_hppa_put_psw (env,PSW_M ); }
Signature · 1 line
2.47.1
Hi Philippe,
Quoted 5 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/[email protected]/
"Add CPU reset function and speed up runtime and translation."- Remove
hppa_cpu_init()
Thanks for picking up my patches and integrating them properly with the reset code.
But sadly your changes somehow break hppa 64-bit CPU support. I think it's to when the reset code is called.
Easy reproducer (no other options/disc/network needed):
./qemu-system-hppa -smp cpus=4 -nographic -machine C3700
Quoted 1 line
- Reset PSW using M bit (untested)
We haven't implemented PSW-M support and the first thing the firmware does is to reprogram PSW. So, basically it's not needed.
Quoted 1 line
Helge, could we add a functional test booting Linux?
What exactly are you looking for?
Some trivial preinstalled disc image with kernels? Any examples?
Helge
Quoted 14 lines
Helge Deller (4):
target/hppa: Converthppa_cpu_init()to ResetHold handler hw/hppa: Reset vCPUs callingresettable_reset()target/hppa: Set PC on vCPU reset
target/hppa: Speed uphppa_is_pa20()Philippe Mathieu-Daudé (1):
target/hppa: Only set PSW 'M' bit on resettarget/hppa/cpu.h | 11 +++++++++-- hw/hppa/machine.c | 6 +++--- target/hppa/cpu.c | 20 +++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-)
Quoted 9 lines · Helge Deller
Hi Philippe,
Quoted 5 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."- Remove
hppa_cpu_init()
Quoted 7 lines
Thanks for picking up my patches and integrating them properly with the reset code.
But sadly your changes somehow break hppa 64-bit CPU support. I think it's to when the reset code is called.Easy reproducer (no other options/disc/network needed):
./qemu-system-hppa -smp cpus=4 -nographic -machine C3700
[*]
Quoted 7 lines
Quoted 2 lines
- Reset PSW using M bit (untested)
We haven't implemented PSW-M support and the first thing the firmware does is to reprogram PSW. So, basically it's not needed.
Quoted 5 lines
Quoted 1 line
Helge, could we add a functional test booting Linux?
What exactly are you looking for?
Some trivial preinstalled disc image with kernels? Any examples?
Your [*] example running SeaBIOS is perfect.
See tests/functional/test_riscv_opensbi.py, but using:
wait_for_console_pattern('SeaBIOS PA-RISC 64-bit Firmware')
Quoted 18 lines
Helge
Quoted 14 lines
Helge Deller (4):
target/hppa: Converthppa_cpu_init()to ResetHold handler hw/hppa: Reset vCPUs callingresettable_reset()target/hppa: Set PC on vCPU reset
target/hppa: Speed uphppa_is_pa20()Philippe Mathieu-Daudé (1):
target/hppa: Only set PSW 'M' bit on resettarget/hppa/cpu.h | 11 +++++++++-- hw/hppa/machine.c | 6 +++--- target/hppa/cpu.c | 20 +++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-)
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Helge Deller
Hi Philippe,
Quoted 5 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."- Remove
hppa_cpu_init()Quoted 7 lines
Thanks for picking up my patches and integrating them properly with the reset code.
But sadly your changes somehow break hppa 64-bit CPU support. I think it's to when the reset code is called.Easy reproducer (no other options/disc/network needed):
./qemu-system-hppa -smp cpus=4 -nographic -machine C3700[*]
Quoted 7 lines
Quoted 2 lines
- Reset PSW using M bit (untested)
We haven't implemented PSW-M support and the first thing the firmware does is to reprogram PSW. So, basically it's not needed.
Quoted 5 lines
Quoted 1 line
Helge, could we add a functional test booting Linux?
What exactly are you looking for?
Some trivial preinstalled disc image with kernels? Any examples?
Quoted 5 lines
Your [*] example running SeaBIOS is perfect.
See
tests/functional/test_riscv_opensbi.py, but using:
wait_for_console_pattern('SeaBIOS PA-RISC 64-bit Firmware')
Then I suggest 2 testcases (32-bit and 64-bit CPU, dropped SMP flag):
./qemu-system-hppa -nographic -machine B160L ./qemu-system-hppa -nographic -machine C3700
Helge
Quoted 20 lines
Quoted 19 lines
Helge
Quoted 14 lines
Helge Deller (4):
target/hppa: Converthppa_cpu_init()to ResetHold handler hw/hppa: Reset vCPUs callingresettable_reset()target/hppa: Set PC on vCPU reset
target/hppa: Speed uphppa_is_pa20()Philippe Mathieu-Daudé (1):
target/hppa: Only set PSW 'M' bit on resettarget/hppa/cpu.h | 11 +++++++++-- hw/hppa/machine.c | 6 +++--- target/hppa/cpu.c | 20 +++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-)
Quoted 7 lines · Helge Deller
Hi Philippe,
Quoted 4 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."
Quoted 6 lines
Quoted 1 line
- Remove
hppa_cpu_init()Thanks for picking up my patches and integrating them properly with the reset code.
But sadly your changes somehow break hppa 64-bit CPU support. I think it's to when the reset code is called.
Likely hppa_is_pa20() called *before* CPU reset...?
Quoted 3 lines
Easy reproducer (no other options/disc/network needed):
./qemu-system-hppa -smp cpus=4 -nographic -machine C3700
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Helge Deller
Hi Philippe,
Quoted 4 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
- Remove
hppa_cpu_init()Thanks for picking up my patches and integrating them properly with the reset code.
But sadly your changes somehow break hppa 64-bit CPU support. I think it's to when the reset code is called.Likely
hppa_is_pa20()called *before* CPU reset...?
Indeed:
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.10
* frame #0: 0x000000010024df30 qemu-system-hppa`hppa_ptlbe [inlined]hppa_is_pa20(env=0x000000011f822230) at cpu.h:304:17
frame #1: 0x000000010024df30 qemu-system-hppa`hppa_ptlbe [inlined]
HPPA_BTLB_ENTRIES(env=0x000000011f822230) at cpu.h:309:12
frame #2: 0x000000010024df30
qemu-system-hppa`hppa_ptlbe(env=0x000000011f822230) at mem_helper.c:642:29
frame #3: 0x0000000100250564
qemu-system-hppa`hppa_cpu_realizefn(dev=0x000000011f81fa00, errp=<unavailable>) at cpu.c:188:9
frame #4: 0x00000001002f812c qemu-system-hppa`device_set_realized(obj=<unavailable>, value=<unavailable>, errp=0x000000016fdfebc0) at qdev.c:495:13
Quoted 4 lines
Quoted 4 lines
Easy reproducer (no other options/disc/network needed):
./qemu-system-hppa -smp cpus=4 -nographic -machine C3700
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Helge Deller
Hi Philippe,
Quoted 4 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."Quoted 8 lines
Quoted 6 lines
Quoted 1 line
- Remove
hppa_cpu_init()Thanks for picking up my patches and integrating them properly with the reset code.
But sadly your changes somehow break hppa 64-bit CPU support. I think it's to when the reset code is called.Likely
hppa_is_pa20()called *before* CPU reset...?Indeed:
Quoted 12 lines
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.10
* frame #0:0x000000010024df30qemu-system-hppa`hppa_ptlbe [inlined]hppa_is_pa20(env=0x000000011f822230)at cpu.h:304:17
frame #1:0x000000010024df30qemu-system-hppa`hppa_ptlbe [inlined]HPPA_BTLB_ENTRIES(env=0x000000011f822230)at cpu.h:309:12
frame #2:0x000000010024df30qemu-system-
hppa`hppa_ptlbe(env=0x000000011f822230) at mem_helper.c:642:29
frame #3:0x0000000100250564qemu-system-
hppa`hppa_cpu_realizefn(dev=0x000000011f81fa00, errp=<unavailable>) at cpu.c:188:9
frame #4:0x00000001002f812cqemu-system-
hppa`device_set_realized(obj=<unavailable>, value=<unavailable>, errp=0x000000016fdfebc0) at qdev.c:495:13
Assigning is_pa20 in instance_init() fixes it:
-- >8 --
target/hppa/cpu.c +8 -2
@@ -193,6 +193,13 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)tcg_cflags_set (cs,CF_PCREL ); } +static void hppa_cpu_initfn (Object *obj) +{ +CPUHPPAState *env =cpu_env (CPU (obj)); + + env->is_pa20 = !!object_dynamic_cast (obj,TYPE_HPPA64_CPU ); +} +static void hppa_cpu_reset_hold (Object *obj,ResetType type) {HPPACPUClass *scc =HPPA_CPU_GET_CLASS (obj);
@@ -209,8 +216,6 @@ static void hppa_cpu_reset_hold(Object *obj, ResetType type)memset (env,0 , offsetof(CPUHPPAState , end_reset_fields)); - env->is_pa20 = !!object_dynamic_cast (obj,TYPE_HPPA64_CPU ); -cpu_hppa_loaded_fr0 (env);cpu_hppa_put_psw (env,PSW_M ); }
@@ -284,6 +289,7 @@ static const TypeInfo hppa_cpu_type_infos[] = { .parent = TYPE_CPU, .instance_size = sizeof(HPPACPU), .instance_align = __alignof(HPPACPU), + .instance_init = hppa_cpu_initfn, .abstract = false, .class_size = sizeof(HPPACPUClass), .class_init = hppa_cpu_class_init,
---
Quoted 13 lines · Helge Deller
Hi Philippe,
Quoted 5 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."- Remove
hppa_cpu_init()Thanks for picking up my patches and integrating them properly with the reset code.
Quoted 5 lines
Quoted 1 line
- Reset PSW using M bit (untested)
We haven't implemented PSW-M support and the first thing the firmware does is to reprogram PSW. So, basically it's not needed.
Good to know it isn't needed yet (I grepped and noticed very few uses). Are you OK with the patch as is (as it matches the spec)?
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Helge Deller
Hi Philippe,
Quoted 5 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."- Remove
hppa_cpu_init()Thanks for picking up my patches and integrating them properly with the reset code.
Quoted 1 line
- Reset PSW using M bit (untested)
Quoted 7 lines
Quoted 3 lines
We haven't implemented PSW-M support and the first thing the firmware does is to reprogram PSW. So, basically it's not needed.
Good to know it isn't needed yet (I grepped and noticed very few uses). Are you OK with the patch as is (as it matches the spec)?
At least I don't have any objections as long as 32- and 64-bit CPUs still boot.
Will you respin the series, then I can test and review?
Helge
Quoted 21 lines · Helge Deller
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Helge Deller
Hi Philippe,
Quoted 5 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/20241229234154.32250-1- [email protected]/ "Add CPU reset function and speed up runtime and translation."- Remove
hppa_cpu_init()Thanks for picking up my patches and integrating them properly with the reset code.
Quoted 1 line
- Reset PSW using M bit (untested)
We haven't implemented PSW-M support and the first thing the firmware does is to reprogram PSW. So, basically it's not needed.
Quoted 8 lines
Quoted 3 lines
Good to know it isn't needed yet (I grepped and noticed very few uses). Are you OK with the patch as is (as it matches the spec)?
At least I don't have any objections as long as 32- and 64-bit CPUs still boot.
Will you respin the series, then I can test and review?
OK!