hexagon: Remove wait{,_next_pc}
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.
Brian Cain (4):
target/hexagon: pass the packet PC to the k0lock/tlblock helpers 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 | 9 +++---- 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 | 15 ++++++------ target/hexagon/hexswi.c | 2 +- target/hexagon/machine.c | 2 -- target/hexagon/op_helper.c | 24 +++++++++---------- target/hexagon/translate.c | 29 ++++++++++++----------- target/hexagon/hex_common.py | 6 ++++- tests/functional/hexagon/test_systests.py | 3 +++ 17 files changed, 57 insertions(+), 73 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 target/hexagon: pass the packet PC to the k0lock/tlblock helpers
Hand the k0lock/tlblock helpers the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
--- target/hexagon/hex_mmu.h | 9 +++++---- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 15 ++++++++------- target/hexagon/op_helper.c | 15 ++++++++------- target/hexagon/hex_common.py | 6 +++++- 5 files changed, 28 insertions(+), 21 deletions(-)
target/hexagon/hex_mmu.h +5 -4
@@ -17,12 +17,13 @@ extern uint32_t hex_tlb_lookup(CPUHexagonState *env, uint32_t ssr, uint32_t VA);extern void hex_mmu_on (CPUHexagonState *env);extern void hex_mmu_off (CPUHexagonState *env);extern void hex_mmu_mode_change (CPUHexagonState *env); -extern bool hex_tlb_find_match (CPUHexagonState *env,uint32_t VA , -MMUAccessType access_type,hwaddr *PA ,int *prot, -uint64_t *size,int32_t *excp,int mmu_idx); +extern bool hex_tlb_find_match (CPUHexagonState *env,target_ulong VA , +MMUAccessType access_type, +hwaddr *PA ,int *prot,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 +8 -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,21 @@ 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%x, 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 +8 -7
@@ -1278,7 +1278,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);
@@ -1292,7 +1292,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 );
@@ -1300,19 +1299,21 @@ 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%x, 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 );
target/hexagon/hex_common.py +5 -1
@@ -284,7 +284,11 @@ def need_ea(tag): def need_PC(tag): - return "A_IMPLICIT_READS_PC" in attribdict[tag] + return ( + "A_IMPLICIT_READS_PC" in attribdict[tag] + or tag == "Y2_k0lock" + or tag == "Y2_tlblock" + ) def need_next_PC(tag):
Signature · 1 line
2.34.1
Re: [PATCH 1/4] target/hexagon: pass the packet PC to the k0lock/tlblock helpers
Quoted 3 lines · Brian Cain
Hand the k0lock/tlblock helpers the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
The word "helpers" isn't entirely accurate. The QEMU helpers already take PC as an argument.
This patch adds the PC argument to the implementation functions hex_tlb_lock/hex_k0_lock called from the respective helpers. See my comment below on hex_common.py.
Quoted 19 lines
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/hex_mmu.h | 9 +++++---- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 15 ++++++++------- target/hexagon/op_helper.c | 15 ++++++++------- target/hexagon/hex_common.py | 6 +++++- 5 files changed, 28 insertions(+), 21 deletions(-)target/hexagon/hex_mmu.h +0
-0@@ -17,12 +17,13 @@ extern uint32_t hex_tlb_lookup(CPUHexagonState *env, uint32_t ssr, uint32_t VA);extern void hex_mmu_on (CPUHexagonState *env);extern void hex_mmu_off (CPUHexagonState *env);extern void hex_mmu_mode_change (CPUHexagonState *env);
target/hexagon/hex_mmu.h extern uint32_t hex_tlb_lookup(CPUHexagonState *env, · line 27
Quoted 10 lines
target/hexagon/hex_mmu.h +4
-3-extern bool hex_tlb_find_match (CPUHexagonState *env,uint32_t VA , -MMUAccessType access_type,hwaddr *PA ,int *prot, -uint64_t *size,int32_t *excp,int mmu_idx); +extern bool hex_tlb_find_match (CPUHexagonState *env,target_ulong VA , +MMUAccessType access_type, +hwaddr *PA ,int *prot,uint64_t *size, +int32_t *excp,int mmu_idx);
Why is this change included in this patch?
Quoted 47 lines
target/hexagon/hex_mmu.h +1
-1extern 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 +1
-2@@ -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 );
target/hexagon/hex_mmu.c void hex_tlb_lock(CPUHexagonState *env) · line 182
Quoted 10 lines
target/hexagon/hex_mmu.c +1
-4@@ -178,19 +177,21 @@ 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%x, thread may hang\n", PC);
Don't use %x, use TARGET_FMT_lx.
Quoted 41 lines
target/hexagon/hex_mmu.c +6
-1CPUState *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 +1
-1@@ -1278,7 +1278,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);target/hexagon/op_helper.c +0
-1@@ -1292,7 +1292,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 );
target/hexagon/op_helper.c static void hex_k0_lock(CPUHexagonState *env) · line 1304
Quoted 10 lines
target/hexagon/op_helper.c +1
-4@@ -1300,19 +1299,21 @@ 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%x, thread may hang\n" ,PC );
Don't use %x, use TARGET_FMT_lx.
Quoted 23 lines
target/hexagon/op_helper.c +6
-1cpu_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);target/hexagon/hex_common.py +0
-0
target/hexagon/hex_common.py def need_ea(tag): · line 292
Quoted 10 lines
target/hexagon/hex_common.py +5
-1@@ -284,7 +284,11 @@ def need_ea(tag): def need_PC(tag): - return "A_IMPLICIT_READS_PC" in attribdict[tag] + return ( + "A_IMPLICIT_READS_PC" in attribdict[tag] + or tag == "Y2_k0lock" + or tag == "Y2_tlblock" + )
This isn't needed. These 2 opcodes already have A_IMPLICIT_READS_PC set. Look for fSET_K0_LOCK and fSET_TLB_LOCK in calculate_attribs in hex_common.py.
Thanks,
Taylor
Re: [PATCH 1/4] target/hexagon: pass the packet PC to the k0lock/tlblock helpers
Quoted 11 lines · Taylor Simpson
On Tue, Sep 15, 2026 at 9:45 AM Brian Cain <[email protected]> wrote:
Hand the k0lock/tlblock helpers the packet PC as a constant instead of relying on next_PC's opcode-dependent staging.
The word "helpers" isn't entirely accurate. The QEMU helpers already take PC as an argument.
This patch adds the PC argument to the implementation functions hex_tlb_lock/hex_k0_lock called from the respective helpers. See my comment below onhex_common.py.
Thanks for the feedback. I'll work on a follow up series to address the issues you raised in this one.
Quoted 193 lines
Signed-off-by: Brian Cain <[email protected]> --- target/hexagon/hex_mmu.h | 9 +++++---- target/hexagon/sys_macros.h | 4 ++-- target/hexagon/hex_mmu.c | 15 ++++++++------- target/hexagon/op_helper.c | 15 ++++++++------- target/hexagon/hex_common.py | 6 +++++- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/target/hexagon/hex_mmu.h b/target/hexagon/hex_mmu.h index 56b2c4a89d0..4eaf15c4996 100644 --- a/target/hexagon/hex_mmu.h +++ b/target/hexagon/hex_mmu.h @@ -17,12 +17,13 @@ extern uint32_t hex_tlb_lookup(CPUHexagonState *env, uint32_t ssr, uint32_t VA); extern void hex_mmu_on(CPUHexagonState *env); extern void hex_mmu_off(CPUHexagonState *env); extern void hex_mmu_mode_change(CPUHexagonState *env); -extern bool hex_tlb_find_match(CPUHexagonState *env, uint32_t VA, - MMUAccessType access_type, hwaddr *PA, int *prot, - uint64_t *size, int32_t *excp, int mmu_idx); +extern bool hex_tlb_find_match(CPUHexagonState *env, target_ulong VA, + MMUAccessType access_type, + hwaddr *PA, int *prot, uint64_t *size, + int32_t *excp, int mmu_idx);Why is this change included in this patch?
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 diff --git a/target/hexagon/sys_macros.h b/target/hexagon/sys_macros.h index a5b9b7f2592..72179d49ab3 100644 --- a/target/hexagon/sys_macros.h +++ b/target/hexagon/sys_macros.h @@ -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) \ diff --git a/target/hexagon/hex_mmu.c b/target/hexagon/hex_mmu.c index d6ee7c40798..d7acaae5ac8 100644 --- a/target/hexagon/hex_mmu.c +++ b/target/hexagon/hex_mmu.c @@ -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,21 @@ 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%x, thread may hang\n", PC);Don't use %x, use
TARGET_FMT_lx.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); diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c index 0d08ac77361..07ba639449c 100644 --- a/target/hexagon/op_helper.c +++ b/target/hexagon/op_helper.c @@ -1278,7 +1278,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); @@ -1292,7 +1292,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); @@ -1300,19 +1299,21 @@ 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%x, thread may hang\n", PC);Don't use %x, use
TARGET_FMT_lx.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); diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py index c180c19b092..1bd31f76a4f 100755 --- a/target/hexagon/hex_common.py +++ b/target/hexagon/hex_common.py @@ -284,7 +284,11 @@ def need_ea(tag): def need_PC(tag): - return "A_IMPLICIT_READS_PC" in attribdict[tag] + return ( + "A_IMPLICIT_READS_PC" in attribdict[tag] + or tag == "Y2_k0lock" + or tag == "Y2_tlblock" + )This isn't needed. These 2 opcodes already have
A_IMPLICIT_READS_PCset. Look forfSET_K0_LOCKandfSET_TLB_LOCKincalculate_attribsinhex_common.py.Thanks,
Taylor
PATCH 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 | 29 +++++++++++++++-------------- 8 files changed, 23 insertions(+), 35 deletions(-)
target/hexagon/cpu.h +0 -1
@@ -146,7 +146,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
@@ -76,7 +76,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;
@@ -315,7 +314,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
@@ -441,7 +441,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
@@ -728,22 +728,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
@@ -184,11 +184,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
@@ -17,7 +17,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
@@ -1306,11 +1306,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 {
@@ -1883,7 +1883,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 +15 -14
@@ -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 ];
@@ -181,16 +180,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 ();
@@ -401,7 +394,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) {
@@ -658,10 +657,13 @@ static void gen_start_packet(DisasContext *ctx)if (ctx->pkt.pkt_has_multi_cof) {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, next_PC); + ctx->pkt_ends_tb =pkt_ends_tb (pkt); +/* +* 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 ], next_PC); }/* Preload the predicated registers into get_result_gpr(ctx, i) */
@@ -1369,8 +1371,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,
@@ -1393,6 +1393,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
Re: [PATCH 2/4] target/hexagon: stage the PC in the PC register, drop next_PC
Quoted 6 lines · Brian Cain
Preload hex_gpr[HEX_REG_PC] with the next packet's address instead of staging it in a separate
next_PCglobal; nothing reads the architectural PC mid-packet. Removeshex_next_PC,next_PC, andneed_next_pc.Signed-off-by Brian Cain <[email protected]>
Quoted 11 lines
--- 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 | 29 +++++++++++++++-------------- 8 files changed, 23 insertions(+), 35 deletions(-)
PATCH 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
@@ -136,7 +136,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
@@ -436,7 +436,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
@@ -214,14 +214,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
@@ -23,7 +23,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
@@ -1734,7 +1734,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;
@@ -1761,7 +1761,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 ); }
@@ -1829,12 +1828,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
Re: [PATCH 3/4] target/hexagon: drop wait_next_pc
Quoted 4 lines · Brian Cain
Read the live PC instead; it already holds the same value once the PC-staging removal in the previous commit landed.
Signed-off-by Brian Cain <[email protected]>
Quoted 12 lines
--- 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(-)
PATCH 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 4/4] tests/functional/hexagon: add bestwait systest
Quoted 11 lines · Brian Cain
Signed-off-by Brian Cain <[email protected]>--- tests/functional/hexagon/test_systests.py | 3 +++ 1 file changed, 3 insertions(+)tests/functional/hexagon/test_systests.py +0
-0
tests/functional/hexagon/test_systests.py def test_semihost(self): · line 101
Quoted 9 lines
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")