misc ppc improvements/optimizations
v4 cover misc ppc improvements/optimizations
This a set of misc ppc arch specific code improvements/optimizations. Most of the improvements are done in Power9/8/7 exception handling code alongwith some code cleanups.
Since patch 7/7 of v2 series have been picked by Aditya in his patchset for P11 support, I have excluded that patch in this series and based on top of his v6 series which contains the required patch as 1/5.
Based on: <[email protected]>
Changelog:
v4: squashed patch 4,5 (in v3) as 4/9 (Nick)
moved 6/10 (in v3) to last 9/9 (Nick)
Added R-bys from Nick, Balaton.
v3: extended improvements to other Power arch p7, p8 (Nick)
other minor improvements
v2: addressed review comments from BALATON Zoltan
v1: Initial patch
Harsh Prateek Bora (9):
target/ppc: use locally stored msr and avoid indirect access target/ppc: optimize hreg_compute_pmu_hflags_value target/ppc: optimize hreg_compute_pmu_hflags_value target/ppc: optimize p9 exception handling routines target/ppc: optimize p8 exception handling routines target/ppc: optimize p7 exception handling routines target/ppc: simplify var usage in ppc_next_unmasked_interrupt target/ppc: combine multiple ail checks into one target/ppc: reduce duplicate code between init_proc_POWER{9, 10}
target/ppc/cpu_init.c | 58 ++-------- target/ppc/excp_helper.c | 230 ++++++++++++++++++++------------------- target/ppc/helper_regs.c | 19 ++-- 3 files changed, 141 insertions(+), 166 deletions(-)
Signature · 1 line
2.45.2
PATCH v4 1/9 target/ppc: use locally stored msr and avoid indirect access
hreg_compute_hflags_value already stores msr locally to be used in most of the logic in the routine however some instances are still using env->msr which is unnecessary. Use locally stored value as available.
--- target/ppc/helper_regs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/ppc/helper_regs.c +2 -2
@@ -143,10 +143,10 @@ static uint32_t hreg_compute_hflags_value(CPUPPCState *env)if (ppc_flags &POWERPC_FLAG_DE ) {target_ulong dbcr0 = env->spr[SPR_BOOKE_DBCR0 ]; -if ((dbcr0 &DBCR0_ICMP ) &&FIELD_EX64 (env->msr,MSR ,DE )) { +if ((dbcr0 &DBCR0_ICMP ) &&FIELD_EX64 (msr,MSR ,DE )) { hflags |=1 <<HFLAGS_SE ; } -if ((dbcr0 &DBCR0_BRT ) &&FIELD_EX64 (env->msr,MSR ,DE )) { +if ((dbcr0 &DBCR0_BRT ) &&FIELD_EX64 (msr,MSR ,DE )) { hflags |=1 <<HFLAGS_BE ; } }else {
Signature · 1 line
2.45.2
PATCH v4 2/9 target/ppc: optimize hreg_compute_pmu_hflags_value
In reply to Harsh Prateek BoraCache env->spr[SPR_POWER_MMCR0] in a local variable as used in multiple conditions to avoid multiple indirect accesses.
--- target/ppc/helper_regs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
target/ppc/helper_regs.c +5 -4
@@ -83,15 +83,16 @@ static bool hreg_check_bhrb_enable(CPUPPCState *env)static uint32_t hreg_compute_pmu_hflags_value (CPUPPCState *env) {uint32_t hflags =0 ; -#if defined(TARGET_PPC64 ) -if (env->spr[SPR_POWER_MMCR0 ] &MMCR0_PMCC0 ) { +target_ulong mmcr0 = env->spr[SPR_POWER_MMCR0 ]; + +if (mmcr0 &MMCR0_PMCC0 ) { hflags |=1 <<HFLAGS_PMCC0 ; } -if (env->spr[SPR_POWER_MMCR0 ] &MMCR0_PMCC1 ) { +if (mmcr0 &MMCR0_PMCC1 ) { hflags |=1 <<HFLAGS_PMCC1 ; } -if (env->spr[SPR_POWER_MMCR0 ] & MMCR0_PMCjCE) { +if (mmcr0 & MMCR0_PMCjCE) { hflags |=1 <<HFLAGS_PMCJCE ; }if (hreg_check_bhrb_enable (env)) {
Signature · 1 line
2.45.2
PATCH v4 3/9 target/ppc: optimize hreg_compute_pmu_hflags_value
In reply to Harsh Prateek BoraThe second if-condition can be true only if the first one above is true. Enclose the latter into the former to avoid un-necessary check if first condition fails.
--- target/ppc/helper_regs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/ppc/helper_regs.c +3 -3
@@ -102,9 +102,9 @@ static uint32_t hreg_compute_pmu_hflags_value(CPUPPCState *env)#ifndef CONFIG_USER_ONLY if (env->pmc_ins_cnt) { hflags |=1 <<HFLAGS_INSN_CNT ; - } -if (env->pmc_ins_cnt &0x1e ) { - hflags |=1 <<HFLAGS_PMC_OTHER ; +if (env->pmc_ins_cnt &0x1e ) { + hflags |=1 <<HFLAGS_PMC_OTHER ; + } }#endif #endif
Signature · 1 line
2.45.2
PATCH v4 4/9 target/ppc: optimize p9 exception handling routines
In reply to Harsh Prateek BoraCurrently, p9 exception handling has multiple if-condition checks where it does an indirect access to pending_interrupts and LPCR via env. Pass the values during entry to avoid multiple indirect accesses.
--- target/ppc/excp_helper.c | 72 ++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 33 deletions(-)
target/ppc/excp_helper.c +39 -33
@@ -1872,60 +1872,65 @@ static int p8_next_unmasked_interrupt(CPUPPCState *env) PPC_INTERRUPT_WDT | PPC_INTERRUPT_CDOORBELL | PPC_INTERRUPT_FIT | \ PPC_INTERRUPT_PIT | PPC_INTERRUPT_THERM) -static int p9_interrupt_powersave (CPUPPCState *env) +static int p9_interrupt_powersave (CPUPPCState *env, +uint32_t pending_interrupts, +target_ulong lpcr) { +/* External Exception */ -if ((env->pending_interrupts &PPC_INTERRUPT_EXT ) && - (env->spr[SPR_LPCR ] &LPCR_EEE )) { -bool heic = !!(env->spr[SPR_LPCR ] &LPCR_HEIC ); +if ((pending_interrupts &PPC_INTERRUPT_EXT ) && + (lpcr &LPCR_EEE )) { +bool heic = !!(lpcr &LPCR_HEIC );if (!heic || !FIELD_EX64_HV (env->msr) ||FIELD_EX64 (env->msr,MSR ,PR )) {return PPC_INTERRUPT_EXT ; } }/* Decrementer Exception */ -if ((env->pending_interrupts &PPC_INTERRUPT_DECR ) && - (env->spr[SPR_LPCR ] &LPCR_DEE )) { +if ((pending_interrupts &PPC_INTERRUPT_DECR ) && + (lpcr &LPCR_DEE )) {return PPC_INTERRUPT_DECR ; }/* Machine Check or Hypervisor Maintenance Exception */ -if (env->spr[SPR_LPCR ] &LPCR_OEE ) { -if (env->pending_interrupts &PPC_INTERRUPT_MCK ) { +if (lpcr &LPCR_OEE ) { +if (pending_interrupts &PPC_INTERRUPT_MCK ) {return PPC_INTERRUPT_MCK ; } -if (env->pending_interrupts &PPC_INTERRUPT_HMI ) { +if (pending_interrupts &PPC_INTERRUPT_HMI ) {return PPC_INTERRUPT_HMI ; } }/* Privileged Doorbell Exception */ -if ((env->pending_interrupts &PPC_INTERRUPT_DOORBELL ) && - (env->spr[SPR_LPCR ] &LPCR_PDEE )) { +if ((pending_interrupts &PPC_INTERRUPT_DOORBELL ) && + (lpcr &LPCR_PDEE )) {return PPC_INTERRUPT_DOORBELL ; }/* Hypervisor Doorbell Exception */ -if ((env->pending_interrupts &PPC_INTERRUPT_HDOORBELL ) && - (env->spr[SPR_LPCR ] &LPCR_HDEE )) { +if ((pending_interrupts &PPC_INTERRUPT_HDOORBELL ) && + (lpcr &LPCR_HDEE )) {return PPC_INTERRUPT_HDOORBELL ; }/* Hypervisor virtualization exception */ -if ((env->pending_interrupts &PPC_INTERRUPT_HVIRT ) && - (env->spr[SPR_LPCR ] &LPCR_HVEE )) { +if ((pending_interrupts &PPC_INTERRUPT_HVIRT ) && + (lpcr &LPCR_HVEE )) {return PPC_INTERRUPT_HVIRT ; } -if (env->pending_interrupts &PPC_INTERRUPT_RESET ) { +if (pending_interrupts &PPC_INTERRUPT_RESET ) {return PPC_INTERRUPT_RESET ; }return 0 ; } -static int p9_next_unmasked_interrupt (CPUPPCState *env) +static int p9_next_unmasked_interrupt (CPUPPCState *env, +uint32_t pending_interrupts, +target_ulong lpcr) {CPUState *cs =env_cpu (env);/* Ignore MSR[EE] when coming out of some power management states */ bool msr_ee =FIELD_EX64 (env->msr,MSR ,EE ) || env->resume_as_sreset; -assert ((env->pending_interrupts &P9_UNUSED_INTERRUPTS ) ==0 ); +assert ((pending_interrupts &P9_UNUSED_INTERRUPTS ) ==0 );if (cs->halted) {if (env->spr[SPR_PSSCR ] &PSSCR_EC ) {
@@ -1933,7 +1938,7 @@ static int p9_next_unmasked_interrupt(CPUPPCState *env)* When PSSCR[EC] is set, LPCR[PECE] controls which interrupts can * wakeup the processor */ -return p9_interrupt_powersave (env); +return p9_interrupt_powersave (env, pending_interrupts, lpcr); }else {/* * When it's clear, any system-caused exception exits power-saving
@@ -1944,14 +1949,14 @@ static int p9_next_unmasked_interrupt(CPUPPCState *env) }/* Machine check exception */ -if (env->pending_interrupts &PPC_INTERRUPT_MCK ) { +if (pending_interrupts &PPC_INTERRUPT_MCK ) {return PPC_INTERRUPT_MCK ; }/* Hypervisor decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_HDECR ) { +if (pending_interrupts &PPC_INTERRUPT_HDECR ) {/* LPCR will be clear when not supported so this will work */ -bool hdice = !!(env->spr[SPR_LPCR ] &LPCR_HDICE ); +bool hdice = !!(lpcr &LPCR_HDICE );if ((msr_ee || !FIELD_EX64_HV (env->msr)) && hdice) {/* HDEC clears on delivery */ return PPC_INTERRUPT_HDECR ;
@@ -1959,18 +1964,18 @@ static int p9_next_unmasked_interrupt(CPUPPCState *env) }/* Hypervisor virtualization interrupt */ -if (env->pending_interrupts &PPC_INTERRUPT_HVIRT ) { +if (pending_interrupts &PPC_INTERRUPT_HVIRT ) {/* LPCR will be clear when not supported so this will work */ -bool hvice = !!(env->spr[SPR_LPCR ] &LPCR_HVICE ); +bool hvice = !!(lpcr &LPCR_HVICE );if ((msr_ee || !FIELD_EX64_HV (env->msr)) && hvice) {return PPC_INTERRUPT_HVIRT ; } }/* External interrupt can ignore MSR:EE under some circumstances */ -if (env->pending_interrupts &PPC_INTERRUPT_EXT ) { -bool lpes0 = !!(env->spr[SPR_LPCR ] &LPCR_LPES0 ); -bool heic = !!(env->spr[SPR_LPCR ] &LPCR_HEIC ); +if (pending_interrupts &PPC_INTERRUPT_EXT ) { +bool lpes0 = !!(lpcr &LPCR_LPES0 ); +bool heic = !!(lpcr &LPCR_HEIC );/* HEIC blocks delivery to the hypervisor */ if ((msr_ee && !(heic && FIELD_EX64_HV(env->msr) && !FIELD_EX64(env->msr, MSR, PR))) ||
@@ -1980,20 +1985,20 @@ static int p9_next_unmasked_interrupt(CPUPPCState *env) }if (msr_ee !=0 ) {/* Decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_DECR ) { +if (pending_interrupts &PPC_INTERRUPT_DECR ) {return PPC_INTERRUPT_DECR ; } -if (env->pending_interrupts &PPC_INTERRUPT_DOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_DOORBELL ) {return PPC_INTERRUPT_DOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_HDOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_HDOORBELL ) {return PPC_INTERRUPT_HDOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_PERFM ) { +if (pending_interrupts &PPC_INTERRUPT_PERFM ) {return PPC_INTERRUPT_PERFM ; }/* EBB exception */ -if (env->pending_interrupts &PPC_INTERRUPT_EBB ) { +if (pending_interrupts &PPC_INTERRUPT_EBB ) {/* * EBB exception must be taken in problem state and * with BESCR_GE set.
@@ -2020,7 +2025,8 @@ static int ppc_next_unmasked_interrupt(CPUPPCState *env)case POWERPC_EXCP_POWER9 :case POWERPC_EXCP_POWER10 :case POWERPC_EXCP_POWER11 : -return p9_next_unmasked_interrupt (env); +return p9_next_unmasked_interrupt (env, env->pending_interrupts, + env->spr[SPR_LPCR ]);default :break ; }
Signature · 1 line
2.45.2
PATCH v4 5/9 target/ppc: optimize p8 exception handling routines
In reply to Harsh Prateek BoraMost of the p8 exception handling accesses env->pending_interrupts and env->spr[SPR_LPCR] at multiple places. Passing it directly as local variables simplifies the code and avoids multiple indirect accesses.
--- target/ppc/excp_helper.c | 60 +++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-)
target/ppc/excp_helper.c +32 -28
@@ -1765,39 +1765,42 @@ static int p7_next_unmasked_interrupt(CPUPPCState *env) PPC_INTERRUPT_CEXT | PPC_INTERRUPT_WDT | PPC_INTERRUPT_CDOORBELL | \ PPC_INTERRUPT_FIT | PPC_INTERRUPT_PIT | PPC_INTERRUPT_THERM) -static int p8_interrupt_powersave (CPUPPCState *env) +static int p8_interrupt_powersave (uint32_t pending_interrupts, +target_ulong lpcr) { -if ((env->pending_interrupts &PPC_INTERRUPT_EXT ) && - (env->spr[SPR_LPCR ] &LPCR_P8_PECE2 )) { +if ((pending_interrupts &PPC_INTERRUPT_EXT ) && + (lpcr &LPCR_P8_PECE2 )) {return PPC_INTERRUPT_EXT ; } -if ((env->pending_interrupts &PPC_INTERRUPT_DECR ) && - (env->spr[SPR_LPCR ] &LPCR_P8_PECE3 )) { +if ((pending_interrupts &PPC_INTERRUPT_DECR ) && + (lpcr &LPCR_P8_PECE3 )) {return PPC_INTERRUPT_DECR ; } -if ((env->pending_interrupts &PPC_INTERRUPT_MCK ) && - (env->spr[SPR_LPCR ] &LPCR_P8_PECE4 )) { +if ((pending_interrupts &PPC_INTERRUPT_MCK ) && + (lpcr &LPCR_P8_PECE4 )) {return PPC_INTERRUPT_MCK ; } -if ((env->pending_interrupts &PPC_INTERRUPT_HMI ) && - (env->spr[SPR_LPCR ] &LPCR_P8_PECE4 )) { +if ((pending_interrupts &PPC_INTERRUPT_HMI ) && + (lpcr &LPCR_P8_PECE4 )) {return PPC_INTERRUPT_HMI ; } -if ((env->pending_interrupts &PPC_INTERRUPT_DOORBELL ) && - (env->spr[SPR_LPCR ] &LPCR_P8_PECE0 )) { +if ((pending_interrupts &PPC_INTERRUPT_DOORBELL ) && + (lpcr &LPCR_P8_PECE0 )) {return PPC_INTERRUPT_DOORBELL ; } -if ((env->pending_interrupts &PPC_INTERRUPT_HDOORBELL ) && - (env->spr[SPR_LPCR ] &LPCR_P8_PECE1 )) { +if ((pending_interrupts &PPC_INTERRUPT_HDOORBELL ) && + (lpcr &LPCR_P8_PECE1 )) {return PPC_INTERRUPT_HDOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_RESET ) { +if (pending_interrupts &PPC_INTERRUPT_RESET ) {return PPC_INTERRUPT_RESET ; }return 0 ; } -static int p8_next_unmasked_interrupt (CPUPPCState *env) +static int p8_next_unmasked_interrupt (CPUPPCState *env, +uint32_t pending_interrupts, +target_ulong lpcr) {CPUState *cs =env_cpu (env);
@@ -1808,18 +1811,18 @@ static int p8_next_unmasked_interrupt(CPUPPCState *env)if (cs->halted) {/* LPCR[PECE] controls which interrupts can exit power-saving mode */ -return p8_interrupt_powersave (env); +return p8_interrupt_powersave (pending_interrupts, lpcr); }/* Machine check exception */ -if (env->pending_interrupts &PPC_INTERRUPT_MCK ) { +if (pending_interrupts &PPC_INTERRUPT_MCK ) {return PPC_INTERRUPT_MCK ; }/* Hypervisor decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_HDECR ) { +if (pending_interrupts &PPC_INTERRUPT_HDECR ) {/* LPCR will be clear when not supported so this will work */ -bool hdice = !!(env->spr[SPR_LPCR ] &LPCR_HDICE ); +bool hdice = !!(lpcr &LPCR_HDICE );if ((msr_ee || !FIELD_EX64_HV (env->msr)) && hdice) {/* HDEC clears on delivery */ return PPC_INTERRUPT_HDECR ;
@@ -1827,9 +1830,9 @@ static int p8_next_unmasked_interrupt(CPUPPCState *env) }/* External interrupt can ignore MSR:EE under some circumstances */ -if (env->pending_interrupts &PPC_INTERRUPT_EXT ) { -bool lpes0 = !!(env->spr[SPR_LPCR ] &LPCR_LPES0 ); -bool heic = !!(env->spr[SPR_LPCR ] &LPCR_HEIC ); +if (pending_interrupts &PPC_INTERRUPT_EXT ) { +bool lpes0 = !!(lpcr &LPCR_LPES0 ); +bool heic = !!(lpcr &LPCR_HEIC );/* HEIC blocks delivery to the hypervisor */ if ((msr_ee && !(heic && FIELD_EX64_HV(env->msr) && !FIELD_EX64(env->msr, MSR, PR))) ||
@@ -1839,20 +1842,20 @@ static int p8_next_unmasked_interrupt(CPUPPCState *env) }if (msr_ee !=0 ) {/* Decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_DECR ) { +if (pending_interrupts &PPC_INTERRUPT_DECR ) {return PPC_INTERRUPT_DECR ; } -if (env->pending_interrupts &PPC_INTERRUPT_DOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_DOORBELL ) {return PPC_INTERRUPT_DOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_HDOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_HDOORBELL ) {return PPC_INTERRUPT_HDOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_PERFM ) { +if (pending_interrupts &PPC_INTERRUPT_PERFM ) {return PPC_INTERRUPT_PERFM ; }/* EBB exception */ -if (env->pending_interrupts &PPC_INTERRUPT_EBB ) { +if (pending_interrupts &PPC_INTERRUPT_EBB ) {/* * EBB exception must be taken in problem state and * with BESCR_GE set.
@@ -2021,7 +2024,8 @@ static int ppc_next_unmasked_interrupt(CPUPPCState *env)case POWERPC_EXCP_POWER7 :return p7_next_unmasked_interrupt (env);case POWERPC_EXCP_POWER8 : -return p8_next_unmasked_interrupt (env); +return p8_next_unmasked_interrupt (env, env->pending_interrupts, + env->spr[SPR_LPCR ]);case POWERPC_EXCP_POWER9 :case POWERPC_EXCP_POWER10 :case POWERPC_EXCP_POWER11 :
Signature · 1 line
2.45.2
PATCH v4 6/9 target/ppc: optimize p7 exception handling routines
In reply to Harsh Prateek BoraLike p8 and p9, simplifying p7 exception handling rotuines to avoid un-necessary multiple indirect accesses to env->pending_interrupts and env->spr[SPR_LPCR].
--- target/ppc/excp_helper.c | 46 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 21 deletions(-)
target/ppc/excp_helper.c +25 -21
@@ -1683,51 +1683,54 @@ void ppc_cpu_do_interrupt(CPUState *cs) PPC_INTERRUPT_PIT | PPC_INTERRUPT_DOORBELL | PPC_INTERRUPT_HDOORBELL | \ PPC_INTERRUPT_THERM | PPC_INTERRUPT_EBB) -static int p7_interrupt_powersave (CPUPPCState *env) +static int p7_interrupt_powersave (uint32_t pending_interrupts, +target_ulong lpcr) { -if ((env->pending_interrupts &PPC_INTERRUPT_EXT ) && - (env->spr[SPR_LPCR ] &LPCR_P7_PECE0 )) { +if ((pending_interrupts &PPC_INTERRUPT_EXT ) && + (lpcr &LPCR_P7_PECE0 )) {return PPC_INTERRUPT_EXT ; } -if ((env->pending_interrupts &PPC_INTERRUPT_DECR ) && - (env->spr[SPR_LPCR ] &LPCR_P7_PECE1 )) { +if ((pending_interrupts &PPC_INTERRUPT_DECR ) && + (lpcr &LPCR_P7_PECE1 )) {return PPC_INTERRUPT_DECR ; } -if ((env->pending_interrupts &PPC_INTERRUPT_MCK ) && - (env->spr[SPR_LPCR ] &LPCR_P7_PECE2 )) { +if ((pending_interrupts &PPC_INTERRUPT_MCK ) && + (lpcr &LPCR_P7_PECE2 )) {return PPC_INTERRUPT_MCK ; } -if ((env->pending_interrupts &PPC_INTERRUPT_HMI ) && - (env->spr[SPR_LPCR ] &LPCR_P7_PECE2 )) { +if ((pending_interrupts &PPC_INTERRUPT_HMI ) && + (lpcr &LPCR_P7_PECE2 )) {return PPC_INTERRUPT_HMI ; } -if (env->pending_interrupts &PPC_INTERRUPT_RESET ) { +if (pending_interrupts &PPC_INTERRUPT_RESET ) {return PPC_INTERRUPT_RESET ; }return 0 ; } -static int p7_next_unmasked_interrupt (CPUPPCState *env) +static int p7_next_unmasked_interrupt (CPUPPCState *env, +uint32_t pending_interrupts, +target_ulong lpcr) {CPUState *cs =env_cpu (env);/* Ignore MSR[EE] when coming out of some power management states */ bool msr_ee =FIELD_EX64 (env->msr,MSR ,EE ) || env->resume_as_sreset; -assert ((env->pending_interrupts &P7_UNUSED_INTERRUPTS ) ==0 ); +assert ((pending_interrupts &P7_UNUSED_INTERRUPTS ) ==0 );if (cs->halted) {/* LPCR[PECE] controls which interrupts can exit power-saving mode */ -return p7_interrupt_powersave (env); +return p7_interrupt_powersave (pending_interrupts, lpcr); }/* Machine check exception */ -if (env->pending_interrupts &PPC_INTERRUPT_MCK ) { +if (pending_interrupts &PPC_INTERRUPT_MCK ) {return PPC_INTERRUPT_MCK ; }/* Hypervisor decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_HDECR ) { +if (pending_interrupts &PPC_INTERRUPT_HDECR ) {/* LPCR will be clear when not supported so this will work */ bool hdice = !!(env->spr[SPR_LPCR ] &LPCR_HDICE );if ((msr_ee || !FIELD_EX64_HV (env->msr)) && hdice) {
@@ -1737,9 +1740,9 @@ static int p7_next_unmasked_interrupt(CPUPPCState *env) }/* External interrupt can ignore MSR:EE under some circumstances */ -if (env->pending_interrupts &PPC_INTERRUPT_EXT ) { -bool lpes0 = !!(env->spr[SPR_LPCR ] &LPCR_LPES0 ); -bool heic = !!(env->spr[SPR_LPCR ] &LPCR_HEIC ); +if (pending_interrupts &PPC_INTERRUPT_EXT ) { +bool lpes0 = !!(lpcr &LPCR_LPES0 ); +bool heic = !!(lpcr &LPCR_HEIC );/* HEIC blocks delivery to the hypervisor */ if ((msr_ee && !(heic && FIELD_EX64_HV(env->msr) && !FIELD_EX64(env->msr, MSR, PR))) ||
@@ -1749,10 +1752,10 @@ static int p7_next_unmasked_interrupt(CPUPPCState *env) }if (msr_ee !=0 ) {/* Decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_DECR ) { +if (pending_interrupts &PPC_INTERRUPT_DECR ) {return PPC_INTERRUPT_DECR ; } -if (env->pending_interrupts &PPC_INTERRUPT_PERFM ) { +if (pending_interrupts &PPC_INTERRUPT_PERFM ) {return PPC_INTERRUPT_PERFM ; } }
@@ -2022,7 +2025,8 @@ static int ppc_next_unmasked_interrupt(CPUPPCState *env)#ifdef TARGET_PPC64 switch (env->excp_model) {case POWERPC_EXCP_POWER7 : -return p7_next_unmasked_interrupt (env); +return p7_next_unmasked_interrupt (env, env->pending_interrupts, + env->spr[SPR_LPCR ]);case POWERPC_EXCP_POWER8 :return p8_next_unmasked_interrupt (env, env->pending_interrupts, env->spr[SPR_LPCR ]);
Signature · 1 line
2.45.2
PATCH v4 7/9 target/ppc: simplify var usage in ppc_next_unmasked_interrupt
In reply to Harsh Prateek BoraAs previously done for arch specific handlers, simplify var usage in ppc_next_unmasked_interrupt by caching the env->pending_interrupts and env->spr[SPR_LPCR] in local vars and using it later at multiple places.
--- target/ppc/excp_helper.c | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
target/ppc/excp_helper.c +27 -27
@@ -2022,31 +2022,31 @@ static int p9_next_unmasked_interrupt(CPUPPCState *env,static int ppc_next_unmasked_interrupt (CPUPPCState *env) { +uint32_t pending_interrupts = env->pending_interrupts; +target_ulong lpcr = env->spr[SPR_LPCR ]; +bool async_deliver; +#ifdef TARGET_PPC64 switch (env->excp_model) {case POWERPC_EXCP_POWER7 : -return p7_next_unmasked_interrupt (env, env->pending_interrupts, - env->spr[SPR_LPCR ]); +return p7_next_unmasked_interrupt (env, pending_interrupts, lpcr);case POWERPC_EXCP_POWER8 : -return p8_next_unmasked_interrupt (env, env->pending_interrupts, - env->spr[SPR_LPCR ]); +return p8_next_unmasked_interrupt (env, pending_interrupts, lpcr);case POWERPC_EXCP_POWER9 :case POWERPC_EXCP_POWER10 :case POWERPC_EXCP_POWER11 : -return p9_next_unmasked_interrupt (env, env->pending_interrupts, - env->spr[SPR_LPCR ]); +return p9_next_unmasked_interrupt (env, pending_interrupts, lpcr);default :break ; }#endif -bool async_deliver;/* External reset */ -if (env->pending_interrupts &PPC_INTERRUPT_RESET ) { +if (pending_interrupts &PPC_INTERRUPT_RESET ) {return PPC_INTERRUPT_RESET ; }/* Machine check exception */ -if (env->pending_interrupts &PPC_INTERRUPT_MCK ) { +if (pending_interrupts &PPC_INTERRUPT_MCK ) {return PPC_INTERRUPT_MCK ; }#if 0 /* TODO */
@@ -2065,9 +2065,9 @@ static int ppc_next_unmasked_interrupt(CPUPPCState *env) async_deliver =FIELD_EX64 (env->msr,MSR ,EE ) || env->resume_as_sreset;/* Hypervisor decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_HDECR ) { +if (pending_interrupts &PPC_INTERRUPT_HDECR ) {/* LPCR will be clear when not supported so this will work */ -bool hdice = !!(env->spr[SPR_LPCR ] &LPCR_HDICE ); +bool hdice = !!(lpcr &LPCR_HDICE );if ((async_deliver || !FIELD_EX64_HV (env->msr)) && hdice) {/* HDEC clears on delivery */ return PPC_INTERRUPT_HDECR ;
@@ -2075,18 +2075,18 @@ static int ppc_next_unmasked_interrupt(CPUPPCState *env) }/* Hypervisor virtualization interrupt */ -if (env->pending_interrupts &PPC_INTERRUPT_HVIRT ) { +if (pending_interrupts &PPC_INTERRUPT_HVIRT ) {/* LPCR will be clear when not supported so this will work */ -bool hvice = !!(env->spr[SPR_LPCR ] &LPCR_HVICE ); +bool hvice = !!(lpcr &LPCR_HVICE );if ((async_deliver || !FIELD_EX64_HV (env->msr)) && hvice) {return PPC_INTERRUPT_HVIRT ; } }/* External interrupt can ignore MSR:EE under some circumstances */ -if (env->pending_interrupts &PPC_INTERRUPT_EXT ) { -bool lpes0 = !!(env->spr[SPR_LPCR ] &LPCR_LPES0 ); -bool heic = !!(env->spr[SPR_LPCR ] &LPCR_HEIC ); +if (pending_interrupts &PPC_INTERRUPT_EXT ) { +bool lpes0 = !!(lpcr &LPCR_LPES0 ); +bool heic = !!(lpcr &LPCR_HEIC );/* HEIC blocks delivery to the hypervisor */ if ((async_deliver && !(heic && FIELD_EX64_HV(env->msr) && !FIELD_EX64(env->msr, MSR, PR))) ||
@@ -2096,45 +2096,45 @@ static int ppc_next_unmasked_interrupt(CPUPPCState *env) }if (FIELD_EX64 (env->msr,MSR ,CE )) {/* External critical interrupt */ -if (env->pending_interrupts &PPC_INTERRUPT_CEXT ) { +if (pending_interrupts &PPC_INTERRUPT_CEXT ) {return PPC_INTERRUPT_CEXT ; } }if (async_deliver !=0 ) {/* Watchdog timer on embedded PowerPC */ -if (env->pending_interrupts &PPC_INTERRUPT_WDT ) { +if (pending_interrupts &PPC_INTERRUPT_WDT ) {return PPC_INTERRUPT_WDT ; } -if (env->pending_interrupts &PPC_INTERRUPT_CDOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_CDOORBELL ) {return PPC_INTERRUPT_CDOORBELL ; }/* Fixed interval timer on embedded PowerPC */ -if (env->pending_interrupts &PPC_INTERRUPT_FIT ) { +if (pending_interrupts &PPC_INTERRUPT_FIT ) {return PPC_INTERRUPT_FIT ; }/* Programmable interval timer on embedded PowerPC */ -if (env->pending_interrupts &PPC_INTERRUPT_PIT ) { +if (pending_interrupts &PPC_INTERRUPT_PIT ) {return PPC_INTERRUPT_PIT ; }/* Decrementer exception */ -if (env->pending_interrupts &PPC_INTERRUPT_DECR ) { +if (pending_interrupts &PPC_INTERRUPT_DECR ) {return PPC_INTERRUPT_DECR ; } -if (env->pending_interrupts &PPC_INTERRUPT_DOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_DOORBELL ) {return PPC_INTERRUPT_DOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_HDOORBELL ) { +if (pending_interrupts &PPC_INTERRUPT_HDOORBELL ) {return PPC_INTERRUPT_HDOORBELL ; } -if (env->pending_interrupts &PPC_INTERRUPT_PERFM ) { +if (pending_interrupts &PPC_INTERRUPT_PERFM ) {return PPC_INTERRUPT_PERFM ; }/* Thermal interrupt */ -if (env->pending_interrupts &PPC_INTERRUPT_THERM ) { +if (pending_interrupts &PPC_INTERRUPT_THERM ) {return PPC_INTERRUPT_THERM ; }/* EBB exception */ -if (env->pending_interrupts &PPC_INTERRUPT_EBB ) { +if (pending_interrupts &PPC_INTERRUPT_EBB ) {/* * EBB exception must be taken in problem state and * with BESCR_GE set.
Signature · 1 line
2.45.2
PATCH v4 8/9 target/ppc: combine multiple ail checks into one
In reply to Harsh Prateek Borappc_excp_apply_ail has multiple if-checks for ail which is un-necessary. Combine them as appropriate.
--- target/ppc/excp_helper.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
target/ppc/excp_helper.c +2 -8
@@ -324,10 +324,7 @@ static void ppc_excp_apply_ail(PowerPCCPU *cpu, int excp, target_ulong msr, } ail = (env->spr[SPR_LPCR ] &LPCR_AIL ) >>LPCR_AIL_SHIFT ; -if (ail ==0 ) { -return ; - } -if (ail ==1 ) { +if (ail ==0 || ail ==1 ) {/* AIL=1 is reserved, treat it like AIL=0 */ return ; }
@@ -351,10 +348,7 @@ static void ppc_excp_apply_ail(PowerPCCPU *cpu, int excp, target_ulong msr, }else { ail = (env->spr[SPR_LPCR ] &LPCR_AIL ) >>LPCR_AIL_SHIFT ; } -if (ail ==0 ) { -return ; - } -if (ail ==1 || ail ==2 ) { +if (ail ==0 || ail ==1 || ail ==2 ) {/* AIL=1 and AIL=2 are reserved, treat them like AIL=0 */ return ; }
Signature · 1 line
2.45.2
PATCH v4 9/9 target/ppc: reduce duplicate code between init_proc_POWER{9, 10}
In reply to Harsh Prateek BoraHistorically, the registration of sprs have been inherited alongwith every new Power arch support being added leading to a lot of code duplication. It's time to do necessary cleanups now to avoid further duplication with newer arch support being added.
--- target/ppc/cpu_init.c | 58 +++++++++---------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-)
target/ppc/cpu_init.c +12 -46
@@ -6410,7 +6410,7 @@ static struct ppc_radix_page_info POWER9_radix_page_info = {#endif /* CONFIG_USER_ONLY */ #define POWER9_BHRB_ENTRIES_LOG2 5 -static void init_proc_POWER9 (CPUPPCState *env) +static void register_power9_common_sprs (CPUPPCState *env) {/* Common Registers */ init_proc_book3s_common (env);
@@ -6429,7 +6429,6 @@ static void init_proc_POWER9(CPUPPCState *env)register_power5p_ear_sprs (env);register_power5p_tb_sprs (env);register_power6_common_sprs (env); -register_HEIR32_spr (env);register_power6_dbg_sprs (env);register_power7_common_sprs (env);register_power8_tce_address_control_sprs (env);
@@ -6447,16 +6446,21 @@ static void init_proc_POWER9(CPUPPCState *env)register_power8_rpr_sprs (env);register_power9_mmu_sprs (env); -/* POWER9 Specific registers */ -spr_register_kvm (env,SPR_TIDR ,"TIDR" ,NULL ,NULL , - spr_read_generic, spr_write_generic, -KVM_REG_PPC_TIDR ,0 ); -/* FIXME: Filter fields properly based on privilege level */ spr_register_kvm_hv (env,SPR_PSSCR ,"PSSCR" ,NULL ,NULL ,NULL ,NULL , spr_read_generic, spr_write_generic,KVM_REG_PPC_PSSCR ,0 ); +} + +static void init_proc_POWER9 (CPUPPCState *env) +{ +register_power9_common_sprs (env); +register_HEIR32_spr (env); +/* POWER9 Specific registers */ +spr_register_kvm (env,SPR_TIDR ,"TIDR" ,NULL ,NULL , + spr_read_generic, spr_write_generic, +KVM_REG_PPC_TIDR ,0 );/* env variables */ env->dcache_line_size =128 ; env->icache_line_size =128 ;
@@ -6562,50 +6566,12 @@ static struct ppc_radix_page_info POWER10_radix_page_info = {#define POWER10_BHRB_ENTRIES_LOG2 5static void init_proc_POWER10 (CPUPPCState *env) { -/* Common Registers */ -init_proc_book3s_common (env); -register_book3s_207_dbg_sprs (env); - -/* Common TCG PMU */ -init_tcg_pmu_power8 (env); - -/* POWER8 Specific Registers */ -register_book3s_ids_sprs (env); -register_amr_sprs (env); -register_iamr_sprs (env); -register_book3s_purr_sprs (env); -register_power5p_common_sprs (env); -register_power5p_lpar_sprs (env); -register_power5p_ear_sprs (env); -register_power5p_tb_sprs (env); -register_power6_common_sprs (env); +register_power9_common_sprs (env);register_HEIR64_spr (env); -register_power6_dbg_sprs (env); -register_power7_common_sprs (env); -register_power8_tce_address_control_sprs (env); -register_power8_ids_sprs (env); -register_power8_ebb_sprs (env); -register_power8_fscr_sprs (env); -register_power8_pmu_sup_sprs (env); -register_power8_pmu_user_sprs (env); -register_power8_tm_sprs (env); -register_power8_pspb_sprs (env); -register_power8_dpdes_sprs (env); -register_vtb_sprs (env); -register_power8_ic_sprs (env); -register_power9_book4_sprs (env); -register_power8_rpr_sprs (env); -register_power9_mmu_sprs (env);register_power10_hash_sprs (env);register_power10_dexcr_sprs (env);register_power10_pmu_sup_sprs (env);register_power10_pmu_user_sprs (env); - -/* FIXME: Filter fields properly based on privilege level */ -spr_register_kvm_hv (env,SPR_PSSCR ,"PSSCR" ,NULL ,NULL ,NULL ,NULL , - spr_read_generic, spr_write_generic, -KVM_REG_PPC_PSSCR ,0 ); -/* env variables */ env->dcache_line_size =128 ; env->icache_line_size =128 ;
Signature · 1 line
2.45.2