hexagon: Remove wait{,_next_pc}
v2 cover hexagon: Remove wait{,_next_pc}
Handling the PC update behavior for wait, locking instructions, COF etc. was managed with extra state. But if we pass the current-packet PC to {k0,tlb}lock, they can update PC when pending. And preloading the PC with the next packet address before executing instructions that could end a TB lets wait() use the PC directly.
This series makes no functional change. The bestwait test case, which exercises the wait instruction and the hardware scheduler feature has been added, but this test passes on the baseline.
Worth a second opinion: this series modifies the CPU VMStateDescription but does not update the version_id. I plan to continue making changes along these lines, leading up to the 11.2 release. I hope that it's appropriate/valid to only update the version_id to capture changes between releases, not merely changes between pull requests.
In v2:
- Switched to TARGET_FMT_lx
- Removed unrelated noise hex_tlb_find_match() change
- Dropped the special cases for Y2_k0lock and Y2_tlblock in hex_common.py
- Use ctx->next_PC consistently
- Clarified commit message for 'pass the packet PC to lock implementations'
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Brian Cain (4):
target/hexagon: pass the packet PC to lock implementations target/hexagon: stage the PC in the PC register, drop next_PC target/hexagon: drop wait_next_pc tests/functional/hexagon: add bestwait systest
target/hexagon/cpu.h | 2 -- target/hexagon/gen_tcg_sys.h | 2 +- target/hexagon/helper.h | 2 +- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/translate.h | 2 -- target/hexagon/cpu.c | 2 -- target/hexagon/cpu_helper.c | 8 ------- target/hexagon/genptr.c | 14 +++--------- target/hexagon/hex_interrupts.c | 4 +--- target/hexagon/hex_mmu.c | 16 ++++++++------ target/hexagon/hexswi.c | 2 +- target/hexagon/machine.c | 2 -- target/hexagon/op_helper.c | 25 +++++++++++---------- target/hexagon/translate.c | 27 ++++++++++++----------- tests/functional/hexagon/test_systests.py | 3 +++ 16 files changed, 49 insertions(+), 68 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/4 target/hexagon: pass the packet PC to lock implementations
Hand the k0lock/tlblock lock implementation functions the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)
target/hexagon/hex_mmu.h +1 -1
@@ -22,7 +22,7 @@ extern bool hex_tlb_find_match(CPUHexagonState *env, uint32_t VA, uint64_t *size, int32_t *excp, int mmu_idx);extern int hex_tlb_check_overlap (CPUHexagonState *env,uint64_t entry,uint64_t index); -extern void hex_tlb_lock (CPUHexagonState *env); +extern void hex_tlb_lock (CPUHexagonState *env,target_ulong PC );extern void hex_tlb_unlock (CPUHexagonState *env);void dump_mmu (MonitorHMP *hmp,CPUHexagonState *env);#endif
target/hexagon/sys_macros.h +2 -2
@@ -145,10 +145,10 @@#define fDCINVIDX (REG )#define fDCINVA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ -#define fSET_TLB_LOCK () hex_tlb_lock(env); +#define fSET_TLB_LOCK () hex_tlb_lock(env, PC);#define fCLEAR_TLB_LOCK () hex_tlb_unlock(env); -#define fSET_K0_LOCK () hex_k0_lock(env); +#define fSET_K0_LOCK () hex_k0_lock(env, PC);#define fCLEAR_K0_LOCK () hex_k0_unlock(env);#define fTLB_IDXMASK (INDEX ) \
target/hexagon/hex_mmu.c +9 -7
@@ -156,7 +156,7 @@ static inline void print_thread_states(const char *str) } } -void hex_tlb_lock (CPUHexagonState *env) +void hex_tlb_lock (CPUHexagonState *env,target_ulong PC ) {qemu_log_mask (CPU_LOG_MMU ,"hex_tlb_lock: " TARGET_FMT_ld"\n" , env->threadId);
@@ -170,7 +170,6 @@ void hex_tlb_lock(CPUHexagonState *env)uint8_t tlb_lock =GET_SYSCFG_FIELD (SYSCFG_TLBLOCK , syscfg);if (tlb_lock) {if (env->tlb_lock_state ==HEX_LOCK_QUEUED ) { - env->next_PC +=4 ; env->tlb_lock_count++; env->tlb_lock_state =HEX_LOCK_OWNER ;SET_SYSCFG_FIELD (env,SYSCFG_TLBLOCK ,1 );
@@ -178,19 +177,22 @@ void hex_tlb_lock(CPUHexagonState *env) }if (env->tlb_lock_state ==HEX_LOCK_OWNER ) {qemu_log_mask (CPU_LOG_MMU |LOG_GUEST_ERROR , -"Double tlblock at PC: 0x%" PRIx32 -", thread may hang\n" , - env->next_PC); - env->next_PC +=4 ; +"Double tlblock at PC: 0x" TARGET_FMT_lx +", thread may hang\n" ,PC );CPUState *cs =env_cpu (env);cpu_interrupt (cs,CPU_INTERRUPT_HALT );return ; } env->tlb_lock_state =HEX_LOCK_WAITING ; +/* +* next_PC has already been advanced past this packet. Rewind it +* so that the thread re-executes the tlblock when it is woken by +* the thread that releases the lock. +*/ + env->next_PC =PC ;CPUState *cs =env_cpu (env);cpu_interrupt (cs,CPU_INTERRUPT_HALT ); }else { - env->next_PC +=4 ; env->tlb_lock_count++; env->tlb_lock_state =HEX_LOCK_OWNER ;SET_SYSCFG_FIELD (env,SYSCFG_TLBLOCK ,1 );
target/hexagon/op_helper.c +9 -7
@@ -1283,7 +1283,7 @@ void HELPER(modify_ssr)(CPUHexagonState *env, uint32_t new, uint32_t old)hexagon_modify_ssr (env, new, old); } -static void hex_k0_lock (CPUHexagonState *env) +static void hex_k0_lock (CPUHexagonState *env,target_ulong PC ) {HexagonCPU *cpu =env_archcpu (env);CPUState *cs =env_cpu (env);
@@ -1297,7 +1297,6 @@ static void hex_k0_lock(CPUHexagonState *env) env->threadId) : 0;if (GET_SYSCFG_FIELD (SYSCFG_K0LOCK , syscfg)) {if (env->k0_lock_state ==HEX_LOCK_QUEUED ) { - env->next_PC +=4 ; env->k0_lock_count++; env->k0_lock_state =HEX_LOCK_OWNER ;SET_SYSCFG_FIELD (env,SYSCFG_K0LOCK ,1 );
@@ -1305,19 +1304,22 @@ static void hex_k0_lock(CPUHexagonState *env) }if (env->k0_lock_state ==HEX_LOCK_OWNER ) {qemu_log_mask (LOG_GUEST_ERROR , -"Double k0lock at PC: 0x%" PRIx32 -", thread may hang\n" , - env->next_PC); - env->next_PC +=4 ; +"Double k0lock at PC: 0x" TARGET_FMT_lx +", thread may hang\n" ,PC );cpu_interrupt (cs,CPU_INTERRUPT_HALT );cpu_loop_exit (cs);return ; } env->k0_lock_state =HEX_LOCK_WAITING ; +/* +* next_PC has already been advanced past this packet. Rewind it +* so that the thread re-executes the k0lock when it is woken by +* the thread that releases the lock. +*/ + env->next_PC =PC ;cpu_interrupt (cs,CPU_INTERRUPT_HALT );cpu_loop_exit (cs); }else { - env->next_PC +=4 ; env->k0_lock_count++; env->k0_lock_state =HEX_LOCK_OWNER ;SET_SYSCFG_FIELD (env,SYSCFG_K0LOCK ,1 );
Signature · 1 line
2.34.1
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
Quoted 11 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
In reply to Brian CainHi Brian,
Quoted 12 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)
Review
Quoted 8 lines
(quoted diff) +3
-3-extern void hex_tlb_lock(CPUHexagonState *env); +extern void hex_tlb_lock(CPUHexagonState *env, target_ulong PC); -void hex_tlb_lock(CPUHexagonState *env) +void hex_tlb_lock(CPUHexagonState *env, target_ulong PC) -static void hex_k0_lock(CPUHexagonState *env) +static void hex_k0_lock(CPUHexagonState *env, target_ulong PC)
Please do not re-introduce more target_ulong uses.
@next_PC was converted from target_ulong to uint32_t in commit 613653e500c ("Hexagon Remove next_PC from runtime state").
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
Quoted 21 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 17 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
Signed-off-by Brian Cain <[email protected]>---
target/hexagon/hex_mmu.h | 2 +-target/hexagon/sys_macros.h| 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++-------4 files changed, 21 insertions(+), 17 deletions(-)target/hexagon/hex_mmu.c +2
-2-extern void hex_tlb_lock (CPUHexagonState *env); +extern void hex_tlb_lock (CPUHexagonState *env,target_ulong PC ); -void hex_tlb_lock (CPUHexagonState *env) +void hex_tlb_lock (CPUHexagonState *env,target_ulong PC )
Quoted 7 lines
target/hexagon/op_helper.c void HELPER(modify_ssr)(CPUHexagonState *env, uint32_t new, uint32_t old) · line 1286
Quoted 2 lines
target/hexagon/op_helper.c +1
-1-static void hex_k0_lock (CPUHexagonState *env) +static void hex_k0_lock (CPUHexagonState *env,target_ulong PC )Please do not re-introduce more
target_ulonguses.@next_PC was converted from
target_ulongtouint32_tin commit613653e500c("Hexagon Removenext_PCfrom runtime state").
That's ideally "cleaner", but in practice, since hexagon currently has a single variant (32 bit only), it's not a problem.
In general, for targets having a single variant (only 32 or 64 bit), I'm not sure we gain anything from chasing down usage of target_*long.
Regards,
Pierrick
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
Quoted 27 lines · Pierrick Bouvier
Quoted 26 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 12 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)Review
Quoted 8 lines
(quoted diff) +3
-3-extern void hex_tlb_lock(CPUHexagonState *env); +extern void hex_tlb_lock(CPUHexagonState *env, target_ulong PC); -void hex_tlb_lock(CPUHexagonState *env) +void hex_tlb_lock(CPUHexagonState *env, target_ulong PC) -static void hex_k0_lock(CPUHexagonState *env) +static void hex_k0_lock(CPUHexagonState *env, target_ulong PC)Please do not re-introduce more
target_ulonguses.
Quoted 8 lines
Quoted 2 lines
@next_PC was converted from
target_ulongtouint32_tin commit613653e500c("Hexagon Removenext_PCfrom runtime state").That's ideally "cleaner", but in practice, since hexagon currently has a single variant (32 bit only), it's not a problem.
In general, for targets having a single variant (only 32 or 64 bit), I'm not sure we gain anything from chasing down usage of target_*long.
I prefer to share my thoughs because some maintainers realize "oh indeed this sed change will take me 37 seconds, let's do it now so Phil will stop bugging me about it" and directly reply "Since this series is fully reviewed I addressed that nit locally before posting the pull request, all good thanks!". Anyway nevermind I'll redo the audit in few months and clean that myself then.
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Pierrick Bouvier
Quoted 27 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 13 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a
constant instead of relying on next_PC's opcode-dependent staging.Signed-off-by Brian Cain <[email protected]>---
target/hexagon/hex_mmu.h | 2 +-target/hexagon/sys_macros.h| 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++-------4 files changed, 21 insertions(+), 17 deletions(-)Review
Quoted 8 lines
(quoted diff) +3
-3-extern void hex_tlb_lock(CPUHexagonState *env); +extern void hex_tlb_lock(CPUHexagonState *env, target_ulong PC); -void hex_tlb_lock(CPUHexagonState *env) +void hex_tlb_lock(CPUHexagonState *env, target_ulong PC) -static void hex_k0_lock(CPUHexagonState *env) +static void hex_k0_lock(CPUHexagonState *env, target_ulong PC)Please do not re-introduce more
target_ulonguses.Quoted 8 lines
Quoted 2 lines
@next_PC was converted from
target_ulongtouint32_tin commit613653e500c("Hexagon Removenext_PCfrom runtime state").That's ideally "cleaner", but in practice, since hexagon currently has a single variant (32 bit only), it's not a problem.
In general, for targets having a single variant (only 32 or 64 bit), I'm not sure we gain anything from chasing down usage of target_*long.
Quoted 6 lines
I prefer to share my thoughs because some maintainers realize "oh indeed this sed change will take me 37 seconds, let's do it now so Phil will stop bugging me about it" and directly reply "Since this series is fully reviewed I addressed that nit locally before posting the pull request, all good thanks!". Anyway nevermind I'll redo the audit in few months and clean that myself then.
Sure, it was not a "stop bugging about it Philippe" comment, just a remark, for Brian also, that what we need to prevent is introducing target_*long which create duplicated definitions.
It's fine to have target specific code, as long as there is a single target variant. Just my 2 cents.
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
Quoted 39 lines · Pierrick Bouvier
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 29 lines · Pierrick Bouvier
Quoted 23 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 12 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a
constant instead of relying on next_PC's opcode-dependent staging.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)Review
Quoted 6 lines
(quoted diff) +3
-3-extern void hex_tlb_lock(CPUHexagonState *env); +extern void hex_tlb_lock(CPUHexagonState *env, target_ulong PC); -void hex_tlb_lock(CPUHexagonState *env) +void hex_tlb_lock(CPUHexagonState *env, target_ulong PC) -static void hex_k0_lock(CPUHexagonState *env) +static void hex_k0_lock(CPUHexagonState *env, target_ulong PC)Please do not re-introduce more
target_ulonguses.Quoted 2 lines
@next_PC was converted from
target_ulongtouint32_tin commit613653e500c("Hexagon Removenext_PCfrom runtime state").That's ideally "cleaner", but in practice, since hexagon currently has a single variant (32 bit only), it's not a problem.
Quoted 8 lines
Quoted 2 lines
In general, for targets having a single variant (only 32 or 64 bit), I'm not sure we gain anything from chasing down usage of target_*long.
I prefer to share my thoughs because some maintainers realize "oh indeed this sed change will take me 37 seconds, let's do it now so Phil will stop bugging me about it" and directly reply "Since this series is fully reviewed I addressed that nit locally before posting the pull request, all good thanks!". Anyway nevermind I'll redo the audit in few months and clean that myself then.
Quoted 6 lines
Sure, it was not a "stop bugging about it Philippe" comment, just a remark, for Brian also, that what we need to prevent is introducing target_*long which create duplicated definitions.
It's fine to have target specific code, as long as there is a single target variant. Just my 2 cents.
Happy to fix it and make a note to myself not to re-introduce it.
:)
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
In reply to Pierrick BouvierQuoted 46 lines · Pierrick Bouvier
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Pierrick Bouvier
Quoted 27 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 13 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a
constant instead of relying on next_PC's opcode-dependent staging.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)Review
Quoted 8 lines
(quoted diff) +3
-3-extern void hex_tlb_lock(CPUHexagonState *env); +extern void hex_tlb_lock(CPUHexagonState *env, target_ulong PC); -void hex_tlb_lock(CPUHexagonState *env) +void hex_tlb_lock(CPUHexagonState *env, target_ulong PC) -static void hex_k0_lock(CPUHexagonState *env) +static void hex_k0_lock(CPUHexagonState *env, target_ulong PC)Please do not re-introduce more
target_ulonguses.Quoted 8 lines
Quoted 2 lines
@next_PC was converted from
target_ulongtouint32_tin commit613653e500c("Hexagon Removenext_PCfrom runtime state").That's ideally "cleaner", but in practice, since hexagon currently has a single variant (32 bit only), it's not a problem.
In general, for targets having a single variant (only 32 or 64 bit), I'm not sure we gain anything from chasing down usage of target_*long.
Quoted 6 lines
I prefer to share my thoughs because some maintainers realize "oh indeed this sed change will take me 37 seconds, let's do it now so Phil will stop bugging me about it" and directly reply "Since this series is fully reviewed I addressed that nit locally before posting the pull request, all good thanks!". Anyway nevermind I'll redo the audit in few months and clean that myself then.
Quoted 6 lines
Sure, it was not a "stop bugging about it Philippe" comment, just a remark, for Brian also, that what we need to prevent is introducing target_*long which create duplicated definitions.
It's fine to have target specific code, as long as there is a single target variant. Just my 2 cents.
OK so this is more about our distinct way of work then. I pay attention to detail and often derails and get delayed / lost, while you keep focus on the main goal and get there faster. Thanksfully we are complementary :) I'll try to reduce my scrutinity on Hexagon code base since you are actively looking at it, that'll help me to focus.
Regards,
Phil.
Re: [PATCH v2 1/4] target/hexagon: pass the packet PC to lock implementations
In reply to Brian CainQuoted 11 lines · Brian Cain
Hand the k0lock/tlblock lock implementation functions the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 2 +- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 16 +++++++++------- target/hexagon/op_helper.c | 16 +++++++++------- 4 files changed, 21 insertions(+), 17 deletions(-)
PATCH v2 2/4 target/hexagon: stage the PC in the PC register, drop next_PC
In reply to Brian CainPreload hex_gpr[HEX_REG_PC] with the next packet's address instead of staging it in a separate next_PC global; nothing reads the architectural PC mid-packet. Removes hex_next_PC, next_PC, and need_next_pc.
--- target/hexagon/cpu.h | 1 - target/hexagon/translate.h | 2 -- target/hexagon/cpu.c | 1 - target/hexagon/genptr.c | 14 +++----------- target/hexagon/hex_mmu.c | 4 ++-- target/hexagon/machine.c | 1 - target/hexagon/op_helper.c | 6 +++--- target/hexagon/translate.c | 27 ++++++++++++++------------- 8 files changed, 22 insertions(+), 34 deletions(-)
target/hexagon/cpu.h +0 -1
@@ -153,7 +153,6 @@ typedef struct CPUArchState {uint32_t k0_lock_count;uint64_t t_cycle_count;#endif -uint32_t next_PC;uint32_t imprecise_exception;target_ulong new_value_usr;
target/hexagon/translate.h +0 -2
@@ -85,7 +85,6 @@ typedef struct DisasContext {DECLARE_BITMAP (insn_qregs_read,NUM_QREGS );bool pre_commit;bool need_commit; -bool need_next_pc;TCGCond branch_cond;target_ulong branch_dest;bool is_tight_loop;
@@ -352,7 +351,6 @@ extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];extern TCGv hex_pred[NUM_PREGS ];extern TCGv hex_slot_cancelled;extern TCGv hex_new_value_usr; -extern TCGv hex_next_PC;extern TCGv hex_store_addr[STORES_MAX ];extern TCGv_i32 hex_store_width[STORES_MAX ];extern TCGv hex_store_val32[STORES_MAX ];
target/hexagon/cpu.c +0 -1
@@ -454,7 +454,6 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type) env->k0_lock_state =HEX_LOCK_UNLOCKED ; env->tlb_lock_count =0 ; env->k0_lock_count =0 ; - env->next_PC =0 ; env->t_sreg[HEX_SREG_HTID ] = cpu->htid; env->threadId = cpu->htid;
target/hexagon/genptr.c +3 -11
@@ -748,22 +748,14 @@ static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr,tcg_gen_brcondi_tl (cond, pred,1 , pred_false); } -/* -* If gen_end_tb() will unconditionally overwrite PC with hex_next_PC -* (because this packet has a predicated COF that may not execute), -* write the branch target there instead of directly into the PC -* global, or the overwrite in gen_end_tb() would clobber it. -*/ -TCGv pc_wr = ctx->need_next_pc ? hex_next_PC : hex_gpr[HEX_REG_PC ]; -if (ctx->pkt.pkt_has_multi_cof) {/* If there are multiple branches in a packet, ignore the second one */ -tcg_gen_movcond_tl (TCG_COND_NE , pc_wr, +tcg_gen_movcond_tl (TCG_COND_NE , hex_gpr[HEX_REG_PC ], ctx->branch_taken,tcg_constant_tl (0 ), - pc_wr, addr); + hex_gpr[HEX_REG_PC ], addr);tcg_gen_movi_tl (ctx->branch_taken,1 ); }else { -tcg_gen_mov_tl (pc_wr, addr); +tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], addr); }if (cond !=TCG_COND_ALWAYS ) {
target/hexagon/hex_mmu.c +2 -2
@@ -185,11 +185,11 @@ void hex_tlb_lock(CPUHexagonState *env, target_ulong PC) } env->tlb_lock_state =HEX_LOCK_WAITING ;/* -* next_PC has already been advanced past this packet. Rewind it +* The PC has already been advanced past this packet. Rewind it * so that the thread re-executes the tlblock when it is woken by * the thread that releases the lock. */ - env->next_PC =PC ; + env->gpr[HEX_REG_PC ] =PC ;CPUState *cs =env_cpu (env);cpu_interrupt (cs,CPU_INTERRUPT_HALT ); }else {
target/hexagon/machine.c +0 -1
@@ -29,7 +29,6 @@ const VMStateDescription vmstate_hexagon_cpu = {VMSTATE_UINT32_ARRAY (env.pred, HexagonCPU,NUM_PREGS ),VMSTATE_UINT32_ARRAY (env.t_sreg, HexagonCPU,NUM_SREGS ),VMSTATE_UINT32_ARRAY (env.greg, HexagonCPU,NUM_GREGS ), -VMSTATE_UINT32 (env.next_PC, HexagonCPU),VMSTATE_UINT32 (env.tlb_lock_state, HexagonCPU),VMSTATE_UINT32 (env.k0_lock_state, HexagonCPU), VMSTATE_UINT32(env.tlb_lock_count, HexagonCPU),
target/hexagon/op_helper.c +3 -3
@@ -1312,11 +1312,11 @@ static void hex_k0_lock(CPUHexagonState *env, target_ulong PC) } env->k0_lock_state =HEX_LOCK_WAITING ;/* -* next_PC has already been advanced past this packet. Rewind it +* The PC has already been advanced past this packet. Rewind it * so that the thread re-executes the k0lock when it is woken by * the thread that releases the lock. */ - env->next_PC =PC ; + env->gpr[HEX_REG_PC ] =PC ;cpu_interrupt (cs,CPU_INTERRUPT_HALT );cpu_loop_exit (cs); }else {
@@ -1892,7 +1892,7 @@ void HELPER(setimask)(CPUHexagonState *env, uint32_t tid, uint32_t imask) }qemu_log_mask (LOG_GUEST_ERROR ,"setimask used with an invalid tid near PC: 0x%" - PRIx32"\n" , env->next_PC); + PRIx32"\n" , env->gpr[HEX_REG_PC ]); }void HELPER (sreg_write_masked )(CPUHexagonState *env,uint32_t reg,uint32_t val)
target/hexagon/translate.c +14 -13
@@ -54,7 +54,6 @@ static const AnalyzeInsn opcode_analyze[XX_LAST_OPCODE] = {TCGv hex_gpr[TOTAL_PER_THREAD_REGS ];TCGv hex_pred[NUM_PREGS ];TCGv hex_slot_cancelled; -TCGv hex_next_PC;TCGv hex_new_value_usr;TCGv hex_store_addr[STORES_MAX ];TCGv_i32 hex_store_width[STORES_MAX ];
@@ -190,16 +189,10 @@ static void gen_goto_tb(DisasContext *ctx, unsigned tb_slot_idx, } } -static bool need_next_PC (DisasContext *ctx); -static void gen_end_tb (DisasContext *ctx) {gen_exec_counters (ctx); -if (ctx->need_next_pc) { -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], hex_next_PC); - } -if (ctx->branch_cond !=TCG_COND_NEVER ) {if (ctx->branch_cond !=TCG_COND_ALWAYS ) {TCGLabel *skip =gen_new_label ();
@@ -410,7 +403,13 @@ static bool pkt_ends_tb(Packet *pkt) } -static bool need_next_PC (DisasContext *ctx) +/* +* True when the PC has to be preloaded with the address of the next packet +* before the packet runs: either a conditional change-of-flow leaves it +* untouched when the condition fails, or the packet ends the TB without +* any change-of-flow to advance it. +*/ +static bool need_pc_preload (DisasContext *ctx) {Packet *pkt = &ctx->pkt;if (pkt->pkt_has_cof || ctx->pkt_ends_tb) {
@@ -714,9 +713,12 @@ static void gen_start_packet(DisasContext *ctx)tcg_gen_movi_tl (ctx->branch_taken,0 ); } ctx->pkt_ends_tb =pkt_ends_tb (&ctx->pkt); - ctx->need_next_pc =need_next_PC (ctx); -if (ctx->need_next_pc) { -tcg_gen_movi_tl (hex_next_PC, ctx->next_PC); +/* +* Any change-of-flow in this packet overwrites the preloaded value, and +* the k0lock/tlblock helpers rewind it when the lock is contested. +*/ +if (need_pc_preload (ctx)) { +tcg_gen_movi_tl (hex_gpr[HEX_REG_PC ], ctx->next_PC); }/* Preload the predicated registers into get_result_gpr(ctx, i) */
@@ -1446,8 +1448,6 @@ void hexagon_translate_init(void) } hex_new_value_usr =tcg_global_mem_new (tcg_env, offsetof(CPUHexagonState , new_value_usr),"new_value_usr" ); - hex_next_PC =tcg_global_mem_new (tcg_env, - offsetof(CPUHexagonState , next_PC),"next_PC" );for (i =0 ; i <NUM_PREGS ; i++) { hex_pred[i] = tcg_global_mem_new(tcg_env,
@@ -1470,6 +1470,7 @@ void hexagon_translate_init(void) hex_imprecise_exception =tcg_global_mem_new (tcg_env, offsetof(CPUHexagonState , imprecise_exception),"imprecise_exception" );#endif +for (i =0 ; i <STORES_MAX ; i++) {snprintf (store_addr_names[i],NAME_LEN ,"store_addr_%d" , i); hex_store_addr[i] = tcg_global_mem_new(tcg_env,
Signature · 1 line
2.34.1
PATCH v2 3/4 target/hexagon: drop wait_next_pc
In reply to Brian CainRead the live PC instead; it already holds the same value once the PC-staging removal in the previous commit landed.
--- target/hexagon/cpu.h | 1 - target/hexagon/gen_tcg_sys.h | 2 +- target/hexagon/helper.h | 2 +- target/hexagon/cpu.c | 1 - target/hexagon/cpu_helper.c | 8 -------- target/hexagon/hex_interrupts.c | 4 +--- target/hexagon/hexswi.c | 2 +- target/hexagon/machine.c | 1 - target/hexagon/op_helper.c | 7 +++---- 9 files changed, 7 insertions(+), 21 deletions(-)
target/hexagon/cpu.h +0 -1
@@ -143,7 +143,6 @@ typedef struct CPUArchState {uint32_t t_sreg[NUM_SREGS ];uint32_t greg[NUM_GREGS ]; -uint32_t wait_next_pc;/* This alias of CPUState.cpu_index is used by imported sources: */ uint32_t threadId;
target/hexagon/gen_tcg_sys.h +1 -1
@@ -80,7 +80,7 @@#define fGEN_TCG_Y2_wait (SHORTCODE ) \ do { \ RsV = RsV; \ - gen_helper_wait(tcg_env, tcg_constant_tl(ctx->pkt.pc)); \ + gen_helper_wait(tcg_env); \ } while (0)#define fGEN_TCG_Y2_resume (SHORTCODE ) \
target/hexagon/helper.h +1 -1
@@ -136,7 +136,7 @@ DEF_HELPER_3(sreg_write_masked, void, env, i32, i32) DEF_HELPER_3(setprio, void, env, i32, i32) DEF_HELPER_2(start, void, env, i32) DEF_HELPER_1(stop, void, env) -DEF_HELPER_2(wait, void, env, i32) +DEF_HELPER_1(wait, void, env) DEF_HELPER_2(resume, void, env, i32) DEF_HELPER_1(resched, void, env)DEF_HELPER_3 (modify_ssr, void, env, i32, i32)
target/hexagon/cpu.c +0 -1
@@ -449,7 +449,6 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)#ifndef CONFIG_USER_ONLY memset (env->t_sreg,0 ,sizeof (uint32_t ) *NUM_SREGS );memset (env->greg,0 ,sizeof (uint32_t ) *NUM_GREGS ); - env->wait_next_pc =0 ; env->tlb_lock_state =HEX_LOCK_UNLOCKED ; env->k0_lock_state =HEX_LOCK_UNLOCKED ; env->tlb_lock_count =0 ;
target/hexagon/cpu_helper.c +0 -8
@@ -215,14 +215,6 @@ static void hexagon_resume_thread(CPUHexagonState *env) {CPUState *cs =env_cpu (env);clear_wait_mode (env); -/* -* The wait instruction keeps the PC pointing to itself -* so that it has an opportunity to check for interrupts. -* -* When we come out of wait mode, adjust the PC to the -* next executable instruction. -*/ - env->gpr[HEX_REG_PC ] = env->wait_next_pc; cs =env_cpu (env);ASSERT_DIRECT_TO_GUEST_UNSET (env, cs->exception_index); cs->halted = false;
target/hexagon/hex_interrupts.c +1 -3
@@ -349,14 +349,12 @@ static void hex_accept_int(CPUHexagonState *env, int int_num)qemu_log_mask (CPU_LOG_INT ,"%s: thread " TARGET_FMT_ld" resuming, exiting WAIT mode\n" , __func__, env->threadId); - elr = env->wait_next_pc;clear_wait_mode (env); cs->halted = false; }else if (env->k0_lock_state ==HEX_LOCK_WAITING ) {g_assert_not_reached (); - }else { - elr = env->gpr[HEX_REG_PC ]; } + elr = env->gpr[HEX_REG_PC ];if (int_should_dtg (env, int_num)) {int vic_group = int_num -2 ;
target/hexagon/hexswi.c +1 -1
@@ -936,7 +936,7 @@ void hexagon_cpu_do_interrupt(CPUState *cs)case HEX_EVENT_IMPRECISE : env->imprecise_exception =0 ;if (get_exe_mode (env) ==HEX_EXE_MODE_WAIT ) { - env->gpr[HEX_REG_PC ] = env->wait_next_pc -4 ; + env->gpr[HEX_REG_PC ] -=4 ;clear_wait_mode (env); }switch (env->cause_code) {
target/hexagon/machine.c +0 -1
@@ -35,7 +35,6 @@ const VMStateDescription vmstate_hexagon_cpu = {VMSTATE_UINT32 (env.k0_lock_count, HexagonCPU),VMSTATE_UINT32 (env.threadId, HexagonCPU),VMSTATE_UINT32 (env.cause_code, HexagonCPU), -VMSTATE_UINT32 (env.wait_next_pc, HexagonCPU),VMSTATE_UINT64 (env.t_cycle_count, HexagonCPU), VMSTATE_UINT32(env.imprecise_exception, HexagonCPU),
target/hexagon/op_helper.c +3 -4
@@ -1743,7 +1743,7 @@ static void set_wait_mode(CPUHexagonState *env)SET_SYSTEM_FIELD (env,HEX_SREG_MODECTL ,MODECTL_W , thread_wait_mask); } -static void hexagon_wait_thread (CPUHexagonState *env,uint32_t PC ) +static void hexagon_wait_thread (CPUHexagonState *env) {CPUState *cs;
@@ -1770,7 +1770,6 @@ static void hexagon_wait_thread(CPUHexagonState *env, uint32_t PC)return ; }set_wait_mode (env); - env->wait_next_pc =PC +4 ;cpu_interrupt (cs,CPU_INTERRUPT_HALT ); }
@@ -1838,12 +1837,12 @@ void HELPER(resched)(CPUHexagonState *env)resched (env); } -void HELPER (wait )(CPUHexagonState *env,uint32_t PC ) +void HELPER (wait )(CPUHexagonState *env) {BQL_LOCK_GUARD ();if (!fIN_DEBUG_MODE (env->threadId)) { -hexagon_wait_thread (env,PC ); +hexagon_wait_thread (env); } }
Signature · 1 line
2.34.1
PATCH v2 4/4 tests/functional/hexagon: add bestwait systest
In reply to Brian Cain--- tests/functional/hexagon/test_systests.py | 3 +++ 1 file changed, 3 insertions(+)
tests/functional/hexagon/test_systests.py +3 -0
@@ -93,6 +93,9 @@ def test_semihost(self): def test_dtg_interrupt(self): self.run_exit_zero("dtg_interrupt") + def test_bestwait(self): + self.run_exit_zero("bestwait") + def test_mmu_multi_tlb(self): self.run_exit_zero("mmu_multi_tlb")
Signature · 1 line
2.34.1
Re: [PATCH v2 4/4] tests/functional/hexagon: add bestwait systest
Quoted 6 lines · Brian Cain
Acked-by Taylor Simpson <[email protected]>Signed-off-by Brian Cain <[email protected]>--- tests/functional/hexagon/test_systests.py | 3 +++ 1 file changed, 3 insertions(+)