hppa CPU reset and speedup
v4 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."
Since v3:
- Added tests, dropped R-b tags
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é (2):
tests: Add functional tests for HPPA machines
target/hppa: Only set PSW 'M' bit on reset
MAINTAINERS | 1 + target/hppa/cpu.h | 11 +++++++-- hw/hppa/machine.c | 6 ++--- target/hppa/cpu.c | 22 ++++++++++++++++- tests/functional/meson.build | 4 +++ tests/functional/test_hppa_seabios.py | 35 +++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 6 deletions(-) create mode 100755 tests/functional/test_hppa_seabios.py
Signature · 1 line
2.47.1
PATCH v4 1/6 tests: Add functional tests for HPPA machines
Add quick firmware boot tests (less than 1sec) for the B160L (32-bit) and C3700 (64-bit) HPPA machines:
$ make check-functional-hppa 1/4 qemu:func-quick+func-hppa / func-hppa-empty_cpu_model OK 0.13s 1 subtests passed 2/4 qemu:func-quick+func-hppa / func-hppa-version OK 0.14s 1 subtests passed 3/4 qemu:func-quick+func-hppa / func-hppa-info_usernet OK 0.22s 1 subtests passed 4/4 qemu:func-quick+func-hppa / func-hppa-hppa_seabios OK 0.22s 2 subtests passed
--- MAINTAINERS | 1 + tests/functional/meson.build | 4 +++ tests/functional/test_hppa_seabios.py | 35 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100755 tests/functional/test_hppa_seabios.py
MAINTAINERS +1 -0
@@ -1201,6 +1201,7 @@ F: include/hw/pci-host/astro.h F: include/hw/pci-host/dino.h F: pc-bios/hppa-firmware.img F: roms/seabios-hppa/ +F: tests/functional/test_hppa_seabios.py LoongArch Machines ------------------
tests/functional/meson.build +4 -0
@@ -104,6 +104,10 @@ tests_avr_system_thorough = [ 'avr_mega2560', ] +tests_hppa_system_quick = [ + 'hppa_seabios', +] + tests_i386_system_thorough = [ 'i386_tuxrun', ]
tests/functional/test_hppa_seabios.py new file +35 -0
@@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# SeaBIOS boot test for HPPA machines +# +# Copyright (c) 2024 Linaro, Ltd +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from qemu_test import QemuSystemTest +from qemu_test import wait_for_console_pattern + +class HppaSeabios(QemuSystemTest): + + timeout = 5 + MACH_BITS = {'B160L': 32, 'C3700': 64} + + def boot_seabios(self): + mach = self.machine + bits = self.MACH_BITS[mach] + self.vm.set_console() + self.vm.launch() + self.machine + wait_for_console_pattern(self, f'SeaBIOS PA-RISC {bits}-bit Firmware') + wait_for_console_pattern(self, f'Emulated machine: HP {mach} ({bits}-bit') + + def test_hppa_32(self): + self.set_machine('B160L') + self.boot_seabios() + + def test_hppa_64(self): + self.set_machine('C3700') + self.boot_seabios() + +if __name__ == '__main__': + QemuSystemTest.main()
Signature · 1 line
2.47.1
Re: [PATCH v4 1/6] tests: Add functional tests for HPPA machines
Quoted 11 lines · Philippe Mathieu-Daudé
Add quick firmware boot tests (less than 1sec) for the B160L (32-bit) and C3700 (64-bit) HPPA machines:
$ make check-functional-hppa 1/4 qemu:func-quick+func-hppa / func-hppa-empty_cpu_model OK 0.13s 1 subtests passed 2/4 qemu:func-quick+func-hppa / func-hppa-version OK 0.14s 1 subtests passed 3/4 qemu:func-quick+func-hppa / func-hppa-info_usernet OK 0.22s 1 subtests passed 4/4 qemu:func-quick+func-hppa / func-hppa-hppa_seabios OK 0.22s 2 subtests passedSuggested-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH v4 1/6] tests: Add functional tests for HPPA machines
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Add quick firmware boot tests (less than 1sec) for the B160L (32-bit) and C3700 (64-bit) HPPA machines:
$ make check-functional-hppa 1/4 qemu:func-quick+func-hppa / func-hppa-empty_cpu_model OK 0.13s 1 subtests passed 2/4 qemu:func-quick+func-hppa / func-hppa-version OK 0.14s 1 subtests passed 3/4 qemu:func-quick+func-hppa / func-hppa-info_usernet OK 0.22s 1 subtests passed 4/4 qemu:func-quick+func-hppa / func-hppa-hppa_seabios OK 0.22s 2 subtests passedSuggested-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 75 lines
--- MAINTAINERS | 1 + tests/functional/meson.build | 4 +++ tests/functional/test_hppa_seabios.py | 35 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+)create mode 100755
tests/functional/test_hppa_seabios.pyMAINTAINERS +1
-0@@ -1201,6 +1201,7 @@ F: include/hw/pci-host/astro.h F: include/hw/pci-host/dino.h F: pc-bios/hppa-firmware.img F: roms/seabios-hppa/ +F: tests/functional/test_hppa_seabios.py LoongArch Machines ------------------tests/functional/meson.build +4
-0@@ -104,6 +104,10 @@ tests_avr_system_thorough = [ 'avr_mega2560', ] +tests_hppa_system_quick = [ + 'hppa_seabios', +] + tests_i386_system_thorough = [ 'i386_tuxrun', ]tests/functional/test_hppa_seabios.py new file +35
-0@@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# +# SeaBIOS boot test for HPPA machines +# +# Copyright (c) 2024 Linaro, Ltd +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from qemu_test import QemuSystemTest +from qemu_test import wait_for_console_pattern + +class HppaSeabios(QemuSystemTest): + + timeout = 5 + MACH_BITS = {'B160L': 32, 'C3700': 64} + + def boot_seabios(self): + mach = self.machine + bits = self.MACH_BITS[mach] + self.vm.set_console() + self.vm.launch() + self.machine + wait_for_console_pattern(self, f'SeaBIOS PA-RISC {bits}-bit Firmware') + wait_for_console_pattern(self, f'Emulated machine: HP {mach} ({bits}-bit') + + def test_hppa_32(self): + self.set_machine('B160L') + self.boot_seabios() + + def test_hppa_64(self): + self.set_machine('C3700') + self.boot_seabios() + +if __name__ == '__main__': + QemuSystemTest.main()
PATCH v4 2/6 target/hppa: Convert hppa_cpu_init() to ResetHold handler
In reply to Philippe Mathieu-Daudé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 v4 3/6 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 v4 4/6 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.
--- 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
Re: [PATCH v4 4/6] target/hppa: Only set PSW 'M' bit on reset
Quoted 9 lines · Philippe Mathieu-Daudé
On reset:
"All PSW bits except the M bit is reset. The M bit is set."
Commit
1a19da0da44("target/hppa: Fill inhppa_cpu_do_interrupt/hppa_cpu_exec_interrupt") inadvertently set the W bit at RESET, remove it and set the M bit.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 17 lines
--- 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)
PATCH v4 5/6 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 v4 6/6 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 | 8 ++++++++ 2 files changed, 12 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 +8 -0
@@ -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);
@@ -282,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,
Signature · 1 line
2.47.1
Quoted 13 lines · Philippe Mathieu-Daudé
Respin of:
https://lore.kernel.org/qemu-devel/[email protected]/
"Add CPU reset function and speed up runtime and translation."Since v3:
- Added tests, dropped R-b tagsHelge 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()
Quoted 3 lines
Philippe Mathieu-Daudé (2):
tests: Add functional tests for HPPA machines
target/hppa: Only set PSW 'M' bit on reset
Helge, I'm queuing this series via my hw-misc tree, thanks!